From 99e57e5c98a69b1d95e87ecc7728164748886a0e Mon Sep 17 00:00:00 2001
From: srichman333 <sarah_n_richman@brown.edu>
Date: Tue, 23 Jan 2024 12:24:22 -0500
Subject: non-numerical histogram fix

---
 src/client/views/nodes/DataVizBox/components/Histogram.tsx | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

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

diff --git a/src/client/views/nodes/DataVizBox/components/Histogram.tsx b/src/client/views/nodes/DataVizBox/components/Histogram.tsx
index 4a1fb2ed1..412957fb1 100644
--- a/src/client/views/nodes/DataVizBox/components/Histogram.tsx
+++ b/src/client/views/nodes/DataVizBox/components/Histogram.tsx
@@ -63,17 +63,17 @@ export class Histogram extends ObservableReactComponent<HistogramProps> {
         if (this._props.axes.length < 1) return [];
         if (this._props.axes.length < 2) {
             var ax0 = this._props.axes[0];
-            if (/\d/.test(this._props.records[0][ax0])) {
+            if (!/[A-Za-z-:]/.test(this._props.records[0][ax0])){
                 this.numericalXData = true;
             }
             return this._tableData.map(record => ({ [ax0]: record[this._props.axes[0]] }));
         }
         var ax0 = this._props.axes[0];
         var ax1 = this._props.axes[1];
-        if (/\d/.test(this._props.records[0][ax0])) {
+        if (!/[A-Za-z-:]/.test(this._props.records[0][ax0])) {
             this.numericalXData = true;
         }
-        if (/\d/.test(this._props.records[0][ax1])) {
+        if (!/[A-Za-z-:]/.test(this._props.records[0][ax1])) {
             this.numericalYData = true;
         }
         return this._tableData.map(record => ({ [ax0]: record[this._props.axes[0]], [ax1]: record[this._props.axes[1]] }));
@@ -89,9 +89,6 @@ export class Histogram extends ObservableReactComponent<HistogramProps> {
 
     @computed get parentViz() {
         return DocCast(this._props.Document.dataViz_parentViz);
-        // return LinkManager.Instance.getAllRelatedLinks(this._props.Document) // out of all links
-        //     .filter(link => link.link_anchor_1 == this._props.Document.dataViz_parentViz) // get links where this chart doc is the target of the link
-        //     .map(link => DocCast(link.link_anchor_1)); // then return the source of the link
     }
 
     @computed get rangeVals(): { xMin?: number; xMax?: number; yMin?: number; yMax?: number } {
-- 
cgit v1.2.3-70-g09d2


From aa3c70399ac2b6a337a9c85fb30f57f82ee44063 Mon Sep 17 00:00:00 2001
From: srichman333 <sarah_n_richman@brown.edu>
Date: Tue, 23 Jan 2024 13:22:13 -0500
Subject: data has a title column

---
 src/client/views/nodes/DataVizBox/DataVizBox.tsx   |  8 ++++++--
 .../nodes/DataVizBox/components/Histogram.tsx      |  1 +
 .../nodes/DataVizBox/components/LineChart.tsx      |  1 +
 .../views/nodes/DataVizBox/components/PieChart.tsx |  1 +
 .../views/nodes/DataVizBox/components/TableBox.tsx | 22 ++++++++++++++++------
 5 files changed, 25 insertions(+), 8 deletions(-)

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

diff --git a/src/client/views/nodes/DataVizBox/DataVizBox.tsx b/src/client/views/nodes/DataVizBox/DataVizBox.tsx
index 981ec0aa1..ea053b09d 100644
--- a/src/client/views/nodes/DataVizBox/DataVizBox.tsx
+++ b/src/client/views/nodes/DataVizBox/DataVizBox.tsx
@@ -104,8 +104,11 @@ export class DataVizBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
     @computed.struct get axes() {
         return StrListCast(this.layoutDoc._dataViz_axes);
     }
-
     selectAxes = (axes: string[]) => (this.layoutDoc._dataViz_axes = new List<string>(axes));
+    @computed.struct get titleCol() {
+        return StrCast(this.layoutDoc._dataViz_titleCol);
+    }
+    selectTitleCol = (titleCol: string) => (this.layoutDoc._dataViz_titleCol = titleCol);
 
     @action // pinned / linked anchor doc includes selected rows, graph titles, and graph colors
     restoreView = (data: Doc) => {
@@ -271,6 +274,7 @@ export class DataVizBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
             layoutDoc: this.layoutDoc,
             records: this.records,
             axes: this.axes,
+            titleCol: this.titleCol,
             //width: this.SidebarShown? this._props.PanelWidth()*.9/1.2: this._props.PanelWidth() * 0.9,
             height: (this._props.PanelHeight() / scale - 32) /* height of 'change view' button */ * 0.9,
             width: (this._props.PanelWidth() / scale) * 0.9,
@@ -278,7 +282,7 @@ export class DataVizBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
         };
         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.TABLE:     return <TableBox  {...sharedProps} docView={this._props.DocumentView} selectAxes={this.selectAxes} selectTitleCol={this.selectTitleCol}/>;
             case DataVizView.LINECHART: return <LineChart {...sharedProps} dataDoc={this.dataDoc} fieldKey={this.fieldKey} ref={r => (this._vizRenderer = r ?? undefined)} vizBox={this} />;
             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)} 
diff --git a/src/client/views/nodes/DataVizBox/components/Histogram.tsx b/src/client/views/nodes/DataVizBox/components/Histogram.tsx
index 412957fb1..44e8b97c6 100644
--- a/src/client/views/nodes/DataVizBox/components/Histogram.tsx
+++ b/src/client/views/nodes/DataVizBox/components/Histogram.tsx
@@ -20,6 +20,7 @@ export interface HistogramProps {
     Document: Doc;
     layoutDoc: Doc;
     axes: string[];
+    titleCol: string;
     records: { [key: string]: any }[];
     width: number;
     height: number;
diff --git a/src/client/views/nodes/DataVizBox/components/LineChart.tsx b/src/client/views/nodes/DataVizBox/components/LineChart.tsx
index 2a9a8b354..f23ab94a2 100644
--- a/src/client/views/nodes/DataVizBox/components/LineChart.tsx
+++ b/src/client/views/nodes/DataVizBox/components/LineChart.tsx
@@ -28,6 +28,7 @@ export interface LineChartProps {
     Document: Doc;
     layoutDoc: Doc;
     axes: string[];
+    titleCol: string;
     records: { [key: string]: any }[];
     width: number;
     height: number;
diff --git a/src/client/views/nodes/DataVizBox/components/PieChart.tsx b/src/client/views/nodes/DataVizBox/components/PieChart.tsx
index 1259a13ff..55c2208a3 100644
--- a/src/client/views/nodes/DataVizBox/components/PieChart.tsx
+++ b/src/client/views/nodes/DataVizBox/components/PieChart.tsx
@@ -19,6 +19,7 @@ export interface PieChartProps {
     Document: Doc;
     layoutDoc: Doc;
     axes: string[];
+    titleCol: string;
     records: { [key: string]: any }[];
     width: number;
     height: number;
diff --git a/src/client/views/nodes/DataVizBox/components/TableBox.tsx b/src/client/views/nodes/DataVizBox/components/TableBox.tsx
index c5fda18ae..c20509029 100644
--- a/src/client/views/nodes/DataVizBox/components/TableBox.tsx
+++ b/src/client/views/nodes/DataVizBox/components/TableBox.tsx
@@ -18,7 +18,9 @@ interface TableBoxProps {
     layoutDoc: Doc;
     records: { [key: string]: any }[];
     selectAxes: (axes: string[]) => void;
+    selectTitleCol: (titleCol: string) => void;
     axes: string[];
+    titleCol: string;
     width: number;
     height: number;
     margin: {
@@ -153,11 +155,18 @@ export class TableBox extends ObservableReactComponent<TableBoxProps> {
             },
             emptyFunction,
             action(e => {
-                const newAxes = this._props.axes;
-                if (newAxes.includes(col)) newAxes.splice(newAxes.indexOf(col), 1);
-                else if (newAxes.length > 1) newAxes[1] = col;
-                else newAxes.push(col);
-                this._props.selectAxes(newAxes);
+                if (e.shiftKey){
+                    if (this._props.titleCol == col) this._props.titleCol = "";
+                    else this._props.titleCol = col;
+                    this._props.selectTitleCol(this._props.titleCol);
+                }
+                else{
+                    const newAxes = this._props.axes;
+                    if (newAxes.includes(col)) newAxes.splice(newAxes.indexOf(col), 1);
+                    else if (newAxes.length > 1) newAxes[1] = col;
+                    else newAxes.push(col);
+                    this._props.selectAxes(newAxes);
+                }
             })
         );
     };
@@ -234,7 +243,8 @@ export class TableBox extends ObservableReactComponent<TableBoxProps> {
                                                 background: NumListCast(this._props.layoutDoc.dataViz_highlitedRows).includes(rowId) ? 'lightYellow' : NumListCast(this._props.layoutDoc.dataViz_selectedRows).includes(rowId) ? 'lightgrey' : '',
                                             }}>
                                             {this.columns.map(col => {
-                                                const colSelected = this._props.axes.length > 1 ? this._props.axes[0] == col || this._props.axes[1] == col : this._props.axes.length > 0 ? this._props.axes[0] == col : false;
+                                                var colSelected = this._props.axes.length > 1 ? this._props.axes[0] == col || this._props.axes[1] == col : this._props.axes.length > 0 ? this._props.axes[0] == col : false;
+                                                if (this._props.titleCol==col) colSelected = true;
                                                 return (
                                                     <td key={this.columns.indexOf(col)} style={{ border: colSelected ? '3px solid black' : '1px solid black', fontWeight: colSelected ? 'bolder' : 'normal' }}>
                                                         <div className="tableBox-cell">{this._props.records[rowId][col]}</div>
-- 
cgit v1.2.3-70-g09d2


From d252886fe97524603ee49e577a535a39f1e664ae Mon Sep 17 00:00:00 2001
From: srichman333 <sarah_n_richman@brown.edu>
Date: Mon, 29 Jan 2024 13:15:27 -0500
Subject: show title of selected histogram bars

---
 src/client/views/nodes/DataVizBox/components/Histogram.tsx | 12 ++++++++++++
 src/client/views/nodes/DataVizBox/components/PieChart.tsx  | 10 ++++------
 2 files changed, 16 insertions(+), 6 deletions(-)

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

diff --git a/src/client/views/nodes/DataVizBox/components/Histogram.tsx b/src/client/views/nodes/DataVizBox/components/Histogram.tsx
index 44e8b97c6..c0e738cfa 100644
--- a/src/client/views/nodes/DataVizBox/components/Histogram.tsx
+++ b/src/client/views/nodes/DataVizBox/components/Histogram.tsx
@@ -452,6 +452,18 @@ export class Histogram extends ObservableReactComponent<HistogramProps> {
                     : ''
             );
             selected = selected.substring(0, selected.length - 2) + ' }';
+            if (this._props.titleCol!="" && (!this._currSelected["frequency"] || this._currSelected["frequency"]<10)){
+                selected+= "\n" + this._props.titleCol + ": "
+                this._tableData.forEach(each => {
+                    if (this._currSelected[this._props.axes[0]]==each[this._props.axes[0]]) {
+                        if (this._props.axes[1]){
+                            if (this._currSelected[this._props.axes[1]]==each[this._props.axes[1]]) selected+= each[this._props.titleCol] + ", ";
+                        }
+                        else selected+= each[this._props.titleCol] + ", ";
+                    }
+                })
+                selected = selected.slice(0,-1).slice(0,-1);
+            }
         }
         var selectedBarColor;
         var barColors = StrListCast(this._props.layoutDoc.histogramBarColors).map(each => each.split('::'));
diff --git a/src/client/views/nodes/DataVizBox/components/PieChart.tsx b/src/client/views/nodes/DataVizBox/components/PieChart.tsx
index f98d51123..54a83879c 100644
--- a/src/client/views/nodes/DataVizBox/components/PieChart.tsx
+++ b/src/client/views/nodes/DataVizBox/components/PieChart.tsx
@@ -348,14 +348,12 @@ export class PieChart extends ObservableReactComponent<PieChartProps> {
             });
             selected = selected.substring(0, selected.length - 2);
             selected += ' }';
-            if (this._props.titleCol!="" && (!this._currSelected["frequency"] || this._currSelected["frequency"]<10) && this._pieChartData){
-                var percentField = Object.keys(this._pieChartData[0])[0];
-                var descriptionField = Object.keys(this._pieChartData[0])[1]!;
+            if (this._props.titleCol!="" && (!this._currSelected["frequency"] || this._currSelected["frequency"]<10)){
                 selected+= "\n" + this._props.titleCol + ": "
                 this._tableData.forEach(each => {
-                    if (this._currSelected[percentField]==each[percentField]) {
-                        if (descriptionField){
-                            if (this._currSelected[descriptionField]==each[descriptionField]) selected+= each[this._props.titleCol] + ", ";
+                    if (this._currSelected[this._props.axes[0]]==each[this._props.axes[0]]) {
+                        if (this._props.axes[1]){
+                            if (this._currSelected[this._props.axes[1]]==each[this._props.axes[1]]) selected+= each[this._props.titleCol] + ", ";
                         }
                         else selected+= each[this._props.titleCol] + ", ";
                     }
-- 
cgit v1.2.3-70-g09d2

