Skip to content

Commit

Permalink
Replace d3-voronoi with d3-delaunay. Fixes #1492
Browse files Browse the repository at this point in the history
  • Loading branch information
domoritz committed Feb 21, 2019
1 parent 6a56c93 commit 6d76b23
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 41 deletions.
4 changes: 2 additions & 2 deletions packages/vega-voronoi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"module": "index",
"repository": "vega/vega",
"scripts": {
"rollup": "rollup -g d3-voronoi:d3,vega-dataflow:vega,vega-util:vega -f umd -n vega.transforms -o build/vega-voronoi.js -- index.js",
"rollup": "rollup -g d3-delaunay:d3,vega-dataflow:vega,vega-util:vega -f umd -n vega.transforms -o build/vega-voronoi.js -- index.js",
"prebuild": "rimraf build && mkdir build",
"build": "yarn rollup",
"postbuild": "terser build/vega-voronoi.js -c -m -o build/vega-voronoi.min.js",
Expand All @@ -22,7 +22,7 @@
"postpublish": "git push && git push --tags"
},
"dependencies": {
"d3-voronoi": "^1.1.4",
"d3-delaunay": "^4.1.5",
"vega-dataflow": "^5.0.0",
"vega-util": "^1.8.0"
},
Expand Down
18 changes: 8 additions & 10 deletions packages/vega-voronoi/src/Voronoi.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Transform} from 'vega-dataflow';
import {inherits} from 'vega-util';
import {voronoi} from 'd3-voronoi';
import {Delaunay} from 'd3-delaunay';

