Skip to content

Commit 97772b7

Browse files
authored
Merge pull request #188 from plotly/add-redux-example
Add redux example
2 parents 9020f1e + 4ef8aa3 commit 97772b7

25 files changed

+33482
-90
lines changed

README.md

Lines changed: 60 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -5,60 +5,61 @@
55
master
66
![master](https://circleci.com/gh/plotly/react-plotly.js-editor/tree/master.svg?style=svg&circle-token=df4574e01732846dba81d800d062be5f0fef5641)
77

8-
## Usage
9-
10-
Install the module with `npm install` or `yarn install`. See some examples
8+
## Installation
9+
10+
Install the module with `npm install` or `yarn install`.
11+
12+
## Quick Start
13+
14+
1. Create a quick project using `create-react-app`: `npm install -g
15+
create-react-app` | `create-react-app quick-start` | `cd quick-start` | `npm
16+
start`
17+
2. Install the needed modules: `npm install plotly.js react-plotly.js
18+
react-plotly.js-editor --save`
19+
3. Import css stylesheets: `import
20+
react-plotly.js-editor/lib/react-plotly.js-editor.css` and
21+
`react-select/dist/react-select.css`
22+
4. Decide how your application is going to manage state: higher level component
23+
(see
24+
[simple example](https://github.com/plotly/react-plotly.js-editor/tree/master/examples/simple))
25+
or with the help of a state management library like Redux (see
26+
[redux example](https://github.com/plotly/react-plotly.js-editor/tree/master/examples/redux))
27+
5. Your application will hold in its state:
28+
* the `graphDiv`, which is the dom element on which plotly.js attaches data
29+
and layout information,
30+
* the editorRevision number and plotRevision numbers, to prevent unneeded app
31+
rerenders
32+
* an object containing all dataSources (ex: `{col1: [1, 2, 3], col2: [4, 3,
33+
2], col3: [17, 13, 9]}`),
34+
* an array of all dataSourceOptions (ex: `[ {value: 'col1', label: 'CO2'},
35+
{value: 'col2', label: 'NO2'}, {value: 'col3', label: 'SiO2'} ]`)
36+
6. Initialize your application's state with the elements above. For the
37+
`graphDiv`, we can pass in an initial object containing data and layout,
38+
plotly.js (via a callback), will then update our state with the `graphDiv`
39+
dom element
40+
7. Write the callbacks that are going to update our application state:
41+
* handlePlotUpdate: should change the app state with the updated `graphDiv`
42+
and increase the editorRevision number
43+
* handleEditorUpdate: should increase the plotRevision number
44+
8. Render the Plot and Editor Components:
45+
* Plot component: is created with react-plotly.js with the
46+
createPlotComponent function and plotly.js as argument. It requires a few
47+
props:
48+
* data, layout, revision: from application state
49+
* onUpdate: the handlePlotUpdate callback created above
50+
* Editor component: is imported from `react-plotly.js-editor`, it requires
51+
these props:
52+
* dataSources, dataSourceOptions, graphDiv, revision: from application
53+
state
54+
* onUpdate: the handleEditorUpdate callback above
55+
* plotly: the plotly.js library
56+
* locale: if using the default locale 'en', it is not necessary to pass in
57+
this prop, more on locales later
58+
59+
See examples
1160
[here](https://github.com/plotly/react-plotly.js-editor/tree/master/examples).
1261

13-
## Overview
14-
15-
The Editor is composed of 3 layers:
16-
17-
### Layer 1: Base Component
18-
19-
```
20-
import PlotlyEditor from `react-plotly.js-editor`
21-
22-
<PlotlyEditor>
23-
```
24-
25-
The PlotlyEditor Component expects you to host the plotly.js figure and data
26-
sources somewhere in your application state. This can be done in a top-level
27-
react component, Redux or any other data flow pattern.
28-
29-
### Layer 2: Container Components
30-
31-
One or more nested Container Components with one and only one connected by a
32-
connect<Container>ToPlot function (connectLayoutToPlot, connectTraceToPlot).
33-
34-
```
35-
<Panel>, <Section>, <Fold>
36-
```
37-
38-
### Layer 3: Attribute Widgets
39-
40-
Each connected by a `connectContainerToPlot` function
41-
42-
```
43-
<Numeric>, <ColorPicker>, <Radio>
44-
```
45-
46-
Data flows via `context` downward and is augmented with additional information
47-
at each layer boundary.
48-
49-
The Base Components aggregate references to the graphDiv objects (data,
50-
fullData, layout...), grid Data sources, locale, update functions etc.
51-
52-
One of the Container Components uses its knowledge about which container to
53-
target (traces, layout, ...) to generate fewer but more specific containers and
54-
updaters which are passed down the hierarchy.
55-
56-
The Attribute widgets are higher-order wrappers around dumb UI controls. The
57-
higher-order wrapper uses the container contexts and specific attributes
58-
information to provide specific plot update functions and other behaviours for
59-
the inner UI control.
60-
61-
## Development
62+
## Development Setup
6263

6364
```
6465
git clone
@@ -69,22 +70,22 @@ react-plotly.js-editor$ npm run watch
6970
```
7071

7172
You can use `npm link` to link your local copy of the `react-plotly.js-editor`
72-
to your test repo. To do so run `npm link` before the `npm run watch` script
73-
mentioned above. Then in your development repo you can do `npm link
74-
react-plotly.js-editor` to use your local copy of the editor.
73+
to your test repo. To do so run `npm link` before `npm run watch`. Then in your
74+
development repo you can do `npm link react-plotly.js-editor` to use your local
75+
copy of the editor.
7576

7677
With `npm link` you can get some errors related to
7778
[multiple copies of react being loaded](https://github.com/facebookincubator/create-react-app/issues/1107).
7879
To get around this, you can create an
7980
[alias](https://github.com/facebookincubator/create-react-app/issues/393) that
8081
points your project to the copy of react that it should be using or you can
81-
simply do `rm -rf node_modules/react` and `rm -rf node_modules/react-dom` inside
82-
of the `react-plotly.js-editor` repository so that your project relies on the
83-
react and react-dom copy of your main project.
82+
simply remove `react` and `react-dom` from the package.json of the
83+
`react-plotly.js-editor` so that your project relies on the `react` and
84+
`react-dom` copy of your main project.
8485

8586
## See also
8687

87-
* [plotlyjs-react](https://github.com/plotly/plotlyjs-react)
88+
* [react-plotlyjs](https://github.com/plotly/react-plotly.js)
8889

8990
## License
9091

examples/async-data/package-lock.json

Lines changed: 114 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/async-data/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"react": "^15.6.1",
99
"react-dom": "^15.6.1",
1010
"react-plotly.js": "^1.0.4",
11-
"react-plotly.js-editor": "^0.1.0",
11+
"react-plotly.js-editor": "0.2.0-alpha.1",
1212
"react-scripts": "1.0.17"
1313
},
1414
"scripts": {

examples/async-data/src/App.css

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/async-data/src/App.test.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)