diff --git a/src/graphs/control-chart/ControlRenderer.js b/src/graphs/control-chart/ControlRenderer.js index 78ed6a3..30736fd 100644 --- a/src/graphs/control-chart/ControlRenderer.js +++ b/src/graphs/control-chart/ControlRenderer.js @@ -77,7 +77,8 @@ class ControlRenderer extends ScatterplotRenderer { } getAvgLeadTime() { - return Math.ceil(this.data.reduce((acc, curr) => acc + curr.leadTime, 0) / this.data.length); + const filteredData = this.data.filter((d) => d.deliveredDate >= this.baselineStartDate && d.deliveredDate <= this.baselineEndDate); + return Math.ceil(filteredData.reduce((acc, curr) => acc + curr.leadTime, 0) / filteredData.length); } generateLines(chartArea, data, x, y) { @@ -100,6 +101,7 @@ class ControlRenderer extends ScatterplotRenderer { } updateGraph(domain) { + this.computeGraphLimits(); this.updateChartArea(domain); if (this.connectDots) { const line = d3 @@ -108,7 +110,6 @@ class ControlRenderer extends ScatterplotRenderer { .y((d) => this.applyYScale(this.currentYScale, d.leadTime)); this.chartArea.selectAll('.dot-line').attr('d', line); } - this.computeGraphLimits(); this.drawGraphLimits(this.currentYScale); this.displayObservationMarkers(this.observations); } diff --git a/src/graphs/moving-range/MovingRangeGraph.js b/src/graphs/moving-range/MovingRangeGraph.js index fe20b0a..d6fae0c 100644 --- a/src/graphs/moving-range/MovingRangeGraph.js +++ b/src/graphs/moving-range/MovingRangeGraph.js @@ -26,10 +26,8 @@ class MovingRangeGraph { if (this.dataSet.length <= 0) { throw new Error('Data set is empty'); } - return Math.ceil( - this.dataSet.filter((d) => d.deliveredDate >= startDate && d.deliveredDate <= endDate).reduce((acc, curr) => acc + curr.leadTime, 0) / - this.dataSet.length - ); + const filteredData = this.dataSet.filter((d) => d.deliveredDate >= startDate && d.deliveredDate <= endDate); + return Math.ceil(filteredData.reduce((acc, curr) => acc + curr.leadTime, 0) / filteredData.length); } } diff --git a/src/graphs/moving-range/MovingRangeRenderer.js b/src/graphs/moving-range/MovingRangeRenderer.js index 096da66..7b733b8 100644 --- a/src/graphs/moving-range/MovingRangeRenderer.js +++ b/src/graphs/moving-range/MovingRangeRenderer.js @@ -88,13 +88,13 @@ class MovingRangeRenderer extends ScatterplotRenderer { } updateGraph(domain) { + this.computeGraphLimits(); this.updateChartArea(domain); const line = d3 .line() .x((d) => this.currentXScale(d.deliveredDate)) .y((d) => this.applyYScale(this.currentYScale, d.leadTime)); this.chartArea.selectAll('.dot-line').attr('d', line); - this.computeGraphLimits(); this.drawGraphLimits(this.currentYScale); } }