Permalink
Browse files

Added demo and test for findNearestPointBy, ref #6231.

  • Loading branch information...
oysteinmoseng committed Mar 29, 2017
1 parent bdc0693 commit f109bdfbf34d69ca9dac2e73c3e0eb0bc76f0005
View
@@ -171,7 +171,7 @@ H.Series = H.seriesType('line', null, { // base series options
//}
turboThreshold: 1000,
// zIndex: null
findNearestPointBy: 'x' // docs
findNearestPointBy: 'x'
}, /** @lends Series.prototype */ {
isCartesian: true,
@@ -0,0 +1,6 @@
---
name: Highcharts Demo
authors:
- Øystein Moseng
js_wrap: b
...
@@ -0,0 +1,3 @@
<script src="https://code.highcharts.com/highcharts.js"></script>
<div id="container" style="height: 400px; width: 800px"></div>
@@ -0,0 +1,47 @@
Highcharts.chart('container', {
title: {
text: 'The top series snaps hover along X axis'
},
plotOptions: {
line: {
marker: {
enabled: true
}
}
},
series: [{
findNearestPointBy: 'x',
// Hover at [3.5, 6] to demo x-dimension search
// Compare to Series 2 behavior at [5.5, 3]
data: [
[0, 6],
[1, 6],
[1, 7],
[2, 6],
[3, 6],
[3.5, 4],
[4, 6],
[5, 6],
[6, 6],
[7, 6]
]
}, {
findNearestPointBy: 'xy',
// Hover at [1, 4] to demo xy-dimension search.
// Useful when having multiple points on the same x-value.
data: [
[0, 3],
[1, 3],
[1, 4],
[2, 3],
[3, 3],
[4, 3],
[5, 3],
[5.5, 5.5],
[6, 3],
[7, 3]
]
}]
});
@@ -0,0 +1,6 @@
---
resources:
- https://code.jquery.com/qunit/qunit-2.0.1.js
- https://code.jquery.com/qunit/qunit-2.0.1.css
js_wrap: b
...
@@ -0,0 +1,6 @@
<script src="https://code.highcharts.com/stock/highcharts.js"></script>
<div id="container" style="width: 600px; margin: 0 auto"></div>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
@@ -0,0 +1,97 @@
QUnit.test('findNearestPointBy test', function (assert) {
var chart = Highcharts.chart('container', {
title: {
text: 'The top series snaps hover along X axis'
},
plotOptions: {
line: {
kdNow: false,
marker: {
enabled: true
}
}
},
series: [{
findNearestPointBy: 'x',
// Hover at [3.5, 6] to demo x-dimension search
// Compare to Series 2 behavior at [5.5, 3]
data: [
[0, 6],
[1, 6],
[1, 7],
[2, 6],
[3, 6],
[3.5, 4],
[4, 6],
[5, 6],
[6, 6]
]
}, {
findNearestPointBy: 'xy',
// Hover at [1, 4] to demo xy-dimension search.
// Useful when having multiple points on the same x-value.
data: [
[0, 3],
[1, 3],
[1, 4],
[2, 3],
[3, 3],
[4, 3],
[5, 3],
[5.5, 5.5],
[6, 3]
]
}]
});
var controller = window.TestController(chart),
x1 = chart.series[0].points[5].plotX + chart.plotLeft,
y1 = chart.series[0].points[1].plotY + chart.plotTop,
x2 = chart.series[1].points[7].plotX + chart.plotLeft,
y2 = chart.series[1].points[1].plotY + chart.plotTop,
x3 = chart.series[0].points[2].plotX + chart.plotLeft,
y3 = chart.series[0].points[2].plotY + chart.plotTop,
x4 = chart.series[0].points[1].plotX + chart.plotLeft,
y4 = chart.series[0].points[1].plotY + chart.plotTop,
x5 = chart.series[1].points[2].plotX + chart.plotLeft,
y5 = chart.series[1].points[2].plotY + chart.plotTop,
x6 = chart.series[1].points[1].plotX + chart.plotLeft,
y6 = chart.series[1].points[1].plotY + chart.plotTop;
controller.mousemove(x1, y1);
assert.ok(
chart.hoverPoint === chart.series[0].points[5],
'Hover point snaps to X'
);
controller.mousemove(x2, y2);
assert.notOk(
chart.hoverPoint === chart.series[1].points[7],
'Hover point does not snap to X'
);
controller.mousemove(x3, y3);
if (chart.hoverPoint === chart.series[0].points[2]) {
controller.mousemove(x4, y4);
assert.notOk(
chart.hoverPoint === chart.series[0].points[1],
'Hover does not allow duplicate X'
);
}
controller.mousemove(x5, y5);
assert.ok(
chart.hoverPoint === chart.series[1].points[2],
'Hover allows duplicate X'
);
controller.mousemove(x6, y6);
assert.ok(
chart.hoverPoint === chart.series[1].points[1],
'Hover allows duplicate X'
);
});

0 comments on commit f109bdf

Please sign in to comment.