Skip to content

Commit 0efeb15

Browse files
committed
bring back mapbox in various places
1 parent 047ed33 commit 0efeb15

File tree

30 files changed

+34674
-29500
lines changed

30 files changed

+34674
-29500
lines changed

.circleci/test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ case $1 in
9595
make-baselines-virtual-webgl)
9696
SUITE=$({\
9797
find $ROOT/test/image/mocks/gl* -type f -printf "%f\n"; \
98+
find $ROOT/test/image/mocks/mapbox* -type f -printf "%f\n"; \
9899
find $ROOT/test/image/mocks/mapnew* -type f -printf "%f\n"; \
99100
} | sed 's/\.json$//1' | circleci tests split)
100101
python3 test/image/make_baseline.py virtual-webgl $SUITE || EXIT_STATE=$?

devtools/test_dashboard/devtools.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
var Fuse = require('fuse.js/dist/fuse.common.js');
66
var mocks = require('../../build/test_dashboard_mocks.json');
7+
var credentials = require('../../build/credentials.json');
78
var Lib = require('../../src/lib');
89

910
require('./perf');
@@ -18,6 +19,10 @@ var Tabs = {
1819
// use local topojson files
1920
topojsonURL: '../../node_modules/sane-topojson/dist/',
2021

22+
// register mapbox access token
23+
// run `npm run preset` if you haven't yet
24+
mapboxAccessToken: credentials.MAPBOX_ACCESS_TOKEN,
25+
2126
// show all logs in console
2227
logging: 2
2328
});

draftlogs/7015_change.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

