Skip to content

Commit

Permalink
fix: Default center not appearing randomly
Browse files Browse the repository at this point in the history
It should not be possible for the hoveredSlice value to ever be 0
  • Loading branch information
amattu2 committed Feb 20, 2024
1 parent 206f46d commit 7f70db3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/components/NodeChart/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ const NodeChart: FC<Props> = ({ label, centerCount, data }: Props) => {
const dataset: PieSectorDataItem[] = useMemo(() => data.filter(({ value }) => value > 0), [data]);
const onMouseOver = useCallback((data) => setHoveredSlice(data), []);
const onMouseLeave = useCallback(() => setHoveredSlice(null), []);
const showDefaultCenter: boolean = useMemo(() => (dataset.length === 0 && hoveredSlice === null)
|| hoveredSlice?.value === 0, [dataset, hoveredSlice]);

return (
<StyledChartContainer>
Expand All @@ -68,7 +70,7 @@ const NodeChart: FC<Props> = ({ label, centerCount, data }: Props) => {
isAnimationActive={false}
aria-label={`${label} chart background`}
>
{(dataset.length === 0 && hoveredSlice === null) && <Label position="center" content={(<PieChartCenter title="Total" value={0} />)} />}
{showDefaultCenter ? <Label position="center" content={(<PieChartCenter title="Total" value={0} />)} /> : null}
</Pie>
<Pie
data={dataset}
Expand Down

0 comments on commit 7f70db3

Please sign in to comment.