-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtreemap-test.js
More file actions
150 lines (145 loc) · 6.05 KB
/
Copy pathtreemap-test.js
File metadata and controls
150 lines (145 loc) · 6.05 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
require("../env");
require("../../d3");
require("../../d3.layout");
var vows = require("vows"),
assert = require("assert");
var suite = vows.describe("d3.layout.treemap");
suite.addBatch({
"treemap": {
topic: function() {
return d3.layout.treemap;
},
"outputs a squarified treemap": function(treemap) {
var t = treemap().size([1000, 1000]).sort(null);
assert.deepEqual(t.nodes({children: [{value: 1}, {value: 2}, {children: [{value: 1}, {value: 2}]}]}).map(layout), [
{x: 0, y: 0, dx: 1000, dy: 1000},
{x: 0, y: 833, dx: 1000, dy: 167},
{x: 600, y: 0, dx: 400, dy: 833},
{x: 0, y: 0, dx: 600, dy: 833},
{x: 0, y: 555, dx: 600, dy: 278},
{x: 0, y: 0, dx: 600, dy: 555}
]);
},
"sorts by value by default": function(treemap) {
var t = treemap().size([1000, 1000]);
assert.deepEqual(t.nodes({children: [{value: 1}, {value: 2}, {children: [{value: 1}, {value: 2}]}]}).map(layout), [
{x: 0, y: 0, dx: 1000, dy: 1000},
{x: 0, y: 0, dx: 333, dy: 500},
{x: 333, y: 0, dx: 667, dy: 500},
{x: 0, y: 500, dx: 1000, dy: 500},
{x: 0, y: 500, dx: 333, dy: 500},
{x: 333, y: 500, dx: 667, dy: 500}
]);
},
"ignores zero values": function(treemap) {
var t = treemap().size([1000, 1000]).sort(null);
assert.deepEqual(t.nodes({children: [{value: 1}, {value: 0}, {value: 2}, {children: [{value: 1}, {value: 2}]}]}).map(layout), [
{x: 0, y: 0, dx: 1000, dy: 1000},
{x: 0, y: 833, dx: 1000, dy: 167},
{x: 1000, y: 0, dx: 0, dy: 833},
{x: 600, y: 0, dx: 400, dy: 833},
{x: 0, y: 0, dx: 600, dy: 833},
{x: 0, y: 555, dx: 600, dy: 278},
{x: 0, y: 0, dx: 600, dy: 555}
]);
},
"ignores NaN values": function(treemap) {
var t = treemap().size([1000, 1000]).sort(null);
assert.deepEqual(t.nodes({children: [{value: 1}, {value: NaN}, {value: 2}, {children: [{value: 1}, {value: 2}]}]}).map(layout), [
{x: 0, y: 0, dx: 1000, dy: 1000},
{x: 0, y: 833, dx: 1000, dy: 167},
{x: 1000, y: 0, dx: 0, dy: 833},
{x: 600, y: 0, dx: 400, dy: 833},
{x: 0, y: 0, dx: 600, dy: 833},
{x: 0, y: 555, dx: 600, dy: 278},
{x: 0, y: 0, dx: 600, dy: 555}
]);
},
"does not overflow empty size": function(treemap) {
var t = treemap().size([0, 0]).sort(null);
assert.deepEqual(t.nodes({children: [{value: 1}, {value: 2}, {children: [{value: 1}, {value: 2}]}]}).map(layout), [
{x: 0, y: 0, dx: 0, dy: 0},
{x: 0, y: 0, dx: 0, dy: 0},
{x: 0, y: 0, dx: 0, dy: 0},
{x: 0, y: 0, dx: 0, dy: 0},
{x: 0, y: 0, dx: 0, dy: 0},
{x: 0, y: 0, dx: 0, dy: 0}
]);
},
"can specify padding as a number": function(treemap) {
var t = treemap().size([1000, 1000]).sort(null).padding(1);
assert.deepEqual(t.nodes({children: [{value: 1}, {value: 2}, {children: [{value: 1}, {value: 2}]}]}).map(layout), [
{x: 0, y: 0, dx: 1000, dy: 1000},
{x: 1, y: 833, dx: 998, dy: 166},
{x: 600, y: 1, dx: 399, dy: 832},
{x: 1, y: 1, dx: 599, dy: 832},
{x: 2, y: 555, dx: 597, dy: 277},
{x: 2, y: 2, dx: 597, dy: 553}
]);
},
"can specify padding as an array": function(treemap) {
var t = treemap().size([1000, 1000]).sort(null).padding([1,2,3,4]);
assert.deepEqual(t.nodes({children: [{value: 1}, {value: 2}, {children: [{value: 1}, {value: 2}]}]}).map(layout), [
{x: 0, y: 0, dx: 1000, dy: 1000},
{x: 4, y: 831, dx: 994, dy: 166},
{x: 600, y: 1, dx: 398, dy: 830},
{x: 4, y: 1, dx: 596, dy: 830},
{x: 8, y: 553, dx: 590, dy: 275},
{x: 8, y: 2, dx: 590, dy: 551}
]);
},
"can specify padding as null": function(treemap) {
var t = treemap().size([1000, 1000]).sort(null).padding(null);
assert.deepEqual(t.nodes({children: [{value: 1}, {value: 2}, {children: [{value: 1}, {value: 2}]}]}).map(layout), [
{x: 0, y: 0, dx: 1000, dy: 1000},
{x: 0, y: 833, dx: 1000, dy: 167},
{x: 600, y: 0, dx: 400, dy: 833},
{x: 0, y: 0, dx: 600, dy: 833},
{x: 0, y: 555, dx: 600, dy: 278},
{x: 0, y: 0, dx: 600, dy: 555}
]);
},
"can specify padding as a function that returns a number": function(treemap) {
var t = treemap().size([1000, 1000]).sort(null).padding(function(d) { return d.depth; });
assert.deepEqual(t.nodes({children: [{value: 1}, {value: 2}, {children: [{value: 1}, {value: 2}]}]}).map(layout), [
{x: 0, y: 0, dx: 1000, dy: 1000},
{x: 0, y: 833, dx: 1000, dy: 167},
{x: 600, y: 0, dx: 400, dy: 833},
{x: 0, y: 0, dx: 600, dy: 833},
{x: 1, y: 555, dx: 598, dy: 277},
{x: 1, y: 1, dx: 598, dy: 554}
]);
},
"can specify padding as a function that returns an array": function(treemap) {
var t = treemap().size([1000, 1000]).sort(null).padding(function(d) { return [d.depth,2,3,4]; });
assert.deepEqual(t.nodes({children: [{value: 1}, {value: 2}, {children: [{value: 1}, {value: 2}]}]}).map(layout), [
{x: 0, y: 0, dx: 1000, dy: 1000},
{x: 4, y: 831, dx: 994, dy: 166},
{x: 600, y: 0, dx: 398, dy: 831},
{x: 4, y: 0, dx: 596, dy: 831},
{x: 8, y: 552, dx: 590, dy: 276},
{x: 8, y: 1, dx: 590, dy: 551}
]);
},
"can specify padding as a function that returns null": function(treemap) {
var t = treemap().size([1000, 1000]).sort(null).padding(function(d) { return d.depth & 1 ? null : 1; });
assert.deepEqual(t.nodes({children: [{value: 1}, {value: 2}, {children: [{value: 1}, {value: 2}]}]}).map(layout), [
{x: 0, y: 0, dx: 1000, dy: 1000},
{x: 1, y: 833, dx: 998, dy: 166},
{x: 600, y: 1, dx: 399, dy: 832},
{x: 1, y: 1, dx: 599, dy: 832},
{x: 1, y: 556, dx: 599, dy: 277},
{x: 1, y: 1, dx: 599, dy: 555}
]);
}
}
});
function layout(node) {
return {
x: node.x,
y: node.y,
dx: node.dx,
dy: node.dy
};
}
suite.export(module);