Skip to content

Commit e3aa07d

Browse files
committed
add dragmode pan button to mapbox modebar
- and set dragmode to 'pan' in fullLayout when its value is coerced to 'zoom' so the corresponding modebar button is correctly highlighted. - do this until dragmode 'zoom' (i.e. a zoombox like behavior) is implemented.
1 parent 744f3c8 commit e3aa07d

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

Diff for: src/components/fx/layout_defaults.js

+8
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
2828
else hovermodeDflt = 'closest';
2929

3030
coerce('hovermode', hovermodeDflt);
31+
32+
// if only mapbox subplots is present on graph,
33+
// reset 'zoom' dragmode to 'pan' until 'zoom' is implemented,
34+
// so that the correct modebar button is active
35+
if(layoutOut._has('mapbox') && layoutOut._basePlotModules.length === 1 &&
36+
layoutOut.dragmode === 'zoom') {
37+
layoutOut.dragmode = 'pan';
38+
}
3139
};
3240

3341
function isHoriz(fullData) {

Diff for: src/components/modebar/manage.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
var Axes = require('../../plots/cartesian/axes');
1313
var scatterSubTypes = require('../../traces/scatter/subtypes');
14+
var Registry = require('../../registry');
1415

1516
var createModeBar = require('./modebar');
1617
var modeBarButtons = require('./buttons');
@@ -78,7 +79,8 @@ function getButtonGroups(gd, buttonsToRemove, buttonsToAdd) {
7879
hasGeo = fullLayout._has('geo'),
7980
hasPie = fullLayout._has('pie'),
8081
hasGL2D = fullLayout._has('gl2d'),
81-
hasTernary = fullLayout._has('ternary');
82+
hasTernary = fullLayout._has('ternary'),
83+
hasMapbox = fullLayout._has('mapbox');
8284

8385
var groups = [];
8486

@@ -121,6 +123,9 @@ function getButtonGroups(gd, buttonsToRemove, buttonsToAdd) {
121123
if(((hasCartesian || hasGL2D) && !allAxesFixed) || hasTernary) {
122124
dragModeGroup = ['zoom2d', 'pan2d'];
123125
}
126+
if(hasMapbox) {
127+
dragModeGroup = ['pan2d'];
128+
}
124129
if(isSelectable(fullData)) {
125130
dragModeGroup.push('select2d');
126131
dragModeGroup.push('lasso2d');

Diff for: test/jasmine/tests/mapbox_test.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var Plotly = require('@lib');
2+
var Plots = require('@src/plots/plots');
23
var Lib = require('@src/lib');
34

45
var constants = require('@src/plots/mapbox/constants');
@@ -31,7 +32,7 @@ describe('mapbox defaults', function() {
3132
beforeEach(function() {
3233
layoutOut = { font: { color: 'red' } };
3334

34-
// needs a ternary-ref in a trace in order to be detected
35+
// needs a mapbox-ref in a trace in order to be detected
3536
fullData = [{ type: 'scattermapbox', subplot: 'mapbox' }];
3637
});
3738

@@ -170,6 +171,16 @@ describe('mapbox defaults', function() {
170171
expect(layoutOut.mapbox.layers[3].fill).toBeUndefined();
171172
expect(layoutOut.mapbox.layers[3].circle).toBeUndefined();
172173
});
174+
175+
it('should set *layout.dragmode* to pan while zoom is not available', function() {
176+
var gd = {
177+
data: fullData,
178+
layout: {}
179+
};
180+
181+
Plots.supplyDefaults(gd);
182+
expect(gd._fullLayout.dragmode).toBe('pan');
183+
});
173184
});
174185

175186
describe('mapbox credentials', function() {

0 commit comments

Comments
 (0)