Skip to content

Commit 6efd442

Browse files
committed
treeSeparation
1 parent 7b61e3e commit 6efd442

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

src/options.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export const field = name => d => d[name];
2222
export const indexOf = (d, i) => i;
2323
export const identity = {transform: d => d};
2424
export const zero = () => 0;
25+
export const one = () => 1;
2526
export const string = x => x == null ? x : `${x}`;
2627
export const number = x => x == null ? x : +x;
2728
export const boolean = x => x == null ? x : !!x;

src/transforms/stack.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {InternMap, cumsum, group, groupSort, greatest, max, min, rollup, sum} from "d3";
22
import {ascendingDefined} from "../defined.js";
3-
import {field, channel, maybeChannel, maybeZ, mid, range, valueof, maybeZero} from "../options.js";
3+
import {field, channel, maybeChannel, maybeZ, mid, range, valueof, maybeZero, one} from "../options.js";
44
import {basic} from "./basic.js";
55

66
export function stackX(stackOptions = {}, options = {}) {
@@ -65,7 +65,7 @@ function mergeOptions(options) {
6565
return [{offset, order, reverse}, rest];
6666
}
6767

68-
function stack(x, y = () => 1, ky, {offset, order, reverse}, options) {
68+
function stack(x, y = one, ky, {offset, order, reverse}, options) {
6969
const z = maybeZ(options);
7070
const [X, setX] = maybeChannel(x);
7171
const [Y1, setY1] = channel(y);

src/transforms/tree.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import {stratify, tree as Tree} from "d3";
2-
import {channel, isObject, range, valueof} from "../options.js";
2+
import {channel, isObject, one, range, valueof} from "../options.js";
33

44
export function treeNode({
55
path, // the delimited path
66
delimiter, // how the path is separated
77
frameAnchor = "left", // TODO different orientations
8-
tree = Tree, // TODO tree sort, tree separation
8+
tree = Tree,
99
treeSort,
10+
treeSeparation,
1011
...options
1112
} = {}) {
1213
const normalize = normalizer(delimiter);
@@ -21,8 +22,10 @@ export function treeNode({
2122
transform(data, facets) {
2223
const P = normalize(valueof(data, path));
2324
const root = stratify().path((i) => P[i])(range(data));
25+
const layout = tree().nodeSize([1, 1]);
2426
if (treeSort != null) root.sort(treeSort);
25-
tree().nodeSize([1, 1])(root);
27+
if (treeSeparation !== undefined) layout.separation(treeSeparation ?? one);
28+
layout(root);
2629
const X = setX([]);
2730
const Y = setY([]);
2831
for (const o of outputs) o[output_values] = o[output_setValues]([]);
@@ -43,8 +46,9 @@ export function treeLink({
4346
path, // the delimited path
4447
delimiter, // how the path is separated
4548
curve = "bump-x", // TODO depends on orientation
46-
tree = Tree, // TODO tree sort, tree separation
49+
tree = Tree,
4750
treeSort,
51+
treeSeparation,
4852
...options
4953
} = {}) {
5054
const {stroke = "#555", strokeWidth = 1.5, strokeOpacity = 0.4} = options;
@@ -67,8 +71,10 @@ export function treeLink({
6771
transform(data, facets) {
6872
const P = normalize(valueof(data, path));
6973
const root = stratify().path(i => P[i])(range(data));
74+
const layout = tree().nodeSize([1, 1]);
7075
if (treeSort != null) root.sort(treeSort);
71-
tree().nodeSize([1, 1])(root);
76+
if (treeSeparation !== undefined) layout.separation(treeSeparation ?? one);
77+
layout(root);
7278
const X1 = setX1([]);
7379
const X2 = setX2([]);
7480
const Y1 = setY1([]);

0 commit comments

Comments
 (0)