Skip to content

Commit c23c54a

Browse files
committed
fix add eventlistener bug and set config and layout to any
1 parent e2c027a commit c23c54a

File tree

4 files changed

+236
-223
lines changed

4 files changed

+236
-223
lines changed

README.md

Lines changed: 49 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,52 +11,62 @@ Self-redraw when props changed.
1111
## Usage
1212

1313
```bash
14-
$ npm install react react-dom typescript plotly.js
15-
$ npm install react-plotlyjs-ts
14+
$ npm i -S react react-dom typescript
15+
$ npm i -D @types/plotly.js
16+
$ npm i -S plotly.js react-plotlyjs-ts
1617
```
1718

1819
```typescript
19-
import PlotlyChart from 'react-plotlyjs-ts';
20+
import * as React from 'react';
21+
import PlotlyChart from './PloylyChart';
2022

21-
...
22-
render(){
23-
const data = [
24-
{
25-
type: 'scatter',
26-
x: [1, 2, 3],
27-
y: [6, 2, 3],
28-
marker: {
29-
color: 'rgb(16, 32, 77)'
30-
}
31-
},
32-
{
33-
type: 'bar',
34-
x: [1, 2, 3],
35-
y: [6, 2, 3],
36-
name: 'bar chart example'
37-
}
38-
];
39-
const layout = {
40-
title: 'simple example',
41-
xaxis: {
42-
title: 'time'
43-
},
44-
annotations: [
23+
class App extends React.Component {
24+
public handleClick = (evt: any) => alert('click')
25+
public handleHover = (evt: any) => alert('hover')
26+
27+
public render() {
28+
const data = [
4529
{
46-
text: 'simple annotation',
47-
x: 0,
48-
xref: 'paper',
49-
y: 0,
50-
yref: 'paper'
30+
marker: {
31+
color: 'rgb(16, 32, 77)'
32+
},
33+
type: 'scatter',
34+
x: [1, 2, 3],
35+
y: [6, 2, 3]
36+
},
37+
{
38+
name: 'bar chart example',
39+
type: 'bar',
40+
x: [1, 2, 3],
41+
y: [6, 2, 3],
5142
}
52-
]
53-
};
54-
return (
55-
<PlotlyChart data={data}
56-
layout={layout}
57-
onClick={({points, event}) => console.log(points, event)} />
58-
)
43+
];
44+
const layout = {
45+
annotations: [
46+
{
47+
text: 'simple annotation',
48+
x: 0,
49+
xref: 'paper',
50+
y: 0,
51+
yref: 'paper'
52+
}
53+
],
54+
title: 'simple example',
55+
xaxis: {
56+
title: 'time'
57+
},
58+
};
59+
return (
60+
<PlotlyChart data={data}
61+
layout={layout}
62+
onClick={this.handleClick}
63+
onHover={this.handleHover}
64+
/>
65+
);
66+
}
5967
}
68+
69+
export default App;
6070
```
6171

6272
## Documentation

dist/index.d.ts

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
/// <reference types="react" />
2-
import * as plotly from 'plotly.js';
3-
import * as React from 'react';
4-
export interface IPlotlyChartProps {
5-
config?: plotly.Config;
6-
data: Partial<plotly.ScatterData>[];
7-
layout?: plotly.Layout;
8-
onClick?: (event: plotly.PlotMouseEvent) => void;
9-
onBeforeHover?: (event: plotly.PlotMouseEvent) => void;
10-
onHover?: (event: plotly.PlotMouseEvent) => void;
11-
onUnHover?: (event: plotly.PlotMouseEvent) => void;
12-
onSelected?: (event: plotly.PlotSelectionEvent) => void;
13-
}
14-
/***
15-
* Usage:
16-
* <PlotlyChart data={toJS(this.model_data)}
17-
* layout={layout}
18-
* onClick={({points, event}) => console.log(points, event)}>
19-
*/
20-
declare class PlotlyChart extends React.Component<IPlotlyChartProps, any> {
21-
container: plotly.PlotlyHTMLElement | null;
22-
attachListeners(): void;
23-
resize: () => void;
24-
draw: (props: IPlotlyChartProps) => Promise<void>;
25-
componentWillReceiveProps(nextProps: IPlotlyChartProps): void;
26-
componentDidMount(): void;
27-
componentWillUnmount(): void;
28-
render(): JSX.Element;
29-
}
30-
export default PlotlyChart;
1+
/// <reference types="react" />
2+
import * as plotly from 'plotly.js';
3+
import * as React from 'react';
4+
export interface IPlotlyChartProps {
5+
config?: any;
6+
data: any;
7+
layout?: any;
8+
onClick?: (event: plotly.PlotMouseEvent) => void;
9+
onBeforeHover?: (event: plotly.PlotMouseEvent) => void;
10+
onHover?: (event: plotly.PlotMouseEvent) => void;
11+
onUnHover?: (event: plotly.PlotMouseEvent) => void;
12+
onSelected?: (event: plotly.PlotSelectionEvent) => void;
13+
}
14+
/***
15+
* Usage:
16+
* <PlotlyChart data={toJS(this.model_data)}
17+
* layout={layout}
18+
* onClick={({points, event}) => console.log(points, event)}>
19+
*/
20+
declare class PlotlyChart extends React.Component<IPlotlyChartProps, any> {
21+
container: plotly.PlotlyHTMLElement | null;
22+
attachListeners(): void;
23+
resize: () => void;
24+
draw: (props: IPlotlyChartProps) => Promise<void>;
25+
componentWillReceiveProps(nextProps: IPlotlyChartProps): void;
26+
componentDidMount(): void;
27+
componentWillUnmount(): void;
28+
render(): JSX.Element;
29+
}
30+
export default PlotlyChart;

0 commit comments

Comments
 (0)