-
-
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 all 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 |
---|---|---|
|
@@ -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.manageCommandObserver(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); | ||
}); | ||
|
||
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.
much cleaner 🎉