Commit 5a86074f authored by olau@iola.dk's avatar olau@iola.dk

Fixed two bugs with negative bars

git-svn-id: https://flot.googlecode.com/svn/trunk@89 1e0a6537-2640-0410-bfb7-f154510ff394
parent 7daabbb3
......@@ -55,7 +55,7 @@ timothytoe). Fixed a bug in finding max values for all-negative data
sets. Prevent the possibility of eternal looping in tick calculations.
Fixed a bug when borderWidth is set to 0 (reported by
Rob/sanchothefat). Fixed a bug with drawing bars extending below 0
(reported by James Hewitt, convenient patch by Ryan Funduk). Fixed a
(reported by James Hewitt, patch by Ryan Funduk). Fixed a
bug with line widths of bars (reported by MikeM). Fixed a bug with
'nw' and 'sw' legend positions. Improved the handling of axis
auto-scaling with bars. Fixed a bug with multi-line x-axis tick
......
......@@ -1299,16 +1299,25 @@
if (data[i] == null)
continue;
var x = data[i][0], y = data[i][1];
var drawLeft = true, drawTop = true, drawRight = true;
// determine the co-ordinates of the bar, account for negative bars having
// flipped top/bottom and draw/don't draw accordingly
var left = x + deltaLeft, right = x + deltaRight, bottom = (y < 0 ? y : 0), top = (y < 0 ? 0 : y);
if (right < axisx.min || left > axisx.max || top < axisy.min || bottom > axisy.max)
continue;
var x = data[i][0], y = data[i][1],
drawLeft = true, drawRight = true,
drawTop = true, drawBottom = false,
left = x + deltaLeft, right = x + deltaRight,
bottom = 0, top = y;
// account for negative bars
if (top < bottom) {
top = 0;
bottom = y
drawBottom = true;
drawTop = false;
}
// clip
if (right < axisx.min || left > axisx.max ||
top < axisy.min || bottom > axisy.max)
continue;
if (left < axisx.min) {
left = axisx.min;
drawLeft = false;
......@@ -1319,9 +1328,11 @@
drawRight = false;
}
if (bottom < axisy.min)
if (bottom < axisy.min) {
bottom = axisy.min;
drawBottom = false;
}
if (top > axisy.max) {
top = axisy.max;
drawTop = false;
......@@ -1338,7 +1349,7 @@
}
// draw outline
if (drawLeft || drawRight || drawTop) {
if (drawLeft || drawRight || drawTop || drawBottom) {
ctx.beginPath();
ctx.moveTo(axisx.p2c(left), axisy.p2c(bottom) + offset);
if (drawLeft)
......@@ -1354,6 +1365,10 @@
ctx.lineTo(axisx.p2c(right), axisy.p2c(bottom) + offset);
else
ctx.moveTo(axisx.p2c(right), axisy.p2c(bottom) + offset);
if (drawBottom)
ctx.lineTo(axisx.p2c(left), axisy.p2c(bottom) + offset);
else
ctx.moveTo(axisx.p2c(left), axisy.p2c(bottom) + offset);
ctx.stroke();
}
}
......@@ -1519,7 +1534,8 @@
// For a bar graph, the cursor must be inside the bar
// and no other point can be nearby
if (!foundPoint && mx >= x + barLeft &&
mx <= x + barRight && my <= y)
mx <= x + barRight &&
(y > 0 ? my >= 0 && my <= y : my <= 0 && my >= y))
item = result(i, j);
}
......
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