-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
71 lines (70 loc) · 2.44 KB
/
index.js
File metadata and controls
71 lines (70 loc) · 2.44 KB
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
import React from 'react';
import ReactDOM from 'react-dom';
import Palette from './core/Palette';
import HorizontalBarChart from './components/barCharts/HorizontalBarChart';
import VerticalBarChart from './components/barCharts/VerticalBarChart';
import SimpleLineChart from './components/lineCharts/SimpleLineChart';
import MultiLineChart from './components/lineCharts/MultiLineChart';
import Tooltip from './core/Tooltip';
import * as jsonData from './demo/dateData.json';
const fakeData = [{ key:'blood', value: 121 },{ key:'argon', value: 112 },
{ key: 'novel', value: 31 }, { key: 'sixtytwo', value: 76 }];
var offset = 0;
const superFake = ()=>{
let fake = [];
for(let i = 0; i < 10; i++){
fake = [...fake, {
x: jsonData[i].x,
y: jsonData[i+offset].y
}]
}
offset += 10;
return fake.sort((a,b)=> new Date(a.x) - new Date(b.x));
};
const superFake2 = ()=>{
let fake = [];
for(let i = 0; i < 5; i++){
fake = [...fake, {
key: i, values: superFake()
}]
}
return fake;
};
const horizontalChartMargin = {
left: 50, top: 10, bottom: 20, right: 10
};
export default class App extends React.Component{
constructor(){
super();
this.state = {
data: superFake(),
data2: superFake2(),
tooltipData: null,
tooltipPosition:{
x: -1, y: -1
}
};
this.tooltipUpdate = this.tooltipUpdate.bind(this);
}
tooltipUpdate(position,content){
this.setState({
tooltipPosition:position||{x:-1,y:-1},
tooltipData: content
});
}
render(){
return (
<div>
<VerticalBarChart data={fakeData} tooltipUpdate={this.tooltipUpdate} barWidth={25} height={300} />
<SimpleLineChart isTimeScaled={true} data={this.state.data} tooltipUpdate={this.tooltipUpdate} lineColor={'#009688'}></SimpleLineChart>
<MultiLineChart isTimeScaled={true} data={this.state.data2} tooltipUpdate={this.tooltipUpdate}></MultiLineChart>
<HorizontalBarChart barHeight={25} data={fakeData} height={110}
margin={horizontalChartMargin} tooltipUpdate={this.tooltipUpdate}/>
<Tooltip position={this.state.tooltipPosition} content={this.state.tooltipData}/>
</div>
);
}
}
ReactDOM.render(
<App/>, document.getElementById('root')
);