-
Notifications
You must be signed in to change notification settings - Fork 219
Expand file tree
/
Copy pathcell-test.js
More file actions
128 lines (117 loc) · 4.23 KB
/
cell-test.js
File metadata and controls
128 lines (117 loc) · 4.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import {assert, it} from "vitest";
import * as Plot from "@observablehq/plot";
it("cell() has the expected defaults", () => {
const cell = Plot.cell();
assert.strictEqual(cell.data, undefined);
assert.strictEqual(cell.transform, undefined);
assert.deepStrictEqual(Object.keys(cell.channels), ["x", "y"]);
assert.deepStrictEqual(
Object.values(cell.channels).map((c) =>
Plot.valueof(
[
[1, 2],
[3, 4]
],
c.value
)
),
[
[1, 3],
[2, 4]
]
);
assert.deepStrictEqual(
Object.values(cell.channels).map((c) => c.scale),
["x", "y"]
);
assert.strictEqual(cell.channels.x.type, "band");
assert.strictEqual(cell.channels.y.type, "band");
assert.strictEqual(cell.fill, undefined);
assert.strictEqual(cell.fillOpacity, undefined);
assert.strictEqual(cell.stroke, undefined);
assert.strictEqual(cell.strokeWidth, undefined);
assert.strictEqual(cell.strokeOpacity, undefined);
assert.strictEqual(cell.strokeLinejoin, undefined);
assert.strictEqual(cell.strokeLinecap, undefined);
assert.strictEqual(cell.strokeMiterlimit, undefined);
assert.strictEqual(cell.strokeDasharray, undefined);
assert.strictEqual(cell.strokeDashoffset, undefined);
assert.strictEqual(cell.mixBlendMode, undefined);
assert.strictEqual(cell.shapeRendering, undefined);
assert.strictEqual(cell.insetTop, 0);
assert.strictEqual(cell.insetRight, 0);
assert.strictEqual(cell.insetBottom, 0);
assert.strictEqual(cell.insetLeft, 0);
});
it("cell(data, {title}) specifies an optional title channel", () => {
const cell = Plot.cell(undefined, {title: "x"});
const {title} = cell.channels;
assert.strictEqual(title.value, "x");
assert.strictEqual(title.scale, undefined);
});
it("cell(data, {fill}) allows fill to be a constant color", () => {
const cell = Plot.cell(undefined, {fill: "red"});
assert.strictEqual(cell.fill, "red");
});
it("cell(data, {fill}) allows fill to be null", () => {
const cell = Plot.cell(undefined, {fill: null});
assert.strictEqual(cell.fill, "none");
});
it("cell(data, {fill}) allows fill to be a variable color", () => {
const cell = Plot.cell(undefined, {fill: "x"});
assert.strictEqual(cell.fill, undefined);
const {fill} = cell.channels;
assert.strictEqual(fill.value, "x");
assert.strictEqual(fill.scale, "auto");
});
it("cell(data, {stroke}) allows stroke to be a constant color", () => {
const cell = Plot.cell(undefined, {stroke: "red"});
assert.strictEqual(cell.stroke, "red");
});
it("cell(data, {stroke}) allows stroke to be null", () => {
const cell = Plot.cell(undefined, {stroke: null});
assert.strictEqual(cell.stroke, undefined);
});
it("cell(data, {stroke}) allows stroke to be a variable color", () => {
const cell = Plot.cell(undefined, {stroke: "x"});
assert.strictEqual(cell.stroke, undefined);
const {stroke} = cell.channels;
assert.strictEqual(stroke.value, "x");
assert.strictEqual(stroke.scale, "auto");
});
it("cellX() defaults x to identity and y to null", () => {
const cell = Plot.cellX();
assert.strictEqual(cell.data, undefined);
assert.strictEqual(cell.transform, undefined);
assert.deepStrictEqual(Object.keys(cell.channels), ["fill", "x"]);
assert.deepStrictEqual(
Object.values(cell.channels).map((c) => Plot.valueof([1, 2, 3], c.value)),
[[1, 2, 3], Uint32Array.of(0, 1, 2)]
);
assert.deepStrictEqual(
Object.values(cell.channels).map((c) => c.scale),
["auto", "x"]
);
assert.strictEqual(cell.channels.x.type, "band");
});
it("cellY() defaults y to identity and x to null", () => {
const cell = Plot.cellY();
assert.strictEqual(cell.data, undefined);
assert.strictEqual(cell.transform, undefined);
assert.deepStrictEqual(Object.keys(cell.channels), ["fill", "y"]);
assert.deepStrictEqual(
Object.values(cell.channels).map((c) => Plot.valueof([1, 2, 3], c.value)),
[[1, 2, 3], Uint32Array.of(0, 1, 2)]
);
assert.deepStrictEqual(
Object.values(cell.channels).map((c) => c.scale),
["auto", "y"]
);
assert.strictEqual(cell.channels.y.type, "band");
});
it("cell() is incompatible with a projection", () => {
assert.throws(
() => Plot.cell([]).plot({projection: "equal-earth"}),
/scale incompatible with channel: projection !== band/
);
});