|
5 | 5 | master
|
6 | 6 | 
|
7 | 7 |
|
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 create-react-app` | `create-react-app quick-start` | `cd quick-start` | `npm start` |
15 |
| -2. Install the needed modules: `npm install plotly.js react-plotly.js react-plotly.js-editor --save` |
16 |
| -3. Import css stylesheets: `import react-plotly.js-editor/lib/react-plotly.js-editor.min.css`. |
17 |
| - * Interested in [theming](https://github.com/plotly/react-plotly.js-editor/tree/master/THEMING.md)? |
18 |
| - * Need to support IE11? import the IE css instead: `import react-plotly.js-editor/lib/react-plotly.js-editor.ie.min.css` |
19 |
| -4. Decide how your application is going to manage state: higher level component |
20 |
| - (see |
21 |
| - [simple example](https://github.com/plotly/react-plotly.js-editor/tree/master/examples/simple)) |
22 |
| - or with the help of a state management library like Redux (see |
23 |
| - [redux example](https://github.com/plotly/react-plotly.js-editor/tree/master/examples/redux)) |
24 |
| -5. Your application will hold in its state: |
| 8 | +## Quick start |
| 9 | + |
| 10 | +``` |
| 11 | +git clone [this repo] |
| 12 | +cd react-plotly.js-editor |
| 13 | +cd examples/simple |
| 14 | +npm install |
| 15 | +npm start |
| 16 | +``` |
| 17 | + |
| 18 | +See more examples |
| 19 | +[here](https://github.com/plotly/react-plotly.js-editor/tree/master/examples). |
| 20 | + |
| 21 | +## To consider |
| 22 | + |
| 23 | +1. Decide how your application is going to manage state: |
| 24 | + * via a higher level component (see [simple example](https://github.com/plotly/react-plotly.js-editor/tree/master/examples/simple)) |
| 25 | + * with a state management library like Redux (see |
| 26 | + [redux example](https://github.com/plotly/react-plotly.js-editor/tree/master/examples/redux)) |
| 27 | +2. Your application will need to hold in its state: |
25 | 28 | * the `graphDiv`, which is the dom element on which plotly.js attaches data
|
26 | 29 | and layout information,
|
27 | 30 | * the editorRevision number and plotRevision numbers, to prevent unneeded app
|
28 | 31 | rerenders
|
29 | 32 | * an object containing all dataSources (ex: `{col1: [1, 2, 3], col2: [4, 3, 2], col3: [17, 13, 9]}`),
|
30 | 33 | * an array of all dataSourceOptions (ex: `[ {value: 'col1', label: 'CO2'}, {value: 'col2', label: 'NO2'}, {value: 'col3', label: 'SiO2'} ]`)
|
31 |
| -6. Initialize your application's state with the elements above. For the |
| 34 | +3. Initialize your application's state with the elements above. For the |
32 | 35 | `graphDiv`, we can pass in an initial object containing data and layout,
|
33 | 36 | plotly.js (via a callback), will then update our state with the `graphDiv`
|
34 | 37 | dom element
|
35 |
| -7. Write the callbacks that are going to update our application state: |
36 |
| - * handlePlotUpdate: should change the app state with the updated `graphDiv` |
| 38 | +4. Provide onUpdate callbacks to update the application's state: |
| 39 | + * Plot component's onUpdate prop: should change the app state with the updated `graphDiv` |
37 | 40 | and increase the editorRevision number
|
38 |
| - * handleEditorUpdate: should increase the plotRevision number |
39 |
| -8. Render the Plot and Editor Components: |
| 41 | + * Editor component's onUpdate prop: should increase the plotRevision number |
| 42 | +5. Render the Plot and Editor Components: |
40 | 43 | * Plot component: is created with react-plotly.js with the
|
41 | 44 | createPlotComponent function and plotly.js as argument. It requires a few
|
42 | 45 | props:
|
43 | 46 | * data, layout, revision: from application state
|
44 |
| - * onUpdate: the handlePlotUpdate callback created above |
| 47 | + * onUpdate: callback that updates state with new graphDiv and editorRevision number |
45 | 48 | * Editor component: is imported from `react-plotly.js-editor`, it requires
|
46 | 49 | these props:
|
47 | 50 | * dataSources, dataSourceOptions, graphDiv, revision: from application
|
48 | 51 | state
|
49 |
| - * onUpdate: the handleEditorUpdate callback above |
| 52 | + * onUpdate: callback that updates state new plotRevision number |
50 | 53 | * plotly: the plotly.js library
|
51 | 54 | * locale: if using the default locale 'en', it is not necessary to pass in
|
52 | 55 | this prop, more on locales later
|
53 | 56 |
|
54 |
| -See examples |
55 |
| -[here](https://github.com/plotly/react-plotly.js-editor/tree/master/examples). |
| 57 | +## Styling |
56 | 58 |
|
57 |
| -## Development Setup |
| 59 | +* Import editor styles with `import react-plotly.js-editor/lib/react-plotly.js-editor.min.css` |
| 60 | +* Interested in [theming](https://github.com/plotly/react-plotly.js-editor/tree/master/THEMING.md)? |
| 61 | +* Need to support IE11? import the IE css instead: `import react-plotly.js-editor/lib/react-plotly.js-editor.ie.min.css` |
58 | 62 |
|
59 |
| -``` |
60 |
| -git clone |
61 |
| -cd react-plotly.js-editor |
62 |
| -react-plotly.js-editor$ npm install |
63 |
| -react-plotly.js-editor$ npm run make:lib |
64 |
| -react-plotly.js-editor$ npm run watch |
65 |
| -``` |
| 63 | +## Development Setup |
66 | 64 |
|
67 |
| -You can use `npm link` to link your local copy of the `react-plotly.js-editor` |
68 |
| -to your test repo. To do so run `npm link` before `npm run watch`. Then in your |
69 |
| -development repo you can do `npm link react-plotly.js-editor` to use your local |
70 |
| -copy of the editor. |
| 65 | +You can use `npm link` to link your local copy of the `react-plotly.js-editor` to your test repo. |
71 | 66 |
|
72 | 67 | With `npm link` you can get some errors related to
|
73 | 68 | [multiple copies of react being loaded](https://github.com/facebookincubator/create-react-app/issues/1107).
|
74 | 69 | To get around this, you can create an
|
75 | 70 | [alias](https://github.com/facebookincubator/create-react-app/issues/393) that
|
76 | 71 | points your project to the copy of react that it should be using or you can
|
77 |
| -simply remove `react` and `react-dom` from the package.json of the |
78 |
| -`react-plotly.js-editor` so that your project relies on the `react` and |
79 |
| -`react-dom` copy of your main project. |
| 72 | +simply remove `react` and `react-dom` from `react-plotly.js-editor`. |
80 | 73 |
|
81 | 74 | ## See also
|
82 | 75 |
|
| 76 | +* [plotly.js](https://github.com/plotly/plotly.js) |
83 | 77 | * [react-plotlyjs](https://github.com/plotly/react-plotly.js)
|
84 | 78 |
|
85 | 79 | ## License
|
|
0 commit comments