From a480995139058c45773c1ad7dd6263728f5de1d7 Mon Sep 17 00:00:00 2001 From: Roman Galochkin Date: Wed, 4 Mar 2020 14:35:25 +0300 Subject: [PATCH 1/2] Fixes edges --- .../charts/DistributionPlot/distPlotD3.js | 36 ++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/src/components/charts/DistributionPlot/distPlotD3.js b/src/components/charts/DistributionPlot/distPlotD3.js index 87278d29..81ccc545 100644 --- a/src/components/charts/DistributionPlot/distPlotD3.js +++ b/src/components/charts/DistributionPlot/distPlotD3.js @@ -3,6 +3,14 @@ const d3 = require('d3'); const moment = require('moment'); require('./styles.css'); +/** + * @param arr + * @returns {*} + */ +function exists(arr) { + return arr.find(num => _.isFinite(num)); +} + /** * @todo: To rename as "DistPlotD3". */ @@ -178,15 +186,27 @@ export class CdfChartD3 { */ getCommonThings() { // Boundaries. - const xMin = this.attrs.minX - || d3.min(this.attrs.data.continuous.xs) - || d3.min(this.attrs.data.discrete.xs); - const xMax = this.attrs.maxX - || d3.max(this.attrs.data.continuous.xs) - || d3.max(this.attrs.data.discrete.xs); + const xMin = exists([ + this.attrs.minX, + d3.min(this.attrs.data.continuous.xs), + d3.min(this.attrs.data.discrete.xs), + ]); + const xMax = exists([ + this.attrs.maxX, + d3.max(this.attrs.data.continuous.xs), + d3.max(this.attrs.data.discrete.xs), + ]); - const yMin = d3.min(this.attrs.data.continuous.ys); - const yMax = d3.max(this.attrs.data.continuous.ys); + const yMin = exists([ + this.attrs.minY, + d3.min(this.attrs.data.continuous.ys), + d3.min(this.attrs.data.discrete.ys), + ]); + const yMax = exists([ + this.attrs.maxY, + d3.max(this.attrs.data.continuous.ys), + d3.max(this.attrs.data.discrete.ys), + ]); // Errors. if (!_.isFinite(xMin)) throw new Error('xMin is undefined'); From e77b1c2e60ed1cf47dd30a6152785d6512ae5387 Mon Sep 17 00:00:00 2001 From: Roman Galochkin Date: Wed, 4 Mar 2020 14:36:44 +0300 Subject: [PATCH 2/2] Renames class and react function --- src/components/charts/DistributionPlot/distPlotD3.js | 5 +---- src/components/charts/DistributionPlot/distPlotReact.js | 9 ++++----- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/components/charts/DistributionPlot/distPlotD3.js b/src/components/charts/DistributionPlot/distPlotD3.js index 81ccc545..eddd0748 100644 --- a/src/components/charts/DistributionPlot/distPlotD3.js +++ b/src/components/charts/DistributionPlot/distPlotD3.js @@ -11,10 +11,7 @@ function exists(arr) { return arr.find(num => _.isFinite(num)); } -/** - * @todo: To rename as "DistPlotD3". - */ -export class CdfChartD3 { +export class DistPlotD3 { constructor() { this.attrs = { diff --git a/src/components/charts/DistributionPlot/distPlotReact.js b/src/components/charts/DistributionPlot/distPlotReact.js index 5385adcd..7cf0e34b 100644 --- a/src/components/charts/DistributionPlot/distPlotReact.js +++ b/src/components/charts/DistributionPlot/distPlotReact.js @@ -1,6 +1,6 @@ import React, { useEffect } from 'react'; import { useSize } from 'react-use'; -import { CdfChartD3 } from './distPlotD3'; +import { DistPlotD3 } from './distPlotD3'; /** * @param min @@ -14,12 +14,11 @@ function getRandomInt(min, max) { } /** - * @todo: To rename as "DistPlotReact". * @param props * @returns {*} * @constructor */ -function CdfChartReact(props) { +function DistPlotReact(props) { const containerRef = React.createRef(); const key = "cdf-chart-react-" + getRandomInt(0, 1000); const scale = props.scale || 'linear'; @@ -35,7 +34,7 @@ function CdfChartReact(props) { useEffect(() => { try { - new CdfChartD3() + new DistPlotD3() .set('svgWidth', width) .set('svgHeight', props.height) .set('maxX', props.maxX) @@ -79,4 +78,4 @@ function CdfChartReact(props) { ]); } -export default CdfChartReact; +export default DistPlotReact;