Sha256: 41d7cb25f07cc83fb2d7630872d612fb2ca9657e701387387949a9e026db5487

Contents?: true

Size: 1.4 KB

Versions: 4

Compression:

Stored size: 1.4 KB

Contents

var vows = require("vows"),
    load = require("../load"),
    assert = require("../assert");

var suite = vows.describe("d3.layout.partition");

suite.addBatch({
  "partition": {
    topic: load("layout/partition").expression("d3.layout.partition"),
    "ignores zero values": function(partition) {
      var p = partition().size([3, 3]);
      assert.deepEqual(p.nodes({children: [{value: 1}, {value: 0}, {value: 2}, {children: [{value: 0}, {value: 0}]}]}).map(metadata), [
        {x: 0, y: 0, dx: 3, dy: 1},
        {x: 2, y: 1, dx: 1, dy: 1},
        {x: 3, y: 1, dx: 0, dy: 1},
        {x: 0, y: 1, dx: 2, dy: 1},
        {x: 3, y: 1, dx: 0, dy: 1},
        {x: 3, y: 2, dx: 0, dy: 1},
        {x: 3, y: 2, dx: 0, dy: 1}
      ]);
    },
    "can handle an empty children array": function(partition) {
      var p = partition();
      assert.deepEqual(p.nodes({children: []}).map(metadata), [
        {x: 0, y: 0, dx: 1, dy: 1}
      ]);
      assert.deepEqual(p.nodes({children: [{children: []}, {value: 1}]}).map(metadata), [
        {x: 0, y: 0,   dx: 1, dy: 0.5},
        {x: 1, y: 0.5, dx: 0, dy: 0.5},
        {x: 0, y: 0.5, dx: 1, dy: 0.5}
      ]);
    }
  }
});

function metadata(node) {
  var metadata = {};
  if ("x" in node) metadata.x = node.x;
  if ("y" in node) metadata.y = node.y;
  if ("dx" in node) metadata.dx = node.dx;
  if ("dy" in node) metadata.dy = node.dy;
  return metadata;
}

suite.export(module);

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
stripchart-0.0.3 lib/stripchart/public/components/d3/test/layout/partition-test.js
stripmem-0.0.3 lib/stripmem/public/components/d3/test/layout/partition-test.js
stripmem-0.0.2 lib/stripmem/public/components/d3/test/layout/partition-test.js
stripmem-0.0.1 lib/stripmem/public/components/d3/test/layout/partition-test.js