-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix centroid calculation. Bump turf to v6.5 #7115
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
Changes from 7 commits
828fa90
917c05d
715e4ff
a937945
d205bc9
b978c7a
3418503
90ee3da
f4de36e
8a5f221
9c618e3
dd05e55
912244b
8e81005
a6e151a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
- Update turf.js to v7 [[#7115](https://github.com/plotly/plotly.js/pull/7115)] | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,9 @@ | |
|
||
var d3 = require('@plotly/d3'); | ||
var countryRegex = require('country-regex'); | ||
var turfArea = require('@turf/area'); | ||
var turfCentroid = require('@turf/centroid'); | ||
var turfBbox = require('@turf/bbox'); | ||
var { area: turfArea } = require('@turf/area'); | ||
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. Wondering how these imports are transpiled in to the dist? 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. Unless minified will they be kept as a destructuring assignment (plotly-geo.js bundle):
Not sure how to run it in python |
||
var { centroid: turfCentroid } = require('@turf/centroid'); | ||
var { bbox: turfBbox } = require('@turf/bbox'); | ||
|
||
var identity = require('./identity'); | ||
var loggers = require('./loggers'); | ||
|
@@ -226,7 +226,11 @@ function extractTraceFeature(calcTrace) { | |
}; | ||
|
||
// Compute centroid, add it to the properties | ||
fOut.properties.ct = findCentroid(fOut); | ||
if (fOut.geometry.coordinates.length > 0) { | ||
fOut.properties.ct = findCentroid(fOut); | ||
} else { | ||
fOut.properties.ct = [NaN, NaN]; | ||
} | ||
|
||
// Mutate in in/out features into calcdata | ||
cdi.fIn = fIn; | ||
|
@@ -291,7 +295,7 @@ function findCentroid(feature) { | |
|
||
for(var i = 0; i < coords.length; i++) { | ||
var polyi = {type: 'Polygon', coordinates: coords[i]}; | ||
var area = turfArea.default(polyi); | ||
var area = turfArea(polyi); | ||
if(area > maxArea) { | ||
maxArea = area; | ||
poly = polyi; | ||
|
@@ -301,7 +305,7 @@ function findCentroid(feature) { | |
poly = geometry; | ||
} | ||
|
||
return turfCentroid.default(poly).geometry.coordinates; | ||
return turfCentroid(poly).geometry.coordinates; | ||
} | ||
|
||
function fetchTraceGeoData(calcData) { | ||
|
@@ -362,7 +366,7 @@ function fetchTraceGeoData(calcData) { | |
// TODO `turf/bbox` gives wrong result when the input feature/geometry | ||
// crosses the anti-meridian. We should try to implement our own bbox logic. | ||
function computeBbox(d) { | ||
return turfBbox.default(d); | ||
return turfBbox(d); | ||
} | ||
|
||
module.exports = { | ||
|
Uh oh!
There was an error while loading. Please reload this page.