forked from d3/d3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproperty-test.js
More file actions
117 lines (113 loc) · 4.32 KB
/
Copy pathproperty-test.js
File metadata and controls
117 lines (113 loc) · 4.32 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
var vows = require("vows"),
_ = require("../../"),
load = require("../load"),
assert = require("../assert");
var suite = vows.describe("selection.property");
suite.addBatch({
"select(body)": {
topic: load("selection/property").document(),
"on a simple page": {
topic: function(d3) {
return d3.select("body");
},
"sets a property as a string": function(body) {
body.property("bgcolor", "red");
assert.equal(body.node().bgcolor, "red");
},
"sets a property as a number": function(body) {
body.property("opacity", 1);
assert.equal(body.node().opacity, "1");
},
"sets a property as a function": function(body) {
body.property("bgcolor", function() { return "orange"; });
assert.equal(body.node().bgcolor, "orange");
},
"sets properties as a map of constants": function(body) {
body.property({bgcolor: "purple", opacity: .41});
assert.equal(body.node().bgcolor, "purple");
assert.equal(body.node().opacity, .41);
},
"sets properties as a map of functions": function(body) {
body.data(["cyan"]).property({bgcolor: String, opacity: function(d, i) { return i; }});
assert.equal(body.node().bgcolor, "cyan");
assert.equal(body.node().opacity, 0);
},
"gets a property value": function(body) {
body.node().bgcolor = "yellow";
assert.equal(body.property("bgcolor"), "yellow");
},
"removes a property as null": function(body) {
body.property("bgcolor", "yellow").property("bgcolor", null);
assert.isFalse("bgcolor" in body.node());
},
"removes a property as a function": function(body) {
body.property("bgcolor", "yellow").property("bgcolor", function() { return null });
assert.isFalse("bgcolor" in body.node());
},
"removes properties as a map of nulls": function(body) {
body.node().bgcolor = "red";
body.property({bgcolor: null});
assert.isFalse("bgcolor" in body.node());
},
"removes properties as a map of functions that return null": function(body) {
body.node().bgcolor = "red";
body.property({bgcolor: function() {}});
assert.isFalse("bgcolor" in body.node());
},
"returns the current selection": function(body) {
assert.isTrue(body.property("bgcolor", "yellow") === body);
}
}
}
});
suite.addBatch({
"selectAll(div)": {
topic: load("selection/property").document(),
"on a simple page": {
topic: function(d3) {
return d3.select("body").html("").selectAll("div").data([0, 1]).enter().append("div");
},
"sets a property as a string": function(div) {
div.property("bgcolor", "red");
assert.equal(div[0][0].bgcolor, "red");
assert.equal(div[0][1].bgcolor, "red");
},
"sets a property as a number": function(div) {
div.property("opacity", 0.4);
assert.equal(div[0][0].opacity, "0.4");
assert.equal(div[0][1].opacity, "0.4");
},
"sets a property as a function": function(div) {
div.property("bgcolor", _.interpolateRgb("brown", "steelblue"));
assert.equal(div[0][0].bgcolor, "#a52a2a");
assert.equal(div[0][1].bgcolor, "#4682b4");
},
"gets a property value": function(div) {
div[0][0].bgcolor = "purple";
assert.equal(div.property("bgcolor"), "purple");
},
"removes a property as null": function(div) {
div.property("bgcolor", "yellow").property("bgcolor", null);
assert.isFalse("bgcolor" in div[0][0]);
assert.isFalse("bgcolor" in div[0][1]);
},
"removes a property as a function": function(div) {
div.property("bgcolor", "yellow").property("bgcolor", function() { return null });
assert.isFalse("bgcolor" in div[0][0]);
assert.isFalse("bgcolor" in div[0][1]);
},
"returns the current selection": function(div) {
assert.isTrue(div.property("bgcolor", "yellow") === div);
},
"ignores null nodes": function(div) {
var node = div[0][1];
div.property("bgcolor", null);
div[0][1] = null;
div.property("bgcolor", "red");
assert.equal(div[0][0].bgcolor, "red");
assert.isFalse("bgcolor" in node);
}
}
}
});
suite.export(module);