From 1462a224463a7d16f8437768718c8b89d77c8a5a Mon Sep 17 00:00:00 2001 From: kelvin27315 Date: Thu, 19 Oct 2023 04:11:45 +0900 Subject: [PATCH 1/3] fix(visx-demo): fix setHoveredId in delaunay-voronoi --- .../visx-demo/src/sandboxes/visx-delaunay-voronoi/Example.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/visx-demo/src/sandboxes/visx-delaunay-voronoi/Example.tsx b/packages/visx-demo/src/sandboxes/visx-delaunay-voronoi/Example.tsx index 5f54485e1..b0f349f9d 100644 --- a/packages/visx-demo/src/sandboxes/visx-delaunay-voronoi/Example.tsx +++ b/packages/visx-demo/src/sandboxes/visx-delaunay-voronoi/Example.tsx @@ -71,7 +71,7 @@ function Example({ width, height, margin = defaultMargin }: VoronoiProps) { const closest = voronoiDiagram.delaunay.find(point.x, point.y); // find neighboring polygons to hightlight - if (closest && data[closest].id !== hoveredId) { + if (data[closest].id !== hoveredId) { const neighbors = Array.from(voronoiDiagram.neighbors(closest)); setNeighborIds(new Set(neighbors.map((d) => data[d].id))); setHoveredId(data[closest].id); From 0d67dcd9c7bfbddd419a154db4a4a92805f22dae Mon Sep 17 00:00:00 2001 From: kelvin27315 Date: Thu, 19 Oct 2023 04:23:42 +0900 Subject: [PATCH 2/3] fix(visx-demo): fix invalid bounds in delaunay-voronoi --- .../visx-demo/src/sandboxes/visx-delaunay-voronoi/Example.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/visx-demo/src/sandboxes/visx-delaunay-voronoi/Example.tsx b/packages/visx-demo/src/sandboxes/visx-delaunay-voronoi/Example.tsx index b0f349f9d..c32f9e2e0 100644 --- a/packages/visx-demo/src/sandboxes/visx-delaunay-voronoi/Example.tsx +++ b/packages/visx-demo/src/sandboxes/visx-delaunay-voronoi/Example.tsx @@ -37,6 +37,8 @@ function Example({ width, height, margin = defaultMargin }: VoronoiProps) { const innerWidth = width - margin.left - margin.right; const innerHeight = height - margin.top - margin.bottom; + if (innerWidth < 0 || innerHeight < 0) return null; + const voronoiDiagram = useMemo( () => voronoi({ From fb47cc74a860556ffdc4ad808ee6b63fae3eebeb Mon Sep 17 00:00:00 2001 From: kelvin27315 Date: Fri, 20 Oct 2023 12:50:42 +0900 Subject: [PATCH 3/3] Refactor to avoid early return and adhere to hooks rules --- .../src/sandboxes/visx-delaunay-voronoi/Example.tsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/visx-demo/src/sandboxes/visx-delaunay-voronoi/Example.tsx b/packages/visx-demo/src/sandboxes/visx-delaunay-voronoi/Example.tsx index c32f9e2e0..aa9ebfda1 100644 --- a/packages/visx-demo/src/sandboxes/visx-delaunay-voronoi/Example.tsx +++ b/packages/visx-demo/src/sandboxes/visx-delaunay-voronoi/Example.tsx @@ -34,10 +34,8 @@ export type VoronoiProps = { }; function Example({ width, height, margin = defaultMargin }: VoronoiProps) { - const innerWidth = width - margin.left - margin.right; - const innerHeight = height - margin.top - margin.bottom; - - if (innerWidth < 0 || innerHeight < 0) return null; + const innerWidth = Math.max(0, width - margin.left - margin.right); + const innerHeight = Math.max(0, height - margin.top - margin.bottom); const voronoiDiagram = useMemo( () =>