|
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.pack"); |
|
9 |
|
10 suite.addBatch({ |
|
11 "pack": { |
|
12 topic: d3.layout.pack, |
|
13 "can handle an empty children array": function(pack) { |
|
14 assert.deepEqual(pack.nodes({children: [{children: []}, {value: 1}]}).map(layout), [ |
|
15 {value: 1, depth: 0, x: 0.5, y: 0.5, r: 0.5}, |
|
16 {value: 0, depth: 1, x: 0.0, y: 0.5, r: 0.0}, |
|
17 {value: 1, depth: 1, x: 0.5, y: 0.5, r: 0.5} |
|
18 ]); |
|
19 }, |
|
20 "can handle zero-valued nodes": function(pack) { |
|
21 assert.deepEqual(pack.nodes({children: [{value: 0}, {value: 1}]}).map(layout), [ |
|
22 {value: 1, depth: 0, x: 0.5, y: 0.5, r: 0.5}, |
|
23 {value: 0, depth: 1, x: 0.0, y: 0.5, r: 0.0}, |
|
24 {value: 1, depth: 1, x: 0.5, y: 0.5, r: 0.5} |
|
25 ]); |
|
26 }, |
|
27 "can handle residual floating point error": function(pack) { |
|
28 var result = pack.nodes({children: [ |
|
29 {value: 0.005348322447389364}, |
|
30 {value: 0.8065882022492588}, |
|
31 {value: 0} |
|
32 ]}).map(layout); |
|
33 assert.isFalse(result.map(function(d) { return d.depth; }).some(isNaN)); |
|
34 assert.isFalse(result.map(function(d) { return d.value; }).some(isNaN)); |
|
35 assert.isFalse(result.map(function(d) { return d.x; }).some(isNaN)); |
|
36 assert.isFalse(result.map(function(d) { return d.y; }).some(isNaN)); |
|
37 assert.isFalse(result.map(function(d) { return d.r; }).some(isNaN)); |
|
38 }, |
|
39 "avoids coincident circles": function(pack) { |
|
40 var result = pack({children: [ |
|
41 {children: [{value: 17010}, {value: 5842}, {value: 0}, {value: 0}]}, |
|
42 {children: [ |
|
43 {children: [{value: 721}, {value: 4294}, {value: 9800}, {value: 1314}, {value: 2220}]}, |
|
44 {value: 1759}, {value: 2165}, {value: 586}, {value: 3331}, {value: 772}, {value: 3322} |
|
45 ]} |
|
46 ]}).map(layout); |
|
47 result.sort(function(a, b) { |
|
48 return a.x < b.x && a.y < b.y ? -1 : 1; |
|
49 }); |
|
50 assert.isFalse(result.slice(1).some(function(d, i) { |
|
51 return d.x === result[i].x && d.y === result[i].y && d.value > 0; |
|
52 })); |
|
53 } |
|
54 } |
|
55 }); |
|
56 |
|
57 function layout(node) { |
|
58 return { |
|
59 value: node.value, |
|
60 depth: node.depth, |
|
61 r: node.r, |
|
62 x: node.x, |
|
63 y: node.y |
|
64 }; |
|
65 } |
|
66 |
|
67 suite.export(module); |