diff --git a/frontend/src/components/FilamentTrends.tsx b/frontend/src/components/FilamentTrends.tsx index 605c3857c..226e1e022 100644 --- a/frontend/src/components/FilamentTrends.tsx +++ b/frontend/src/components/FilamentTrends.tsx @@ -27,7 +27,7 @@ const COLORS = ['#00ae42', '#3b82f6', '#f59e0b', '#ef4444', '#8b5cf6', '#ec4899' export function FilamentTrends({ archives, currency = '$' }: FilamentTrendsProps) { const { t } = useTranslation(); const [filamentTypeMetric, setFilamentTypeMetric] = useState('weight'); - const [colorMetric, setColorMetric] = useState<'weight' | 'prints'>('prints'); + const [colorMetric, setColorMetric] = useState('weight'); // Calculate daily usage data const dailyData = useMemo(() => { @@ -377,70 +377,71 @@ export function FilamentTrends({ archives, currency = '$' }: FilamentTrendsProps

{t('stats.colorDistribution')}

-
- - -
+
{colorData.length > 0 ? (() => { const colorTotal = colorData.reduce((sum, e) => sum + e.value, 0); return ( -
- - - - {colorData.map((entry, index) => ( - - ))} - - [ - colorMetric === 'weight' ? formatWeight(Number(value ?? 0)) : `${value ?? 0}`, - colorMetric === 'weight' ? t('stats.filamentByWeight') : t('stats.filamentByPrints'), - ]} - /> - - -
+
+
+ + + + {colorData.map((entry, index) => ( + + ))} + + [ + colorMetric === 'weight' ? formatWeight(Number(value ?? 0)) : `${value ?? 0}`, + colorMetric === 'weight' ? t('stats.filamentByWeight') : t('stats.filamentByPrints'), + ]} + /> + + +
+ + {colorMetric === 'weight' ? formatWeight(colorTotal) : colorTotal} + + + {colorData.length} {colorData.length === 1 ? 'color' : 'colors'} + +
+
+
{colorData.slice(0, 8).map((entry) => { const percent = colorTotal > 0 ? ((entry.value / colorTotal) * 100).toFixed(0) : 0; return ( -
-
+
- - {colorMetric === 'weight' ? formatWeight(entry.value) : entry.value} ยท {percent}% + + {percent}%
); })} - {colorData.length > 8 && ( -

+{colorData.length - 8} more

- )}
+ {colorData.length > 8 && ( +

+{colorData.length - 8} more

+ )}
); })() : ( -
+
{t('stats.noColorData')}
)} diff --git a/frontend/src/components/MetricToggle.tsx b/frontend/src/components/MetricToggle.tsx index 5e6726b23..e508969a3 100644 --- a/frontend/src/components/MetricToggle.tsx +++ b/frontend/src/components/MetricToggle.tsx @@ -7,9 +7,10 @@ const METRICS: Metric[] = ['weight', 'prints', 'time']; interface MetricToggleProps { value: Metric; onChange: (metric: Metric) => void; + exclude?: Metric[]; } -export function MetricToggle({ value, onChange }: MetricToggleProps) { +export function MetricToggle({ value, onChange, exclude }: MetricToggleProps) { const { t } = useTranslation(); const labels: Record = { @@ -18,9 +19,11 @@ export function MetricToggle({ value, onChange }: MetricToggleProps) { time: t('stats.filamentByTime'), }; + const metrics = exclude ? METRICS.filter(m => !exclude.includes(m)) : METRICS; + return (
- {METRICS.map(m => ( + {metrics.map(m => (