Skip to content

Commit 7b61e3e

Browse files
committed
treeSort
1 parent 29358cc commit 7b61e3e

File tree

2 files changed

+509
-505
lines changed

2 files changed

+509
-505
lines changed

src/transforms/tree.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export function treeNode({
66
delimiter, // how the path is separated
77
frameAnchor = "left", // TODO different orientations
88
tree = Tree, // TODO tree sort, tree separation
9+
treeSort,
910
...options
1011
} = {}) {
1112
const normalize = normalizer(delimiter);
@@ -20,6 +21,7 @@ export function treeNode({
2021
transform(data, facets) {
2122
const P = normalize(valueof(data, path));
2223
const root = stratify().path((i) => P[i])(range(data));
24+
if (treeSort != null) root.sort(treeSort);
2325
tree().nodeSize([1, 1])(root);
2426
const X = setX([]);
2527
const Y = setY([]);
@@ -28,7 +30,7 @@ export function treeNode({
2830
const i = node.data;
2931
if (i === undefined) continue; // imputed node
3032
X[i] = node.y;
31-
Y[i] = node.x;
33+
Y[i] = -node.x;
3234
for (const o of outputs) o[output_values][i] = o[output_evaluate](node);
3335
}
3436
return {data, facets};
@@ -42,6 +44,7 @@ export function treeLink({
4244
delimiter, // how the path is separated
4345
curve = "bump-x", // TODO depends on orientation
4446
tree = Tree, // TODO tree sort, tree separation
47+
treeSort,
4548
...options
4649
} = {}) {
4750
const {stroke = "#555", strokeWidth = 1.5, strokeOpacity = 0.4} = options;
@@ -64,6 +67,7 @@ export function treeLink({
6467
transform(data, facets) {
6568
const P = normalize(valueof(data, path));
6669
const root = stratify().path(i => P[i])(range(data));
70+
if (treeSort != null) root.sort(treeSort);
6771
tree().nodeSize([1, 1])(root);
6872
const X1 = setX1([]);
6973
const X2 = setX2([]);
@@ -75,8 +79,8 @@ export function treeLink({
7579
if (i === undefined) continue; // imputed node
7680
X1[i] = source.y;
7781
X2[i] = target.y;
78-
Y1[i] = source.x;
79-
Y2[i] = target.x;
82+
Y1[i] = -source.x;
83+
Y2[i] = -target.x;
8084
for (const o of outputs) o[output_values][i] = o[output_evaluate](target, source);
8185
}
8286
if (root.data !== undefined) for (const o of outputs) o[output_values][root.data] = o[output_evaluate](root, null);

0 commit comments

Comments
 (0)