Skip to content

feat: add DensityMap trace for the MapLibre map subplot#416

Open
jqnatividad wants to merge 4 commits into
plotly:mainfrom
dathere:feat/density-map-upstream
Open

feat: add DensityMap trace for the MapLibre map subplot#416
jqnatividad wants to merge 4 commits into
plotly:mainfrom
dathere:feat/density-map-upstream

Conversation

@jqnatividad

Copy link
Copy Markdown
Contributor

Summary

plotly.rs has ChoroplethMap for the modern MapLibre map subplot (layout.map), but no density-heatmap trace for it. plotly.js provides densitymap as the MapLibre-based successor to the (Mapbox-based, now deprecated) densitymapbox. This PR adds a matching DensityMap Rust trace.

Closes #414.

⚠️ Stacked on #410

DensityMap is drawn on the MapLibre map subplot introduced in #410, so this PR is stacked on top of #410 and should be reviewed/merged after it. Until #410 merges, the diff here also shows #410's commits; once #410 lands in main, this diff reduces to just the DensityMap addition. (Depends on #410.)

What changed

New DensityMap<Lat, Lon, Z> trace mirroring ChoroplethMap's structure with a density data model (no marker/selected/unselected — density traces have none):

  • Data: lat, lon, z (per-point weight), radius, opacity
  • Color: zauto, zmin/zmax/zmid, colorscale, autocolorscale, reversescale, showscale, colorbar, coloraxis
  • Hover: text, hovertext, hoverinfo, hovertemplate, hovertemplatefallback, hoverlabel
  • Map/misc: subplot (defaults to "map"), below, ids, meta, customdata, uirevision

Registration: a DensityMap variant on PlotType (serializes to "densitymap"), plus module/type re-exports in traces/mod.rs and lib.rs. Includes a serialize_density_map unit test and a doctest.

Testing

  • cargo test -p plotlyserialize_density_map and its doctest pass.
  • cargo clippy --features all -- -D warnings -A deprecated — clean.
  • cargo +nightly fmt --all -- --check — clean.

🤖 Generated with Claude Code

jqnatividad and others added 4 commits July 1, 2026 06:48
Add choropleth map support (addresses plotly#408):

- `Choropleth<Loc, Z>` on the existing `geo` subplot, with a `LocationMode`
  enum (ISO-3 / USA-states / country names / geojson-id), a dedicated
  `choropleth::Marker`, selection support, z-bounds, and the shared
  `ColorScale`/`ColorBar` machinery. `geojson` accepts a URL string or an
  inline GeoJSON object.
- `ChoroplethMap<Loc, Z>`, the plotly.js 3.x `choroplethmap` trace on the
  MapLibre `map` subplot (GeoJSON-only).
- New MapLibre `map` subplot via `LayoutMap` + `MapStyle` + `MapBounds`.
- `LayoutGeo` additions: `fitbounds` (`GeoFitBounds`), `resolution`
  (`GeoResolution`, 1:110M/1:50M base-layer detail), and `bgcolor`.
- `PlotType::Choropleth`/`ChoroplethMap` variants, re-exports, serialization
  tests, doctests, runnable `examples/maps` examples, and a Maps book recipe.

Attribute names/types follow the plotly.js v3.6.0 plot-schema.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The embedded choropleth example calls GeoResolution::OneOverFiftyMillion,
but the shared import block omitted GeoResolution, so copying the documented
imports alongside the example would not compile.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add the modern MapLibre-based `densitymap` trace type, the density
counterpart to `ChoroplethMap`. It draws a weighted kernel-density
heatmap from lat/lon points (optional per-point weight z) onto the
`layout.map` subplot, with full color-scale (colorscale, colorbar,
showscale, reversescale, autocolorscale, coloraxis, zmin/zmax/zmid)
and hover (text, hovertext, hoverinfo, hovertemplate, hoverlabel,
customdata) support. Unlike ChoroplethMap it has no marker/selection.

Registers the trace: DensityMap variant on PlotType (serializes to
"densitymap"), module + type re-exports in traces/mod.rs and lib.rs.
Includes a serialize_density_map unit test and a doctest.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

Add DensityMap trace for the MapLibre map subplot (plotly.js densitymap)

1 participant