-
-
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 24 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 |
---|---|---|
|
@@ -33,6 +33,8 @@ module.exports = function updateMenusDefaults(layoutIn, layoutOut) { | |
// used to determine object constancy | ||
menuOut._index = i; | ||
|
||
menuOut._input.active = menuOut.active; | ||
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. Why do we need 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. Without this, there's an intermediate state in which this value is updated when changes occur, but is I ran into this while testing: I checked this to see if the external value was updated when component interactions occurred. That worked fine, but before changes were made, the value was 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. Removed this line. |
||
|
||
contOut.push(menuOut); | ||
} | ||
}; | ||
|
@@ -48,7 +50,9 @@ function menuDefaults(menuIn, menuOut, layoutOut) { | |
var visible = coerce('visible', buttons.length > 0); | ||
if(!visible) return; | ||
|
||
coerce('active'); | ||
// Default to zero since active must be *something*: | ||
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 that's the case, we should add 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, good point. That works for me. I think that's best since 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. Oops. The default is set. Removing this. I think this may have been a change that I thought was necessary while debugging but ultimately did not need. 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. Hold on. The updatemenu 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 okay. Let me adjust on my end then. That makes sense. I guess it just bothered me that the first item is selected when the chart loads but the variable is not set. 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. Reverted updatemenus change and fixed sliders initialization + defaults to match the behavior. |
||
coerce('active', 0); | ||
|
||
coerce('direction'); | ||
coerce('type'); | ||
coerce('showactive'); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,6 @@ | |
|
||
var d3 = require('d3'); | ||
|
||
var Plotly = require('../../plotly'); | ||
var Plots = require('../../plots/plots'); | ||
var Lib = require('../../lib'); | ||
var Color = require('../color'); | ||
|
@@ -21,7 +20,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 +113,11 @@ module.exports = function draw(gd) { | |
headerGroups.each(function(menuOpts) { | ||
var gHeader = d3.select(this); | ||
|
||
var _gButton = menuOpts.type === 'dropdown' ? gButton : null; | ||
Plots.createCommandObserver(gd, menuOpts, 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,21 +296,9 @@ 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'); | ||
setActive(gd, menuOpts, buttonOpts, gHeader, gButton, buttonIndex); | ||
|
||
if(menuOpts.type === 'dropdown') { | ||
drawHeader(gd, gHeader, gButton, menuOpts); | ||
} | ||
|
||
drawButtons(gd, gHeader, gButton, menuOpts); | ||
|
||
// call button method | ||
var args = buttonOpts.args; | ||
Plotly[buttonOpts.method](gd, args[0], args[1], args[2]); | ||
Plots.executeAPICommand(gd, buttonOpts.method, buttonOpts.args); | ||
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. much cleaner 🎉 |
||
}); | ||
|
||
button.on('mouseover', function() { | ||
|
@@ -326,6 +317,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 |
---|---|---|
|
@@ -2302,14 +2302,7 @@ Plotly.animate = function(gd, frameOrGroupNameOrFrameList, animationOpts) { | |
var newFrame = trans._currentFrame = trans._frameQueue.shift(); | ||
|
||
if(newFrame) { | ||
gd.emit('plotly_animatingframe', { | ||
name: newFrame.name, | ||
frame: newFrame.frame, | ||
animation: { | ||
frame: newFrame.frameOpts, | ||
transition: newFrame.transitionOpts, | ||
} | ||
}); | ||
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 |
||
|
||
trans._lastFrameAt = Date.now(); | ||
trans._timeToNext = newFrame.frameOpts.duration; | ||
|
@@ -2324,6 +2317,15 @@ Plotly.animate = function(gd, frameOrGroupNameOrFrameList, animationOpts) { | |
newFrame.frameOpts, | ||
newFrame.transitionOpts | ||
); | ||
|
||
gd.emit('plotly_animatingframe', { | ||
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. @rreusser can you share some info about why the 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 are a lot of things taking place synchronously and asynchronously so that I wanted to move the event trigger as late as possible to ensure the changes have actually taken place in order to be picked up by bound components. I think maybe a better long-term solution is an event after 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 for the info 👍 |
||
name: newFrame.name, | ||
frame: newFrame.frame, | ||
animation: { | ||
frame: newFrame.frameOpts, | ||
transition: newFrame.transitionOpts, | ||
} | ||
}); | ||
} 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.
I'm big a fan of this new pattern here where one routine creates + updates command observer. This should make the command observer logic more easily reused in the future when we integrate it in other components 👍
One small suggestion, now that
createCommandObsever
can create and update a command observer, maybe we should rename it something likemanageCommandObserver
similar tomanageModebar
?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.
Sounds good. I was going to go with
createOrUpdateCommandObserver
, but that seemed excessive. Changing now.