aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client/views/nodes/DataVizBox/ChartBox.tsx14
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() {