@@ -114,7 +114,7 @@ const projections = {
114
114
} ,
115
115
aitoff ( [ lon , lat ] , width , height , center ) {
116
116
if ( ! Math . sinc ) {
117
- Math . sinc = function ( x ) {
117
+ Math . sinc = function ( x ) {
118
118
return x === 0 ? 1 : Math . sin ( Math . PI * x ) / ( Math . PI * x ) ;
119
119
} ;
120
120
}
@@ -140,7 +140,7 @@ const projections = {
140
140
const y = height / 2 - height / 2 * ( Math . SQRT2 * Math . sin ( φ ) / denom ) / 1.4142135623730951 ;
141
141
return [ x , y ] ;
142
142
} ,
143
- bonne ( [ lon , lat ] , width , height , center = [ 0 , 0 ] ) {
143
+ bonne ( [ lon , lat ] , width , height , center = [ 0 , 0 ] ) {
144
144
const φ = 45 * Math . PI / 180 ;
145
145
const [ lon0 , _lat0 ] = center ;
146
146
const λ = ( lon - lon0 ) * Math . PI / 180 ;
@@ -196,7 +196,7 @@ const projections = {
196
196
x = Math . sign ( λ ) * pi * ( A * G_P2 + Math . sqrt ( Math . max ( 0 , A2 * G_P2 * G_P2 - P2_A2 * ( G * G - P2 ) ) ) ) / P2_A2 ;
197
197
y = Math . sign ( φ ) * pi * ( P * Q - A * Math . sqrt ( Math . max ( 0 , ( A2 + 1 ) * P2_A2 - Q * Q ) ) ) / P2_A2 ;
198
198
}
199
- const scale = ( width / 2 ) / pi * 0.98 ;
199
+ const scale = ( width / 2 ) / pi * 0.98 ;
200
200
const cx = width / 2 , cy = height / 2 ;
201
201
return [ cx + x * scale , cy - y * scale ] ;
202
202
} ,
@@ -253,7 +253,7 @@ function geoToPath(geometry) {
253
253
return '' ;
254
254
}
255
255
256
- function getProjectedBounds ( projection , features , width , height , center = [ 0 , 0 ] ) {
256
+ function getProjectedBounds ( projection , features , width , height , center = [ 0 , 0 ] ) {
257
257
let minX = Infinity , minY = Infinity , maxX = - Infinity , maxY = - Infinity ;
258
258
for ( const feature of features ) {
259
259
const geom = feature . geometry ;
@@ -281,10 +281,50 @@ function getProjectedBounds(projection, features, width, height, center = [0,0])
281
281
}
282
282
}
283
283
284
+ function mergeCountries ( features , parent , child ) {
285
+ const parentFeature = features . find (
286
+ f => ( f . properties . admin === parent || f . properties . name === parent )
287
+ ) ;
288
+ const childFeature = features . find (
289
+ f => ( f . properties . admin === child || f . properties . name === child )
290
+ ) ;
291
+ if ( parentFeature && childFeature ) {
292
+ if ( parentFeature . geometry . type === 'Polygon' ) {
293
+ parentFeature . geometry = {
294
+ type : 'MultiPolygon' ,
295
+ coordinates : [ parentFeature . geometry . coordinates ]
296
+ } ;
297
+ }
298
+ if ( childFeature . geometry . type === 'Polygon' ) {
299
+ parentFeature . geometry . coordinates . push ( childFeature . geometry . coordinates ) ;
300
+ } else if ( childFeature . geometry . type === 'MultiPolygon' ) {
301
+ parentFeature . geometry . coordinates . push ( ...childFeature . geometry . coordinates ) ;
302
+ }
303
+ features = features . filter (
304
+ f => ! ( f . properties . admin === child || f . properties . name === child )
305
+ ) ;
306
+ }
307
+ return features
308
+ }
309
+
310
+ function setupTerritories ( config , geoData ) {
311
+ let features = Array . isArray ( geoData )
312
+ ? geoData . map ( f => ( { ...f } ) )
313
+ : ( geoData . features ? geoData . features . map ( f => ( { ...f } ) ) : [ ] ) ;
314
+
315
+ if ( config . style . chart . territory . showTaiwanAsPartOfChina ) {
316
+ features = mergeCountries ( features , 'China' , 'Taiwan' ) ;
317
+ }
318
+ if ( geoData . type === 'FeatureCollection' ) {
319
+ return { ...geoData , features } ;
320
+ }
321
+ return features ;
322
+ }
284
323
285
324
const geo = {
286
325
projections,
287
326
getProjectedBounds,
327
+ setupTerritories
288
328
}
289
329
290
330
export default geo
0 commit comments