From 75387187e260a7f569b73b1e6e8057e5623b9650 Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Fri, 29 Mar 2024 18:16:13 -0400
Subject: small fix to retoreTargetView.  reformatted file.

---
 src/client/views/nodes/DataVizBox/DataVizBox.tsx | 79 ++++++++++++------------
 1 file changed, 40 insertions(+), 39 deletions(-)

(limited to 'src/client/views/nodes/DataVizBox/DataVizBox.tsx')

diff --git a/src/client/views/nodes/DataVizBox/DataVizBox.tsx b/src/client/views/nodes/DataVizBox/DataVizBox.tsx
index 66a08f13e..22f1f7b79 100644
--- a/src/client/views/nodes/DataVizBox/DataVizBox.tsx
+++ b/src/client/views/nodes/DataVizBox/DataVizBox.tsx
@@ -118,8 +118,8 @@ export class DataVizBox extends ViewBoxAnnotatableComponent<FieldViewProps>() im
 
     @action // pinned / linked anchor doc includes selected rows, graph titles, and graph colors
     restoreView = (data: Doc) => {
-        const changedView = this.dataVizView !== data.config_dataViz && (this.layoutDoc._dataViz = data.config_dataViz);
-        const changedAxes = this.axes.join('') !== StrListCast(data.config_dataVizAxes).join('') && (this.layoutDoc._dataViz_axes = new List<string>(StrListCast(data.config_dataVizAxes)));
+        const changedView = data.config_dataViz && this.dataVizView !== data.config_dataViz && (this.layoutDoc._dataViz = data.config_dataViz);
+        const changedAxes = data.config_dataVizAxes && this.axes.join('') !== StrListCast(data.config_dataVizAxes).join('') && (this.layoutDoc._dataViz_axes = new List<string>(StrListCast(data.config_dataVizAxes)));
         this.layoutDoc.dataViz_selectedRows = Field.Copy(data.dataViz_selectedRows);
         this.layoutDoc.dataViz_histogram_barColors = Field.Copy(data.dataViz_histogram_barColors);
         this.layoutDoc.dataViz_histogram_defaultColor = data.dataViz_histogram_defaultColor;
@@ -266,7 +266,7 @@ export class DataVizBox extends ViewBoxAnnotatableComponent<FieldViewProps>() im
         if (!DataVizBox.dataset.has(CsvCast(this.dataDoc[this.fieldKey]).url.href)) this.fetchData();
         this._disposers.datavis = reaction(
             () => {
-                if (this.layoutDoc.dataViz_schemaLive==undefined) this.layoutDoc.dataViz_schemaLive = true; 
+                if (this.layoutDoc.dataViz_schemaLive == undefined) this.layoutDoc.dataViz_schemaLive = true;
                 const getFrom = DocCast(this.layoutDoc.dataViz_asSchema);
                 const keys = Cast(getFrom?.schema_columnKeys, listSpec('string'))?.filter(key => key != 'text');
                 if (!keys) return;
@@ -283,42 +283,43 @@ export class DataVizBox extends ViewBoxAnnotatableComponent<FieldViewProps>() im
                         });
                         current.push(row);
                     });
