From 1b6ad26eaafd04f2962e62ffc737d6960b339e22 Mon Sep 17 00:00:00 2001 From: yong1le Date: Mon, 6 Oct 2025 16:15:32 -0400 Subject: [PATCH 1/3] fix(chart): cross-filtering on cca2 country code --- .../src/WorldMap.js | 24 +++++++++++++++---- superset/viz.py | 1 + 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/superset-frontend/plugins/legacy-plugin-chart-world-map/src/WorldMap.js b/superset-frontend/plugins/legacy-plugin-chart-world-map/src/WorldMap.js index 2fd9e5f6a470..92ce8eef384d 100644 --- a/superset-frontend/plugins/legacy-plugin-chart-world-map/src/WorldMap.js +++ b/superset-frontend/plugins/legacy-plugin-chart-world-map/src/WorldMap.js @@ -31,6 +31,7 @@ const propTypes = { data: PropTypes.arrayOf( PropTypes.shape({ country: PropTypes.string, + country_cca2: PropTypes.string, latitude: PropTypes.number, longitude: PropTypes.number, name: PropTypes.string, @@ -115,8 +116,15 @@ function WorldMap(element, props) { const getCrossFilterDataMask = source => { const selected = Object.values(filterState.selectedValues || {}); const key = source.id || source.country; - const country = - countryFieldtype === 'name' ? mapData[key]?.name : mapData[key]?.country; + + let country; + if (countryFieldtype === 'name') { + country = mapData[key]?.name; + } else if (countryFieldtype === 'cca2') { + country = mapData[key]?.country_cca2; + } else { + country = mapData[key]?.country; + } if (!country) { return undefined; @@ -169,8 +177,16 @@ function WorldMap(element, props) { const pointerEvent = d3.event; pointerEvent.preventDefault(); const key = source.id || source.country; - const val = - countryFieldtype === 'name' ? mapData[key]?.name : mapData[key]?.country; + + let val; + if (countryFieldtype === 'name') { + val = mapData[key]?.name; + } else if (countryFieldtype === 'cca2') { + val = mapData[key]?.country_cca2; + } else { + val = mapData[key]?.country; + } + let drillToDetailFilters; let drillByFilters; if (val) { diff --git a/superset/viz.py b/superset/viz.py index b5a4d5217ba5..3b50aea145d0 100644 --- a/superset/viz.py +++ b/superset/viz.py @@ -1313,6 +1313,7 @@ def get_data(self, df: pd.DataFrame) -> VizData: self.form_data["country_fieldtype"], row["country"] ) if country: + row["country_cca2"] = country["cca2"] row["country"] = country["cca3"] row["latitude"] = country["lat"] row["longitude"] = country["lng"] From 25776cb174097c11e532c01c34c9aaf185dbc87b Mon Sep 17 00:00:00 2001 From: yong1le Date: Sun, 26 Oct 2025 19:39:21 -0400 Subject: [PATCH 2/3] refactor(chart): separate filter codes from display code format --- .../legacy-plugin-chart-world-map/src/WorldMap.js | 14 +++++++++++--- superset/viz.py | 6 +++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/superset-frontend/plugins/legacy-plugin-chart-world-map/src/WorldMap.js b/superset-frontend/plugins/legacy-plugin-chart-world-map/src/WorldMap.js index 92ce8eef384d..7a0ac99698c3 100644 --- a/superset-frontend/plugins/legacy-plugin-chart-world-map/src/WorldMap.js +++ b/superset-frontend/plugins/legacy-plugin-chart-world-map/src/WorldMap.js @@ -31,7 +31,11 @@ const propTypes = { data: PropTypes.arrayOf( PropTypes.shape({ country: PropTypes.string, - country_cca2: PropTypes.string, + codes: PropTypes.shape({ + cca2: PropTypes.string, + cca3: PropTypes.string, + cioc: PropTypes.string, + }), latitude: PropTypes.number, longitude: PropTypes.number, name: PropTypes.string, @@ -121,7 +125,9 @@ function WorldMap(element, props) { if (countryFieldtype === 'name') { country = mapData[key]?.name; } else if (countryFieldtype === 'cca2') { - country = mapData[key]?.country_cca2; + country = mapData[key]?.codes?.cca2; + } else if (countryFieldtype === 'cioc') { + country = mapData[key]?.codes?.cioc; } else { country = mapData[key]?.country; } @@ -182,7 +188,9 @@ function WorldMap(element, props) { if (countryFieldtype === 'name') { val = mapData[key]?.name; } else if (countryFieldtype === 'cca2') { - val = mapData[key]?.country_cca2; + val = mapData[key]?.codes?.cca2; + } else if (countryFieldtype === 'cioc') { + val = mapData[key]?.codes?.cioc; } else { val = mapData[key]?.country; } diff --git a/superset/viz.py b/superset/viz.py index 3b50aea145d0..6b324ce23c88 100644 --- a/superset/viz.py +++ b/superset/viz.py @@ -1313,7 +1313,11 @@ def get_data(self, df: pd.DataFrame) -> VizData: self.form_data["country_fieldtype"], row["country"] ) if country: - row["country_cca2"] = country["cca2"] + row["codes"] = { + "cca2": country["cca2"], + "cca3": country["cca3"], + "cioc": country["cioc"], + } row["country"] = country["cca3"] row["latitude"] = country["lat"] row["longitude"] = country["lng"] From bedc5709dd26d86762e25a7cac635f5e3524d5be Mon Sep 17 00:00:00 2001 From: yong1le Date: Thu, 6 Nov 2025 17:41:01 -0500 Subject: [PATCH 3/3] refactor(chart): only send required code instead of all --- .../src/WorldMap.js | 33 +++---------------- superset/viz.py | 6 +--- 2 files changed, 6 insertions(+), 33 deletions(-) diff --git a/superset-frontend/plugins/legacy-plugin-chart-world-map/src/WorldMap.js b/superset-frontend/plugins/legacy-plugin-chart-world-map/src/WorldMap.js index 7a0ac99698c3..36fb436e2e32 100644 --- a/superset-frontend/plugins/legacy-plugin-chart-world-map/src/WorldMap.js +++ b/superset-frontend/plugins/legacy-plugin-chart-world-map/src/WorldMap.js @@ -31,11 +31,7 @@ const propTypes = { data: PropTypes.arrayOf( PropTypes.shape({ country: PropTypes.string, - codes: PropTypes.shape({ - cca2: PropTypes.string, - cca3: PropTypes.string, - cioc: PropTypes.string, - }), + code: PropTypes.string, latitude: PropTypes.number, longitude: PropTypes.number, name: PropTypes.string, @@ -120,17 +116,8 @@ function WorldMap(element, props) { const getCrossFilterDataMask = source => { const selected = Object.values(filterState.selectedValues || {}); const key = source.id || source.country; - - let country; - if (countryFieldtype === 'name') { - country = mapData[key]?.name; - } else if (countryFieldtype === 'cca2') { - country = mapData[key]?.codes?.cca2; - } else if (countryFieldtype === 'cioc') { - country = mapData[key]?.codes?.cioc; - } else { - country = mapData[key]?.country; - } + const country = + countryFieldtype === 'name' ? mapData[key]?.name : mapData[key]?.code; if (!country) { return undefined; @@ -183,18 +170,8 @@ function WorldMap(element, props) { const pointerEvent = d3.event; pointerEvent.preventDefault(); const key = source.id || source.country; - - let val; - if (countryFieldtype === 'name') { - val = mapData[key]?.name; - } else if (countryFieldtype === 'cca2') { - val = mapData[key]?.codes?.cca2; - } else if (countryFieldtype === 'cioc') { - val = mapData[key]?.codes?.cioc; - } else { - val = mapData[key]?.country; - } - + const val = + countryFieldtype === 'name' ? mapData[key]?.name : mapData[key]?.code; let drillToDetailFilters; let drillByFilters; if (val) { diff --git a/superset/viz.py b/superset/viz.py index 6b324ce23c88..b9c242628cb4 100644 --- a/superset/viz.py +++ b/superset/viz.py @@ -1313,11 +1313,7 @@ def get_data(self, df: pd.DataFrame) -> VizData: self.form_data["country_fieldtype"], row["country"] ) if country: - row["codes"] = { - "cca2": country["cca2"], - "cca3": country["cca3"], - "cioc": country["cioc"], - } + row["code"] = country[self.form_data["country_fieldtype"]] row["country"] = country["cca3"] row["latitude"] = country["lat"] row["longitude"] = country["lng"]