@@ -114,7 +114,7 @@ const projections = {
114114 } ,
115115 aitoff ( [ lon , lat ] , width , height , center ) {
116116 if ( ! Math . sinc ) {
117- Math . sinc = function ( x ) {
117+ Math . sinc = function ( x ) {
118118 return x === 0 ? 1 : Math . sin ( Math . PI * x ) / ( Math . PI * x ) ;
119119 } ;
120120 }
@@ -140,7 +140,7 @@ const projections = {
140140 const y = height / 2 - height / 2 * ( Math . SQRT2 * Math . sin ( φ ) / denom ) / 1.4142135623730951 ;
141141 return [ x , y ] ;
142142 } ,
143- bonne ( [ lon , lat ] , width , height , center = [ 0 , 0 ] ) {
143+ bonne ( [ lon , lat ] , width , height , center = [ 0 , 0 ] ) {
144144 const φ = 45 * Math . PI / 180 ;
145145 const [ lon0 , _lat0 ] = center ;
146146 const λ = ( lon - lon0 ) * Math . PI / 180 ;
@@ -196,7 +196,7 @@ const projections = {
196196 x = Math . sign ( λ ) * pi * ( A * G_P2 + Math . sqrt ( Math . max ( 0 , A2 * G_P2 * G_P2 - P2_A2 * ( G * G - P2 ) ) ) ) / P2_A2 ;
197197 y = Math . sign ( φ ) * pi * ( P * Q - A * Math . sqrt ( Math . max ( 0 , ( A2 + 1 ) * P2_A2 - Q * Q ) ) ) / P2_A2 ;
198198 }
199- const scale = ( width / 2 ) / pi * 0.98 ;
199+ const scale = ( width / 2 ) / pi * 0.98 ;
200200 const cx = width / 2 , cy = height / 2 ;
201201 return [ cx + x * scale , cy - y * scale ] ;
202202 } ,
@@ -253,7 +253,7 @@ function geoToPath(geometry) {
253253 return '' ;
254254}
255255
256- function getProjectedBounds ( projection , features , width , height , center = [ 0 , 0 ] ) {
256+ function getProjectedBounds ( projection , features , width , height , center = [ 0 , 0 ] ) {
257257 let minX = Infinity , minY = Infinity , maxX = - Infinity , maxY = - Infinity ;
258258 for ( const feature of features ) {
259259 const geom = feature . geometry ;
@@ -281,10 +281,50 @@ function getProjectedBounds(projection, features, width, height, center = [0,0])
281281 }
282282}
283283
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+ }
284323
285324const geo = {
286325 projections,
287326 getProjectedBounds,
327+ setupTerritories
288328}
289329
290330export default geo
0 commit comments