diff --git a/superset-frontend/plugins/plugin-chart-country-map/src/CountryMap.tsx b/superset-frontend/plugins/plugin-chart-country-map/src/CountryMap.tsx index dfc759685a6..252ef66dd99 100644 --- a/superset-frontend/plugins/plugin-chart-country-map/src/CountryMap.tsx +++ b/superset-frontend/plugins/plugin-chart-country-map/src/CountryMap.tsx @@ -29,7 +29,6 @@ import { extent } from 'd3-array'; import { rgb } from 'd3-color'; import { geoMercator, geoPath } from 'd3-geo'; import { - CategoricalColorNamespace, getNumberFormatter, getSequentialSchemeRegistry, } from '@superset-ui/core'; @@ -131,7 +130,9 @@ const CountryMap: FC = props => { // ---- Load GeoJSON ---------------------------------------------------- useEffect(() => { if (!geoJsonUrl) { - setError('No GeoJSON URL resolved (check worldview / admin_level / country).'); + setError( + 'No GeoJSON URL resolved (check worldview / admin_level / country).', + ); setGeo(null); return; } @@ -168,8 +169,11 @@ const CountryMap: FC = props => { if (!data.length || !metricName) return {}; const numericData = data .map(d => ({ - key: String(d[Object.keys(d).find(k => k !== metricName) || 'key'] ?? ''), - value: typeof d[metricName] === 'number' ? (d[metricName] as number) : NaN, + key: String( + d[Object.keys(d).find(k => k !== metricName) || 'key'] ?? '', + ), + value: + typeof d[metricName] === 'number' ? (d[metricName] as number) : NaN, })) .filter(d => Number.isFinite(d.value)); if (!numericData.length) return {}; @@ -178,9 +182,7 @@ const CountryMap: FC = props => { const scheme = linearColorScheme ? getSequentialSchemeRegistry().get(linearColorScheme) : null; - const linear = scheme - ? scheme.createLinearScale([lo, hi]) - : (() => '#ccc'); + const linear = scheme ? scheme.createLinearScale([lo, hi]) : () => '#ccc'; const out: Record = {}; numericData.forEach(d => { @@ -190,7 +192,10 @@ const CountryMap: FC = props => { }, [data, metricName, linearColorScheme]); const formatter = useMemo( - () => (numberFormat ? getNumberFormatter(numberFormat) : (n: number) => String(n)), + () => + numberFormat + ? getNumberFormatter(numberFormat) + : (n: number) => String(n), [numberFormat], ); @@ -208,7 +213,10 @@ const CountryMap: FC = props => { type: 'FeatureCollection', features: filteredFeatures, }; - const projection = geoMercator().fitSize([width, height], featureCollection); + const projection = geoMercator().fitSize( + [width, height], + featureCollection, + ); const path = geoPath(projection); const ns = 'http://www.w3.org/2000/svg'; @@ -309,7 +317,9 @@ const CountryMap: FC = props => { if (error) { return ( -
+
Error loading map: {error}
); @@ -336,7 +346,19 @@ const CountryMap: FC = props => { )}
)} - {!geo &&
Loading map…
} + {!geo && ( +
+ Loading map… +
+ )} ); }; diff --git a/superset-frontend/plugins/plugin-chart-country-map/src/plugin/controlPanel.tsx b/superset-frontend/plugins/plugin-chart-country-map/src/plugin/controlPanel.tsx index 604e19463e1..7af4ad964f0 100644 --- a/superset-frontend/plugins/plugin-chart-country-map/src/plugin/controlPanel.tsx +++ b/superset-frontend/plugins/plugin-chart-country-map/src/plugin/controlPanel.tsx @@ -254,8 +254,6 @@ const NAME_LANGUAGE_CHOICES: Array<[string, string]> = [ const isAdminCountry = (controls: Record) => controls.admin_level?.value === String(0) || controls.admin_level?.value === 0; -const isAdminSubdivision = (controls: Record) => - controls.admin_level?.value === String(1) || controls.admin_level?.value === 1; const isAdminAggregated = (controls: Record) => controls.admin_level?.value === 'aggregated'; diff --git a/superset-frontend/plugins/plugin-chart-country-map/src/plugin/transformProps.ts b/superset-frontend/plugins/plugin-chart-country-map/src/plugin/transformProps.ts index 0f259cdf2da..6cb1d9b907f 100644 --- a/superset-frontend/plugins/plugin-chart-country-map/src/plugin/transformProps.ts +++ b/superset-frontend/plugins/plugin-chart-country-map/src/plugin/transformProps.ts @@ -18,6 +18,7 @@ */ import { CountryMapChartProps, + CountryMapFormData, CountryMapTransformedProps, } from '../types'; @@ -40,7 +41,8 @@ const GEOJSON_BASE = '/static/assets/country-maps'; export default function transformProps( chartProps: CountryMapChartProps, ): CountryMapTransformedProps { - const { formData, queriesData, width, height } = chartProps; + const { queriesData, width, height } = chartProps; + const formData = chartProps.formData as CountryMapFormData; const data = (queriesData?.[0]?.data as Record[]) ?? []; const worldview = formData.worldview || 'ukr'; @@ -50,11 +52,9 @@ export default function transformProps( if (formData.composite) { geoJsonUrl = `${GEOJSON_BASE}/composite_${formData.composite}_${worldview}.geo.json`; } else if (formData.region_set && formData.country) { - geoJsonUrl = - `${GEOJSON_BASE}/regional_${formData.country}_${formData.region_set}_${worldview}.geo.json`; + geoJsonUrl = `${GEOJSON_BASE}/regional_${formData.country}_${formData.region_set}_${worldview}.geo.json`; } else if (adminLevel === 1 && formData.country) { - geoJsonUrl = - `${GEOJSON_BASE}/${worldview}_admin1_${formData.country}.geo.json`; + geoJsonUrl = `${GEOJSON_BASE}/${worldview}_admin1_${formData.country}.geo.json`; } else if (adminLevel === 0) { geoJsonUrl = `${GEOJSON_BASE}/${worldview}_admin0.geo.json`; } diff --git a/superset-frontend/plugins/plugin-chart-country-map/tsconfig.json b/superset-frontend/plugins/plugin-chart-country-map/tsconfig.json index 8992e79cb1c..9e1fa339c1a 100644 --- a/superset-frontend/plugins/plugin-chart-country-map/tsconfig.json +++ b/superset-frontend/plugins/plugin-chart-country-map/tsconfig.json @@ -4,9 +4,10 @@ "baseUrl": "../..", "outDir": "lib", "rootDir": "src", - "declarationDir": "lib" + "declarationDir": "lib", + "resolveJsonModule": true }, - "include": ["src/**/*.ts", "src/**/*.tsx", "types/**/*"], + "include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.json", "types/**/*"], "exclude": [ "src/**/*.js", "src/**/*.jsx",