-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add support for Winkel Tripel projection #492
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
84530d9
add winkel tripel geo type
chriddyp 422430d
add new geo projection bundle
etpinard af675c6
use eslint-disable instead of listing in eslintignore
etpinard 8c4721b
move constants/geo_constants to plots/geo/constants:
etpinard 515f2fb
add image test for winkel tripel projection
etpinard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,3 @@ build | |
|
||
test/jasmine/assets/jquery-1.8.3.min.js | ||
src/plots/polar/micropolar.js | ||
src/plots/geo/projections.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
/** | ||
* Copyright 2012-2016, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
|
||
'use strict'; | ||
|
||
var params = module.exports = {}; | ||
|
||
// projection names to d3 function name | ||
params.projNames = { | ||
// d3.geo.projection | ||
'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' | ||
}; | ||
|
||
// name of the axes | ||
params.axesNames = ['lonaxis', 'lataxis']; | ||
|
||
// max longitudinal angular span (EXPERIMENTAL) | ||
params.lonaxisSpan = { | ||
'orthographic': 180, | ||
'azimuthal equal area': 360, | ||
'azimuthal equidistant': 360, | ||
'conic conformal': 180, | ||
'gnomonic': 160, | ||
'stereographic': 180, | ||
'transverse mercator': 180, | ||
'*': 360 | ||
}; | ||
|
||
// max latitudinal angular span (EXPERIMENTAL) | ||
params.lataxisSpan = { | ||
'conic conformal': 150, | ||
'stereographic': 179.5, | ||
'*': 180 | ||
}; | ||
|
||
// defaults for each scope | ||
params.scopeDefaults = { | ||
world: { | ||
lonaxisRange: [-180, 180], | ||
lataxisRange: [-90, 90], | ||
projType: 'equirectangular', | ||
projRotate: [0, 0, 0] | ||
}, | ||
usa: { | ||
lonaxisRange: [-180, -50], | ||
lataxisRange: [15, 80], | ||
projType: 'albers usa' | ||
}, | ||
europe: { | ||
lonaxisRange: [-30, 60], | ||
lataxisRange: [30, 80], | ||
projType: 'conic conformal', | ||
projRotate: [15, 0, 0], | ||
projParallels: [0, 60] | ||
}, | ||
asia: { | ||
lonaxisRange: [22, 160], | ||
lataxisRange: [-15, 55], | ||
projType: 'mercator', | ||
projRotate: [0, 0, 0] | ||
}, | ||
africa: { | ||
lonaxisRange: [-30, 60], | ||
lataxisRange: [-40, 40], | ||
projType: 'mercator', | ||
projRotate: [0, 0, 0] | ||
}, | ||
'north america': { | ||
lonaxisRange: [-180, -45], | ||
lataxisRange: [5, 85], | ||
projType: 'conic conformal', | ||
projRotate: [-100, 0, 0], | ||
projParallels: [29.5, 45.5] | ||
}, | ||
'south america': { | ||
lonaxisRange: [-100, -30], | ||
lataxisRange: [-60, 15], | ||
projType: 'mercator', | ||
projRotate: [0, 0, 0] | ||
} | ||
}; | ||
|
||
// angular pad to avoid rounding error around clip angles | ||
params.clipPad = 1e-3; | ||
|
||
// map projection precision | ||
params.precision = 0.1; | ||
|
||
// default land and water fill colors | ||
params.landColor = '#F0DC82'; | ||
params.waterColor = '#3399FF'; | ||
|
||
// locationmode to layer name | ||
params.locationmodeToLayer = { | ||
'ISO-3': 'countries', | ||
'USA-states': 'subunits', | ||
'country names': 'countries' | ||
}; | ||
|
||
// SVG element for a sphere (use to frame maps) | ||
params.sphereSVG = {type: 'Sphere'}; | ||
|
||
// N.B. base layer names must be the same as in the topojson files | ||
|
||
// base layer with a fill color | ||
params.fillLayers = ['ocean', 'land', 'lakes']; | ||
|
||
// base layer with a only a line color | ||
params.lineLayers = ['subunits', 'countries', 'coastlines', 'rivers', 'frame']; | ||
|
||
// all base layers - in order | ||
params.baseLayers = [ | ||
'ocean', 'land', 'lakes', | ||
'subunits', 'countries', 'coastlines', 'rivers', | ||
'lataxis', 'lonaxis', | ||
'frame' | ||
]; | ||
|
||
params.layerNameToAdjective = { | ||
ocean: 'ocean', | ||
land: 'land', | ||
lakes: 'lake', | ||
subunits: 'subunit', | ||
countries: 'country', | ||
coastlines: 'coastline', | ||
rivers: 'river', | ||
frame: 'frame' | ||
}; | ||
|
||
// base layers drawn over choropleth | ||
params.baseLayersOverChoropleth = ['rivers', 'lakes']; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,18 +6,19 @@ | |
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
/** | ||
* Forked from https://github.com/d3/d3-geo-projection | ||
* Pasted from https://github.com/etpinard/d3-geo-projection | ||
/* | ||
* Generated by https://github.com/etpinard/d3-geo-projection-picker | ||
* | ||
* Containing only the 'most useful' projection types | ||
* and compatible with CommonJs | ||
* which is hand-picks projection from https://github.com/d3/d3-geo-projection | ||
* | ||
* into a CommonJS require-able module. | ||
*/ | ||
|
||
var d3 = require('d3'); | ||
'use strict'; | ||
|
||
/* eslint-disable */ | ||
|
||
function addProjectionToD3() { | ||
function addProjectionsToD3(d3) { | ||
d3.geo.project = function(object, projection) { | ||
var stream = projection.stream; | ||
if (!stream) throw new Error("not yet supported"); | ||
|
@@ -78,7 +79,7 @@ function addProjectionToD3() { | |
d3_geo_projectPoints.push([ x, y ]); | ||
}, | ||
lineEnd: function() { | ||
if (d3_geo_projectPoints.length) d3_geo_projectLines.push(d3_geo_projectPoints), | ||
if (d3_geo_projectPoints.length) d3_geo_projectLines.push(d3_geo_projectPoints), | ||
d3_geo_projectPoints = []; | ||
}, | ||
result: function() { | ||
|
@@ -205,7 +206,7 @@ function addProjectionToD3() { | |
}; | ||
var projection = d3.geo.projection(forward), stream_ = projection.stream; | ||
projection.stream = function(stream) { | ||
var rotate = projection.rotate(), rotateStream = stream_(stream), sphereStream = (projection.rotate([ 0, 0 ]), | ||
var rotate = projection.rotate(), rotateStream = stream_(stream), sphereStream = (projection.rotate([ 0, 0 ]), | ||
stream_(stream)); | ||
projection.rotate(rotate); | ||
rotateStream.sphere = function() { | ||
|
@@ -405,6 +406,39 @@ function addProjectionToD3() { | |
(d3.geo.sinusoidal = function() { | ||
return projection(sinusoidal); | ||
}).raw = sinusoidal; | ||
function aitoff(λ, φ) { | ||
var cosφ = Math.cos(φ), sinciα = sinci(acos(cosφ * Math.cos(λ /= 2))); | ||
return [ 2 * cosφ * Math.sin(λ) * sinciα, Math.sin(φ) * sinciα ]; | ||
} | ||
aitoff.invert = function(x, y) { | ||
if (x * x + 4 * y * y > π * π + ε) return; | ||
var λ = x, φ = y, i = 25; | ||
do { | ||
var sinλ = Math.sin(λ), sinλ_2 = Math.sin(λ / 2), cosλ_2 = Math.cos(λ / 2), sinφ = Math.sin(φ), cosφ = Math.cos(φ), sin_2φ = Math.sin(2 * φ), sin2φ = sinφ * sinφ, cos2φ = cosφ * cosφ, sin2λ_2 = sinλ_2 * sinλ_2, C = 1 - cos2φ * cosλ_2 * cosλ_2, E = C ? acos(cosφ * cosλ_2) * Math.sqrt(F = 1 / C) : F = 0, F, fx = 2 * E * cosφ * sinλ_2 - x, fy = E * sinφ - y, δxδλ = F * (cos2φ * sin2λ_2 + E * cosφ * cosλ_2 * sin2φ), δxδφ = F * (.5 * sinλ * sin_2φ - E * 2 * sinφ * sinλ_2), δyδλ = F * .25 * (sin_2φ * sinλ_2 - E * sinφ * cos2φ * sinλ), δyδφ = F * (sin2φ * cosλ_2 + E * sin2λ_2 * cosφ), denominator = δxδφ * δyδλ - δyδφ * δxδλ; | ||
if (!denominator) break; | ||
var δλ = (fy * δxδφ - fx * δyδφ) / denominator, δφ = (fx * δyδλ - fy * δxδλ) / denominator; | ||
λ -= δλ, φ -= δφ; | ||
} while ((Math.abs(δλ) > ε || Math.abs(δφ) > ε) && --i > 0); | ||
return [ λ, φ ]; | ||
}; | ||
(d3.geo.aitoff = function() { | ||
return projection(aitoff); | ||
}).raw = aitoff; | ||
function winkel3(λ, φ) { | ||
var coordinates = aitoff(λ, φ); | ||
return [ (coordinates[0] + λ / halfπ) / 2, (coordinates[1] + φ) / 2 ]; | ||
} | ||
winkel3.invert = function(x, y) { | ||
var λ = x, φ = y, i = 25; | ||
do { | ||
var cosφ = Math.cos(φ), sinφ = Math.sin(φ), sin_2φ = Math.sin(2 * φ), sin2φ = sinφ * sinφ, cos2φ = cosφ * cosφ, sinλ = Math.sin(λ), cosλ_2 = Math.cos(λ / 2), sinλ_2 = Math.sin(λ / 2), sin2λ_2 = sinλ_2 * sinλ_2, C = 1 - cos2φ * cosλ_2 * cosλ_2, E = C ? acos(cosφ * cosλ_2) * Math.sqrt(F = 1 / C) : F = 0, F, fx = .5 * (2 * E * cosφ * sinλ_2 + λ / halfπ) - x, fy = .5 * (E * sinφ + φ) - y, δxδλ = .5 * F * (cos2φ * sin2λ_2 + E * cosφ * cosλ_2 * sin2φ) + .5 / halfπ, δxδφ = F * (sinλ * sin_2φ / 4 - E * sinφ * sinλ_2), δyδλ = .125 * F * (sin_2φ * sinλ_2 - E * sinφ * cos2φ * sinλ), δyδφ = .5 * F * (sin2φ * cosλ_2 + E * sin2λ_2 * cosφ) + .5, denominator = δxδφ * δyδλ - δyδφ * δxδλ, δλ = (fy * δxδφ - fx * δyδφ) / denominator, δφ = (fx * δyδλ - fy * δxδλ) / denominator; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wat even. |
||
λ -= δλ, φ -= δφ; | ||
} while ((Math.abs(δλ) > ε || Math.abs(δφ) > ε) && --i > 0); | ||
return [ λ, φ ]; | ||
}; | ||
(d3.geo.winkel3 = function() { | ||
return projection(winkel3); | ||
}).raw = winkel3; | ||
} | ||
|
||
module.exports = addProjectionToD3; | ||
module.exports = addProjectionsToD3; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uhhh...