diff --git a/src/Graph.tsx b/src/Graph.tsx index 277797d933..02964a518b 100644 --- a/src/Graph.tsx +++ b/src/Graph.tsx @@ -1,60 +1,66 @@ -import React, { Component } from 'react'; -import { Table } from '@finos/perspective'; -import { ServerRespond } from './DataStreamer'; -import { DataManipulator } from './DataManipulator'; +import React, {Component} from 'react'; +import {Table, TableData} from '@finos/perspective'; +import {ServerRespond} from './DataStreamer'; +import {DataManipulator} from './DataManipulator'; import './Graph.css'; interface IProps { - data: ServerRespond[], + data: ServerRespond[], } interface PerspectiveViewerElement extends HTMLElement { - load: (table: Table) => void, + load: (table: Table) => void, } + class Graph extends Component { - table: Table | undefined; + table: Table | undefined; - render() { - return React.createElement('perspective-viewer'); - } + render() { + return React.createElement('perspective-viewer'); + } - componentDidMount() { - // Get element from the DOM. - const elem = document.getElementsByTagName('perspective-viewer')[0] as unknown as PerspectiveViewerElement; + componentDidMount() { + // Get element from the DOM. + const elem = document.getElementsByTagName('perspective-viewer')[0] as unknown as PerspectiveViewerElement; - const schema = { - stock: 'string', - top_ask_price: 'float', - top_bid_price: 'float', - timestamp: 'date', - }; + const schema = { + price_abc: 'float', + price_def: 'float', + ratio: 'float', + timestamp: 'date', + upper_bound: 'float', + lower_bound: 'float', + trigger_alert: 'float' + }; - if (window.perspective && window.perspective.worker()) { - this.table = window.perspective.worker().table(schema); - } - if (this.table) { - // Load the `table` in the `` DOM reference. - elem.load(this.table); - elem.setAttribute('view', 'y_line'); - elem.setAttribute('column-pivots', '["stock"]'); - elem.setAttribute('row-pivots', '["timestamp"]'); - elem.setAttribute('columns', '["top_ask_price"]'); - elem.setAttribute('aggregates', JSON.stringify({ - stock: 'distinctcount', - top_ask_price: 'avg', - top_bid_price: 'avg', - timestamp: 'distinct count', - })); + if (window.perspective && window.perspective.worker()) { + this.table = window.perspective.worker().table(schema); + } + if (this.table) { + // Load the `table` in the `` 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', + timestamp: 'distinct count', + upper_bound: 'avg', + lower_bound: 'avg', + trigger_alert: 'avg' + })); + } } - } - componentDidUpdate() { - if (this.table) { - this.table.update( - DataManipulator.generateRow(this.props.data), - ); + componentDidUpdate() { + if (this.table) { + this.table.update([ + DataManipulator.generateRow(this.props.data), + ] as unknown as TableData); + } } - } } export default Graph;