Skip to content

Commit ddf3db9

Browse files
authored
mark.channels is an object (#994)
* mark.channels is an object * object all the channels
1 parent 9049e81 commit ddf3db9

33 files changed

+319
-313
lines changed

src/channel.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,18 @@ export function Channel(data, {scale, type, value, filter, hint}) {
1515
};
1616
}
1717

18-
export function channelObject(channelDescriptors, data) {
19-
const channels = {};
20-
for (const channel of channelDescriptors) {
21-
channels[channel.name] = Channel(data, channel);
22-
}
23-
return channels;
18+
export function Channels(descriptors, data) {
19+
return Object.fromEntries(Object.entries(descriptors).map(([name, channel]) => {
20+
return [name, Channel(data, channel)];
21+
}));
2422
}
2523

2624
// TODO Use Float64Array for scales with numeric ranges, e.g. position?
2725
export function valueObject(channels, scales) {
28-
const values = {};
29-
for (const channelName in channels) {
30-
const {scale: scaleName, value} = channels[channelName];
26+
return Object.fromEntries(Object.entries(channels).map(([name, {scale: scaleName, value}]) => {
3127
const scale = scales[scaleName];
32-
values[channelName] = scale === undefined ? value : map(value, scale);
33-
}
34-
return values;
28+
return [name, scale === undefined ? value : map(value, scale)];
29+
}));
3530
}
3631

3732
// Note: mutates channel.domain! This is set to a function so that it is lazily

src/marks/area.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ export class Area extends Mark {
2121
const {x1, y1, x2, y2, z, curve, tension} = options;
2222
super(
2323
data,
24-
[
25-
{name: "x1", value: x1, scale: "x"},
26-
{name: "y1", value: y1, scale: "y"},
27-
{name: "x2", value: x2, scale: "x", optional: true},
28-
{name: "y2", value: y2, scale: "y", optional: true},
29-
{name: "z", value: maybeZ(options), optional: true}
30-
],
24+
{
25+
x1: {value: x1, scale: "x"},
26+
y1: {value: y1, scale: "y"},
27+
x2: {value: x2, scale: "x", optional: true},
28+
y2: {value: y2, scale: "y", optional: true},
29+
z: {value: maybeZ(options), optional: true}
30+
},
3131
options,
3232
defaults
3333
);

src/marks/arrow.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ export class Arrow extends Mark {
3030
} = options;
3131
super(
3232
data,
33-
[
34-
{name: "x1", value: x1, scale: "x"},
35-
{name: "y1", value: y1, scale: "y"},
36-
{name: "x2", value: x2, scale: "x", optional: true},
37-
{name: "y2", value: y2, scale: "y", optional: true}
38-
],
33+
{
34+
x1: {value: x1, scale: "x"},
35+
y1: {value: y1, scale: "y"},
36+
x2: {value: x2, scale: "x", optional: true},
37+
y2: {value: y2, scale: "y", optional: true}
38+
},
3939
options,
4040
defaults
4141
);

src/marks/bar.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ export class BarX extends AbstractBar {
6666
const {x1, x2, y} = options;
6767
super(
6868
data,
69-
[
70-
{name: "x1", value: x1, scale: "x"},
71-
{name: "x2", value: x2, scale: "x"},
72-
{name: "y", value: y, scale: "y", type: "band", optional: true}
73-
],
69+
{
70+
x1: {value: x1, scale: "x"},
71+
x2: {value: x2, scale: "x"},
72+
y: {value: y, scale: "y", type: "band", optional: true}
73+
},
7474
options,
7575
defaults
7676
);
@@ -93,11 +93,11 @@ export class BarY extends AbstractBar {
9393
const {x, y1, y2} = options;
9494
super(
9595
data,
96-
[
97-
{name: "y1", value: y1, scale: "y"},
98-
{name: "y2", value: y2, scale: "y"},
99-
{name: "x", value: x, scale: "x", type: "band", optional: true}
100-
],
96+
{
97+
y1: {value: y1, scale: "y"},
98+
y2: {value: y2, scale: "y"},
99+
x: {value: x, scale: "x", type: "band", optional: true}
100+
},
101101
options,
102102
defaults
103103
);

src/marks/cell.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ export class Cell extends AbstractBar {
1010
constructor(data, {x, y, ...options} = {}) {
1111
super(
1212
data,
13-
[
14-
{name: "x", value: x, scale: "x", type: "band", optional: true},
15-
{name: "y", value: y, scale: "y", type: "band", optional: true}
16-
],
13+
{
14+
x: {value: x, scale: "x", type: "band", optional: true},
15+
y: {value: y, scale: "y", type: "band", optional: true}
16+
},
1717
options,
1818
defaults
1919
);

src/marks/delaunay.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ class DelaunayLink extends Mark {
4747
const {x, y, z, curve, tension} = options;
4848
super(
4949
data,
50-
[
51-
{name: "x", value: x, scale: "x", optional: true},
52-
{name: "y", value: y, scale: "y", optional: true},
53-
{name: "z", value: z, optional: true}
54-
],
50+
{
51+
x: {value: x, scale: "x", optional: true},
52+
y: {value: y, scale: "y", optional: true},
53+
z: {value: z, optional: true}
54+
},
5555
options,
5656
delaunayLinkDefaults
5757
);
@@ -129,11 +129,11 @@ class AbstractDelaunayMark extends Mark {
129129
const {x, y} = options;
130130
super(
131131
data,
132-
[
133-
{name: "x", value: x, scale: "x", optional: true},
134-
{name: "y", value: y, scale: "y", optional: true},
135-
{name: "z", value: zof(options), optional: true}
136-
],
132+
{
133+
x: {value: x, scale: "x", optional: true},
134+
y: {value: y, scale: "y", optional: true},
135+
z: {value: zof(options), optional: true}
136+
},
137137
options,
138138
defaults
139139
);
@@ -188,11 +188,11 @@ class Voronoi extends Mark {
188188
const {x, y, z} = options;
189189
super(
190190
data,
191-
[
192-
{name: "x", value: x, scale: "x", optional: true},
193-
{name: "y", value: y, scale: "y", optional: true},
194-
{name: "z", value: z, optional: true}
195-
],
191+
{
192+
x: {value: x, scale: "x", optional: true},
193+
y: {value: y, scale: "y", optional: true},
194+
z: {value: z, optional: true}
195+
},
196196
options,
197197
voronoiDefaults
198198
);

src/marks/density.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ export class Density extends Mark {
2222
const strokeDensity = isDensity(stroke) && (stroke = "currentColor", true);
2323
super(
2424
data,
25-
[
26-
{name: "x", value: x, scale: "x", optional: true},
27-
{name: "y", value: y, scale: "y", optional: true},
28-
{name: "z", value: maybeZ({z, fill, stroke}), optional: true},
29-
{name: "weight", value: weight, optional: true}
30-
],
25+
{
26+
x: {value: x, scale: "x", optional: true},
27+
y: {value: y, scale: "y", optional: true},
28+
z: {value: maybeZ({z, fill, stroke}), optional: true},
29+
weight: {value: weight, optional: true}
30+
},
3131
densityInitializer({...options, fill, stroke}, fillDensity, strokeDensity),
3232
defaults
3333
);

src/marks/dot.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ export class Dot extends Mark {
2323
const [vr, cr] = maybeNumberChannel(r, vsymbol == null ? 3 : 4.5);
2424
super(
2525
data,
26-
[
27-
{name: "x", value: x, scale: "x", optional: true},
28-
{name: "y", value: y, scale: "y", optional: true},
29-
{name: "r", value: vr, scale: "r", filter: positive, optional: true},
30-
{name: "rotate", value: vrotate, optional: true},
31-
{name: "symbol", value: vsymbol, scale: "symbol", optional: true}
32-
],
26+
{
27+
x: {value: x, scale: "x", optional: true},
28+
y: {value: y, scale: "y", optional: true},
29+
r: {value: vr, scale: "r", filter: positive, optional: true},
30+
rotate: {value: vrotate, optional: true},
31+
symbol: {value: vsymbol, scale: "symbol", optional: true}
32+
},
3333
options.sort === undefined && options.reverse === undefined ? sort({channel: "r", order: "descending"}, options) : options,
3434
defaults
3535
);
@@ -42,10 +42,9 @@ export class Dot extends Mark {
4242
// appropriate default symbols based on whether the dots are filled or
4343
// stroked, and for the symbol legend to match the appearance of the dots.
4444
const {channels} = this;
45-
const symbolChannel = channels.find(({scale}) => scale === "symbol");
45+
const {symbol: symbolChannel} = channels;
4646
if (symbolChannel) {
47-
const fillChannel = channels.find(({name}) => name === "fill");
48-
const strokeChannel = channels.find(({name}) => name === "stroke");
47+
const {fill: fillChannel, stroke: strokeChannel} = channels;
4948
symbolChannel.hint = {
5049
fill: fillChannel ? (fillChannel.value === symbolChannel.value ? "color" : "currentColor") : this.fill,
5150
stroke: strokeChannel ? (strokeChannel.value === symbolChannel.value ? "color" : "currentColor") : this.stroke

src/marks/image.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ export class Image extends Mark {
4242
const [vh, ch] = maybeNumberChannel(height, 16);
4343
super(
4444
data,
45-
[
46-
{name: "x", value: x, scale: "x", optional: true},
47-
{name: "y", value: y, scale: "y", optional: true},
48-
{name: "width", value: vw, filter: positive, optional: true},
49-
{name: "height", value: vh, filter: positive, optional: true},
50-
{name: "src", value: vs, optional: true}
51-
],
45+
{
46+
x: {value: x, scale: "x", optional: true},
47+
y: {value: y, scale: "y", optional: true},
48+
width: {value: vw, filter: positive, optional: true},
49+
height: {value: vh, filter: positive, optional: true},
50+
src: {value: vs, optional: true}
51+
},
5252
options,
5353
defaults
5454
);

src/marks/line.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ export class Line extends Mark {
2222
const {x, y, z, curve, tension} = options;
2323
super(
2424
data,
25-
[
26-
{name: "x", value: x, scale: "x"},
27-
{name: "y", value: y, scale: "y"},
28-
{name: "z", value: maybeZ(options), optional: true}
29-
],
25+
{
26+
x: {value: x, scale: "x"},
27+
y: {value: y, scale: "y"},
28+
z: {value: maybeZ(options), optional: true}
29+
},
3030
options,
3131
defaults
3232
);

0 commit comments

Comments
 (0)