Skip to content

Commit 05679e3

Browse files
committed
transpose cells channel
1 parent 5bc227f commit 05679e3

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/marks/delaunay.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -226,41 +226,40 @@ class Voronoi extends Mark {
226226
let {x: X, y: Y, z: Z} = channels;
227227
({x: X, y: Y} = applyPosition(channels, scales, context));
228228
Z = Z?.value;
229-
const C = new Array(data.length);
229+
const C = new Array(facets.length);
230230
const [cx, cy] = applyFrameAnchor(this, dimensions);
231231
const xi = X ? (i) => X[i] : constant(cx);
232232
const yi = Y ? (i) => Y[i] : constant(cy);
233233
for (let [fi, facet] of facets.entries()) {
234234
if (X) facet = facet.filter((i) => defined(X[i]));
235235
if (Y) facet = facet.filter((i) => defined(Y[i]));
236+
const Cf = C[fi] = [];
236237
for (const [, index] of maybeGroup(facet, Z)) {
237238
const delaunay = Delaunay.from(index, xi, yi);
238239
const voronoi = voronoiof(delaunay, dimensions);
239240
for (let i = 0, n = index.length; i < n; ++i) {
240-
const c = voronoi.renderCell(i);
241-
if (c) (C[index[i]] ||= [])[fi] = c;
241+
Cf[index[i]] = voronoi.renderCell(i);
242242
}
243243
}
244244
}
245-
return {data, facets, channels: {cells: {value: C}}};
245+
return {data, facets, channels: {cells: {value: C, filter: null}}};
246246
}),
247247
voronoiDefaults
248248
);
249249
}
250250
render(index, scales, channels, dimensions, context) {
251251
const {x, y} = scales;
252-
const {x: X, y: Y, cells: C} = channels;
253-
const fi = index.fi ?? 0;
252+
const {x: X, y: Y, cells: {[index.fi ?? 0]: C}} = channels;
254253
return create("svg:g", context)
255254
.call(applyIndirectStyles, this, dimensions, context)
256255
.call(applyTransform, this, {x: X && x, y: Y && y})
257256
.call((g) => {
258257
g.selectAll()
259-
.data(index)
258+
.data(index.filter((i) => C[i] != null))
260259
.enter()
261260
.append("path")
262261
.call(applyDirectStyles, this)
263-
.attr("d", (i) => C[i][fi])
262+
.attr("d", (i) => C[i])
264263
.call(applyChannelStyles, this, channels);
265264
})
266265
.node();

0 commit comments

Comments
 (0)