-                    if (!this.layoutDoc._dataViz_schemaOG){ // makes a copy of the original table for the "live" toggle
-                        let csvRows = [];
-                        csvRows.push(keys.join(','));
-                        for (let i = 0; i < children.length-1; i++) {
-                            let eachRow = [];
-                            for (let j = 0; j < keys.length; j++) {
-                                var cell = children[i][keys[j]];
-                                if (cell && (cell as string)) cell = cell.toString().replace(/\,/g, '');
-                                eachRow.push(cell);
-                            }
-                            csvRows.push(eachRow);
+                if (!this.layoutDoc._dataViz_schemaOG) {
+                    // makes a copy of the original table for the "live" toggle
+                    let csvRows = [];
+                    csvRows.push(keys.join(','));
+                    for (let i = 0; i < children.length - 1; i++) {
+                        let eachRow = [];
+                        for (let j = 0; j < keys.length; j++) {
+                            var cell = children[i][keys[j]];
+                            if (cell && (cell as string)) cell = cell.toString().replace(/\,/g, '');
+                            eachRow.push(cell);
                         }
-                        const blob = new Blob([csvRows.join('\n')], { type: 'text/csv' });
-                        const options = { x: 0, y: 0, title: 'schemaTable for static dataviz', _width: 300, _height: 100, type: 'text/csv' };
-                        const file = new File([blob], 'schemaTable for static dataviz', options);
-                        const loading = Docs.Create.LoadingDocument(file, options);
-                        DocUtils.uploadFileToDoc(file, {}, loading);
-                        this.layoutDoc._dataViz_schemaOG = loading;
-                    }
-                    const ogDoc = this.layoutDoc._dataViz_schemaOG as Doc
-                    const ogHref = CsvCast(ogDoc[this.fieldKey])? CsvCast(ogDoc[this.fieldKey]).url.href : undefined;
-                    const href = CsvCast(this.Document[this.fieldKey]).url.href
-                    if (ogHref && !DataVizBox.datasetSchemaOG.has(href)){ // sets original dataset to the var
-                        const lastRow = current.pop();
-                        DataVizBox.datasetSchemaOG.set(href, current);
-                        current.push(lastRow!);
-                        fetch('/csvData?uri=' + ogHref)
-                            .then(res => res.json().then(action(res => !res.errno && DataVizBox.datasetSchemaOG.set(href, res))));
+                        csvRows.push(eachRow);
                     }
+                    const blob = new Blob([csvRows.join('\n')], { type: 'text/csv' });
+                    const options = { x: 0, y: 0, title: 'schemaTable for static dataviz', _width: 300, _height: 100, type: 'text/csv' };
+                    const file = new File([blob], 'schemaTable for static dataviz', options);
+                    const loading = Docs.Create.LoadingDocument(file, options);
+                    DocUtils.uploadFileToDoc(file, {}, loading);
+                    this.layoutDoc._dataViz_schemaOG = loading;
+                }
+                const ogDoc = this.layoutDoc._dataViz_schemaOG as Doc;
+                const ogHref = CsvCast(ogDoc[this.fieldKey]) ? CsvCast(ogDoc[this.fieldKey]).url.href : undefined;
+                const href = CsvCast(this.Document[this.fieldKey]).url.href;
+                if (ogHref && !DataVizBox.datasetSchemaOG.has(href)) {
+                    // sets original dataset to the var
+                    const lastRow = current.pop();
+                    DataVizBox.datasetSchemaOG.set(href, current);
+                    current.push(lastRow!);
+                    fetch('/csvData?uri=' + ogHref).then(res => res.json().then(action(res => !res.errno && DataVizBox.datasetSchemaOG.set(href, res))));
+                }
                 return current;
             },
             current => {
                 if (current) {
-                   const href = CsvCast(this.Document[this.fieldKey]).url.href;
-                   if (this.layoutDoc.dataViz_schemaLive) DataVizBox.dataset.set(href, current);
-                   else DataVizBox.dataset.set(href, DataVizBox.datasetSchemaOG.get(href)!);
+                    const href = CsvCast(this.Document[this.fieldKey]).url.href;
+                    if (this.layoutDoc.dataViz_schemaLive) DataVizBox.dataset.set(href, current);
+                    else DataVizBox.dataset.set(href, DataVizBox.datasetSchemaOG.get(href)!);
                 }
             },
             { fireImmediately: true }
@@ -399,8 +400,8 @@ export class DataVizBox extends ViewBoxAnnotatableComponent<FieldViewProps>() im
 
     @action
     changeLiveSchemaCheckbox = () => {
-        this.layoutDoc.dataViz_schemaLive = !this.layoutDoc.dataViz_schemaLive
-    }
+        this.layoutDoc.dataViz_schemaLive = !this.layoutDoc.dataViz_schemaLive;
+    };
 
     render() {
         const scale = this._props.NativeDimScaling?.() || 1;
@@ -427,11 +428,11 @@ export class DataVizBox extends ViewBoxAnnotatableComponent<FieldViewProps>() im
                     <Toggle text={'PIE CHART'} toggleType={ToggleType.BUTTON} type={Type.SEC} color={'black'} onClick={e => (this.layoutDoc._dataViz = DataVizView.PIECHART)} toggleStatus={this.layoutDoc._dataViz == -DataVizView.PIECHART} />
                 </div>
 
-                {(this.layoutDoc && this.layoutDoc.dataViz_asSchema)?(
+                {this.layoutDoc && this.layoutDoc.dataViz_asSchema ? (
                     <div className={'liveSchema-checkBox'} style={{ width: this._props.width }}>
-                    <Checkbox color="primary" onChange={this.changeLiveSchemaCheckbox} checked={this.layoutDoc.dataViz_schemaLive as boolean} />
-                    Display Live Updates to Canvas
-                </div>
+                        <Checkbox color="primary" onChange={this.changeLiveSchemaCheckbox} checked={this.layoutDoc.dataViz_schemaLive as boolean} />
+                        Display Live Updates to Canvas
+                    </div>
                 ) : null}
 
                 {this.renderVizView}
-- 
cgit v1.2.3-70-g09d2

