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: ...@@ -12,6 +12,7 @@ Changes:
example percentiles.html for a use case). example percentiles.html for a use case).
- More predictable handling of gaps for the stacking plugin, now all - More predictable handling of gaps for the stacking plugin, now all
undefined ranges are skipped. undefined ranges are skipped.
- Stacking plugin can stack horizontal bar charts.
Bug fixes: Bug fixes:
......
...@@ -102,7 +102,7 @@ ...@@ -102,7 +102,7 @@
fill: true, fill: true,
fillColor: null, fillColor: null,
align: "left", // or "center" align: "left", // or "center"
horizontal: false // when horizontal, left is now top horizontal: false
}, },
shadowSize: 3 shadowSize: 3
}, },
...@@ -382,8 +382,13 @@ ...@@ -382,8 +382,13 @@
format.push({ x: true, number: true, required: true }); format.push({ x: true, number: true, required: true });
format.push({ y: 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 }); 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; s.datapoints.format = format;
} }
...@@ -1584,6 +1589,9 @@ ...@@ -1584,6 +1589,9 @@
drawLeft, drawRight, drawTop, drawBottom, drawLeft, drawRight, drawTop, drawBottom,
tmp; 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) { if (horizontal) {
drawBottom = drawRight = drawTop = true; drawBottom = drawRight = drawTop = true;
drawLeft = false; drawLeft = false;
......
...@@ -64,9 +64,12 @@ adjusted (e.g for bar charts or filled areas). ...@@ -64,9 +64,12 @@ adjusted (e.g for bar charts or filled areas).
newpoints = [], newpoints = [],
px, py, intery, qx, qy, bottom, px, py, intery, qx, qy, bottom,
withlines = s.lines.show, 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, withsteps = withlines && s.lines.steps,
fromgap = true, fromgap = true,
keyOffset = horizontal ? 1 : 0,
accumulateOffset = horizontal ? 0 : 1,
i = 0, j = 0, l; i = 0, j = 0, l;
while (true) { while (true) {
...@@ -98,17 +101,17 @@ adjusted (e.g for bar charts or filled areas). ...@@ -98,17 +101,17 @@ adjusted (e.g for bar charts or filled areas).
} }
else { else {
// cases where we actually got two points // cases where we actually got two points
px = points[i]; px = points[i + keyOffset];
py = points[i + 1]; py = points[i + accumulateOffset];
qx = otherpoints[j]; qx = otherpoints[j + keyOffset];
qy = otherpoints[j + 1]; qy = otherpoints[j + accumulateOffset];
bottom = 0; bottom = 0;
if (px == qx) { if (px == qx) {
for (m = 0; m < ps; ++m) for (m = 0; m < ps; ++m)
newpoints.push(points[i + m]); newpoints.push(points[i + m]);
newpoints[l + 1] += qy; newpoints[l + accumulateOffset] += qy;
bottom = qy; bottom = qy;
i += ps; i += ps;
...@@ -118,9 +121,9 @@ adjusted (e.g for bar charts or filled areas). ...@@ -118,9 +121,9 @@ adjusted (e.g for bar charts or filled areas).
// we got past point below, might need to // we got past point below, might need to
// insert interpolated extra point // insert interpolated extra point
if (withlines && i > 0 && points[i - ps] != null) { 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(qx);
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;
...@@ -141,9 +144,9 @@ adjusted (e.g for bar charts or filled areas). ...@@ -141,9 +144,9 @@ adjusted (e.g for bar charts or filled areas).
// 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 + 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; i += ps;
} }
...@@ -175,6 +178,6 @@ adjusted (e.g for bar charts or filled areas). ...@@ -175,6 +178,6 @@ adjusted (e.g for bar charts or filled areas).
init: init, init: init,
options: options, options: options,
name: 'stack', name: 'stack',
version: '1.1' version: '1.2'
}); });
})(jQuery); })(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