export default function Voronoi(params) {
Transform.call(this, null, params);
Expand All @@ -27,20 +27,18 @@ var defaultExtent = [[-1e5, -1e5], [1e5, 1e5]];
prototype.transform = function(_, pulse) {
var as = _.as || 'path',
data = pulse.source,
diagram, polygons, i, n;
delaunay, extent, voronoi, polygon, i, n;

// configure and construct voronoi diagram
diagram = voronoi().x(_.x).y(_.y);
if (_.size) diagram.size(_.size);
else diagram.extent(_.extent || defaultExtent);

this.value = (diagram = diagram(data));
delaunay = Delaunay.from(data, _.x, _.y);
extent = _.size ? [0, 0 , _.size[0], _.size[1]] : _.extent || defaultExtent;
this.value = (voronoi = delaunay.voronoi(extent))

// map polygons to paths
polygons = diagram.polygons();
for (i=0, n=data.length; i<n; ++i) {
data[i][as] = polygons[i]
? 'M' + polygons[i].join('L') + 'Z'
polygon = voronoi.cellPolygon(i);
data[i][as] = polygon
? 'M' + polygon.join('L') + 'Z'
: null;
}

Expand Down
8 changes: 5 additions & 3 deletions packages/vega-voronoi/test/voronoi-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ var tape = require('tape'),
tape('Voronoi generates voronoi cell paths', function(t) {
var data = [
{x: 10, y: 10},
{x: 20, y: 10}
{x: 20, y: 10},
{x: 10, y: 20}
];

var x = util.field('x'),
Expand All @@ -24,7 +25,8 @@ tape('Voronoi generates voronoi cell paths', function(t) {

df.pulse(c0, changeset().insert(data)).run();
var out = vo.pulse.add;
t.equal(out[0].path, 'M15,20L15,0L0,0L0,20Z');
t.equal(out[1].path, 'M15,0L15,20L30,20L30,0Z');
t.equal(out[0].path, 'M0,0L15,0L15,15L0,15L0,0Z');
t.equal(out[1].path, 'M30,0L30,20L20,20L15,15L15,0L30,0Z');
t.equal(out[2].path, 'M0,20L0,15L15,15L20,20L0,20Z');
t.end();
});
2 changes: 1 addition & 1 deletion packages/vega/rollup.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const external = [].concat(!externals ? [] : [
'd3-time',
'd3-time-format',
'd3-timer',
'd3-voronoi',
'd3-delaunay',
'topojson-client'
]);

Expand Down
38 changes: 13 additions & 25 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1531,12 +1531,19 @@ d3-contour@^1.3.2:
dependencies:
d3-array "^1.1.1"

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==
dependencies:
delaunator "^2.0.0"

d3-dispatch@1:
version "1.0.5"
resolved "https://registry.yarnpkg.com/d3-dispatch/-/d3-dispatch-1.0.5.tgz#e25c10a186517cd6c82dd19ea018f07e01e39015"
integrity sha512-vwKx+lAqB1UuCeklr6Jh1bvC4SZgbSqbkGBLClItFBIYH4vqDJCA7qfoy14lXmJdnBOdxndAMxjCbImJYW7e6g==

d3-dsv@^1.0.10, d3-dsv@^1.1.1:
d3-dsv@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/d3-dsv/-/d3-dsv-1.1.1.tgz#aaa830ecb76c4b5015572c647cc6441e3c7bb701"
integrity sha512-1EH1oRGSkeDUlDRbhsFytAXU6cAmXFzc52YUe6MRlPClmWb85MP1J5x+YJRzya4ynZWnbELdSAvATFW/MbxaXw==
Expand Down Expand Up @@ -1642,11 +1649,6 @@ d3-timer@1, d3-timer@^1.0.9:
resolved "https://registry.yarnpkg.com/d3-timer/-/d3-timer-1.0.9.tgz#f7bb8c0d597d792ff7131e1c24a36dd471a471ba"
integrity sha512-rT34J5HnQUHhcLvhSB9GjCkN0Ddd5Y8nCwDBG2u6wQEeYxT/Lf51fTFFkldeib/sE/J0clIe0pnCfs6g/lRbyg==

d3-voronoi@^1.1.4:
version "1.1.4"
resolved "https://registry.yarnpkg.com/d3-voronoi/-/d3-voronoi-1.1.4.tgz#dd3c78d7653d2bb359284ae478645d95944c8297"
integrity sha512-dArJ32hchFsrQ8uMiTBLq256MpnZjeuBtdHpaDlYuQyjU0CVzCJl/BVW+SkszaAeH95D/8gxqAhgx0ouAWAfRg==

dargs@^4.0.1:
version "4.1.0"
resolved "https://registry.yarnpkg.com/dargs/-/dargs-4.1.0.tgz#03a9dbb4b5c2f139bf14ae53f0b8a2a6a86f4e17"
Expand Down Expand Up @@ -1799,6 +1801,11 @@ defined@~1.0.0:
"@types/parsimmon" "^1.3.0"
parsimmon "^1.2.0"

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==

delayed-stream@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
Expand Down Expand Up @@ -5529,30 +5536,11 @@ validate-npm-package-name@^3.0.0:
dependencies:
builtins "^1.0.3"

vega-dataflow@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/vega-dataflow/-/vega-dataflow-4.1.0.tgz#c63abee8502eedf42a972ad5d3a2ce7475aab7d8"
integrity sha512-LuXoN3LkYWNYTPeMiOgSlw2TZAWjmN46Q9HmHM8ClhXYAj+pYme3IPdtYn1OmcvWe4rKeiYgNYrtJCgTOvCepg==
dependencies:
vega-loader "^3.1.0"
vega-util "^1.7.0"

vega-datasets@^1.22.0:
version "1.22.0"
resolved "https://registry.yarnpkg.com/vega-datasets/-/vega-datasets-1.22.0.tgz#a839f51ec5abb70ab0687e6dbf0ecd231558c605"
integrity sha512-eeChIzCIBqn1bQY0nEzX0N7DkUEMhjF92qnjmfRfi0EkWG1sG9nGQbYKDGGOQcpVOXSFM8rEhTBTZfRvlL5KJg==

vega-loader@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/vega-loader/-/vega-loader-3.1.0.tgz#21caa0e78e158a676eafd0e7cb5bae4c18996c5a"
integrity sha512-FD9KJdPxBOa+fTnjC2dfY5+kB05hXyVOfjIkssmgyyhELJPp2FwclcF4mVy7Ay1E8fUHY3GgbwSE5jL8k4pYUg==
dependencies:
d3-dsv "^1.0.10"
d3-time-format "^2.1.3"
node-fetch "^2.3.0"
topojson-client "^3.0.0"
vega-util "^1.7.0"

verror@1.10.0:
version "1.10.0"
resolved "https://registry.yarnpkg.com/verror/-/verror-1.10.0.tgz#3a105ca17053af55d6e270c1f8288682e18da400"
Expand Down

0 comments on commit 6d76b23

Please sign in to comment.