toolkit/javascript/d3/test/layout/tree-test.js
changeset 47 c0b4a8b5a012
equal deleted inserted replaced
46:efd9c589177a 47:c0b4a8b5a012
       
     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.tree");
       
     9 
       
    10 suite.addBatch({
       
    11   "tree": {
       
    12     topic: d3.layout.tree,
       
    13     "can handle an empty children array": function(tree) {
       
    14       assert.deepEqual(tree.nodes({children: []}).map(layout), [
       
    15         {depth: 0, x: 0.5, y: 0}
       
    16       ]);
       
    17       assert.deepEqual(tree.nodes({children: [
       
    18         {children: []},
       
    19         {children: [{}]},
       
    20         {children: [{}]}
       
    21       ]}).map(layout), [
       
    22         {depth: 0, x: .5,   y: 0},
       
    23         {depth: 1, x: .125, y: 0.5},
       
    24         {depth: 1, x: .375, y: 0.5},
       
    25         {depth: 2, x: .375, y: 1},
       
    26         {depth: 1, x: .875, y: 0.5},
       
    27         {depth: 2, x: .875, y: 1}
       
    28       ]);
       
    29     }
       
    30   }
       
    31 });
       
    32 
       
    33 function layout(node) {
       
    34   return {
       
    35     depth: node.depth,
       
    36     x: node.x,
       
    37     y: node.y
       
    38   };
       
    39 }
       
    40 
       
    41 suite.export(module);