Skip to content

Conversation

@chesselingfm
Copy link

Added implementation for Datawrapper's choropleth map API

  • Define columns for keys and values
  • Choose your basemap - at this point you have to know Datawrapper's internal name for the basemap
  • Projections
  • Select Key and Value columns from your df (and define ist key column contains leading zeros)
  • define color mode, palettes and colors
  • Map zoom
  • Internal borders
  • Hide empty regions

@palewire
Copy link
Collaborator

Great start!

Here's one thing. If you look in the tests/samples folder you will see that we've packaged some JSON configuration files and data uploads drawn from the real-world charts that Datawrapper includes in its documentation site.

Those are then integrated into tests that verify the code is working. One sample is pulled out and featured in our documentation site with a Pythonic implementation as an example.

Do you think you'd be able to try add those pieces yet?

@palewire palewire requested a review from Copilot October 31, 2025 13:34
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for choropleth maps to the datawrapper library, enabling users to create geographic data visualizations where regions are colored based on data values.

Key changes:

  • New ChoroplethMap class with comprehensive configuration options for data mapping, basemaps, colors, and tooltips
  • Three new enum classes (ColorScale, ColorMode, BasemapProjection) for type-safe configuration
  • Integration with existing library architecture through proper imports and exports

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
datawrapper/charts/enums/color_scale.py Defines ColorScale enum with scale types (linear, log, sqrt, quantile, jenks)
datawrapper/charts/enums/color_mode.py Defines ColorMode enum for gradient vs buckets coloring
datawrapper/charts/enums/basemap_projection.py Defines BasemapProjection enum with map projection types
datawrapper/charts/enums/init.py Exports new enum classes for external use
datawrapper/charts/choropleth_map.py Main implementation with ChoroplethMap class and Tooltip configuration
datawrapper/charts/base.py Adds "d3-maps-choropleth" to supported chart types
datawrapper/charts/init.py Exports ChoroplethMap and related classes
datawrapper/init.py Re-exports ChoroplethMap and enums at package level

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

map_key_attr: str = Field(
default="",
alias="map-key-attr",
description="The attribute in the basemap to match against your keys column (e.g., 'iso-a3', 'fips', 'ags)",
Copy link

Copilot AI Oct 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing closing single quote in the description string. The string should end with 'ags')" instead of 'ags)".

Suggested change
description="The attribute in the basemap to match against your keys column (e.g., 'iso-a3', 'fips', 'ags)",
description="The attribute in the basemap to match against your keys column (e.g., 'iso-a3', 'fips', 'ags')",

Copilot uses AI. Check for mistakes.
Comment on lines +296 to +298
if self.color_scale == "quantile":
interpolation = "equidistant"
elif self.color_scale == "jenks":
Copy link

Copilot AI Oct 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 295 initializes interpolation to 'equidistant', then line 297 redundantly sets it to the same value when color_scale == 'quantile'. The if-condition on line 296-297 has no effect and should be removed.

Suggested change
if self.color_scale == "quantile":
interpolation = "equidistant"
elif self.color_scale == "jenks":
if self.color_scale == "jenks":

Copilot uses AI. Check for mistakes.
@chesselingfm
Copy link
Author

chesselingfm commented Oct 31, 2025 via email

@palewire
Copy link
Collaborator

Yes, that's right. We use this tool to snatch the JSON from the official examples. https://palewi.re/docs/datawrapper-json-bookmarklet/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants