Skip to content

Commit 0909f33

Browse files
committed
add geo.visible
- which when set to false, overrides all the geo.show* defaults - add jasmine default test - add `geo.visible` to geo_featureidkey mock
1 parent 2b5ddec commit 0909f33

File tree

5 files changed

+98
-12
lines changed

5 files changed

+98
-12
lines changed

src/plots/geo/layout_attributes.js

+6
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,12 @@ var attrs = module.exports = overrideAll({
200200
].join(' ')
201201
}
202202
},
203+
visible: {
204+
valType: 'boolean',
205+
role: 'info',
206+
dflt: true,
207+
description: 'Sets the default visibility of the base layers.'
208+
},
203209
showcoastlines: {
204210
valType: 'boolean',
205211
role: 'info',

src/plots/geo/layout_defaults.js

+13-10
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
3030
function handleGeoDefaults(geoLayoutIn, geoLayoutOut, coerce, opts) {
3131
var subplotData = getSubplotData(opts.fullData, 'geo', opts.id);
3232
var traceIndices = subplotData.map(function(t) { return t._expandedIndex; });
33-
var show;
3433

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

48+
var visible = coerce('visible');
49+
var show;
50+
4951
for(var i = 0; i < axesNames.length; i++) {
5052
var axisName = axesNames[i];
5153
var dtickDflt = [30, 10][i];
@@ -67,7 +69,7 @@ function handleGeoDefaults(geoLayoutIn, geoLayoutOut, coerce, opts) {
6769
coerce(axisName + '.tick0');
6870
coerce(axisName + '.dtick', dtickDflt);
6971

70-
show = coerce(axisName + '.showgrid');
72+
show = coerce(axisName + '.showgrid', !visible ? false : undefined);
7173
if(show) {
7274
coerce(axisName + '.gridcolor');
7375
coerce(axisName + '.gridwidth');
@@ -106,13 +108,13 @@ function handleGeoDefaults(geoLayoutIn, geoLayoutOut, coerce, opts) {
106108
coerce('projection.rotation.lat', dfltProjRotate[1]);
107109
coerce('projection.rotation.roll', dfltProjRotate[2]);
108110

109-
show = coerce('showcoastlines', !isScoped);
111+
show = coerce('showcoastlines', !isScoped && visible);
110112
if(show) {
111113
coerce('coastlinecolor');
112114
coerce('coastlinewidth');
113115
}
114116

115-
show = coerce('showocean');
117+
show = coerce('showocean', !visible ? false : undefined);
116118
if(show) coerce('oceancolor');
117119
}
118120

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

141143
coerce('projection.scale');
142144

143-
show = coerce('showland');
145+
show = coerce('showland', !visible ? false : undefined);
144146
if(show) coerce('landcolor');
145147

146-
show = coerce('showlakes');
148+
show = coerce('showlakes', !visible ? false : undefined);
147149
if(show) coerce('lakecolor');
148150

149-
show = coerce('showrivers');
151+
show = coerce('showrivers', !visible ? false : undefined);
150152
if(show) {
151153
coerce('rivercolor');
152154
coerce('riverwidth');
153155
}
154156

155-
show = coerce('showcountries', isScoped && scope !== 'usa');
157+
show = coerce('showcountries', isScoped && scope !== 'usa' && visible);
156158
if(show) {
157159
coerce('countrycolor');
158160
coerce('countrywidth');
@@ -162,14 +164,15 @@ function handleGeoDefaults(geoLayoutIn, geoLayoutOut, coerce, opts) {
162164
// Only works for:
163165
// USA states at 110m
164166
// USA states + Canada provinces at 50m
165-
coerce('showsubunits', true);
167+
// !!
168+
coerce('showsubunits', visible);
166169
coerce('subunitcolor');
167170
coerce('subunitwidth');
168171
}
169172

170173
if(!isScoped) {
171174
// Does not work in non-world scopes
172-
show = coerce('showframe', true);
175+
show = coerce('showframe', visible);
173176
if(show) {
174177
coerce('framecolor');
175178
coerce('framewidth');
-3.27 KB
Loading

test/image/mocks/geo_featureidkey.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@
5757
"layout": {
5858
"geo": {
5959
"center": { "lon": -86, "lat": 33 },
60-
"projection": {"scale": 30}
60+
"projection": {"scale": 30},
61+
"visible": false
6162
},
6263
"width": 600,
6364
"height": 400,

test/jasmine/tests/geo_test.js

+77-1
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,69 @@ describe('Test Geo layout defaults', function() {
623623
});
624624
});
625625
});
626+
627+
describe('geo.visible should override show* defaults', function() {
628+
var keys = [
629+
'lonaxis.showgrid',
630+
'lataxis.showgrid',
631+
'showcoastlines',
632+
'showocean',
633+
'showland',
634+
'showlakes',
635+
'showrivers',
636+
'showcountries',
637+
'showsubunits',
638+
'showframe'
639+
];
640+
641+
function _assert(extra) {
642+
var geo = layoutOut.geo;
643+
keys.forEach(function(k) {
644+
var actual = Lib.nestedProperty(geo, k).get();
645+
if(extra && k in extra) {
646+
expect(actual).toBe(extra[k], k);
647+
} else {
648+
expect(actual).toBe(false, k);
649+
}
650+
});
651+
}
652+
653+
it('- base case', function() {
654+
layoutIn = {
655+
geo: { visible: false }
656+
};
657+
658+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
659+
_assert({
660+
showsubunits: undefined
661+
});
662+
});
663+
664+
it('- scoped case', function() {
665+
layoutIn = {
666+
geo: { scope: 'europe', visible: false }
667+
};
668+
669+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
670+
_assert({
671+
showframe: undefined,
672+
showsubunits: undefined
673+
});
674+
});
675+
676+
it('- scope:usa case', function() {
677+
layoutIn = {
678+
geo: { scope: 'usa', visible: false }
679+
};
680+
681+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
682+
_assert({
683+
showframe: undefined,
684+
showcoastlines: undefined,
685+
showocean: undefined
686+
});
687+
});
688+
});
626689
});
627690

628691
describe('geojson / topojson utils', function() {
@@ -1556,7 +1619,20 @@ describe('Test geo interactions', function() {
15561619
.then(done);
15571620
});
15581621

1559-
// TODO add test for scope:'none'
1622+
it('- geo.visible:false', function(done) {
1623+
Plotly.plot(gd, [{
1624+
type: 'scattergeo',
1625+
lon: [0],
1626+
lat: [0]
1627+
}], {
1628+
geo: {visible: false}
1629+
})
1630+
.then(_assert(0))
1631+
.then(function() { return Plotly.relayout(gd, 'geo.visible', true); })
1632+
.then(_assert(1))
1633+
.catch(failTest)
1634+
.then(done);
1635+
});
15601636
});
15611637
});
15621638

0 commit comments

Comments
 (0)