11import { createSelector , createSelectorMemoized } from '@mui/x-internals/store' ;
22import {
3- geoAlbers ,
4- geoAlbersUsa ,
5- geoAzimuthalEqualArea ,
6- geoAzimuthalEquidistant ,
7- geoConicConformal ,
8- geoConicEqualArea ,
9- geoConicEquidistant ,
10- geoEqualEarth ,
11- geoEquirectangular ,
12- geoGnomonic ,
13- geoMercator ,
14- geoNaturalEarth1 ,
15- geoOrthographic ,
16- geoStereographic ,
17- geoTransverseMercator ,
183 geoPath ,
194 type ExtendedFeatureCollection ,
205 type GeoProjection ,
@@ -31,29 +16,6 @@ import { selectorChartDrawingArea } from '../../corePlugins/useChartDimensions/u
3116import { type ChartState } from '../../models/chart' ;
3217import { type GeoTooltipPosition } from '../../corePlugins/useChartSeriesConfig' ;
3318
34- const PROJECTION_FACTORIES : Record < D3NamedProjection , ( ( ) => GeoProjection ) | undefined > = {
35- // Azimuthal projections (https://d3js.org/d3-geo/azimuthal)
36- azimuthalEqualArea : geoAzimuthalEqualArea ,
37- azimuthalEquidistant : geoAzimuthalEquidistant ,
38- gnomonic : geoGnomonic ,
39- orthographic : geoOrthographic ,
40- stereographic : geoStereographic ,
41-
42- // Conic projections (https://d3js.org/d3-geo/conic)
43- conicConformal : geoConicConformal ,
44- conicEqualArea : geoConicEqualArea ,
45- conicEquidistant : geoConicEquidistant ,
46- albers : geoAlbers ,
47- albersUsa : geoAlbersUsa , // Special composition for the USA with an edge case for Alaska and Hawaii.
48-
49- // Cylindrical projections (https://d3js.org/d3-geo/cylindrical)
50- equirectangular : geoEquirectangular ,
51- mercator : geoMercator ,
52- transverseMercator : geoTransverseMercator ,
53- equalEarth : geoEqualEarth ,
54- naturalEarth1 : geoNaturalEarth1 ,
55- } ;
56-
5719const isConicProjection = ( projection : GeoProjection ) : projection is GeoConicProjection => {
5820 return 'parallels' in projection && typeof projection . parallels === 'function' ;
5921} ;
@@ -73,6 +35,12 @@ export const selectorChartRawProjection = createSelector(
7335 ( geoProjection ) : GeoProjectionInput | null => geoProjection ?. projection ?? null ,
7436) ;
7537
38+ export const selectorChartProjectionFactory = createSelector (
39+ selectorChartGeoProjectionState ,
40+ ( geoProjection ) : Record < D3NamedProjection , ( ( ) => GeoProjection ) | undefined > | null =>
41+ geoProjection ?. factories ?? null ,
42+ ) ;
43+
7644export const selectorChartRawScale = createSelector (
7745 selectorChartGeoProjectionState ,
7846 ( geoProjection ) : number | null => geoProjection ?. scale ?? null ,
@@ -133,6 +101,7 @@ export const selectorChartGeoFeatureIndexesByName = createSelectorMemoized(
133101 */
134102export const selectorChartProjection = createSelectorMemoized (
135103 selectorChartRawProjection ,
104+ selectorChartProjectionFactory ,
136105 selectorChartGeoData ,
137106 selectorChartParallels ,
138107 selectorChartRotate ,
@@ -141,24 +110,25 @@ export const selectorChartProjection = createSelectorMemoized(
141110 selectorChartDrawingArea ,
142111 (
143112 projectionInput ,
113+ projectionFactory ,
144114 geoData ,
145115 parallels ,
146116 rotate ,
147117 translate ,
148118 scale ,
149119 drawingArea ,
150120 ) : GeoProjection | null => {
151- if ( ! projectionInput ) {
121+ if ( ! projectionInput || ! projectionFactory ) {
152122 return null ;
153123 }
154124 let projection : GeoProjection ;
155125 if ( typeof projectionInput === 'string' ) {
156- const factory = PROJECTION_FACTORIES [ projectionInput ] ;
126+ const factory = projectionFactory [ projectionInput ] ;
157127 if ( ! factory ) {
158128 if ( process . env . NODE_ENV !== 'production' ) {
159129 console . error (
160130 `MUI X Charts: Unknown projection name '${ projectionInput } '. ` +
161- `Expected one of: ${ Object . keys ( PROJECTION_FACTORIES ) . join ( ', ' ) } .` ,
131+ `Expected one of: ${ Object . keys ( projectionFactory ) . join ( ', ' ) } .` ,
162132 ) ;
163133 }
164134 return null ;
0 commit comments