Skip to content

Commit 4f71fc0

Browse files
committed
mark scale map
1 parent f2456dc commit 4f71fc0

5 files changed

Lines changed: 911 additions & 902 deletions

File tree

src/channel.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ import {isSymbol, maybeSymbol} from "./symbols.js";
55
import {maybeReduce} from "./transforms/group.js";
66

77
// TODO Type coercion?
8-
export function Channel(data, {scale, type, value, filter, hint}) {
8+
export function Channel(data, {scale, type, value, filter, hint}, scaleOverride) {
99
let V = valueof(data, value);
1010

11-
// For color and symbol scales, allow the channel to opt-out of the scale by
12-
// providing literal values. In the case of symbols, we must further promote
13-
// symbol names (e.g., "plus") to a symbol instance (symbolPlus).
14-
if (V) {
11+
// For color and symbol scales, if a scale is not explicitly overridden,
12+
// ignore the channel’s default scale if the channel values are literal. In
13+
// the case of symbols, we must further promote symbol names (e.g., "plus") to
14+
// a symbol instance (symbolPlus).
15+
if (scaleOverride !== undefined) {
16+
scale = scaleOverride;
17+
} else if (V) {
1518
const is = scale === "color" ? isColor : scale === "symbol" ? isSymbol : null;
1619
if (is && isFirst(V, is) && isEvery(V, is)) {
1720
if (is === isSymbol) V = map(V, maybeSymbol);
@@ -29,18 +32,20 @@ export function Channel(data, {scale, type, value, filter, hint}) {
2932
};
3033
}
3134

32-
export function Channels(descriptors, data) {
33-
return Object.fromEntries(Object.entries(descriptors).map(([name, channel]) => [name, Channel(data, channel)]));
35+
export function Channels(channels, data, scales) {
36+
return Object.fromEntries(
37+
Object.entries(channels).map(([name, channel]) => {
38+
return [name, Channel(data, channel, scales?.[name])];
39+
})
40+
);
3441
}
3542

3643
// TODO Use Float64Array for scales with numeric ranges, e.g. position?
3744
export function valueObject(channels, scales) {
3845
return Object.fromEntries(
3946
Object.entries(channels).map(([name, {scale: scaleName, value}]) => {
4047
let scale;
41-
if (scaleName !== undefined) {
42-
scale = scales[scaleName];
43-
}
48+
if (scaleName != null) scale = scales[scaleName];
4449
return [name, scale === undefined ? value : map(value, scale)];
4550
})
4651
);

src/mark.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ export class Mark {
2323
marginBottom = margin,
2424
marginLeft = margin,
2525
clip,
26-
channels: extraChannels
26+
channels: extraChannels,
27+
scale
2728
} = options;
2829
this.data = data;
2930
this.sort = isDomainSort(sort) ? sort : null;
@@ -54,6 +55,7 @@ export class Mark {
5455
this.marginBottom = +marginBottom;
5556
this.marginLeft = +marginLeft;
5657
this.clip = maybeClip(clip);
58+
this.scales = scale;
5759
// Super-faceting currently disallow position channels; in the future, we
5860
// could allow position to be specified in fx and fy in addition to (or
5961
// instead of) x and y.
@@ -70,7 +72,7 @@ export class Mark {
7072
let data = arrayify(this.data);
7173
if (facets === undefined && data != null) facets = [range(data)];
7274
if (this.transform != null) ({facets, data} = this.transform(data, facets)), (data = arrayify(data));
73-
const channels = Channels(this.channels, data);
75+
const channels = Channels(this.channels, data, this.scales);
7476
if (this.sort != null) channelDomain(channels, facetChannels, data, this.sort); // mutates facetChannels!
7577
return {data, facets, channels};
7678
}

src/marks/contour.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ function contourGeometry({thresholds, interval, ...options}) {
174174
return {
175175
data: contourData,
176176
facets: contourFacets,
177-
channels: Channels(this.contourChannels, contourData)
177+
channels: Channels(this.contourChannels, contourData, this.scales)
178178
};
179179
});
180180
}

0 commit comments

Comments
 (0)