-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathexample-scatterplot.jsx
81 lines (69 loc) · 1.78 KB
/
example-scatterplot.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import * as React from 'react';
import d3 from 'd3';
import { ScatterPlot } from '../../src/main';
export default class ScatterplotExample extends React.Component {
static propTypes = {
selected: React.PropTypes.string
}
constructor (props) {
super(props);
this.state = {data: []};
}
dataLoader() {
d3.json('data/scatter-series.json', (err, rsp) => {
if (err) return console.error('Scatterplot data loading error!');
// Add a random value to each row to scale the dot's by
const data = rsp.series[0].data.map((row) => {
row.push(Math.floor(Math.random() * 100) + 1);
return row;
});
this.setState({data: data});
});
}
componentWillMount() {
this.dataLoader();
}
componentDidMount() {}
setToolTipContent(element, item) {
const msg = [
'<span>Weight: ' + item[0] + '</span><br/>',
'<span>Height: ' + item[1] + '</span><br/>',
'<span>Random: ' + item[2] + '</span>'
];
element.html(msg.join(''));
}
render () {
var opts = {
xAccessor: d => d[0],
yAccessor: d => d[1],
tooltip: true,
dotRadiusScale: d3.scale.sqrt().range([1, 6]),
dotRadiusAccessor: d => d[2],
tooltipOptions: {
onSetTooltipContent: this.setToolTipContent.bind(this),
offset: [0, -10],
align: 'top center',
closeDelay: 100
},
yaxis: {
className: 'y axis',
orient: 'left',
position: 'left',
label: {
text: 'Weight (kg)',
attr: {
transform: 'rotate(-90)',
y: 6,
dy: '0.71em'
},
style: {
'text-anchor': 'end'
}
}
}
};
return (
<ScatterPlot data={this.state.data} {...opts}/>
);
}
}