fix: make pie chart legend always visible with hover percentages (#23)
Show category names permanently in compact form (text-xs) so they are always discoverable. Percentages appear only on chart hover to save space, matching the original request while keeping the legend accessible without interaction. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
66d0cd85ff
commit
18c7ef3ee9
1 changed files with 4 additions and 5 deletions
|
|
@ -117,15 +117,14 @@ export default function CategoryPieChart({
|
||||||
</ResponsiveContainer>
|
</ResponsiveContainer>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
<div className="flex flex-wrap gap-x-3 gap-y-1 mt-2">
|
||||||
className={`flex flex-wrap gap-x-4 gap-y-1 mt-2 transition-opacity duration-200 ${isChartHovered ? "opacity-100" : "opacity-0 pointer-events-none"}`}
|
|
||||||
>
|
|
||||||
{data.map((item, index) => {
|
{data.map((item, index) => {
|
||||||
const isHidden = hiddenCategories.has(item.category_name);
|
const isHidden = hiddenCategories.has(item.category_name);
|
||||||
|
const pct = total > 0 && !isHidden ? Math.round((item.total / total) * 100) : null;
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
key={index}
|
key={index}
|
||||||
className={`flex items-center gap-1.5 text-sm ${isHidden ? "opacity-40" : ""}`}
|
className={`flex items-center gap-1 text-xs ${isHidden ? "opacity-40" : ""}`}
|
||||||
onContextMenu={(e) => {
|
onContextMenu={(e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
setContextMenu({ x: e.clientX, y: e.clientY, item });
|
setContextMenu({ x: e.clientX, y: e.clientY, item });
|
||||||
|
|
@ -135,7 +134,7 @@ export default function CategoryPieChart({
|
||||||
>
|
>
|
||||||
<PatternSwatch index={index} color={item.category_color} prefix="cat-pie" />
|
<PatternSwatch index={index} color={item.category_color} prefix="cat-pie" />
|
||||||
<span className="text-[var(--muted-foreground)]">
|
<span className="text-[var(--muted-foreground)]">
|
||||||
{item.category_name} {total > 0 && !isHidden ? `${Math.round((item.total / total) * 100)}%` : ""}
|
{item.category_name}{isChartHovered && pct != null ? ` ${pct}%` : ""}
|
||||||
</span>
|
</span>
|
||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue