Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mapbox-gl@1.0.0 + improvements #3987

Merged
merged 49 commits into from
Jul 4, 2019
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
2d4fe9b
bump mapbox-gl to 1.0.0 :tada:
etpinard May 17, 2019
95240e2
:hocho: clean navigation block
etpinard May 17, 2019
e0c684f
add missing .catch(failTest)
etpinard May 17, 2019
889abb6
adapt tests for mapbox-gl@v1
etpinard May 17, 2019
41d167f
adapt find-mapbox-access-token for maps that don't use Mapbox styles
etpinard May 17, 2019
1ee02da
mv DOM-related Lib function to src/lib/dom.js
etpinard May 29, 2019
5b43b8c
add mapbox-gl CSS when registering mapbox basePlotModule
etpinard May 17, 2019
a2d2522
modernize createMapbox API
etpinard May 30, 2019
1987b22
update mapbox baseline (using mapbox-gl@v1)
etpinard Jun 26, 2019
23ffe4f
add mapbox using OSM map raster style mock
etpinard Jun 26, 2019
43c568f
improve Choropleth.calc
etpinard Jun 18, 2019
91e0319
add dflt to choropleth marker.line.color
etpinard Jun 7, 2019
8fc1dbe
add choroplethmapbox attributes
etpinard Jun 4, 2019
70878b7
add `PlotlyGeoAssets` to window during Plotly.register
etpinard Jun 6, 2019
012a749
fetch GeoJSON URLs found in calcdata before updateData()
etpinard Jun 18, 2019
5d27983
introducing choroplethmapbox trace module
etpinard Jun 18, 2019
f7f3190
sort all choroplethmapbox traces below scattermapbox traces
etpinard Jun 18, 2019
4e88075
add GeoJSON feature 'properties' to eventData
etpinard Jun 18, 2019
a166761
improve mapbox hover after drag
etpinard Jun 18, 2019
9a602ba
first cut choroplethmapbox tests
etpinard Jun 18, 2019
a457722
allow numbers as *locations* items when using custom *geojson*
etpinard Jun 18, 2019
1359307
fixup choroplethmapbox hover content post-#3968
etpinard Jun 18, 2019
4d7e0aa
implement *below* in choroplethmapbox traces
etpinard Jun 26, 2019
cb202a8
add :three: choroplethmapbox mocks
etpinard Jun 26, 2019
e509047
mojtaba-proof a few things
etpinard Jun 27, 2019
7dd04e7
fixup choroplethmapbox "below" test
etpinard Jun 27, 2019
654c08e
do not coerce choropleth* marker.line.color
etpinard Jun 27, 2019
22c2a1e
add missing @gl tag to mapbox tests
etpinard Jun 27, 2019
fe6782d
add doNotFailOnEmptyTestSuite CLI option
etpinard Jun 27, 2019
7e15d81
add densitymapbox attributes
etpinard Jun 28, 2019
91a9bc4
implement densitymapbox
etpinard Jun 28, 2019
4f42d1b
add densitymapbox jasmine tests
etpinard Jun 28, 2019
4299857
add :three: densitymapbox mocks
etpinard Jun 28, 2019
1add90e
remove layers from last to first
etpinard Jun 28, 2019
36e3f06
add *open-street-map* `mapbox.style` value
etpinard Jun 28, 2019
ca48461
Merge pull request #3993 from plotly/densitymapbox-pr
etpinard Jun 28, 2019
a765249
raster support
Jun 2, 2019
7dcc506
fix syntax test
Jun 2, 2019
0c99017
do not decode raster source URL
etpinard Jul 2, 2019
153c6b4
add support for `sourcetype: 'image'` layers
etpinard Jul 2, 2019
54efdad
add some layer sourcetype -> type logic
etpinard Jul 2, 2019
0b17b62
add raster/raster and image/raster layers
etpinard Jul 2, 2019
f5bc2e4
bump mapbox-gl to 1.1.0
etpinard Jul 2, 2019
b69cf4b
Merge pull request #4006 from plotly/mapbox-raster-layer
etpinard Jul 2, 2019
6d7929c
Merge branch 'mapbox-v1' into choroplethmapbox-pr
etpinard Jul 3, 2019
eb04b4c
Merge pull request #3988 from plotly/choroplethmapbox-pr
etpinard Jul 3, 2019
a646575
Merge branch 'master' into mapbox-v1
etpinard Jul 3, 2019
8c48aa2
fixup package-lock
etpinard Jul 3, 2019
dfa4ec7
rm unnecessary --showSkipped CLI arg
etpinard Jul 3, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
369 changes: 99 additions & 270 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"glslify": "^7.0.0",
"has-hover": "^1.0.1",
"has-passive-events": "^1.0.0",
"mapbox-gl": "0.45.0",
"mapbox-gl": "1.0.0",
"matrix-camera-controller": "^2.1.3",
"mouse-change": "^1.4.0",
"mouse-event-offset": "^3.0.2",
Expand Down
5 changes: 1 addition & 4 deletions src/components/dragelement/unhover.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,16 @@
* LICENSE file in the root directory of this source tree.
*/


