feat: add native point clustering to ScatterMap#418
Open
jqnatividad wants to merge 6 commits into
Open
Conversation
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>
Add `ScatterMap`, the MapLibre-based counterpart to `ScatterMapbox`, drawn on the `layout.map` subplot (`LayoutMap`/`MapStyle`). It mirrors `ScatterMapbox` field-for-field — markers/lines, `Fill`/`Selection`, and the full hover set (text/hovertext/hoverinfo/hovertemplate/customdata/hoverlabel) — but emits `"type": "scattermap"` and references `layout.map`. Add a `PlotType::ScatterMap` variant, re-export `ScatterMap` and the `scatter_map` module, and add a `serialize_scatter_map` unit test plus a doc example. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add a `Cluster` option to the MapLibre `ScatterMap` trace, exposing plotly.js's `scattermap.cluster` attributes (`enabled`, `color`, `maxzoom`, `opacity`, `size`, `step`). Clustering groups nearby markers client-side (MapLibre supercluster) into bubbles that expand into individual points on zoom, decluttering dense point maps without dropping any data. This is a `scattermap`-only feature; the deprecated `ScatterMapbox` has no equivalent. Stacked on the ScatterMap trace addition (plotly#417).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds native point clustering to the MapLibre
ScatterMaptrace (#417) via a newClusteroption, exposing plotly.js'sscattermap.clusterattributes.When enabled, nearby markers are grouped client-side (MapLibre's supercluster) into cluster bubbles that progressively expand into individual points as the map is zoomed in — decluttering dense point maps without dropping any data (every point still ships in the trace and becomes individually visible/hoverable at higher zoom).
This is a
scattermap-only feature: the deprecated Mapbox-basedScatterMapboxhas no equivalent, which is why it's a follow-up rather than part of the field-for-field port in #417.Clusterattaches toScatterMap, so this PR is stacked on #417 → #416 → #410 and should be reviewed/merged after them. Until they land inmain, the diff here also shows their commits; once merged, this diff reduces to just theClusteraddition.What changed
New
Clusterstruct onplotly::traces::scatter_map, plus acluster: Option<Cluster>field onScatterMap(with the usualFieldSetterbuilder):enabled(bool)color(color or per-step array,Dim<Box<dyn Color>>)maxzoom(0-24; zoom past which clusters expand into points)opacitysize(single or per-step array)step(single or per-step array;-1= auto)Includes a
serialize_clusterunit test and aClusterdoctest.Testing
cargo test -p plotly --lib scatter_map—serialize_clusterandserialize_scatter_mappass.cargo test -p plotly --doc scatter_map—ClusterandScatterMapdoctests pass.cargo clippy— clean.cargo +nightly fmt --all -- --check— clean.maxzoomavoids the MapLibreclusterMaxZoom > source maxzoomwarning.🤖 Generated with Claude Code