Commit 569685fb authored by olau@iola.dk's avatar olau@iola.dk

Added support for stacking horizontal bar charts to the stacking plugin


git-svn-id: https://flot.googlecode.com/svn/trunk@230 1e0a6537-2640-0410-bfb7-f154510ff394
parent c3a34cd6
......@@ -12,6 +12,7 @@ Changes:
example percentiles.html for a use case).
- More predictable handling of gaps for the stacking plugin, now all
undefined ranges are skipped.
- Stacking plugin can stack horizontal bar charts.
Bug fixes:
......
......@@ -102,7 +102,7 @@
fill: true,
fillColor: null,
align: "left", // or "center"
horizontal: false // when horizontal, left is now top
horizontal: false
},
shadowSize: 3
},
......@@ -382,8 +382,13 @@
format.push({ x: true, number: true, required: true });
format.push({ y: true, number: true, required: true });
if (s.bars.show || (s.lines.show && s.lines.fill))
if (s.bars.show || (s.lines.show && s.lines.fill)) {
format.push({ y: true, number: true, required: false, defaultValue: 0 });
if (s.bars.horizontal) {
delete format[format.length - 1].y;
format[format.length - 1].x = true;
}
}
s.datapoints.format = format;
}
......@@ -1584,6 +1589,9 @@
drawLeft, drawRight, drawTop, drawBottom,
tmp;
// in horizontal mode, we start the bar from the left
// instead of from the bottom so it appears to be
// horizontal rather than vertical
if (horizontal) {
drawBottom = drawRight = drawTop = true;
drawLeft = false;
......
......@@ -64,9 +64,12 @@ adjusted (e.g for bar charts or filled areas).
newpoints = [],
px, py, intery, qx, qy, bottom,
withlines = s.lines.show,
withbottom = ps > 2 && datapoints.format[2].y,
horizontal = s.bars.horizontal,
withbottom = ps > 2 && (horizontal ? datapoints.format[2].x : datapoints.format[2].y),
withsteps = withlines && s.lines.steps,
fromgap = true,
keyOffset = horizontal ? 1 : 0,
accumulateOffset = horizontal ? 0 : 1,
i = 0, j = 0, l;
while (true) {
......@@ -98,17 +101,17 @@ adjusted (e.g for bar charts or filled areas).
}
else {
// cases where we actually got two points
px = points[i];
py = points[i + 1];
qx = otherpoints[j];
qy = otherpoints[j + 1];
px = points[i + keyOffset];
py = points[i + accumulateOffset];
qx = otherpoints[j + keyOffset];
qy = otherpoints[j + accumulateOffset];
bottom = 0;
if (px == qx) {
for (m = 0; m < ps; ++m)
newpoints.push(points[i + m]);
newpoints[l + 1] += qy;
newpoints[l + accumulateOffset] += qy;
bottom = qy;
i += ps;
......@@ -118,9 +121,9 @@ adjusted (e.g for bar charts or filled areas).
// we got past point below, might need to
// insert interpolated extra point
if (withlines && i > 0 && points[i - ps] != null) {
intery = py + (points[i - ps + 1] - py) * (qx - px) / (points[i - ps] - px);
intery = py + (points[i - ps + accumulateOffset] - py) * (qx - px) / (points[i - ps + keyOffset] - px);
newpoints.push(qx);
newpoints.push(intery + qy)
newpoints.push(intery + qy);
for (m = 2; m < ps; ++m)
newpoints.push(points[i + m]);
bottom = qy;
......@@ -141,9 +144,9 @@ adjusted (e.g for bar charts or filled areas).
// we might be able to interpolate a point below,
// this can give us a better y
if (withlines && j > 0 && otherpoints[j - otherps] != null)
bottom = qy + (otherpoints[j - otherps + 1] - qy) * (px - qx) / (otherpoints[j - otherps] - qx);
bottom = qy + (otherpoints[j - otherps + accumulateOffset] - qy) * (px - qx) / (otherpoints[j - otherps + keyOffset] - qx);
newpoints[l + 1] += bottom;
newpoints[l + accumulateOffset] += bottom;
i += ps;
}
......@@ -175,6 +178,6 @@ adjusted (e.g for bar charts or filled areas).
init: init,
options: options,
name: 'stack',
version: '1.1'
version: '1.2'
});
})(jQuery);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment