|
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.cluster"); |
|
9 |
|
10 suite.addBatch({ |
|
11 "cluster": { |
|
12 topic: d3.layout.cluster, |
|
13 "can handle an empty children array": function(cluster) { |
|
14 assert.deepEqual(cluster.nodes({value: 1, children: [{value: 1, children: []}, {value: 1}]}).map(layout), [ |
|
15 {value: 1, depth: 0, x: 0.5, y: 0}, |
|
16 {value: 1, depth: 1, x: 0.25, y: 1}, |
|
17 {value: 1, depth: 1, x: 0.75, y: 1} |
|
18 ]); |
|
19 }, |
|
20 "can handle zero-valued nodes": function(cluster) { |
|
21 assert.deepEqual(cluster.nodes({value: 0, children: [{value: 0}, {value: 1}]}).map(layout), [ |
|
22 {value: 0, depth: 0, x: 0.5, y: 0}, |
|
23 {value: 0, depth: 1, x: 0.25, y: 1}, |
|
24 {value: 1, depth: 1, x: 0.75, y: 1} |
|
25 ]); |
|
26 } |
|
27 } |
|
28 }); |
|
29 |
|
30 function layout(node) { |
|
31 return { |
|
32 value: node.value, |
|
33 depth: node.depth, |
|
34 x: node.x, |
|
35 y: node.y |
|
36 }; |
|
37 } |
|
38 |
|
39 suite.export(module); |