From 481a847b1074c9544e947e409b96778ac4d4f852 Mon Sep 17 00:00:00 2001
From: srichman333 <sarah_n_richman@brown.edu>
Date: Wed, 9 Aug 2023 15:24:03 -0400
Subject: numerical y axis data fix

---
 src/client/views/nodes/DataVizBox/components/Histogram.tsx | 11 ++++-------
 1 file changed, 4 insertions(+), 7 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 e04d37094..ed663006f 100644
--- a/src/client/views/nodes/DataVizBox/components/Histogram.tsx
+++ b/src/client/views/nodes/DataVizBox/components/Histogram.tsx
@@ -1,13 +1,10 @@
 import { observer } from "mobx-react";
-import { Doc, DocListCast, StrListCast } from "../../../../../fields/Doc";
+import { Doc, StrListCast } from "../../../../../fields/Doc";
 import * as React from 'react';
 import * as d3 from 'd3';
 import { IReactionDisposer, action, computed, observable, reaction } from "mobx";
 import { LinkManager } from "../../../../util/LinkManager";
 import { Cast, DocCast, StrCast} from "../../../../../fields/Types";
-import { DocumentManager } from "../../../../util/DocumentManager";
-import { Id } from "../../../../../fields/FieldSymbols";
-import { DataVizBox } from "../DataVizBox";
 import { PinProps, PresBox } from "../../trails";
 import { Docs } from "../../../../documents/Documents";
 import { List } from "../../../../../fields/List";
@@ -299,7 +296,7 @@ export class Histogram extends React.Component<HistogramProps> {
         }
         // y-axis
         const maxFrequency = this.numericalYData? d3.max(histDataSet, function(d: any) { 
-            return Number(d[yAxisTitle]!.replace(/\$/g, '').replace(/\%/g, '').replace(/\</g, ''))})
+            return d[yAxisTitle]? Number(d[yAxisTitle]!.replace(/\$/g, '').replace(/\%/g, '').replace(/\</g, '')) : 0})
                     : d3.max(bins, function(d) { return d.length; })
         var y = d3.scaleLinear()
             .range([height, 0]);
@@ -359,14 +356,14 @@ export class Histogram extends React.Component<HistogramProps> {
               .attr("transform", this.numericalYData?
                     function (d) {
                         var eachData = histDataSet.filter((data: { [x: string]: number; }) => {return data[xAxisTitle]==d[0]}) 
-                        var length = eachData[0][yAxisTitle].replace(/\$/g, '').replace(/\%/g, '').replace(/\</g, '');
+                        var length = eachData.length? eachData[0][yAxisTitle].replace(/\$/g, '').replace(/\%/g, '').replace(/\</g, '') : 0;
                         return "translate(" + x(d.x0!) + "," + y(length) + ")";
                     }
                     : function(d) { return "translate(" + x(d.x0!) + "," + y(d.length) + ")"; })
               .attr("height", this.numericalYData? 
                     function(d) {
                         var eachData = histDataSet.filter((data: { [x: string]: number; }) => {return data[xAxisTitle]==d[0]}) 
-                        var length = eachData[0][yAxisTitle].replace(/\$/g, '').replace(/\%/g, '').replace(/\</g, '');
+                        var length = eachData.length? eachData[0][yAxisTitle].replace(/\$/g, '').replace(/\%/g, '').replace(/\</g, '') : 0;
                         return height-y(length)}
                     : function(d) { 
                         return height - y(d.length)})
-- 
cgit v1.2.3-70-g09d2

