Skip to content

Commit 4faebbc

Browse files
committed
a few more dataify
1 parent b652131 commit 4faebbc

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

src/mark.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {channelDomain, createChannels, valueObject} from "./channel.js";
22
import {defined} from "./defined.js";
33
import {maybeFacetAnchor} from "./facet.js";
44
import {maybeClip, maybeNamed, maybeValue} from "./options.js";
5-
import {arrayify, isArrowTable, isDomainSort, isObject, isOptions, keyword, range, singleton} from "./options.js";
5+
import {dataify, isDomainSort, isObject, isOptions, keyword, range, singleton} from "./options.js";
66
import {project} from "./projection.js";
77
import {styles} from "./style.js";
88
import {basic, initializer} from "./transforms/basic.js";
@@ -130,10 +130,6 @@ export class Mark {
130130
}
131131
}
132132

133-
function dataify(data) {
134-
return isArrowTable(data) ? data : arrayify(data);
135-
}
136-
137133
export function marks(...marks) {
138134
marks.plot = Mark.prototype.plot;
139135
return marks;

src/options.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,11 @@ export function keyword(input, name, allowed) {
156156
return i;
157157
}
158158

159+
// Like arrayify, but also allows data to be an Apache Arrow Table.
160+
export function dataify(data) {
161+
return isArrowTable(data) ? data : arrayify(data);
162+
}
163+
159164
// Promotes the specified data to an array as needed.
160165
export function arrayify(values) {
161166
if (values == null || isArray(values)) return values;
@@ -261,7 +266,7 @@ export function maybeZ({z, fill, stroke} = {}) {
261266
}
262267

263268
export function lengthof(data) {
264-
return isArray(data) ? data.length : data.numRows;
269+
return isArray(data) ? data.length : data?.numRows;
265270
}
266271

267272
// Returns a Uint32Array with elements [0, 1, 2, … data.length - 1].

src/plot.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {axisFx, axisFy, axisX, axisY, gridFx, gridFy, gridX, gridY} from "./mark
1010
import {frame} from "./marks/frame.js";
1111
import {tip} from "./marks/tip.js";
1212
import {isColor, isIterable, isNone, isScaleOptions} from "./options.js";
13-
import {arrayify, map, yes, maybeIntervalTransform, subarray} from "./options.js";
13+
import {dataify, lengthof, map, yes, maybeIntervalTransform, subarray} from "./options.js";
1414
import {createProjection, getGeometryChannels, hasProjection} from "./projection.js";
1515
import {createScales, createScaleFunctions, autoScaleRange, exposeScales} from "./scales.js";
1616
import {innerDimensions, outerDimensions} from "./scales.js";
@@ -459,7 +459,7 @@ function maybeTopFacet(facet, options) {
459459
if (facet == null) return;
460460
const {x, y} = facet;
461461
if (x == null && y == null) return;
462-
const data = arrayify(facet.data);
462+
const data = dataify(facet.data);
463463
if (data == null) throw new Error("missing facet data");
464464
const channels = {};
465465
if (x != null) channels.fx = createChannel(data, {value: x, scale: "fx"});
@@ -478,7 +478,7 @@ function maybeMarkFacet(mark, topFacetState, options) {
478478
// here with maybeTopFacet that we could reduce.
479479
const {fx, fy} = mark;
480480
if (fx != null || fy != null) {
481-
const data = arrayify(mark.data ?? fx ?? fy);
481+
const data = dataify(mark.data ?? fx ?? fy);
482482
if (data === undefined) throw new Error(`missing facet data in ${mark.ariaLabel}`);
483483
if (data === null) return; // ignore channel definitions if no data is provided TODO this right?
484484
const channels = {};
@@ -500,7 +500,7 @@ function maybeMarkFacet(mark, topFacetState, options) {
500500
if (
501501
data.length > 0 &&
502502
(groups.size > 1 || (groups.size === 1 && channels.fx && channels.fy && [...groups][0][1].size > 1)) &&
503-
arrayify(mark.data)?.length === data.length
503+
lengthof(dataify(mark.data)) === lengthof(data)
504504
) {
505505
warn(
506506
`Warning: the ${mark.ariaLabel} mark appears to use faceted data, but isn’t faceted. The mark data has the same length as the facet data and the mark facet option is "auto", but the mark data and facet data are distinct. If this mark should be faceted, set the mark facet option to true; otherwise, suppress this warning by setting the mark facet option to false.`

src/transforms/basic.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {randomLcg} from "d3";
22
import {ascendingDefined, descendingDefined} from "../defined.js";
3-
import {arrayify, isDomainSort, isOptions, maybeValue, valueof} from "../options.js";
3+
import {dataify, isDomainSort, isOptions, maybeValue, valueof} from "../options.js";
44

55
export function basic({filter: f1, sort: s1, reverse: r1, transform: t1, initializer: i1, ...options} = {}, transform) {
66
// If both t1 and t2 are defined, returns a composite transform that first
@@ -40,7 +40,7 @@ function composeTransform(t1, t2) {
4040
if (t2 == null) return t1 === null ? undefined : t1;
4141
return function (data, facets, plotOptions) {
4242
({data, facets} = t1.call(this, data, facets, plotOptions));
43-
return t2.call(this, arrayify(data), facets, plotOptions);
43+
return t2.call(this, dataify(data), facets, plotOptions);
4444
};
4545
}
4646

0 commit comments

Comments
 (0)