Skip to content

Add satellite and various projection types to geo subplots #5801

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 19 commits into from
Jul 9, 2021
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
1 change: 1 addition & 0 deletions draftlogs/5801_add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Add satellite and various projection types to geo subplots [[#5801](https://github.com/plotly/plotly.js/pull/5801)]
112 changes: 52 additions & 60 deletions src/plots/geo/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,128 +2,120 @@

// projection names to d3 function name
exports.projNames = {
'equirectangular': 'equirectangular',
'mercator': 'mercator',
'orthographic': 'orthographic',
'natural earth': 'naturalEarth',
'kavrayskiy7': 'kavrayskiy7',
'miller': 'miller',
'robinson': 'robinson',
'eckert4': 'eckert4',
'azimuthal equal area': 'azimuthalEqualArea',
'azimuthal equidistant': 'azimuthalEquidistant',
'conic equal area': 'conicEqualArea',
'conic conformal': 'conicConformal',
'conic equidistant': 'conicEquidistant',
'gnomonic': 'gnomonic',
'stereographic': 'stereographic',
'mollweide': 'mollweide',
'hammer': 'hammer',
'transverse mercator': 'transverseMercator',
'albers usa': 'albersUsa',
'winkel tripel': 'winkel3',
'aitoff': 'aitoff',
'sinusoidal': 'sinusoidal',
/*
// potential projections that could be added to the API

'airy': 'airy',
// 'albers': 'albers',
'armadillo': 'armadillo',
'aitoff': 'aitoff',
'albers usa': 'albersUsa',
'albers': 'albers',
// 'armadillo': 'armadillo',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a pattern to the ones we're still omitting?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some of these are now enabled by eb30073.
Let me see if I could easily fix the clipping issue for some other remaining ones...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Most of the remaining ones are interrupted-projections and polyhedral-projections as well as two-point projections , require extra work and attributes and we could say it is outside the scope of this PR.

'august': 'august',
'azimuthal equal area': 'azimuthalEqualArea',
'azimuthal equidistant': 'azimuthalEquidistant',
'baker': 'baker',
'berghaus': 'berghaus',
// 'berghaus': 'berghaus',
'bertin1953': 'bertin1953',
'boggs': 'boggs',
'bonne': 'bonne',
'bottomley': 'bottomley',
'bromley': 'bromley',
// 'chamberlin africa': 'chamberlinAfrica',
// 'chamberlin': 'chamberlin',
'chamberlin africa': 'chamberlinAfrica',
'collignon': 'collignon',
'conic conformal': 'conicConformal',
'conic equal area': 'conicEqualArea',
'conic equidistant': 'conicEquidistant',
'craig': 'craig',
'craster': 'craster',
'cylindrical equal area': 'cylindricalEqualArea',
'cylindrical stereographic': 'cylindricalStereographic',
'eckert1': 'eckert1',
'eckert2': 'eckert2',
'eckert3': 'eckert3',
'eckert4': 'eckert4',
'eckert5': 'eckert5',
'eckert6': 'eckert6',
'eisenlohr': 'eisenlohr',
'equirectangular': 'equirectangular',
'fahey': 'fahey',
'foucaut': 'foucaut',
'foucaut sinusoidal': 'foucautSinusoidal',
'gilbert': 'gilbert',
'gingery': 'gingery',
'foucaut': 'foucaut',
// 'gilbert': 'gilbert',
// 'gingery': 'gingery',
'ginzburg4': 'ginzburg4',
'ginzburg5': 'ginzburg5',
'ginzburg6': 'ginzburg6',
'ginzburg8': 'ginzburg8',
'ginzburg9': 'ginzburg9',
'gnomonic': 'gnomonic',
'gringorten quincuncial': 'gringortenQuincuncial',
'gringorten': 'gringorten',
'guyou': 'guyou',
'hammer retroazimuthal': 'hammerRetroazimuthal',
'healpix': 'healpix',
// 'hammer retroazimuthal': 'hammerRetroazimuthal',
'hammer': 'hammer',
// 'healpix': 'healpix',
'hill': 'hill',
'homolosine': 'homolosine',
'hufnagel': 'hufnagel',
'hyperelliptical': 'hyperelliptical',
// 'interrupted boggs': 'interruptedBoggs',
// 'interrupted homolosine': 'interruptedHomolosine',
// 'interrupted mollweide hemispheres': 'interruptedMollweideHemispheres',
// 'interrupted mollweide': 'interruptedMollweide',
// 'interrupted quartic authalic': 'interruptedQuarticAuthalic',
// 'interrupted sinu mollweide': 'interruptedSinuMollweide',
// 'interrupted sinusoidal': 'interruptedSinusoidal',
'kavrayskiy7': 'kavrayskiy7',
'lagrange': 'lagrange',
'larrivee': 'larrivee',
'laskowski': 'laskowski',
'littrow': 'littrow',
// 'littrow': 'littrow',
'loximuthal': 'loximuthal',
'mercator': 'mercator',
'miller': 'miller',
// 'modified stereographic alaska': 'modifiedStereographicAlaska',
// 'modified stereographic gs48': 'modifiedStereographicGs48',
// 'modified stereographic gs50': 'modifiedStereographicGs50',
// 'modified stereographic lee': 'modifiedStereographicLee',
// 'modified stereographic miller': 'modifiedStereographicMiller',
// 'modified stereographic': 'modifiedStereographic',
'modified stereographic alaska': 'modifiedStereographicAlaska',
'modified stereographic gs48': 'modifiedStereographicGs48',
'modified stereographic gs50': 'modifiedStereographicGs50',
'modified stereographic miller': 'modifiedStereographicMiller',
'modified stereographic lee': 'modifiedStereographicLee',
'mollweide': 'mollweide',
'mt flat polar parabolic': 'mtFlatPolarParabolic',
'mt flat polar quartic': 'mtFlatPolarQuartic',
'mt flat polar sinusoidal': 'mtFlatPolarSinusoidal',
'natural earth': 'naturalEarth',
'natural earth1': 'naturalEarth1',
'natural earth2': 'naturalEarth2',
'nell hammer': 'nellHammer',
'nicolosi': 'nicolosi',
'orthographic': 'orthographic',
'patterson': 'patterson',
'peirce quincuncial': 'peirceQuincuncial',
'polyconic': 'polyconic',
// 'polyhedral butterfly': 'polyhedralButterfly',
// 'polyhedral collignon': 'polyhedralCollignon',
// 'polyhedral waterman': 'polyhedralWaterman',
'rectangular polyconic': 'rectangularPolyconic',
'robinson': 'robinson',
'satellite': 'satellite',
'sinu mollweide': 'sinuMollweide',
'sinusoidal': 'sinusoidal',
'stereographic': 'stereographic',
'times': 'times',
// 'two point azimuthal': 'twoPointAzimuthal',
'transverse mercator': 'transverseMercator',
// 'two point azimuthalUsa': 'twoPointAzimuthalUsa',
// 'two point equidistant': 'twoPointEquidistant',
// 'two point azimuthal': 'twoPointAzimuthal',
// 'two point equidistantUsa': 'twoPointEquidistantUsa',
// 'two point equidistant': 'twoPointEquidistant',
'van der grinten': 'vanDerGrinten',
'van der grinten2': 'vanDerGrinten2',
'van der grinten3': 'vanDerGrinten3',
'van der grinten4': 'vanDerGrinten4',
// 'wagner': 'wagner',
'wagner4': 'wagner4',
'wagner6': 'wagner6',
// 'wagner7': 'wagner7',
// 'wagner': 'wagner',
'wiechel': 'wiechel',
'winkel tripel': 'winkel3',
'winkel3': 'winkel3',

// 'interrupt': 'interrupt',
'interrupted homolosine': 'interruptedHomolosine',
'interrupted sinusoidal': 'interruptedSinusoidal',
'interrupted boggs': 'interruptedBoggs',
'interrupted sinu mollweide': 'interruptedSinuMollweide',
'interrupted mollweide': 'interruptedMollweide',
'interrupted mollweide hemispheres': 'interruptedMollweideHemispheres',
'interrupted quartic authalic': 'interruptedQuarticAuthalic',

'polyhedral butterfly': 'polyhedralButterfly',
'polyhedral collignon': 'polyhedralCollignon',
'polyhedral waterman': 'polyhedralWaterman',

'gringorten quincuncial': 'gringortenQuincuncial',
'peirce quincuncial': 'peirceQuincuncial',
*/
};

// name of the axes
Expand Down
10 changes: 7 additions & 3 deletions src/plots/geo/geo.js
Original file line number Diff line number Diff line change
Expand Up @@ -647,9 +647,9 @@ function getProjection(geoLayout) {
var projFn = geo[projName] || geoProjection[projName];
var projection = projFn();

var clipAngle = geoLayout._isClipped ?
constants.lonaxisSpan[projType] / 2 :
null;
var clipAngle =
geoLayout._isSatellite ? Math.acos(1 / projLayout.distance) * 180 / Math.PI :
geoLayout._isClipped ? constants.lonaxisSpan[projType] / 2 : null;

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

projection.precision(constants.precision);

if(geoLayout._isSatellite) {
projection.tilt(projLayout.tilt).distance(projLayout.distance);
}

if(clipAngle) {
projection.clipAngle(clipAngle - constants.clipPad);
}
Expand Down
18 changes: 18 additions & 0 deletions src/plots/geo/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,24 @@ var attrs = module.exports = overrideAll({
].join(' ')
}
},
tilt: {
valType: 'number',
dflt: 0,
description: [
'For satellite projection type only.',
'Sets the tilt angle of perspective projection.'
].join(' ')
},
distance: {
valType: 'number',
min: 1.001,
dflt: 2,
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.'
].join(' ')
},
parallels: {
valType: 'info_array',
items: [
Expand Down
8 changes: 7 additions & 1 deletion src/plots/geo/layout_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ function handleGeoDefaults(geoLayoutIn, geoLayoutOut, coerce, opts) {
if(isAlbersUsa) scope = geoLayoutOut.scope = 'usa';

var isScoped = geoLayoutOut._isScoped = (scope !== 'world');
var isConic = geoLayoutOut._isConic = projType.indexOf('conic') !== -1;
var isSatellite = geoLayoutOut._isSatellite = projType === 'satellite';
var isConic = geoLayoutOut._isConic = projType.indexOf('conic') !== -1 || projType === 'albers';
var isClipped = geoLayoutOut._isClipped = !!constants.lonaxisSpan[projType];

if(geoLayoutIn.visible === false) {
Expand Down Expand Up @@ -148,6 +149,11 @@ function handleGeoDefaults(geoLayoutIn, geoLayoutOut, coerce, opts) {
coerce('center.lon', centerLonDflt);
coerce('center.lat', centerLatDflt);

if(isSatellite) {
coerce('projection.tilt');
coerce('projection.distance');
}

if(isConic) {
var dfltProjParallels = scopeParams.projParallels || [0, 60];
coerce('projection.parallels', dfltProjParallels);
Expand Down
Binary file added test/image/baselines/canada_geo_projections.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/image/baselines/distance_satellite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/geo_fitbounds-locations.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/image/baselines/various_geo_projections.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading