-
Notifications
You must be signed in to change notification settings - Fork 0
/
Graph.tsx
65 lines (57 loc) · 1.74 KB
/
Graph.tsx
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
import React, { Component } from 'react';
import { Table } from '@jpmorganchase/perspective';
import { ServerRespond } from './DataStreamer';
import { DataManipulator } from './DataManipulator';
import './Graph.css';
interface IProps {
data: ServerRespond[],
}
interface PerspectiveViewerElement extends HTMLElement {
load: (table: Table) => void,
}
class Graph extends Component<IProps, {}> {
table: Table | undefined;
render() {
return React.createElement('perspective-viewer');
}
componentDidMount() {
// Get element from the DOM.
const elem = document.getElementsByTagName('perspective-viewer')[0] as unknown as PerspectiveViewerElement;
const schema = {
price_abc : 'float',
price_def : 'float',
ratio : 'float',
upper_bound: 'float',
lower_bound: 'float',
trigger_alert : 'float',
timestamp: 'date',
};
if (window.perspective && window.perspective.worker()) {
this.table = window.perspective.worker().table(schema);
}
if (this.table) {
// Load the `table` in the `<perspective-viewer>` DOM reference.
elem.load(this.table);
elem.setAttribute('view', 'y_line');
elem.setAttribute('row-pivots', '["timestamp"]');
elem.setAttribute('columns', '["ratio","lower_bound","upper_bound","trigger_alert"]');
elem.setAttribute('aggregates', JSON.stringify({
price_abc : 'avg',
price_def : 'avg',
ratio : 'avg',
upper_bound: 'avg',
lower_bound: 'avg',
trigger_alert : 'avg',
timestamp: 'distinct count',
}));
}
}
componentDidUpdate() {
if (this.table) {
this.table.update(
[DataManipulator.generateRow(this.props.data),]
);
}
}
}
export default Graph;