-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Common interface to interpret and execute API methods #1016
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 11 commits
f2d268d
65f618d
7ef0404
edb6773
f50fcaa
60dd634
4bc8387
93b8253
43dc3d4
65d24f3
d2696e7
7db7f03
57fcf96
7db5f1f
26ad1ff
986b4dc
20ac69f
f993ed7
99d7c8e
f8c0094
6abec15
5df94a7
d35ee35
a554cad
e5a80ee
45717b1
52de9e4
0c40b02
df2d5bb
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 |
---|---|---|
|
@@ -21,7 +21,6 @@ var anchorUtils = require('../legend/anchor_utils'); | |
|
||
var constants = require('./constants'); | ||
|
||
|
||
module.exports = function draw(gd) { | ||
var fullLayout = gd._fullLayout, | ||
menuData = makeMenuData(fullLayout); | ||
|
@@ -115,6 +114,13 @@ module.exports = function draw(gd) { | |
headerGroups.each(function(menuOpts) { | ||
var gHeader = d3.select(this); | ||
|
||
if(!menuOpts._commandObserver) { | ||
var _gButton = menuOpts.type === 'dropdown' ? gButton : null; | ||
menuOpts._commandObserver = Plots.createCommandObserver(gd, menuOpts.buttons, function(data) { | ||
setActive(gd, menuOpts, menuOpts.buttons[data.index], gHeader, _gButton, data.index, true); | ||
}); | ||
} | ||
|
||
if(menuOpts.type === 'dropdown') { | ||
drawHeader(gd, gHeader, gButton, menuOpts); | ||
|
||
|
@@ -293,17 +299,7 @@ function drawButtons(gd, gHeader, gButton, menuOpts) { | |
.call(setItemPosition, menuOpts, posOpts); | ||
|
||
button.on('click', function() { | ||
// update 'active' attribute in menuOpts | ||
menuOpts._input.active = menuOpts.active = buttonIndex; | ||
|
||
// fold up buttons and redraw header | ||
gButton.attr(constants.menuIndexAttrName, '-1'); | ||
|
||
if(menuOpts.type === 'dropdown') { | ||
drawHeader(gd, gHeader, gButton, menuOpts); | ||
} | ||
|
||
drawButtons(gd, gHeader, gButton, menuOpts); | ||
setActive(gd, menuOpts, buttonOpts, gHeader, gButton, buttonIndex); | ||
|
||
// call button method | ||
var args = buttonOpts.args; | ||
|
@@ -326,6 +322,22 @@ function drawButtons(gd, gHeader, gButton, menuOpts) { | |
Lib.setTranslate(gButton, menuOpts.lx, menuOpts.ly); | ||
} | ||
|
||
function setActive(gd, menuOpts, buttonOpts, gHeader, gButton, buttonIndex, isSilentUpdate) { | ||
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. nice abstraction |
||
// update 'active' attribute in menuOpts | ||
menuOpts._input.active = menuOpts.active = buttonIndex; | ||
|
||
if(menuOpts.type === 'dropdown') { | ||
// fold up buttons and redraw header | ||
gButton.attr(constants.menuIndexAttrName, '-1'); | ||
|
||
drawHeader(gd, gHeader, gButton, menuOpts); | ||
} | ||
|
||
if(!isSilentUpdate || menuOpts.type === 'buttons') { | ||
drawButtons(gd, gHeader, gButton, menuOpts); | ||
} | ||
} | ||
|
||
function drawItem(item, menuOpts, itemOpts) { | ||
item.call(drawItemRect, menuOpts) | ||
.call(drawItemText, menuOpts, itemOpts); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1204,6 +1204,7 @@ Plotly.restyle = function restyle(gd, astr, val, traces) { | |
|
||
return plotDone.then(function() { | ||
gd.emit('plotly_restyle', specs.eventData); | ||
gd.emit('plotly_plotmodified'); | ||
return gd; | ||
}); | ||
}; | ||
|
@@ -1710,6 +1711,7 @@ Plotly.relayout = function relayout(gd, astr, val) { | |
|
||
return plotDone.then(function() { | ||
gd.emit('plotly_relayout', specs.eventData); | ||
gd.emit('plotly_plotmodified'); | ||
return gd; | ||
}); | ||
}; | ||
|
@@ -2124,6 +2126,7 @@ Plotly.update = function update(gd, traceUpdate, layoutUpdate, traces) { | |
data: restyleSpecs.eventData, | ||
layout: relayoutSpecs.eventData | ||
}); | ||
gd.emit('plotly_plotmodified'); | ||
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. why not just subscribe to the existing 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. Didn't know about it! Just need to add that event in a couple more places, but that should be perfect. 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, other reason, now that I think about it: Should afterplot be emitted between frames? The exact sequence definitely matters, so the other logic was that a unique event would free us from tight coupling. 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.
Hmm. Very good question. I'd say no. 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. Do you think it should be a separate event for this purpose? Again, my fear was coupling the component update code with events that serve other purposes. But I can try to use 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 have no strong opinion here. I'll leave it up to you. |
||
|
||
return gd; | ||
}); | ||
|
@@ -2302,6 +2305,8 @@ Plotly.animate = function(gd, frameOrGroupNameOrFrameList, animationOpts) { | |
var newFrame = trans._currentFrame = trans._frameQueue.shift(); | ||
|
||
if(newFrame) { | ||
gd._fullLayout._currentFrame = newFrame.name; | ||
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. Very nice. I'll use that for |
||
|
||
gd.emit('plotly_animatingframe', { | ||
name: newFrame.name, | ||
frame: newFrame.frame, | ||
|
@@ -2324,6 +2329,8 @@ Plotly.animate = function(gd, frameOrGroupNameOrFrameList, animationOpts) { | |
newFrame.frameOpts, | ||
newFrame.transitionOpts | ||
); | ||
|
||
gd.emit('plotly_plotmodified'); | ||
} else { | ||
// If there are no more frames, then stop the RAF loop: | ||
stopAnimationLoop(); | ||
|
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.
@rreusser if I understand correctly,
_commandObserver
:relinkPrivateKeys
in supply-defaults on updatemenuOpts.buttons
is modified e.g. viaPlotly.relayout(gd, 'updatemenus[0].buttons[0].label', 'new label');