aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/DataVizBox/DataVizBox.tsx
diff options
context:
space:
mode:
authorsrichman333 <sarah_n_richman@brown.edu>2023-10-10 16:21:41 -0400
committersrichman333 <sarah_n_richman@brown.edu>2023-10-10 16:21:41 -0400
commit9e91e6065333f03d3f3bf2c0d43b822d85344c78 (patch)
tree4c923fc8257b597d69700bee4c1a4e69d3cbe21a /src/client/views/nodes/DataVizBox/DataVizBox.tsx
parent368e33c076085b1b73f522ac88f548a2ad081c80 (diff)
parentd929c0511cae863412a398f426d9e5b7ca64e6d9 (diff)
merge?
Diffstat (limited to 'src/client/views/nodes/DataVizBox/DataVizBox.tsx')
-rw-r--r--src/client/views/nodes/DataVizBox/DataVizBox.tsx81
1 files changed, 24 insertions, 57 deletions
diff --git a/src/client/views/nodes/DataVizBox/DataVizBox.tsx b/src/client/views/nodes/DataVizBox/DataVizBox.tsx
index 28dbe7578..903b3b9d0 100644
--- a/src/client/views/nodes/DataVizBox/DataVizBox.tsx
+++ b/src/client/views/nodes/DataVizBox/DataVizBox.tsx
@@ -43,7 +43,7 @@ export class DataVizBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
// all CSV records in the dataset (that aren't an empty row)
@computed.struct get records() {
var records = DataVizBox.dataset.get(CsvCast(this.rootDoc[this.fieldKey]).url.href);
- return records?.filter(record => Object.keys(record).some(key => record[key]));
+ return records?.filter(record => Object.keys(record).some(key => record[key])) ?? [];
}
// currently chosen visualization type: line, pie, histogram, table
@@ -229,71 +229,38 @@ export class DataVizBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
// toggles for user to decide which chart type to view the data in
renderVizView = () => {
- let width = this.props.PanelWidth() * 0.9;
- if (this.SidebarShown) width = width/1.2
- const height = (this.props.PanelHeight() - 32) /* height of 'change view' button */ * 0.9;
- const margin = { top: 10, right: 25, bottom: 75, left: 45 };
- if (this.records) {
- switch (this.dataVizView) {
- case DataVizView.TABLE:
- return <div className="data-view"><TableBox layoutDoc={this.layoutDoc} records={this.records} axes={this.axes} height={height} width={width} margin={margin} rootDoc={this.rootDoc} docView={this.props.DocumentView} selectAxes={this.selectAxes} /></div>;
- case DataVizView.LINECHART:
- return (
- <LineChart
- layoutDoc={this.layoutDoc}
- ref={r => (this._vizRenderer = r ?? undefined)}
- height={height}
- width={width}
- fieldKey={this.fieldKey}
- margin={margin}
- rootDoc={this.rootDoc}
- axes={this.axes}
- records={this.records}
- dataDoc={this.dataDoc}
- />
- );
- case DataVizView.HISTOGRAM:
- return (
- <Histogram
- layoutDoc={this.layoutDoc}
- ref={r => (this._vizRenderer = r ?? undefined)}
- height={height}
- width={width}
- fieldKey={this.fieldKey}
- margin={margin}
- rootDoc={this.rootDoc}
- axes={this.axes}
- records={this.records}
- dataDoc={this.dataDoc}
- />
- );
- case DataVizView.PIECHART:
- return (
- <PieChart
- layoutDoc={this.layoutDoc}
- ref={r => (this._vizRenderer = r ?? undefined)}
- height={height}
- width={width}
- fieldKey={this.fieldKey}
- margin={margin}
- rootDoc={this.rootDoc}
- axes={this.axes}
- records={this.records}
- dataDoc={this.dataDoc}
- />
- );
- }
+ const sharedProps = {
+ rootDoc: this.rootDoc,
+ layoutDoc: this.layoutDoc,
+ records: this.records,
+ axes: this.axes,
+ height: (this.props.PanelHeight() - 32) /* height of 'change view' button */ * 0.9,
+ width: this.props.PanelWidth() * 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 <TableBox {...sharedProps} docView={this.props.DocumentView} selectAxes={this.selectAxes} />;
+ case DataVizView.LINECHART:
+ return <LineChart {...sharedProps} dataDoc={this.dataDoc} fieldKey={this.fieldKey} ref={r => (this._vizRenderer = r ?? undefined)} />;
+ case DataVizView.HISTOGRAM:
+ return <Histogram {...sharedProps} dataDoc={this.dataDoc} fieldKey={this.fieldKey} ref={r => (this._vizRenderer = r ?? undefined)} />;
+ case DataVizView.PIECHART:
+ return <PieChart {...sharedProps} dataDoc={this.dataDoc} fieldKey={this.fieldKey} ref={r => (this._vizRenderer = r ?? undefined)} />;
}
- return 'no data/visualization';
};
render() {
- return !this.records?.length ? (
+ return !this.records.length ? (
// displays how to get data into the DataVizBox if its empty
<div className="start-message">To create a DataViz box, either import / drag a CSV file into your canvas or copy a data table and use the command 'ctrl + p' to bring the data table to your canvas.</div>
) : (
<div
className="dataViz"
+ style={{
+ pointerEvents: this.props.isContentActive() === true ? 'all' : 'none',
+ }}
onWheel={e => e.stopPropagation()}
ref={r =>
r?.addEventListener(