Skip to content

Commit 4e79658

Browse files
riccardoscalcombostockFil
authored
Update pointer.md (#1898)
Include an illustrative code snippet demonstrating how to use the value of the plot element in an input event listener to react to pointing. --------- Co-authored-by: Mike Bostock <mbostock@gmail.com> Co-authored-by: Philippe Rivière <fil@rezo.net>
1 parent 158f8e3 commit 4e79658

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

docs/interactions/pointer.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,14 @@ The pointer transform supports “click-to-stick”: clicking on the chart locks
155155

156156
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.
157157

158+
```js
159+
const plot = Plot.plot(options);
160+
161+
plot.addEventListener("input", (event) => {
162+
console.log(plot.value);
163+
});
164+
```
165+
158166
## Pointer options
159167

160168
The following options control the pointer transform:

0 commit comments

Comments
 (0)