jansule opened a new pull request, #25869: URL: https://github.com/apache/superset/pull/25869
<!--- Please write the PR title following the conventions at https://www.conventionalcommits.org/en/v1.0.0/ Example: fix(dashboard): load charts correctly --> ### SUMMARY <!--- Describe the change below, including rationale and design decisions --> This adds a new plugin `plugin-chart-cartodiagram` that allows creating cartodiagrams, i.e. charts on a map. See also https://github.com/apache/superset/discussions/21758. ## How does it work? In order to support as many charts as possible, we created some kind of a meta plugin that takes configurations of any existing chart plugin supported by superset and places it on a map. To do so, we make all charts with a common data source selectable, and inject a group-by property based on a provided geometry column. Then, we use the `buildQuery()` and `transformProps()` functions of each chart in combination with the respective chart component (via the `ChartComponentRegistry`) to render them on a map. Through this, all configuration options of any chart are supported. Additional configuration options for cartodiagrams are: - **Map extent**: Either fit the view to the extent of the chart data (every item should be visible), or defined a custom extent by moving the map to the desired location. - **Background layers**: Add an arbitrary number of background layers to the map. Currently the formats WMS (raster), XYZ (raster) and WFS (vector) in multiple versions are supported. Vector layers can be styled in the explore view. - **Background color of chart**: The background color and opacity of the chart can be configured in order to improve the readability of a chart depending on the configured background layers. - **Corner radius of chart**: Set the corner radius of the wrapping `<div>` element of a chart. - **Zoom based chart size**: Set the chart size for each zoom level in order to avoid cluttering. Predefined functions to compute all values are provided (`fixed`, `linear`, `exponential`). Default layers can be configured in `MainPreset.js` which will be shown by default for every configured cartodiagram panel. Users are able to edit/remove these layers for a single panel in the explore view. Default layers currently include a WMS showing OpenStreetMap data in grayscale. *Disclaimer*: The service providing the OpenStreetMap data is a demo service hosted by terrestris GmbH & Co. KG, which is my employer. On a higher zoomlevel, it shows a watermark for our paid service. The demo server is not recommended to be used in production and we recommend replacing this service. It was just added for others to have a default background map while getting familiar with the plugin and probably should be replaced in the future. ## Technical Details/Requirements Additional libraries: - **[OpenLayers](https://openlayers.org/)** as mapping library - **[GeoStyler](https://geostyler.org/)** for styling of vector data (disclaimer: I am one of the maintainers of GeoStyler) Both libraries are part of the [Open Source Geospatial Foundation](https://www.osgeo.org/), so the chances of future development of those libraries are quite certain. --- In order to make use of above libraries, we had to update some dependencies (e.g. typescript, see also https://github.com/apache/superset/pull/24272), and we also had to make use of `npm dedupe` in order to resolve version conflicts. Unfortunately, this resulted in a nearly complete rewrite of the `package-lock.json`. Due to some version upgrades, we also had to apply some linting fixes, which results in more changed files than actually directly related to this PR. Sorry for that. --- The `<SelectControl>` had to be changed a little to be able to add a customized list of options. We use it to display all charts with a common dataset and also check, if a previously selected chart was updated after the selection. ## Limitations There are some limitations of the plugin, which probably should be addressed in the future: - We currently only support geometries in the coordinate reference system (CRS) `EPSG:3857` (WGS 84 / Pseudo-Mercator). Additional CRSs might be added in the future. - For now, we expect the geometry column to return a GeoJSON point geometry for placing the charts on the map. Additional geometries (e.g. lines and polygons), as well as additional formats (WellKnownText, lat/lon, etc.) might be added in the future. - Rendering performance can be improved and varies strongly depending on the used chart type. - Currently, filters applied to a dashboard are not reflected in the cartodiagram plugin. We would be grateful, if someone can hint us to the right direction for supporting this. --- Since the background layers point to external services, the CSP have to be adjusted. Additional information can be found in the README of the plugin. ## How can this be improved? This PR is just the first step into the direction for additional geospatial support. So there are many things that can be added and improved. Besides the points mentioned above, following points might also be useful: - Adding a FeatureFlag to chart plugins that should be allowed to place on a map is probably a nice feature that was also already discussed with @villebro. To do so, the filter options of the REST API need to be extended. - Improved caching of the charts in the client, in order to reduce the number of rerenderings of a chart. - Adding the geometries of the actual dataset as a background layer and allow styling it. ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF <!--- Skip this if not applicable --> **Example dashboard with some cartodiagrams:**  **Explore view of cartodiagram plugin (configuration):**  **Explore view of cartodiagram plugin (customization):**  **Explore view of cartodiagram plugin (layer configuration):**  **Explore view of cartodiagram plugin (layer styling):**  ### TESTING INSTRUCTIONS <!--- Required! What steps can be taken to manually verify the changes? --> ### ADDITIONAL INFORMATION <!--- Check any relevant boxes with "x" --> <!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue --> - [x] Has associated issue: https://github.com/apache/superset/discussions/21758 - [ ] Required feature flags: - [ ] Changes UI - [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351)) - [ ] Migration is atomic, supports rollback & is backwards-compatible - [ ] Confirm DB migration upgrade and downgrade tested - [ ] Runtime estimates and downtime expectations provided - [x] Introduces new feature or API - [ ] Removes existing feature or API -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
