You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This component will refresh the plot via [`Plotly.react`](https://plot.ly/javascript/plotlyjs-function-reference/#plotlyreact) if any of the following are true:
104
+
This component will refresh the plot via [`Plotly.react`](https://plotly.com/javascript/plotlyjs-function-reference/#plotlyreact) if any of the following are true:
111
105
112
106
- The `revision` prop is defined and has changed, OR;
113
107
- One of `data`, `layout` or `config` has changed identity as checked via a shallow `===`, OR;
114
108
- The number of elements in `frames` has changed
115
109
116
-
Furthermore, when called, [`Plotly.react`](https://plot.ly/javascript/plotlyjs-function-reference/#plotlyreact) will only refresh the data being plotted if the _identity_ of the data arrays (e.g. `x`, `y`, `marker.color` etc) has changed, or if `layout.datarevision` has changed.
110
+
Furthermore, when called, [`Plotly.react`](https://plotly.com/javascript/plotlyjs-function-reference/#plotlyreact) will only refresh the data being plotted if the _identity_ of the data arrays (e.g. `x`, `y`, `marker.color` etc) has changed, or if `layout.datarevision` has changed.
117
111
118
-
In short, this means that simply adding data points to a trace in `data` or changing a value in `layout` will not cause a plot to update unless this is done immutably via something like [immutability-helper](https://github.com/kolodny/immutability-helper) if performance considerations permit it, or unless `revision` and/or [`layout.datarevision`](https://plot.ly/javascript/reference/#layout-datarevision) are used to force a rerender.
112
+
In short, this means that simply adding data points to a trace in `data` or changing a value in `layout` will not cause a plot to update unless this is done immutably via something like [immutability-helper](https://github.com/kolodny/immutability-helper) if performance considerations permit it, or unless `revision` and/or [`layout.datarevision`](https://plotly.com/javascript/reference/#layout-datarevision) are used to force a rerender.
119
113
120
114
## API Reference
121
115
@@ -125,10 +119,10 @@ In short, this means that simply adding data points to a trace in `data` or chan
|`data`|`Array`|`[]`| list of trace objects (see https://plot.ly/javascript/reference/)|
129
-
|`layout`|`Object`|`undefined`| layout object (see https://plot.ly/javascript/reference/#layout)|
130
-
|`frames`|`Array`|`undefined`| list of frame objects (see https://plot.ly/javascript/reference/)|
131
-
|`config`|`Object`|`undefined`| config object (see https://plot.ly/javascript/configuration-options/)|
122
+
|`data`|`Array`|`[]`| list of trace objects (see https://plotly.com/javascript/reference/)|
123
+
|`layout`|`Object`|`undefined`| layout object (see https://plotly.com/javascript/reference/#layout)|
124
+
|`frames`|`Array`|`undefined`| list of frame objects (see https://plotly.com/javascript/reference/)|
125
+
|`config`|`Object`|`undefined`| config object (see https://plotly.com/javascript/configuration-options/)|
132
126
|`revision`|`Number`|`undefined`| When provided, causes the plot to update when the revision is incremented. |
133
127
|`onInitialized`|`Function(figure, graphDiv)`|`undefined`| Callback executed after plot is initialized. See below for parameter information. |
134
128
|`onUpdate`|`Function(figure, graphDiv)`|`undefined`| Callback executed when a plot is updated due to new data or layout, or when user interacts with a plot. See below for parameter information. |
@@ -140,7 +134,11 @@ In short, this means that simply adding data points to a trace in `data` or chan
140
134
|`debug`|`Boolean`|`false`| Assign the graph div to `window.gd` for debugging |
141
135
|`useResizeHandler`|`Boolean`|`false`| When true, adds a call to `Plotly.Plot.resize()` as a `window.resize` event handler |
142
136
143
-
**Note**: To make a plot responsive, i.e. to fill its containing element and resize when the window is resized, use `style` or `className` to set the dimensions of the element (i.e. using `width: 100%; height: 100%` or some similar values) and set `useResizeHandler` to `true` while setting `layout.autosize` to `true` and leaving `layout.height` and `layout.width` undefined. This can be seen in action in [this CodePen](https://codepen.io/nicolaskruchten/pen/ERgBZX) and will implement the behaviour documented here: https://plot.ly/javascript/responsive-fluid-layout/
137
+
**Refs**: a `ref` attached to `<Plot>` resolves to the rendered `<div>` element (the plotly graph div), so you can call low-level plotly.js APIs against it directly (e.g. `Plotly.toImage(ref.current)`).
138
+
139
+
**TypeScript**: this package ships its own declaration files. Trace and layout shapes are typed as `unknown` since the wrapper does not bind to a specific plotly.js type surface; consumers wanting tighter typing on the `data` / `layout` props can re-declare them locally.
140
+
141
+
**Note**: To make a plot responsive, i.e. to fill its containing element and resize when the window is resized, use `style` or `className` to set the dimensions of the element (i.e. using `width: 100%; height: 100%` or some similar values) and set `useResizeHandler` to `true` while setting `layout.autosize` to `true` and leaving `layout.height` and `layout.width` undefined. A short example is in the [Responsive plot](#responsive-plot) section below. See also the [responsive layout reference](https://plotly.com/javascript/responsive-fluid-layout/).
To make the plot fill its container and resize with the window, leave the layout's `width`/`height` unset, enable `autosize`, and turn on `useResizeHandler`. Size the wrapper `<div>` with `style` or `className`:
All [plotly.js events](https://plotly.com/javascript/plotlyjs-events/) are surfaced as `on<EventName>` props (see the [Event handler props](#event-handler-props) table). Each handler receives the raw plotly.js event payload:
By default, the `Plot` component exported by this library loads a precompiled version of all of `plotly.js`, so `plotly.js` must be installed as a peer dependency. This bundle is around 6Mb unminified, and minifies to just over 2Mb.
For quick one-off demos on [CodePen](https://codepen.io/) or [JSFiddle](https://jsfiddle.net/), you may wish to just load the component directly as a script tag. We don't host the bundle directly, so you should never rely on this to work forever or in production, but you can use a third-party service to load the factory version of the component from, for example, [https://unpkg.com/react-plotly.js@latest/dist/create-plotly-component.min.js](https://unpkg.com/react-plotly.js@latest/dist/create-plotly-component.min.js).
211
-
212
-
You can load plotly.js and the component factory with:
287
+
For quick one-off demos in JSFiddle or similar environments, you can load the component directly as a script tag. We don't host the bundle ourselves, so don't rely on this in production, but you can pull it from a CDN such as [unpkg](https://unpkg.com) or [jsdelivr](https://www.jsdelivr.com):
React is pinned to 18 here because React 19 stopped shipping UMD builds; consumers wanting React 19 should load it via [importmap](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap) or use a bundler.
297
+
298
+
The factory is exposed as the global `createPlotlyComponent`. Build the component and mount it:
To transpile from ES2015 + JSX into the ES5 npm-distributed version:
318
+
To build the published artifacts (`dist/index.{mjs,cjs}`, `dist/factory.{mjs,cjs}`, the UMD bundle, and the declaration files) via [tsup](https://tsup.egoist.dev/):
244
319
245
320
```bash
246
-
$ npm run prepublishOnly
321
+
$ npm run build
247
322
```
248
323
249
-
To run the tests:
324
+
To run lint + typecheck + jest:
250
325
251
326
```bash
252
327
$ npm run test
253
328
```
254
329
330
+
To watch source files and rebuild on change:
331
+
332
+
```bash
333
+
$ npm run watch
334
+
```
335
+
336
+
Releases are cut from `master` per the steps in [`RELEASE.md`](./RELEASE.md).
0 commit comments