Skip to content

Commit 34681a7

Browse files
readme and props passthrough
1 parent 166e1a2 commit 34681a7

File tree

2 files changed

+8
-50
lines changed

2 files changed

+8
-50
lines changed

README.md

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -28,55 +28,7 @@ See more examples
2828

2929
## Overview
3030

31-
This module's entry point is a React component called `<PlotlyEditor />` which connects to a [plotly.js](https://plot.ly/javascript/)-powered `<Plot />` component care of [`react-plotly.js`](https://github.com/plotly/react-plotly.js). A plotly.js plot is defined by a JSON-serializable object called a _figure_. `<PlotlyEditor />` accepts as children React components whose descendents are input elements wrapped via `connectToContainer()` calls so as to bind them to the `<Plot />`'s figure's values. If no children are passed to the `<PlotlyEditor />`, the `<DefaultEditor />` is used. This module also exposes the [building block components](#Built-in-Components) that comprise the `<DefaultEditor />` so that developers can create their own customized editors.
32-
33-
## Connecting `<PlotlyEditor />` to `<Plot />`
34-
35-
The binding between `<PlotlyEditor />` and `<Plot />` works a little differently that in most React apps because plotly.js mutates its properties. This is mapped onto React's one-way dataflow model via event handlers and shared revision numbers which trigger re-renders of mutated state. The following subset of the [simple example](https://github.com/plotly/react-chart-editor/tree/master/examples/simple) shows how this works using a parent component to store state, but the principle is the same with a different state-manage approach, as shown in the [redux example](https://github.com/plotly/react-chart-editor/tree/master/examples/redux):
36-
37-
```javascript
38-
import PlotlyEditor from 'react-chart-editor';
39-
import Plot from 'react-plotly.js';
40-
41-
class App extends Component {
42-
constructor() {
43-
super();
44-
this.state = {graphDiv: {}, editorRevision: 0, plotRevision: 0};
45-
}
46-
47-
handlePlotUpdate(graphDiv) {
48-
this.setState(({editorRevision: x}) => ({editorRevision: x + 1, graphDiv}));
49-
}
50-
51-
handleEditorUpdate() {
52-
this.setState(({plotRevision: x}) => ({plotRevision: x + 1}));
53-
}
54-
55-
render() {
56-
return (
57-
<div>
58-
<PlotlyEditor
59-
graphDiv={this.state.graphDiv}
60-
onUpdate={this.handleEditorUpdate.bind(this)}
61-
revision={this.state.editorRevision}
62-
{...snip}
63-
/>
64-
<Plot
65-
data={this.state.graphDiv.data}
66-
layout={this.state.graphDiv.layout}
67-
onUpdate={this.handlePlotUpdate.bind(this)}
68-
revision={this.state.plotRevision}
69-
{...snip}
70-
/>
71-
</div>
72-
);
73-
}
74-
}
75-
```
76-
77-
## Data Management
78-
79-
`<PlotlyEditor />` accepts a `dataSources` property which is an object of arrays of data, as well as a `dataSourceOptions` property which contains metadata about the `dataSources`, such as human-readable labels used to populate input elements like dropdown menus. `<PlotlyEditor />` treats these properties as immutable so any changes to them will trigger a rerender, and accepts an `onUpdateTraces` event handler property which is called whenever it needs to access a column from `dataSources`, enabling asynchronous data loading e.g. from remote APIs. The [async-data example](https://github.com/plotly/react-chart-editor/tree/master/examples/async-data) shows how this is done using a dummy asynchronous back-end proxy.
31+
This module's entry point is a React component called `<PlotlyEditor />` which connects an instance of `<EditorControls />` to a [plotly.js](https://plot.ly/javascript/)-powered `<Plot />` component care of [`react-plotly.js`](https://github.com/plotly/react-plotly.js). `<PlotlyEditor />` accepts as children React components whose descendents are input elements wrapped via `connectToContainer()` calls so as to bind them to the `<Plot />`'s figure's values. If no children are passed to the `<PlotlyEditor />`, the `<DefaultEditor />` is used. This module also exposes the [building block components](#Built-in-Components) that comprise the `<DefaultEditor />` so that developers can create their own customized editors.
8032

8133
## Styling the `<DefaultEditor />` and the built-in components
8234

@@ -198,7 +150,7 @@ For use in containers bound to annotations e.g. as children of `<AnnotationAccor
198150

199151
To use Satellite Maps in the Editor, [Mapbox access tokens](https://www.mapbox.com/help/how-access-tokens-work/) are required.
200152

201-
Once you have your tokens, you can provide it as a config prop to the `react-plotly.js` generated `Plot` component: `<Plot config={{mapboxAccessToken: 'your token'}}/>`
153+
Once you have your tokens, you can provide it as a config prop to the `<PlotlyEditor />` component: `<PlotlyEditor config={{mapboxAccessToken: 'your token'}}/>`
202154

203155
## See also
204156

src/PlotlyEditor.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class PlotlyEditor extends Component {
2020
plotly={this.props.plotly}
2121
onUpdate={this.props.onUpdate}
2222
advancedTraceTypeSelector={this.props.advancedTraceTypeSelector}
23+
locale={this.props.locale}
24+
traceTypesConfig={this.props.traceTypesConfig}
25+
dictionaries={this.props.dictionaries}
2326
>
2427
{this.props.children}
2528
</EditorControls>
@@ -56,6 +59,9 @@ PlotlyEditor.propTypes = {
5659
useResizeHandler: PropTypes.bool,
5760
debug: PropTypes.bool,
5861
advancedTraceTypeSelector: PropTypes.bool,
62+
locale: PropTypes.string,
63+
traceTypesConfig: PropTypes.object,
64+
dictionaries: PropTypes.object,
5965
};
6066

6167
export default PlotlyEditor;

0 commit comments

Comments
 (0)