-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure winning points of hover are listed first when hoversubplots
is set to "axis" and sorting by distance
#6963
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0eaec35
fix (x|y) spike position and ensure main subplot hover points are sor…
archmoj 1ab4e1a
jasmine test
archmoj 337cda0
draftlog
archmoj bb704dc
Merge remote-tracking branch 'origin/master' into fix6960-hoversubplots
archmoj 5b6998d
comment
archmoj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- Ensure winning points of hover are listed first when hoversubplots is set to "axis" and sorting by distance [[#6963](https://github.com/plotly/plotly.js/pull/6963)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,10 @@ var cartesianScatterPoints = { | |
splom: true | ||
}; | ||
|
||
function distanceSort(a, b) { | ||
return a.distance - b.distance; | ||
} | ||
|
||
// fx.hover: highlight data on hover | ||
// evt can be a mousemove event, or an object with data about what points | ||
// to hover on | ||
|
@@ -270,15 +274,21 @@ function _hover(gd, evt, subplot, noHoverEvent, eventTarget) { | |
var hovermodeHasX = (hovermode || '').charAt(0) === 'x'; | ||
var hovermodeHasY = (hovermode || '').charAt(0) === 'y'; | ||
|
||
var firstXaxis; | ||
var firstYaxis; | ||
|
||
if(hasCartesian && (hovermodeHasX || hovermodeHasY) && hoversubplots === 'axis') { | ||
var subplotsLength = subplots.length; | ||
for(var p = 0; p < subplotsLength; p++) { | ||
spId = subplots[p]; | ||
if(plots[spId]) { | ||
// 'cartesian' case | ||
|
||
firstXaxis = Axes.getFromId(gd, spId, 'x'); | ||
firstYaxis = Axes.getFromId(gd, spId, 'y'); | ||
|
||
var subplotsWith = ( | ||
Axes.getFromId(gd, spId, hovermodeHasX ? 'x' : 'y') | ||
hovermodeHasX ? firstXaxis : firstYaxis | ||
)._subplotsWith; | ||
|
||
if(subplotsWith && subplotsWith.length) { | ||
|
@@ -661,6 +671,9 @@ function _hover(gd, evt, subplot, noHoverEvent, eventTarget) { | |
var thisSpikeDistance; | ||
|
||
for(var i = 0; i < pointsData.length; i++) { | ||
if(firstXaxis && firstXaxis._id !== pointsData[i].xa._id) continue; | ||
if(firstYaxis && firstYaxis._id !== pointsData[i].ya._id) continue; | ||
|
||
thisSpikeDistance = pointsData[i].spikeDistance; | ||
if(spikeOnWinning && i === 0) thisSpikeDistance = -Infinity; | ||
|
||
|
@@ -700,9 +713,26 @@ function _hover(gd, evt, subplot, noHoverEvent, eventTarget) { | |
gd._spikepoints = newspikepoints; | ||
|
||
var sortHoverData = function() { | ||
if(hoversubplots !== 'axis') { | ||
hoverData.sort(function(d1, d2) { return d1.distance - d2.distance; }); | ||
} | ||
// When sorting keep the points in the main subplot at the top | ||
// then add points in other subplots | ||
|
||
var hoverDataInSubplot = hoverData.filter(function(a) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. naming suggestion -- should these functions be called |
||
return ( | ||
(firstXaxis && firstXaxis._id === a.xa._id) && | ||
(firstYaxis && firstYaxis._id === a.ya._id) | ||
); | ||
}); | ||
|
||
var hoverDataOutSubplot = hoverData.filter(function(a) { | ||
return !( | ||
(firstXaxis && firstXaxis._id === a.xa._id) && | ||
(firstYaxis && firstYaxis._id === a.ya._id) | ||
); | ||
}); | ||
|
||
hoverDataInSubplot.sort(distanceSort); | ||
hoverDataOutSubplot.sort(distanceSort); | ||
hoverData = hoverDataInSubplot.concat(hoverDataOutSubplot); | ||
|
||
// move period positioned points and box/bar-like traces to the end of the list | ||
hoverData = orderRangePoints(hoverData, hovermode); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@archmoj Could you add a comment here explaining the new sorting logic?