Skip to content

Commit

Permalink
Merge pull request #4483 from plotly/fix4482-geo-visible-showland
Browse files Browse the repository at this point in the history
geo.visible false should override template.layout.geo.show*
  • Loading branch information
archmoj authored Jan 13, 2020
2 parents f89a5ae + ca9200b commit 76ef49d
Show file tree
Hide file tree
Showing 4 changed files with 273 additions and 26 deletions.
23 changes: 22 additions & 1 deletion src/plots/geo/layout_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
84 changes: 84 additions & 0 deletions test/image/mocks/geo_visible_false_override_template.json
Original file line number Diff line number Diff line change
@@ -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
}
}
}
}
}
}
192 changes: 167 additions & 25 deletions test/jasmine/tests/geo_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
});
});
});
});
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 76ef49d

Please sign in to comment.