-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add spikelines #2247
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
Add spikelines #2247
Changes from 10 commits
132b5b2
85714e8
cd83ecf
006b55d
b14286b
e5875a9
37e419f
911ae0e
751d527
f562832
6c2f368
f56413a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,28 @@ module.exports = { | |
editType: 'modebar', | ||
description: 'Determines the mode of hover interactions.' | ||
}, | ||
|
||
hoverdistance: { | ||
valType: 'integer', | ||
min: 0, | ||
dflt: 20, | ||
role: 'style', | ||
editType: 'none', | ||
description: [ | ||
'Sets the default distance (in points) to look for data', | ||
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 usually write (in pixels) instead of (in points) in our attribute descriptions. |
||
'to add hover labels (zero means no cutoff)' | ||
].join(' ') | ||
}, | ||
spikedistance: { | ||
valType: 'integer', | ||
min: 0, | ||
dflt: 20, | ||
role: 'style', | ||
editType: 'none', | ||
description: [ | ||
'Sets the default distance (in points) to look for data to draw', | ||
'spikelines to (zero means no cutoff).' | ||
].join(' ') | ||
}, | ||
hoverlabel: { | ||
bgcolor: { | ||
valType: 'color', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,8 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) { | |
else hovermodeDflt = 'closest'; | ||
|
||
coerce('hovermode', hovermodeDflt); | ||
coerce('hoverdistance'); | ||
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 could get fancy here by making this: var hoverMode = coerce('hovermode', hovermodeDflt);
if(hoverDistance) coerce('hoverdistance'); as Unfortunately, we can't add similar logic for 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. Actually, we can, because if hovermode is false, we are not firing any hover events, so the spikelines are disabled too. var hoverMode = coerce('hovermode', hovermodeDflt);
if(hoverMode) {
coerce('hoverdistance');
coerce('spikedistance');
} 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 catch. Thanks! |
||
coerce('spikedistance'); | ||
|
||
// if only mapbox or geo subplots is present on graph, | ||
// reset 'zoom' dragmode to 'pan' until 'zoom' is implemented, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -237,9 +237,6 @@ function handleCartesian(gd, ev) { | |
if(astr === 'hovermode' && (val === 'x' || val === 'y')) { | ||
val = fullLayout._isHoriz ? 'y' : 'x'; | ||
button.setAttribute('data-val', val); | ||
if(val !== 'closest') { | ||
fullLayout._cartesianSpikesEnabled = 'off'; | ||
} | ||
} else if(astr === 'hovermode' && val === 'closest') { | ||
for(i = 0; i < axList.length; i++) { | ||
ax = axList[i]; | ||
|
@@ -551,12 +548,10 @@ modeBarButtons.toggleSpikelines = { | |
click: function(gd) { | ||
var fullLayout = gd._fullLayout; | ||
|
||
fullLayout._cartesianSpikesEnabled = fullLayout.hovermode === 'closest' ? | ||
(fullLayout._cartesianSpikesEnabled === 'on' ? 'off' : 'on') : 'on'; | ||
fullLayout._cartesianSpikesEnabled = fullLayout._cartesianSpikesEnabled === 'on' ? 'off' : 'on'; | ||
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. Done 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. Great. Thanks! Now, could you restore and update the |
||
|
||
var aobj = setSpikelineVisibility(gd); | ||
|
||
aobj.hovermode = 'closest'; | ||
Plotly.relayout(gd, aobj); | ||
} | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2048,7 +2048,7 @@ axes.doTicks = function(gd, axid, skipTitle) { | |
top: pos, | ||
bottom: pos, | ||
left: ax._offset, | ||
rigth: ax._offset + ax._length, | ||
right: ax._offset + ax._length, | ||
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 catch. Did this cause any bugs previously? 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. It did in one of my early implementations |
||
width: ax._length, | ||
height: 0 | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -387,6 +387,14 @@ module.exports = { | |
'plotted on' | ||
].join(' ') | ||
}, | ||
spikesnap: { | ||
valType: 'enumerated', | ||
values: ['data', 'cursor'], | ||
dflt: 'data', | ||
role: 'style', | ||
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. Though always debatable, all the new attributes you added should be 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. Thanks! Changed it for |
||
editType: 'none', | ||
description: 'Determines whether spikelines are stuck to the cursor or to the closest datapoints.' | ||
}, | ||
tickfont: fontAttrs({ | ||
editType: 'ticks', | ||
description: 'Sets the tick font.' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,6 +145,7 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) { | |
coerce('spikethickness'); | ||
coerce('spikedash'); | ||
coerce('spikemode'); | ||
coerce('spikesnap'); | ||
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. If you're interested, we should covert this 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. Thanks! Done. 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. Wow. Thanks for doing this! |
||
} | ||
|
||
var positioningOptions = { | ||
|
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.
As
Infinity
isn't JSON-serializable, we declare attributes of the likes (e.g.hoverlabel.namelength
) withmin: -1
, so that users can sethoverdistance: -1
for an infinite search radius. Morevover,hoverdistance: 0
should imply no hover labels/events, similarly forspikedistance
.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.
Thanks! Done.