Skip to content

Commit 2c1de3d

Browse files
Filmbostock
andauthored
lots of new links (#1487)
* new links * what is plot links * yet another histogram * a bit more links (300!) * why-plot links * plots links * transforms links * facet links * legend links * curve link * formats links, fix Invalid date * shorthand links * scales links * remove duplicate * restore blank lines --------- Co-authored-by: Mike Bostock <[email protected]>
1 parent 6cf51bf commit 2c1de3d

File tree

13 files changed

+81
-83
lines changed

13 files changed

+81
-83
lines changed

docs/features/curves.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ A **curve** defines how to turn a discrete representation of a line as a sequenc
4141
</label>
4242
</p>
4343

44-
:::plot
44+
:::plot https://observablehq.com/@observablehq/plot-curve-option
4545
```js-vue
4646
Plot.plot({
4747
marks: [

docs/features/facets.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Faceting partitions data by ordinal or categorical value and then repeats a plot
2525

2626
For example, below we recreate the Trellis display (“reminiscent of garden trelliswork”) of [Becker *et al.*](https://hci.stanford.edu/courses/cs448b/papers/becker-trellis-jcgs.pdf) using the dot’s **fy** channel to declare vertical↕︎ facets, showing the yields of several varieties of barley across several sites for the years <span :style="{borderBottom: `solid 2px ${d3.schemeTableau10[0]}`}">1931</span> and <span :style="{borderBottom: `solid 2px ${d3.schemeTableau10[1]}`}">1932</span>.
2727

28-
:::plot
28+
:::plot https://observablehq.com/@observablehq/plot-trellis
2929
```js
3030
Plot.plot({
3131
height: 800,
@@ -59,7 +59,7 @@ Use the [frame mark](../marks/frame.md) for stronger visual separation of facets
5959

6060
The chart above reveals a likely data collection error: the years appear to be reversed for the Morris site as it is the only site where the yields in <span :style="{borderBottom: `solid 2px ${d3.schemeTableau10[1]}`}">1932</span> were higher than in <span :style="{borderBottom: `solid 2px ${d3.schemeTableau10[0]}`}">1931</span>. The anomaly in Morris is more obvious if we use directed arrows to show the year-over-year change. The [group transform](../transforms/group.md) groups the observations by site and variety to compute the change.
6161

62-
:::plot defer
62+
:::plot defer https://observablehq.com/@observablehq/plot-trellis-anomaly
6363
```js
6464
Plot.plot({
6565
height: 800,
@@ -94,7 +94,7 @@ Here the sort order has changed slightly: the *y* and *fy* domains are sorted by
9494

9595
Faceting requires ordinal or categorical data because there are a discrete number of facets; the associated *fx* and *fy* scales are [band scales](./scales.md#discrete-position). Quantitative or temporal data can be made ordinal by binning, say using [Math.floor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor). Or, use the [**interval** scale option](../transforms/interval.md) on the *fx* or *fy* scale. Below, we produce a [box plot](../marks/box.md) of the weights (in kilograms) of Olympic athletes, faceted by height binned at a 10cm (0.1 meter) interval.
9696

97-
:::plot defer
97+
:::plot defer https://observablehq.com/@observablehq/plot-olympians-box-plot
9898
```js
9999
Plot.plot({
100100
fy: {
@@ -116,7 +116,7 @@ If you are interested in automatic faceting for quantitative data, please upvote
116116

117117
When both **fx** and **fy** channels are specified, two-dimensional faceting results, as in the faceted scatterplot of penguin culmen measurements below. The horizontal↔︎ facet shows sex (with the rightmost column representing penguins whose *sex* field is null, indicating missing data), while the vertical↕︎ facet shows species.
118118

119-
:::plot defer
119+
:::plot defer https://observablehq.com/@observablehq/plot-two-dimensional-faceting
120120
```js
121121
Plot.plot({
122122
grid: true,
@@ -137,7 +137,7 @@ Plot.plot({
137137

138138
You can mix-and-match faceted and non-faceted marks within the same plot. The non-faceted marks will be repeated across all facets. This is useful for decoration marks, such as a [frame](../marks/frame.md), and also for context: below, the entire population of penguins is repeated in each facet as small gray dots, making it easier to see how each facet compares to the whole.
139139

140-
:::plot defer
140+
:::plot defer https://observablehq.com/@observablehq/plot-non-faceted-marks
141141
```js
142142
Plot.plot({
143143
grid: true,
@@ -206,7 +206,7 @@ This example uses an [immediately-invoked function expression (IIFE)](https://de
206206

207207
The above chart also demonstrates faceted annotations, using a [text mark](../marks/text.md) to label the facet in lieu of facet axes. Below, we apply a single text annotation to the *Adelie* facet by setting the **fy** channel to a single-element array parallel to the data.
208208

209-
:::plot defer
209+
:::plot defer https://observablehq.com/@observablehq/plot-annotated-facets
210210
```js
211211
Plot.plot({
212212
marginLeft: 60,

docs/features/formats.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ These helper functions are provided for convenience as a **tickFormat** option f
1212
## formatIsoDate(*date*)
1313

1414
```js
15-
Plot.formatIsoDate(new Date("2020-01-01T00:00.000Z")) // "2020-01-01"
15+
Plot.formatIsoDate(new Date("2020-01-01T00:00:00.000Z")) // "2020-01-01"
1616
```
1717

1818
Given a *date*, returns the shortest equivalent ISO 8601 UTC string. If the given *date* is not valid, returns `"Invalid Date"`. See [isoformat](https://github.com/mbostock/isoformat).
1919

2020
## formatWeekday(*locale*, *format*)
2121

22-
:::plot
22+
:::plot https://observablehq.com/@observablehq/plot-format-helpers
2323
```js
2424
Plot.textX(d3.range(7)).plot({x: {tickFormat: Plot.formatWeekday()}})
2525
```
@@ -33,7 +33,7 @@ Returns a function that formats a given week day number (from 0 = Sunday to 6 =
3333

3434
## formatMonth(*locale*, *format*)
3535

36-
:::plot
36+
:::plot https://observablehq.com/@observablehq/plot-format-helpers
3737
```js
3838
Plot.textX(d3.range(12)).plot({x: {tickFormat: Plot.formatMonth(), ticks: 12}})
3939
```

docs/features/legends.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ onMounted(() => {
2828

2929
Plot can generate **legends** for *color*, *opacity*, and *symbol* [scales](./scales.md). For example, the scatterplot below of body measurements of Olympic athletes includes a legend for its *color* scale, allowing the meaning of color to be interpreted by the reader. (The axes similarly document the meaning of the *x* and *y* position scales.)
3030

31-
:::plot defer
31+
:::plot defer https://observablehq.com/@observablehq/plot-olympians-scatterplot
3232
```js
3333
Plot.plot({
3434
color: {legend: true},
@@ -41,7 +41,7 @@ Plot.plot({
4141

4242
The legend above is a *swatches* legend because the *color* scale is *ordinal* (with a *categorical* scheme). When the *color* scale is continuous, a *ramp* legend with a smooth gradient is generated instead. The plot below of global average surface temperature ([GISTEMP](https://data.giss.nasa.gov/gistemp/)) uses a *diverging* *color* scale to indicate the deviation from the 1951–1980 average in degrees Celsius.
4343

44-
:::plot defer
44+
:::plot defer https://observablehq.com/@observablehq/plot-colored-scatterplot
4545
```js
4646
Plot.plot({
4747
color: {
@@ -78,7 +78,7 @@ Plot does not yet generate legends for the *r* (radius) scale or the *length* sc
7878

7979
If the **legend** [scale option](./scales.md#scale-options) is true, the default legend will be produced for the scale; otherwise, the meaning of the **legend** option depends on the scale: for quantitative color scales, it defaults to *ramp* but may be set to *swatches* for a discrete scale (most commonly for *threshold* color scales); for *ordinal* *color* scales and *symbol* scales, only the *swatches* value is supported.
8080

81-
<!-- TODO Describe the color and opacity options, and demo the symbol legend with a redundant color encoding. -->
81+
<!-- TODO Describe the color and opacity options. -->
8282

8383
Categorical and ordinal color legends are rendered as swatches, unless the **legend** option is set to *ramp*. The swatches can be configured with the following options:
8484

docs/features/plots.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ onMounted(() => {
2525

2626
To render a **plot** in Observable Plot, call [plot](#plot-options) (typically as `Plot.plot`), passing in the desired *options*. This function returns an SVG or HTML figure element.
2727

28-
:::plot
28+
:::plot https://observablehq.com/@observablehq/plot-hello-world
2929
```js
3030
Plot.plot({
3131
marks: [
@@ -70,7 +70,7 @@ Rather than baking data into JavaScript, use [JSON](https://en.wikipedia.org/wik
7070

7171
To use data with Plot, pass the data as the first argument to the mark constructor. We can then assign columns of data such as *Date* and *Close* to visual properties of the mark (or “channels”) such as horizontal↔︎ position **x** and vertical↕︎ position **y**.
7272

73-
:::plot defer
73+
:::plot defer https://observablehq.com/@observablehq/plot-first-line-chart
7474
```js
7575
Plot.plot({
7676
marks: [
@@ -82,7 +82,7 @@ Plot.plot({
8282

8383
A plot can have multiple marks, and each mark has its own data. For example, say we had a similar table `goog` representing the daily price of Google stock for the same period. Below, the <span style="border-bottom: solid 2px var(--vp-c-red);">red</span> line represents Google stock, while the <span style="border-bottom: solid 2px var(--vp-c-blue);">blue</span> line represents Apple stock.
8484

85-
:::plot defer
85+
:::plot defer https://observablehq.com/@observablehq/plot-layered-marks
8686
```js
8787
Plot.plot({
8888
marks: [
@@ -100,7 +100,7 @@ When comparing the performance of different stocks, we typically want to normali
100100

101101
Alternatively, the tables can be combined, say with a *Symbol* column to distinguish AAPL from GOOG. This allows the use of a categorical *color* scale and legend.
102102

103-
:::plot defer
103+
:::plot defer https://observablehq.com/@observablehq/plot-stocks-multiline-chart
104104
```js
105105
Plot.plot({
106106
color: {legend: true},
@@ -120,7 +120,7 @@ Each mark may be a nested array of marks, allowing composition. Marks may also b
120120

121121
Marks are drawn in the given order, with the last mark drawn on top. For example, below <span style="border-bottom: solid 2px var(--vp-c-green);">green</span> bars are drawn on top of <span style="border-bottom: solid 2px;">{{dark ? "white" : "black"}}</span> bars.
122122

123-
:::plot
123+
:::plot https://observablehq.com/@observablehq/plot-marks-z-order
124124
```js
125125
Plot.plot({
126126
x: {padding: 0.4},
@@ -157,7 +157,7 @@ The **aspectRatio** option, if not null, computes a default **height** such that
157157
</label>
158158
</p>
159159

160-
:::plot defer
160+
:::plot defer https://observablehq.com/@observablehq/plot-intro-to-aspectratio
161161
```js
162162
Plot.plot({
163163
grid: true,
@@ -184,7 +184,7 @@ Unitless numbers ([quirky lengths](https://www.w3.org/TR/css-values-4/#deprecate
184184

185185
If a **caption** is specified, Plot.plot wraps the generated SVG element in an HTML figure element with a figcaption, returning the figure. To specify an HTML caption, the caption can be specified as an HTML element, say using the [`html` tagged template literal](http://github.com/observablehq/htl); otherwise, the specified string represents text that will be escaped as needed.
186186

187-
:::plot
187+
:::plot https://observablehq.com/@observablehq/plot-caption
188188
```js
189189
Plot.plot({
190190
caption: "Figure 1. A chart with a caption.",

docs/features/scales.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ onMounted(() => {
4040

4141
When visualizing this data with a [line](../marks/line.md), the *x* scale is responsible for mapping dates to horizontal↔︎ positions. For example, 1880-01-01 might be mapped to *x* = 40 (on the left) and 2016-12-01 might be mapped to *x* = 620 (on the right). Likewise, the *y* scale maps temperature anomalies to vertical↕︎ positions.
4242

43-
:::plot
43+
:::plot https://observablehq.com/@observablehq/plot-scales-intro
4444
```js
4545
Plot.lineY(gistemp, {x: "Date", y: "Anomaly"}).plot()
4646
```
@@ -69,7 +69,7 @@ const maxAnomaly = d3.max(gistemp, (d) => d.Anomaly);
6969

7070
Scales aren’t limited to horizontal and vertical position. They can also output to color, radius, length, opacity, and more. For example if we switch to a [rule](../marks/rule.md) and use the **stroke** channel instead of **y**, we get a one-dimensional heatmap:
7171

72-
:::plot defer
72+
:::plot defer https://observablehq.com/@observablehq/plot-scales-intro
7373
```js
7474
Plot.ruleX(gistemp, {x: "Date", stroke: "Anomaly"}).plot()
7575
```
@@ -86,7 +86,7 @@ function color(anomaly) {
8686

8787
Within a given [plot](./plots.md), marks share scales. For example, if a plot has two line marks, such as the lines below visualizing the daily closing price of <span style="border-bottom: solid 2px var(--vp-c-red);">Google</span> and <span style="border-bottom: solid 2px var(--vp-c-blue);">Apple</span> stock, both share the same *x* and *y* scales for a consistent encoding.
8888

89-
:::plot defer
89+
:::plot defer https://observablehq.com/@observablehq/plot-layered-marks
9090
```js
9191
Plot.plot({
9292
marks: [
@@ -118,23 +118,23 @@ Let’s look at some examples to make this less abstract.
118118

119119
The domain of a quantitative scale is a continuous extent [*min*, *max*] where *min* and *max* are numbers, such as temperatures. Below, the first domain value (*x* = 0) corresponds to the left side of the plot while the second (*x* = 100) corresponds to the right side.
120120

121-
:::plot
121+
:::plot https://observablehq.com/@observablehq/plot-continuous-scales
122122
```js
123123
Plot.plot({x: {domain: [0, 100], grid: true}})
124124
```
125125
:::
126126

127127
Flipping the domain reverses the scale so that +*x* points ←left instead of right→.
128128

129-
:::plot
129+
:::plot https://observablehq.com/@observablehq/plot-continuous-scales
130130
```js
131131
Plot.plot({x: {domain: [100, 0], grid: true}})
132132
```
133133
:::
134134

135135
Alternatively, use the **reverse** option; this is convenient when the domain is implied from data rather than specified explicitly. (We’ll cover implied domains in more detail in the *inference* section below.)
136136

137-
:::plot
137+
:::plot https://observablehq.com/@observablehq/plot-continuous-scales
138138
```js
139139
Plot.plot({x: {domain: [0, 100], reverse: true, grid: true}})
140140
```
@@ -144,7 +144,7 @@ If the domain is dates, Plot will default to a UTC scale. This is a linear scale
144144

145145
<!-- Plot doesn’t parse dates; convert your strings to [Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) instances with [d3.utcParse](https://github.com/d3/d3-time-format#utcParse) or [d3.autoType](https://github.com/d3/d3-dsv#autoType). -->
146146

147-
:::plot
147+
:::plot https://observablehq.com/@observablehq/plot-continuous-scales
148148
```js
149149
Plot.plot({x: {domain: [new Date("2021-01-01"), new Date("2022-01-01")], grid: true}})
150150
```
@@ -156,61 +156,61 @@ We are working on better multi-line ticks for time scales; please upvote [#1285]
156156

157157
To force a UTC scale, say when the data is milliseconds since UNIX epoch rather than Date instances, pass *utc* as the **type** option. Though we recommend coercing strings and numbers to more specific types when you load data, rather than relying on scales to do it.
158158

159-
:::plot
159+
:::plot https://observablehq.com/@observablehq/plot-continuous-scales
160160
```js
161161
Plot.plot({x: {type: "utc", domain: [1609459200000, 1640995200000], grid: true}})
162162
```
163163
:::
164164

165165
If the scale **type** is *time*, the ticks will be in local time rather than UTC.
166166

167-
:::plot
167+
:::plot https://observablehq.com/@observablehq/plot-continuous-scales
168168
```js
169169
Plot.plot({x: {type: "time", domain: [new Date(2021, 0, 1), new Date(2022, 0, 1)], grid: true}})
170170
```
171171
:::
172172

173173
When plotting values that vary widely, such as the luminosity of stars in an [HR diagram](https://observablehq.com/@mbostock/hertzsprung-russell-diagram), a *log* scale may improve readability. Log scales default to base-10 ticks with SI-prefix notation.
174174

175-
:::plot
175+
:::plot https://observablehq.com/@observablehq/plot-continuous-scales
176176
```js
177177
Plot.plot({x: {type: "log", domain: [1e0, 1e5], grid: true}})
178178
```
179179
:::
180180

181181
If you prefer conventional notation, you can specify the **tickFormat** option to change the behavior of the axis. The **tickFormat** option can either be a [d3.format](https://github.com/d3/d3-format) string or a function that takes a tick value and returns the corresponding string. Note, however, that this may result in overlapping text.
182182

183-
:::plot
183+
:::plot https://observablehq.com/@observablehq/plot-continuous-scales
184184
```js
185185
Plot.plot({x: {type: "log", domain: [1e0, 1e5], tickFormat: ",", grid: true}})
186186
```
187187
:::
188188

189189
Log scales also support a **base** option, say for powers of two. This does not affect the scale’s encoding, but it does change where ticks are shown.
190190

191-
:::plot
191+
:::plot https://observablehq.com/@observablehq/plot-continuous-scales
192192
```js
193193
Plot.plot({x: {type: "log", base: 2, domain: [1e0, 1e4], ticks: 20, grid: true}})
194194
```
195195
:::
196196

197197
The domain of a log scale cannot include (or cross) zero; for this, consider a [bi-symmetric log](https://github.com/d3/d3-scale#symlog-scales) scale instead.
198198

199-
:::plot
199+
:::plot https://observablehq.com/@observablehq/plot-continuous-scales
200200
```js
201201
Plot.plot({x: {type: "symlog", domain: [-10, 10], grid: true}})
202202
```
203203
:::
204204

205205
Power scales and square-root scales are also supported. The *pow* scale supports the **exponent** option, which defaults to 1 (for a linear scale).
206206

207-
:::plot
207+
:::plot https://observablehq.com/@observablehq/plot-continuous-scales
208208
```js
209209
Plot.plot({x: {type: "sqrt", domain: [0, 100], grid: true}})
210210
```
211211
:::
212212

213-
:::plot
213+
:::plot https://observablehq.com/@observablehq/plot-continuous-scales
214214
```js
215215
Plot.plot({x: {type: "pow", exponent: 1 / 3, domain: [0, 100], grid: true}})
216216
```
@@ -224,15 +224,15 @@ Sadly, not all data is continuous: some data is merely ordinal, such as t-shirt
224224

225225
A *point* scale divides space into uniformly-spaced discrete values. It is commonly used for scatterplots (a [dot mark](../marks/dot.md)) of ordinal data. It is the default scale type for ordinal data on the *x* and *y* scale.
226226

227-
:::plot
227+
:::plot https://observablehq.com/@observablehq/plot-discrete-scales
228228
```js
229229
Plot.plot({x: {type: "point", domain: "ABCDEFGHIJ", grid: true}})
230230
```
231231
:::
232232

233233
A band scale divides space into uniformly-spaced and -sized discrete intervals. It is commonly used for bar charts (bar marks). To show the bands below, we use a [cell](../marks/cell.md) instead of a [grid](../marks/grid.md).
234234

235-
:::plot
235+
:::plot https://observablehq.com/@observablehq/plot-discrete-scales
236236
```js
237237
Plot
238238
.cell("ABCDEFGHIJ", {x: Plot.identity, stroke: "currentColor", strokeOpacity: 0.1})
@@ -255,7 +255,7 @@ While *point* and *band* scales appear visually similar when only the grid is vi
255255
</label>
256256
</p>
257257

258-
:::plot hidden
258+
:::plot hidden https://observablehq.com/@observablehq/plot-discrete-scales
259259
```js
260260
Plot.plot({
261261
grid: true,
@@ -273,7 +273,7 @@ Plot.plot({
273273
```
274274
:::
275275

276-
:::plot hidden
276+
:::plot hidden https://observablehq.com/@observablehq/plot-discrete-scales
277277
```js
278278
Plot.plot({
279279
grid: true,
@@ -434,7 +434,7 @@ Plot.plot({
434434

435435
Below we again show observed global surface temperatures. The reversed *BuRd* color scheme is used since <span :style="{borderBottom: `solid 2px ${d3.interpolateRdBu(0.9)}`}">blue</span> and <span :style="{borderBottom: `solid 2px ${d3.interpolateRdBu(0.1)}`}">red</span> are semantically associated with cold and hot, respectively.
436436

437-
:::plot
437+
:::plot https://observablehq.com/@observablehq/plot-colored-scatterplot
438438
```js
439439
Plot.plot({
440440
grid: true,
@@ -537,7 +537,7 @@ But wait, there’s more! 😅 Plot has *opacity*, *r*, *symbol*, and *length* s
537537
</label>
538538
</p>
539539

540-
:::plot
540+
:::plot https://observablehq.com/@observablehq/plot-radius-scale-range
541541
```js
542542
Plot.plot({
543543
r: {range: [0, radius]},
@@ -568,7 +568,7 @@ All position scales (*x*, *y*, *fx*, and *fy*) have implicit automatic ranges ba
568568

569569
The **transform** scale option allows you to apply a function to all values before they are passed through the scale. This is convenient for transforming a scale’s data, say to convert to thousands or between temperature units.
570570

571-
:::plot defer
571+
:::plot defer https://observablehq.com/@observablehq/plot-fahrenheit-to-celsius-scale-transform
572572
```js{5}
573573
Plot.plot({
574574
y: {
@@ -586,7 +586,7 @@ Plot.plot({
586586

587587
The **percent** scale option is shorthand for a **transform** that multiplies values by 100; it also adds a percent symbol (%) to the default label.
588588

589-
:::plot
589+
:::plot https://observablehq.com/@observablehq/plot-percent-scale-transform
590590
```js{2}
591591
Plot.plot({
592592
y: {percent: true}, // convert proportion [0, 1] to percent [0, 100]

0 commit comments

Comments
 (0)