Skip to content

Commit 65e7255

Browse files
committed
Add redux example
1 parent 9020f1e commit 65e7255

File tree

17 files changed

+12997
-68
lines changed

17 files changed

+12997
-68
lines changed

README.md

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -5,60 +5,60 @@
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: more on this later
57+
58+
See examples
1159
[here](https://github.com/plotly/react-plotly.js-editor/tree/master/examples).
1260

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
61+
## Development Setup
6262

6363
```
6464
git clone
@@ -69,22 +69,22 @@ react-plotly.js-editor$ npm run watch
6969
```
7070

7171
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.
72+
to your test repo. To do so run `npm link` before `npm run watch`. Then in your
73+
development repo you can do `npm link react-plotly.js-editor` to use your local
74+
copy of the editor.
7575

7676
With `npm link` you can get some errors related to
7777
[multiple copies of react being loaded](https://github.com/facebookincubator/create-react-app/issues/1107).
7878
To get around this, you can create an
7979
[alias](https://github.com/facebookincubator/create-react-app/issues/393) that
8080
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.
81+
simply remove `react` and `react-dom` from the package.json of the
82+
`react-plotly.js-editor` so that your project relies on the `react` and
83+
`react-dom` copy of your main project.
8484

8585
## See also
8686

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

8989
## License
9090

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.

examples/redux/.gitignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# See https://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
6+
# testing
7+
/coverage
8+
9+
# production
10+
/build
11+
12+
# misc
13+
.DS_Store
14+
.env.local
15+
.env.development.local
16+
.env.test.local
17+
.env.production.local
18+
19+
npm-debug.log*
20+
yarn-debug.log*
21+
yarn-error.log*

0 commit comments

Comments
 (0)