|
9 | 9 | ascending |
10 | 10 | } from "d3"; |
11 | 11 | import {composeRender, Mark} from "../mark.js"; |
12 | | -import {dataify, identity, isIterable, keyword, maybeInterval, maybeTuple, take} from "../options.js"; |
| 12 | +import {constant, dataify, identity, isIterable, keyword, maybeInterval, maybeTuple, take} from "../options.js"; |
13 | 13 | import {applyAttr} from "../style.js"; |
14 | 14 |
|
15 | 15 | const defaults = {ariaLabel: "brush", fill: "#777", fillOpacity: 0.3, stroke: "#fff"}; |
@@ -319,12 +319,25 @@ function renderFilter(initialTest, channelDefaults = {}) { |
319 | 319 | const {x: X, y: Y, x1: X1, x2: X2, y1: Y1, y2: Y2} = values; |
320 | 320 | const MX = X ?? (X1 && X2 ? Float64Array.from(X1, (v, i) => (v + X2[i]) / 2) : undefined); |
321 | 321 | const MY = Y ?? (Y1 && Y2 ? Float64Array.from(Y1, (v, i) => (v + Y2[i]) / 2) : undefined); |
322 | | - const filter = (test) => |
323 | | - typeof test === "function" ? index.filter((i) => test(MX?.[i], MY?.[i])) : test ? index : []; |
324 | | - let g = next(filter(initialTest), scales, values, dimensions, context); |
| 322 | + const render = (test) => { |
| 323 | + if (typeof test !== "function") test = constant(test); |
| 324 | + let run = []; |
| 325 | + const runs = [run]; |
| 326 | + for (const i of index) { |
| 327 | + if (test(MX?.[i], MY?.[i])) run.push(i); |
| 328 | + else if (run.length) runs.push((run = [])); |
| 329 | + } |
| 330 | + const g = next(runs[0], scales, values, dimensions, context); |
| 331 | + for (const run of runs.slice(1)) { |
| 332 | + const h = next(run, scales, values, dimensions, context); |
| 333 | + while (h.firstChild) g.appendChild(h.firstChild); |
| 334 | + } |
| 335 | + return g; |
| 336 | + }; |
| 337 | + let g = render(initialTest); |
325 | 338 | updatePerFacet.push((test) => { |
326 | 339 | const transform = g.getAttribute("transform"); |
327 | | - g.replaceWith((g = next(filter(test), scales, values, dimensions, context))); |
| 340 | + g.replaceWith((g = render(test))); |
328 | 341 | if (transform) g.setAttribute("transform", transform); |
329 | 342 | }); |
330 | 343 | return g; |
|
0 commit comments