Skip to content

Commit db225cd

Browse files
committed
declare bounds object
1 parent 85f838c commit db225cd

File tree

6 files changed

+71
-75
lines changed

6 files changed

+71
-75
lines changed

draftlogs/6339_add.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Add bounds to mapbox suplots [[6339](https://github.com/plotly/plotly.js/pull/6339)]

src/plots/mapbox/layout_attributes.js

+29-27
Original file line numberDiff line numberDiff line change
@@ -95,33 +95,35 @@ var attrs = module.exports = overrideAll({
9595
].join(' ')
9696
},
9797

98-
westbound: {
99-
valType: 'number',
100-
description: [
101-
'Sets the minimum longitude of the map (in degrees East)',
102-
'if `eastbound`, `southbound` and `northbound` are declared.'
103-
].join(' ')
104-
},
105-
eastbound: {
106-
valType: 'number',
107-
description: [
108-
'Sets the maximum longitude of the map (in degrees East)',
109-
'if `westbound`, `southbound` and `northbound` are declared.'
110-
].join(' ')
111-
},
112-
southbound: {
113-
valType: 'number',
114-
description: [
115-
'Sets the minimum latitude of the map (in degrees North)',
116-
'if `eastbound`, `westbound` and `northbound` are declared.'
117-
].join(' ')
118-
},
119-
northbound: {
120-
valType: 'number',
121-
description: [
122-
'Sets the maximum latitude of the map (in degrees North)',
123-
'if `eastbound`, `westbound` and `southbound` are declared.'
124-
].join(' ')
98+
bounds: {
99+
west: {
100+
valType: 'number',
101+
description: [
102+
'Sets the minimum longitude of the map (in degrees East)',
103+
'if `east`, `south` and `north` are declared.'
104+
].join(' ')
105+
},
106+
east: {
107+
valType: 'number',
108+
description: [
109+
'Sets the maximum longitude of the map (in degrees East)',
110+
'if `west`, `south` and `north` are declared.'
111+
].join(' ')
112+
},
113+
south: {
114+
valType: 'number',
115+
description: [
116+
'Sets the minimum latitude of the map (in degrees North)',
117+
'if `east`, `west` and `north` are declared.'
118+
].join(' ')
119+
},
120+
north: {
121+
valType: 'number',
122+
description: [
123+
'Sets the maximum latitude of the map (in degrees North)',
124+
'if `east`, `west` and `south` are declared.'
125+
].join(' ')
126+
}
125127
},
126128

127129
layers: templatedArray('layer', {

src/plots/mapbox/layout_defaults.js

+9-12
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,17 @@ function handleDefaults(containerIn, containerOut, coerce, opts) {
2626
coerce('bearing');
2727
coerce('pitch');
2828

29-
var westbound = coerce('westbound');
30-
var eastbound = coerce('eastbound');
31-
var southbound = coerce('southbound');
32-
var northbound = coerce('northbound');
29+
var west = coerce('bounds.west');
30+
var east = coerce('bounds.east');
31+
var south = coerce('bounds.south');
32+
var north = coerce('bounds.north');
3333
if(
34-
westbound === undefined ||
35-
eastbound === undefined ||
36-
southbound === undefined ||
37-
northbound === undefined
34+
west === undefined ||
35+
east === undefined ||
36+
south === undefined ||
37+
north === undefined
3838
) {
39-
delete containerOut.westbound;
40-
delete containerOut.eastbound;
41-
delete containerOut.southbound;
42-
delete containerOut.northbound;
39+
delete containerOut.bounds;
4340
}
4441

4542
handleArrayContainerDefaults(containerIn, containerOut, {

src/plots/mapbox/mapbox.js

+2-12
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,8 @@ proto.createMap = function(calcData, fullLayout, resolve, reject) {
9191
// store access token associated with this map
9292
self.accessToken = opts.accesstoken;
9393

94-
var westbound = opts.westbound;
95-
var eastbound = opts.eastbound;
96-
var southbound = opts.southbound;
97-
var northbound = opts.northbound;
98-
var maxBounds = (
99-
/*
100-
westbound !== undefined &&
101-
eastbound !== undefined &&
102-
southbound !== undefined &&
103-
*/
104-
northbound !== undefined
105-
) ? [[westbound, southbound], [eastbound, northbound]] : null;
94+
var bounds = opts.bounds;
95+
var maxBounds = bounds ? [[bounds.west, bounds.south], [bounds.east, bounds.north]] : null;
10696

10797
// create the map!
10898
var map = self.map = new mapboxgl.Map({

test/image/mocks/mapbox_bubbles-text.json

+6-4
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@
3939
],
4040
"layout": {
4141
"mapbox": {
42-
"westbound": -60,
43-
"eastbound": 60,
44-
"southbound": -30,
45-
"northbound": 30,
42+
"bounds": {
43+
"west": -60,
44+
"east": 60,
45+
"south": -30,
46+
"north": 30
47+
},
4648
"style": "light",
4749
"zoom": 2.5,
4850
"center": {

test/plot-schema.json

+24-20
Original file line numberDiff line numberDiff line change
@@ -3006,6 +3006,30 @@
30063006
"editType": "plot",
30073007
"valType": "number"
30083008
},
3009+
"bounds": {
3010+
"east": {
3011+
"description": "Sets the maximum longitude of the map (in degrees East) if `west`, `south` and `north` are declared.",
3012+
"editType": "plot",
3013+
"valType": "number"
3014+
},
3015+
"editType": "plot",
3016+
"north": {
3017+
"description": "Sets the maximum latitude of the map (in degrees North) if `east`, `west` and `south` are declared.",
3018+
"editType": "plot",
3019+
"valType": "number"
3020+
},
3021+
"role": "object",
3022+
"south": {
3023+
"description": "Sets the minimum latitude of the map (in degrees North) if `east`, `west` and `north` are declared.",
3024+
"editType": "plot",
3025+
"valType": "number"
3026+
},
3027+
"west": {
3028+
"description": "Sets the minimum longitude of the map (in degrees East) if `east`, `south` and `north` are declared.",
3029+
"editType": "plot",
3030+
"valType": "number"
3031+
}
3032+
},
30093033
"center": {
30103034
"editType": "plot",
30113035
"lat": {
@@ -3086,11 +3110,6 @@
30863110
"valType": "info_array"
30873111
}
30883112
},
3089-
"eastbound": {
3090-
"description": "Sets the maximum longitude of the map (in degrees East) if `westbound`, `southbound` and `northbound` are declared.",
3091-
"editType": "plot",
3092-
"valType": "number"
3093-
},
30943113
"editType": "plot",
30953114
"layers": {
30963115
"items": {
@@ -3311,23 +3330,13 @@
33113330
},
33123331
"role": "object"
33133332
},
3314-
"northbound": {
3315-
"description": "Sets the maximum latitude of the map (in degrees North) if `eastbound`, `westbound` and `southbound` are declared.",
3316-
"editType": "plot",
3317-
"valType": "number"
3318-
},
33193333
"pitch": {
33203334
"description": "Sets the pitch angle of the map (in degrees, where *0* means perpendicular to the surface of the map) (mapbox.pitch).",
33213335
"dflt": 0,
33223336
"editType": "plot",
33233337
"valType": "number"
33243338
},
33253339
"role": "object",
3326-
"southbound": {
3327-
"description": "Sets the minimum latitude of the map (in degrees North) if `eastbound`, `westbound` and `northbound` are declared.",
3328-
"editType": "plot",
3329-
"valType": "number"
3330-
},
33313340
"style": {
33323341
"description": "Defines the map layers that are rendered by default below the trace layers defined in `data`, which are themselves by default rendered below the layers defined in `layout.mapbox.layers`. These layers can be defined either explicitly as a Mapbox Style object which can contain multiple layer definitions that load data from any public or private Tile Map Service (TMS or XYZ) or Web Map Service (WMS) or implicitly by using one of the built-in style objects which use WMSes which do not require any access tokens, or by using a default Mapbox style or custom Mapbox style URL, both of which require a Mapbox access token Note that Mapbox access token can be set in the `accesstoken` attribute or in the `mapboxAccessToken` config option. Mapbox Style objects are of the form described in the Mapbox GL JS documentation available at https://docs.mapbox.com/mapbox-gl-js/style-spec The built-in plotly.js styles objects are: carto-darkmatter, carto-positron, open-street-map, stamen-terrain, stamen-toner, stamen-watercolor, white-bg The built-in Mapbox styles are: basic, streets, outdoors, light, dark, satellite, satellite-streets Mapbox style URLs are of the form: mapbox://mapbox.mapbox-<name>-<version>",
33333342
"dflt": "basic",
@@ -3355,11 +3364,6 @@
33553364
"editType": "none",
33563365
"valType": "any"
33573366
},
3358-
"westbound": {
3359-
"description": "Sets the minimum longitude of the map (in degrees East) if `eastbound`, `southbound` and `northbound` are declared.",
3360-
"editType": "plot",
3361-
"valType": "number"
3362-
},
33633367
"zoom": {
33643368
"description": "Sets the zoom level of the map (mapbox.zoom).",
33653369
"dflt": 1,

0 commit comments

Comments
 (0)