Skip to content

Add attribute-based legends (colorlegend, sizelegend, symbollegend) - #7656

Open
Rhoahndur wants to merge 2 commits into
plotly:masterfrom
Rhoahndur:feature/add-attribute-legends
Open

Add attribute-based legends (colorlegend, sizelegend, symbollegend)#7656
Rhoahndur wants to merge 2 commits into
plotly:masterfrom
Rhoahndur:feature/add-attribute-legends

Conversation

@Rhoahndur

@RhoahndurRhoahndur commented Nov 26, 2025

Copy link
Copy Markdown

Implementation for Issue #5099 ( #5099 ) adds three new legend components that show unique values from marker attributes (color, size, symbol) rather than trace-based legends.

New components:

  • colorlegend: displays unique color values as swatches
  • sizelegend: displays size ranges as graduated circles
  • symbollegend: displays unique marker symbols

Features:

  • Click to toggle visibility of points with that attribute value (remains to be implemented)
  • Support for multiple legends (colorlegend, colorlegend2, etc.)
  • Configurable positioning, styling, and orientation
  • Works with scatter and scatter-variant traces

Summary

This PR implements attribute-based legends as requested in #5099.

Currently, Plotly.js legends are trace-centric (one entry per trace), which becomes unwieldy when multiple traces share visual attributes like color scales or size mappings across hundreds of points. This enhancement adds three new legend components that allow users to create separate legends based on marker attributes:

  • colorlegend - Discrete color swatch legend for categorical or binned color values
  • sizelegend - Graduated circle legend for size ranges
  • symbollegend - Symbol shape legend for marker symbols

New Trace Attributes

  • marker.colorlegend - Reference to layout.colorlegend
  • marker.sizelegend - Reference to layout.sizelegend
  • marker.symbollegend - Reference to layout.symbollegend

Example Usage

Plotly.newPlot('div',[{type: 'scatter',x: [1,2,3,4],y: [10,20,15,25],marker: {color: ['Species A','Species B','Species A','Species C'],colorlegend: 'colorlegend'}}],{colorlegend: {title: {text: 'Species'},x: 1.02,y: 1}});
## TestPlannpmrunlintpassesnpmrunschemaregeneratedJasminetestsaddedforallthreecomponentsImagemocks added: colorlegend_basic,sizelegend_basic,symbollegend_basicManualtestingindevdashboardNote: ThisismyfirstcontributiontoPlotly.js(oneoftwoPRsI'm working on for this project). I'vedonemybesttofollowtheexistingpatternsinthecodebase(particularlythecolorbarandlegendcomponents),butI'm very open to feedback on the implementation approach, code style, or anything else. Thank you for taking the time to review!

Implementation for Issue plotly#5099 adds three new legend components that show
unique values from marker attributes (color, size, symbol) rather
than trace-based legends.
New components:
- colorlegend: displays unique color values as swatches
- sizelegend: displays size ranges as graduated circles
- symbollegend: displays unique marker symbols
Features:
- Click to toggle visibility of points with that attribute value
- Support for multiple legends (colorlegend, colorlegend2, etc.)
- Configurable positioning, styling, and orientation
- Works with scatter and scatter-variant traces
@Rhoahndur
Rhoahndurforce-pushed the feature/add-attribute-legends branch from 64a2bf4 to 74a792aCompareNovember 27, 2025 01:38
@Rhoahndur
Rhoahndurforce-pushed the feature/add-attribute-legends branch from 74a792a to 8c270e0CompareNovember 27, 2025 02:06
@Rhoahndur

Copy link
Copy Markdown
Author

The failing image tests (uniformtext_sunburst_treemap, treemap_textfit, treemap_sunburst_marker_colors, treemap_packages_colorscale_novalue, sunburst_coffee) are unrelated to my changes - I did not modify any sunburst or treemap code. These appear to be pre-existing issues or environment-specific failures.

Sign up for freeto 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.

3 participants

@Rhoahndur@emilykl@robertclaus