Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions js/annotations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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 + ')'
});
Expand Down Expand Up @@ -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,
Expand All @@ -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({
Expand Down