From 1299019fa7185e53620245a4bca3a4beb9c95b78 Mon Sep 17 00:00:00 2001 From: Naafiyan Ahmed Date: Wed, 6 Jul 2022 21:08:20 -0400 Subject: added support for line graph --- src/client/views/nodes/DataVizBox/ChartBox.tsx | 45 ++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/client/views/nodes/DataVizBox/ChartBox.tsx b/src/client/views/nodes/DataVizBox/ChartBox.tsx index 26ccd1c12..1a084cf55 100644 --- a/src/client/views/nodes/DataVizBox/ChartBox.tsx +++ b/src/client/views/nodes/DataVizBox/ChartBox.tsx @@ -10,8 +10,10 @@ import { Tooltip, Legend, InteractionItem, + PointElement, + LineElement, } from 'chart.js'; - import { Bar, getDatasetAtEvent, getElementAtEvent } from 'react-chartjs-2'; + import { Bar, getDatasetAtEvent, getElementAtEvent, Line } from 'react-chartjs-2'; import { ChartJSOrUndefined } from "react-chartjs-2/dist/types"; import { action, computed, observable } from "mobx"; import { Cast, StrCast } from "../../../../fields/Types"; @@ -37,7 +39,9 @@ ChartJS.register( BarElement, Title, Tooltip, - Legend + Legend, + PointElement, + LineElement ); const primaryColor = 'rgba(53, 162, 235, 0.5)'; @@ -51,6 +55,22 @@ export class ChartBox extends React.Component { @observable private _prevIndex: { dIndex: number, index: number} | undefined = undefined; @observable private _chartJsData: ChartJsData | undefined= undefined; + @computed get currView() { + if (this.props.rootDoc._dataVizView) { + return StrCast(this.props.rootDoc._currChartView); + } else { + return "table"; + } + } + + constructor(props: any) { + super(props); + if (!this.props.rootDoc._currChartView) { + // TODO: nda - this might not always want to default to "table" + this.props.rootDoc._currChartView = "bar"; + } + } + @computed get options() { return { responsive: true, @@ -92,6 +112,14 @@ export class ChartBox extends React.Component { this.generateChartJsData(); } + @action + onClickChangeChart = (e: React.MouseEvent) => { + e.preventDefault(); + e.stopPropagation(); + console.log(e.currentTarget.value); + this.props.rootDoc._currChartView = e.currentTarget.value.toLowerCase(); + } + @action onClick = (e: any) => { e.preventDefault(); @@ -116,7 +144,18 @@ export class ChartBox extends React.Component { render() { if (this.props.pairs && this._chartJsData) { - return this.onClick(e)} /> + return ( +
+
+ {this.props.rootDoc._currChartView == "line" ? + ( this.onClick(e)} />) : + ( this.onClick(e)} />) + } +
+ + +
+ ) } else { return
} -- cgit v1.2.3-70-g09d2