Skip to content

Commit 76926d7

Browse files
committed
fix modebar logic and tests for select dragmodes
1 parent ca60e63 commit 76926d7

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

src/components/modebar/manage.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,19 @@ function getButtonGroups(fullLayout, buttonsToRemove, buttonsToAdd) {
9999

100100
var hasCartesian = fullLayout._hasCartesian,
101101
hasGL2D = fullLayout._hasGL2D,
102-
allAxesFixed = areAllAxesFixed(fullLayout);
102+
allAxesFixed = areAllAxesFixed(fullLayout),
103+
dragModeGroup = [];
104+
105+
if((hasCartesian || hasGL2D) && !allAxesFixed) {
106+
dragModeGroup = ['zoom2d', 'pan2d'];
107+
}
108+
if(hasCartesian) {
109+
dragModeGroup.push('select2d');
110+
dragModeGroup.push('lasso2d');
111+
}
112+
if(dragModeGroup.length) addGroup(dragModeGroup);
103113

104114
if((hasCartesian || hasGL2D) && !allAxesFixed) {
105-
addGroup(['zoom2d', 'pan2d', 'select2d', 'lasso2d']);
106115
addGroup(['zoomIn2d', 'zoomOut2d', 'autoScale2d', 'resetScale2d']);
107116
}
108117

test/jasmine/tests/modebar_test.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ describe('ModeBar', function() {
161161
it('creates mode bar (cartesian version)', function() {
162162
var buttons = getButtons([
163163
['toImage', 'sendDataToCloud'],
164-
['zoom2d', 'pan2d'],
164+
['zoom2d', 'pan2d', 'select2d', 'lasso2d'],
165165
['zoomIn2d', 'zoomOut2d', 'autoScale2d', 'resetScale2d'],
166166
['hoverClosestCartesian', 'hoverCompareCartesian']
167167
]);
@@ -175,13 +175,14 @@ describe('ModeBar', function() {
175175

176176
expect(modeBar.hasButtons(buttons)).toBe(true);
177177
expect(countGroups(modeBar)).toEqual(5);
178-
expect(countButtons(modeBar)).toEqual(11);
178+
expect(countButtons(modeBar)).toEqual(13);
179179
expect(countLogo(modeBar)).toEqual(1);
180180
});
181181

182182
it('creates mode bar (cartesian fixed-axes version)', function() {
183183
var buttons = getButtons([
184184
['toImage', 'sendDataToCloud'],
185+
['select2d', 'lasso2d'],
185186
['hoverClosestCartesian', 'hoverCompareCartesian']
186187
]);
187188

@@ -192,8 +193,8 @@ describe('ModeBar', function() {
192193
var modeBar = gd._fullLayout._modeBar;
193194

194195
expect(modeBar.hasButtons(buttons)).toBe(true);
195-
expect(countGroups(modeBar)).toEqual(3);
196-
expect(countButtons(modeBar)).toEqual(5);
196+
expect(countGroups(modeBar)).toEqual(4);
197+
expect(countButtons(modeBar)).toEqual(7);
197198
expect(countLogo(modeBar)).toEqual(1);
198199
});
199200

@@ -339,25 +340,32 @@ describe('ModeBar', function() {
339340
it('updates mode bar buttons if modeBarButtonsToRemove changes', function() {
340341
var gd = setupGraphInfo();
341342
manageModeBar(gd);
343+
var initialButtonCount = countButtons(gd._fullLayout._modeBar);
342344

343345
gd._context.modeBarButtonsToRemove = ['toImage', 'sendDataToCloud'];
344346
manageModeBar(gd);
345347

346-
expect(countButtons(gd._fullLayout._modeBar)).toEqual(9);
348+
expect(countButtons(gd._fullLayout._modeBar))
349+
.toEqual(initialButtonCount - 2);
347350
});
348351

349352
it('updates mode bar buttons if modeBarButtonsToAdd changes', function() {
350353
var gd = setupGraphInfo();
351354
manageModeBar(gd);
352355

356+
var initialGroupCount = countGroups(gd._fullLayout._modeBar),
357+
initialButtonCount = countButtons(gd._fullLayout._modeBar);
358+
353359
gd._context.modeBarButtonsToAdd = [{
354360
name: 'some button',
355361
click: noop
356362
}];
357363
manageModeBar(gd);
358364

359-
expect(countGroups(gd._fullLayout._modeBar)).toEqual(6);
360-
expect(countButtons(gd._fullLayout._modeBar)).toEqual(12);
365+
expect(countGroups(gd._fullLayout._modeBar))
366+
.toEqual(initialGroupCount + 1);
367+
expect(countButtons(gd._fullLayout._modeBar))
368+
.toEqual(initialButtonCount + 1);
361369
});
362370

363371
it('sets up buttons with modeBarButtonsToAdd and modeBarButtonToRemove', function() {
@@ -374,7 +382,7 @@ describe('ModeBar', function() {
374382

375383
var modeBar = gd._fullLayout._modeBar;
376384
expect(countGroups(modeBar)).toEqual(6);
377-
expect(countButtons(modeBar)).toEqual(10);
385+
expect(countButtons(modeBar)).toEqual(12);
378386
});
379387

380388
it('sets up buttons with modeBarButtonsToAdd and modeBarButtonToRemove (2)', function() {
@@ -394,7 +402,7 @@ describe('ModeBar', function() {
394402

395403
var modeBar = gd._fullLayout._modeBar;
396404
expect(countGroups(modeBar)).toEqual(7);
397-
expect(countButtons(modeBar)).toEqual(12);
405+
expect(countButtons(modeBar)).toEqual(14);
398406
});
399407

400408
it('sets up buttons with fully custom modeBarButtons', function() {

0 commit comments

Comments
 (0)