Skip to content

Commit 50d57c4

Browse files
authored
don’t filter extra unscaled channels (#1536)
1 parent 60be56d commit 50d57c4

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

src/mark.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {channelDomain, createChannels, valueObject} from "./channel.js";
22
import {defined} from "./defined.js";
33
import {maybeFacetAnchor} from "./facet.js";
4-
import {maybeValues} from "./options.js";
4+
import {maybeValue} from "./options.js";
55
import {arrayify, isDomainSort, isOptions, keyword, maybeNamed, range, singleton} from "./options.js";
66
import {project} from "./projection.js";
77
import {maybeClip, styles} from "./style.js";
@@ -39,7 +39,7 @@ export class Mark {
3939
}
4040
this.facetAnchor = maybeFacetAnchor(facetAnchor);
4141
channels = maybeNamed(channels);
42-
if (extraChannels !== undefined) channels = {...maybeValues(maybeNamed(extraChannels)), ...channels};
42+
if (extraChannels !== undefined) channels = {...maybeChannels(extraChannels), ...channels};
4343
if (defaults !== undefined) channels = {...styles(this, options, defaults), ...channels};
4444
this.channels = Object.fromEntries(
4545
Object.entries(channels)
@@ -133,3 +133,13 @@ export function marks(...marks) {
133133
marks.plot = Mark.prototype.plot; // Note: depends on side-effect in plot!
134134
return marks;
135135
}
136+
137+
function maybeChannels(channels) {
138+
return Object.fromEntries(
139+
Object.entries(maybeNamed(channels)).map(([name, channel]) => {
140+
channel = maybeValue(channel);
141+
if (channel.filter === undefined && channel.scale == null) channel = {...channel, filter: null};
142+
return [name, channel];
143+
})
144+
);
145+
}

src/marks/tip.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {select} from "d3";
22
import {getSource} from "../channel.js";
33
import {create} from "../context.js";
4+
import {defined} from "../defined.js";
45
import {formatDefault} from "../format.js";
56
import {Mark} from "../mark.js";
67
import {maybeAnchor, maybeFrameAnchor, maybeTuple, number, string} from "../options.js";
@@ -109,13 +110,15 @@ export class Tip extends Mark {
109110
if (key === "x1" && "x2" in sources) continue;
110111
if (key === "y1" && "y2" in sources) continue;
111112
const channel = sources[key];
113+
const value = channel.value[i];
114+
if (!defined(value) && channel.scale == null) continue;
112115
const color = channel.scale === "color" ? channels[key][i] : undefined;
113116
if (key === "x2" && "x1" in sources) {
114117
yield [formatLabel(scales, channel) ?? "x", formatPair(sources.x1, channel, i)];
115118
} else if (key === "y2" && "y1" in sources) {
116119
yield [formatLabel(scales, channel) ?? "y", formatPair(sources.y1, channel, i)];
117120
} else {
118-
yield [formatLabel(scales, channel) ?? key, formatDefault(channel.value[i]), color];
121+
yield [formatLabel(scales, channel) ?? key, formatDefault(value), color];
119122
}
120123
}
121124
if (index.fi != null && fx) yield [fx.label ?? "fx", formatFx(index.fx)];

src/options.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -328,15 +328,6 @@ export function maybeValue(value) {
328328
return value === undefined || isOptions(value) ? value : {value};
329329
}
330330

331-
// Like maybeValue, but for an object for values.
332-
export function maybeValues(channels) {
333-
return Object.fromEntries(
334-
Object.entries(channels).map(([name, channel]) => {
335-
return [name, maybeValue(channel)];
336-
})
337-
);
338-
}
339-
340331
// Coerces the given channel values (if any) to numbers. This is useful when
341332
// values will be interpolated into other code, such as an SVG transform, and
342333
// where we don’t wish to allow unexpected behavior for weird input.

0 commit comments

Comments
 (0)