superset icon indicating copy to clipboard operation
superset copied to clipboard

Map crossfilter doesn't work

Open Mavyre opened this issue 2 years ago • 4 comments

When creating a map chart, with a country field type other than CCA3, the map crossfilter doesn't work. It seems like the map crossfilter always filter columns with a CCA3 code.

How to reproduce the bug

  1. Create a map chart (with a CCA2 code column for instance)
  2. Add it to a dashboard, along with other charts
  3. Click any country to trigger cross filter

Expected results

The other charts should be filtered out correctly

Actual results

Other charts are empty

Screenshots

image image

Environment

(please complete the following information):

  • browser type and version: Brave 1.57.47; Chromium: 116.0.5845.96
  • Docker container: apache/superset:latest-dev

Checklist

Make sure to follow these steps before submitting your issue - thank you!

  • [X] I have checked the superset logs for python stacktraces and included it here as text if there are any.
  • [X] I have reproduced the issue with at least the latest released version of superset.
  • [X] I have checked the issue tracker for the same issue and I haven't found one similar.

Mavyre avatar Sep 06 '23 19:09 Mavyre

This works in current versions. Thanks for reporting nonetheless!

rusackas avatar Mar 08 '24 20:03 rusackas

This is still broken on master so the ticket should reopend. @rusackas might only have tested the "Full name" option as it is handled separately in an extra code path: https://github.com/apache/superset/blob/9db431b4303fb83b79584d254bd0344ade117381/superset-frontend/plugins/legacy-plugin-chart-world-map/src/WorldMap.js#L118

But as seen here, the "country" field will always have the cca3 value. That is indeed required for visualization: https://github.com/apache/superset/blob/9db431b4303fb83b79584d254bd0344ade117381/superset/viz.py#L1564

But to use a crossfilter it is required to also forward the actual value of the row to hand back to the filter, this is the patch we are using which fixes the issues:

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 540097be2..c866486fd 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
@@ -30,6 +30,7 @@ import { ColorBy } from './utils';
 const propTypes = {
   data: PropTypes.arrayOf(
     PropTypes.shape({
+      value: PropTypes.string,
       country: PropTypes.string,
       latitude: PropTypes.number,
       longitude: PropTypes.number,
@@ -114,8 +115,7 @@ 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;
+    const country = mapData[key]?.value;
 
     if (!country) {
       return undefined;
diff --git a/superset/viz.py b/superset/viz.py
index 8ba785ddc..b5ef29119 100644
--- a/superset/viz.py
+++ b/superset/viz.py
@@ -1608,6 +1608,7 @@ class WorldMapViz(BaseViz):
                         self.form_data["country_fieldtype"], row["country"]
                     )
             if country:
+                row["value"] = row["country"]
                 row["country"] = country["cca3"]
                 row["latitude"] = country["lat"]
                 row["longitude"] = country["lng"]

doctorseus avatar Apr 24 '24 11:04 doctorseus

Oh how great it would be to whittle away at viz.py until it's gone for good. If there's a PR to be had that will improve the situation for all, we'd welcome it! (cc @villebro)

rusackas avatar Apr 24 '24 14:04 rusackas

Please, fix this. I have cca2 country values in other charts.

slyseinstrument avatar May 03 '24 09:05 slyseinstrument

This issue is also coming up in my situation. Having CCA2 country codes and as a result the cross-filtering does not work as expected. My source is Matomo data. So +1 from me.

jaroet avatar May 28 '24 07:05 jaroet

Also come across this.

dmarkey avatar Sep 09 '24 23:09 dmarkey

all.csv Ah solution was join iso2 -> iso3 using this.

dmarkey avatar Sep 10 '24 00:09 dmarkey