Skip to content

Commit

Permalink
#5997, panning not working with reversed axes. Also closes #3278.
Browse files Browse the repository at this point in the history
  • Loading branch information
oysteinmoseng committed Nov 21, 2016
1 parent c5729dc commit aee476c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions js/parts/Interaction.js
Expand Up @@ -416,8 +416,16 @@ extend(Chart.prototype, /** @lends Chart.prototype */ {
extremes = axis.getExtremes(),
newMin = axis.toValue(startPos - mousePos, true) + halfPointRange,
newMax = axis.toValue(startPos + axis.len - mousePos, true) - halfPointRange,
goingLeft = startPos > mousePos; // #3613

goingLeft = startPos > mousePos, // #3613
tmp;

// Swap min/max for reversed axes (#5997)
if (axis.reversed) {
tmp = newMin;
newMin = newMax;
newMax = tmp;
}

if (axis.series.length &&
(goingLeft || newMin > Math.min(extremes.dataMin, extremes.min)) &&
(!goingLeft || newMax < Math.max(extremes.dataMax, extremes.max))) {
Expand Down

2 comments on commit aee476c

@Drumstix42
Copy link

@Drumstix42 Drumstix42 commented on aee476c Nov 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This partially fixes the issue, but the halfPointRange needs adjusting as well as the goingLeft flag. Otherwise, the extremes get set incorrectly when zoomed, and when not zoomed you can scroll past the normal min/max.

I suggest add a variable for reversed:
reversed = axis.reversed,

Change halfPointRange declaration line to this:
halfPointRange = (axis.pointRange || 0) / 2 * (reversed ? -1 : 1),
(added the reversed check at the end)

And modify your new if statement to look like this:
if (reversed) { goingLeft = startPos < mousePos tmp = newMin; newMin = newMax; newMax = tmp; }
(Uses the reversed var now, and added the goingLeft check with opposite comparison)

I tested this on the newest public version of Highcharts and was able to successfully pan in normal and reversed xAxis.

@oysteinmoseng
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Drumstix42 Great catch, thanks for your comment!

Please sign in to comment.