-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Instead, the hierarchy layouts now take simple hierarchical input data as they did in D3 3.x, and d3.hierarchy now takes tabular input data and converts it into a simple hierarchy. This avoids having the hierarchical layouts mutate their inputs. (I’ve omitted the children accessor from the hierarchy layouts, but I might bring it back.)
- Loading branch information
Showing
30 changed files
with
528 additions
and
589 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import visitBefore from "./visitBefore"; | ||
|
||
export default function(node, compare) { | ||
visitBefore(node, function(node) { | ||
if (node.children) { | ||
node.children.sort(compare); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
export default function() { | ||
var node = this, nodes = [this]; | ||
while (node = node.parent) nodes.push(node); | ||
var node = this, nodes = [node]; | ||
while (node = node.parent) { | ||
nodes.push(node); | ||
} | ||
return nodes; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
import visit from "../visit"; | ||
|
||
export default function() { | ||
var nodes = []; | ||
this.each(function(node) { nodes.push(node); }); | ||
visit(this, function(node) { | ||
nodes.push(node); | ||
}); | ||
return nodes; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,39 @@ | ||
import node_ancestors from "./ancestors"; | ||
import node_descendants from "./descendants"; | ||
import node_leaves from "./leaves"; | ||
import node_each from "./each"; | ||
import node_eachAfter from "./eachAfter"; | ||
import node_eachBefore from "./eachBefore"; | ||
import node_revalue from "./revalue"; | ||
import node_sort from "./sort"; | ||
|
||
export default function node(data) { | ||
return new Node(data); | ||
var root = new Node(data), | ||
node = root, | ||
nodes = [root], | ||
child, | ||
children, | ||
i, | ||
n; | ||
|
||
while ((node = nodes.pop()) != null) { | ||
if ((children = node.data.children) && (n = children.length)) { | ||
node.children = new Array(n); | ||
for (i = n - 1; i >= 0; --i) { | ||
nodes.push(child = node.children[i] = new Node(children[i])); | ||
child.parent = node; | ||
child.depth = node.depth + 1; | ||
} | ||
} | ||
} | ||
|
||
return root; | ||
} | ||
|
||
function Node(data) { | ||
this.data = data; | ||
this.depth = 0; | ||
this.parent = null; | ||
} | ||
|
||
Node.prototype = node.prototype = { | ||
constructor: Node, | ||
ancestors: node_ancestors, | ||
descendants: node_descendants, | ||
leaves: node_leaves, | ||
each: node_each, | ||
eachAfter: node_eachAfter, | ||
eachBefore: node_eachBefore, | ||
revalue: node_revalue, | ||
sort: node_sort | ||
leaves: node_leaves | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
import visit from "../visit"; | ||
|
||
export default function() { | ||
var leaves = []; | ||
this.each(function(node) { if (!node.children) leaves.push(node); }); | ||
visit(this, function(node) { | ||
if (!node.children) { | ||
leaves.push(node); | ||
} | ||
}); | ||
return leaves; | ||
} |
Oops, something went wrong.