-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Description
Summary
As part of an ongoing Plotly Professional Services contract, Kobold Metals has requested multiple feature requests/bug fixes for Plotly.js. One of these feature requests is the ability to click on legend titles to toggle the visibility of all traces in that legend.
This feature enhancement would be useful for situations where multiple legends are used to organize different categories of data. Clicking a legend title would provide a quick way to show/hide entire categories of traces without clicking each item individually.
Problem Statement
Legend titles are currently non-interactive text elements. When working with multiple legends, users might want to quickly toggle all traces on/off. Currently, this requires clicking each item individually, which can be tedious.
Key Decision: How should we implement clickable legend titles, and what should the default behavior be?
Proposed Solution
API
Add a titleclick attribute to control whether the legend title is clickable:
layout: {
legend: {
title: { text: 'Legend 1' },
titleclick: true
}
}The titleclick attribute is a boolean:
true: Clicking the title toggles all traces in that legendfalse: Title is not clickable
The default value for titleclick depends on the number of legends in the plot:
- Single legend: defaults to
false - Multiple legends: defaults to
true
Visual Feedback
Clickable titles will show a pointer cursor on hover, matching the existing legend item behavior.
Implementation Plan (with rough timeline)
-
Add attributes and defaults (Week 1)
- Add
titleclickattribute tosrc/components/legend/attributes.js - Update
src/components/legend/defaults.jsto set defaults based on legend count
- Add
-
Implement click handling (Week 1-2)
- Add clickable
rectoverlay to legend titles - Create new function to read click event from clicking legend title and toggle all traces in the legend
- Add pointer cursor styling for clickable titles
- Add clickable
-
Testing (Week 2)
- Write mock and Jasmine tests for clickable legend titles