Skip to content

Commit 6fd7d57

Browse files
Filmbostock
andauthored
document more libs (#345)
* arrow, d3, and versions * htl * inputs * L * plot * topojson * remove versions * colors that work well in both light and dark modes I couldn't find how to use var(--theme-foreground-focus). * less awful start and end steps * Apply suggestions from code review * link to katex.org * Update docs/lib/inputs.md --------- Co-authored-by: Mike Bostock <[email protected]>
1 parent 26fcfd7 commit 6fd7d57

File tree

11 files changed

+168
-7
lines changed

11 files changed

+168
-7
lines changed

docs/lib/arquero.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Arquero
22

3-
[Arquero](https://uwdata.github.io/arquero/) is a JavaScript library for “query processing and transformation of array-backed data tables.” Arquero (currently version ${aq.version}) is available by default as `aq` in Markdown, but you can import it explicitly like so:
3+
[Arquero](https://uwdata.github.io/arquero/) is a JavaScript library for “query processing and transformation of array-backed data tables.” Arquero is available by default as `aq` in Markdown, but you can import it explicitly like so:
44

55
```js echo
66
import * as aq from "npm:arquero";

docs/lib/arrow.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
11
# Apache Arrow
22

3+
[Apache Arrow](https://arrow.apache.org/) defines a language-independent columnar memory format for flat and hierarchical data, organized for efficient analytic operations. You will probably not consume it directly, but it is used by [Arquero](arquero), [DuckDB](duckdb), and other libraries to handle data efficiently.
4+
5+
Apache Arrow is available by default as `Arrow` in Markdown, but you can import it explicitly like so:
6+
37
```js echo
48
import * as Arrow from "npm:apache-arrow";
59
```
10+
11+
For example, let’s create a table representing a year’s worth of random walk:
12+
13+
```js echo
14+
const date = d3.utcDay.range(new Date("2023-01-01"), new Date("2024-01-02"));
15+
const random = d3.randomNormal.source(d3.randomLcg(42))(); // seeded random
16+
const value = d3.cumsum(date, random);
17+
const table = Arrow.tableFromArrays({date, value});
18+
display([...table]);
19+
```
20+
21+
```js echo
22+
display(Plot.plot({
23+
marks: [
24+
Plot.ruleY([0]),
25+
Plot.lineY(table, {x: "date", y: "value"})
26+
]
27+
}));
28+
```

docs/lib/counties-albers-10m.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

docs/lib/d3.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# D3
22

3+
[D3](https://d3js.org) (or D3.js) is a free, open-source JavaScript library for visualizing data. Its low-level approach built on web standards offers unparalleled flexibility in authoring dynamic, data-driven graphics.
4+
5+
D3 is available by default as `d3` in Markdown, but you can import it explicitly like so:
6+
37
```js echo
48
import * as d3 from "npm:d3";
59
```
10+
11+
We recommend using [Observable Plot](plot) if you want to create _simple_ charts from your data; but for more complex needs, including interactivity and animations, and more generally for bespoke data visualization, you will most probably want to use D3.
12+
13+
Check out [D3’s extensive documentation](https://d3js.org/) for examples.

docs/lib/dot.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ digraph G {
4141
subgraph cluster_0 {
4242
a0 -> a1 -> a2 -> a3
4343
label = "process #1"
44+
color = lightblue
4445
}
4546
subgraph cluster_1 {
4647
b0 -> b1 -> b2 -> b3
4748
label = "process #2"
48-
color = blue
49+
color = orange
4950
}
5051
start -> a0
5152
start -> b0
@@ -54,7 +55,7 @@ digraph G {
5455
a3 -> a0
5556
a3 -> end
5657
b3 -> end
57-
start [shape = Mdiamond]
58-
end [shape = Msquare]
58+
start [shape = diamond]
59+
end [shape = square]
5960
}
6061
```

docs/lib/htl.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,45 @@
11
# Hypertext Literal
22

3+
[Hypertext Literal](https://github.com/observablehq/htl) is a tagged template literal for HTML which interpolates _values based on context_, allowing automatic escaping and the interpolation of non-serializable values.
4+
5+
Hypertext Literal is available by default as `htl` in Markdown, together with its methods `html` and `svg`. You can import it explicitly like so:
6+
37
```js echo
48
import {html} from "npm:htl";
59
```
610

11+
```js echo
12+
html`<span ${{
13+
style: {
14+
background: "yellow",
15+
padding: "3px",
16+
cursor: "pointer",
17+
userSelect: "none"
18+
},
19+
onclick() {
20+
this.style.background = d3.interpolateRainbow(Math.random());
21+
}
22+
}}>Click me!</span>`
23+
```
24+
25+
The `svg` method likewise generates contextual SVG fragments, which can be useful, say, to position two charts side by side:
26+
727
```js echo
828
import {svg} from "npm:htl";
929
```
1030

31+
```js echo
32+
const chart1 = Plot.barY([3, 4, 2, 7, 5]).plot({width: 120, height: 80});
33+
const chart2 = Plot.barY([5, 1, 7, 6, 2]).plot({width: 120, height: 80});
34+
display(svg`<svg width=260 height=80>
35+
<g>${chart1}</g>
36+
<g ${{transform: "translate(140,0)"}}>${chart2}</g>
37+
</svg>`);
38+
```
39+
40+
If you prefer using `htl.html` and `htl.svg`, just import everything:
41+
1142
```js echo
1243
import * as htl from "npm:htl";
1344
```
45+

docs/lib/inputs.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
# Observable Inputs
22

3+
[Observable Inputs](https://github.com/observablehq/inputs) provides lightweight interface components — buttons, sliders, dropdowns, tables, and the like — to help you explore data and build interactive displays.
4+
5+
Observable Inputs is available by default as `Inputs` in Markdown, but you can import it explicitly like so:
6+
37
```js echo
48
import * as Inputs from "npm:@observablehq/inputs";
59
```
610

11+
or just import the inputs you use:
12+
13+
```js echo
14+
import {Button, Color} from "npm:@observablehq/inputs";
15+
```
16+
717
These basic inputs will get you started.
818

919
* [Button](#button) - do something when a button is clicked

docs/lib/leaflet.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
# Leaflet
22

3+
[Leaflet](https://leafletjs.com/) is an open-source JavaScript library for mobile-friendly interactive maps.
4+
5+
Leaflet is available by default as `L` in Observable markdown, you can also import it explicitly:
6+
37
```js echo
48
import * as L from "npm:leaflet";
59
```
610

11+
To create a map, follow the [tutorial](https://leafletjs.com/examples/quick-start/):
12+
713
```js echo
814
const div = Object.assign(display(document.createElement("div")), {style: "height: 400px;"});
915
const map = L.map(div).setView([51.505, -0.09], 13);
1016
L.tileLayer("https://tile.openstreetmap.org/{z}/{x}/{y}.png").addTo(map);
11-
L.marker([51.5, -0.09]).addTo(map).bindPopup("A pretty CSS popup.<br> Easily customizable.").openPopup();
17+
L.marker([51.5, -0.09]).addTo(map).bindPopup("A nice popup<br> indicating a point of interest.");
1218
```

docs/lib/plot.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,35 @@
11
# Observable Plot
22

3+
[Observable Plot](https://observablehq.com/plot/) is a JavaScript library for exploratory data visualization, made by the same team as [D3](d3). Plot is available by default as `Plot` in Markdown, but you can import it explicitly like so:
4+
35
```js echo
46
import * as Plot from "npm:@observablehq/plot";
57
```
68

9+
To display a chart in Observable Markdown, simply call `Plot.plot` in a JavaScript expression code block:
10+
11+
````md
12+
```js
13+
Plot.plot({
14+
marks: [
15+
Plot.barY(alphabet, {x: "letter", y: "frequency"})
16+
]
17+
})
18+
```
19+
````
20+
21+
For example, here’s a Voronoi chart:
22+
723
```js echo
8-
Plot.frame().plot()
24+
const random = d3.randomLcg(42);
25+
const chart = Plot.voronoi(Array.from({length: 100}, () => [random(), random()])).plot({nice: true});
26+
27+
display(chart);
928
```
29+
30+
Or, to include a ${Plot.lineY([1, 2, 0, 4, 0, 3, 1, 5, 7, 2, 3]).plot({axis: null, width: 80, height: 18})} sparkline in your text — or bars ${Plot.barY([1, 2, 4, 3, 1, 5], {fill: Plot.identity}).plot({axis: null, width: 80, height: 18})} — just call:
31+
32+
```md
33+
… include a ${Plot.lineY([1, 2, 0, 4, 0, 3, 1, 5, 7, 2, 3]).plot({axis: null, width: 80, height: 18})} sparkline…
34+
… bars ${Plot.lineY([1, 2, 4, 3, 1, 5], {fill: Plot.identity}).plot({axis: null, width: 80, height: 18})} — just…
35+
```

docs/lib/tex.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,5 @@ c = \pm\sqrt{a^2 + b^2}
5252
\f\hat\xi\,e^{2 \pi i \xi x}
5353
\,d\xi
5454
```
55+
56+
For more, see [the documentation website](https://katex.org/), in particular the [list of supported functions](https://katex.org/docs/supported).

0 commit comments

Comments
 (0)