From 79452f07cc6d59b36acbeba47c9d443c11948adf Mon Sep 17 00:00:00 2001 From: Sharan <115540022+shar2040@users.noreply.github.com> Date: Mon, 5 Dec 2022 15:56:49 +0530 Subject: [PATCH] Create task2 --- task2 | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 task2 diff --git a/task2 b/task2 new file mode 100644 index 0000000..451f9ef --- /dev/null +++ b/task2 @@ -0,0 +1,106 @@ +From: Varun +Date: Mon, 05 Dec 20222 +Subject: [PATCH] Create patch file + + +--- + src/App.tsx | 23 +++++++++++++++++++---- + src/Graph.tsx | 13 +++++++++++-- + 2 files changed, 30 insertions(+), 6 deletions(-) + +diff --git a/src/App.tsx b/src/App.tsx +index 0728518..77c3fab 100755 +--- a/src/App.tsx ++++ b/src/App.tsx +@@ -8,6 +8,7 @@ import './App.css'; + */ + interface IState { + data: ServerRespond[], ++ showGraph: boolean, + } + + /** +@@ -22,25 +23,39 @@ 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, + }; + } + ++ + /** + * 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[]) => { ++ let x=0; ++ const interval = setInterval(() => { ++ 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] }); +- }); ++ this.setState({ ++ data: serverResponds, ++ showGraph: true, ++ }); ++ }); ++ x++; ++ if (x > 1000) { ++ clearInterval(interval); ++ } ++ }, 100); + } + + /** +diff --git a/src/Graph.tsx b/src/Graph.tsx +index ec1430e..4ddaa2c 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,15 @@ 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"}`); + } + } + +-- +2.26.2