From e6d1dd82f5d472bddaf66f9210142249d6fa09aa Mon Sep 17 00:00:00 2001 From: Naafiyan Ahmed Date: Wed, 6 Jul 2022 20:21:04 -0400 Subject: added endpoint routes for csv and integrated chartjs --- src/client/views/nodes/DataVizBox/HistogramBox.tsx | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/client/views/nodes/DataVizBox/HistogramBox.tsx') diff --git a/src/client/views/nodes/DataVizBox/HistogramBox.tsx b/src/client/views/nodes/DataVizBox/HistogramBox.tsx index 00dc2ef46..4488323fe 100644 --- a/src/client/views/nodes/DataVizBox/HistogramBox.tsx +++ b/src/client/views/nodes/DataVizBox/HistogramBox.tsx @@ -3,6 +3,7 @@ import { observer } from "mobx-react"; import * as React from "react"; import { Doc } from "../../../../fields/Doc"; import { NumCast } from "../../../../fields/Types"; +import { DragManager } from "../../../util/DragManager"; import "./HistogramBox.scss"; interface HistogramBoxProps { @@ -15,6 +16,8 @@ interface HistogramBoxProps { export class HistogramBox extends React.Component { + private _dropXDispoer?: DragManager.DragDropDisposer; + private _dropYDispoer?: DragManager.DragDropDisposer; private origin = {x: 0.1 * this.width, y: 0.9 * this.height}; -- cgit v1.2.3-70-g09d2 From ba8cb4194062b0f939afd136a269625f9f26dcaa Mon Sep 17 00:00:00 2001 From: Naafiyan Ahmed Date: Mon, 25 Jul 2022 19:10:55 -0400 Subject: cleaned up code and moved files around --- src/client/views/nodes/DataVizBox/ChartBox.tsx | 101 +------- .../views/nodes/DataVizBox/ChartInterface.ts | 33 +++ src/client/views/nodes/DataVizBox/DataVizBox.tsx | 2 +- src/client/views/nodes/DataVizBox/DrawHelper.ts | 247 ------------------- .../views/nodes/DataVizBox/HistogramBox.scss | 18 -- src/client/views/nodes/DataVizBox/HistogramBox.tsx | 162 ------------- .../nodes/DataVizBox/HistogramBoxPrimitives.scss | 0 .../nodes/DataVizBox/HistogramBoxPrimitives.tsx | 16 -- .../nodes/DataVizBox/HistogramLabelPrimitives.scss | 0 .../nodes/DataVizBox/HistogramLabelPrimitives.tsx | 13 - src/client/views/nodes/DataVizBox/LineChart.tsx | 269 -------------------- src/client/views/nodes/DataVizBox/TableBox.scss | 22 -- src/client/views/nodes/DataVizBox/TableBox.tsx | 37 --- .../views/nodes/DataVizBox/components/Chart.scss | 10 + .../nodes/DataVizBox/components/LineChart.tsx | 270 +++++++++++++++++++++ .../nodes/DataVizBox/components/TableBox.scss | 22 ++ .../views/nodes/DataVizBox/components/TableBox.tsx | 37 +++ src/client/views/nodes/DataVizBox/utils/D3Utils.ts | 12 +- 18 files changed, 386 insertions(+), 885 deletions(-) create mode 100644 src/client/views/nodes/DataVizBox/ChartInterface.ts delete mode 100644 src/client/views/nodes/DataVizBox/DrawHelper.ts delete mode 100644 src/client/views/nodes/DataVizBox/HistogramBox.scss delete mode 100644 src/client/views/nodes/DataVizBox/HistogramBox.tsx delete mode 100644 src/client/views/nodes/DataVizBox/HistogramBoxPrimitives.scss delete mode 100644 src/client/views/nodes/DataVizBox/HistogramBoxPrimitives.tsx delete mode 100644 src/client/views/nodes/DataVizBox/HistogramLabelPrimitives.scss delete mode 100644 src/client/views/nodes/DataVizBox/HistogramLabelPrimitives.tsx delete mode 100644 src/client/views/nodes/DataVizBox/LineChart.tsx delete mode 100644 src/client/views/nodes/DataVizBox/TableBox.scss delete mode 100644 src/client/views/nodes/DataVizBox/TableBox.tsx create mode 100644 src/client/views/nodes/DataVizBox/components/Chart.scss create mode 100644 src/client/views/nodes/DataVizBox/components/LineChart.tsx create mode 100644 src/client/views/nodes/DataVizBox/components/TableBox.scss create mode 100644 src/client/views/nodes/DataVizBox/components/TableBox.tsx (limited to 'src/client/views/nodes/DataVizBox/HistogramBox.tsx') diff --git a/src/client/views/nodes/DataVizBox/ChartBox.tsx b/src/client/views/nodes/DataVizBox/ChartBox.tsx index f2450bc7c..a2e4fd73c 100644 --- a/src/client/views/nodes/DataVizBox/ChartBox.tsx +++ b/src/client/views/nodes/DataVizBox/ChartBox.tsx @@ -1,11 +1,10 @@ import { observer } from 'mobx-react'; import * as React from 'react'; import { Doc, HeightSym } from '../../../../fields/Doc'; -import { ChartJSOrUndefined } from 'react-chartjs-2/dist/types'; import { action, computed, observable } from 'mobx'; import { Cast, NumCast, StrCast } from '../../../../fields/Types'; -import { CategoricalChartState } from 'recharts/types/chart/generateCategoricalChart'; -import { LineChart } from './LineChart'; +import { LineChart } from './components/LineChart'; +import { Chart, ChartData } from './ChartInterface'; export interface ChartBoxProps { rootDoc: Doc; @@ -15,26 +14,11 @@ export interface ChartBoxProps { getAnchor: () => Doc; } -const primaryColor = 'rgba(53, 162, 235, 0.5)'; -const selectedColor = 'rgba(255, 99, 132, 0.5)'; - -export interface RechartData { - name: string | number; - y: number; -} - export interface DataPoint { x: number; y: number; } -export interface ChartData { - xLabel: string; - yLabel: string; - data: DataPoint[]; - tooltipContent: (data: DataPoint) => string; -} - @observer export class ChartBox extends React.Component { @observable private _chartData: ChartData | undefined = undefined; @@ -55,7 +39,7 @@ export class ChartBox extends React.Component { } } - setCurrChart(chart: LineChart | undefined) { + setCurrChart(chart: Chart | undefined) { // this.currChart = chart; } @@ -69,17 +53,15 @@ export class ChartBox extends React.Component { const data: ChartData = { xLabel: '', yLabel: '', - data: [], - tooltipContent: (data: DataPoint) => { - return `x: ${data.x} y: ${data.y}`; - }, + data: [[]], }; if (this.props.pairs && this.props.pairs.length > 0) { data.xLabel = 'x'; data.yLabel = 'y'; this.props.pairs.forEach(pair => { - data.data.push({ x: pair.x, y: pair.y }); + // TODO: nda - add actual support for multiple sets of data + data.data[0].push({ x: pair.x, y: pair.y }); }); } @@ -87,30 +69,7 @@ export class ChartBox extends React.Component { this.props.rootDoc._chartData = JSON.stringify(data); } - // @action - // generateChartJsData() { - // if (this.props.rootDoc._chartData) { - // // parse the string into a json object - // this._chartJsData = JSON.parse(StrCast(this.props.rootDoc._chartData)); - // this._prevColor = StrCast(this.props.rootDoc._prevColor); - // this._prevIndex = JSON.parse(StrCast(this.props.rootDoc._prevIndex)); - // return; - // } - // const labels = this.props.pairs.map(p => p.x); - // const dataset = { - // label: 'Dataset 1', - // data: this.props.pairs.map(p => p.y), - // backgroundColor: this.props.pairs.map(p => primaryColor), - // }; - // const data = { - // labels, - // datasets: [dataset], - // }; - // this._chartJsData = data; - // } - componentDidMount() { - // this.generateChartJsData(); this.generateChartData(); // setting timeout to allow rerender cycle of the actual chart tof inish setTimeout(() => { @@ -127,21 +86,6 @@ export class ChartBox extends React.Component { this.props.rootDoc._currChartView = e.currentTarget.value.toLowerCase(); }; - onMouseMove = (e: CategoricalChartState) => { - console.log(e); - - // pops up at 526 when it should be at 263 - // at 100%scale it pops up at 526 but mouse shows 263 at 50% scale - if (e.chartX && e.chartY) { - e.chartX += 263; - e.chartY += 263; - } - // if (e.chartX && e.chartY) { - // e.chartX -= 200; - // e.chartY -= 200; - // } - }; - scrollFocus(doc: Doc, smooth: boolean) {} handleDotClick = (e: any) => { @@ -152,37 +96,6 @@ export class ChartBox extends React.Component { return this.currChart?._getAnchor(); } - // handleTextClick = (e: any) => { - // console.log(e); - // } - - // @computed get reLineChart() { - // return ( - // // - // console.log(e)} - // onMouseMove={e => this.onMouseMove(e)}> - // - // console.log(e)} /> - // - // - // - // - // {/* */} - // - // // - // ); - // } - render() { if (this.props.pairs && this._chartData) { let width = NumCast(this.props.rootDoc._width); @@ -200,7 +113,7 @@ export class ChartBox extends React.Component { this.onClick(e)} /> )} */} {/* {this.reLineChart} */} - +