Skip to content

Commit 42ac4f0

Browse files
committed
pass data to initializer
1 parent bca32ba commit 42ac4f0

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

src/plot.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ export function plot(options = {}) {
7575
: mark.facet === "include" ? facetsIndex
7676
: mark.facet === "exclude" ? facetsExclude || (facetsExclude = facetsIndex.map(f => Uint32Array.from(difference(facetIndex, f))))
7777
: undefined;
78-
const {facets, channels} = mark.initialize(markFacets, facetChannels);
78+
const {data, facets, channels} = mark.initialize(markFacets, facetChannels);
7979
applyScaleTransforms(channels, options);
80-
stateByMark.set(mark, {facets, channels});
80+
stateByMark.set(mark, {data, facets, channels});
8181
}
8282

8383
// Initalize the scales and axes.
@@ -94,7 +94,7 @@ export function plot(options = {}) {
9494
const newByScale = new Set();
9595
for (const [mark, state] of stateByMark) {
9696
if (mark.reinitialize != null) {
97-
const {facets, channels} = mark.reinitialize(state.facets, state.channels, scales);
97+
const {facets, channels} = mark.reinitialize(state.data, state.facets, state.channels, scales);
9898
if (facets !== undefined) state.facets = facets;
9999
if (channels !== undefined) {
100100
inferChannelScale(channels, mark);
@@ -278,7 +278,7 @@ export class Mark {
278278
if (this.transform != null) ({facets, data} = this.transform(data, facets)), data = arrayify(data);
279279
const channels = channelObject(this.channels, data);
280280
if (this.sort != null) channelSort(channels, facetChannels, data, this.sort);
281-
return {facets, channels};
281+
return {data, facets, channels};
282282
}
283283
filter(index, channels, values) {
284284
for (const name in channels) {

src/transforms/hexbin.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {hexbin as Hexbin} from "d3-hexbin"; // TODO inline
22
import {sqrt4_3} from "../symbols.js";
3-
import {basic} from "./basic.js";
43
import {hasOutput, maybeOutputs} from "./group.js";
54

65
export function hexbin(outputs = {fill: "count"}, options = {}) {
@@ -19,11 +18,8 @@ function hexbinn(outputs, {radius = 10, ...options}) {
1918
symbol: "hexagon",
2019
...!hasOutput(outputs, "r") && {r: radius},
2120
...hasOutput(outputs, "fill") && {stroke: "none"},
22-
...basic(options, (data, facets) => {
23-
for (const o of outputs) o.initialize(data);
24-
return {data, facets};
25-
}),
26-
initialize(facets, {x: X, y: Y}, {x, y}) {
21+
...options,
22+
initialize(data, facets, {x: X, y: Y}, {x, y}) {
2723
if (X === undefined) throw new Error("missing channel: x");
2824
if (Y === undefined) throw new Error("missing channel: y");
2925
({value: X} = X);
@@ -33,6 +29,7 @@ function hexbinn(outputs, {radius = 10, ...options}) {
3329
const BX = [];
3430
const BY = [];
3531
let i = 0;
32+
for (const o of outputs) o.initialize(data);
3633
for (const facet of facets) {
3734
const binFacet = [];
3835
for (const o of outputs) o.scope("facet", facet);

0 commit comments

Comments
 (0)