From 923b0d20cd95311122ec5886698b3fb2dfadb882 Mon Sep 17 00:00:00 2001
From: srichman333 <sarah_n_richman@brown.edu>
Date: Fri, 12 Jan 2024 12:56:09 -0500
Subject: live schema toggle works on refresh

---
 .../views/collections/collectionFreeForm/CollectionFreeFormView.tsx  | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

(limited to 'src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx')

diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
index 8268a47d8..de4f01014 100644
--- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
+++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
@@ -2005,15 +2005,14 @@ ScriptingGlobals.add(function datavizFromSchema(doc: Doc) {
             csvRows.push(eachRow);
         }
         const blob = new Blob([csvRows.join('\n')], { type: 'text/csv' });
-        const options = { x: 0, y: -300, title: 'schemaTable', _width: 300, _height: 100, type: 'text/csv' };
+        const options = { x: 0, y: 0, title: 'schemaTable', _width: 300, _height: 100, type: 'text/csv' };
         const file = new File([blob], 'schemaTable', options);
         const loading = Docs.Create.LoadingDocument(file, options);
         loading.presentation_openInLightbox = true;
         DocUtils.uploadFileToDoc(file, {}, loading);
 
         if (view.ComponentView?.addDocument) {
-            //  loading.dataViz_fromSchema = true;
-            loading.dataViz_asSchema = view.layoutDoc;
+            loading._dataViz_asSchema = view.layoutDoc;
             SchemaCSVPopUp.Instance.setView(view);
             SchemaCSVPopUp.Instance.setTarget(view.layoutDoc);
             SchemaCSVPopUp.Instance.setDataVizDoc(loading);
-- 
cgit v1.2.3-70-g09d2


From db51496360e8eac55b5e83283370c4aeec7a11d8 Mon Sep 17 00:00:00 2001
From: srichman333 <sarah_n_richman@brown.edu>
Date: Wed, 17 Jan 2024 15:01:30 -0500
Subject: cleaner

---
 .../collectionFreeForm/CollectionFreeFormView.tsx  |   2 +
 src/client/views/nodes/DataVizBox/DataVizBox.tsx   | 116 +++++++++------------
 .../views/nodes/DataVizBox/components/TableBox.tsx |   2 -
 3 files changed, 52 insertions(+), 68 deletions(-)

(limited to 'src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx')

diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
index de4f01014..881c80a1a 100644
--- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
+++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
@@ -1985,6 +1985,7 @@ ScriptingGlobals.add(function sendToBack(doc: Doc) {
     SelectionManager.Views.forEach(view => view.CollectionFreeFormView?.bringToFront(view.Document, true));
 });
 ScriptingGlobals.add(function datavizFromSchema(doc: Doc) {
+    // creating a dataviz doc to represent the schema table
     SelectionManager.Views.forEach(view => {
         if (!view.layoutDoc.schema_columnKeys) {
             view.layoutDoc.schema_columnKeys = new List<string>(['title', 'type', 'author', 'author_date']);
@@ -2011,6 +2012,7 @@ ScriptingGlobals.add(function datavizFromSchema(doc: Doc) {
         loading.presentation_openInLightbox = true;
         DocUtils.uploadFileToDoc(file, {}, loading);
 
+        // holds the doc in a popup until it is dragged onto a canvas
         if (view.ComponentView?.addDocument) {
             loading._dataViz_asSchema = view.layoutDoc;
             SchemaCSVPopUp.Instance.setView(view);
diff --git a/src/client/views/nodes/DataVizBox/DataVizBox.tsx b/src/client/views/nodes/DataVizBox/DataVizBox.tsx
index 6d060f535..981ec0aa1 100644
--- a/src/client/views/nodes/DataVizBox/DataVizBox.tsx
+++ b/src/client/views/nodes/DataVizBox/DataVizBox.tsx
@@ -1,6 +1,6 @@
 import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
 import { Colors, Toggle, ToggleType, Type } from 'browndash-components';
-import { ObservableMap, action, computed, makeObservable, observable, runInAction } from 'mobx';
+import { ObservableMap, action, computed, observable, runInAction } from 'mobx';
 import { observer } from 'mobx-react';
 import * as React from 'react';
 import { emptyFunction, returnEmptyString, returnFalse, returnOne, setupMoveUpEvents } from '../../../../Utils';
@@ -17,7 +17,6 @@ import { UndoManager, undoable } from '../../../util/UndoManager';
 import { ViewBoxAnnotatableComponent } from '../../DocComponent';
 import { MarqueeAnnotator } from '../../MarqueeAnnotator';
 import { SidebarAnnos } from '../../SidebarAnnos';
-import { CollectionFreeFormView } from '../../collections/collectionFreeForm';
 import { AnchorMenu } from '../../pdf/AnchorMenu';
 import { GPTPopup } from '../../pdf/GPTPopup/GPTPopup';
 import { DocFocusOptions, DocumentView } from '../DocumentView';
@@ -339,59 +338,63 @@ export class DataVizBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
     }
 
     @action
+    // handles when the dataviz doc was made by copying a schema table
     updateSchemaViz = () => {
         const href = CsvCast(this.Document[this.fieldKey]).url.href;
-
-        if (this.layoutDoc.dataViz_schemaLive || !DataVizBox.datasetSchemaOG.has(href)){
-            const getFrom = DocCast(this.layoutDoc.dataViz_asSchema);
-            const keys = Cast(getFrom.schema_columnKeys, listSpec('string'))?.filter(key => key != 'text');
-            if (!keys) return;
-            const children = DocListCast(getFrom[Doc.LayoutFieldKey(getFrom)]);
-
-            if (!this.layoutDoc._dataViz_schemaOG){
-                let csvRows = [];
-                csvRows.push(keys.join(','));
-                for (let i = 0; i < children.length; 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 getFromDoc = DocCast(this.layoutDoc.dataViz_asSchema);
+        const children = DocListCast(getFromDoc[Doc.LayoutFieldKey(getFromDoc)]);
+
+        if (children.length != this.schemaBoxLength) {
+            if (this.layoutDoc.dataViz_schemaLive || !DataVizBox.datasetSchemaOG.has(href)){
+                const keys = Cast(getFromDoc.schema_columnKeys, listSpec('string'))?.filter(key => key != 'text');
+                if (!keys) return;
+
+                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; 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);
                     }
-                    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 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;
-            if (ogHref && !DataVizBox.datasetSchemaOG.has(href)){
-                DataVizBox.datasetSchemaOG.set(href, []);
-                fetch('/csvData?uri=' + ogHref)
-                    .then(res => res.json().then(action(res => !res.errno && DataVizBox.datasetSchemaOG.set(href, res))));
-            }
+                const ogDoc = this.layoutDoc._dataViz_schemaOG as Doc
+                const ogHref = CsvCast(ogDoc[this.fieldKey])? CsvCast(ogDoc[this.fieldKey]).url.href : undefined;
+                if (ogHref && !DataVizBox.datasetSchemaOG.has(href)){
+                    DataVizBox.datasetSchemaOG.set(href, []);
+                    fetch('/csvData?uri=' + ogHref)
+                        .then(res => res.json().then(action(res => !res.errno && DataVizBox.datasetSchemaOG.set(href, res))));
+                }
 
-            var current: { [key: string]: string }[] = [];
-            for (let i = 0; i < children.length; i++) {
-                var row: { [key: string]: string } = {};
-                if (children[i]) {
-                    for (let j = 0; j < keys.length; j++) {
-                        var cell = children[i][keys[j]];
-                        if (cell && (cell as string)) cell = cell.toString().replace(/\,/g, '');
-                        row[keys[j]] = StrCast(cell);
+                var current: { [key: string]: string }[] = [];
+                for (let i = 0; i < children.length; i++) {
+                    var row: { [key: string]: string } = {};
+                    if (children[i]) {
+                        for (let j = 0; j < keys.length; j++) {
+                            var cell = children[i][keys[j]];
+                            if (cell && (cell as string)) cell = cell.toString().replace(/\,/g, '');
+                            row[keys[j]] = StrCast(cell);
+                        }
                     }
+                    current.push(row);
                 }
-                current.push(row);
+                this.setDataset(href, current);
+            }
+            else {
+                this.setDataset(href, DataVizBox.datasetSchemaOG.get(href));
             }
-            this.setDataset(href, current);
-        }
-        else {
-            this.setDataset(href, DataVizBox.datasetSchemaOG.get(href));
         }
     };
 
@@ -425,26 +428,6 @@ export class DataVizBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
                     <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>
 
-                {/* <CollectionFreeFormView
-                    ref={this._ffref}
-                    {...this._props}
-                    setContentView={emptyFunction}
-                    renderDepth={this._props.renderDepth - 1}
-                    fieldKey={this.annotationKey}
-                    styleProvider={this._props.styleProvider}
-                    isAnnotationOverlay={true}
-                    annotationLayerHostsContent={false}
-                    PanelWidth={this._props.PanelWidth}
-                    PanelHeight={this._props.PanelHeight}
-                    select={emptyFunction}
-                    isAnyChildContentActive={returnFalse}
-                    whenChildContentsActiveChanged={this.whenChildContentsActiveChanged}
-                    removeDocument={this.removeDocument}
-                    moveDocument={this.moveDocument}
-                    addDocument={this.addDocument}>
-                    {this.renderVizView}
-                </CollectionFreeFormView> */}
-
                 {(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} />
@@ -453,6 +436,7 @@ export class DataVizBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
                 ) : null}
 
                 {this.renderVizView}
+
                 <div className="dataviz-sidebar" style={{ width: `${this.sidebarWidthPercent}`, backgroundColor: `${this.sidebarColor}` }} onPointerDown={this.onPointerDown}>
                     <SidebarAnnos
                         ref={this._sidebarRef}
diff --git a/src/client/views/nodes/DataVizBox/components/TableBox.tsx b/src/client/views/nodes/DataVizBox/components/TableBox.tsx
index ed44d9269..c5fda18ae 100644
--- a/src/client/views/nodes/DataVizBox/components/TableBox.tsx
+++ b/src/client/views/nodes/DataVizBox/components/TableBox.tsx
@@ -83,14 +83,12 @@ export class TableBox extends ObservableReactComponent<TableBoxProps> {
         return this._props.docView?.()?.screenToViewTransform().Scale || 1;
     }
     @computed get rowHeight() {
-        console.log('scale = ' + this.viewScale + '  table = ' + this._tableHeight + ' ids = ' + this._tableDataIds.length);
         return (this.viewScale * this._tableHeight) / this._tableDataIds.length;
     }
     @computed get startID() {
         return this.rowHeight ? Math.max(Math.floor(this._scrollTop / this.rowHeight) - 1, 0) : 0;
     }
     @computed get endID() {
-        console.log('start = ' + this.startID + '  container = ' + this._tableContainerHeight + ' scale = ' + this.viewScale + ' row = ' + this.rowHeight);
         return Math.ceil(this.startID + (this._tableContainerHeight * this.viewScale) / (this.rowHeight || 1));
     }
     @action handleScroll = () => {
-- 
cgit v1.2.3-70-g09d2

