Skip to content

Commit c6f3fed

Browse files
committed
Add readme documentation
1 parent 0f7e254 commit c6f3fed

8 files changed

+353
-284
lines changed

LICENSE

+21
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

+53-13
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,60 @@
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, 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.
22+
23+
```javascript
24+
import Plot from 'react-plotly.js'
25+
26+
render () {
27+
return <Plot
28+
data={...}
29+
layout={...}
30+
frames={...}
31+
config={...}
32+
/>
33+
}
34+
```
35+
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 versions](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:
1651

1752
```javascript
18-
const createPlotlyComponent = require('plotly.js-react');
19-
const PlotlyComponent = createPlotlyComponent(Plotly);
53+
import plotComponentFactory from 'react-plotly.js/factory'
54+
const Plot = plotComponentFactory(Plotly);
2055

2156
render () {
22-
<PlotlyComponent
57+
return <Plot
2358
data={...}
2459
layout={...}
2560
frames={...}
@@ -28,7 +63,8 @@ render () {
2863
}
2964
```
3065

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.
66+
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).
67+
3268

3369
## API
3470

@@ -48,6 +84,8 @@ The only requirement is that plotly.js is loaded before you inject it. You may n
4884

4985
### Event handler props
5086

87+
Event handlers for [`plotly.js` events](https://plot.ly/javascript/plotlyjs-events/) may be attached through the following props.
88+
5189
| Prop | Type | Plotly Event |
5290
| ---- | ---- | ----------- |
5391
| `onAfterExport` | `Function` | `plotly_afterexport` |
@@ -88,12 +126,14 @@ $ npm start
88126
To build the dist version:
89127

90128
```bash
91-
$ npm run prepublish
129+
$ npm run prepublishOnly
92130
```
93131

94-
## See also
132+
To run the tests:
95133

96-
- [plotly-react-editor](https://github.com/plotly/plotly-react-editor)
134+
```bash
135+
$ npm run test
136+
```
97137

98138
## License
99139

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"license": "MIT",
55
"description": "A plotly.js react component from Plotly",
66
"author": "Plotly, Inc.",
7-
"main": "lib/react-plotly.js",
7+
"main": "react-plotly.js",
88
"repository": {
99
"type": "git",
1010
"url": "https://github.com/plotly/react-plotly.js.git"
@@ -19,7 +19,7 @@
1919
"example:build:assets": "rm -rf example/dist/assets && cp -r example/assets example/dist/assets",
2020
"example:build": "rm -rf example/dist && mkdir -p example/dist && npm run example:build:html && npm run example:build:js && npm run example:build:assets",
2121
"example:deploy": "netlify deploy example/dist",
22-
"make:lib": "mkdir -p lib && babel src/react-plotly.js -o lib/react-plotly.js --presets=es2015,react --source-maps --plugins babel-plugin-add-module-exports",
22+
"make:lib": "babel src/*.js --out-dir=./ --presets=es2015,react --source-maps --plugins babel-plugin-add-module-exports",
2323
"make:build": "mkdir -p build && browserify src/react-plotly.js -o ./build/react-plotly.js -t [ babelify --presets [ es2015 react ] ] -t browserify-global-shim --standalone createPlotlyComponent && uglifyjs ./build/react-plotly.js --compress --mangle --output ./build/react-plotly.js.min.js --source-map filename=build/react-plotly.js.min.js.map",
2424
"clean": "rm -rf build lib",
2525
"prepublishOnly": "npm run make:lib && npm run make:build",

src/__tests__/react-plotly.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from "react";
22
import { mount } from "enzyme";
3-
import createComponent from "../react-plotly";
3+
import createComponent from "../factory";
44
import once from "onetime";
55

66
describe("<Plotly/>", () => {

0 commit comments

Comments
 (0)