Skip to content

Commit d6506fb

Browse files
committed
set peerDependencies, documentation
1 parent 92ea302 commit d6506fb

File tree

4 files changed

+59
-33
lines changed

4 files changed

+59
-33
lines changed

.npmignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
npm-debug.log
2-
tsconfig.json
32
node_modules
43
.idea

README.md

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,78 @@
11
# React-PlotlyJS-Typescript [![npm version](https://badge.fury.io/js/react-plotlyjs-ts.svg)](https://badge.fury.io/js/react-plotlyjs-ts)
22

3-
Inspired by [React-PlotlyJS](https://github.com/benjeffery/react-plotlyjs), many thanks!
4-
53
A react-typescript component for Plotly.JS graphs.
64

75
Self-redraw when props changed.
86

97
## Usage
108

9+
```bash
10+
$ npm install react react-dom typescript plotly.js
11+
$ npm install react-plotlyjs-ts
12+
```
13+
1114
```typescript
1215
import PlotlyChart from 'react-plotlyjs-ts';
1316

1417
...
1518
render(){
1619
const data = [
1720
{
18-
type: 'scatter', // all "scatter" attributes: https://plot.ly/javascript/reference/#scatter
19-
x: [1, 2, 3], // more about "x": #scatter-x
20-
y: [6, 2, 3], // #scatter-y
21-
marker: { // marker is an object, valid marker keys: #scatter-marker
22-
color: 'rgb(16, 32, 77)' // more about "marker.color": #scatter-marker-color
21+
type: 'scatter',
22+
x: [1, 2, 3],
23+
y: [6, 2, 3],
24+
marker: {
25+
color: 'rgb(16, 32, 77)'
2326
}
2427
},
2528
{
26-
type: 'bar', // all "bar" chart attributes: #bar
27-
x: [1, 2, 3], // more about "x": #bar-x
28-
y: [6, 2, 3], // #bar-y
29-
name: 'bar chart example' // #bar-name
29+
type: 'bar',
30+
x: [1, 2, 3],
31+
y: [6, 2, 3],
32+
name: 'bar chart example'
3033
}
3134
];
32-
const layout = { // all "layout" attributes: #layout
33-
title: 'simple example', // more about "layout.title": #layout-title
34-
xaxis: { // all "layout.xaxis" attributes: #layout-xaxis
35-
title: 'time' // more about "layout.xaxis.title": #layout-xaxis-title
35+
const layout = {
36+
title: 'simple example',
37+
xaxis: {
38+
title: 'time'
3639
},
37-
annotations: [ // all "annotation" attributes: #layout-annotations
40+
annotations: [
3841
{
39-
text: 'simple annotation', // #layout-annotations-text
40-
x: 0, // #layout-annotations-x
41-
xref: 'paper', // #layout-annotations-xref
42-
y: 0, // #layout-annotations-y
43-
yref: 'paper' // #layout-annotations-yref
42+
text: 'simple annotation',
43+
x: 0,
44+
xref: 'paper',
45+
y: 0,
46+
yref: 'paper'
4447
}
4548
]
4649
};
4750
return (
48-
<PlotlyChart data={data} layout={layout} />
49-
)
51+
<PlotlyChart data={toJS(this.model_data)}
52+
layout={layout}
53+
onClick={({points, event}) => console.log(points, event)}> )
5054
}
55+
```
56+
57+
## Documentation
58+
Define PlotlyChart props below:
59+
```typescript
60+
data: any[];
61+
layout?: any;
62+
config?: any;
63+
onClick?: (data: { points: any, event: any }) => any;
64+
onBeforeHover?: (data: { points: any, event: any }) => any;
65+
onHover?: (data: { points: any, event: any }) => any;
66+
onUnHover?: (data: { points: any, event: any }) => any;
67+
onSelected?: (data: { points: any, event: any }) => any;
68+
```
69+
* data, layout, config are the same as in the [plotly.js](https://www.npmjs.com/package/plotly.js).
70+
* <b>onClick, onBeforeHover, onHover, onUnHover, onSelected</b> are on event functions.
71+
Use ES6 destructuring to get the points and event.
72+
5173

74+
## Todo
75+
Add testing
5276

53-
```
77+
## Thanks
78+
Inspired by [React-PlotlyJS](https://github.com/benjeffery/react-plotlyjs), many thanks!

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "react-plotlyjs-ts",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "Typescript-React component for Plotly.js",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
77
"scripts": {
8-
"build": "tsc"
8+
"build": "tsc"
99
},
1010
"repository": {
1111
"type": "git",
@@ -19,7 +19,9 @@
1919
"author": "caitengjiao1987@gmail.com",
2020
"license": "MIT",
2121
"dependencies": {
22-
"lodash": "^4.17.4",
22+
"lodash": "^4.17.4"
23+
},
24+
"peerDependencies": {
2325
"plotly.js": "^1.30.0",
2426
"react": "^15.6.1",
2527
"react-dom": "^15.6.1",

src/index.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ export interface IPlotlyChartProps {
66
data: any[];
77
layout?: any;
88
config?: any;
9-
onClick?: (data: any) => any;
10-
onBeforeHover?: (data: any) => any;
11-
onHover?: (data: any) => any;
12-
onUnHover?: (data: any) => any;
13-
onSelected?: (data: any) => any;
9+
onClick?: (data: { points: any, event: any }) => any;
10+
onBeforeHover?: (data: { points: any, event: any }) => any;
11+
onHover?: (data: { points: any, event: any }) => any;
12+
onUnHover?: (data: { points: any, event: any }) => any;
13+
onSelected?: (data: { points: any, event: any }) => any;
1414
}
1515

1616
/***

0 commit comments

Comments
 (0)