Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit eeee911

Browse files
committed
use {} instead of [] to identify line & fill layers
- move enter-only methods to enter-block - and use '.style()` instead of `.attr()` for consistency with Color and Drawing methods.
1 parent ce31666 commit eeee911

File tree

2 files changed

+38
-22
lines changed

2 files changed

+38
-22
lines changed

src/plots/geo/constants.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,20 @@ exports.sphereSVG = {type: 'Sphere'};
127127
// N.B. base layer names must be the same as in the topojson files
128128

129129
// base layer with a fill color
130-
exports.fillLayers = ['ocean', 'land', 'lakes'];
130+
exports.fillLayers = {
131+
ocean: 1,
132+
land: 1,
133+
lakes: 1
134+
};
131135

132136
// base layer with a only a line color
133-
exports.lineLayers = ['subunits', 'countries', 'coastlines', 'rivers', 'frame'];
137+
exports.lineLayers = {
138+
subunits: 1,
139+
countries: 1,
140+
coastlines: 1,
141+
rivers: 1,
142+
frame: 1
143+
};
134144

135145
exports.layers = [
136146
'bg',

src/plots/geo/geo.js

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -227,19 +227,20 @@ proto.updateBaseLayers = function(fullLayout, geoLayout) {
227227
return (d === 'lonaxis' || d === 'lataxis');
228228
}
229229

230-
function isTopoLayer(d) {
231-
return (
232-
constants.fillLayers.indexOf(d) !== -1 ||
233-
constants.lineLayers.indexOf(d) !== -1
234-
);
230+
function isLineLayer(d) {
231+
return Boolean(constants.lineLayers[d]);
232+
}
233+
234+
function isFillLayer(d) {
235+
return Boolean(constants.fillLayers[d]);
235236
}
236237

237238
var allLayers = this.hasChoropleth ?
238239
constants.layersForChoropleth :
239240
constants.layers;
240241

241242
var layerData = allLayers.filter(function(d) {
242-
return isTopoLayer(d) ? geoLayout['show' + d] :
243+
return (isLineLayer(d) || isFillLayer(d)) ? geoLayout['show' + d] :
243244
isAxisLayer(d) ? geoLayout[d].showgrid :
244245
true;
245246
});
@@ -259,15 +260,23 @@ proto.updateBaseLayers = function(fullLayout, geoLayout) {
259260
var layer = layers[d] = d3.select(this);
260261

261262
if(d === 'bg') {
262-
_this.bgRect = layer.append('rect').style('pointer-events', 'all');
263+
_this.bgRect = layer.append('rect')
264+
.style('pointer-events', 'all');
263265
} else if(isAxisLayer(d)) {
264-
basePaths[d] = layer.append('path');
266+
basePaths[d] = layer.append('path')
267+
.style('fill', 'none');
265268
} else if(d === 'backplot') {
266-
layer.append('g').classed('choroplethlayer', true);
269+
layer.append('g')
270+
.classed('choroplethlayer', true);
267271
} else if(d === 'frontplot') {
268-
layer.append('g').classed('scatterlayer', true);
269-
} else if(isTopoLayer(d)) {
270-
basePaths[d] = layer.append('path');
272+
layer.append('g')
273+
.classed('scatterlayer', true);
274+
} else if(isLineLayer(d)) {
275+
basePaths[d] = layer.append('path')
276+
.style('fill', 'none');
277+
} else if(isFillLayer(d)) {
278+
basePaths[d] = layer.append('path')
279+
.style('stroke', 'none');
271280
}
272281
});
273282

@@ -279,22 +288,19 @@ proto.updateBaseLayers = function(fullLayout, geoLayout) {
279288

280289
if(d === 'frame') {
281290
path.datum(constants.sphereSVG);
282-
} else if(isTopoLayer(d)) {
291+
} else if(isLineLayer(d) || isFillLayer(d)) {
283292
path.datum(topojsonFeature(topojson, topojson.objects[d]));
284293
} else if(isAxisLayer(d)) {
285294
path.datum(makeGraticule(d, geoLayout))
286-
.attr('fill', 'none')
287295
.call(Color.stroke, geoLayout[d].gridcolor)
288296
.call(Drawing.dashLine, '', geoLayout[d].gridwidth);
289297
}
290298

291-
if(constants.fillLayers.indexOf(d) !== -1) {
292-
path.attr('stroke', 'none')
293-
.call(Color.fill, geoLayout[adj + 'color']);
294-
} else if(constants.lineLayers.indexOf(d) !== -1) {
295-
path.attr('fill', 'none')
296-
.call(Color.stroke, geoLayout[adj + 'color'])
299+
if(isLineLayer(d)) {
300+
path.call(Color.stroke, geoLayout[adj + 'color'])
297301
.call(Drawing.dashLine, '', geoLayout[adj + 'width']);
302+
} else if(isFillLayer(d)) {
303+
path.call(Color.fill, geoLayout[adj + 'color']);
298304
}
299305
});
300306
};

0 commit comments

Comments
 (0)