Skip to content

Commit 0a62ab5

Browse files
committed
flareCluster, flareIndent
1 parent 21aad85 commit 0a62ab5

File tree

4 files changed

+54
-4
lines changed

4 files changed

+54
-4
lines changed

src/transforms/tree.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ export function treeNode({
2525
transform(data, facets) {
2626
const P = normalize(valueof(data, path));
2727
const root = stratify().path((i) => P[i])(range(data));
28-
const layout = treeLayout().nodeSize([1, 1]);
2928
if (treeSort != null) root.sort(treeSort);
30-
if (treeSeparation !== undefined) layout.separation(treeSeparation ?? one);
29+
const layout = treeLayout();
30+
if (layout.nodeSize) layout.nodeSize([1, 1]);
31+
if (layout.separation && treeSeparation !== undefined) layout.separation(treeSeparation ?? one);
3132
layout(root);
3233
const X = setX([]);
3334
const Y = setY([]);
@@ -75,9 +76,10 @@ export function treeLink({
7576
transform(data, facets) {
7677
const P = normalize(valueof(data, path));
7778
const root = stratify().path(i => P[i])(range(data));
78-
const layout = treeLayout().nodeSize([1, 1]);
7979
if (treeSort != null) root.sort(treeSort);
80-
if (treeSeparation !== undefined) layout.separation(treeSeparation ?? one);
80+
const layout = treeLayout();
81+
if (layout.nodeSize) layout.nodeSize([1, 1]);
82+
if (layout.separation && treeSeparation !== undefined) layout.separation(treeSeparation ?? one);
8183
layout(root);
8284
const X1 = setX1([]);
8385
const X2 = setX2([]);

test/plots/flare-cluster.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as Plot from "@observablehq/plot";
2+
import * as d3 from "d3";
3+
4+
export default async function() {
5+
const flare = await d3.csv("data/flare.csv", d3.autoType);
6+
return Plot.plot({
7+
axis: null,
8+
inset: 10,
9+
insetRight: 120,
10+
height: 2400,
11+
marks: Plot.cluster(flare, {path: "name", delimiter: "."})
12+
});
13+
}

test/plots/flare-indent.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import * as Plot from "@observablehq/plot";
2+
import * as d3 from "d3";
3+
4+
export default async function () {
5+
const flare = await d3.csv("data/flare.csv", d3.autoType);
6+
return Plot.plot({
7+
axis: null,
8+
inset: 10,
9+
insetRight: 120,
10+
round: true,
11+
width: 200,
12+
height: 3600,
13+
marks: Plot.tree(flare, {
14+
strokeWidth: 1,
15+
strokeOpacity: 1,
16+
r: 2.5,
17+
curve: "step-before",
18+
treeLayout: indent,
19+
path: "name",
20+
delimiter: "."
21+
})
22+
});
23+
}
24+
25+
function indent() {
26+
return (root) => {
27+
let i = 0;
28+
root.eachBefore((node) => {
29+
node.y = node.depth;
30+
node.x = ++i;
31+
});
32+
};
33+
}

test/plots/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ export {default as energyProduction} from "./energy-production.js";
5353
export {default as figcaption} from "./figcaption.js";
5454
export {default as figcaptionHtml} from "./figcaption-html.js";
5555
export {default as firstLadies} from "./first-ladies.js";
56+
export {default as flareCluster} from "./flare-cluster.js";
57+
export {default as flareIndent} from "./flare-indent.js";
5658
export {default as flareTree} from "./flare-tree.js";
5759
export {default as footballCoverage} from "./football-coverage.js";
5860
export {default as fruitSales} from "./fruit-sales.js";

0 commit comments

Comments
 (0)