10000 Introducing layout update menus (aka dropdowns) by etpinard · Pull Request #770 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content

Introducing layout update menus (aka dropdowns) #770

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

Merged
merged 17 commits into from
Aug 3, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
improve object constancy approach:
- the '_index' field now corresponds to the menu index
  in the user layout update menu container.
  This is a more 'consistent' field than e.g. the index in the menuData.
- the '_index' field is set at the default step
  -> no need to rely on relinkPrivateKeys.
  • Loading branch information
etpinard committed Aug 3, 2016
commit 361025385ff53a21d79b5d6961529f36b4d1ccaa
6 changes: 6 additions & 0 deletions src/components/updatemenus/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ module.exports = function updateMenusDefaults(layoutIn, layoutOut) {
menuOut = {};

menuDefaults(menuIn, menuOut, layoutOut);

// used on button click to update the 'active' field
menuOut._input = menuIn;

// used to determine object constancy
menuOut._index = i;

contOut.push(menuOut);
}
};
Expand Down
14 changes: 5 additions & 9 deletions src/components/updatemenus/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,28 +125,24 @@ module.exports = function draw(gd) {

function makeMenuData(fullLayout) {
var contOpts = fullLayout[constants.name],
menuData = [],
cnt = 0;
menuData = [];

// Filter visible dropdowns and attach '_index' to each
// fullLayout options object to be used for 'object constancy'
// in the data join key function.
//
// Note that '_index' is relinked from update to update via
// Plots.supplyDefaults.

for(var i = 0; i < contOpts.length; i++) {
var item = contOpts[i];

if(item.visible) {
if(!item._index) item._index = cnt++;
menuData.push(item);
}
if(item.visible) menuData.push(item);
}

return menuData;
}

// Note that '_index' is set at the default step,
// it corresponds to the menu index in the user layout update menu container.
// This is a more 'consistent' field than e.g. the index in the menuData.
function keyFunction(opts) {
return opts._index;
}
Expand Down
21 changes: 21 additions & 0 deletions test/jasmine/tests/updatemenus_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,27 @@ describe('update menus interactions', function() {
expect(gd._fullLayout._pushmargin['updatemenu-0']).toBeUndefined();
expect(gd._fullLayout._pushmargin['updatemenu-1']).toBeUndefined();

return Plotly.relayout(gd, {
'updatemenus[2]': {
buttons: [{
method: 'relayout',
args: ['title', 'new title']
}]
}
});
}).then(function() {
assertMenus([0]);
expect(gd._fullLayout._pushmargin['updatemenu-0']).toBeUndefined();
expect(gd._fullLayout._pushmargin['updatemenu-1']).toBeUndefined();
expect(gd._fullLayout._pushmargin['updatemenu-2']).toBeDefined();

return Plotly.relayout(gd, 'updatemenus[0].visible', true);
}).then(function() {
assertMenus([0, 0]);
expect(gd._fullLayout._pushmargin['updatemenu-0']).toBeDefined();
expect(gd._fullLayout._pushmargin['updatemenu-1']).toBeUndefined();
expect(gd._fullLayout._pushmargin['updatemenu-2']).toBeDefined();

done();
});
});
Expand Down
0