-
-
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
implement hoverinfo 'none' and 'skip' in sankey #3096
Changes from all commits
69c11fe
880973a
d247b8b
1919b72
e942bc5
1813d6c
9e4f1a0
706e7ae
7c24d29
53d7ce3
87c30fe
7a32036
b436003
fe7ab49
644c4e3
ccaef04
dc8ba12
ea73c64
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 |
---|---|---|
|
@@ -9,20 +9,13 @@ | |
'use strict'; | ||
|
||
var fontAttrs = require('../../plots/font_attributes'); | ||
var plotAttrs = require('../../plots/attributes'); | ||
var colorAttrs = require('../../components/color/attributes'); | ||
var fxAttrs = require('../../components/fx/attributes'); | ||
var domainAttrs = require('../../plots/domain').attributes; | ||
|
||
var extendFlat = require('../../lib/extend').extendFlat; | ||
var overrideAll = require('../../plot_api/edit_types').overrideAll; | ||
|
||
module.exports = overrideAll({ | ||
hoverinfo: extendFlat({}, plotAttrs.hoverinfo, { | ||
flags: ['label', 'text', 'value', 'percent', 'name'], | ||
}), | ||
hoverlabel: fxAttrs.hoverlabel, // needs editType override | ||
|
||
var attrs = module.exports = overrideAll({ | ||
domain: domainAttrs({name: 'sankey', trace: true}), | ||
|
||
orientation: { | ||
|
@@ -127,6 +120,18 @@ module.exports = overrideAll({ | |
role: 'style', | ||
description: 'Sets the thickness (in px) of the `nodes`.' | ||
}, | ||
hoverinfo: { | ||
valType: 'enumerated', | ||
values: ['all', 'none', 'skip'], | ||
dflt: 'all', | ||
role: 'info', | ||
description: [ | ||
'Determines which trace information appear when hovering nodes.', | ||
'If `none` or `skip` are set, no information is displayed upon hovering.', | ||
'But, if `none` is set, click and hover events are still fired.' | ||
].join(' ') | ||
}, | ||
hoverlabel: fxAttrs.hoverlabel, // needs editType override, | ||
description: 'The nodes of the Sankey plot.' | ||
}, | ||
|
||
|
@@ -185,6 +190,21 @@ module.exports = overrideAll({ | |
role: 'info', | ||
description: 'A numeric value representing the flow volume value.' | ||
}, | ||
hoverinfo: { | ||
valType: 'enumerated', | ||
values: ['all', 'none', 'skip'], | ||
dflt: 'all', | ||
role: 'info', | ||
description: [ | ||
'Determines which trace information appear when hovering links.', | ||
'If `none` or `skip` are set, no information is displayed upon hovering.', | ||
'But, if `none` is set, click and hover events are still fired.' | ||
].join(' ') | ||
}, | ||
hoverlabel: fxAttrs.hoverlabel, // needs editType override, | ||
description: 'The links of the Sankey plot.' | ||
} | ||
}, 'calc', 'nested'); | ||
// hide unsupported top-level properties from plot-schema | ||
attrs.hoverinfo = undefined; | ||
attrs.hoverlabel = undefined; | ||
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. But wait, trace 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 think we should either make node/link 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. @etpinard It's great that you noticed that change and I agree this should be handled better! FYI, having 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. Ah indeed - good catch @etpinard - I'd go for:
That would be more friendly for the (probably most common) case that users want node and link hover labels styled the same. 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. ... and maybe we should have a trace 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.
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. e.g. Not all the flags to be implemented in #3097 should be available from the trace hoverinfo, but I think setting trace-wide |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -13,37 +13,55 @@ var attributes = require('./attributes'); | |||||||||||||||||||||||||||||||
var Color = require('../../components/color'); | ||||||||||||||||||||||||||||||||
var tinycolor = require('tinycolor2'); | ||||||||||||||||||||||||||||||||
var handleDomainDefaults = require('../../plots/domain').defaults; | ||||||||||||||||||||||||||||||||
var handleHoverLabelDefaults = require('../../components/fx/hoverlabel_defaults'); | ||||||||||||||||||||||||||||||||
var Template = require('../../plot_api/plot_template'); | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) { | ||||||||||||||||||||||||||||||||
function coerce(attr, dflt) { | ||||||||||||||||||||||||||||||||
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt); | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
coerce('node.label'); | ||||||||||||||||||||||||||||||||
coerce('node.pad'); | ||||||||||||||||||||||||||||||||
coerce('node.thickness'); | ||||||||||||||||||||||||||||||||
coerce('node.line.color'); | ||||||||||||||||||||||||||||||||
coerce('node.line.width'); | ||||||||||||||||||||||||||||||||
// node attributes | ||||||||||||||||||||||||||||||||
var nodeIn = traceIn.node, nodeOut = Template.newContainer(traceOut, 'node'); | ||||||||||||||||||||||||||||||||
function coerceNode(attr, dflt) { | ||||||||||||||||||||||||||||||||
return Lib.coerce(nodeIn, nodeOut, attributes.node, attr, dflt); | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
coerceNode('label'); | ||||||||||||||||||||||||||||||||
coerceNode('pad'); | ||||||||||||||||||||||||||||||||
coerceNode('thickness'); | ||||||||||||||||||||||||||||||||
coerceNode('line.color'); | ||||||||||||||||||||||||||||||||
coerceNode('line.width'); | ||||||||||||||||||||||||||||||||
coerceNode('hoverinfo'); | ||||||||||||||||||||||||||||||||
handleHoverLabelDefaults(nodeIn, nodeOut, coerceNode, layout.hoverlabel); | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
var colors = layout.colorway; | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
var defaultNodePalette = function(i) {return colors[i % colors.length];}; | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
coerce('node.color', traceOut.node.label.map(function(d, i) { | ||||||||||||||||||||||||||||||||
coerceNode('color', nodeOut.label.map(function(d, i) { | ||||||||||||||||||||||||||||||||
return Color.addOpacity(defaultNodePalette(i), 0.8); | ||||||||||||||||||||||||||||||||
})); | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
coerce('link.label'); | ||||||||||||||||||||||||||||||||
coerce('link.source'); | ||||||||||||||||||||||||||||||||
coerce('link.target'); | ||||||||||||||||||||||||||||||||
coerce('link.value'); | ||||||||||||||||||||||||||||||||
coerce('link.line.color'); | ||||||||||||||||||||||||||||||||
coerce('link.line.width'); | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
coerce('link.color', traceOut.link.value.map(function() { | ||||||||||||||||||||||||||||||||
return tinycolor(layout.paper_bgcolor).getLuminance() < 0.333 ? | ||||||||||||||||||||||||||||||||
'rgba(255, 255, 255, 0.6)' : | ||||||||||||||||||||||||||||||||
'rgba(0, 0, 0, 0.2)'; | ||||||||||||||||||||||||||||||||
// link attributes | ||||||||||||||||||||||||||||||||
var linkIn = traceIn.link, linkOut = Template.newContainer(traceOut, 'link'); | ||||||||||||||||||||||||||||||||
function coerceLink(attr, dflt) { | ||||||||||||||||||||||||||||||||
return Lib.coerce(linkIn, linkOut, attributes.link, attr, dflt); | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
coerceLink('label'); | ||||||||||||||||||||||||||||||||
coerceLink('source'); | ||||||||||||||||||||||||||||||||
coerceLink('target'); | ||||||||||||||||||||||||||||||||
coerceLink('value'); | ||||||||||||||||||||||||||||||||
coerceLink('line.color'); | ||||||||||||||||||||||||||||||||
coerceLink('line.width'); | ||||||||||||||||||||||||||||||||
coerceLink('hoverinfo'); | ||||||||||||||||||||||||||||||||
handleHoverLabelDefaults(linkIn, linkOut, coerceLink, layout.hoverlabel); | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
var defaultLinkColor = tinycolor(layout.paper_bgcolor).getLuminance() < 0.333 ? | ||||||||||||||||||||||||||||||||
'rgba(255, 255, 255, 0.6)' : | ||||||||||||||||||||||||||||||||
'rgba(0, 0, 0, 0.2)'; | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
coerceLink('color', linkOut.value.map(function() { | ||||||||||||||||||||||||||||||||
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. For the next time you're working in these files @antoinerg, here's Lines 167 to 181 in 7ae6fd6
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. Good to know about the existence |
||||||||||||||||||||||||||||||||
return defaultLinkColor; | ||||||||||||||||||||||||||||||||
})); | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
handleDomainDefaults(traceOut, layout, coerce); | ||||||||||||||||||||||||||||||||
|
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.
Oh so, trace-level
hoverinfo
is no longer available for sankey traces? Luckily it never worked so this isn't breaking change.Does this PR close #3097 ?
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.
It wouldn't close it.
Issue #3097 is about supporting
hoverinfo
options other than the basicskip
andnone
. Although the current doc say that we support many:none actually worked except
all
. This PR is solely about adding support forskip
andnone
. Those two are arguably more urgent to support (ie. whether to hide the hoverlabels and whether to emit hover events at the same time).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.
Good to know. Thanks!