Skip to content

Initial version #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Oct 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"rules": {
"semi": 2,
"no-unused-vars": 2,
"react/display-name": 2,
"react/jsx-key": 2,
"react/jsx-no-comment-textnodes": 2,
"react/jsx-no-duplicate-props": 2,
"react/jsx-no-target-blank": 2,
"react/jsx-no-undef": 2,
"react/jsx-uses-react": 2,
"react/jsx-uses-vars": 2,
"react/no-children-prop": 2,
"react/no-danger-with-children": 2,
"react/no-deprecated": 2,
"react/no-direct-mutation-state": 2,
"react/no-find-dom-node": 2,
"react/no-is-mounted": 2,
"react/no-render-return-value": 2,
"react/no-string-refs": 2,
"react/no-unescaped-entities": 2,
"react/no-unknown-property": 2,
"react/prop-types": 2,
"react/react-in-jsx-scope": 2,
"react/require-render-return": 2,
},
"plugins": [
"react"
]
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2017 Plotly, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
77 changes: 60 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
# plotly.js-react
# react-plotly.js

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

## Installation

Not yet published

```bash
$ npm install plotly.js-react
$ npm install react-plotly.js plotly.js
```

## Usage

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).
### With bundled `plotly.js`

[`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.

```bash
$ npm install -S react-plotly.js plotly.js
```

Since `plotly.js` is a peer dependency, you do not need to require it separately to use it.

```javascript
const createPlotlyComponent = require('plotly.js-react');
const PlotlyComponent = createPlotlyComponent(Plotly);
import Plot from 'react-plotly.js'

render () {
<PlotlyComponent
return <Plot
data={...}
layout={...}
frames={...}
Expand All @@ -28,7 +33,37 @@ render () {
}
```

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.
### With external `plotly.js`

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.

```bash
$ npm install -S react-plotly.js
```

Given perhaps a script tag that has loaded a CDN version of plotly.js,

```html
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
```

you may then inject Plotly and use the returned React component:

```javascript
import plotComponentFactory from 'react-plotly.js/factory'
const Plot = plotComponentFactory(Plotly);

render () {
return <Plot
data={...}
layout={...}
frames={...}
config={...}
/>
}
```

**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).

## API

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

### Event handler props

Event handlers for [`plotly.js` events](https://plot.ly/javascript/plotlyjs-events/) may be attached through the following props.

| Prop | Type | Plotly Event |
| ---- | ---- | ----------- |
| `onAfterExport` | `Function` | `plotly_afterexport` |
Expand Down Expand Up @@ -76,6 +113,10 @@ The only requirement is that plotly.js is loaded before you inject it. You may n
| `onTransitionInterrupted` | `Function` | `plotly_transitioninterrupted` |
| `onUnhover` | `Function` | `plotly_unhover` |

## Roadmap

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.

## Development

To get started:
Expand All @@ -85,15 +126,17 @@ $ npm install
$ npm start
```

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

```bash
$ npm run prepublish
$ npm run prepublishOnly
```

## See also
To run the tests:

- [plotly-react-editor](https://github.com/plotly/plotly-react-editor)
```bash
$ npm run test
```

## License

Expand Down
Loading