-
Notifications
You must be signed in to change notification settings - Fork 230
Expand file tree
/
Copy pathdot-test.js
More file actions
113 lines (100 loc) · 3.74 KB
/
Copy pathdot-test.js
File metadata and controls
113 lines (100 loc) · 3.74 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
import * as Plot from "@observablehq/plot";
import assert from "assert";
it("dot() has the expected defaults", () => {
const dot = Plot.dot();
assert.strictEqual(dot.data, undefined);
assert.strictEqual(dot.transform, undefined);
assert.deepStrictEqual(Object.keys(dot.channels), ["x", "y"]);
assert.deepStrictEqual(
Object.values(dot.channels).map((c) =>
Plot.valueof(
[
[1, 2],
[3, 4]
],
c.value
)
),
[
[1, 3],
[2, 4]
]
);
assert.deepStrictEqual(
Object.values(dot.channels).map((c) => c.scale),
["x", "y"]
);
assert.strictEqual(dot.r, 3);
assert.strictEqual(dot.fill, "none");
assert.strictEqual(dot.fillOpacity, undefined);
assert.strictEqual(dot.stroke, "currentColor");
assert.strictEqual(dot.strokeWidth, 1.5);
assert.strictEqual(dot.strokeOpacity, undefined);
assert.strictEqual(dot.strokeLinejoin, undefined);
assert.strictEqual(dot.strokeLinecap, undefined);
assert.strictEqual(dot.strokeMiterlimit, undefined);
assert.strictEqual(dot.strokeDasharray, undefined);
assert.strictEqual(dot.strokeDashoffset, undefined);
assert.strictEqual(dot.mixBlendMode, undefined);
assert.strictEqual(dot.shapeRendering, undefined);
});
it("dot accepts undefined data", () => {
Plot.dot({length: 1}).initialize();
});
it("dot(data, {r}) allows r to be a constant radius", () => {
const dot = Plot.dot(undefined, {r: 42});
assert.strictEqual(dot.r, 42);
});
it("dot(data, {r}) allows r to be a variable radius", () => {
const dot = Plot.dot(undefined, {r: "x"});
assert.strictEqual(dot.r, undefined);
const {r} = dot.channels;
assert.strictEqual(r.value, "x");
assert.strictEqual(r.scale, "r");
});
it("dot(data, {title}) specifies an optional title channel", () => {
const dot = Plot.dot(undefined, {title: "x"});
const {title} = dot.channels;
assert.strictEqual(title.value, "x");
assert.strictEqual(title.scale, undefined);
});
it("dot(data, {fill}) allows fill to be a constant color", () => {
const dot = Plot.dot(undefined, {fill: "red"});
assert.strictEqual(dot.fill, "red");
});
it("dot(data, {fill}) allows fill to be null", () => {
const dot = Plot.dot(undefined, {fill: null});
assert.strictEqual(dot.fill, "none");
});
it("dot(data, {fill}) allows fill to be a variable color", () => {
const dot = Plot.dot(undefined, {fill: "x"});
assert.strictEqual(dot.fill, undefined);
const {fill} = dot.channels;
assert.strictEqual(fill.value, "x");
assert.strictEqual(fill.scale, "auto");
});
it("dot(data, {fill}) defaults stroke to undefined if fill is not none", () => {
assert.strictEqual(Plot.dot(undefined, {fill: "red"}).stroke, undefined);
assert.strictEqual(Plot.dot(undefined, {fill: "x"}).stroke, undefined);
assert.strictEqual(Plot.dot(undefined, {fill: "none"}).stroke, "currentColor");
});
it("dot(data, {stroke}) allows stroke to be a constant color", () => {
const dot = Plot.dot(undefined, {stroke: "red"});
assert.strictEqual(dot.stroke, "red");
});
it("dot(data, {stroke}) allows stroke to be null", () => {
const dot = Plot.dot(undefined, {stroke: null});
assert.strictEqual(dot.stroke, undefined);
});
it("dot(data, {stroke}) allows stroke to be a variable color", () => {
const dot = Plot.dot(undefined, {stroke: "x"});
assert.strictEqual(dot.stroke, undefined);
const {stroke} = dot.channels;
assert.strictEqual(stroke.value, "x");
assert.strictEqual(stroke.scale, "auto");
});
it("dot(data, {stroke}) defaults strokeWidth to 1.5 if stroke is defined", () => {
assert.strictEqual(Plot.dot(undefined, {stroke: "red"}).strokeWidth, 1.5);
assert.strictEqual(Plot.dot(undefined, {stroke: "x"}).strokeWidth, 1.5);
assert.strictEqual(Plot.dot(undefined, {stroke: null}).strokeWidth, undefined);
});