Skip to content

Commit 956ae00

Browse files
committed
apply latest d3-geo and d3-geo-projection
1 parent 4ac68aa commit 956ae00

File tree

4 files changed

+33
-450
lines changed

4 files changed

+33
-450
lines changed

package-lock.json

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@
7070
"country-regex": "^1.1.0",
7171
"d3": "^3.5.17",
7272
"d3-force": "^1.2.1",
73+
"d3-geo": "^1.12.1",
74+
"d3-geo-projection": "^2.9.0",
7375
"d3-hierarchy": "^1.1.9",
7476
"d3-interpolate": "^1.4.0",
7577
"d3-time-format": "^2.2.3",

src/plots/geo/geo.js

+12-6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
/* global PlotlyGeoAssets:false */
1212

1313
var d3 = require('d3');
14+
var geo = require('d3-geo');
15+
var geoPath = require('d3-geo').geoPath;
16+
var geoDistance = require('d3-geo').geoDistance;
17+
var geoProjection = require('d3-geo-projection');
1418

1519
var Registry = require('../../registry');
1620
var Lib = require('../../lib');
@@ -32,8 +36,6 @@ var geoUtils = require('../../lib/geo_location_utils');
3236
var topojsonUtils = require('../../lib/topojson_utils');
3337
var topojsonFeature = require('topojson-client').feature;
3438

35-
require('./projections')(d3);
36-
3739
function Geo(opts) {
3840
this.id = opts.id;
3941
this.graphDiv = opts.graphDiv;
@@ -655,7 +657,7 @@ proto.render = function() {
655657
}
656658
};
657659

658-
// Helper that wraps d3.geo[/* projection name /*]() which:
660+
// Helper that wraps d3[geo + /* Projection name /*]() which:
659661
//
660662
// - adds 'fitExtent' (available in d3 v4)
661663
// - adds 'getPath', 'getBounds' convenience methods
@@ -670,7 +672,11 @@ function getProjection(geoLayout) {
670672
var projLayout = geoLayout.projection;
671673
var projType = projLayout.type;
672674

673-
var projection = d3.geo[constants.projNames[projType]]();
675+
var projName = constants.projNames[projType];
676+
// uppercase the first letter and add geo to the start of method name
677+
projName = 'geo' + projName.charAt(0).toUpperCase() + projName.slice(1);
678+
var projFn = geo[projName] || geoProjection[projName];
679+
var projection = projFn();
674680

675681
var clipAngle = geoLayout._isClipped ?
676682
constants.lonaxisSpan[projType] / 2 :
@@ -693,7 +699,7 @@ function getProjection(geoLayout) {
693699

694700
if(clipAngle) {
695701
var r = projection.rotate();
696-
var angle = d3.geo.distance(lonlat, [-r[0], -r[1]]);
702+
var angle = geoDistance(lonlat, [-r[0], -r[1]]);
697703
var maxAngle = clipAngle * Math.PI / 180;
698704
return angle > maxAngle;
699705
} else {
@@ -702,7 +708,7 @@ function getProjection(geoLayout) {
702708
};
703709

704710
projection.getPath = function() {
705-
return d3.geo.path().projection(projection);
711+
return geoPath().projection(projection);
706712
};
707713

708714
projection.getBounds = function(object) {

0 commit comments

Comments
 (0)