From ac09fdb9ca5b46e36f11452925e304a17580e0fd Mon Sep 17 00:00:00 2001 From: VisheshRawal Date: Tue, 14 Mar 2023 14:35:42 +0530 Subject: [PATCH] Resolved the Graph Issue --- .idea/.gitignore | 3 +++ .../inspectionProfiles/profiles_settings.xml | 6 +++++ .idea/jpmc-task-2.iml | 14 ++++++++++++ .idea/misc.xml | 4 ++++ .idea/modules.xml | 8 +++++++ .idea/vcs.xml | 6 +++++ src/App.tsx | 22 ++++++++++++++----- src/Graph.tsx | 9 ++++++-- 8 files changed, 65 insertions(+), 7 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/jpmc-task-2.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000000..26d33521af1 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 00000000000..105ce2da2d6 --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/jpmc-task-2.iml b/.idea/jpmc-task-2.iml new file mode 100644 index 00000000000..8e5446ac959 --- /dev/null +++ b/.idea/jpmc-task-2.iml @@ -0,0 +1,14 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000000..92bb01f0150 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000000..c9be9638e35 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000000..35eb1ddfbbc --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/App.tsx b/src/App.tsx index 0728518c0d8..a449dcf4bb6 100755 --- a/src/App.tsx +++ b/src/App.tsx @@ -8,6 +8,7 @@ import './App.css'; */ interface IState { data: ServerRespond[], + showGraph: boolean, } /** @@ -22,6 +23,7 @@ class App extends Component<{}, IState> { // data saves the server responds. // We use this state to parse data down to the child element (Graph) as element property data: [], + showGraph: false, }; } @@ -29,18 +31,28 @@ class App extends Component<{}, IState> { * Render Graph react component with state.data parse as property data */ renderGraph() { - return () + 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] }); + let x = 0; + const interval = setInterval(() => { + DataStreamer.getData((serverResponds: ServerRespond[]) => { + this.setState({ + data: serverResponds, + showGraph: true, + }); }); + x++; + if (x > 1000) { + clearInterval(interval); + } + }, 100); } /** diff --git a/src/Graph.tsx b/src/Graph.tsx index 3b2a7da1a38..61602bda071 100644 --- a/src/Graph.tsx +++ b/src/Graph.tsx @@ -14,7 +14,7 @@ interface IProps { * Perspective library adds load to HTMLElement prototype. * This interface acts as a wrapper for Typescript compiler. */ -interface PerspectiveViewerElement { +interface PerspectiveViewerElement extends HTMLElement{ load: (table: Table) => void, } @@ -32,7 +32,7 @@ class Graph extends Component { componentDidMount() { // Get element to attach the table from the DOM. - const elem: PerspectiveViewerElement = document.getElementsByTagName('perspective-viewer')[0] as unknown as PerspectiveViewerElement; + const elem = document.getElementsByTagName('perspective-viewer')[0] as unknown as PerspectiveViewerElement; const schema = { stock: 'string', @@ -49,6 +49,11 @@ class Graph extends Component { // 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"}'); } }