-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Array support for trace hoverinfo
#1761
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
Changes from 2 commits
aab3366
2acf548
b649b11
7ed8681
371d31e
e8a9ddd
3c693a0
d7999e2
3c3fda4
d1f03c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -349,10 +349,22 @@ lib.noneOrAll = function(containerIn, containerOut, attrList) { | |
} | ||
}; | ||
|
||
lib.mergeArray = function(traceAttr, cd, cdAttr) { | ||
/** merge data array into calcdata items | ||
* | ||
* @param {array} traceAttr : trace attribute | ||
* @param {object} cd : calcdata trace | ||
* @param {string} cdAttr : calcdata key | ||
* @param {function} [fn] : optional function to apply to each array item | ||
* | ||
*/ | ||
lib.mergeArray = function(traceAttr, cd, cdAttr, fn) { | ||
fn = fn || lib.identity; | ||
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 wonder whether it would be worth avoiding
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. That won't make that much of a difference (at least in Chrome 58) https://gist.github.com/etpinard/4a5c7983a619efb4c98cb927529b9af6 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. awesome, thanks for checking. |
||
|
||
if(Array.isArray(traceAttr)) { | ||
var imax = Math.min(traceAttr.length, cd.length); | ||
for(var i = 0; i < imax; i++) cd[i][cdAttr] = traceAttr[i]; | ||
for(var i = 0; i < imax; i++) { | ||
cd[i][cdAttr] = fn(traceAttr[i]); | ||
} | ||
} | ||
}; | ||
|
||
|
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.
This here coerces
hoverinfo
items with no valid flags to'all'
ifgd.data.length > 1
or all flags but'name'
on single-trace graphs. For example,This is debatable I feel. Perhaps,
hoverinfo
items with no valid flags should get coerced to'none'
instead? This would be more in line with e.g.marker.color
whereI'm currently leaning toward the second option, but I have no strong opinion.
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.
I think as you have it is probably correct - an invalid entry gets the default behavior, which is
'all'
or all but name. This could come in handy, in as far as the default is really what you want most of the time, for tweakinghoverinfo
of just a few points by providing those in the array and leaving the rest of the arrayundefined
ornull
.