aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsrichman333 <sarah_n_richman@brown.edu>2023-08-08 14:25:18 -0400
committersrichman333 <sarah_n_richman@brown.edu>2023-08-08 14:25:18 -0400
commit5614478b54b754665faff41c9a09b9bd0535e2f5 (patch)
treeaabffcb38b6e178cd60ca10e16943d9a094d0bfc /src
parentb44722cc4e35b994ad50d47cf2586785b3e0ab2d (diff)
histogram bug fixes
Diffstat (limited to 'src')
-rw-r--r--src/client/views/nodes/DataVizBox/components/Histogram.tsx18
-rw-r--r--src/client/views/nodes/DataVizBox/components/PieChart.tsx2
2 files changed, 15 insertions, 5 deletions
diff --git a/src/client/views/nodes/DataVizBox/components/Histogram.tsx b/src/client/views/nodes/DataVizBox/components/Histogram.tsx
index 6591581f7..26c40045c 100644
--- a/src/client/views/nodes/DataVizBox/components/Histogram.tsx
+++ b/src/client/views/nodes/DataVizBox/components/Histogram.tsx
@@ -16,6 +16,7 @@ import { ColorPicker, EditableText, IconButton, Size, Type } from "browndash-com
import { FaFillDrip } from "react-icons/fa";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { listSpec } from "../../../../../fields/Schema";
+import { scaleCreatorNumerical, yAxisCreator } from "../utils/D3Utils";
export interface HistogramProps {
rootDoc: Doc;
@@ -63,7 +64,7 @@ export class Histogram extends React.Component<HistogramProps> {
var ax0 = this.props.axes[0];
var ax1 = this.props.axes[1];
if (/\d/.test(this.props.pairs[0][ax0])) { this.numericalXData = true;}
- if (/\d/.test(this.props.pairs[0][ax1]) && this.props.pairs.length < this.maxBins) { this.numericalYData = true;}
+ if (/\d/.test(this.props.pairs[0][ax1]) ) { this.numericalYData = true;}
return this.props.pairs
?.filter(pair => (!this.incomingLinks.length ? true : this.incomingLinks[0]!.selected && StrListCast(this.incomingLinks[0].selected).includes(guids[this.props.pairs.indexOf(pair)])))
.map(pair => ({ [ax0]: (pair[this.props.axes[0]]), [ax1]: (pair[this.props.axes[1]]) }))
@@ -282,7 +283,7 @@ export class Histogram extends React.Component<HistogramProps> {
}
for (let i=0; i<data.length; i++){
let barData = histStringDataSet.filter(each => each[xAxisTitle]==data[i])
- barData[0][yAxisTitle] = Number(barData[0][yAxisTitle]) + 1;
+ histStringDataSet.filter(each => each[xAxisTitle]==data[i])[0][yAxisTitle] = Number(barData[0][yAxisTitle]) + 1;
}
}
histDataSet = histStringDataSet
@@ -337,10 +338,13 @@ export class Histogram extends React.Component<HistogramProps> {
translateXAxis = eachRectWidth / 2;
}
else {
+ eachRectWidth = width/(bins.length+1)
+ x.range([0, width-eachRectWidth])
xAxis = d3.axisBottom(x)
.ticks(numBins-1)
}
- const maxFrequency = this.numericalYData? d3.max(histDataSet, function(d: any) { return d[yAxisTitle]!.replace(/\$/g, '').replace(/\%/g, '').replace(/\</g, '')})
+ const maxFrequency = this.numericalYData? d3.max(histDataSet, function(d: any) {
+ return Number(d[yAxisTitle]!.replace(/\$/g, '').replace(/\%/g, '').replace(/\</g, ''))})
: d3.max(bins, function(d) { return d.length; })
var y = d3.scaleLinear()
@@ -348,8 +352,14 @@ export class Histogram extends React.Component<HistogramProps> {
y.domain([0, +maxFrequency!]);
var yAxis = d3.axisLeft(y)
.ticks(maxFrequency!)
- svg.append("g")
+ if (this.numericalYData){
+ const yScale = scaleCreatorNumerical(0, Number(maxFrequency), height, 0);
+ yAxisCreator(svg.append('g'), width, yScale);
+ }
+ else{
+ svg.append("g")
.call(yAxis);
+ }
svg.append("g")
.attr("transform", "translate(" + translateXAxis + ", " + height + ")")
.call(xAxis)
diff --git a/src/client/views/nodes/DataVizBox/components/PieChart.tsx b/src/client/views/nodes/DataVizBox/components/PieChart.tsx
index 913bdd9a4..0fd4f6b54 100644
--- a/src/client/views/nodes/DataVizBox/components/PieChart.tsx
+++ b/src/client/views/nodes/DataVizBox/components/PieChart.tsx
@@ -245,7 +245,7 @@ export class PieChart extends React.Component<PieChartProps> {
var showSelected = this.byCategory? pieDataSet[index] : this._piechartData[index];
if (changeSelectedVariables){
- sameAsCurrent = (this.byCategory && this._currSelected)?
+ sameAsCurrent = (this._currSelected)?
(showSelected[Object.keys(showSelected)[0]]==this._currSelected![Object.keys(showSelected)[0]]
&& showSelected[Object.keys(showSelected)[1]]==this._currSelected![Object.keys(showSelected)[1]])
: