Skip to content

Commit 51e956f

Browse files
committed
autoscaleAxisLimits now scales to smoothed and shifted data
1 parent 0f44f92 commit 51e956f

1 file changed

Lines changed: 35 additions & 8 deletions

File tree

js/data_object.js

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,27 @@ const dataObject = class {
88
}
99

1010
changeXmin(xmin) {
11-
this.globalSettings.xmin = xmin
11+
if (isFinite(xmin)) {
12+
this.globalSettings.xmin = xmin
13+
}
1214
}
1315

1416
changeXmax(xmax) {
15-
this.globalSettings.xmax = xmax
17+
if (isFinite(xmax)) {
18+
this.globalSettings.xmax = xmax
19+
}
1620
}
1721

1822
changeYmin(ymin) {
19-
this.globalSettings.ymin = ymin
23+
if (isFinite(ymin)) {
24+
this.globalSettings.ymin = ymin
25+
}
2026
}
2127

2228
changeYmax(ymax) {
23-
this.globalSettings.ymax = ymax
29+
if (isFinite(ymax)) {
30+
this.globalSettings.ymax = ymax
31+
}
2432
}
2533

2634
changeSymmetricY(symmetricY) {
@@ -106,10 +114,29 @@ const dataObject = class {
106114

107115
const self = this;
108116
return new Promise(function(resolve) {
109-
const xmin = self.compositeData.reduce((a, c) => c.hideSense && c.hideAnti ? a : Math.min(a, c.xmin), Infinity),
110-
xmax = self.compositeData.reduce((a, c) => c.hideSense && c.hideAnti ? a : Math.max(a, c.xmax), -Infinity),
111-
ymin = -self.compositeData.reduce((a, c) => c.hideAnti ? a : Math.max(a, Math.max(...c.anti) * c.scale), -Infinity),
112-
ymax = self.compositeData.reduce((a, c) => c.hideSense ? a : Math.max(a, Math.max(...c.sense) * c.scale), -Infinity);
117+
let xmin = Infinity,
118+
xmax = -Infinity,
119+
ymin = Infinity,
120+
ymax = -Infinity;
121+
for (const compositeDataObj of self.compositeData) {
122+
if (compositeDataObj.hideSense && compositeDataObj.hideAnti) {
123+
continue
124+
};
125+
const smoothing = compositeDataObj.smoothing === null ?
126+
self.globalSettings.smoothing : compositeDataObj.smoothing,
127+
bpShift = compositeDataObj.bpShift === null ?
128+
self.globalSettings.bpShift : compositeDataObj.bpShift;
129+
xmin = Math.min(xmin, compositeDataObj.xmin - bpShift);
130+
xmax = Math.max(xmax, compositeDataObj.xmax + bpShift);
131+
if (!compositeDataObj.hideSense) {
132+
ymax = Math.max(ymax, Math.max(...plotObj.slidingWindow(compositeDataObj.sense, smoothing)) *
133+
compositeDataObj.scale)
134+
};
135+
if (!compositeDataObj.hideAnti) {
136+
ymin = Math.min(ymin, -Math.max(...plotObj.slidingWindow(compositeDataObj.anti, smoothing)) *
137+
compositeDataObj.scale)
138+
}
139+
};
113140

114141
self.changeXmin(xmin);
115142
self.changeXmax(xmax);

0 commit comments

Comments
 (0)