Treat nodes with empty children arrays as leaves.

Fixes #286.
This commit is contained in:
Jason Davies 2011-09-08 00:26:44 +01:00
Родитель f90bc4fd50
Коммит d024c3f82c
4 изменённых файлов: 26 добавлений и 5 удалений

Просмотреть файл

@ -1027,12 +1027,12 @@ d3.layout.hierarchy = function() {
// Also converts the data representation into a standard hierarchy structure.
function recurse(data, depth, nodes) {
var childs = children.call(hierarchy, data, depth),
n,
node = d3_layout_hierarchyInline ? data : {data: data};
node.depth = depth;
nodes.push(node);
if (childs) {
if (childs && (n = childs.length)) {
var i = -1,
n = childs.length,
c = node.children = [],
v = 0,
j = depth + 1;

2
d3.layout.min.js поставляемый

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -7,12 +7,12 @@ d3.layout.hierarchy = function() {
// Also converts the data representation into a standard hierarchy structure.
function recurse(data, depth, nodes) {
var childs = children.call(hierarchy, data, depth),
n,
node = d3_layout_hierarchyInline ? data : {data: data};
node.depth = depth;
nodes.push(node);
if (childs) {
if (childs && (n = childs.length)) {
var i = -1,
n = childs.length,
c = node.children = [],
v = 0,
j = depth + 1;

Просмотреть файл

@ -0,0 +1,21 @@
require("../env");
require("../../d3");
require("../../d3.layout");
var vows = require("vows"),
assert = require("assert");
var suite = vows.describe("d3.layout.hierarchy");
suite.addBatch({
"hierarchy": {
topic: d3.layout.hierarchy,
"doesn't overwrite the value of a node that has an empty children array": function(hierarchy) {
assert.deepEqual(hierarchy({value: 1, children: []}), [
{data: {value: 1, children: []}, depth: 0, value: 1}
]);
}
}
});
suite.export(module);