Skip to content

Commit f51d66b

Browse files
committed
standardise layer/source id prefixes
1 parent 16abdfb commit f51d66b

File tree

8 files changed

+31
-24
lines changed

8 files changed

+31
-24
lines changed

src/plots/mapbox/constants.js

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ module.exports = {
4242
}]
4343
},
4444

45+
traceLayerPrefix: 'plotly-trace-layer-',
46+
layoutLayerPrefix: 'plotly-layout-layer-',
47+
4548
wrongVersionErrorMsg: [
4649
'Your custom plotly.js bundle is not using the correct mapbox-gl version',
4750
'Please install mapbox-gl@' + requiredVersion + '.'

src/plots/mapbox/layers.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@
1010

1111
var Lib = require('../../lib');
1212
var convertTextOpts = require('./convert_text_opts');
13+
var constants = require('./constants');
1314

1415
function MapboxLayer(subplot, index) {
1516
this.subplot = subplot;
1617
this.map = subplot.map;
1718

18-
this.uid = subplot.uid + '-' + 'layer' + index;
19+
this.uid = subplot.uid + '-' + index;
1920

20-
this.idSource = this.uid + '-source';
21-
this.idLayer = this.uid + '-layer';
21+
this.idSource = 'source-' + this.uid;
22+
this.idLayer = constants.layoutLayerPrefix + this.uid;
2223

2324
// some state variable to check if a remove/add step is needed
2425
this.sourceType = null;

src/traces/choroplethmapbox/plot.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,18 @@
1010

1111
var convert = require('./convert').convert;
1212
var convertOnSelect = require('./convert').convertOnSelect;
13+
var LAYER_PREFIX = require('../../plots/mapbox/constants').traceLayerPrefix;
1314

1415
function ChoroplethMapbox(subplot, uid) {
1516
this.subplot = subplot;
1617
this.uid = uid;
1718

1819
// N.B. fill and line layers share same source
19-
this.sourceId = uid + '-source';
20+
this.sourceId = 'source-' + uid;
2021

2122
this.layerList = [
22-
['fill', uid + '-layer-fill'],
23-
['line', uid + '-layer-line']
23+
['fill', LAYER_PREFIX + uid + '-fill'],
24+
['line', LAYER_PREFIX + uid + '-line']
2425
];
2526

2627
// previous 'below' value,

src/traces/densitymapbox/plot.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@
99
'use strict';
1010

1111
var convert = require('./convert');
12+
var LAYER_PREFIX = require('../../plots/mapbox/constants').traceLayerPrefix;
1213

1314
function DensityMapbox(subplot, uid) {
1415
this.subplot = subplot;
1516
this.uid = uid;
1617

17-
this.sourceId = uid + '-source';
18+
this.sourceId = 'source-' + uid;
1819

1920
this.layerList = [
20-
['heatmap', uid + '-layer-heatmap']
21+
['heatmap', LAYER_PREFIX + uid + '-heatmap']
2122
];
2223

2324
// previous 'below' value,

src/traces/scattermapbox/plot.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,24 @@
99
'use strict';
1010

1111
var convert = require('./convert');
12+
var LAYER_PREFIX = require('../../plots/mapbox/constants').traceLayerPrefix;
1213

1314
function ScatterMapbox(subplot, uid) {
1415
this.subplot = subplot;
1516
this.uid = uid;
1617

1718
this.sourceIds = {
18-
fill: uid + '-source-fill',
19-
line: uid + '-source-line',
20-
circle: uid + '-source-circle',
21-
symbol: uid + '-source-symbol'
19+
fill: 'source-' + uid + '-fill',
20+
line: 'source-' + uid + '-line',
21+
circle: 'source-' + uid + '-circle',
22+
symbol: 'source-' + uid + '-symbol'
2223
};
2324

2425
this.layerIds = {
25-
fill: uid + '-layer-fill',
26-
line: uid + '-layer-line',
27-
circle: uid + '-layer-circle',
28-
symbol: uid + '-layer-symbol'
26+
fill: LAYER_PREFIX + uid + '-fill',
27+
line: LAYER_PREFIX + uid + '-line',
28+
circle: LAYER_PREFIX + uid + '-circle',
29+
symbol: LAYER_PREFIX + uid + '-symbol'
2930
};
3031

3132
this.order = ['fill', 'line', 'circle', 'symbol'];

test/jasmine/tests/choroplethmapbox_test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ describe('@noCI Test choroplethmapbox interactions:', function() {
692692
expect(getLayerIds()).withContext('default *below*').toEqual([
693693
'background', 'landuse_overlay_national_park', 'landuse_park',
694694
'waterway', 'water',
695-
'a-layer-fill', 'a-layer-line',
695+
'plotly-trace-layer-a-fill', 'plotly-trace-layer-a-line',
696696
'building', 'tunnel_minor', 'tunnel_major', 'road_minor', 'road_major',
697697
'bridge_minor case', 'bridge_major case', 'bridge_minor', 'bridge_major',
698698
'admin_country', 'poi_label', 'road_major_label',
@@ -708,7 +708,7 @@ describe('@noCI Test choroplethmapbox interactions:', function() {
708708
'bridge_minor case', 'bridge_major case', 'bridge_minor', 'bridge_major',
709709
'admin_country', 'poi_label', 'road_major_label',
710710
'place_label_other', 'place_label_city', 'country_label',
711-
'a-layer-fill', 'a-layer-line'
711+
'plotly-trace-layer-a-fill', 'plotly-trace-layer-a-line'
712712
]);
713713
})
714714
.then(function() { return Plotly.restyle(gd, 'below', 'place_label_other'); })
@@ -719,7 +719,7 @@ describe('@noCI Test choroplethmapbox interactions:', function() {
719719
'building', 'tunnel_minor', 'tunnel_major', 'road_minor', 'road_major',
720720
'bridge_minor case', 'bridge_major case', 'bridge_minor', 'bridge_major',
721721
'admin_country', 'poi_label', 'road_major_label',
722-
'a-layer-fill', 'a-layer-line',
722+
'plotly-trace-layer-a-fill', 'plotly-trace-layer-a-line',
723723
'place_label_other', 'place_label_city', 'country_label',
724724
]);
725725
})

test/jasmine/tests/densitymapbox_test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ describe('@noCI Test densitymapbox interactions:', function() {
452452
'building', 'tunnel_minor', 'tunnel_major', 'road_minor', 'road_major',
453453
'bridge_minor case', 'bridge_major case', 'bridge_minor', 'bridge_major',
454454
'admin_country',
455-
'a-layer-heatmap',
455+
'plotly-trace-layer-a-heatmap',
456456
'poi_label', 'road_major_label',
457457
'place_label_other', 'place_label_city', 'country_label'
458458
]);
@@ -466,7 +466,7 @@ describe('@noCI Test densitymapbox interactions:', function() {
466466
'bridge_minor case', 'bridge_major case', 'bridge_minor', 'bridge_major',
467467
'admin_country', 'poi_label', 'road_major_label',
468468
'place_label_other', 'place_label_city', 'country_label',
469-
'a-layer-heatmap'
469+
'plotly-trace-layer-a-heatmap'
470470
]);
471471
})
472472
.then(function() { return Plotly.restyle(gd, 'below', 'place_label_other'); })
@@ -477,7 +477,7 @@ describe('@noCI Test densitymapbox interactions:', function() {
477477
'building', 'tunnel_minor', 'tunnel_major', 'road_minor', 'road_major',
478478
'bridge_minor case', 'bridge_major case', 'bridge_minor', 'bridge_major',
479479
'admin_country', 'poi_label', 'road_major_label',
480-
'a-layer-heatmap',
480+
'plotly-trace-layer-a-heatmap',
481481
'place_label_other', 'place_label_city', 'country_label',
482482
]);
483483
})

test/jasmine/tests/mapbox_test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1210,11 +1210,11 @@ describe('@noCI, mapbox plots', function() {
12101210
var uid = subplot.uid;
12111211

12121212
var traceSources = Object.keys(sources).filter(function(k) {
1213-
return k.indexOf('-source-') !== -1;
1213+
return k.indexOf('source-') === 0;
12141214
});
12151215

12161216
var traceLayers = Object.keys(layers).filter(function(k) {
1217-
return k.indexOf('-layer-') !== -1;
1217+
return k.indexOf('plotly-trace-layer-') === 0;
12181218
});
12191219

12201220
var layoutSources = Object.keys(sources).filter(function(k) {

0 commit comments

Comments
 (0)