Skip to content

Commit 19a001d

Browse files
committed
apply latest d3-geo and d3-geo-projection
1 parent 45f4513 commit 19a001d

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

package-lock.json

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@
7272
"convex-hull": "^1.0.3",
7373
"country-regex": "^1.1.0",
7474
"d3-force": "^1.2.1",
75+
"d3-geo": "^1.12.1",
76+
"d3-geo-projection": "^2.9.0",
7577
"d3-hierarchy": "^1.1.9",
7678
"d3-interpolate": "^1.4.0",
7779
"d3-time-format": "^2.2.3",

src/plots/geo/geo.js

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

1313
var d3 = require('@plotly/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');
@@ -33,8 +37,6 @@ var geoUtils = require('../../lib/geo_location_utils');
3337
var topojsonUtils = require('../../lib/topojson_utils');
3438
var topojsonFeature = require('topojson-client').feature;
3539

36-
require('./projections')(d3);
37-
3840
function Geo(opts) {
3941
this.id = opts.id;
4042
this.graphDiv = opts.graphDiv;
@@ -656,7 +658,7 @@ proto.render = function() {
656658
}
657659
};
658660

659-
// Helper that wraps d3.geo[/* projection name /*]() which:
661+
// Helper that wraps d3[geo + /* Projection name /*]() which:
660662
//
661663
// - adds 'fitExtent' (available in d3 v4)
662664
// - adds 'getPath', 'getBounds' convenience methods
@@ -671,7 +673,11 @@ function getProjection(geoLayout) {
671673
var projLayout = geoLayout.projection;
672674
var projType = projLayout.type;
673675

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

676682
var clipAngle = geoLayout._isClipped ?
677683
constants.lonaxisSpan[projType] / 2 :
@@ -694,7 +700,7 @@ function getProjection(geoLayout) {
694700

695701
if(clipAngle) {
696702
var r = projection.rotate();
697-
var angle = d3.geo.distance(lonlat, [-r[0], -r[1]]);
703+
var angle = geoDistance(lonlat, [-r[0], -r[1]]);
698704
var maxAngle = clipAngle * Math.PI / 180;
699705
return angle > maxAngle;
700706
} else {
@@ -703,7 +709,7 @@ function getProjection(geoLayout) {
703709
};
704710

705711
projection.getPath = function() {
706-
return d3.geo.path().projection(projection);
712+
return geoPath().projection(projection);
707713
};
708714

709715
projection.getBounds = function(object) {

0 commit comments

Comments
 (0)