diff options
author | srichman333 <sarah_n_richman@brown.edu> | 2023-07-12 12:09:53 -0400 |
---|---|---|
committer | srichman333 <sarah_n_richman@brown.edu> | 2023-07-12 12:09:53 -0400 |
commit | cbe80a7b0fa7a887596859f74f0461a7c7f376d3 (patch) | |
tree | a3460cfee1aac4c42fba9103d778ca0e8b966071 /src/client/views/nodes/DataVizBox/components/Histogram.tsx | |
parent | 0694f00a07801a579ae1a7b0f84e0aec852a2a22 (diff) |
histogram decimals + prices
Diffstat (limited to 'src/client/views/nodes/DataVizBox/components/Histogram.tsx')
-rw-r--r-- | src/client/views/nodes/DataVizBox/components/Histogram.tsx | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/client/views/nodes/DataVizBox/components/Histogram.tsx b/src/client/views/nodes/DataVizBox/components/Histogram.tsx index 623453ea3..6047e6424 100644 --- a/src/client/views/nodes/DataVizBox/components/Histogram.tsx +++ b/src/client/views/nodes/DataVizBox/components/Histogram.tsx @@ -14,7 +14,6 @@ import { PinProps, PresBox } from "../../trails"; import { Docs } from "../../../../documents/Documents"; import { List } from "../../../../../fields/List"; import './Chart.scss'; -import e from "connect-flash"; export interface HistogramProps { rootDoc: Doc; @@ -46,7 +45,7 @@ export class Histogram extends React.Component<HistogramProps> { if (this.props.axes.length < 1) return []; if (this.props.axes.length < 2) { var ax0 = this.props.axes[0]; - if (+this.props.pairs[0][this.props.axes[0]]) { this.numericalData = true;} + if (/\d/.test(this.props.pairs[0][ax0])){ this.numericalData = true } return this.props.pairs ?.filter(pair => (!this.incomingLinks.length ? true : Array.from(Object.keys(pair)).some(key => pair[key] && key.startsWith('select')))) .map(pair => ({ [ax0]: (pair[this.props.axes[0]])})) @@ -54,7 +53,7 @@ export class Histogram extends React.Component<HistogramProps> { var ax0 = this.props.axes[0]; var ax1 = this.props.axes[1]; - if (+this.props.pairs[0][this.props.axes[0]]) { this.numericalData = true;} + if (/\d/.test(this.props.pairs[0][ax0])) { this.numericalData = true;} return this.props.pairs ?.filter(pair => (!this.incomingLinks.length ? true : Array.from(Object.keys(pair)).some(key => pair[key] && key.startsWith('select')))) .map(pair => ({ [ax0]: (pair[this.props.axes[0]]), [ax1]: (pair[this.props.axes[1]]) })) @@ -229,7 +228,7 @@ export class Histogram extends React.Component<HistogramProps> { }) var field = Object.keys(dataSet[0])[0] const data = validData.map((d: { [x: string]: any; }) => { - if (this.numericalData) {return +d[field] } + if (this.numericalData) { return +d[field].replace(/\$/g, '') } return d[field] }) return data; @@ -248,7 +247,9 @@ export class Histogram extends React.Component<HistogramProps> { var endingPoint = numBins; var translateXAxis = 0; if (this.numericalData) { - numBins = this.rangeVals.xMax! - this.rangeVals.xMin! + 1; + if (Number.isInteger(this.rangeVals.xMin!)){ + numBins = this.rangeVals.xMax! - this.rangeVals.xMin! + 1; + } startingPoint = this.rangeVals.xMin!; endingPoint = this.rangeVals.xMax!; if (numBins>15) numBins = 15; @@ -283,7 +284,7 @@ export class Histogram extends React.Component<HistogramProps> { .domain([startingPoint!, endingPoint!]) .thresholds(x.ticks(numBins)) var bins = histogram(data) - var eachRectWidth = width/(bins.length) + var eachRectWidth = width/(bins.length+1) var graphStartingPoint = bins[0].x1! - (bins[1].x1! - bins[1].x0!) bins[0].x0 = graphStartingPoint; x = x.domain([graphStartingPoint, endingPoint]) |