Skip to content

Commit

Permalink
Fixed #6420, When multiple axes, show only one snapping crosshair at …
Browse files Browse the repository at this point in the history
…the same time.
  • Loading branch information
jon-a-nygaard committed Apr 20, 2017
1 parent f6b24a7 commit 4f0fd7c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 13 deletions.
22 changes: 10 additions & 12 deletions js/parts/Pointer.js
Expand Up @@ -371,20 +371,18 @@ H.Pointer.prototype = {
}
});
}
// Draw crosshairs (#4927, #5269 #5066, #5658)

// Issues related to crosshair #4927, #5269 #5066, #5658
each(chart.axes, function drawAxisCrosshair(axis) {
// Snap is true. For each hover point, loop over the axes and draw a
// crosshair if that point belongs to the axis.
// @todo Consider only one crosshair per axis.
if (pick(axis.crosshair.snap, true)) {
each(points, function (p) {
if (p.series[axis.coll] === axis) {
axis.drawCrosshair(e, p);
}
});
} else {
var snap = pick(axis.crosshair.snap, true);
if (!snap) {
axis.drawCrosshair(e);
// axis has snapping crosshairs, and hover point is belonging to axis
} else if (hoverPoint && hoverPoint.series[axis.coll] === axis) {
axis.drawCrosshair(e, hoverPoint);
// axis has snapping crosshairs, but hover point is not belonging to axis
} else {
axis.hideCrosshair();
}
});
},
Expand Down
48 changes: 47 additions & 1 deletion samples/unit-tests/axis/crosshairs/demo.js
Expand Up @@ -63,4 +63,50 @@ QUnit.test('snap', function (assert) {
// );

// TODO Test positioning of crosshairs.
});
});

QUnit.test('Show only one snapping crosshair at the same time. #6420', function (assert) {
var chart = Highcharts.chart('container', {
xAxis: [{
crosshair: true
}, {
opposite: true,
crosshair: true
}],
series: [{
name: 'Installation',
data: [1, 2, 3],
xAxis: 0
}, {
name: 'Manufacturing',
data: [1, 2, 3].reverse(),
xAxis: 1
}]
}),
series1 = chart.series[0],
series2 = chart.series[1];

series1.points[0].onMouseOver();
assert.strictEqual(
series1.xAxis.cross.attr('visibility'),
'visible',
'Hover Series 1: crosshair on xAxis of Series 1 is visible'
);
assert.strictEqual(
!!series2.xAxis.cross,
false,
'Hover Series 1: crosshair on xAxis of Series 2 does not exist'
);

series2.points[2].onMouseOver();
assert.strictEqual(
series1.xAxis.cross.attr('visibility'),
'hidden',
'Hover Series 2: crosshair on xAxis of Series 1 is hidden'
);
assert.strictEqual(
series2.xAxis.cross.attr('visibility'),
'visible',
'Hover Series 2: crosshair on xAxis of Series 2 is visible'
);
});

0 comments on commit 4f0fd7c

Please sign in to comment.