Skip to content

feat: add native point clustering to ScatterMap#418

Merged
andrei-ng merged 1 commit into
plotly:mainfrom
dathere:feat/scatter-map-cluster
Jul 9, 2026
Merged

feat: add native point clustering to ScatterMap#418
andrei-ng merged 1 commit into
plotly:mainfrom
dathere:feat/scatter-map-cluster

Conversation

@jqnatividad

Copy link
Copy Markdown
Contributor

Summary

Adds native point clustering to the MapLibre ScatterMap trace (#417) via a new Cluster option, exposing plotly.js's scattermap.cluster attributes.

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-based ScatterMapbox has no equivalent, which is why it's a follow-up rather than part of the field-for-field port in #417.

⚠️ Stacked on #417

Cluster attaches to ScatterMap, so this PR is stacked on #417#416#410 and should be reviewed/merged after them. Until they land in main, the diff here also shows their commits; once merged, this diff reduces to just the Cluster addition.

What changed

New Cluster struct on plotly::traces::scatter_map, plus a cluster: Option<Cluster> field on ScatterMap (with the usual FieldSetter builder):

  • enabled (bool)
  • color (color or per-step array, Dim<Box<dyn Color>>)
  • maxzoom (0-24; zoom past which clusters expand into points)
  • opacity
  • size (single or per-step array)
  • step (single or per-step array; -1 = auto)

Includes a serialize_cluster unit test and a Cluster doctest.

Testing

  • cargo test -p plotly --lib scatter_mapserialize_cluster and serialize_scatter_map pass.
  • cargo test -p plotly --doc scatter_mapCluster and ScatterMap doctests pass.
  • cargo clippy — clean.
  • cargo +nightly fmt --all -- --check — clean.
  • Verified end-to-end rendering in-browser (plotly.js 3.6.0): clusters form at the fitted zoom, expand into individual hoverable points on zoom-in, and maxzoom avoids the MapLibre clusterMaxZoom > source maxzoom warning.

🤖 Generated with Claude Code

@jqnatividad jqnatividad mentioned this pull request Jul 6, 2026
4 tasks
 - 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).

Signed-off-by: Andrei Gherghescu <8067229+andrei-ng@users.noreply.github.com>
@andrei-ng andrei-ng force-pushed the feat/scatter-map-cluster branch from c4d4d9f to 0c7fc5e Compare July 9, 2026 06:50
@andrei-ng andrei-ng merged commit 9722338 into plotly:main Jul 9, 2026
31 of 32 checks passed
@andrei-ng

Copy link
Copy Markdown
Collaborator

@jqnatividad, thanks for the PRs!
All merged now.

@andrei-ng andrei-ng deleted the feat/scatter-map-cluster branch July 9, 2026 07:00
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