lib/index-strict.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ Plotly.register([
3636
require('./heatmapgl'),
3737
require('../src/traces/parcoords/strict'),
3838
require('./parcats'),
39+
require('./scattermapbox'),
40+
require('./choroplethmapbox'),
41+
require('./densitymapbox'),
3942
require('./scattermapnew'),
4043
require('./choroplethmapnew'),
4144
require('./densitymapnew'),

lib/locales/si.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 303 additions & 52 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
"@plotly/d3": "3.8.2",
7575
"@plotly/d3-sankey": "0.7.2",
7676
"@plotly/d3-sankey-circular": "0.33.1",
77+
"@plotly/mapbox-gl": "1.13.4",
7778
"@turf/area": "^6.4.0",
7879
"@turf/bbox": "^6.4.0",
7980
"@turf/centroid": "^6.0.2",

src/components/fx/hover.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1561,7 +1561,11 @@ function getHoverLabelText(d, showCommonLabel, hovermode, fullLayout, t0, g) {
15611561
if(d.zLabel !== undefined) {
15621562
if(d.xLabel !== undefined) text += 'x: ' + d.xLabel + '<br>';
15631563
if(d.yLabel !== undefined) text += 'y: ' + d.yLabel + '<br>';
1564-
if(d.trace.type !== 'choropleth' && d.trace.type !== 'choroplethmapnew') {
1564+
if(
1565+
d.trace.type !== 'choropleth' &&
1566+
d.trace.type !== 'choroplethmapbox' &&
1567+
d.trace.type !== 'choroplethmapnew'
1568+
) {
15651569
text += (text ? 'z: ' : '') + d.zLabel;
15661570
}
15671571
} else if(showCommonLabel && d[h0 + 'Label'] === t0) {

src/components/fx/layout_defaults.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut) {
1919
var dragMode = coerce('dragmode');
2020
if(dragMode === 'select') coerce('selectdirection');
2121

22-
// if only mapnew or geo subplots is present on graph,
22+
// if only mapbox, mapnew or geo subplots is present on graph,
2323
// reset 'zoom' dragmode to 'pan' until 'zoom' is implemented,
2424
// so that the correct modebar button is active
25-
var hasMapnew = layoutOut._has('mapnew');
25+
var hasMap = layoutOut._has('mapbox') || layoutOut._has('mapnew');
2626
var hasGeo = layoutOut._has('geo');
2727
var len = layoutOut._basePlotModules.length;
2828

2929
if(layoutOut.dragmode === 'zoom' && (
30-
((hasMapnew || hasGeo) && len === 1) ||
31-
(hasMapnew && hasGeo && len === 2)
30+
((hasMap || hasGeo) && len === 1) ||
31+
(hasMap && hasGeo && len === 2)
3232
)) {
3333
layoutOut.dragmode = 'pan';
3434
}

src/components/legend/style.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,12 +541,14 @@ module.exports = function style(s, gd, legend) {
541541
useGradient = true;
542542
break;
543543
case 'choropleth' :
544+
case 'choroplethmapbox' :
544545
case 'choroplethmapnew' :
545546
ptsData = [
546547
['M-6,-6V6H6V-6Z']
547548
];
548549
useGradient = true;
549550
break;
551+
case 'densitymapbox' :
550552
case 'densitymapnew' :
551553
ptsData = [
552554
['M-6,0 a6,6 0 1,0 12,0 a 6,6 0 1,0 -12,0']

src/components/modebar/buttons.js

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,7 @@ modeBarButtons.resetViews = {
651651
handleCamera3d(gd, ev);
652652

653653
resetView(gd, 'geo');
654+
resetView(gd, 'mapbox');
654655
resetView(gd, 'mapnew');
655656
}
656657
};
@@ -684,6 +685,17 @@ function setSpikelineVisibility(gd) {
684685
return aobj;
685686
}
686687

688+
modeBarButtons.resetViewMapbox = {
689+
name: 'resetViewMapbox',
690+
_cat: 'resetView',
691+
title: function(gd) { return _(gd, 'Reset view'); },
692+
attr: 'reset',
693+
icon: Icons.home,
694+
click: function(gd) {
695+
resetView(gd, 'mapbox');
696+
}
697+
};
698+
687699
modeBarButtons.resetViewMapnew = {
688700
name: 'resetViewMapnew',
689701
_cat: 'resetView',
@@ -695,6 +707,16 @@ modeBarButtons.resetViewMapnew = {
695707
}
696708
};
697709

710+
modeBarButtons.zoomInMapbox = {
711+
name: 'zoomInMapbox',
712+
_cat: 'zoomin',
713+
title: function(gd) { return _(gd, 'Zoom in'); },
714+
attr: 'zoom',
715+
val: 'in',
716+
icon: Icons.zoom_plus,
717+
click: handleMapboxZoom
718+
};
719+
698720
modeBarButtons.zoomInMapnew = {
699721
name: 'zoomInMapnew',
700722
_cat: 'zoomin',
@@ -705,6 +727,16 @@ modeBarButtons.zoomInMapnew = {
705727
click: handleMapnewZoom
706728
};
707729

730+
modeBarButtons.zoomOutMapbox = {
731+
name: 'zoomOutMapbox',
732+
_cat: 'zoomout',
733+
title: function(gd) { return _(gd, 'Zoom out'); },
734+
attr: 'zoom',
735+
val: 'out',
736+
icon: Icons.zoom_minus,
737+
click: handleMapboxZoom
738+
};
739+
708740
modeBarButtons.zoomOutMapnew = {
709741
name: 'zoomOutMapnew',
710742
_cat: 'zoomout',
@@ -715,11 +747,19 @@ modeBarButtons.zoomOutMapnew = {
715747
click: handleMapnewZoom
716748
};
717749

750+
function handleMapboxZoom(gd, ev) {
751+
_handleMapZoom(gd, ev, 'mapbox');
752+
}
753+
718754
function handleMapnewZoom(gd, ev) {
755+
_handleMapZoom(gd, ev, 'mapnew');
756+
}
757+
758+
function _handleMapZoom(gd, ev, mapType) {
719759
var button = ev.currentTarget;
720760
var val = button.getAttribute('data-val');
721761
var fullLayout = gd._fullLayout;
722-
var subplotIds = fullLayout._subplots.mapnew || [];
762+
var subplotIds = fullLayout._subplots[mapType] || [];
723763
var scalar = 1.05;
724764
var aObj = {};
725765

src/components/modebar/manage.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ function getButtonGroups(gd) {
109109
var hasFunnelarea = fullLayout._has('funnelarea');
110110
var hasGL2D = fullLayout._has('gl2d');
111111
var hasTernary = fullLayout._has('ternary');
112+
var hasMapbox = fullLayout._has('mapbox');
112113
var hasMapnew = fullLayout._has('mapnew');
113114
var hasPolar = fullLayout._has('polar');
114115
var hasSmith = fullLayout._has('smith');
@@ -154,7 +155,7 @@ function getButtonGroups(gd) {
154155
var resetGroup = [];
155156
var dragModeGroup = [];
156157

157-
if((hasCartesian || hasGL2D || hasPie || hasFunnelarea || hasTernary) + hasGeo + hasGL3D + hasMapnew + hasPolar + hasSmith > 1) {
158+
if((hasCartesian || hasGL2D || hasPie || hasFunnelarea || hasTernary) + hasGeo + hasGL3D + hasMapbox + hasMapnew + hasPolar + hasSmith > 1) {
158159
// graphs with more than one plot types get 'union buttons'
159160
// which reset the view or toggle hover labels across all subplots.
160161
hoverGroup = ['toggleHover'];
@@ -166,6 +167,10 @@ function getButtonGroups(gd) {
166167
} else if(hasGL3D) {
167168
hoverGroup = ['hoverClosest3d'];
168169
resetGroup = ['resetCameraDefault3d', 'resetCameraLastSave3d'];
170+
} else if(hasMapbox) {
171+
zoomGroup = ['zoomInMapbox', 'zoomOutMapbox'];
172+
hoverGroup = ['toggleHover'];
173+
resetGroup = ['resetViewMapbox'];
169174
} else if(hasMapnew) {
170175
zoomGroup = ['zoomInMapnew', 'zoomOutMapnew'];
171176
hoverGroup = ['toggleHover'];
@@ -200,7 +205,7 @@ function getButtonGroups(gd) {
200205
dragModeGroup = ['zoom3d', 'pan3d', 'orbitRotation', 'tableRotation'];
201206
} else if(((hasCartesian || hasGL2D) && !allAxesFixed) || hasTernary) {
202207
dragModeGroup = ['zoom2d', 'pan2d'];
203-
} else if(hasMapnew || hasGeo) {
208+
} else if(hasMapbox || hasMapnew || hasGeo) {
204209
dragModeGroup = ['pan2d'];
205210
} else if(hasPolar) {
206211
dragModeGroup = ['zoom2d'];
@@ -228,7 +233,7 @@ function getButtonGroups(gd) {
228233
if(DRAW_MODES.indexOf(b) !== -1) {
229234
// accept pre-defined drag modes i.e. shape drawing features as string
230235
if(
231-
fullLayout._has('mapnew') || // draw shapes in paper coordinate (could be improved in future to support data coordinate, when there is no pitch)
236+
fullLayout._has('mapbox') || fullLayout._has('mapnew') || // draw shapes in paper coordinate (could be improved in future to support data coordinate, when there is no pitch)
232237
fullLayout._has('cartesian') // draw shapes in data coordinate
233238
) {
234239
dragModeGroup.push(b);

src/components/selections/select.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ function clearSelectionsCache(dragOptions, immediateSelect) {
752752
var selections;
753753
if(
754754
isSelectMode &&
755-
!hasSubplot(dragOptions) // only allow cartesian - no mapnew for now
755+
!hasSubplot(dragOptions) // only allow cartesian - no maps for now
756756
) {
757757
selections = newSelections(outlines, dragOptions);
758758
}
@@ -1549,7 +1549,7 @@ function getFillRangeItems(dragOptions) {
15491549
var plotinfo = dragOptions.plotinfo;
15501550

15511551
return (
1552-
plotinfo.fillRangeItems || // allow subplots (i.e. geo, mapnew, sankey) to override fillRangeItems routine
1552+
plotinfo.fillRangeItems || // allow subplots (i.e. geo, mapbox, mapnew, sankey) to override fillRangeItems routine
15531553
makeFillRangeItems(dragOptions.xaxes.concat(dragOptions.yaxes))
15541554
);
15551555
}

src/plot_api/plot_api.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ function setPlotContext(gd, config) {
517517
szOut.cartesian = 1;
518518
szOut.gl3d = 1;
519519
szOut.geo = 1;
520+
szOut.mapbox = 1;
520521
szOut.mapnew = 1;
521522
} else if(typeof szIn === 'string') {
522523
var parts = szIn.split('+');
@@ -526,6 +527,7 @@ function setPlotContext(gd, config) {
526527
} else if(szIn !== false) {
527528
szOut.gl3d = 1;
528529
szOut.geo = 1;
530+
szOut.mapbox = 1;
529531
szOut.mapnew = 1;
530532
}
531533
}
@@ -2387,6 +2389,7 @@ var layoutUIControlPatterns = [
23872389
{pattern: /^(ternary\d*\.[abc]axis)\.(min|title\.text)$/},
23882390
{pattern: /^(polar\d*\.radialaxis)\.((auto)?range|angle|title\.text)/},
23892391
{pattern: /^(polar\d*\.angularaxis)\.rotation/},
2392+
{pattern: /^(mapbox\d*)\.(center|zoom|bearing|pitch)/},
23902393
{pattern: /^(mapnew\d*)\.(center|zoom|bearing|pitch)/},
23912394

23922395
{pattern: /^legend\.(x|y)$/, attr: 'editrevision'},

src/plot_api/plot_config.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,12 @@ var configAttributes = {
157157

158158
scrollZoom: {
159159
valType: 'flaglist',
160-
flags: ['cartesian', 'gl3d', 'geo', 'mapnew'],
160+
flags: ['cartesian', 'gl3d', 'geo', 'mapbox', 'mapnew'],
161161
extras: [true, false],
162162
dflt: 'gl3d+geo+mapnew',
163163
description: [
164164
'Determines whether mouse wheel or two-finger scroll zooms is enable.',
165-
'Turned on by default for gl3d, geo and mapnew subplots',
165+
'Turned on by default for gl3d, geo, mapbox and mapnew subplots',
166166
'(as these subplot types do not have zoombox via pan),',
167167
'but turned off by default for cartesian subplots.',
168168
'Set `scrollZoom` to *false* to disable scrolling for all subplots.'
@@ -192,7 +192,7 @@ var configAttributes = {
192192
'This is the time interval (in ms) between first mousedown and',
193193
'2nd mouseup to constitute a double-click.',
194194
'This setting propagates to all on-subplot double clicks',
195-
'(except for geo and mapnew) and on-legend double clicks.'
195+
'(except for geo, mapbox and mapnew) and on-legend double clicks.'
196196
].join(' ')
197197
},
198198

@@ -382,6 +382,16 @@ var configAttributes = {
382382
].join(' ')
383383
},
384384

385+
mapboxAccessToken: {
386+
valType: 'string',
387+
dflt: null,
388+
description: [
389+
'Mapbox access token (required to plot mapbox trace types)',
390+
'If using an Mapbox Atlas server, set this option to \'\'',
391+
'so that plotly.js won\'t attempt to authenticate to the public Mapbox server.'
392+
].join(' ')
393+
},
394+
385395
logging: {
386396
valType: 'integer',
387397
min: 0,

src/plots/geo/geo.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ proto.updateFx = function(fullLayout, geoLayout) {
526526
}
527527

528528
if(clickMode.indexOf('event') > -1) {
529-
// TODO: like pie and mapnew, this doesn't support right-click
529+
// TODO: like pie and maps, this doesn't support right-click
530530
// actually this one is worse, as right-click starts a pan, or leaves
531531
// select in a weird state.
532532
// Also, only tangentially related, we should cancel hover during pan

src/plots/plots.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,8 @@ plots.supplyDefaults = function(gd, opts) {
326326

327327
var formatObj = getFormatObj(gd, d3FormatKeys);
328328

329+
// stash the token from context so mapbox subplots can use it as default
330+
newFullLayout._mapboxAccessToken = context.mapboxAccessToken;
329331

330332
// first fill in what we can of layout without looking at data
331333
// because fullData needs a few things from layout

src/registry.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var Loggers = require('./lib/loggers');
44
var noop = require('./lib/noop');
55
var pushUnique = require('./lib/push_unique');
66
var isPlainObject = require('./lib/is_plain_object');
7+
var addStyleRule = require('./lib/dom').addStyleRule;
78
var ExtendModule = require('./lib/extend');
89

910
var basePlotAttributes = require('./plots/attributes');
@@ -275,6 +276,14 @@ function registerTraceModule(_module) {
275276
var basePlotModule = _module.basePlotModule;
276277
var bpmName = basePlotModule.name;
277278

279+
// add mapbox-gl CSS here to avoid console warning on instantiation
280+
if(bpmName === 'mapbox') {
281+
var styleRules = basePlotModule.constants.styleRules;
282+
for(var k in styleRules) {
283+
addStyleRule('.js-plotly-plot .plotly .mapboxgl-' + k, styleRules[k]);
284+
}
285+
}
286+
278287
// add maplibre-gl CSS here to avoid console warning on instantiation
279288
if(bpmName === 'mapnew') {
280289
addCss('https://unpkg.com/maplibre-gl@^4.3.2/dist/maplibre-gl.css');
@@ -283,7 +292,7 @@ function registerTraceModule(_module) {
283292
// if `plotly-geo-assets.js` is not included,
284293
// add `PlotlyGeoAssets` global to stash references to all fetched
285294
// topojson / geojson data
286-
if((bpmName === 'geo' || bpmName === 'mapnew') &&
295+
if((bpmName === 'geo' || bpmName === 'mapbox' || bpmName === 'mapnew') &&
287296
(window.PlotlyGeoAssets === undefined)
288297
) {
289298
window.PlotlyGeoAssets = {topojson: {}};

src/snapshot/cloneplot.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ module.exports = function clonePlot(graphObj, options) {
5555
var oldLayout = graphObj.layout;
5656
var newData = extendDeep([], oldData);
5757
var newLayout = extendDeep({}, oldLayout, cloneLayoutOverride(options.tileClass));
58+
var context = graphObj._context || {};
5859

5960
if(options.width) newLayout.width = options.width;
6061
if(options.height) newLayout.height = options.height;
@@ -142,6 +143,7 @@ module.exports = function clonePlot(graphObj, options) {
142143
displaylogo: options.displaylogo || false,
143144
showLink: options.showLink || false,
144145
showTips: options.showTips || false,
146+
mapboxAccessToken: context.mapboxAccessToken
145147
}
146148
};
147149

src/snapshot/helpers.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ exports.getDelay = function(fullLayout) {
88
return (
99
fullLayout._has('gl3d') ||
1010
fullLayout._has('gl2d') ||
11+
fullLayout._has('mapbox') ||
1112
fullLayout._has('mapnew')
1213
) ? 500 : 0;
1314
};

0 commit comments

Comments
 (0)