From ed63ae81b1ba6954c1a1e75da8df8665a7a34fd1 Mon Sep 17 00:00:00 2001
From: srichman333 <sarah_n_richman@brown.edu>
Date: Thu, 27 Jul 2023 11:28:43 -0400
Subject: more info on selected histogram bars + better labels for selected pie
 chart slices

---
 src/client/views/nodes/DataVizBox/components/PieChart.tsx | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

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

diff --git a/src/client/views/nodes/DataVizBox/components/PieChart.tsx b/src/client/views/nodes/DataVizBox/components/PieChart.tsx
index fc24e5821..cead40d92 100644
--- a/src/client/views/nodes/DataVizBox/components/PieChart.tsx
+++ b/src/client/views/nodes/DataVizBox/components/PieChart.tsx
@@ -239,6 +239,8 @@ export class PieChart extends React.Component<PieChartProps> {
         d3.select(this._piechartRef.current).select('svg').remove();
         d3.select(this._piechartRef.current).select('.tooltip').remove();
         
+        var percentField = Object.keys(dataSet[0])[0]
+        var descriptionField = Object.keys(dataSet[0])[1]!
         var radius = Math.min(width, height) / 2 - Math.max(this.props.margin.top, this.props.margin.bottom, this.props.margin.left, this.props.margin.right)
         var svg = (this._piechartSvg = d3
             .select(this._piechartRef.current)
@@ -262,15 +264,17 @@ export class PieChart extends React.Component<PieChartProps> {
         });
         if (this.byCategory){
             let uniqueCategories = [...new Set(data)]
-            var pieStringDataSet: { frequency: any, label: any }[] = [];
+            var pieStringDataSet: { frequency: number, [percentField]: string }[] = [];
             for (let i=0; i<uniqueCategories.length; i++){
-                pieStringDataSet.push({frequency: 0, label: uniqueCategories[i]})
+                pieStringDataSet.push({frequency: 0, [percentField]: uniqueCategories[i]})
             }
             for (let i=0; i<data.length; i++){
-                let sliceData = pieStringDataSet.filter(each => each.label==data[i])
+                let sliceData = pieStringDataSet.filter(each => each[percentField]==data[i])
                 sliceData[0].frequency = sliceData[0].frequency + 1;
             }
             pieDataSet = pieStringDataSet
+            percentField = Object.keys(pieDataSet[0])[0]
+            descriptionField = Object.keys(pieDataSet[0])[1]!
             data = this.data(pieStringDataSet)
         }
         var trackDuplicates : {[key: string]: any} = {};
@@ -323,8 +327,6 @@ export class PieChart extends React.Component<PieChartProps> {
             if (!sameAsCurrent!) selected.attr('class', 'slice hover');
         });
 
-        var percentField = Object.keys(pieDataSet[0])[0]
-        var descriptionField = Object.keys(pieDataSet[0])[1]!
         var arcs = g.selectAll("arc")
             .data(pie(data))
             .enter()
-- 
cgit v1.2.3-70-g09d2

