Skip to content

Commit fa4f7f2

Browse files
committed
Integrate graph with map and homepage
1 parent fa7d0f4 commit fa4f7f2

4 files changed

Lines changed: 154 additions & 3 deletions

File tree

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
2+
// Test battery time series JSON
3+
// This data is from a single sensor over a period of time
4+
// It will be used in an XYFrame (Line graph) to show the sensors battery over time
5+
6+
export default [
7+
{
8+
id: "sensor-1", color:'blue',
9+
data: [
10+
{
11+
gasSensor: 200,
12+
created_at: new Date(2017, 7, 1),
13+
},
14+
{
15+
gasSensor: 250,
16+
created_at: new Date(2017, 7, 2),
17+
},
18+
{
19+
gasSensor: 220,
20+
created_at: new Date(2017, 7, 3),
21+
},
22+
{
23+
gasSensor: 230,
24+
created_at: new Date(2017, 7, 4),
25+
},
26+
{
27+
gasSensor: 240,
28+
created_at: new Date(2017, 7, 5),
29+
}
30+
]
31+
32+
},
33+
{
34+
id: "sensor-2", color:'red',
35+
data: [
36+
{
37+
gasSensor: 220,
38+
created_at: new Date(2017, 7, 1),
39+
},
40+
{
41+
gasSensor: 300,
42+
created_at: new Date(2017, 7, 2),
43+
},
44+
{
45+
gasSensor: 300,
46+
created_at: new Date(2017, 7, 3),
47+
},
48+
{
49+
gasSensor: 290,
50+
created_at: new Date(2017, 7, 4),
51+
},
52+
{
53+
gasSensor: 300,
54+
created_at: new Date(2017, 7, 5),
55+
}
56+
]
57+
58+
},
59+
{
60+
id: "sensor-3", color:'green',
61+
data: [
62+
{
63+
gasSensor: 220,
64+
created_at: new Date(2017, 7, 1),
65+
},
66+
{
67+
gasSensor: 220,
68+
created_at: new Date(2017, 7, 2),
69+
},
70+
{
71+
gasSensor: 220,
72+
created_at: new Date(2017, 7, 3),
73+
},
74+
{
75+
gasSensor: 210,
76+
created_at: new Date(2017, 7, 4),
77+
},
78+
{
79+
gasSensor: 220,
80+
created_at: new Date(2017, 7, 5),
81+
}
82+
]
83+
},
84+
85+
]

sensorgriddashboard/src/components/HomePage.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import './HomePage.css'
33
import NavBar from './NavBar'
44
import Battery from './Battery'
55
import MyGoogleMap from './MyGoogleMap'
6+
import TimeSeries from './TimeSeries'
7+
import realTestData from '../TestData/testData';
8+
69
import {
710
Collapse,
811
Navbar,
@@ -22,15 +25,15 @@ import {
2225
DropdownMenu,
2326
DropdownItem
2427
} from 'reactstrap';
25-
import Average from './Average.js'
2628

2729
class HomePage extends Component {
2830
constructor(props) {
2931
super(props);
3032

3133
this.toggle = this.toggle.bind(this);
3234
this.state = {
33-
isOpen: false
35+
isOpen: false,
36+
displayData: realTestData,
3437
};
3538
}
3639
toggle() {
@@ -58,8 +61,8 @@ class HomePage extends Component {
5861
</Navbar>
5962
<Battery className = "Battery" />
6063
<NavBar className = "Navigation"/>
64+
<TimeSeries displayData={this.state.displayData}/>
6165
<MyGoogleMap />
62-
</div>
6366
</div>
6467
)
6568
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.tooltip-content {
2+
background: white;
3+
border: 1px solid black;
4+
color: black;
5+
padding: 10px;
6+
z-index: 99;
7+
min-width: 120px;
8+
}
9+
10+
.tooltip-content:before {
11+
background: white;
12+
content: '';
13+
padding: 0px;
14+
transform: rotate(45deg);
15+
width: 15px;
16+
height: 15px;
17+
position: absolute;
18+
z-index: 99;
19+
}
20+
21+
.linegraph {
22+
width: 700px
23+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React, { Component } from 'react'
2+
import { scaleTime } from 'd3-scale'
3+
import { XYFrame, OrdinalFrame } from "semiotic"
4+
import './TimeSeries.css';
5+
6+
7+
8+
class TimeSeries extends Component {
9+
constructor(props){
10+
super(props)
11+
}
12+
13+
render() {
14+
return (
15+
<XYFrame
16+
size={[1200, 500]}
17+
lines={this.props.displayData}
18+
lineDataAccessor={"data"}
19+
lineStyle={d => ({ fill: d.color, fillOpacity: 0.5, stroke: d.color, strokeWidth: '3px' })}
20+
xAccessor="created_at"
21+
yAccessor="gasSensor"
22+
xScaleType={scaleTime()}
23+
lineIDAccessor="id"
24+
margin={{ "top": 60, "bottom": 65, "left": 260, "right": 20 }}
25+
hoverAnnotation={true}
26+
axes={[
27+
{ orient: 'left', tickFormat: d => d },
28+
{ ticks: 5, orient: 'bottom', tickFormat: d => {
29+
// console.log(typeof d)
30+
// console.log(d.toString().split(" "))
31+
// console.log(d.toString().split(" ")[1] + " " + d.toString().split(" ")[2])
32+
return d.toString().split(" ")[1] + " " + d.toString().split(" ")[2]
33+
}
34+
}
35+
]}
36+
/>
37+
);
38+
}
39+
}
40+
export default TimeSeries

0 commit comments

Comments
 (0)