Skip to content

Commit

Permalink
Fixed #6231, added findNearestPointBy option to series.
Browse files Browse the repository at this point in the history
  • Loading branch information
oysteinmoseng committed Mar 29, 2017
1 parent 2a2092e commit 956ff1d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion js/parts-more/Polar.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ wrap(seriesProto, 'buildKDTree', function (proceed) {
if (this.kdByAngle) {
this.searchPoint = this.searchPointByAngle;
} else {
this.kdDimensions = 2;
this.options.findNearestPointBy = 'xy';
}
}
proceed.apply(this);
Expand Down
6 changes: 5 additions & 1 deletion js/parts/Pointer.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ H.Pointer.prototype = {
noSharedTooltip = s.noSharedTooltip && shared;
directTouch = !shared && s.directTouch;
if (s.visible && !noSharedTooltip && !directTouch && pick(s.options.enableMouseTracking, true)) { // #3821
kdpointT = s.searchPoint(e, !noSharedTooltip && s.kdDimensions === 1); // #3828
// #3828
kdpointT = s.searchPoint(
e,
!noSharedTooltip && s.options.findNearestPointBy.indexOf('y') < 0
);
if (kdpointT && kdpointT.series) { // Point.series becomes null when reset and before redraw (#5197)
kdpoints.push(kdpointT);
}
Expand Down
2 changes: 1 addition & 1 deletion js/parts/ScatterSeries.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var Series = H.Series,
*/
seriesType('scatter', 'line', {
lineWidth: 0,
findNearestPointBy: 'xy',
marker: {
enabled: true // Overrides auto-enabling in line series (#3647)
},
Expand All @@ -38,7 +39,6 @@ seriesType('scatter', 'line', {
noSharedTooltip: true,
trackerGroups: ['group', 'markerGroup', 'dataLabelsGroup'],
takeOrdinalPosition: false, // #2342
kdDimensions: 2,
drawGraph: function () {
if (this.options.lineWidth) {
Series.prototype.drawGraph.call(this);
Expand Down
15 changes: 8 additions & 7 deletions js/parts/Series.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ H.Series = H.seriesType('line', null, { // base series options
//valuePrefix: '',
//ySuffix: ''
//}
turboThreshold: 1000
turboThreshold: 1000,
// zIndex: null

findNearestPointBy: 'x' // docs

}, /** @lends Series.prototype */ {
isCartesian: true,
Expand Down Expand Up @@ -1931,7 +1931,6 @@ H.Series = H.seriesType('line', null, { // base series options
* KD Tree && PointSearching Implementation
*/

kdDimensions: 1,
kdAxisArray: ['clientX', 'plotY'],

searchPoint: function (e, compareX) {
Expand All @@ -1958,7 +1957,8 @@ H.Series = H.seriesType('line', null, { // base series options
this.buildingKdTree = true;

var series = this,
dimensions = series.kdDimensions;
dimensions = series.options.findNearestPointBy.indexOf('y') > -1 ?
2 : 1;

// Internal function
function _kdtree(points, depth, dimensions) {
Expand Down Expand Up @@ -2010,7 +2010,9 @@ H.Series = H.seriesType('line', null, { // base series options
var series = this,
kdX = this.kdAxisArray[0],
kdY = this.kdAxisArray[1],
kdComparer = compareX ? 'distX' : 'dist';
kdComparer = compareX ? 'distX' : 'dist',
kdDimensions = series.options.findNearestPointBy.indexOf('y') > -1 ?
2 : 1;

// Set the one and two dimensional distance on the point object
function setDistance(p1, p2) {
Expand Down Expand Up @@ -2060,8 +2062,7 @@ H.Series = H.seriesType('line', null, { // base series options
}

if (this.kdTree) {
return _search(point,
this.kdTree, this.kdDimensions, this.kdDimensions);
return _search(point, this.kdTree, kdDimensions, kdDimensions);
}
}

Expand Down

0 comments on commit 956ff1d

Please sign in to comment.