Skip to content
Merged
6 changes: 6 additions & 0 deletions src/plots/geo/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ var attrs = module.exports = overrideAll({
].join(' ')
}
},
visible: {
valType: 'boolean',
role: 'info',
dflt: true,
description: 'Sets the default visibility of the base layers.'
},
showcoastlines: {
valType: 'boolean',
role: 'info',
Expand Down
23 changes: 13 additions & 10 deletions src/plots/geo/layout_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
function handleGeoDefaults(geoLayoutIn, geoLayoutOut, coerce, opts) {
var subplotData = getSubplotData(opts.fullData, 'geo', opts.id);
var traceIndices = subplotData.map(function(t) { return t._expandedIndex; });
var show;

var resolution = coerce('resolution');
var scope = coerce('scope');
Expand All @@ -46,6 +45,9 @@ function handleGeoDefaults(geoLayoutIn, geoLayoutOut, coerce, opts) {
var isConic = geoLayoutOut._isConic = projType.indexOf('conic') !== -1;
var isClipped = geoLayoutOut._isClipped = !!constants.lonaxisSpan[projType];

var visible = coerce('visible');
var show;

for(var i = 0; i < axesNames.length; i++) {
var axisName = axesNames[i];
var dtickDflt = [30, 10][i];
Expand All @@ -67,7 +69,7 @@ function handleGeoDefaults(geoLayoutIn, geoLayoutOut, coerce, opts) {
coerce(axisName + '.tick0');
coerce(axisName + '.dtick', dtickDflt);

show = coerce(axisName + '.showgrid');
show = coerce(axisName + '.showgrid', !visible ? false : undefined);
if(show) {
coerce(axisName + '.gridcolor');
coerce(axisName + '.gridwidth');
Expand Down Expand Up @@ -106,13 +108,13 @@ function handleGeoDefaults(geoLayoutIn, geoLayoutOut, coerce, opts) {
coerce('projection.rotation.lat', dfltProjRotate[1]);
coerce('projection.rotation.roll', dfltProjRotate[2]);

show = coerce('showcoastlines', !isScoped);
show = coerce('showcoastlines', !isScoped && visible);
if(show) {
coerce('coastlinecolor');
coerce('coastlinewidth');
}

show = coerce('showocean');
show = coerce('showocean', !visible ? false : undefined);
if(show) coerce('oceancolor');
}

Expand Down Expand Up @@ -140,19 +142,19 @@ function handleGeoDefaults(geoLayoutIn, geoLayoutOut, coerce, opts) {

coerce('projection.scale');

show = coerce('showland');
show = coerce('showland', !visible ? false : undefined);
if(show) coerce('landcolor');

show = coerce('showlakes');
show = coerce('showlakes', !visible ? false : undefined);
if(show) coerce('lakecolor');

show = coerce('showrivers');
show = coerce('showrivers', !visible ? false : undefined);
if(show) {
coerce('rivercolor');
coerce('riverwidth');
}

show = coerce('showcountries', isScoped && scope !== 'usa');
show = coerce('showcountries', isScoped && scope !== 'usa' && visible);
if(show) {
coerce('countrycolor');
coerce('countrywidth');
Expand All @@ -162,14 +164,15 @@ function handleGeoDefaults(geoLayoutIn, geoLayoutOut, coerce, opts) {
// Only works for:
// USA states at 110m
// USA states + Canada provinces at 50m
coerce('showsubunits', true);
// !!
Comment thread
etpinard marked this conversation as resolved.
Outdated
coerce('showsubunits', visible);
coerce('subunitcolor');
coerce('subunitwidth');
}

if(!isScoped) {
// Does not work in non-world scopes
show = coerce('showframe', true);
show = coerce('showframe', visible);
if(show) {
coerce('framecolor');
coerce('framewidth');
Expand Down
Binary file modified test/image/baselines/geo_featureidkey.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion test/image/mocks/geo_featureidkey.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
"layout": {
"geo": {
"center": { "lon": -86, "lat": 33 },
"projection": {"scale": 30}
"projection": {"scale": 30},
"visible": false
},
"width": 600,
"height": 400,
Expand Down
78 changes: 77 additions & 1 deletion test/jasmine/tests/geo_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,69 @@ describe('Test Geo layout defaults', function() {
});
});
});

describe('geo.visible should override show* defaults', function() {
var keys = [
'lonaxis.showgrid',
'lataxis.showgrid',
'showcoastlines',
'showocean',
'showland',
'showlakes',
'showrivers',
'showcountries',
'showsubunits',
'showframe'
];

function _assert(extra) {
var geo = layoutOut.geo;
keys.forEach(function(k) {
var actual = Lib.nestedProperty(geo, k).get();
if(extra && k in extra) {
expect(actual).toBe(extra[k], k);
} else {
expect(actual).toBe(false, k);
}
});
}

it('- base case', function() {
layoutIn = {
geo: { visible: false }
};

supplyLayoutDefaults(layoutIn, layoutOut, fullData);
_assert({
showsubunits: undefined
});
});

it('- scoped case', function() {
layoutIn = {
geo: { scope: 'europe', visible: false }
};

supplyLayoutDefaults(layoutIn, layoutOut, fullData);
_assert({
showframe: undefined,
showsubunits: undefined
});
});

it('- scope:usa case', function() {
layoutIn = {
geo: { scope: 'usa', visible: false }
};

supplyLayoutDefaults(layoutIn, layoutOut, fullData);
_assert({
showframe: undefined,
showcoastlines: undefined,
showocean: undefined
});
});
});
});

describe('geojson / topojson utils', function() {
Expand Down Expand Up @@ -1556,7 +1619,20 @@ describe('Test geo interactions', function() {
.then(done);
});

// TODO add test for scope:'none'
it('- geo.visible:false', function(done) {
Plotly.plot(gd, [{
type: 'scattergeo',
lon: [0],
lat: [0]
}], {
geo: {visible: false}
})
.then(_assert(0))
.then(function() { return Plotly.relayout(gd, 'geo.visible', true); })
.then(_assert(1))
.catch(failTest)
.then(done);
});
});
});

Expand Down