2011-08-19 22:01:12 +04:00
|
|
|
require("../env");
|
|
|
|
|
|
|
|
var vows = require("vows"),
|
|
|
|
assert = require("assert");
|
|
|
|
|
|
|
|
var suite = vows.describe("d3.layout.tree");
|
|
|
|
|
|
|
|
suite.addBatch({
|
|
|
|
"tree": {
|
|
|
|
topic: d3.layout.tree,
|
|
|
|
"can handle an empty children array": function(tree) {
|
2011-09-30 11:43:22 +04:00
|
|
|
assert.deepEqual(tree.nodes({children: []}).map(layout), [
|
|
|
|
{depth: 0, x: 0.5, y: 0}
|
|
|
|
]);
|
2011-09-30 11:48:28 +04:00
|
|
|
assert.deepEqual(tree.nodes({children: [
|
2011-09-30 11:43:22 +04:00
|
|
|
{children: []},
|
|
|
|
{children: [{}]},
|
|
|
|
{children: [{}]}
|
2011-09-30 11:48:28 +04:00
|
|
|
]}).map(layout), [
|
2011-09-30 11:43:22 +04:00
|
|
|
{depth: 0, x: .5, y: 0},
|
|
|
|
{depth: 1, x: .125, y: 0.5},
|
|
|
|
{depth: 1, x: .375, y: 0.5},
|
|
|
|
{depth: 2, x: .375, y: 1},
|
|
|
|
{depth: 1, x: .875, y: 0.5},
|
|
|
|
{depth: 2, x: .875, y: 1}
|
2011-08-19 22:01:12 +04:00
|
|
|
]);
|
2011-12-13 16:43:37 +04:00
|
|
|
},
|
|
|
|
"can handle a single node": function(tree) {
|
|
|
|
assert.deepEqual(tree.nodes({value: 0}).map(layout), [
|
|
|
|
{depth: 0, x: 0.5, y: 0}
|
|
|
|
]);
|
2011-08-19 22:01:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-09-30 11:43:22 +04:00
|
|
|
function layout(node) {
|
|
|
|
return {
|
|
|
|
depth: node.depth,
|
|
|
|
x: node.x,
|
|
|
|
y: node.y
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2011-08-19 22:01:12 +04:00
|
|
|
suite.export(module);
|