Rerun prepare script
This commit is contained in:
parent
349a6c1d53
commit
8614acdfae
24 changed files with 1132 additions and 226 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import { useMemo } from 'react';
|
||||
import { SEGMENT_COLORS } from '../../lib/consts';
|
||||
import { formatValue } from '../../lib/format';
|
||||
import { formatValue, roundedPercentages } from '../../lib/format';
|
||||
|
||||
interface Segment {
|
||||
name: string;
|
||||
|
|
@ -30,6 +30,10 @@ function shortenLabel(name: string): string {
|
|||
|
||||
export default function StackedBarChart({ segments, total, colorMap }: StackedBarChartProps) {
|
||||
const sortedSegments = useMemo(() => [...segments].sort((a, b) => b.value - a.value), [segments]);
|
||||
const roundedPcts = useMemo(
|
||||
() => roundedPercentages(sortedSegments.map((s) => s.value), total, 1),
|
||||
[sortedSegments, total]
|
||||
);
|
||||
|
||||
if (total === 0) {
|
||||
return <div className="text-xs text-warm-400 dark:text-warm-500 italic">No data</div>;
|
||||
|
|
@ -51,7 +55,7 @@ export default function StackedBarChart({ segments, total, colorMap }: StackedBa
|
|||
backgroundColor:
|
||||
colorMap?.[segment.name] ?? SEGMENT_COLORS[i % SEGMENT_COLORS.length],
|
||||
}}
|
||||
title={`${shortenLabel(segment.name)}: ${formatValue(segment.value)} (${pct.toFixed(1)}%)`}
|
||||
title={`${shortenLabel(segment.name)}: ${formatValue(segment.value)} (${roundedPcts[i].toFixed(1)}%)`}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue