Skip to content

Commit 76ef49d

Browse files
authored
Merge pull request #4483 from plotly/fix4482-geo-visible-showland
geo.visible false should override template.layout.geo.show*
2 parents f89a5ae + ca9200b commit 76ef49d

File tree

4 files changed

+273
-26
lines changed

4 files changed

+273
-26
lines changed

src/plots/geo/layout_defaults.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,30 @@ function handleGeoDefaults(geoLayoutIn, geoLayoutOut, coerce, opts) {
4545
var isConic = geoLayoutOut._isConic = projType.indexOf('conic') !== -1;
4646
var isClipped = geoLayoutOut._isClipped = !!constants.lonaxisSpan[projType];
4747

48+
if(geoLayoutIn.visible === false) {
49+
// should override template.layout.geo.show* - see issue 4482
50+
51+
// make a copy
52+
var newTemplate = Lib.extendDeep({}, geoLayoutOut._template);
53+
54+
// override show*
55+
newTemplate.showcoastlines = false;
56+
newTemplate.showcountries = false;
57+
newTemplate.showframe = false;
58+
newTemplate.showlakes = false;
59+
newTemplate.showland = false;
60+
newTemplate.showocean = false;
61+
newTemplate.showrivers = false;
62+
newTemplate.showsubunits = false;
63+
if(newTemplate.lonaxis) newTemplate.lonaxis.showgrid = false;
64+
if(newTemplate.lataxis) newTemplate.lataxis.showgrid = false;
65+
66+
// set ref to copy
67+
geoLayoutOut._template = newTemplate;
68+
}
4869
var visible = coerce('visible');
49-
var show;
5070

71+
var show;
5172
for(var i = 0; i < axesNames.length; i++) {
5273
var axisName = axesNames[i];
5374
var dtickDflt = [30, 10][i];
Loading
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{
2+
"data": [
3+
{
4+
"type": "scattergeo",
5+
"marker": {
6+
"opacity": 0.5,
7+
"color": "green",
8+
"size": 100
9+
},
10+
"lon": [
11+
0
12+
],
13+
"lat": [
14+
0
15+
]
16+
},
17+
{
18+
"geo": "geo2",
19+
"type": "scattergeo",
20+
"marker": {
21+
"opacity": 0.5,
22+
"color": "yellow",
23+
"size": 100
24+
},
25+
"lon": [
26+
0
27+
],
28+
"lat": [
29+
0
30+
]
31+
},
32+
{
33+
"geo": "geo3",
34+
"type": "scattergeo",
35+
"marker": {
36+
"opacity": 0.5,
37+
"color": "red",
38+
"size": 100
39+
},
40+
"lon": [
41+
0
42+
],
43+
"lat": [
44+
0
45+
]
46+
}
47+
],
48+
"layout": {
49+
"width": 600,
50+
"height": 800,
51+
"title": {
52+
"text": "geo visible false should override template.layout.geo.show*"
53+
},
54+
"geo": {
55+
"visible": true
56+
},
57+
"geo2": {
58+
"visible": false
59+
},
60+
"geo3": {
61+
"visible": true
62+
},
63+
"template": {
64+
"layout": {
65+
"geo": {
66+
"showcoastlines": true,
67+
"showcountries": true,
68+
"showframe": true,
69+
"showland": true,
70+
"showlakes": true,
71+
"showocean": true,
72+
"showrivers": true,
73+
"showsubunits": true,
74+
"lonaxis": {
75+
"showgrid": true
76+
},
77+
"lataxis": {
78+
"showgrid": true
79+
}
80+
}
81+
}
82+
}
83+
}
84+
}

test/jasmine/tests/geo_test.js

Lines changed: 167 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ describe('Test Geo layout defaults', function() {
624624
});
625625
});
626626

