Plotly.js: Add support for custom geojson polygons in choropleth traces

Created on 10 Oct 2019  路  13Comments  路  Source: plotly/plotly.js

Locationmode right now only accepts these 3 options: "ISO-3" | "USA-states" | "country names"

I want to make choropleth maps for different countries on provinces level, as equivalent to _locationmode: "USA-states"_. Instead of defining a new _locationmode_ for every country, like "BRA-states" or "ESP-states" maybe it would be better to define a new generic one calles "province" and afterwards define the country using _locations_ option.

feature

All 13 comments

Our current topojson files (built in https://github.com/etpinard/sane-topojson using Natural Earth data) contain:

  • (only) USA states for the 110m resolution
  • USA, Brazil and Australian states + Canadian provinces at 50m

The "full" subunit lists are available here.


In general, we can't use a single locationmode value for all these subunits because they have overlapping values. For example, 'WA' means both Washington state and Western Australia.


I suspect what you're _really_ looking for is either:

  • Add topojson files for the 10m resolution to have subunits from more countries available to choropleth traces. We would consider doing this only for scoped geo maps, as in the 'world' scope rendering would be too slow (in SVG at least)
  • To provide your own "subunit" topojson (or geojson) in choropleth traces, similar how choroplethmapbox does it.

@nicolaskruchten I suspect you're looking for us to implement

  • To provide your own "subunit" topojson (or geojson) in choropleth traces, similar how choroplethmapbox does it.

item here?

Yup. TopoJSON optional for now but basically the same API as we did for mapbox would be great, plus some automatic bounding box logic

  • To provide your own "subunit" topojson (or geojson) in choropleth traces, similar how choroplethmapbox does it.

Yes, that's what I'm looking for. The first option also would be nice, but actually it's not hard to make (or find) topojson files for different countries.

Thanks for translating my description into a proper feature request.

Here's my WIP branch:

where a new locationmode value is added in choropleth and scattergeo traces called 'geojson-id' and where much of the corresponding choroplethmapbox logic is reused.


Now regarding

plus some automatic bounding box logic

This is essentially the geo subplot version of https://github.com/plotly/plotly.js/issues/3434. To me, it makes more sense to implement this at the subplot level.

I'm thinking of adding a new layout.geo attribute named fitbounds which would be false by default. When turned on, we would compute the bounds of the data in all traces (i.e. lon/lat pts for scattergeo, polygons for choropleth) on the subplot and "fit" them (i.e. compute the corresponding projection.scale and translation) before first render. This would essentially be an "opt-on" version of our autorange routine.

That's probably a couple more days of work; nothing substantial. Does that sound ok?

... oops, I forgot to paste the link to the demo:https://codepen.io/etpinard/pen/zYxOoEB

That's probably a couple more days of work; nothing substantial. Does that sound ok?

Yes! Can we default it to true for geo subplots that contain only choropleth in geojson mode... somehow?

Also: this would be geo-only right? we would add it to mapbox some other day?

Can we default it to true for geo subplots that contain only choropleth in geojson mode... somehow?

We could, but I'd vote against it for consistency with choroplethmapbox.

Also: this would be geo-only right? we would add it to mapbox some other day?

Yes, that's the plan for v1.52.0

what would fitbounds do when not using geojson and/or in the presence of scope?

Having thought about this a bit, I think fitbounds would need to accept two modes, in addition to "off"... One scoped to the entire geojson, and one scoped to locations-only.

Having thought about this a bit, I think fitbounds would need to accept two modes, in addition to "off"... One scoped to the entire geojson, and one scoped to locations-only.

Sure, good call.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

WG- picture WG-  路  3Comments

jonmmease picture jonmmease  路  3Comments

emanuelsetitinger picture emanuelsetitinger  路  3Comments

chriddyp picture chriddyp  路  3Comments

etpinard picture etpinard  路  3Comments