Skip to content

Commit 4cbe129

Browse files
committed
Add link to migration guide to deprecation warning
1 parent 6a906bb commit 4cbe129

File tree

4 files changed

+86
-82
lines changed

4 files changed

+86
-82
lines changed

src/plots/mapbox/index.js

+67-66
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ exports.idRegex = exports.attrRegex = Lib.counterRegex(MAPBOX);
2727

2828
var deprecationWarning = [
2929
'mapbox subplots and traces are deprecated!',
30-
'Please consider switching to `map` subplots and traces.'
30+
'Please consider switching to `map` subplots and traces.',
31+
'Learn more at: https://plotly.com/javascript/maplibre-migration/'
3132
].join(' ');
3233

3334
exports.attributes = {
@@ -52,7 +53,7 @@ exports.supplyLayoutDefaults = require('./layout_defaults');
5253
var firstPlot = true;
5354

5455
exports.plot = function plot(gd) {
55-
if(firstPlot) {
56+
if (firstPlot) {
5657
firstPlot = false;
5758
Lib.warn(deprecationWarning);
5859
}
@@ -61,25 +62,25 @@ exports.plot = function plot(gd) {
6162
var calcData = gd.calcdata;
6263
var mapboxIds = fullLayout._subplots[MAPBOX];
6364

64-
if(mapboxgl.version !== constants.requiredVersion) {
65+
if (mapboxgl.version !== constants.requiredVersion) {
6566
throw new Error(constants.wrongVersionErrorMsg);
6667
}
6768

6869
var accessToken = findAccessToken(gd, mapboxIds);
6970
mapboxgl.accessToken = accessToken;
7071

71-
for(var i = 0; i < mapboxIds.length; i++) {
72+
for (var i = 0; i < mapboxIds.length; i++) {
7273
var id = mapboxIds[i];
7374
var subplotCalcData = getSubplotCalcData(calcData, MAPBOX, id);
7475
var opts = fullLayout[id];
7576
var mapbox = opts._subplot;
7677

77-
if(!mapbox) {
78+
if (!mapbox) {
7879
mapbox = new Mapbox(gd, id);
7980
fullLayout[id]._subplot = mapbox;
8081
}
8182

82-
if(!mapbox.viewInitial) {
83+
if (!mapbox.viewInitial) {
8384
mapbox.viewInitial = {
8485
center: Lib.extendFlat({}, opts.center),
8586
zoom: opts.zoom,
@@ -92,24 +93,24 @@ exports.plot = function plot(gd) {
9293
}
9394
};
9495

95-
exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout) {
96+
exports.clean = function (newFullData, newFullLayout, oldFullData, oldFullLayout) {
9697
var oldMapboxKeys = oldFullLayout._subplots[MAPBOX] || [];
9798

98-
for(var i = 0; i < oldMapboxKeys.length; i++) {
99+
for (var i = 0; i < oldMapboxKeys.length; i++) {
99100
var oldMapboxKey = oldMapboxKeys[i];
100101

101-
if(!newFullLayout[oldMapboxKey] && !!oldFullLayout[oldMapboxKey]._subplot) {
102+
if (!newFullLayout[oldMapboxKey] && !!oldFullLayout[oldMapboxKey]._subplot) {
102103
oldFullLayout[oldMapboxKey]._subplot.destroy();
103104
}
104105
}
105106
};
106107

107-
exports.toSVG = function(gd) {
108+
exports.toSVG = function (gd) {
108109
var fullLayout = gd._fullLayout;
109110
var subplotIds = fullLayout._subplots[MAPBOX];
110111
var size = fullLayout._size;
111112

112-
for(var i = 0; i < subplotIds.length; i++) {
113+
for (var i = 0; i < subplotIds.length; i++) {
113114
var opts = fullLayout[subplotIds[i]];
114115
var domain = opts.domain;
115116
var mapbox = opts._subplot;
@@ -131,84 +132,84 @@ exports.toSVG = function(gd) {
131132

132133
// Append logo if visible
133134
var hidden = subplotDiv.select('.mapboxgl-ctrl-logo').node().offsetParent === null;
134-
if(!hidden) {
135+
if (!hidden) {
135136
var logo = fullLayout._glimages.append('g');
136137
logo.attr('transform', strTranslate(size.l + size.w * domain.x[0] + 10, size.t + size.h * (1 - domain.y[0]) - 31));
137138
logo.append('path')
138-
.attr('d', constants.mapboxLogo.path0)
139-
.style({
140-
opacity: 0.9,
141-
fill: '#ffffff',
142-
'enable-background': 'new'
143-
});
139+
.attr('d', constants.mapboxLogo.path0)
140+
.style({
141+
opacity: 0.9,
142+
fill: '#ffffff',
143+
'enable-background': 'new'
144+
});
144145

145146
logo.append('path')
146-
.attr('d', constants.mapboxLogo.path1)
147-
.style('opacity', 0.35)
148-
.style('enable-background', 'new');
147+
.attr('d', constants.mapboxLogo.path1)
148+
.style('opacity', 0.35)
149+
.style('enable-background', 'new');
149150

150151
logo.append('path')
151-
.attr('d', constants.mapboxLogo.path2)
152-
.style('opacity', 0.35)
153-
.style('enable-background', 'new');
152+
.attr('d', constants.mapboxLogo.path2)
153+
.style('opacity', 0.35)
154+
.style('enable-background', 'new');
154155

155156
logo.append('polygon')
156-
.attr('points', constants.mapboxLogo.polygon)
157-
.style({
158-
opacity: 0.9,
159-
fill: '#ffffff',
160-
'enable-background': 'new'
161-
});
157+
.attr('points', constants.mapboxLogo.polygon)
158+
.style({
159+
opacity: 0.9,
160+
fill: '#ffffff',
161+
'enable-background': 'new'
162+
});
162163
}
163164

164165
// Add attributions
165166
var attributions = subplotDiv
166-
.select('.mapboxgl-ctrl-attrib').text()
167-
.replace('Improve this map', '');
167+
.select('.mapboxgl-ctrl-attrib').text()
168+
.replace('Improve this map', '');
168169

169170
var attributionGroup = fullLayout._glimages.append('g');
170171

171172
var attributionText = attributionGroup.append('text');
172173
attributionText
173-
.text(attributions)
174-
.classed('static-attribution', true)
175-
.attr({
176-
'font-size': 12,
177-
'font-family': 'Arial',
178-
color: 'rgba(0, 0, 0, 0.75)',
179-
'text-anchor': 'end',
180-
'data-unformatted': attributions
181-
});
174+
.text(attributions)
175+
.classed('static-attribution', true)
176+
.attr({
177+
'font-size': 12,
178+
'font-family': 'Arial',
179+
color: 'rgba(0, 0, 0, 0.75)',
180+
'text-anchor': 'end',
181+
'data-unformatted': attributions
182+
});
182183

183184
var bBox = Drawing.bBox(attributionText.node());
184185

185186
// Break into multiple lines twice larger than domain
186187
var maxWidth = size.w * (domain.x[1] - domain.x[0]);
187-
if((bBox.width > maxWidth / 2)) {
188+
if ((bBox.width > maxWidth / 2)) {
188189
var multilineAttributions = attributions.split('|').join('<br>');
189190
attributionText
190-
.text(multilineAttributions)
191-
.attr('data-unformatted', multilineAttributions)
192-
.call(svgTextUtils.convertToTspans, gd);
191+
.text(multilineAttributions)
192+
.attr('data-unformatted', multilineAttributions)
193+
.call(svgTextUtils.convertToTspans, gd);
193194

194195
bBox = Drawing.bBox(attributionText.node());
195196
}
196197
attributionText.attr('transform', strTranslate(-3, -bBox.height + 8));
197198

198199
// Draw white rectangle behind text
199200
attributionGroup
200-
.insert('rect', '.static-attribution')
201-
.attr({
202-
x: -bBox.width - 6,
203-
y: -bBox.height - 3,
204-
width: bBox.width + 6,
205-
height: bBox.height + 3,
206-
fill: 'rgba(255, 255, 255, 0.75)'
207-
});
201+
.insert('rect', '.static-attribution')
202+
.attr({
203+
x: -bBox.width - 6,
204+
y: -bBox.height - 3,
205+
width: bBox.width + 6,
206+
height: bBox.height + 3,
207+
fill: 'rgba(255, 255, 255, 0.75)'
208+
});
208209

209210
// Scale down if larger than domain
210211
var scaleRatio = 1;
211-
if((bBox.width + 6) > maxWidth) scaleRatio = maxWidth / (bBox.width + 6);
212+
if ((bBox.width + 6) > maxWidth) scaleRatio = maxWidth / (bBox.width + 6);
212213

213214
var offset = [(size.l + size.w * domain.x[1]), (size.t + size.h * (1 - domain.y[0]))];
214215
attributionGroup.attr('transform', strTranslate(offset[0], offset[1]) + strScale(scaleRatio));
@@ -222,7 +223,7 @@ function findAccessToken(gd, mapboxIds) {
222223
var context = gd._context;
223224

224225
// special case for Mapbox Atlas users
225-
if(context.mapboxAccessToken === '') return '';
226+
if (context.mapboxAccessToken === '') return '';
226227

227228
var tokensUseful = [];
228229
var tokensListed = [];
@@ -231,42 +232,42 @@ function findAccessToken(gd, mapboxIds) {
231232

232233
// Take the first token we find in a mapbox subplot.
233234
// These default to the context value but may be overridden.
234-
for(var i = 0; i < mapboxIds.length; i++) {
235+
for (var i = 0; i < mapboxIds.length; i++) {
235236
var opts = fullLayout[mapboxIds[i]];
236237
var token = opts.accesstoken;
237238

238-
if(isStyleRequireAccessToken(opts.style)) {
239-
if(token) {
239+
if (isStyleRequireAccessToken(opts.style)) {
240+
if (token) {
240241
Lib.pushUnique(tokensUseful, token);
241242
} else {
242-
if(isStyleRequireAccessToken(opts._input.style)) {
243+
if (isStyleRequireAccessToken(opts._input.style)) {
243244
Lib.error('Uses Mapbox map style, but did not set an access token.');
244245
hasOneSetMapboxStyle = true;
245246
}
246247
wontWork = true;
247248
}
248249
}
249250

250-
if(token) {
251+
if (token) {
251252
Lib.pushUnique(tokensListed, token);
252253
}
253254
}
254255

255-
if(wontWork) {
256+
if (wontWork) {
256257
var msg = hasOneSetMapboxStyle ?
257258
constants.noAccessTokenErrorMsg :
258259
constants.missingStyleErrorMsg;
259260
Lib.error(msg);
260261
throw new Error(msg);
261262
}
262263

263-
if(tokensUseful.length) {
264-
if(tokensUseful.length > 1) {
264+
if (tokensUseful.length) {
265+
if (tokensUseful.length > 1) {
265266
Lib.warn(constants.multipleTokensErrorMsg);
266267
}
267268
return tokensUseful[0];
268269
} else {
269-
if(tokensListed.length) {
270+
if (tokensListed.length) {
270271
Lib.log([
271272
'Listed mapbox access token(s)', tokensListed.join(','),
272273
'but did not use a Mapbox map style, ignoring token(s).'
@@ -284,11 +285,11 @@ function isStyleRequireAccessToken(s) {
284285
);
285286
}
286287

287-
exports.updateFx = function(gd) {
288+
exports.updateFx = function (gd) {
288289
var fullLayout = gd._fullLayout;
289290
var subplotIds = fullLayout._subplots[MAPBOX];
290291

291-
for(var i = 0; i < subplotIds.length; i++) {
292+
for (var i = 0; i < subplotIds.length; i++) {
292293
var subplotObj = fullLayout[subplotIds[i]]._subplot;
293294
subplotObj.updateFx(fullLayout);
294295
}

src/traces/choroplethmapbox/index.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
var deprecationWarning = [
44
'*choroplethmapbox* trace is deprecated!',
5-
'Please consider switching to the *choroplethmap* trace type and `map` subplots.'
5+
'Please consider switching to the *choroplethmap* trace type and `map` subplots.',
6+
'Learn more at: https://plotly.com/javascript/maplibre-migration/'
67
].join(' ');
78

89
module.exports = {
@@ -15,28 +16,28 @@ module.exports = {
1516
eventData: require('../choropleth/event_data'),
1617
selectPoints: require('../choropleth/select'),
1718

18-
styleOnSelect: function(_, cd) {
19-
if(cd) {
19+
styleOnSelect: function (_, cd) {
20+
if (cd) {
2021
var trace = cd[0].trace;
2122
trace._glTrace.updateOnSelect(cd);
2223
}
2324
},
2425

25-
getBelow: function(trace, subplot) {
26+
getBelow: function (trace, subplot) {
2627
var mapLayers = subplot.getMapLayers();
2728

2829
// find layer just above top-most "water" layer
2930
// that is not a plotly layer
30-
for(var i = mapLayers.length - 2; i >= 0; i--) {
31+
for (var i = mapLayers.length - 2; i >= 0; i--) {
3132
var layerId = mapLayers[i].id;
3233

33-
if(typeof layerId === 'string' &&
34+
if (typeof layerId === 'string' &&
3435
layerId.indexOf('water') === 0
35-
) {
36-
for(var j = i + 1; j < mapLayers.length; j++) {
36+
) {
37+
for (var j = i + 1; j < mapLayers.length; j++) {
3738
layerId = mapLayers[j].id;
3839

39-
if(typeof layerId === 'string' &&
40+
if (typeof layerId === 'string' &&
4041
layerId.indexOf('plotly-') === -1
4142
) {
4243
return layerId;

src/traces/densitymapbox/index.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
var deprecationWarning = [
44
'*densitymapbox* trace is deprecated!',
5-
'Please consider switching to the *densitymap* trace type and `map` subplots.'
5+
'Please consider switching to the *densitymap* trace type and `map` subplots.',
6+
'Learn more at: https://plotly.com/javascript/maplibre-migration/'
67
].join(' ');
78

89
module.exports = {
@@ -15,15 +16,15 @@ module.exports = {
1516
hoverPoints: require('./hover'),
1617
eventData: require('./event_data'),
1718

18-
getBelow: function(trace, subplot) {
19+
getBelow: function (trace, subplot) {
1920
var mapLayers = subplot.getMapLayers();
2021

2122
// find first layer with `type: 'symbol'`,
2223
// that is not a plotly layer
23-
for(var i = 0; i < mapLayers.length; i++) {
24+
for (var i = 0; i < mapLayers.length; i++) {
2425
var layer = mapLayers[i];
2526
var layerId = layer.id;
26-
if(layer.type === 'symbol' &&
27+
if (layer.type === 'symbol' &&
2728
typeof layerId === 'string' && layerId.indexOf('plotly-') === -1
2829
) {
2930
return layerId;

src/traces/scattermapbox/index.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
var deprecationWarning = [
44
'*scattermapbox* trace is deprecated!',
5-
'Please consider switching to the *scattermap* trace type and `map` subplots.'
5+
'Please consider switching to the *scattermap* trace type and `map` subplots.',
6+
'Learn more at: https://plotly.com/javascript/maplibre-migration/'
67
].join(' ');
78

89
module.exports = {
@@ -16,8 +17,8 @@ module.exports = {
1617
eventData: require('./event_data'),
1718
selectPoints: require('./select'),
1819

19-
styleOnSelect: function(_, cd) {
20-
if(cd) {
20+
styleOnSelect: function (_, cd) {
21+
if (cd) {
2122
var trace = cd[0].trace;
2223
trace._glTrace.update(cd);
2324
}

0 commit comments

Comments
 (0)