diff --git a/src/plots/geo/layout_defaults.js b/src/plots/geo/layout_defaults.js index 5f081d157ba..d690a616265 100644 --- a/src/plots/geo/layout_defaults.js +++ b/src/plots/geo/layout_defaults.js @@ -45,9 +45,30 @@ function handleGeoDefaults(geoLayoutIn, geoLayoutOut, coerce, opts) { var isConic = geoLayoutOut._isConic = projType.indexOf('conic') !== -1; var isClipped = geoLayoutOut._isClipped = !!constants.lonaxisSpan[projType]; + if(geoLayoutIn.visible === false) { + // should override template.layout.geo.show* - see issue 4482 + + // make a copy + var newTemplate = Lib.extendDeep({}, geoLayoutOut._template); + + // override show* + newTemplate.showcoastlines = false; + newTemplate.showcountries = false; + newTemplate.showframe = false; + newTemplate.showlakes = false; + newTemplate.showland = false; + newTemplate.showocean = false; + newTemplate.showrivers = false; + newTemplate.showsubunits = false; + if(newTemplate.lonaxis) newTemplate.lonaxis.showgrid = false; + if(newTemplate.lataxis) newTemplate.lataxis.showgrid = false; + + // set ref to copy + geoLayoutOut._template = newTemplate; + } var visible = coerce('visible'); - var show; + var show; for(var i = 0; i < axesNames.length; i++) { var axisName = axesNames[i]; var dtickDflt = [30, 10][i]; diff --git a/test/image/baselines/geo_visible_false_override_template.png b/test/image/baselines/geo_visible_false_override_template.png new file mode 100644 index 00000000000..7c26ebd0909 Binary files /dev/null and b/test/image/baselines/geo_visible_false_override_template.png differ diff --git a/test/image/mocks/geo_visible_false_override_template.json b/test/image/mocks/geo_visible_false_override_template.json new file mode 100644 index 00000000000..2d831e10f3b --- /dev/null +++ b/test/image/mocks/geo_visible_false_override_template.json @@ -0,0 +1,84 @@ +{ + "data": [ + { + "type": "scattergeo", + "marker": { + "opacity": 0.5, + "color": "green", + "size": 100 + }, + "lon": [ + 0 + ], + "lat": [ + 0 + ] + }, + { + "geo": "geo2", + "type": "scattergeo", + "marker": { + "opacity": 0.5, + "color": "yellow", + "size": 100 + }, + "lon": [ + 0 + ], + "lat": [ + 0 + ] + }, + { + "geo": "geo3", + "type": "scattergeo", + "marker": { + "opacity": 0.5, + "color": "red", + "size": 100 + }, + "lon": [ + 0 + ], + "lat": [ + 0 + ] + } + ], + "layout": { + "width": 600, + "height": 800, + "title": { + "text": "geo visible false should override template.layout.geo.show*" + }, + "geo": { + "visible": true + }, + "geo2": { + "visible": false + }, + "geo3": { + "visible": true + }, + "template": { + "layout": { + "geo": { + "showcoastlines": true, + "showcountries": true, + "showframe": true, + "showland": true, + "showlakes": true, + "showocean": true, + "showrivers": true, + "showsubunits": true, + "lonaxis": { + "showgrid": true + }, + "lataxis": { + "showgrid": true + } + } + } + } + } +} diff --git a/test/jasmine/tests/geo_test.js b/test/jasmine/tests/geo_test.js index 3828874767c..426c9a7e745 100644 --- a/test/jasmine/tests/geo_test.js +++ b/test/jasmine/tests/geo_test.js @@ -624,7 +624,7 @@ describe('Test Geo layout defaults', function() { }); }); - describe('geo.visible should override show* defaults', function() { + describe('geo.visible should override show* defaults even with template any show* is true', function() { var keys = [ 'lonaxis.showgrid', 'lataxis.showgrid', @@ -650,39 +650,93 @@ describe('Test Geo layout defaults', function() { }); } - it('- base case', function() { - layoutIn = { - geo: { visible: false } - }; + [true, false, undefined].forEach(function(q) { + it('- base case | ' + q, function() { + layoutIn = { + template: { + layout: { + geo: { + showcoastlines: q, + showcountries: q, + showframe: q, + showland: q, + showlakes: q, + showocean: q, + showrivers: q, + showsubunits: q, + lonaxis: { showgrid: q }, + lataxis: { showgrid: q } + } + } + }, + geo: { visible: false } + }; - supplyLayoutDefaults(layoutIn, layoutOut, fullData); - _assert({ - showsubunits: undefined + supplyLayoutDefaults(layoutIn, layoutOut, fullData); + _assert({ + showsubunits: undefined + }); }); }); - it('- scoped case', function() { - layoutIn = { - geo: { scope: 'europe', visible: false } - }; + [true, false, undefined].forEach(function(q) { + it('- scoped case', function() { + layoutIn = { + template: { + layout: { + geo: { + showcoastlines: q, + showcountries: q, + showframe: q, + showland: q, + showlakes: q, + showocean: q, + showrivers: q, + showsubunits: q, + lonaxis: { showgrid: q }, + lataxis: { showgrid: q } + } + } + }, + geo: { scope: 'europe', visible: false } + }; - supplyLayoutDefaults(layoutIn, layoutOut, fullData); - _assert({ - showframe: undefined, - showsubunits: undefined + supplyLayoutDefaults(layoutIn, layoutOut, fullData); + _assert({ + showframe: undefined, + showsubunits: undefined + }); }); }); - it('- scope:usa case', function() { - layoutIn = { - geo: { scope: 'usa', visible: false } - }; + [true, false, undefined].forEach(function(q) { + it('- scope:usa case', function() { + layoutIn = { + template: { + layout: { + geo: { + showcoastlines: q, + showcountries: q, + showframe: q, + showland: q, + showlakes: q, + showocean: q, + showrivers: q, + showsubunits: q, + lonaxis: { showgrid: q }, + lataxis: { showgrid: q } + } + } + }, + geo: { scope: 'usa', visible: false } + }; - supplyLayoutDefaults(layoutIn, layoutOut, fullData); - _assert({ - showframe: undefined, - showcoastlines: undefined, - showocean: undefined + supplyLayoutDefaults(layoutIn, layoutOut, fullData); + _assert({ + showframe: undefined, + showcoastlines: undefined, + showocean: undefined + }); }); }); }); @@ -1566,6 +1620,94 @@ describe('Test geo interactions', function() { .then(done); }); + it([ + 'geo.visible should honor template.layout.geo.show* defaults', + 'when template.layout.geo.visible is set to false,', + 'and does NOT set layout.geo.visible template' + ].join(' '), function(done) { + var gd = createGraphDiv(); + + Plotly.react(gd, [{ + type: 'scattergeo', + lat: [0], + lon: [0], + marker: { size: 100 } + }], { + template: { + layout: { + geo: { + visible: false, + showcoastlines: true, + showcountries: true, + showframe: true, + showland: true, + showlakes: true, + showocean: true, + showrivers: true, + showsubunits: true, + lonaxis: { showgrid: true }, + lataxis: { showgrid: true } + } + } + }, + geo: {} + }) + .then(function() { + expect(gd._fullLayout.geo.showcoastlines).toBe(true); + expect(gd._fullLayout.geo.showcountries).toBe(true); + expect(gd._fullLayout.geo.showframe).toBe(true); + expect(gd._fullLayout.geo.showland).toBe(true); + expect(gd._fullLayout.geo.showlakes).toBe(true); + expect(gd._fullLayout.geo.showocean).toBe(true); + expect(gd._fullLayout.geo.showrivers).toBe(true); + expect(gd._fullLayout.geo.showsubunits).toBe(undefined); + expect(gd._fullLayout.geo.lonaxis.showgrid).toBe(true); + expect(gd._fullLayout.geo.lataxis.showgrid).toBe(true); + }) + .then(function() { + return Plotly.react(gd, [{ + type: 'scattergeo', + lat: [0], + lon: [0], + marker: {size: 100} + }], { + template: { + layout: { + geo: { + showcoastlines: true, + showcountries: true, + showframe: true, + showland: true, + showlakes: true, + showocean: true, + showrivers: true, + showsubunits: true, + lonaxis: { showgrid: true }, + lataxis: { showgrid: true } + } + } + }, + geo: { + visible: false + } + }); + }) + .then(function() { + expect(gd._fullLayout.geo.showcoastlines).toBe(false); + expect(gd._fullLayout.geo.showcountries).toBe(false); + expect(gd._fullLayout.geo.showframe).toBe(false); + expect(gd._fullLayout.geo.showland).toBe(false); + expect(gd._fullLayout.geo.showlakes).toBe(false); + expect(gd._fullLayout.geo.showocean).toBe(false); + expect(gd._fullLayout.geo.showrivers).toBe(false); + expect(gd._fullLayout.geo.showsubunits).toBe(undefined); + expect(gd._fullLayout.geo.lonaxis.showgrid).toBe(false); + expect(gd._fullLayout.geo.lataxis.showgrid).toBe(false); + }) + .catch(failTest) + .then(done); + }); + describe('should not make request for topojson when not needed', function() { var gd;