Skip to content

Commit d102a47

Browse files
committed
implement tilt and distance for satellite projection
1 parent 0840127 commit d102a47

File tree

7 files changed

+255
-2
lines changed

7 files changed

+255
-2
lines changed

Diff for: src/plots/geo/geo.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -648,8 +648,8 @@ function getProjection(geoLayout) {
648648
var projection = projFn();
649649

650650
var clipAngle =
651-
projType === 'satellite' ? Math.acos(1 / projection.distance()) * 180 / Math.PI :
652-
geoLayout._isClipped ? constants.lonaxisSpan[projType] / 2 : null;
651+
geoLayout._isSatellite ? Math.acos(1 / projLayout.distance) * 180 / Math.PI :
652+
geoLayout._isClipped ? constants.lonaxisSpan[projType] / 2 : null;
653653

654654
var methods = ['center', 'rotate', 'parallels', 'clipExtent'];
655655
var dummyFn = function(_) { return _ ? projection : []; };
@@ -686,6 +686,10 @@ function getProjection(geoLayout) {
686686

687687
projection.precision(constants.precision);
688688

689+
if(geoLayout._isSatellite) {
690+
projection.tilt(projLayout.tilt).distance(projLayout.distance);
691+
}
692+
689693
if(clipAngle) {
690694
projection.clipAngle(clipAngle - constants.clipPad);
691695
}

Diff for: src/plots/geo/layout_attributes.js

+18
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,24 @@ var attrs = module.exports = overrideAll({
134134
].join(' ')
135135
}
136136
},
137+
tilt: {
138+
valType: 'number',
139+
dflt: 0,
140+
description: [
141+
'For satellite projection type only.',
142+
'Sets the tilt angle of perspective projection.'
143+
].join(' ')
144+
},
145+
distance: {
146+
valType: 'number',
147+
min: 1.001,
148+
dflt: 2,
149+
description: [
150+
'For satellite projection type only.',
151+
'Sets the distance from the center of the sphere to the point of view',
152+
'as a proportion of the sphere’s radius.'
153+
].join(' ')
154+
},
137155
parallels: {
138156
valType: 'info_array',
139157
items: [

Diff for: src/plots/geo/layout_defaults.js

+6
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ function handleGeoDefaults(geoLayoutIn, geoLayoutOut, coerce, opts) {
3434
if(isAlbersUsa) scope = geoLayoutOut.scope = 'usa';
3535

3636
var isScoped = geoLayoutOut._isScoped = (scope !== 'world');
37+
var isSatellite = geoLayoutOut._isSatellite = projType === 'satellite';
3738
var isConic = geoLayoutOut._isConic = projType.indexOf('conic') !== -1;
3839
var isClipped = geoLayoutOut._isClipped = !!constants.lonaxisSpan[projType];
3940

@@ -148,6 +149,11 @@ function handleGeoDefaults(geoLayoutIn, geoLayoutOut, coerce, opts) {
148149
coerce('center.lon', centerLonDflt);
149150
coerce('center.lat', centerLatDflt);
150151

152+
if(isSatellite) {
153+
coerce('projection.tilt');
154+
coerce('projection.distance');
155+
}
156+
151157
if(isConic) {
152158
var dfltProjParallels = scopeParams.projParallels || [0, 60];
153159
coerce('projection.parallels', dfltProjParallels);

Diff for: test/image/baselines/distance_satellite.png

169 KB
Loading

Diff for: test/image/mocks/distance_satellite.json

+183
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
{
2+
"data": [
3+
{
4+
"type": "choropleth",
5+
"colorscale": "Greens",
6+
"showscale": false,
7+
"hoverinfo": "z+text",
8+
"z": [
9+
1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
10+
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
11+
21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
12+
31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
13+
41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
14+
51, 52, 53, 54, 55, 56, 57, 58, 59
15+
],
16+
"text": [
17+
"Alabama",
18+
"Alaska",
19+
"American Samoa",
20+
"Arizona",
21+
"Arkansas",
22+
"California",
23+
"Colorado",
24+
"Connecticut",
25+
"Delaware",
26+
"District Of Columbia",
27+
"Federated States Of Micronesia",
28+
"Florida",
29+
"Georgia",
30+
"Guam",
31+
"Hawaii",
32+
"Idaho",
33+
"Illinois",
34+
"Indiana",
35+
"Iowa",
36+
"Kansas",
37+
"Kentucky",
38+
"Louisiana",
39+
"Maine",
40+
"Marshall Islands",
41+
"Maryland",
42+
"Massachusetts",
43+
"Michigan",
44+
"Minnesota",
45+
"Mississippi",
46+
"Missouri",
47+
"Montana",
48+
"Nebraska",
49+
"Nevada",
50+
"New Hampshire",
51+
"New Jersey",
52+
"New Mexico",
53+
"New York",
54+
"North Carolina",
55+
"North Dakota",
56+
"Northern Mariana Islands",
57+
"Ohio",
58+
"Oklahoma",
59+
"Oregon",
60+
"Palau",
61+
"Pennsylvania",
62+
"Puerto Rico",
63+
"Rhode Island",
64+
"South Carolina",
65+
"South Dakota",
66+
"Tennessee",
67+
"Texas",
68+
"Utah",
69+
"Vermont",
70+
"Virgin Islands",
71+
"Virginia",
72+
"Washington",
73+
"West Virginia",
74+
"Wisconsin",
75+
"Wyoming"
76+
],
77+
"locationmode": "USA-states",
78+
"locations": [
79+
"AL",
80+
"AK",
81+
"AS",
82+
"AZ",
83+
"AR",
84+
"CA",
85+
"CO",
86+
"CT",
87+
"DE",
88+
"DC",
89+
"FM",
90+
"FL",
91+
"GA",
92+
"GU",
93+
"HI",
94+
"ID",
95+
"IL",
96+
"IN",
97+
"IA",
98+
"KS",
99+
"KY",
100+
"LA",
101+
"ME",
102+
"MH",
103+
"MD",
104+
"MA",
105+
"MI",
106+
"MN",
107+
"MS",
108+
"MO",
109+
"MT",
110+
"NE",
111+
"NV",
112+
"NH",
113+
"NJ",
114+
"NM",
115+
"NY",
116+
"NC",
117+
"ND",
118+
"MP",
119+
"OH",
120+
"OK",
121+
"OR",
122+
"PW",
123+
"PA",
124+
"PR",
125+
"RI",
126+
"SC",
127+
"SD",
128+
"TN",
129+
"TX",
130+
"UT",
131+
"VT",
132+
"VI",
133+
"VA",
134+
"WA",
135+
"WV",
136+
"WI",
137+
"WY"
138+
]
139+
}
140+
],
141+
"layout": {
142+
"showlegend": false,
143+
"width": 800,
144+
"height": 800,
145+
"title": {
146+
"font": { "size": 16 },
147+
"text": "<b>satellite projection in Plotly</b><br>distance: 1.5<br>tilt: 15<br>latitude: 45<br>longitude: -90<br>roll: 30"
148+
},
149+
"margin": {
150+
"t": 100,
151+
"b": 20,
152+
"l": 20,
153+
"r": 20
154+
},
155+
"paper_bgcolor": "darkgray",
156+
"geo": {
157+
"bgcolor": "rgba(0,0,0,0)",
158+
"projection": {
159+
"type": "satellite",
160+
"rotation": {
161+
"lon": -90,
162+
"lat": 45,
163+
"roll": 30
164+
},
165+
"tilt": 15,
166+
"distance": 1.5
167+
},
168+
"lonaxis": {
169+
"showgrid": true,
170+
"gridwidth": 1,
171+
"gridcolor": "lightgray"
172+
},
173+
"lataxis": {
174+
"showgrid": true,
175+
"gridwidth": 1,
176+
"gridcolor": "lightgray"
177+
},
178+
"showcoastlines": false,
179+
"showland": true,
180+
"showocean": true
181+
}
182+
}
183+
}

Diff for: test/jasmine/tests/geo_test.js

+29
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,35 @@ describe('Test Geo layout defaults', function() {
130130
});
131131
});
132132

133+
it('should only coerce projection.tilt and projection.distance if type is satellite', function() {
134+
var projTypes = layoutAttributes.projection.type.values;
135+
136+
function testOne(projType) {
137+
layoutIn = {
138+
geo: {
139+
projection: {
140+
type: projType,
141+
tilt: 30,
142+
distance: 3
143+
}
144+
}
145+
};
146+
147+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
148+
}
149+
150+
projTypes.forEach(function(projType) {
151+
testOne(projType);
152+
if(projType === 'satellite') {
153+
expect(layoutOut.geo.projection.tilt).toBeDefined();
154+
expect(layoutOut.geo.projection.distance).toBeDefined();
155+
} else {
156+
expect(layoutOut.geo.projection.tilt).toBeUndefined();
157+
expect(layoutOut.geo.projection.distance).toBeUndefined();
158+
}
159+
});
160+
});
161+
133162
it('should only coerce projection.parallels if type is conic', function() {
134163
var projTypes = layoutAttributes.projection.type.values;
135164

Diff for: test/plot-schema.json

+13
Original file line numberDiff line numberDiff line change
@@ -2005,6 +2005,13 @@
20052005
"valType": "color"
20062006
},
20072007
"projection": {
2008+
"distance": {
2009+
"description": "For satellite projection type only. Sets the distance from the center of the sphere to the point of view as a proportion of the sphere’s radius.",
2010+
"dflt": 2,
2011+
"editType": "plot",
2012+
"min": 1.001,
2013+
"valType": "number"
2014+
},
20082015
"editType": "plot",
20092016
"parallels": {
20102017
"description": "For conic projection types only. Sets the parallels (tangent, secant) where the cone intersects the sphere.",
@@ -2048,6 +2055,12 @@
20482055
"min": 0,
20492056
"valType": "number"
20502057
},
2058+
"tilt": {
2059+
"description": "For satellite projection type only. Sets the tilt angle of perspective projection.",
2060+
"dflt": 0,
2061+
"editType": "plot",
2062+
"valType": "number"
2063+
},
20512064
"type": {
20522065
"description": "Sets the projection type.",
20532066
"editType": "plot",

0 commit comments

Comments
 (0)