Skip to content

Commit 0d2e6ea

Browse files
integrated development environment (#263)
1 parent 19fe63e commit 0d2e6ea

File tree

8 files changed

+9527
-2202
lines changed

8 files changed

+9527
-2202
lines changed

README.md

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Check out the [live demo here](https://plotly.github.io/react-plotly.js-editor/)
1313

1414
## Quick start
1515

16-
Check out the demo of the `DefaultEditor` at https://plotly.github.io/react-plotly.js-editor/ or run it locally with:
16+
Check out the demo of the latest release of the `DefaultEditor` at https://plotly.github.io/react-plotly.js-editor/ or run it locally with:
1717

1818
```
1919
git clone [this repo]
@@ -86,32 +86,10 @@ class App extends Component {
8686

8787
## Development Setup
8888

89-
You can use `npm link` to link your local copy of the `react-plotly.js-editor` to your test repo.
90-
91-
With `npm link` you can get some errors related to
92-
[multiple copies of react being loaded](https://github.com/facebookincubator/create-react-app/issues/1107).
93-
To get around this, you can create an
94-
[alias](https://github.com/facebookincubator/create-react-app/issues/393) that
95-
points your project to the copy of react that it should be using or you can
96-
simply remove `react` and `react-dom` from `react-plotly.js-editor`.
97-
98-
### Using the `simple` example for development
99-
100-
In one terminal:
101-
102-
```
103-
npm link # registers react-plotly.js-editor for subsequent npm link calls
104-
npm run watch # keep this running
10589
```
106-
107-
In another terminal:
108-
109-
```
110-
cd examples/simple # or any other application directory
11190
npm install
112-
rm -rf node_modules/react node_modules/react-dom node_modules/react-plotly.js-edit
113-
npm link react-plotly.js-edit
114-
npm start # keep this running
91+
npm start
92+
# start hacking
11593
```
11694

11795
## Built-in Components

dev/favicon.ico

3.78 KB
Binary file not shown.

dev/index.html

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<link rel="shortcut icon" href="/favicon.ico">
6+
<title>Editor Dev</title>
7+
<style>
8+
body {
9+
margin: 0;
10+
padding: 0;
11+
font-family: sans-serif;
12+
}
13+
14+
.app{
15+
display: flex;
16+
/*
17+
We are defining the max height of the app so that the editor knows how big to be
18+
currently the editor will take up whatever space it can if it is not constrained in its parent
19+
*/
20+
min-height: 100vh;
21+
max-height: 100vh;
22+
width: 100%;
23+
}
24+
.app__main {
25+
max-width: 100%;
26+
max-height: 100vh;
27+
overflow: auto;
28+
flex-grow: 1;
29+
}
30+
</style>
31+
</head>
32+
<body>
33+
<div id="root"></div>
34+
<script src="bundle.js" type="text/javascript"></script>
35+
</body>
36+
</html>

dev/index.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import React, {Component} from 'react';
2+
import ReactDOM from 'react-dom';
3+
import plotly from 'plotly.js/dist/plotly-basic';
4+
import createPlotComponent from 'react-plotly.js/factory';
5+
import PlotlyEditor from '../src';
6+
import '../src/styles/main.scss';
7+
8+
const dataSources = {
9+
col1: [1, 2, 3], // eslint-disable-line no-magic-numbers
10+
col2: [4, 3, 2], // eslint-disable-line no-magic-numbers
11+
col3: [17, 13, 9], // eslint-disable-line no-magic-numbers
12+
};
13+
const dataSourceOptions = Object.keys(dataSources).map(name => ({
14+
value: name,
15+
label: name,
16+
}));
17+
18+
const Plot = createPlotComponent(plotly);
19+
20+
class App extends Component {
21+
constructor() {
22+
super();
23+
24+
// The graphDiv object is passed to Plotly.js, which then causes it to be
25+
// overwritten with a full DOM node that contains data, layout, _fullData,
26+
// _fullLayout etc in handlePlotUpdate()
27+
this.state = {
28+
graphDiv: {},
29+
editorRevision: 0,
30+
plotRevision: 0,
31+
};
32+
}
33+
34+
handlePlotUpdate(graphDiv) {
35+
this.setState(({editorRevision: x}) => ({editorRevision: x + 1, graphDiv}));
36+
}
37+
38+
handleEditorUpdate() {
39+
this.setState(({plotRevision: x}) => ({plotRevision: x + 1}));
40+
}
41+
42+
render() {
43+
return (
44+
<div className="app">
45+
<PlotlyEditor
46+
graphDiv={this.state.graphDiv}
47+
onUpdate={this.handleEditorUpdate.bind(this)}
48+
revision={this.state.editorRevision}
49+
dataSources={dataSources}
50+
dataSourceOptions={dataSourceOptions}
51+
plotly={plotly}
52+
/>
53+
<div className="app__main" style={{width: '100%', height: '100%'}}>
54+
<Plot
55+
debug
56+
useResizeHandler
57+
data={this.state.graphDiv.data}
58+
layout={this.state.graphDiv.layout}
59+
onUpdate={this.handlePlotUpdate.bind(this)}
60+
onInitialized={this.handlePlotUpdate.bind(this)}
61+
revision={this.state.plotRevision}
62+
style={{width: '100%', height: '100%'}}
63+
/>
64+
</div>
65+
</div>
66+
);
67+
}
68+
}
69+
70+
ReactDOM.render(<App />, document.getElementById('root'));

0 commit comments

Comments
 (0)