-
-
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
support template string on hover #3126
Merged
Merged
Changes from 51 commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
4c197e8
rough first implementation for hovertemplate
antoinerg 613c8f5
supply hover's eventData inot hovertemplate
antoinerg edf4795
delete unrelated file from branch
antoinerg dd62855
update description for hovertemplate
antoinerg a86327a
fix hovertemplate test not being run
antoinerg 1fde3aa
for now, only offer hoverdata and trace objects to hovertemplate
antoinerg d263cce
templateString evaluates attributes with a dot in their name
antoinerg 040208f
do not coerce hoverinfo if hovertemplate is defined
antoinerg 3eaa3b9
replace templateString with the more specific hovertemplateString
antoinerg 0084efb
hovertemplate: add warning if variable can't be found
antoinerg 046d367
coerce hovertemplate at trace-level, starting with scatter(gl)
antoinerg 59083ad
add <extra></extra> tag to hovertemplate for secondary labels
antoinerg 266d43a
add URL to d3-format documentation
antoinerg 108b68a
initial hovertemplate support for pie
antoinerg eb1a94a
pie hovertemplate test %{label}
antoinerg 8214d36
bar support with limited test
antoinerg bb97abe
add hovertemplate support in histogram
antoinerg 22e3a9d
pie returns default formatted value
antoinerg 377ecba
pass hovertemplate data around in `hoverData` instead of opts
antoinerg bc6cbab
update Fx.multiHovers to properly massage hoverItem
antoinerg 8c9ba5b
fix lint
antoinerg c767482
pass `trace` object in Fx.loneHover and Fx.multiHovers for hovertemplate
antoinerg 6d4c03a
extra regex still matches in the presence of newlines
antoinerg 8f440b0
fix jsDocs syntax
antoinerg 0659d20
move regex to outer scope
antoinerg 41ab464
remove old unused commented lines
antoinerg 37e40f9
move regex to outside scope
antoinerg 8e8b75b
move hovertemplate out of global-level plots attributes
antoinerg 2015c57
scatter: do not coerce hovertemplate if hoveron: 'fills'
antoinerg aef48c0
fix lint
antoinerg a3058f4
test hovertemplate support for <extra> and pseudo-html
antoinerg 3068d7d
hovertemplate warns user about missing variables up to 10 times
antoinerg a808883
hovertemplate attribute supports array
antoinerg 522f744
scattergl support for hovertemplate array
antoinerg c501b44
pie support for hovertemplate array
antoinerg f89baca
make axes available in eventData to give access to its title
antoinerg 369c9d6
add axis information to eventData only if hovertemplate
antoinerg 8d95f05
axis information is already included in hovertemplate
antoinerg 1e4bd33
pie: test that hovertemplate supports array
antoinerg 61a2da7
list available variables in pie's hovertemplate description
antoinerg 43a4cd9
hovertemplate: do not look into trace object, use fullData instead
antoinerg 70befe3
describe hovertemplate variables for scatter(gl)
antoinerg b6822e8
describe hovertemplate variables for histogram
antoinerg 59bc981
fix lint
antoinerg f75f2e0
scatter: test hover event data
antoinerg 0654245
test that event data has correct fields in bar, scatter, histogram
antoinerg 0ecd1c1
bar test: fix hover position to trigger hover events
antoinerg 6f86522
scatter: add `marker.color` to `hovertemplate` available variables
antoinerg 7be804e
one source of truth for event data keys used for doc and test
antoinerg 583eb97
fix lint
antoinerg 14ac99f
scatter: list additionnal variables available in eventData
antoinerg 1caf321
hovertemplate: update desc, do no list attributes that are `arrayOK`
antoinerg a78600a
fix syntax
antoinerg 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
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
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,48 @@ | ||
/** | ||
* Copyright 2012-2018, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
module.exports = function(opts, extra) { | ||
opts = opts || {}; | ||
extra = extra || {}; | ||
|
||
var descPart = extra.description ? ' ' + extra.description : ''; | ||
var keys = extra.keys || []; | ||
if(keys.length > 0) { | ||
var quotedKeys = []; | ||
for(var i = 0; i < keys.length; i++) { | ||
quotedKeys[i] = '`' + keys[i] + '`'; | ||
} | ||
descPart = descPart + 'This trace supports the additional '; | ||
if(keys.length === 1) { | ||
descPart = 'variable ' + quotedKeys[0]; | ||
} else { | ||
descPart = 'variables ' + quotedKeys.slice(0, -1).join(', ') + ' and ' + quotedKeys.slice(-1) + '.'; | ||
} | ||
} | ||
|
||
var hovertemplate = { | ||
valType: 'string', | ||
role: 'info', | ||
dflt: '', | ||
arrayOk: true, | ||
editType: 'none', | ||
description: [ | ||
'Template string used for rendering the information that appear on hover box.', | ||
'Note that this will override `hoverinfo`.', | ||
'Variables are inserted using %{variable}, for example "y: %{y}".', | ||
'Numbers are formatted using d3-format\'s syntax %{variable:d3-format}, for example "Price: %{y:$.2f}".', | ||
'See https://github.com/d3/d3-format/blob/master/README.md#locale_format for details on the formatting syntax.', | ||
'The variables available in `hovertemplate` are the ones emitted as event data described at this link https://plot.ly/javascript/plotlyjs-events/#event-data.', | ||
descPart | ||
].join(' ') | ||
}; | ||
|
||
return hovertemplate; | ||
}; |
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
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
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
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,14 @@ | ||
/** | ||
* Copyright 2012-2018, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
|
||
'use strict'; | ||
|
||
module.exports = { | ||
eventDataKeys: [] | ||
}; |
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
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
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
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,14 @@ | ||
/** | ||
* Copyright 2012-2018, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
|
||
'use strict'; | ||
|
||
module.exports = { | ||
eventDataKeys: ['binNumber'] | ||
}; |
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
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
Oops, something went wrong.
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.
Very interesting. I've never been a big fan of
hasOwnProperty
(probably because it's a long word to type out), but look at this:using http://jsbench.github.io/#1aebf699d73fb743127903c0b0a8bece
... so maybe we should start switching to
hasOwnProperty
in hot codepaths 🔥