Skip to content

Commit

Permalink
Add baseline for the pbc charts
Browse files Browse the repository at this point in the history
  • Loading branch information
ClaudiaGivan committed Sep 27, 2024
1 parent 058a909 commit f3051c0
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 11 deletions.
2 changes: 1 addition & 1 deletion examples/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ async function renderGraphs(data, serviceId) {
//The Load and reset config input buttons css selectors
const loadConfigInputSelector = "#load-config-input";
const resetConfigInputSelector = "#reset-config-input";
//The controls div css selector that contains the reporting range days input and the x axis labeling units dropdown
//The controls div css selector that contains the reporting range days input and the x axes labeling units dropdown
const controlsElementSelector = "#controls-div";

const {
Expand Down
4 changes: 4 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions src/graphs/control-chart/ControlRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ class ControlRenderer extends ScatterplotRenderer {
timeScale = 'linear';
connectDots = false;

constructor(data, avgMovingRange, chartName) {
constructor(data, avgMovingRangeFunc, chartName) {
super(data);
this.chartName = chartName;
this.chartType = 'CONTROL';
this.avgMovingRange = avgMovingRange;
this.avgMovingRangeFunc = avgMovingRangeFunc;
this.dotClass = 'control-dot';
this.yAxisLabel = 'Days';
}
Expand All @@ -27,6 +27,7 @@ class ControlRenderer extends ScatterplotRenderer {
drawGraphLimits(yScale) {
this.drawHorizontalLine(yScale, this.topLimit, 'purple', 'top-pb', `UPL=${this.topLimit}`);
this.drawHorizontalLine(yScale, this.avgLeadTime, 'orange', 'mid-pb', `Avg=${this.avgLeadTime}`);

if (this.bottomLimit > 0) {
this.drawHorizontalLine(yScale, this.bottomLimit, 'purple', 'bottom-pb', `LPL=${this.bottomLimit}`);
} else {
Expand All @@ -36,9 +37,10 @@ class ControlRenderer extends ScatterplotRenderer {

computeGraphLimits() {
this.avgLeadTime = this.getAvgLeadTime();
this.topLimit = Math.ceil(this.avgLeadTime + this.avgMovingRange * 2.66);
const avgMovingRange = this.avgMovingRangeFunc(this.baselineStartDate, this.baselineEndDate);
this.topLimit = Math.ceil(this.avgLeadTime + avgMovingRange * 2.66);

this.bottomLimit = Math.ceil(this.avgLeadTime - this.avgMovingRange * 2.66);
this.bottomLimit = Math.ceil(this.avgLeadTime - avgMovingRange * 2.66);
const maxY = this.y.domain()[1] > this.topLimit ? this.y.domain()[1] : this.topLimit + 5;
let minY = this.y.domain()[0];
if (this.bottomLimit > 5) {
Expand Down Expand Up @@ -106,6 +108,7 @@ 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);
}
Expand Down
8 changes: 6 additions & 2 deletions src/graphs/moving-range/MovingRangeGraph.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class MovingRangeGraph {
dataSet = [];

constructor(data) {
this.data = data;
}
Expand All @@ -21,11 +22,14 @@ class MovingRangeGraph {
return this.dataSet;
}

getAvgMovingRange() {
getAvgMovingRange(startDate, endDate) {
if (this.dataSet.length <= 0) {
throw new Error('Data set is empty');
}
return Math.ceil(this.dataSet.reduce((acc, curr) => acc + curr.leadTime, 0) / this.dataSet.length);
return Math.ceil(
this.dataSet.filter((d) => d.deliveredDate >= startDate && d.deliveredDate <= endDate).reduce((acc, curr) => acc + curr.leadTime, 0) /
this.dataSet.length
);
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/graphs/moving-range/MovingRangeRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ class MovingRangeRenderer extends ScatterplotRenderer {
color = '#0ea5e9';
timeScale = 'linear';

constructor(data, avgMovingRange, workTicketsURL, chartName) {
constructor(data, avgMovingRangeFunc, workTicketsURL, chartName) {
super(data);
this.avgMovingRange = avgMovingRange;
this.avgMovingRangeFunc = avgMovingRangeFunc;
this.workTicketsURL = workTicketsURL;
this.chartName = chartName;
this.chartType = 'MOVING_RANGE';
Expand All @@ -25,12 +25,13 @@ class MovingRangeRenderer extends ScatterplotRenderer {
}

drawGraphLimits(yScale) {
const avgMovingRange = this.avgMovingRangeFunc(this.baselineStartDate, this.baselineEndDate);
this.drawHorizontalLine(yScale, this.topLimit, 'purple', 'top-mr', `UPL=${this.topLimit}`);
this.drawHorizontalLine(yScale, this.avgMovingRange, 'orange', 'mid-mr', `Avg=${this.avgMovingRange}`);
this.drawHorizontalLine(yScale, avgMovingRange, 'orange', 'mid-mr', `Avg=${avgMovingRange}`);
}

computeGraphLimits() {
this.topLimit = 3.27 * this.avgMovingRange;
this.topLimit = 3.27 * this.avgMovingRangeFunc(this.baselineStartDate, this.baselineEndDate);
const maxY = this.y.domain()[1] > this.topLimit ? this.y.domain()[1] : this.topLimit + 5;
this.y.domain([this.y.domain()[0], maxY]);
}
Expand Down Expand Up @@ -93,6 +94,7 @@ class MovingRangeRenderer extends ScatterplotRenderer {
.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);
}
}
Expand Down
21 changes: 21 additions & 0 deletions src/graphs/scatterplot/ScatterplotRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class ScatterplotRenderer extends UIControlsRenderer {
yAxisLabel = '# of delivery days';
timeScale = 'logarithmic';
workTicketsURL = '#';
baselineStartDate;
baselineEndDate;

/**
* Creates a ScatterplotRenderer instance
Expand All @@ -39,6 +41,8 @@ class ScatterplotRenderer extends UIControlsRenderer {
*/
constructor(data) {
super(data);
this.baselineStartDate = this.data[0].deliveredDate;
this.baselineEndDate = this.data[this.data.length - 1].deliveredDate;
}

/**
Expand Down Expand Up @@ -222,6 +226,23 @@ class ScatterplotRenderer extends UIControlsRenderer {
}
}

setBaselineListener(baselineStartDateSelector, baselineEndDateSelector) {
this.baselineStartDateElement = document.querySelector(baselineStartDateSelector);
if (this.baselineStartDateElement) {
this.baselineStartDateElement.addEventListener('change', (event) => {
this.baselineStartDate = new Date(event.target.value);
this.updateGraph(this.selectedTimeRange);
});
}
this.baselineEndDateElement = document.querySelector(baselineEndDateSelector);
if (this.baselineEndDateElement) {
this.baselineEndDateElement.addEventListener('change', (event) => {
this.baselineEndDate = new Date(event.target.value);
this.updateGraph(this.selectedTimeRange);
});
}
}

//region Axes rendering

/**
Expand Down

0 comments on commit f3051c0

Please sign in to comment.