Skip to content

Commit d4d4a97

Browse files
authored
Merge pull request #6 from plotly/develop
Initial version
2 parents 015ac53 + 974e971 commit d4d4a97

26 files changed

+268
-3358
lines changed

.eslintrc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"parserOptions": {
3+
"ecmaVersion": 6,
4+
"sourceType": "module",
5+
"ecmaFeatures": {
6+
"jsx": true
7+
}
8+
},
9+
"rules": {
10+
"semi": 2,
11+
"no-unused-vars": 2,
12+
"react/display-name": 2,
13+
"react/jsx-key": 2,
14+
"react/jsx-no-comment-textnodes": 2,
15+
"react/jsx-no-duplicate-props": 2,
16+
"react/jsx-no-target-blank": 2,
17+
"react/jsx-no-undef": 2,
18+
"react/jsx-uses-react": 2,
19+
"react/jsx-uses-vars": 2,
20+
"react/no-children-prop": 2,
21+
"react/no-danger-with-children": 2,
22+
"react/no-deprecated": 2,
23+
"react/no-direct-mutation-state": 2,
24+
"react/no-find-dom-node": 2,
25+
"react/no-is-mounted": 2,
26+
"react/no-render-return-value": 2,
27+
"react/no-string-refs": 2,
28+
"react/no-unescaped-entities": 2,
29+
"react/no-unknown-property": 2,
30+
"react/prop-types": 2,
31+
"react/react-in-jsx-scope": 2,
32+
"react/require-render-return": 2,
33+
},
34+
"plugins": [
35+
"react"
36+
]
37+
}

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2017 Plotly, Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 60 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
1-
# plotly.js-react
1+
# react-plotly.js
22

3-
> A React component for plotly.js charts <a href="https://z8tgespzmd63w51brzdh360ryvgt3m1ho.netlify.com/">&rarr; See demo</a>
3+
> A [plotly.js](https://github.com/plotly/plotly.js) React component from [Plotly](https://plot.ly/)
44
55
## Installation
66

7-
Not yet published
8-
97
```bash
10-
$ npm install plotly.js-react
8+
$ npm install react-plotly.js plotly.js
119
```
1210

1311
## Usage
1412

15-
The component definition is created by dependency injection so that you can use whichever version of plotly.js you'd like, including the [CDN versions](https://plot.ly/javascript/getting-started/#plotlyjs-cdn).
13+
### With bundled `plotly.js`
14+
15+
[`plotly.js`](https://github.com/plotly/plotly.js) is a peer dependency of `react-plotly.js`. If you would like to bundle `plotly.js` with the rest of your project and use it in this component, you must install it separately.
16+
17+
```bash
18+
$ npm install -S react-plotly.js plotly.js
19+
```
20+
21+
Since `plotly.js` is a peer dependency, you do not need to require it separately to use it.
1622

1723
```javascript
18-
const createPlotlyComponent = require('plotly.js-react');
19-
const PlotlyComponent = createPlotlyComponent(Plotly);
24+
import Plot from 'react-plotly.js'
2025

2126
render () {
22-
<PlotlyComponent
27+
return <Plot
2328
data={...}
2429
layout={...}
2530
frames={...}
@@ -28,7 +33,37 @@ render () {
2833
}
2934
```
3035

31-
The only requirement is that plotly.js is loaded before you inject it. You may need to use a module like [load-script](https://www.npmjs.com/package/load-script) to ensure it's available.
36+
### With external `plotly.js`
37+
38+
If you wish to use a version of `plotly.js` that is not bundled with the rest of your project, whether a [CDN version](https://plot.ly/javascript/getting-started/#plotlyjs-cdn) or through a [static distribution bundle](https://github.com/plotly/plotly.js/tree/master/dist), you may skip installing `plotly.js` and ignore the peer dependency warning.
39+
40+
```bash
41+
$ npm install -S react-plotly.js
42+
```
43+
44+
Given perhaps a script tag that has loaded a CDN version of plotly.js,
45+
46+
```html
47+
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
48+
```
49+
50+
you may then inject Plotly and use the returned React component:
51+
52+
```javascript
53+
import plotComponentFactory from 'react-plotly.js/factory'
54+
const Plot = plotComponentFactory(Plotly);
55+
56+
render () {
57+
return <Plot
58+
data={...}
59+
layout={...}
60+
frames={...}
61+
config={...}
62+
/>
63+
}
64+
```
65+
66+
**Note**: You must ensure `Plotly` is available before your React app tries to render the component. That could mean perhaps using script tag (without `async` or `defer`) or a utility like [load-script](https://www.npmjs.com/package/load-script).
3267

3368
## API
3469

@@ -42,12 +77,14 @@ The only requirement is that plotly.js is loaded before you inject it. You may n
4277
| `frames` | `Array` | `undefined` | list of frame objects |
4378
| `fit` | `Boolean` | `false` | When true, disregards `layout.width` and `layout.height` and fits to the parent div size, updating on `window.resize` |
4479
| `debug` | `Boolean` | `false` | Assign the graph div to `window.gd` for debugging |
45-
| `onInitialized | `Function` | null | Callback executed once after plot is initialized |
46-
| `onUpdate | `Function` | null | Callback executed when a plotly.js API method is invoked |
47-
| `onError | `Function` | null | Callback executed when a plotly.js API method rejects |
80+
| `onInitialized` | `Function` | `undefined` | Callback executed once after plot is initialized |
81+
| `onUpdate` | `Function` | `undefined` | Callback executed when a plotly.js API method is invoked |
82+
| `onError` | `Function` | `undefined` | Callback executed when a plotly.js API method rejects |
4883

4984
### Event handler props
5085

86+
Event handlers for [`plotly.js` events](https://plot.ly/javascript/plotlyjs-events/) may be attached through the following props.
87+
5188
| Prop | Type | Plotly Event |
5289
| ---- | ---- | ----------- |
5390
| `onAfterExport` | `Function` | `plotly_afterexport` |
@@ -76,6 +113,10 @@ The only requirement is that plotly.js is loaded before you inject it. You may n
76113
| `onTransitionInterrupted` | `Function` | `plotly_transitioninterrupted` |
77114
| `onUnhover` | `Function` | `plotly_unhover` |
78115

116+
## Roadmap
117+
118+
This component currently creates a new plot every time the input changes. That makes it stable and good enough for production use, but `plotly.js` will soon gain react-style support for computing and drawing changes incrementally. What does that mean for you? That means you can expect to keep using this component with little or no modification but that the plotting will simply happen much faster when you upgrade to the first version of `plotly.js` to support this feature. If this component requires any significant changes, a new major version will be released at the same time to ensure stability.
119+
79120
## Development
80121

81122
To get started:
@@ -85,15 +126,17 @@ $ npm install
85126
$ npm start
86127
```
87128

88-
To build the dist version:
129+
To transpile from ES2015 + JSX into the ES5 npm-distributed version:
89130

90131
```bash
91-
$ npm run prepublish
132+
$ npm run prepublishOnly
92133
```
93134

94-
## See also
135+
To run the tests:
95136

96-
- [plotly-react-editor](https://github.com/plotly/plotly-react-editor)
137+
```bash
138+
$ npm run test
139+
```
97140

98141
## License
99142

0 commit comments

Comments
 (0)