'use strict';


var Events = require('../../lib/events');
var throttle = require('../../lib/throttle');
var getGraphDiv = require('../../lib/get_graph_div');
var getGraphDiv = require('../../lib/dom').getGraphDiv;

var hoverConstants = require('../fx/constants');

var unhover = module.exports = {};


unhover.wrapped = function(gd, evt, subplot) {
gd = getGraphDiv(gd);

Expand Down
101 changes: 101 additions & 0 deletions src/lib/dom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/**
* Copyright 2012-2019, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

var d3 = require('d3');
var loggers = require('./loggers');

/**
* Allow referencing a graph DOM element either directly
* or by its id string
*
* @param {HTMLDivElement|string} gd: a graph element or its id
*
* @returns {HTMLDivElement} the DOM element of the graph
*/
function getGraphDiv(gd) {
var gdElement;

if(typeof gd === 'string') {
gdElement = document.getElementById(gd);

if(gdElement === null) {
throw new Error('No DOM element with id \'' + gd + '\' exists on the page.');
}

return gdElement;
} else if(gd === null || gd === undefined) {
throw new Error('DOM element provided is null or undefined');
}

// otherwise assume that gd is a DOM element
return gd;
}

function isPlotDiv(el) {
var el3 = d3.select(el);
return el3.node() instanceof HTMLElement &&
el3.size() &&
el3.classed('js-plotly-plot');
}

function removeElement(el) {
var elParent = el && el.parentNode;
if(elParent) elParent.removeChild(el);
}

/**
* for dynamically adding style rules
* makes one stylesheet that contains all rules added
* by all calls to this function
*/
function addStyleRule(selector, styleString) {
addRelatedStyleRule('global', selector, styleString);
}

/**
* for dynamically adding style rules
* to a stylesheet uniquely identified by a uid
*/
function addRelatedStyleRule(uid, selector, styleString) {
var id = 'plotly.js-style-' + uid;
var style = document.getElementById(id);
if(!style) {
style = document.createElement('style');
style.setAttribute('id', id);
// WebKit hack :(
style.appendChild(document.createTextNode(''));
document.head.appendChild(style);
}
var styleSheet = style.sheet;

if(styleSheet.insertRule) {
styleSheet.insertRule(selector + '{' + styleString + '}', 0);
} else if(styleSheet.addRule) {
styleSheet.addRule(selector, styleString, 0);
} else loggers.warn('addStyleRule failed');
}

/**
* to remove from the page a stylesheet identified by a given uid
*/
function deleteRelatedStyleRule(uid) {
var id = 'plotly.js-style-' + uid;
var style = document.getElementById(id);
if(style) removeElement(style);
}

module.exports = {
getGraphDiv: getGraphDiv,
isPlotDiv: isPlotDiv,
removeElement: removeElement,
addStyleRule: addStyleRule,
addRelatedStyleRule: addRelatedStyleRule,
deleteRelatedStyleRule: deleteRelatedStyleRule
};
35 changes: 0 additions & 35 deletions src/lib/get_graph_div.js

This file was deleted.

62 changes: 7 additions & 55 deletions src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* LICENSE file in the root directory of this source tree.
*/


'use strict';

var d3 = require('d3');
Expand Down Expand Up @@ -138,7 +137,13 @@ lib.throttle = throttleModule.throttle;
lib.throttleDone = throttleModule.done;
lib.clearThrottle = throttleModule.clear;

lib.getGraphDiv = require('./get_graph_div');
var domModule = require('./dom');
lib.getGraphDiv = domModule.getGraphDiv;
lib.isPlotDiv = domModule.isPlotDiv;
lib.removeElement = domModule.removeElement;
lib.addStyleRule = domModule.addStyleRule;
lib.addRelatedStyleRule = domModule.addRelatedStyleRule;
lib.deleteRelatedStyleRule = domModule.deleteRelatedStyleRule;

lib.clearResponsive = require('./clear_responsive');

Expand Down Expand Up @@ -676,59 +681,6 @@ lib.containsAny = function(s, fragments) {
return false;
};

lib.isPlotDiv = function(el) {
var el3 = d3.select(el);
return el3.node() instanceof HTMLElement &&
el3.size() &&
el3.classed('js-plotly-plot');
};

lib.removeElement = function(el) {
var elParent = el && el.parentNode;
if(elParent) elParent.removeChild(el);
};

/**
* for dynamically adding style rules
* makes one stylesheet that contains all rules added
* by all calls to this function
*/
lib.addStyleRule = function(selector, styleString) {
lib.addRelatedStyleRule('global', selector, styleString);
};

/**
* for dynamically adding style rules
* to a stylesheet uniquely identified by a uid
*/
lib.addRelatedStyleRule = function(uid, selector, styleString) {
var id = 'plotly.js-style-' + uid;
var style = document.getElementById(id);
if(!style) {
style = document.createElement('style');
style.setAttribute('id', id);
// WebKit hack :(
style.appendChild(document.createTextNode(''));
document.head.appendChild(style);
}
var styleSheet = style.sheet;

if(styleSheet.insertRule) {
styleSheet.insertRule(selector + '{' + styleString + '}', 0);
} else if(styleSheet.addRule) {
styleSheet.addRule(selector, styleString, 0);
} else lib.warn('addStyleRule failed');
};

/**
* to remove from the page a stylesheet identified by a given uid
*/
lib.deleteRelatedStyleRule = function(uid) {
var id = 'plotly.js-style-' + uid;
var style = document.getElementById(id);
if(style) lib.removeElement(style);
};

lib.isIE = function() {
return typeof window.navigator.msSaveBlob !== 'undefined';
};
Expand Down
11 changes: 9 additions & 2 deletions src/plots/mapbox/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

'use strict';

var requiredVersion = '0.45.0';
var requiredVersion = '1.0.0';

module.exports = {
requiredVersion: requiredVersion,
Expand All @@ -31,11 +31,18 @@ module.exports = {
'More info here: https://www.mapbox.com/help/define-access-token/'
].join('\n'),

multipleTokensErrorMsg: [
'Set multiple mapbox access token across different mapbox subplot,',
'using first token found as mapbox-gl does not allow multiple' +
'access tokens on the same page.'
].join('\n'),

mapOnErrorMsg: 'Mapbox error.',

// a subset of node_modules/mapbox-gl/dist/mapbox-gl.css
styleRules: {
map: 'overflow:hidden;position:relative;',
'missing-css': 'display:none',
'missing-css': 'display:none;',
'canary': 'background-color:salmon;'
}
};
58 changes: 41 additions & 17 deletions src/plots/mapbox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@ var Lib = require('../../lib');
var getSubplotCalcData = require('../../plots/get_data').getSubplotCalcData;
var xmlnsNamespaces = require('../../constants/xmlns_namespaces');

var createMapbox = require('./mapbox');
var constants = require('./constants');
var Mapbox = require('./mapbox');

var MAPBOX = 'mapbox';

for(var k in constants.styleRules) {
Lib.addStyleRule('.mapboxgl-' + k, constants.styleRules[k]);
}
var constants = exports.constants = require('./constants');

exports.name = MAPBOX;

Expand All @@ -46,7 +43,7 @@ exports.attributes = {
}
};

