Skip to content

Commit bfc5e87

Browse files
committed
warn on high-cardinality implicit z
1 parent 5c0001c commit bfc5e87

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

src/marks/area.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const defaults = {
1717

1818
export class Area extends Mark {
1919
constructor(data, options = {}) {
20-
const {x1, y1, x2, y2, curve, tension} = options;
20+
const {x1, y1, x2, y2, z, curve, tension} = options;
2121
super(
2222
data,
2323
[
@@ -30,6 +30,7 @@ export class Area extends Mark {
3030
options,
3131
defaults
3232
);
33+
this.z = z;
3334
this.curve = Curve(curve, tension);
3435
}
3536
render(I, {x, y}, channels, dimensions) {
@@ -39,7 +40,7 @@ export class Area extends Mark {
3940
.call(applyIndirectStyles, this, dimensions)
4041
.call(applyTransform, x, y, dx, dy)
4142
.call(g => g.selectAll()
42-
.data(groupIndex(I, [X1, Y1, X2, Y2], channels))
43+
.data(groupIndex(I, [X1, Y1, X2, Y2], this, channels))
4344
.join("path")
4445
.call(applyDirectStyles, this)
4546
.call(applyGroupedChannelStyles, this, channels)

src/marks/line.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const defaults = {
1818

1919
export class Line extends Mark {
2020
constructor(data, options = {}) {
21-
const {x, y, curve, tension} = options;
21+
const {x, y, z, curve, tension} = options;
2222
super(
2323
data,
2424
[
@@ -29,6 +29,7 @@ export class Line extends Mark {
2929
options,
3030
defaults
3131
);
32+
this.z = z;
3233
this.curve = Curve(curve, tension);
3334
markers(this, options);
3435
}
@@ -39,7 +40,7 @@ export class Line extends Mark {
3940
.call(applyIndirectStyles, this, dimensions)
4041
.call(applyTransform, x, y, offset + dx, offset + dy)
4142
.call(g => g.selectAll()
42-
.data(groupIndex(I, [X, Y], channels))
43+
.data(groupIndex(I, [X, Y], this, channels))
4344
.join("path")
4445
.call(applyDirectStyles, this)
4546
.call(applyGroupedChannelStyles, this, channels)

src/style.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {group, isoFormat, namespaces} from "d3";
22
import {defined, nonempty} from "./defined.js";
33
import {formatNumber} from "./format.js";
44
import {string, number, maybeColorChannel, maybeNumberChannel, isTemporal, isNumeric, isNoneish, isNone, isRound, keyof} from "./options.js";
5+
import {warn} from "./warnings.js";
56

67
export const offset = typeof window !== "undefined" && window.devicePixelRatio > 1 ? 0 : 0.5;
78

@@ -183,13 +184,21 @@ function groupAesthetics({ariaLabel: AL, title: T, fill: F, fillOpacity: FO, str
183184
return [AL, T, F, FO, S, SO, SW, O, H].filter(c => c !== undefined);
184185
}
185186

186-
export function* groupIndex(I, position, channels) {
187+
function groupZ(I, Z, z) {
188+
const G = group(I, i => Z[i]);
189+
if (z === undefined && G.size >= I.length >> 2) {
190+
warn(`Warning: the implicit z channel has high cardinality. This may occur when the fill or stroke channel is associated with quantitative data rather than ordinal or categorical data. You can suppress this warning by setting the z option explicitly; if this data represents a single series, set z to null.`);
191+
}
192+
return G.values();
193+
}
194+
195+
export function* groupIndex(I, position, {z}, channels) {
187196
const {z: Z} = channels; // group channel
188197
const A = groupAesthetics(channels); // aesthetic channels
189198
const C = [...position, ...A]; // all channels
190199

191200
// Group the current index by Z (if any).
192-
for (const G of Z ? group(I, i => Z[i]).values() : [I]) {
201+
for (const G of Z ? groupZ(I, Z, z) : [I]) {
193202
let Ag; // the A-values (aesthetics) of the current group, if any
194203
let Gg; // the current group index (a subset of G, and I), if any
195204
out: for (const i of G) {

0 commit comments

Comments
 (0)