Skip to content

geo.visible false should override template.layout.geo.show* #4483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: {
Copy link
Collaborator

@alexcjohnson alexcjohnson Jan 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry to be a pain, but I still don't see a test case that sets template.layout.geo.visible=false, does NOT set layout.geo.visible, and verifies that template.layout.geo.show* settings are still honored in fullLayout.geo

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 9448c8f.

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