exports.layoutAttributes = require('./layout_attributes');
var layoutAttrs = exports.layoutAttributes = require('./layout_attributes');

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

Expand All @@ -69,14 +66,7 @@ exports.plot = function plot(gd) {
var mapbox = opts._subplot;

if(!mapbox) {
mapbox = createMapbox({
gd: gd,
container: fullLayout._glcontainer.node(),
id: id,
fullLayout: fullLayout,
staticPlot: gd._context.staticPlot
});

mapbox = new Mapbox(gd, id);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice clean up here 👍

fullLayout[id]._subplot = mapbox;
}

Expand Down Expand Up @@ -132,24 +122,58 @@ exports.toSVG = function(gd) {
}
};

// N.B. mapbox-gl only allows one accessToken to be set per page:
// https://github.com/mapbox/mapbox-gl-js/issues/6331
function findAccessToken(gd, mapboxIds) {
var fullLayout = gd._fullLayout;
var context = gd._context;

// special case for Mapbox Atlas users
if(context.mapboxAccessToken === '') return '';

var tokensUseful = [];
var tokensListed = [];
var wontWork = false;

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

if(typeof style === 'string' && layoutAttrs.style.values.indexOf(style) !== -1) {
if(token) {
Lib.pushUnique(tokensUseful, token);
} else {
Lib.error('Uses Mapbox map style, but did not set an access token.');
wontWork = true;
}
}

if(opts.accesstoken) {
return opts.accesstoken;
if(token) {
Lib.pushUnique(tokensListed, token);
}
}

throw new Error(constants.noAccessTokenErrorMsg);
if(wontWork) {
throw new Error(constants.noAccessTokenErrorMsg);
}

if(tokensUseful.length) {
if(tokensUseful.length > 1) {
Lib.warn(constants.multipleTokensErrorMsg);
}
return tokensUseful[0];
} else {
if(tokensListed.length) {
Lib.log([
'Listed mapbox access token(s)', tokensListed.join(','),
'but did not use a Mapbox map style, ignoring token(s).'
].join(' '));
}
return '';
}
}

exports.updateFx = function(gd) {
Expand Down
2 changes: 1 addition & 1 deletion src/plots/mapbox/layers.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ proto.removeLayer = function() {
}
};

proto.dispose = function dispose() {
proto.dispose = function() {
var map = this.map;
map.removeLayer(this.idLayer);
map.removeSource(this.idSource);
Expand Down
Loading