627-
describe('geo.visible should override show* defaults', function() {
627+
describe('geo.visible should override show* defaults even with template any show* is true', function() {
628628
var keys = [
629629
'lonaxis.showgrid',
630630
'lataxis.showgrid',
@@ -650,39 +650,93 @@ describe('Test Geo layout defaults', function() {
650650
});
651651
}
652652

653-
it('- base case', function() {
654-
layoutIn = {
655-
geo: { visible: false }
656-
};
653+
[true, false, undefined].forEach(function(q) {
654+
it('- base case | ' + q, function() {
655+
layoutIn = {
656+
template: {
657+
layout: {
658+
geo: {
659+
showcoastlines: q,
660+
showcountries: q,
661+
showframe: q,
662+
showland: q,
663+
showlakes: q,
664+
showocean: q,
665+
showrivers: q,
666+
showsubunits: q,
667+
lonaxis: { showgrid: q },
668+
lataxis: { showgrid: q }
669+
}
670+
}
671+
},
672+
geo: { visible: false }
673+
};
657674

658-
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
659-
_assert({
660-
showsubunits: undefined
675+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
676+
_assert({
677+
showsubunits: undefined
678+
});
661679
});
662680
});
663681

664-
it('- scoped case', function() {
665-
layoutIn = {
666-
geo: { scope: 'europe', visible: false }
667-
};
682+
[true, false, undefined].forEach(function(q) {
683+
it('- scoped case', function() {
684+
layoutIn = {
685+
template: {
686+
layout: {
687+
geo: {
688+
showcoastlines: q,
689+
showcountries: q,
690+
showframe: q,
691+
showland: q,
692+
showlakes: q,
693+
showocean: q,
694+
showrivers: q,
695+
showsubunits: q,
696+
lonaxis: { showgrid: q },
697+
lataxis: { showgrid: q }
698+
}
699+
}
700+
},
701+
geo: { scope: 'europe', visible: false }
702+
};
668703

669-
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
670-
_assert({
671-
showframe: undefined,
672-
showsubunits: undefined
704+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
705+
_assert({
706+
showframe: undefined,
707+
showsubunits: undefined
708+
});
673709
});
674710
});
675711

676-
it('- scope:usa case', function() {
677-
layoutIn = {
678-
geo: { scope: 'usa', visible: false }
679-
};
712+
[true, false, undefined].forEach(function(q) {
713+
it('- scope:usa case', function() {
714+
layoutIn = {
715+
template: {
716+
layout: {
717+
geo: {
718+
showcoastlines: q,
719+
showcountries: q,
720+
showframe: q,
721+
showland: q,
722+
showlakes: q,
723+
showocean: q,
724+
showrivers: q,
725+
showsubunits: q,
726+
lonaxis: { showgrid: q },
727+
lataxis: { showgrid: q }
728+
}
729+
}
730+
},
731+
geo: { scope: 'usa', visible: false }
732+
};
680733

681-
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
682-
_assert({
683-
showframe: undefined,
684-
showcoastlines: undefined,
685-
showocean: undefined
734+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
735+
_assert({
736+
showframe: undefined,
737+
showcoastlines: undefined,
738+
showocean: undefined
739+
});
686740
});
687741
});
688742
});
@@ -1566,6 +1620,94 @@ describe('Test geo interactions', function() {
15661620
.then(done);
15671621
});
15681622

1623+
it([
1624+
'geo.visible should honor template.layout.geo.show* defaults',
1625+
'when template.layout.geo.visible is set to false,',
1626+
'and does NOT set layout.geo.visible template'
1627+
].join(' '), function(done) {
1628+
var gd = createGraphDiv();
1629+
1630+
Plotly.react(gd, [{
1631+
type: 'scattergeo',
1632+
lat: [0],
1633+
lon: [0],
1634+
marker: { size: 100 }
1635+
}], {
1636+
template: {
1637+
layout: {
1638+
geo: {
1639+
visible: false,
1640+
showcoastlines: true,
1641+
showcountries: true,
1642+
showframe: true,
1643+
showland: true,
1644+
showlakes: true,
1645+
showocean: true,
1646+
showrivers: true,
1647+
showsubunits: true,
1648+
lonaxis: { showgrid: true },
1649+
lataxis: { showgrid: true }
1650+
}
1651+
}
1652+
},
1653+
geo: {}
1654+
})
1655+
.then(function() {
1656+
expect(gd._fullLayout.geo.showcoastlines).toBe(true);
1657+
expect(gd._fullLayout.geo.showcountries).toBe(true);
1658+
expect(gd._fullLayout.geo.showframe).toBe(true);
1659+
expect(gd._fullLayout.geo.showland).toBe(true);
1660+
expect(gd._fullLayout.geo.showlakes).toBe(true);
1661+
expect(gd._fullLayout.geo.showocean).toBe(true);
1662+
expect(gd._fullLayout.geo.showrivers).toBe(true);
1663+
expect(gd._fullLayout.geo.showsubunits).toBe(undefined);
1664+
expect(gd._fullLayout.geo.lonaxis.showgrid).toBe(true);
1665+
expect(gd._fullLayout.geo.lataxis.showgrid).toBe(true);
1666+
})
1667+
.then(function() {
1668+
return Plotly.react(gd, [{
1669+
type: 'scattergeo',
1670+
lat: [0],
1671+
lon: [0],
1672+
marker: {size: 100}
1673+
}], {
1674+
template: {
1675+
layout: {
1676+
geo: {
1677+
showcoastlines: true,
1678+
showcountries: true,
1679+
showframe: true,
1680+
showland: true,
1681+
showlakes: true,
1682+
showocean: true,
1683+
showrivers: true,
1684+
showsubunits: true,
1685+
lonaxis: { showgrid: true },
1686+
lataxis: { showgrid: true }
1687+
}
1688+
}
1689+
},
1690+
geo: {
1691+
visible: false
1692+
}
1693+
});
1694+
})
1695+
.then(function() {
1696+
expect(gd._fullLayout.geo.showcoastlines).toBe(false);
1697+
expect(gd._fullLayout.geo.showcountries).toBe(false);
1698+
expect(gd._fullLayout.geo.showframe).toBe(false);
1699+
expect(gd._fullLayout.geo.showland).toBe(false);
1700+
expect(gd._fullLayout.geo.showlakes).toBe(false);
1701+
expect(gd._fullLayout.geo.showocean).toBe(false);
1702+
expect(gd._fullLayout.geo.showrivers).toBe(false);
1703+
expect(gd._fullLayout.geo.showsubunits).toBe(undefined);
1704+
expect(gd._fullLayout.geo.lonaxis.showgrid).toBe(false);
1705+
expect(gd._fullLayout.geo.lataxis.showgrid).toBe(false);
1706+
})
1707+
.catch(failTest)
1708+
.then(done);
1709+
});
1710+
15691711
describe('should not make request for topojson when not needed', function() {
15701712
var gd;
15711713

0 commit comments

Comments
 (0)