Skip to content

Commit fc37827

Browse files
committed
optimize for the common case of 1 facet
1 parent 301de0d commit fc37827

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/facet.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {maybeFontSizeChannel} from "./marks/text.js";
44
import {maybePathChannel} from "./marks/image.js";
55

66
export function facetReindex(facets, n) {
7+
if (facets.length === 1) return {facets};
78
const overlap = new Uint8Array(n);
89
let count = 0;
910
let plan;

src/transforms/bin.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import {bin as binner, extent, thresholdFreedmanDiaconis, thresholdScott, thresholdSturges, utcTickInterval} from "d3";
1+
import {
2+
bin as binner,
3+
extent,
4+
sum,
5+
thresholdFreedmanDiaconis,
6+
thresholdScott,
7+
thresholdSturges,
8+
utcTickInterval
9+
} from "d3";
210
import {
311
valueof,
412
identity,
@@ -160,7 +168,7 @@ function binn(
160168
...("fill" in inputs && {fill: GF || fill}),
161169
...("stroke" in inputs && {stroke: GS || stroke}),
162170
...basic(options, (data, facets) => {
163-
const cover = (bx || by) && union(facets);
171+
const cover = (bx || by) && merge(facets);
164172
const K = valueof(data, k);
165173
const Z = valueof(data, z);
166174
const F = valueof(data, vfill);
@@ -366,8 +374,10 @@ function binempty() {
366374
return new Uint32Array(0);
367375
}
368376

369-
function union(facets) {
370-
const U = new Set();
371-
for (const f of facets) for (const i of f) U.add(i);
377+
function merge(facets) {
378+
if (facets.length === 1) return facets[0];
379+
const U = new Uint32Array(sum(facets, (f) => f.length));
380+
let k = 0;
381+
for (const f of facets) for (const i of f) U[k++] = i;
372382
return U;
373383
}

0 commit comments

Comments
 (0)