From 972558cdee4fcfb1f04e20411664f92006a93940 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Rivi=C3=A8re?= Date: Mon, 21 Aug 2023 10:22:53 +0200 Subject: [PATCH] voronoi mark + reindexed facets --- src/marks/delaunay.js | 4 +- test/output/penguinCulmenVoronoiExclude.svg | 1161 +++++++++++++++++++ test/plots/penguin-culmen-voronoi.ts | 25 + 3 files changed, 1189 insertions(+), 1 deletion(-) create mode 100644 test/output/penguinCulmenVoronoiExclude.svg diff --git a/src/marks/delaunay.js b/src/marks/delaunay.js index 3e07113861..f0427cfa2d 100644 --- a/src/marks/delaunay.js +++ b/src/marks/delaunay.js @@ -8,7 +8,8 @@ import {constant, maybeTuple, maybeZ} from "../options.js"; import {applyPosition} from "../projection.js"; import {applyFrameAnchor, applyTransform} from "../style.js"; import {applyChannelStyles, applyDirectStyles, applyIndirectStyles} from "../style.js"; -import {initializer} from "../transforms/basic.js"; +import {basic, initializer} from "../transforms/basic.js"; +import {exclusiveFacets} from "../transforms/exclusiveFacets.js"; import {maybeGroup} from "../transforms/group.js"; const delaunayLinkDefaults = { @@ -296,6 +297,7 @@ export function hull(data, options) { } export function voronoi(data, options) { + options = basic(options, (data, facets) => exclusiveFacets(data, facets)); return delaunayMark(Voronoi, data, options); } diff --git a/test/output/penguinCulmenVoronoiExclude.svg b/test/output/penguinCulmenVoronoiExclude.svg new file mode 100644 index 0000000000..ef999af5d9 --- /dev/null +++ b/test/output/penguinCulmenVoronoiExclude.svg @@ -0,0 +1,1161 @@ + + + + + Adelie + + + Chinstrap + + + Gentoo + + + + species + + + + + + + + + + + + + + + + + + + + + 34 + 36 + 38 + 40 + 42 + 44 + 46 + 48 + 50 + 52 + 54 + 56 + 58 + + + + ↑ culmen_length_mm + + + + + + + + + + + + + + + + + + 15 + 20 + + + 15 + 20 + + + 15 + 20 + + + + culmen_depth_mm → + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/plots/penguin-culmen-voronoi.ts b/test/plots/penguin-culmen-voronoi.ts index 6c3d46e0b8..4f3bd165a5 100644 --- a/test/plots/penguin-culmen-voronoi.ts +++ b/test/plots/penguin-culmen-voronoi.ts @@ -10,3 +10,28 @@ export async function penguinCulmenVoronoi() { ] }); } + +export async function penguinCulmenVoronoiExclude() { + const penguins = await d3.csv("data/penguins.csv", d3.autoType); + const xy = {fx: "species", x: "culmen_depth_mm", y: "culmen_length_mm"}; + return Plot.plot({ + inset: 10, + marks: [ + Plot.frame(), + Plot.dot(penguins, {...xy, facet: "exclude", fill: "currentColor", r: 1.5}), + Plot.dot(penguins, {...xy, facet: "include", fillOpacity: 0.25, fill: "currentColor", r: 1.5}), + Plot.voronoiMesh(penguins, {...xy, facet: "exclude"}), + Plot.voronoi( + penguins, + Plot.pointer({ + ...xy, + facet: "exclude", + stroke: "species", + fill: "species", + fillOpacity: 0.2, + maxRadius: Infinity + }) + ) + ] + }); +}