Skip to content
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 event and test for updatemenus events #1128

Merged
merged 2 commits into from
Nov 9, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/components/updatemenus/draw.js
Original file line number Diff line number Diff line change
@@ -299,6 +299,8 @@ function drawButtons(gd, gHeader, gButton, menuOpts) {
setActive(gd, menuOpts, buttonOpts, gHeader, gButton, buttonIndex);

Plots.executeAPICommand(gd, buttonOpts.method, buttonOpts.args);

gd.emit('plotly_buttonclicked', {menu: menuOpts, button: buttonOpts, active: menuOpts.active});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some people have been asking for an event on legend item click.

I'm not suggesting we should have a lone event for updatemenu button click and legend item click, but we should make sure the event names are consistent.

I'm thinking plotly_buttonclicked and plotly_legendclick, unless someone find the two confusing.

});

button.on('mouseover', function() {
25 changes: 25 additions & 0 deletions test/jasmine/tests/updatemenus_test.js
Original file line number Diff line number Diff line change
@@ -380,6 +380,31 @@ describe('update menus interactions', function() {
});
});

it('should emit an event on button click', function(done) {
var clickCnt = 0;
var data = [];
gd.on('plotly_buttonclicked', function(datum) {
data.push(datum);
clickCnt++;
});

click(selectHeader(0)).then(function() {
expect(clickCnt).toEqual(0);

return click(selectButton(2));
}).then(function() {
expect(clickCnt).toEqual(1);
expect(data.length).toEqual(1);
expect(data[0].active).toEqual(2);

return click(selectButton(1));
}).then(function() {
expect(clickCnt).toEqual(2);
expect(data.length).toEqual(2);
expect(data[1].active).toEqual(1);
}).catch(fail).then(done);
});

it('should apply update on button click', function(done) {
var header0 = selectHeader(0),
header1 = selectHeader(1);