diff options
author | Naafiyan Ahmed <naafiyan@gmail.com> | 2022-07-06 20:50:30 -0400 |
---|---|---|
committer | Naafiyan Ahmed <naafiyan@gmail.com> | 2022-07-06 20:50:30 -0400 |
commit | 5a9cd07ae924bf7e3aeb5b70ce42bfa0a2900ddf (patch) | |
tree | 3a8af190981b2a3b46699ab65feb6117eba58d6c | |
parent | 1ccbb22c29ea406dae824b9163ddc676263bb83a (diff) |
storing render details in field
-rw-r--r-- | src/client/views/nodes/DataVizBox/ChartBox.tsx | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/client/views/nodes/DataVizBox/ChartBox.tsx b/src/client/views/nodes/DataVizBox/ChartBox.tsx index 56f61474b..26ccd1c12 100644 --- a/src/client/views/nodes/DataVizBox/ChartBox.tsx +++ b/src/client/views/nodes/DataVizBox/ChartBox.tsx @@ -14,6 +14,7 @@ import { import { Bar, getDatasetAtEvent, getElementAtEvent } from 'react-chartjs-2'; import { ChartJSOrUndefined } from "react-chartjs-2/dist/types"; import { action, computed, observable } from "mobx"; +import { Cast, StrCast } from "../../../../fields/Types"; export interface ChartBoxProps { @@ -67,6 +68,13 @@ export class ChartBox extends React.Component<ChartBoxProps> { @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', @@ -98,8 +106,12 @@ export class ChartBox extends React.Component<ChartBoxProps> { this._prevIndex = { dIndex: index.datasetIndex, index: index.index }; this._prevColor = this._chartJsData.datasets[index.datasetIndex].backgroundColor[index.index]; this._chartJsData.datasets[index.datasetIndex].backgroundColor[index.index] = selectedColor; - // TODO: nda - send data back to the backend so that we know how to render the chart this._chartRef.current.update(); + // stringify this._chartJsData + const strData = JSON.stringify(this._chartJsData); + this.props.rootDoc._chartData = strData; + this.props.rootDoc._prevColor = this._prevColor; + this.props.rootDoc._prevIndex = JSON.stringify(this._prevIndex); } render() { |