|
1 require("../env"); |
|
2 require("../../d3"); |
|
3 require("../../d3.layout"); |
|
4 |
|
5 var vows = require("vows"), |
|
6 assert = require("assert"); |
|
7 |
|
8 var suite = vows.describe("d3.layout.partition"); |
|
9 |
|
10 suite.addBatch({ |
|
11 "partition": { |
|
12 topic: function() { |
|
13 return d3.layout.partition; |
|
14 }, |
|
15 "ignores zero values": function(partition) { |
|
16 var p = partition().size([3, 3]); |
|
17 assert.deepEqual(p.nodes({children: [{value: 1}, {value: 0}, {value: 2}, {children: [{value: 0}, {value: 0}]}]}).map(metadata), [ |
|
18 {x: 0, y: 0, dx: 3, dy: 1}, |
|
19 {x: 2, y: 1, dx: 1, dy: 1}, |
|
20 {x: 3, y: 1, dx: 0, dy: 1}, |
|
21 {x: 0, y: 1, dx: 2, dy: 1}, |
|
22 {x: 3, y: 1, dx: 0, dy: 1}, |
|
23 {x: 3, y: 2, dx: 0, dy: 1}, |
|
24 {x: 3, y: 2, dx: 0, dy: 1} |
|
25 ]); |
|
26 }, |
|
27 "can handle an empty children array": function(partition) { |
|
28 var p = partition(); |
|
29 assert.deepEqual(p.nodes({children: []}).map(metadata), [ |
|
30 {x: 0, y: 0, dx: 1, dy: 1} |
|
31 ]); |
|
32 assert.deepEqual(p.nodes({children: [{children: []}, {value: 1}]}).map(metadata), [ |
|
33 {x: 0, y: 0, dx: 1, dy: 0.5}, |
|
34 {x: 1, y: 0.5, dx: 0, dy: 0.5}, |
|
35 {x: 0, y: 0.5, dx: 1, dy: 0.5} |
|
36 ]); |
|
37 } |
|
38 } |
|
39 }); |
|
40 |
|
41 function metadata(node) { |
|
42 var metadata = {}; |
|
43 if ("x" in node) metadata.x = node.x; |
|
44 if ("y" in node) metadata.y = node.y; |
|
45 if ("dx" in node) metadata.dx = node.dx; |
|
46 if ("dy" in node) metadata.dy = node.dy; |
|
47 return metadata; |
|
48 } |
|
49 |
|
50 suite.export(module); |