Skip to content

Commit 850d39f

Browse files
author
benrubson
committed
Revert grafana#6287 for jquery.flot.stack.js
1 parent 61bb9cb commit 850d39f

File tree

1 file changed

+57
-46
lines changed

1 file changed

+57
-46
lines changed

public/vendor/flot/jquery.flot.stack.js

Lines changed: 57 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -78,46 +78,41 @@ charts or filled areas).
7878
i = 0, j = 0, l, m;
7979

8080
while (true) {
81-
// browse all points from the current series and from the previous series
82-
if (i >= points.length && j >= otherpoints.length)
81+
if (i >= points.length)
8382
break;
8483

85-
// newpoints will replace current series with
86-
// as many points as different timestamps we have in the 2 (current & previous) series
8784
l = newpoints.length;
88-
px = points[i + keyOffset];
89-
py = points[i + accumulateOffset];
90-
qx = otherpoints[j + keyOffset];
91-
qy = otherpoints[j + accumulateOffset];
92-
bottom = 0;
93-
94-
if (i < points.length && px == null) {
95-
// let's ignore null points from current series, nothing to do with them
85+
86+
if (points[i] == null) {
87+
// copy gaps
88+
for (m = 0; m < ps; ++m)
89+
newpoints.push(points[i + m]);
9690
i += ps;
9791
}
98-
else if (j < otherpoints.length && qx == null) {
99-
// let's ignore null points from previous series, nothing to do with them
100-
j += otherps;
92+
else if (j >= otherpoints.length) {
93+
// for lines, we can't use the rest of the points
94+
if (!withlines) {
95+
for (m = 0; m < ps; ++m)
96+
newpoints.push(points[i + m]);
97+
}
98+
i += ps;
10199
}
102-
else if (i >= points.length) {
103-
// no more points in the current series, simply take the remaining points
104-
// from the previous series so that next series will correctly stack
100+
else if (otherpoints[j] == null) {
101+
// oops, got a gap
105102
for (m = 0; m < ps; ++m)
106-
newpoints.push(otherpoints[j + m]);
107-
bottom = qy;
103+
newpoints.push(null);
104+
fromgap = true;
108105
j += otherps;
109106
}
110-
else if (j >= otherpoints.length) {
111-
// no more points in the previous series, of course let's take
112-
// the remaining points from the current series
113-
for (m = 0; m < ps; ++m)
114-
newpoints.push(points[i + m]);
115-
i += ps;
116-
}
117107
else {
118-
// next available points from current and previous series have the same timestamp
108+
// cases where we actually got two points
109+
px = points[i + keyOffset];
110+
py = points[i + accumulateOffset];
111+
qx = otherpoints[j + keyOffset];
112+
qy = otherpoints[j + accumulateOffset];
113+
bottom = 0;
114+
119115
if (px == qx) {
120-
// so take the point from the current series and skip the previous' one
121116
for (m = 0; m < ps; ++m)
122117
newpoints.push(points[i + m]);
123118

@@ -127,39 +122,55 @@ charts or filled areas).
127122
i += ps;
128123
j += otherps;
129124
}
130-
// next available point with the smallest timestamp is from the previous series
131125
else if (px > qx) {
132-
// so take the point from the previous series so that next series will correctly stack
133-
for (m = 0; m < ps; ++m)
134-
newpoints.push(otherpoints[j + m]);
135-
136-
// we might be able to interpolate
137-
if (i > 0 && points[i - ps] != null)
138-
newpoints[l + accumulateOffset] += py + (points[i - ps + accumulateOffset] - py) * (qx - px) / (points[i - ps + keyOffset] - px);
139-
140-
bottom = qy;
126+
// we got past point below, might need to
127+
// insert interpolated extra point
128+
if (withlines && i > 0 && points[i - ps] != null) {
129+
intery = py + (points[i - ps + accumulateOffset] - py) * (qx - px) / (points[i - ps + keyOffset] - px);
130+
newpoints.push(qx);
131+
newpoints.push(intery + qy);
132+
for (m = 2; m < ps; ++m)
133+
newpoints.push(points[i + m]);
134+
bottom = qy;
135+
}
141136

142137
j += otherps;
143138
}
144-
// (px < qx) next available point with the smallest timestamp is from the current series
145-
else {
146-
// so of course let's take the point from the current series
139+
else { // px < qx
140+
if (fromgap && withlines) {
141+
// if we come from a gap, we just skip this point
142+
i += ps;
143+
continue;
144+
}
145+
147146
for (m = 0; m < ps; ++m)
148147
newpoints.push(points[i + m]);
149148

150149
// we might be able to interpolate a point below,
151150
// this can give us a better y
152-
if (j > 0 && otherpoints[j - otherps] != null)
151+
if (withlines && j > 0 && otherpoints[j - otherps] != null)
153152
bottom = qy + (otherpoints[j - otherps + accumulateOffset] - qy) * (px - qx) / (otherpoints[j - otherps + keyOffset] - qx);
154153

155154
newpoints[l + accumulateOffset] += bottom;
156155

157156
i += ps;
158157
}
159-
}
160158

161-
if (l != newpoints.length && withbottom)
162-
newpoints[l + 2] = bottom;
159+
fromgap = false;
160+
161+
if (l != newpoints.length && withbottom)
162+
newpoints[l + 2] += bottom;
163+
}
164+
165+
// maintain the line steps invariant
166+
if (withsteps && l != newpoints.length && l > 0
167+
&& newpoints[l] != null
168+
&& newpoints[l] != newpoints[l - ps]
169+
&& newpoints[l + 1] != newpoints[l - ps + 1]) {
170+
for (m = 0; m < ps; ++m)
171+
newpoints[l + ps + m] = newpoints[l + m];
172+
newpoints[l + 1] = newpoints[l - ps + 1];
173+
}
163174
}
164175

165176
datapoints.points = newpoints;

0 commit comments

Comments
 (0)