From b93c96a58d4614d020142648630ab7cdffc84094 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Benitte?= Date: Sat, 13 Jul 2019 10:58:47 +0900 Subject: [PATCH] fix(voronoi): upgrade d3-delaunay to fix single/collinear points (#640) --- Makefile | 3 ++- packages/voronoi/package.json | 2 +- packages/voronoi/tests/.eslintrc.yml | 2 ++ packages/voronoi/tests/computeMesh.test.js | 19 +++++++++++++++++++ yarn.lock | 18 +++++++++--------- 5 files changed, 33 insertions(+), 11 deletions(-) create mode 100644 packages/voronoi/tests/.eslintrc.yml create mode 100644 packages/voronoi/tests/computeMesh.test.js diff --git a/Makefile b/Makefile index aefad531e..c3d9e264b 100644 --- a/Makefile +++ b/Makefile @@ -146,7 +146,8 @@ packages-tslint: ##@1 packages run tslint on all packages ./packages/scatterplot/index.d.ts \ ./packages/stream/index.d.ts \ ./packages/swarmplot/index.d.ts \ - ./packages/waffle/index.d.ts + ./packages/waffle/index.d.ts \ + ./packages/voronoi/index.d.ts package-test-cover-%: ##@1 packages run tests for a package with code coverage @yarn jest -c ./packages/jest.config.js --rootDir . --coverage ./packages/${*}/tests diff --git a/packages/voronoi/package.json b/packages/voronoi/package.json index 53fcb0cbf..a9f9af5fc 100644 --- a/packages/voronoi/package.json +++ b/packages/voronoi/package.json @@ -25,7 +25,7 @@ ], "dependencies": { "@nivo/core": "0.59.1", - "d3-delaunay": "^4.1.5", + "d3-delaunay": "^5.1.1", "d3-scale": "^3.0.0", "recompose": "^0.30.0" }, diff --git a/packages/voronoi/tests/.eslintrc.yml b/packages/voronoi/tests/.eslintrc.yml new file mode 100644 index 000000000..2f8de9aea --- /dev/null +++ b/packages/voronoi/tests/.eslintrc.yml @@ -0,0 +1,2 @@ +env: + jest: true diff --git a/packages/voronoi/tests/computeMesh.test.js b/packages/voronoi/tests/computeMesh.test.js new file mode 100644 index 000000000..673916b71 --- /dev/null +++ b/packages/voronoi/tests/computeMesh.test.js @@ -0,0 +1,19 @@ +import { computeMesh } from '../src/computeMesh' + +it(`should be able to compute mesh for collinear points`, () => { + const points = [[0, 0], [50, 50], [100, 100]] + + const { voronoi } = computeMesh({ points, width: 500, height: 500, debug: true }) + + const cells = [...voronoi.cellPolygons()] + expect(cells).toHaveLength(3) +}) + +it(`should be able to compute mesh for a single point`, () => { + const points = [[50, 50]] + + const { voronoi } = computeMesh({ points, width: 500, height: 500, debug: true }) + + const cells = [...voronoi.cellPolygons()] + expect(cells).toHaveLength(1) +}) diff --git a/yarn.lock b/yarn.lock index 37f7596ef..4e6b99150 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6311,12 +6311,12 @@ d3-color@1, d3-color@^1.2.3: resolved "https://registry.yarnpkg.com/d3-color/-/d3-color-1.2.3.tgz#6c67bb2af6df3cc8d79efcc4d3a3e83e28c8048f" integrity sha512-x37qq3ChOTLd26hnps36lexMRhNXEtVxZ4B25rL0DVdDsGQIJGB18S7y9XDwlDD6MD/ZBzITCf4JjGMM10TZkw== -d3-delaunay@^4.1.5: - version "4.1.5" - resolved "https://registry.yarnpkg.com/d3-delaunay/-/d3-delaunay-4.1.5.tgz#4318c6d28b22988d88d11650eda440318afe419a" - integrity sha512-rBKVohmXT9+BrDicH8umAVUwtkfLIydVlWnpIEDUZ4l2e1vXCaKbypByF8tkN8TUUKnzJY0s8ldQEroeBRMO9Q== +d3-delaunay@^5.1.1: + version "5.1.1" + resolved "https://registry.yarnpkg.com/d3-delaunay/-/d3-delaunay-5.1.1.tgz#fa2313f5fff1c6007f7d814276fc6914f370d63c" + integrity sha512-BPT4Ej3tpXe+XdexZnave8XfRZHqRn8CZt2oIO9xBhQAaoKgssa9RHuzeszizpOWqtnh6GHBQmLoE2guhifghA== dependencies: - delaunator "^2.0.0" + delaunator "4" d3-dispatch@1: version "1.0.5" @@ -6681,10 +6681,10 @@ del@^3.0.0: pify "^3.0.0" rimraf "^2.2.8" -delaunator@^2.0.0: - version "2.0.5" - resolved "https://registry.yarnpkg.com/delaunator/-/delaunator-2.0.5.tgz#c2a9ba2cf3d5aaab8fa0aa3ae82426d3fc0aeaf5" - integrity sha512-GSYmkITO56erpQzv5Pw+8Vg769kurM16IVUq/AcMb5ZCJCtV7Z2agx9lJ7EbbLno8L099iH2d+hvAK34ZnsvIQ== +delaunator@4: + version "4.0.0" + resolved "https://registry.yarnpkg.com/delaunator/-/delaunator-4.0.0.tgz#3630f477b4923f472f534c62a028aeca6fe22d96" + integrity sha512-KzVgOHix5xaIVzZSfbv3Uzw9aI7mQNDet4Yd2p+tBNkfNHMFJbjbVa3q0nC7q7TjWZLX49QbzcT+pXazXX3Qmg== delayed-stream@~1.0.0: version "1.0.0"