forked from observablehq/plot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtree.js
71 lines (69 loc) · 1.75 KB
/
tree.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import {cluster as Cluster} from "d3";
import {isNoneish} from "../options.js";
import {marks} from "../mark.js";
import {maybeTreeAnchor, treeLink, treeNode} from "../transforms/tree.js";
import {dot} from "./dot.js";
import {link} from "./link.js";
import {text} from "./text.js";
export function tree(data, options = {}) {
let {
fill,
stroke,
strokeWidth,
strokeOpacity,
strokeLinejoin,
strokeLinecap,
strokeMiterlimit,
strokeDasharray,
strokeDashoffset,
marker,
markerStart = marker,
markerEnd = marker,
dot: dotDot = isNoneish(markerStart) && isNoneish(markerEnd),
text: textText = "node:name",
textStroke = "white",
title = "node:path",
dx,
dy,
...remainingOptions
} = options;
if (dx === undefined) dx = maybeTreeAnchor(remainingOptions.treeAnchor).dx;
return marks(
link(
data,
treeLink({
markerStart,
markerEnd,
stroke: stroke !== undefined ? stroke : fill === undefined ? "node:internal" : fill,
strokeWidth,
strokeOpacity,
strokeLinejoin,
strokeLinecap,
strokeMiterlimit,
strokeDasharray,
strokeDashoffset,
...remainingOptions
})
),
dotDot
? dot(data, treeNode({fill: fill === undefined ? "node:internal" : fill, title, ...remainingOptions}))
: null,
textText != null
? text(
data,
treeNode({
text: textText,
fill: fill === undefined ? "currentColor" : fill,
stroke: textStroke,
dx,
dy,
title,
...remainingOptions
})
)
: null
);
}
export function cluster(data, options) {
return tree(data, {...options, treeLayout: Cluster});
}