Skip to content

Commit dbb7d59

Browse files
authored
documentation tree (#1698)
from the d3 website: d3/d3@fbf24bb and d3/d3@9f88f02
1 parent 97f1657 commit dbb7d59

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

docs/.vitepress/theme/custom.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
z-index: 1;
3232
}
3333

34+
.vp-doc .plot a:hover {
35+
text-decoration: initial;
36+
}
37+
3438
:root [aria-label="tip"][fill="white"],
3539
:root [aria-label="tip"] [fill="white"] {
3640
fill: var(--vp-c-bg-alt);

docs/what-is-plot.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import * as Plot from "@observablehq/plot";
44
import * as d3 from "d3";
5-
import {shallowRef, onMounted} from "vue";
5+
import {computed, onMounted, shallowRef} from "vue";
6+
import {useData} from "vitepress";
7+
import PlotRender from "./components/PlotRender.js";
68

79
const olympians = shallowRef([
810
{weight: 31, height: 1.21, sex: "female"},
@@ -13,6 +15,28 @@ onMounted(() => {
1315
d3.csv("./data/athletes.csv", d3.autoType).then((data) => (olympians.value = data));
1416
});
1517

18+
const {site: {value: {themeConfig: {sidebar}}}} = useData();
19+
20+
const paths = computed(() => {
21+
const paths = [];
22+
(function visit(node, path) {
23+
paths.push({path, link: node.link && `.${node.link}`});
24+
if (node.items) {
25+
for (const item of node.items) {
26+
visit(item, (path === "/" ? path : path + "/") + item.text);
27+
}
28+
}
29+
})({items: sidebar}, "/Plot");
30+
return paths;
31+
});
32+
33+
// https://github.com/observablehq/plot/issues/1703
34+
function computeTreeWidth(paths) {
35+
const root = d3.tree().nodeSize([1, 1])(d3.stratify().path((d) => d.path)(paths));
36+
const [x1, x2] = d3.extent(root, (d) => d.x);
37+
return x2 - x1;
38+
}
39+
1640
</script>
1741

1842
# What is Plot?
@@ -68,3 +92,19 @@ Plot.plot({
6892
})
6993
```
7094
:::
95+
96+
## What can Plot do?
97+
98+
Because marks are composable, and because you can extend Plot with custom marks, you can make almost anything with it — much more than the charts above! The following [tree diagram](./marks/tree.md) of the documentation gives a sense of what’s ”in the box” with Plot. Peruse our [gallery of examples](https://observablehq.com/@observablehq/plot-gallery) for more inspiration.
99+
100+
<PlotRender :options='{
101+
axis: null,
102+
height: computeTreeWidth(paths) * 12,
103+
marginTop: 4,
104+
marginRight: 120,
105+
marginBottom: 4,
106+
marginLeft: 24,
107+
marks: [
108+
Plot.tree(paths, {path: "path", textStroke: "var(--vp-c-bg)", channels: {href: {value: "link", filter: null}}, treeSort: null})
109+
]
110+
}' />

0 commit comments

Comments
 (0)