|
@@ -1,6 +1,6 @@
|
|
|
/* Flot plugin for stacking data sets rather than overlyaing them.
|
|
/* Flot plugin for stacking data sets rather than overlyaing them.
|
|
|
|
|
|
|
|
-Copyright (c) 2007-2013 IOLA and Ole Laursen.
|
|
|
|
|
|
|
+Copyright (c) 2007-2014 IOLA and Ole Laursen.
|
|
|
Licensed under the MIT license.
|
|
Licensed under the MIT license.
|
|
|
|
|
|
|
|
The plugin assumes the data is sorted on x (or y if stacking horizontally).
|
|
The plugin assumes the data is sorted on x (or y if stacking horizontally).
|
|
@@ -14,16 +14,16 @@ Two or more series are stacked when their "stack" attribute is set to the same
|
|
|
key (which can be any number or string or just "true"). To specify the default
|
|
key (which can be any number or string or just "true"). To specify the default
|
|
|
stack, you can set the stack option like this:
|
|
stack, you can set the stack option like this:
|
|
|
|
|
|
|
|
- series: {
|
|
|
|
|
- stack: null/false, true, or a key (number/string)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ series: {
|
|
|
|
|
+ stack: null/false, true, or a key (number/string)
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
You can also specify it for a single series, like this:
|
|
You can also specify it for a single series, like this:
|
|
|
|
|
|
|
|
- $.plot( $("#placeholder"), [{
|
|
|
|
|
- data: [ ... ],
|
|
|
|
|
- stack: true
|
|
|
|
|
- }])
|
|
|
|
|
|
|
+ $.plot( $("#placeholder"), [{
|
|
|
|
|
+ data: [ ... ],
|
|
|
|
|
+ stack: true
|
|
|
|
|
+ }])
|
|
|
|
|
|
|
|
The stacking order is determined by the order of the data series in the array
|
|
The stacking order is determined by the order of the data series in the array
|
|
|
(later series end up on top of the previous).
|
|
(later series end up on top of the previous).
|
|
@@ -39,21 +39,21 @@ charts or filled areas).
|
|
|
var options = {
|
|
var options = {
|
|
|
series: { stack: null } // or number/string
|
|
series: { stack: null } // or number/string
|
|
|
};
|
|
};
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
function init(plot) {
|
|
function init(plot) {
|
|
|
function findMatchingSeries(s, allseries) {
|
|
function findMatchingSeries(s, allseries) {
|
|
|
var res = null;
|
|
var res = null;
|
|
|
for (var i = 0; i < allseries.length; ++i) {
|
|
for (var i = 0; i < allseries.length; ++i) {
|
|
|
if (s == allseries[i])
|
|
if (s == allseries[i])
|
|
|
break;
|
|
break;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (allseries[i].stack == s.stack)
|
|
if (allseries[i].stack == s.stack)
|
|
|
res = allseries[i];
|
|
res = allseries[i];
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
return res;
|
|
return res;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
function stackData(plot, s, datapoints) {
|
|
function stackData(plot, s, datapoints) {
|
|
|
if (s.stack == null || s.stack === false)
|
|
if (s.stack == null || s.stack === false)
|
|
|
return;
|
|
return;
|
|
@@ -118,7 +118,7 @@ charts or filled areas).
|
|
|
|
|
|
|
|
newpoints[l + accumulateOffset] += qy;
|
|
newpoints[l + accumulateOffset] += qy;
|
|
|
bottom = qy;
|
|
bottom = qy;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
i += ps;
|
|
i += ps;
|
|
|
j += otherps;
|
|
j += otherps;
|
|
|
}
|
|
}
|
|
@@ -131,7 +131,7 @@ charts or filled areas).
|
|
|
newpoints.push(intery + qy);
|
|
newpoints.push(intery + qy);
|
|
|
for (m = 2; m < ps; ++m)
|
|
for (m = 2; m < ps; ++m)
|
|
|
newpoints.push(points[i + m]);
|
|
newpoints.push(points[i + m]);
|
|
|
- bottom = qy;
|
|
|
|
|
|
|
+ bottom = qy;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
j += otherps;
|
|
j += otherps;
|
|
@@ -142,22 +142,22 @@ charts or filled areas).
|
|
|
i += ps;
|
|
i += ps;
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
for (m = 0; m < ps; ++m)
|
|
for (m = 0; m < ps; ++m)
|
|
|
newpoints.push(points[i + m]);
|
|
newpoints.push(points[i + m]);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// we might be able to interpolate a point below,
|
|
// we might be able to interpolate a point below,
|
|
|
// this can give us a better y
|
|
// this can give us a better y
|
|
|
if (withlines && j > 0 && otherpoints[j - otherps] != null)
|
|
if (withlines && j > 0 && otherpoints[j - otherps] != null)
|
|
|
bottom = qy + (otherpoints[j - otherps + accumulateOffset] - qy) * (px - qx) / (otherpoints[j - otherps + keyOffset] - qx);
|
|
bottom = qy + (otherpoints[j - otherps + accumulateOffset] - qy) * (px - qx) / (otherpoints[j - otherps + keyOffset] - qx);
|
|
|
|
|
|
|
|
newpoints[l + accumulateOffset] += bottom;
|
|
newpoints[l + accumulateOffset] += bottom;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
i += ps;
|
|
i += ps;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
fromgap = false;
|
|
fromgap = false;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (l != newpoints.length && withbottom)
|
|
if (l != newpoints.length && withbottom)
|
|
|
newpoints[l + 2] += bottom;
|
|
newpoints[l + 2] += bottom;
|
|
|
}
|
|
}
|
|
@@ -175,10 +175,10 @@ charts or filled areas).
|
|
|
|
|
|
|
|
datapoints.points = newpoints;
|
|
datapoints.points = newpoints;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
plot.hooks.processDatapoints.push(stackData);
|
|
plot.hooks.processDatapoints.push(stackData);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
$.plot.plugins.push({
|
|
$.plot.plugins.push({
|
|
|
init: init,
|
|
init: init,
|
|
|
options: options,
|
|
options: options,
|