From 2ce1139cf7ac97c3804c32f30154541a606a19c9 Mon Sep 17 00:00:00 2001 From: David Schnur Date: Mon, 22 Jul 2013 11:40:43 -0400 Subject: [PATCH] Fix highlights for right-aligned bars. Support for right-aligned bars was never added to the hover or highlight code; only the actual bar drawing. We need to replicate that in the other two places as well. Resolves #1093. --- jquery.flot.js | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/jquery.flot.js b/jquery.flot.js index 3bedcb5..500e690 100644 --- a/jquery.flot.js +++ b/jquery.flot.js @@ -2801,8 +2801,22 @@ Licensed under the MIT license. } if (s.bars.show && !item) { // no other point can be nearby - var barLeft = s.bars.align == "left" ? 0 : -s.bars.barWidth/2, - barRight = barLeft + s.bars.barWidth; + + switch (s.bars.align) { + case "left": + barLeft = 0; + break; + case "right": + barLeft = -s.bars.barWidth; + break; + case "center": + barLeft = -s.bars.barWidth / 2; + break; + default: + throw new Error("Invalid bar alignment: " + s.bars.align); + } + + barRight = barLeft + s.bars.barWidth; for (j = 0; j < points.length; j += ps) { var x = points[j], y = points[j + 1], b = points[j + 2]; @@ -3000,7 +3014,21 @@ Licensed under the MIT license. function drawBarHighlight(series, point) { var highlightColor = (typeof series.highlightColor === "string") ? series.highlightColor : $.color.parse(series.color).scale('a', 0.5).toString(), fillStyle = highlightColor, - barLeft = series.bars.align == "left" ? 0 : -series.bars.barWidth/2; + barLeft; + + switch (series.bars.align) { + case "left": + barLeft = 0; + break; + case "right": + barLeft = -series.bars.barWidth; + break; + case "center": + barLeft = -series.bars.barWidth / 2; + break; + default: + throw new Error("Invalid bar alignment: " + series.bars.align); + } octx.lineWidth = series.bars.lineWidth; octx.strokeStyle = highlightColor;