Skip to content

Commit 02e9e25

Browse files
leolionartclaude
andcommitted
fix: unify usage and cost charts to top 5 models
Align Cost Analysis with Usage Trends by scoping both charts to the same top 5 model set and update legend labels to "Top 5 Models" for clarity. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent ba951f4 commit 02e9e25

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

frontend/src/components/Dashboard.jsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -622,14 +622,19 @@ function Dashboard({ stats, dailyStats, modelUsage, hourlyStats, loading, isRefr
622622
const sparklineData = hourlyChartData.slice(-12)
623623
const costSparkline = dailyChartData.length >= 2 ? dailyChartData : [...Array(7)].map((_, i) => ({ cost: i === 6 ? totalCost : totalCost * (i * 0.1) }))
624624

625-
// Cost breakdown datasets
625+
// Cost breakdown datasets (same top 5 model scope as Usage Trends)
626+
const top5ModelSet = useMemo(() => new Set(activeTopModels), [activeTopModels])
627+
626628
const costBreakdownBase = useMemo(() => {
627-
return (filteredModelUsage || []).map((m) => ({
629+
const top5Models = (filteredModelUsage || []).filter(m => top5ModelSet.has(m.model_name))
630+
const top5TotalCost = top5Models.reduce((sum, m) => sum + (m.estimated_cost_usd || 0), 0)
631+
632+
return top5Models.map((m) => ({
628633
...m,
629-
percentage: totalCost > 0 ? ((m.estimated_cost_usd || 0) / totalCost * 100).toFixed(0) : '0',
634+
percentage: top5TotalCost > 0 ? ((m.estimated_cost_usd || 0) / top5TotalCost * 100).toFixed(0) : '0',
630635
color: getModelColor(m.model_name)
631636
}))
632-
}, [filteredModelUsage, totalCost])
637+
}, [filteredModelUsage, top5ModelSet])
633638

634639
// Legend always sorted by cost (desc)
635640
const costLegend = useMemo(() => {
@@ -1145,7 +1150,7 @@ function Dashboard({ stats, dailyStats, modelUsage, hourlyStats, loading, isRefr
11451150
gap: '4px',
11461151
paddingRight: '4px'
11471152
}}>
1148-
<span>Model</span>
1153+
<span>Top 5 Models</span>
11491154
<span style={{ textAlign: 'right' }}>Req</span>
11501155
<span style={{ textAlign: 'right' }}>Tokens</span>
11511156
<span style={{ textAlign: 'right', color: isDarkMode ? '#10b981' : '#059669' }}>Cost</span>
@@ -1443,7 +1448,7 @@ function Dashboard({ stats, dailyStats, modelUsage, hourlyStats, loading, isRefr
14431448
justifyContent: 'space-between',
14441449
paddingRight: '8px'
14451450
}}>
1446-
<span>Model</span>
1451+
<span>Top 5 Models</span>
14471452
<span>Cost / %</span>
14481453
</div>
14491454
{costLegend.map((model, index) => (

0 commit comments

Comments
 (0)