Skip to content

Commit 324a1f6

Browse files
Filmbostock
andauthored
more example links (#1644)
Co-authored-by: Mike Bostock <[email protected]>
1 parent a091f70 commit 324a1f6

File tree

5 files changed

+39
-21
lines changed

5 files changed

+39
-21
lines changed

docs/features/facets.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ The **facet** margin options behave largely the same as the margin [plot options
274274

275275
The **facet** plot option is also an alternative to the **fx** and **fy** mark options. It is useful when multiple marks share the same data; the **x** and **y** facet channels are then shared by all marks that use the facet data. (Other marks will be repeated across facets.) For example, we can visualize the famous [Anscombe’s quartet](https://en.wikipedia.org/wiki/Anscombe's_quartet) as a scatterplot with horizontal facets.
276276

277-
:::plot
277+
:::plot https://observablehq.com/@observablehq/plot-anscombes-quartet
278278
```js
279279
Plot.plot({
280280
grid: true,

docs/features/interactions.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ When looking at a scatterplot, the reader may wonder, *what abstract values does
2525

2626
The [pointer transform](../interactions/pointer.md) can provide an answer: it dynamically [filters](../transforms/filter.md) a mark such that only the data closest to the pointer (such as the mouse) is rendered. The pointer transform is often paired with the [tip mark](../marks/tip.md) for interactive tooltips, revealing exact values as the pointer moves over the plot. The tip can show additional fields not otherwise visible, such as the *name* and *sport* of Olympic athletes below.
2727

28-
:::plot defer
28+
:::plot defer https://observablehq.com/@observablehq/scatterplot-with-interactive-tips
2929
```js
3030
Plot.dot(olympians, {
3131
x: "weight",
@@ -39,7 +39,7 @@ Plot.dot(olympians, {
3939

4040
The [crosshair mark](../interactions/crosshair.md) uses the pointer transform internally to display a [rule](../marks/rule.md) and a [text](../marks/text.md) showing the **x** (horizontal↔︎ position) and **y** (vertical↕︎ position) value of the nearest data.
4141

42-
:::plot defer
42+
:::plot defer https://observablehq.com/@observablehq/plot-crosshair
4343
```js
4444
Plot.plot({
4545
marks: [
@@ -70,6 +70,6 @@ With the exception of render transforms (see the [pointer transform](https://git
7070

7171
That said, you can simply throw away an old plot and replace it with a new one! This allows plotting of dynamic data: data which can change in real-time as it streams in, or because it is derived in response to external inputs such as range sliders and search boxes.
7272

73-
On Observable, you can use [viewof](https://observablehq.com/@observablehq/views) in conjunction with [Observable Inputs](https://observablehq.com/@observablehq/inputs) for interactivity. If your cell references another cell, it will automatically re-run whenever the upstream cell’s value changes. For example, try dragging the slider in this [hexbin example](https://observablehq.com/@observablehq/plot-hexbin-binwidth?intent=fork). In React, use [useEffect](https://react.dev/reference/react/useEffect) and [useRef](https://react.dev/reference/react/useRef) to re-render the plot when data changes. In Vue, use [ref](https://vuejs.org/api/reactivity-core.html#ref). For more, see our [getting started guide](../getting-started.md).
73+
On Observable, you can use [viewof](https://observablehq.com/@observablehq/views) in conjunction with [Observable Inputs](https://observablehq.com/@observablehq/inputs) (or other plots!) for interactivity. If your cell references another cell, it will automatically re-run whenever the upstream cell’s value changes. For example, try dragging the slider in this [hexbin example](https://observablehq.com/@observablehq/plot-hexbin-binwidth?intent=fork). In React, use [useEffect](https://react.dev/reference/react/useEffect) and [useRef](https://react.dev/reference/react/useRef) to re-render the plot when data changes. In Vue, use [ref](https://vuejs.org/api/reactivity-core.html#ref). For more, see our [getting started guide](../getting-started.md).
7474

7575
You can also manipulate the SVG that Plot creates, if you are comfortable using lower-level APIs; see examples by [Mike Freeman](https://observablehq.com/@mkfreeman/plot-animation) and [Philippe Rivière](https://observablehq.com/@fil/plot-animate-a-bar-chart).

docs/interactions/crosshair.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import penguins from "../data/penguins.ts";
1212

1313
The **crosshair mark** shows the *x* (horizontal↔︎ position) and *y* (vertical↕︎ position) value of the point closest to the [pointer](./pointer.md) on the bottom and left sides of the frame, respectively.
1414

15-
:::plot defer
15+
:::plot defer https://observablehq.com/@observablehq/plot-crosshair
1616
```js
1717
Plot.plot({
1818
marks: [
@@ -25,7 +25,7 @@ Plot.plot({
2525

2626
For charts which have a “dominant” dimension, such as time in a time-series chart, use the crosshairX or crosshairY mark for the [pointerX](./pointer.md#pointerx-options) or [pointerY](./pointer.md#pointery-options) transform as appropriate.
2727

28-
:::plot defer
28+
:::plot defer https://observablehq.com/@observablehq/plot-crosshairx
2929
```js
3030
Plot.plot({
3131
marks: [
@@ -38,7 +38,7 @@ Plot.plot({
3838

3939
If either **x** or **y** is not specified, the crosshair is one-dimensional.
4040

41-
:::plot defer
41+
:::plot defer https://observablehq.com/@observablehq/plot-one-dimensional-crosshair
4242
```js
4343
Plot.plot({
4444
marks: [
@@ -51,7 +51,7 @@ Plot.plot({
5151

5252
The **color** option sets the fill color of the text and the stroke color of the rule. This option can be specified as a channel to reinforce a color encoding.
5353

54-
:::plot defer
54+
:::plot defer https://observablehq.com/@observablehq/plot-colored-crosshair
5555
```js
5656
Plot.plot({
5757
marks: [
@@ -91,3 +91,19 @@ Plot.crosshair(cars, {x: "economy (mpg)", y: "cylinders"})
9191
```
9292

9393
Returns a new crosshair for the given *data* and *options*, drawing horizontal and vertical rules. The corresponding **x** and **y** values are also drawn just outside the bottom and left sides of the frame, respectively, typically on top of the axes. If either **x** or **y** is not specified, the crosshair will be one-dimensional.
94+
95+
## crosshairX(*data*, *options*)
96+
97+
```js
98+
Plot.crosshairX(aapl, {x: "Date", y: "Close"})
99+
```
100+
101+
Like crosshair, but using [pointerX](./pointer.md#pointerx-options) when *x* is the dominant dimension, like time in a time-series chart.
102+
103+
## crosshairY(*data*, *options*)
104+
105+
```js
106+
Plot.crosshairY(aapl, {x: "Date", y: "Close"})
107+
```
108+
109+
Like crosshair, but using [pointerY](./pointer.md#pointery-options) when *y* is the dominant dimension.

docs/interactions/pointer.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ To demonstrate, below the pointer transform filters a filled <span style="border
3434
</label>
3535
</p>
3636

37-
:::plot defer hidden
37+
:::plot defer hidden https://observablehq.com/@observablehq/plot-pointer-transform
3838
```js
3939
Plot.plot({
4040
marks: [
@@ -74,7 +74,7 @@ The pointer transform is similar to the [filter](../transforms/filter.md) and [s
7474

7575
The pointer transform supports both one- and two-dimensional pointing modes. The two-dimensional mode, [pointer](#pointer-options-1), is used above and is suitable for scatterplots and the general case: it finds the point closest to the pointer by measuring distance in *x* and *y*. The one-dimensional modes, [pointerX](#pointerx-options) and [pointerY](#pointery-options), in contrast only consider distance in one dimension; this is desirable when a chart has a “dominant” dimension, such as time in a time-series chart, the binned quantitative dimension in a histogram, or the categorical dimension of a bar chart.
7676

77-
Try the different modes on the line chart below to get a feel for how their behavior.
77+
Try the different modes on the line chart below to get a feel for their behavior.
7878

7979
<p>
8080
<span class="label-input">
@@ -85,15 +85,15 @@ Try the different modes on the line chart below to get a feel for how their beha
8585
</span>
8686
</p>
8787

88-
:::plot defer
88+
:::plot defer https://observablehq.com/@observablehq/plot-pointer-modes-x-y-and-xy
8989
```js-vue
9090
Plot.lineY(aapl, {x: "Date", y: "Close", tip: "{{linetip}}"}).plot()
9191
```
9292
:::
9393

9494
“One-dimensional” is a slight misnomer: the pointerX and pointerY transforms consider distance in both dimensions, but the distance along the non-dominant dimension is divided by 100. Below, the pointerX transform is applied to a multi-series line chart; the closest point in *x* is chosen, while *y* is used to “break ties” such that you can focus different series by moving the mouse vertically.
9595

96-
:::plot defer
96+
:::plot defer https://observablehq.com/@observablehq/plot-multi-series-line-chart-interactive-tips
9797
```js
9898
Plot.plot({
9999
marks: [
@@ -114,7 +114,7 @@ One-dimensional pointing makes even small bars or rects easily hoverable. If you
114114
</span>
115115
</p>
116116

117-
:::plot defer
117+
:::plot defer https://observablehq.com/@observablehq/plot-one-dimensional-pointing
118118
```js-vue
119119
Plot.plot({
120120
x: {label: "Daily volume (log₁₀)"},
@@ -134,7 +134,7 @@ The pointer transform will prefer the midpoint of the **x1** and **x2** channels
134134

135135
The **px** and **py** channels may be used to specify pointing target positions independent of the displayed mark. Below, text in the top-left corner shows the focused date and closing price. The focused point is also highlighted with a red dot and rule.
136136

137-
:::plot defer
137+
:::plot defer https://observablehq.com/@observablehq/plot-pointer-target-position
138138
```js
139139
Plot.plot({
140140
height: 160,
@@ -153,6 +153,8 @@ As the above chart shows, a plot can have multiple pointer transforms. Each poin
153153

154154
The pointer transform supports “click-to-stick”: clicking on the chart locks the currently-focused point until you click again. By locking the pointer, you can select text from the tip for copy and paste. If a plot has multiple pointer transforms, clicking will lock all pointer transforms.
155155

156+
The pointer transform emits an [*input* event](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/input_event) whenever the focused points changes, and sets the value of the plot element to the focused data. This allows you to use a plot as an [Observable view](https://observablehq.com/@observablehq/views) (viewof), or to register an *input* event listener to react to pointing.
157+
156158
## Pointer options
157159

158160
The following options control the pointer transform:

docs/marks/tip.md

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

2727
The **tip mark** displays text, or several name-value pairs, in a floating box anchored to a given position in **x** and **y**. The tip mark is often paired with the [pointer transform](../interactions/pointer.md) to reveal details on demand when hovering over a chart, as in this line chart of Apple stock price:
2828

29-
:::plot defer
29+
:::plot defer https://observablehq.com/@observablehq/plot-line-chart-interactive-tip
3030
```js
3131
Plot.lineY(aapl, {x: "Date", y: "Close", tip: true}).plot({y: {grid: true}})
3232
```
@@ -46,7 +46,7 @@ Plot.plot({
4646

4747
The tip mark can also be used for static annotations, say to draw attention to elements of interest or to add context. The tip text is supplied via the **title** channel. If the tip mark‘s data is an array of strings, the **title** channel defaults to [identity](../features/transforms.md#identity).
4848

49-
:::plot defer
49+
:::plot defer https://observablehq.com/@observablehq/plot-static-annotations
5050
```js
5151
Plot.plot({
5252
y: {grid: true},
@@ -69,7 +69,7 @@ When using the **title** channel, the tip mark wraps text to 20 ems by default,
6969

7070
The **title** channel can be used with interactive tips, too. If you have a few moments, hover the chart below to read about various athletes who competed at Rio 2016.
7171

72-
:::plot defer
72+
:::plot defer https://observablehq.com/@observablehq/plot-tips-longer-text
7373
```js
7474
Plot.plot({
7575
grid: true,
@@ -95,7 +95,7 @@ Plot.plot({
9595

9696
If no **title** channel is supplied, the tip mark displays all channel values. You can supply additional name-value pairs by registering extra channels using the **channels** mark option. In the scatterplot of Olympic athletes below, you can hover to see the *name* and *sport* of each athlete. This is helpful for noticing patterns—tall basketball players, giant weightlifters and judoka, diminutive gymnasts—and for seeing individuals.
9797

98-
:::plot defer
98+
:::plot defer https://observablehq.com/@observablehq/plot-tips-additional-channels
9999
```js
100100
Plot.dot(olympians, {
101101
x: "weight",
@@ -115,15 +115,15 @@ If a channel is bound to the *color* or *opacity* scale, the tip mark displays a
115115

116116
The tip mark recognizes that **x1** & **x2** and **y1** & **y2** are paired channels. Below, observe that the *weight* shown in the tip is a range such as 64–66 kg; however, the *frequency* is shown as the difference between the **y1** and **y2** channels. The latter is achieved by the stack transform setting a channel hint to indicate that **y1** and **y2** represent a length.
117117

118-
:::plot defer
118+
:::plot defer https://observablehq.com/@observablehq/plot-tips-paired-channels
119119
```js
120120
Plot.rectY(olympians, Plot.binX({y: "count"}, {x: "weight", fill: "sex", tip: true})).plot()
121121
```
122122
:::
123123

124124
This even works when stacking negative values, say to mirror the histogram instead of stacking it. (The tip displays negative frequency, but this is consistent with the *y* axis.)
125125

126-
:::plot defer
126+
:::plot defer https://observablehq.com/@observablehq/plot-tips-paired-channels
127127
```js
128128
Plot.rectY(olympians, Plot.binX({y: "sum"}, {x: "weight", y: (d) => d.sex === "male" ? 1 : -1, fill: "sex", tip: true})).plot({y: {label: "Frequency"}})
129129
```
@@ -156,7 +156,7 @@ If you don’t specify an **anchor**, the tip mark will choose one automatically
156156

157157
The tip mark is compatible with transforms that derive **x** and **y** dynamically from data, such as the [centroid transform](../transforms/centroid.md) which computes polygon centroids. Below, a map of the United States shows state names. We reduce the size of the tips by setting the **textPadding** option to 3 pixels instead of the default 8.
158158

159-
:::plot defer
159+
:::plot defer https://observablehq.com/@observablehq/plot-maps-tips
160160
```js
161161
Plot.plot({
162162
projection: "albers-usa",

0 commit comments

Comments
 (0)