From 1b568af6b2725b9eed6f591bfce193d39d5804de Mon Sep 17 00:00:00 2001 From: bobzel Date: Sat, 18 Nov 2023 14:36:09 -0500 Subject: fixed scaling of dataviz boxes when native dims are set. --- src/client/views/nodes/DataVizBox/DataVizBox.tsx | 34 ++++++++++------------ .../views/nodes/DataVizBox/components/PieChart.tsx | 6 +--- 2 files changed, 17 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/client/views/nodes/DataVizBox/DataVizBox.tsx b/src/client/views/nodes/DataVizBox/DataVizBox.tsx index b3f813eda..1cb0a50f3 100644 --- a/src/client/views/nodes/DataVizBox/DataVizBox.tsx +++ b/src/client/views/nodes/DataVizBox/DataVizBox.tsx @@ -109,28 +109,26 @@ export class DataVizBox extends ViewBoxAnnotatableComponent() { }; // toggles for user to decide which chart type to view the data in - renderVizView = () => { + @computed get renderVizView() { + const scale = this.props.NativeDimScaling?.() || 1; const sharedProps = { rootDoc: this.rootDoc, layoutDoc: this.layoutDoc, records: this.records, axes: this.axes, - height: (this.props.PanelHeight() * (this.props.NativeDimScaling?.() || 1) - 32) /* height of 'change view' button */ * 0.9, - width: this.props.PanelWidth() * (this.props.NativeDimScaling?.() || 1) * 0.9, + height: (this.props.PanelHeight() / scale - 32) /* height of 'change view' button */ * 0.9, + width: (this.props.PanelWidth() / scale) * 0.9, margin: { top: 10, right: 25, bottom: 75, left: 45 }, }; if (!this.records.length) return 'no data/visualization'; switch (this.dataVizView) { - case DataVizView.TABLE: - return ; - case DataVizView.LINECHART: - return (this._vizRenderer = r ?? undefined)} />; - case DataVizView.HISTOGRAM: - return (this._vizRenderer = r ?? undefined)} />; - case DataVizView.PIECHART: - return (this._vizRenderer = r ?? undefined)} />; - } - }; + case DataVizView.TABLE: return ; + case DataVizView.LINECHART: return (this._vizRenderer = r ?? undefined)} />; + case DataVizView.HISTOGRAM: return (this._vizRenderer = r ?? undefined)} />; + case DataVizView.PIECHART: return (this._vizRenderer = r ?? undefined)} + margin={{ top: 10, right: 15, bottom: 15, left: 15 }} />; + } // prettier-ignore + } render() { const scale = this.props.NativeDimScaling?.() || 1; @@ -160,12 +158,12 @@ export class DataVizBox extends ViewBoxAnnotatableComponent() { ) }>
- (this.layoutDoc._dataViz = DataVizView.TABLE)} toggleStatus={this.layoutDoc._dataViz == DataVizView.TABLE} /> - (this.layoutDoc._dataViz = DataVizView.LINECHART)} toggleStatus={this.layoutDoc._dataViz == DataVizView.LINECHART} /> - (this.layoutDoc._dataViz = DataVizView.HISTOGRAM)} toggleStatus={this.layoutDoc._dataViz == DataVizView.HISTOGRAM} /> - (this.layoutDoc._dataViz = DataVizView.PIECHART)} toggleStatus={this.layoutDoc._dataViz == DataVizView.PIECHART} /> + (this.layoutDoc._dataViz = DataVizView.TABLE)} toggleStatus={this.layoutDoc._dataViz === DataVizView.TABLE} /> + (this.layoutDoc._dataViz = DataVizView.LINECHART)} toggleStatus={this.layoutDoc._dataViz === DataVizView.LINECHART} /> + (this.layoutDoc._dataViz = DataVizView.HISTOGRAM)} toggleStatus={this.layoutDoc._dataViz === DataVizView.HISTOGRAM} /> + (this.layoutDoc._dataViz = DataVizView.PIECHART)} toggleStatus={this.layoutDoc._dataViz == -DataVizView.PIECHART} />
- {this.renderVizView()} + {this.renderVizView} ); } diff --git a/src/client/views/nodes/DataVizBox/components/PieChart.tsx b/src/client/views/nodes/DataVizBox/components/PieChart.tsx index 561f39141..7303eb184 100644 --- a/src/client/views/nodes/DataVizBox/components/PieChart.tsx +++ b/src/client/views/nodes/DataVizBox/components/PieChart.tsx @@ -88,11 +88,7 @@ export class PieChart extends React.Component { componentDidMount = () => { this._disposers.chartData = reaction( () => ({ dataSet: this._pieChartData, w: this.width, h: this.height }), - ({ dataSet, w, h }) => { - if (dataSet!.length > 0) { - this.drawChart(dataSet, w, h); - } - }, + ({ dataSet, w, h }) => dataSet!.length > 0 && this.drawChart(dataSet, w, h), { fireImmediately: true } ); }; -- cgit v1.2.3-70-g09d2