diff --git a/src/App.tsx b/src/App.tsx
index 0728518c0d8..17cb4289c79 100755
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -7,7 +7,8 @@ import './App.css';
* State declaration for
*/
interface IState {
- data: ServerRespond[],
+ data: ServerRespond[],
+ showGraph: boolean
}
/**
@@ -18,30 +19,41 @@ class App extends Component<{}, IState> {
constructor(props: {}) {
super(props);
- this.state = {
- // data saves the server responds.
- // We use this state to parse data down to the child element (Graph) as element property
- data: [],
- };
- }
+ this.state = {
+ // data saves the server responds.
+ // We use this state to parse data down to the child element (Graph) as element property
+ data: [],
+ showGraph: false
+ };
+ }
- /**
- * Render Graph react component with state.data parse as property data
- */
- renderGraph() {
- return ()
- }
+ /**
+ * Render Graph react component with state.data parse as property data
+ */
+ renderGraph() {
+ if (this.state.showGraph) {
+ return ()
+ }
+ }
- /**
- * Get new data from server and update the state with the new data
- */
- getDataFromServer() {
- DataStreamer.getData((serverResponds: ServerRespond[]) => {
- // Update the state by creating a new array of data that consists of
- // Previous data in the state and the new data from server
- this.setState({ data: [...this.state.data, ...serverResponds] });
- });
- }
+ /**
+ * Get new data from server and update the state with the new data
+ */
+ getDataFromServer() {
+ let x = 0;
+ const interval = setInterval(() => {
+ DataStreamer.getData((serverResponds: ServerRespond[]) => {
+ this.setState({
+ data: serverResponds,
+ showGraph: true
+ });
+ });
+ x++;
+ if (x > 1000) {
+ clearInterval(interval);
+ }
+ }, 100);
+ }
/**
* Render the App react component
diff --git a/src/Graph.tsx b/src/Graph.tsx
index 3b2a7da1a38..557e7760397 100644
--- a/src/Graph.tsx
+++ b/src/Graph.tsx
@@ -14,8 +14,8 @@ interface IProps {
* Perspective library adds load to HTMLElement prototype.
* This interface acts as a wrapper for Typescript compiler.
*/
-interface PerspectiveViewerElement {
- load: (table: Table) => void,
+interface PerspectiveViewerElement extends HTMLElement {
+ load: (table: Table) => void,
}
/**
@@ -30,9 +30,9 @@ class Graph extends Component {
return React.createElement('perspective-viewer');
}
- componentDidMount() {
- // Get element to attach the table from the DOM.
- const elem: PerspectiveViewerElement = document.getElementsByTagName('perspective-viewer')[0] as unknown as PerspectiveViewerElement;
+ componentDidMount() {
+ // Get element to attach the table from the DOM.
+ const elem = document.getElementsByTagName('perspective-viewer')[0] as unknown as PerspectiveViewerElement;
const schema = {
stock: 'string',
@@ -47,10 +47,17 @@ class Graph extends Component {
if (this.table) {
// Load the `table` in the `` DOM reference.
- // Add more Perspective configurations here.
- elem.load(this.table);
+ // Add more Perspective configurations here.
+ 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",
+ '{"stock":"distinct_count", "top_ask_price":"avg", "top_bid_price":"avg", "timestamp":"distinct_count"}'
+ );
+ }
}
- }
componentDidUpdate() {
// Everytime the data props is updated, insert the data into Perspective table