fix(stats): implement Model Types chart in Collection tab with correct type distribution

This commit is contained in:
Will Miao
2026-06-18 06:48:46 +08:00
parent 8314b9bedb
commit b7721866e5
2 changed files with 84 additions and 1 deletions

View File

@@ -240,6 +240,9 @@ export class StatisticsManager {
// Storage efficiency chart
this.createStorageEfficiencyChart();
// Model types chart (Collection tab)
this.createModelTypesChart();
}
createCollectionPieChart() {
@@ -554,6 +557,68 @@ export class StatisticsManager {
});
}
createModelTypesChart() {
const ctx = document.getElementById('modelTypesChart');
if (!ctx || !this.data.collection || !this.data.collection.model_types_distribution) return;
const distribution = this.data.collection.model_types_distribution;
const typeDisplayNames = {
lora: 'LoRA',
locon: 'LyCORIS',
dora: 'DoRA',
checkpoint: 'Checkpoint',
diffusion_model: 'Diffusion Model',
embedding: 'Embeddings'
};
const colorPalette = {
lora: 'oklch(68% 0.28 256)',
locon: 'oklch(68% 0.25 190)',
dora: 'oklch(68% 0.25 330)',
checkpoint: 'oklch(68% 0.28 45)',
diffusion_model: 'oklch(68% 0.25 280)',
embedding: 'oklch(68% 0.25 120)'
};
const labels = Object.keys(distribution).map(k => typeDisplayNames[k] || k);
const values = Object.values(distribution);
const colors = Object.keys(distribution).map(k => colorPalette[k] || 'oklch(68% 0.15 0)');
const data = {
labels: labels,
datasets: [{
data: values,
backgroundColor: colors,
borderColor: getComputedStyle(document.documentElement).getPropertyValue('--border-color'),
borderWidth: 2
}]
};
this.charts.modelTypes = new Chart(ctx, {
type: 'doughnut',
data: data,
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
position: 'bottom'
},
tooltip: {
callbacks: {
label: (context) => {
const total = context.dataset.data.reduce((a, b) => a + b, 0);
const value = context.parsed;
const pct = ((value / total) * 100).toFixed(1);
return ` ${context.label}: ${value} (${pct}%)`;
}
}
}
}
}
});
}
async initializeLists() {
const listTypes = [
{ type: 'lora', containerId: 'topLorasList' },