Skip to content

Commit

Permalink
Merge pull request #7087 from plotly/deprecate-mapbox
Browse files Browse the repository at this point in the history
add deprecation warning for mapbox traces and mapbox subplot
  • Loading branch information
archmoj authored Aug 29, 2024
2 parents 0b70a9c + e609834 commit 39b5929
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 47 deletions.
1 change: 1 addition & 0 deletions draftlogs/7087_change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- deprecate mapbox traces and mapbox subplot [[#7087](https://github.com/plotly/plotly.js/pull/7087)]
94 changes: 54 additions & 40 deletions src/plots/mapbox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,19 @@ exports.idRoot = MAPBOX;

exports.idRegex = exports.attrRegex = Lib.counterRegex(MAPBOX);

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

exports.attributes = {
subplot: {
valType: 'subplotid',
dflt: 'mapbox',
editType: 'calc',
description: [
deprecationWarning,
'Sets a reference between this trace\'s data coordinates and',
'a mapbox subplot.',
'If *mapbox* (the default value), the data refer to `layout.mapbox`.',
Expand All @@ -43,7 +50,14 @@ exports.layoutAttributes = require('./layout_attributes');

exports.supplyLayoutDefaults = require('./layout_defaults');

var firstPlot = true;

exports.plot = function plot(gd) {
if(firstPlot) {
firstPlot = false;
Lib.warn(deprecationWarning);
}

var fullLayout = gd._fullLayout;
var calcData = gd.calcdata;
var mapboxIds = fullLayout._subplots[MAPBOX];
Expand Down Expand Up @@ -122,50 +136,50 @@ exports.toSVG = function(gd) {
var logo = fullLayout._glimages.append('g');
logo.attr('transform', strTranslate(size.l + size.w * domain.x[0] + 10, size.t + size.h * (1 - domain.y[0]) - 31));
logo.append('path')
.attr('d', constants.mapboxLogo.path0)
.style({
opacity: 0.9,
fill: '#ffffff',
'enable-background': 'new'
});
.attr('d', constants.mapboxLogo.path0)
.style({
opacity: 0.9,
fill: '#ffffff',
'enable-background': 'new'
});

logo.append('path')
.attr('d', constants.mapboxLogo.path1)
.style('opacity', 0.35)
.style('enable-background', 'new');
.attr('d', constants.mapboxLogo.path1)
.style('opacity', 0.35)
.style('enable-background', 'new');

logo.append('path')
.attr('d', constants.mapboxLogo.path2)
.style('opacity', 0.35)
.style('enable-background', 'new');
.attr('d', constants.mapboxLogo.path2)
.style('opacity', 0.35)
.style('enable-background', 'new');

logo.append('polygon')
.attr('points', constants.mapboxLogo.polygon)
.style({
opacity: 0.9,
fill: '#ffffff',
'enable-background': 'new'
});
.attr('points', constants.mapboxLogo.polygon)
.style({
opacity: 0.9,
fill: '#ffffff',
'enable-background': 'new'
});
}

// Add attributions
var attributions = subplotDiv
.select('.mapboxgl-ctrl-attrib').text()
.replace('Improve this map', '');
.select('.mapboxgl-ctrl-attrib').text()
.replace('Improve this map', '');

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

var attributionText = attributionGroup.append('text');
attributionText
.text(attributions)
.classed('static-attribution', true)
.attr({
'font-size': 12,
'font-family': 'Arial',
color: 'rgba(0, 0, 0, 0.75)',
'text-anchor': 'end',
'data-unformatted': attributions
});
.text(attributions)
.classed('static-attribution', true)
.attr({
'font-size': 12,
'font-family': 'Arial',
color: 'rgba(0, 0, 0, 0.75)',
'text-anchor': 'end',
'data-unformatted': attributions
});

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

Expand All @@ -174,24 +188,24 @@ exports.toSVG = function(gd) {
if((bBox.width > maxWidth / 2)) {
var multilineAttributions = attributions.split('|').join('<br>');
attributionText
.text(multilineAttributions)
.attr('data-unformatted', multilineAttributions)
.call(svgTextUtils.convertToTspans, gd);
.text(multilineAttributions)
.attr('data-unformatted', multilineAttributions)
.call(svgTextUtils.convertToTspans, gd);

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

// Draw white rectangle behind text
attributionGroup
.insert('rect', '.static-attribution')
.attr({
x: -bBox.width - 6,
y: -bBox.height - 3,
width: bBox.width + 6,
height: bBox.height + 3,
fill: 'rgba(255, 255, 255, 0.75)'
});
.insert('rect', '.static-attribution')
.attr({
x: -bBox.width - 6,
y: -bBox.height - 3,
width: bBox.width + 6,
height: bBox.height + 3,
fill: 'rgba(255, 255, 255, 0.75)'
});

// Scale down if larger than domain
var scaleRatio = 1;
Expand Down
9 changes: 8 additions & 1 deletion src/traces/choroplethmapbox/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
'use strict';

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

module.exports = {
attributes: require('./attributes'),
supplyDefaults: require('./defaults'),
Expand Down Expand Up @@ -27,7 +33,7 @@ module.exports = {

if(typeof layerId === 'string' &&
layerId.indexOf('water') === 0
) {
) {
for(var j = i + 1; j < mapLayers.length; j++) {
layerId = mapLayers[j].id;

Expand All @@ -48,6 +54,7 @@ module.exports = {
meta: {
hr_name: 'choropleth_mapbox',
description: [
deprecationWarning,
'GeoJSON features to be filled are set in `geojson`',
'The data that describes the choropleth value-to-color mapping',
'is set in `locations` and `z`.'
Expand Down
7 changes: 7 additions & 0 deletions src/traces/densitymapbox/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
'use strict';

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

module.exports = {
attributes: require('./attributes'),
supplyDefaults: require('./defaults'),
Expand Down Expand Up @@ -33,6 +39,7 @@ module.exports = {
meta: {
hr_name: 'density_mapbox',
description: [
deprecationWarning,
'Draws a bivariate kernel density estimation with a Gaussian kernel',
'from `lon` and `lat` coordinates and optional `z` values using a colorscale.'
].join(' ')
Expand Down
7 changes: 7 additions & 0 deletions src/traces/scattermapbox/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
'use strict';

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

module.exports = {
attributes: require('./attributes'),
supplyDefaults: require('./defaults'),
Expand All @@ -25,6 +31,7 @@ module.exports = {
meta: {
hrName: 'scatter_mapbox',
description: [
deprecationWarning,
'The data visualized as scatter point, lines or marker symbols',
'on a Mapbox GL geographic map',
'is provided by longitude/latitude pairs in `lon` and `lat`.'
Expand Down
12 changes: 6 additions & 6 deletions test/plot-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -29751,7 +29751,7 @@
}
},
"subplot": {
"description": "Sets a reference between this trace's data coordinates and a mapbox subplot. If *mapbox* (the default value), the data refer to `layout.mapbox`. If *mapbox2*, the data refer to `layout.mapbox2`, and so on.",
"description": "mapbox subplots and traces are deprecated! Please consider switching to `map` subplots and traces. Learn more at: https://plotly.com/javascript/maplibre-migration/ Sets a reference between this trace's data coordinates and a mapbox subplot. If *mapbox* (the default value), the data refer to `layout.mapbox`. If *mapbox2*, the data refer to `layout.mapbox2`, and so on.",
"dflt": "mapbox",
"editType": "calc",
"valType": "subplotid"
Expand Down Expand Up @@ -29865,7 +29865,7 @@
"showLegend"
],
"meta": {
"description": "GeoJSON features to be filled are set in `geojson` The data that describes the choropleth value-to-color mapping is set in `locations` and `z`.",
"description": "*choroplethmapbox* trace is deprecated! Please consider switching to the *choroplethmap* trace type and `map` subplots. Learn more at: https://plotly.com/javascript/maplibre-migration/ GeoJSON features to be filled are set in `geojson` The data that describes the choropleth value-to-color mapping is set in `locations` and `z`.",
"hr_name": "choropleth_mapbox"
},
"type": "choroplethmapbox"
Expand Down Expand Up @@ -37184,7 +37184,7 @@
}
},
"subplot": {
"description": "Sets a reference between this trace's data coordinates and a mapbox subplot. If *mapbox* (the default value), the data refer to `layout.mapbox`. If *mapbox2*, the data refer to `layout.mapbox2`, and so on.",
"description": "mapbox subplots and traces are deprecated! Please consider switching to `map` subplots and traces. Learn more at: https://plotly.com/javascript/maplibre-migration/ Sets a reference between this trace's data coordinates and a mapbox subplot. If *mapbox* (the default value), the data refer to `layout.mapbox`. If *mapbox2*, the data refer to `layout.mapbox2`, and so on.",
"dflt": "mapbox",
"editType": "calc",
"valType": "subplotid"
Expand Down Expand Up @@ -37282,7 +37282,7 @@
"showLegend"
],
"meta": {
"description": "Draws a bivariate kernel density estimation with a Gaussian kernel from `lon` and `lat` coordinates and optional `z` values using a colorscale.",
"description": "*densitymapbox* trace is deprecated! Please consider switching to the *densitymap* trace type and `map` subplots. Learn more at: https://plotly.com/javascript/maplibre-migration/ Draws a bivariate kernel density estimation with a Gaussian kernel from `lon` and `lat` coordinates and optional `z` values using a colorscale.",
"hr_name": "density_mapbox"
},
"type": "densitymapbox"
Expand Down Expand Up @@ -80422,7 +80422,7 @@
}
},
"subplot": {
"description": "Sets a reference between this trace's data coordinates and a mapbox subplot. If *mapbox* (the default value), the data refer to `layout.mapbox`. If *mapbox2*, the data refer to `layout.mapbox2`, and so on.",
"description": "mapbox subplots and traces are deprecated! Please consider switching to `map` subplots and traces. Learn more at: https://plotly.com/javascript/maplibre-migration/ Sets a reference between this trace's data coordinates and a mapbox subplot. If *mapbox* (the default value), the data refer to `layout.mapbox`. If *mapbox2*, the data refer to `layout.mapbox2`, and so on.",
"dflt": "mapbox",
"editType": "calc",
"valType": "subplotid"
Expand Down Expand Up @@ -80580,7 +80580,7 @@
"scatter-like"
],
"meta": {
"description": "The data visualized as scatter point, lines or marker symbols on a Mapbox GL geographic map is provided by longitude/latitude pairs in `lon` and `lat`.",
"description": "*scattermapbox* trace is deprecated! Please consider switching to the *scattermap* trace type and `map` subplots. Learn more at: https://plotly.com/javascript/maplibre-migration/ The data visualized as scatter point, lines or marker symbols on a Mapbox GL geographic map is provided by longitude/latitude pairs in `lon` and `lat`.",
"hrName": "scatter_mapbox"
},
"type": "scattermapbox"
Expand Down

0 comments on commit 39b5929

Please sign in to comment.