aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/DataVizBox/components/LineChart.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/nodes/DataVizBox/components/LineChart.tsx')
-rw-r--r--src/client/views/nodes/DataVizBox/components/LineChart.tsx33
1 files changed, 23 insertions, 10 deletions
diff --git a/src/client/views/nodes/DataVizBox/components/LineChart.tsx b/src/client/views/nodes/DataVizBox/components/LineChart.tsx
index 313164691..2357b7c69 100644
--- a/src/client/views/nodes/DataVizBox/components/LineChart.tsx
+++ b/src/client/views/nodes/DataVizBox/components/LineChart.tsx
@@ -4,6 +4,7 @@ import * as React from 'react';
// import d3
import * as d3 from 'd3';
import { Doc, DocListCast } from '../../../../../fields/Doc';
+import { List } from '../../../../../fields/List';
import { listSpec } from '../../../../../fields/Schema';
import { Cast } from '../../../../../fields/Types';
import { Docs } from '../../../../documents/Documents';
@@ -32,7 +33,8 @@ export interface LineChartData {
}
export interface LineChartProps {
rootDoc: Doc;
- pairs: { x: number; y: number }[];
+ axes: string[];
+ pairs: { [key: string]: any }[];
width: number;
height: number;
dataDoc: Doc;
@@ -67,8 +69,13 @@ export class LineChart extends React.Component<LineChartProps> {
Array.from(Object.keys(this._disposers)).forEach(key => this._disposers[key]());
}
componentDidMount = () => {
+ this._disposers.chartdata = reaction(
+ () => this.props.axes.slice(),
+ axes => axes.length > 1 && this.generateChartData(),
+ { fireImmediately: true }
+ );
this._disposers.chartData = reaction(
- () => ({ dataSet: this._lineChartData?.dataSet, w: this.props.width, h: this.props.height }),
+ () => ({ dataSet: this._lineChartData?.dataSet, axes: this.props.axes.slice(), w: this.props.width, h: this.props.height }),
vals => {
if (vals.dataSet) {
this._rangeVals = minMaxRange(vals.dataSet);
@@ -89,16 +96,15 @@ export class LineChart extends React.Component<LineChartProps> {
},
{ fireImmediately: true }
);
- this.generateChartData();
};
@action
generateChartData() {
this._lineChartData = {
- xLabel: 'x',
- yLabel: 'y',
+ xLabel: this.props.axes[0],
+ yLabel: this.props.axes[1],
// TODO: nda - add actual support for multiple sets of data
- dataSet: [this.props.pairs?.map(pair => ({ x: pair.x, y: pair.y }))],
+ dataSet: [this.props.pairs?.map(pair => ({ x: Number(pair[this.props.axes[0]]), y: Number(pair[this.props.axes[1]]) }))],
};
}
@@ -129,12 +135,17 @@ export class LineChart extends React.Component<LineChartProps> {
// loop through and remove any annotations that no longer exist
}
+ @action
restoreView = (data: Doc) => {
- const coords = Cast(data.presDataViz, listSpec('number'), null);
- if ((coords && this._currSelected?.x !== coords[0]) || this._currSelected?.y !== coords[1]) {
+ const coords = Cast(data.presDataVizSelection, listSpec('number'), null);
+ if (coords?.length > 1 && (this._currSelected?.x !== coords[0] || this._currSelected?.y !== coords[1])) {
this.setCurrSelected(coords[0], coords[1]);
return true;
}
+ if (this._currSelected) {
+ this._currSelected = undefined;
+ return true;
+ }
return false;
};
@@ -143,7 +154,8 @@ export class LineChart extends React.Component<LineChartProps> {
const anchor = Docs.Create.TextanchorDocument({
title: 'line doc selection' + this._currSelected?.x,
});
- PresBox.pinDocView(anchor, { pinDocLayout: pinProps?.pinDocLayout, pinData: { ...(pinProps?.pinData ?? {}), dataviz: this._currSelected ? [this._currSelected.x, this._currSelected.y] : undefined } }, this.props.dataDoc);
+ PresBox.pinDocView(anchor, { pinDocLayout: pinProps?.pinDocLayout, pinData: pinProps?.pinData }, this.props.dataDoc);
+ anchor.presDataVizSelection = this._currSelected ? new List<number>([this._currSelected.x, this._currSelected.y]) : undefined;
return anchor;
};
@@ -277,9 +289,10 @@ export class LineChart extends React.Component<LineChartProps> {
};
render() {
+ const selectedPt = this._currSelected ? `x: ${this._currSelected.x} y: ${this._currSelected.y}` : 'none';
return (
<div ref={this._lineChartRef} className="chart-container">
- <span>Curr Selected: {this._currSelected ? `x: ${this._currSelected.x} y: ${this._currSelected.y}` : 'none'}</span>
+ <span> {this.props.axes.length < 2 ? 'first use table view to select two axes to plot' : `Curr Selected: ${selectedPt}`}</span>
</div>
);
}