-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Set unified hovermode via template #4669
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 all commits
2c76d79
3c883ff
9c07a91
11a4e27
3c47bf9
dc704ae
abf3a55
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* Copyright 2012-2020, 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'; | ||
|
||
var Lib = require('../../lib'); | ||
var layoutAttributes = require('./layout_attributes'); | ||
|
||
module.exports = function handleHoverModeDefaults(layoutIn, layoutOut, fullData) { | ||
function coerce(attr, dflt) { | ||
// don't coerce if it is already coerced in other place e.g. in cartesian defaults | ||
if(layoutOut[attr] !== undefined) return layoutOut[attr]; | ||
|
||
return Lib.coerce(layoutIn, layoutOut, layoutAttributes, attr, dflt); | ||
} | ||
|
||
var clickmode = coerce('clickmode'); | ||
|
||
var hovermodeDflt; | ||
if(layoutOut._has('cartesian')) { | ||
if(clickmode.indexOf('select') > -1) { | ||
hovermodeDflt = 'closest'; | ||
} else { | ||
// flag for 'horizontal' plots: | ||
// determines the state of the mode bar 'compare' hovermode button | ||
layoutOut._isHoriz = isHoriz(fullData, layoutOut); | ||
hovermodeDflt = layoutOut._isHoriz ? 'y' : 'x'; | ||
} | ||
} else hovermodeDflt = 'closest'; | ||
|
||
return coerce('hovermode', hovermodeDflt); | ||
}; | ||
|
||
function isHoriz(fullData, fullLayout) { | ||
var stackOpts = fullLayout._scatterStackOpts || {}; | ||
|
||
for(var i = 0; i < fullData.length; i++) { | ||
var trace = fullData[i]; | ||
var subplot = trace.xaxis + trace.yaxis; | ||
var subplotStackOpts = stackOpts[subplot] || {}; | ||
var groupOpts = subplotStackOpts[trace.stackgroup] || {}; | ||
|
||
if(trace.orientation !== 'h' && groupOpts.orientation !== 'h') { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -9,40 +9,24 @@ | |||||||||||||||
'use strict'; | ||||||||||||||||
|
||||||||||||||||
var Lib = require('../../lib'); | ||||||||||||||||
var isUnifiedHover = require('./helpers').isUnifiedHover; | ||||||||||||||||
var layoutAttributes = require('./layout_attributes'); | ||||||||||||||||
var handleHoverModeDefaults = require('./hovermode_defaults'); | ||||||||||||||||
|
||||||||||||||||
module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) { | ||||||||||||||||
function coerce(attr, dflt) { | ||||||||||||||||
return Lib.coerce(layoutIn, layoutOut, layoutAttributes, attr, dflt); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
var clickmode = coerce('clickmode'); | ||||||||||||||||
|
||||||||||||||||
var dragMode = coerce('dragmode'); | ||||||||||||||||
if(dragMode === 'select') coerce('selectdirection'); | ||||||||||||||||
|
||||||||||||||||
var hovermodeDflt; | ||||||||||||||||
if(layoutOut._has('cartesian')) { | ||||||||||||||||
if(clickmode.indexOf('select') > -1) { | ||||||||||||||||
hovermodeDflt = 'closest'; | ||||||||||||||||
} else { | ||||||||||||||||
// flag for 'horizontal' plots: | ||||||||||||||||
// determines the state of the mode bar 'compare' hovermode button | ||||||||||||||||
layoutOut._isHoriz = isHoriz(fullData, layoutOut); | ||||||||||||||||
hovermodeDflt = layoutOut._isHoriz ? 'y' : 'x'; | ||||||||||||||||
} | ||||||||||||||||
} else hovermodeDflt = 'closest'; | ||||||||||||||||
|
||||||||||||||||
var hoverMode = coerce('hovermode', hovermodeDflt); | ||||||||||||||||
var hoverMode = handleHoverModeDefaults(layoutIn, layoutOut, fullData); | ||||||||||||||||
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. We talked about short-circuiting this one, right? something like: var hoverMode = layoutOut.hovermode;
if (hoverMode === undefined) {
hoverMode = handleHoverModeDefaults(layoutIn, layoutOut, fullData);
} Is that a possibility? Or would that not work for some reason? 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.
plotly.js/src/components/fx/hovermode_defaults.js Lines 14 to 20 in abf3a55
|
||||||||||||||||
if(hoverMode) { | ||||||||||||||||
var dflt; | ||||||||||||||||
if(['x unified', 'y unified'].indexOf(hoverMode) !== -1) { | ||||||||||||||||
dflt = -1; | ||||||||||||||||
} | ||||||||||||||||
coerce('hoverdistance'); | ||||||||||||||||
coerce('spikedistance', dflt); | ||||||||||||||||
coerce('spikedistance', isUnifiedHover(hoverMode) ? -1 : undefined); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
var dragMode = coerce('dragmode'); | ||||||||||||||||
if(dragMode === 'select') coerce('selectdirection'); | ||||||||||||||||
|
||||||||||||||||
// if only mapbox or geo subplots is present on graph, | ||||||||||||||||
// reset 'zoom' dragmode to 'pan' until 'zoom' is implemented, | ||||||||||||||||
// so that the correct modebar button is active | ||||||||||||||||
|
@@ -57,20 +41,3 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) { | |||||||||||||||
layoutOut.dragmode = 'pan'; | ||||||||||||||||
} | ||||||||||||||||
}; | ||||||||||||||||
|
||||||||||||||||
function isHoriz(fullData, fullLayout) { | ||||||||||||||||
var stackOpts = fullLayout._scatterStackOpts || {}; | ||||||||||||||||
|
||||||||||||||||
for(var i = 0; i < fullData.length; i++) { | ||||||||||||||||
var trace = fullData[i]; | ||||||||||||||||
var subplot = trace.xaxis + trace.yaxis; | ||||||||||||||||
var subplotStackOpts = stackOpts[subplot] || {}; | ||||||||||||||||
var groupOpts = subplotStackOpts[trace.stackgroup] || {}; | ||||||||||||||||
|
||||||||||||||||
if(trace.orientation !== 'h' && groupOpts.orientation !== 'h') { | ||||||||||||||||
return false; | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
return true; | ||||||||||||||||
} |
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.
nonblocking, but at one point these names were useful in stack traces. That may or may not not be the case anymore, based on changes to our build and sourcemap processes... but historically that was the reason for names like this that are otherwise unused.