-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
compare/unified hover include all points at same coordinate #4664
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
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 |
---|---|---|
|
@@ -365,7 +365,7 @@ function _hover(gd, evt, subplot, noHoverEvent) { | |
// find the closest point in each trace | ||
// this is minimum dx and/or dy, depending on mode | ||
// and the pixel position for the label (labelXpx, labelYpx) | ||
function findHoverPoints(vals) { | ||
function findHoverPoints(customXVal, customYVal) { | ||
for(curvenum = 0; curvenum < searchData.length; curvenum++) { | ||
cd = searchData[curvenum]; | ||
|
||
|
@@ -467,6 +467,9 @@ function _hover(gd, evt, subplot, noHoverEvent) { | |
mode = mode ? 'closest' : 'y'; | ||
} | ||
} | ||
} else if(customXVal !== undefined && customYVal !== undefined) { | ||
xval = customXVal; | ||
yval = customYVal; | ||
} else { | ||
xval = xvalArray[subploti]; | ||
yval = yvalArray[subploti]; | ||
|
@@ -625,6 +628,46 @@ function _hover(gd, evt, subplot, noHoverEvent) { | |
|
||
hoverData.sort(function(d1, d2) { return d1.distance - d2.distance; }); | ||
|
||
// If in compare mode, select every point at position | ||
if(hoverData[0].length !== 0 && | ||
['x', 'y'].indexOf(mode) !== -1 && | ||
hoverData[0].trace.type !== 'splom' // TODO: add support for splom | ||
) { | ||
var hd = hoverData[0]; | ||
var cd0 = hd.cd[hd.index]; | ||
var isGrouped = (fullLayout.boxmode === 'group' || fullLayout.violinmode === 'group'); | ||
archmoj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
var xVal = hd.xVal; | ||
var ax = hd.xa; | ||
if(ax.type === 'category') xVal = ax._categoriesMap[xVal]; | ||
if(ax.type === 'date') xVal = ax.d2c(xVal); | ||
if(cd0 && cd0.t && cd0.t.posLetter === ax._id && isGrouped) { | ||
xVal += cd0.t.dPos; | ||
} | ||
|
||
var yVal = hd.yVal; | ||
ax = hd.ya; | ||
if(ax.type === 'category') yVal = ax._categoriesMap[yVal]; | ||
if(ax.type === 'date') yVal = ax.d2c(yVal); | ||
archmoj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if(cd0 && cd0.t && cd0.t.posLetter === ax._id && isGrouped) { | ||
yVal += cd0.t.dPos; | ||
} | ||
|
||
findHoverPoints(xVal, yVal); | ||
|
||
// Remove duplicated hoverData points | ||
// note that d3 also filters identical points in the rendering steps | ||
// TODO: use ES6 map | ||
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. I don't think we can make that a TODO just yet - perhaps if & when we convert the whole syntax to ES6 we can make sure we include polyfills for this and other feature, THEN we can use it whenever we wish... |
||
var repeated = {}; | ||
hoverData = hoverData.filter(function(hd) { | ||
var key = hoverDataKey(hd); | ||
if(!repeated[key]) { | ||
repeated[key] = true; | ||
return repeated[key]; | ||
} | ||
}); | ||
} | ||
|
||
// lastly, emit custom hover/unhover events | ||
var oldhoverdata = gd._hoverdata; | ||
var newhoverdata = []; | ||
|
@@ -703,6 +746,10 @@ function _hover(gd, evt, subplot, noHoverEvent) { | |
}); | ||
} | ||
|
||
function hoverDataKey(d) { | ||
return [d.trace.index, d.index, d.x0, d.y0, d.name, d.attr, d.xa, d.ya || ''].join(','); | ||
} | ||
|
||
var EXTRA_STRING_REGEX = /<extra>([\s\S]*)<\/extra>/; | ||
|
||
function createHoverText(hoverData, opts, gd) { | ||
|
@@ -1032,7 +1079,7 @@ function createHoverText(hoverData, opts, gd) { | |
.data(hoverData, function(d) { | ||
// N.B. when multiple items have the same result key-function value, | ||
// only the first of those items in hoverData gets rendered | ||
return [d.trace.index, d.index, d.x0, d.y0, d.name, d.attr, d.xa, d.ya || ''].join(','); | ||
return hoverDataKey(d); | ||
}); | ||
hoverLabels.enter().append('g') | ||
.classed('hovertext', true) | ||
|
This file contains hidden or 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.
concerning
creating a dynamic array of strings just for index checking might be slow.
Could we create a constant e.g.
at the upper scope and reuse that here?
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.
or even
var XY = {x: 1, y: 1}
->if(XY[mode])
😅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.
Done in b8b9395