diff --git a/js/annotations.js b/js/annotations.js index 582358c..5ca12ee 100644 --- a/js/annotations.js +++ b/js/annotations.js @@ -579,8 +579,8 @@ linkType = (linkedTo instanceof H.Point) ? 'point' : (linkedTo instanceof H.Series) ? 'series' : null; if (linkType === 'point') { - options.x = linkedTo.plotX + chart.plotLeft; - options.y = linkedTo.plotY + chart.plotTop; + options.x = xAxis.toPixels(linkedTo.x); + options.y = yAxis.toPixels(linkedTo.y); series = linkedTo.series; } else if (linkType === 'series') { series = linkedTo; @@ -601,6 +601,12 @@ x = (defined(options.xValue) ? xAxis.toPixels(options.xValue /* + xAxis.minPointOffset */) : options.x); y = defined(options.yValue) ? yAxis.toPixels(options.yValue) : options.y; + if (chart.inverted) { + var tempX = x; + x = y; + y = tempX; + } + if (isNaN(x) || isNaN(y) || !isNumber(x) || !isNumber(y)) { return; } @@ -840,13 +846,24 @@ if (!chart.isInsidePlot(clickX - chart.plotLeft, clickY - chart.plotTop)) { return; } - var note = chart.activeAnnotation; - - var x = note.options.allowDragX ? event.clientX - note.startX + note.group.translateX : note.group.translateX, + var note = chart.activeAnnotation, + x, + y; + + if (chart.inverted) { + // Screen X is Y axis and screen Y is X axis. + x = note.options.allowDragY ? event.clientX - note.startX + note.group.translateX : note.group.translateX; + y = note.options.allowDragX ? event.clientY - note.startY + note.group.translateY : note.group.translateY; + note.transX = y; + note.transY = x; + } else { + // Screen X is X axis and screen X is X axis. + x = note.options.allowDragX ? event.clientX - note.startX + note.group.translateX : note.group.translateX; y = note.options.allowDragY ? event.clientY - note.startY + note.group.translateY : note.group.translateY; - - note.transX = x; - note.transY = y; + note.transX = x; + note.transY = y; + } + note.group.attr({ transform: 'translate(' + x + ',' + y + ')' }); @@ -877,6 +894,7 @@ event.stopPropagation(); event.preventDefault(); if (chart.activeAnnotation && (chart.activeAnnotation.transX !== 0 || chart.activeAnnotation.transY !== 0)) { + // `transX` and `transY` are set taking in acount `chart.inverted`. var note = chart.activeAnnotation, x = note.transX, y = note.transY, @@ -891,7 +909,7 @@ yAxis = note.chart.yAxis[note.options.yAxis], newX = xAxis.toValue(x), newY = yAxis.toValue(y); - + if (x !== 0 || y !== 0) { if (allowDragX && allowDragY) { note.update({