Skip to content

feat(experimental): add legend_isolate_on_click option#1061

Open
maxim-yegorov wants to merge 1 commit intoRomRider:devfrom
maxim-yegorov:feat/legend-isolate-on-click
Open

feat(experimental): add legend_isolate_on_click option#1061
maxim-yegorov wants to merge 1 commit intoRomRider:devfrom
maxim-yegorov:feat/legend-isolate-on-click

Conversation

@maxim-yegorov
Copy link

@maxim-yegorov maxim-yegorov commented Mar 4, 2026

Changes

New feature: legend_isolate_on_click

When enabled, clicking a legend item isolates that series (hides all others). Clicking the same item again restores all series.

type: custom:apexcharts-card
experimental:
  legend_isolate_on_click: true
series:
  - entity: sensor.living_room_temperature
    name: Living Room
  - entity: sensor.kitchen_temperature
    name: Kitchen

Requires all series to have unique names (same constraint as hidden_by_default). The default ApexCharts toggle behavior is disabled when this option is active.

Bug fix: TypeError crash in ApexCharts v5 sections view

Fixes TypeError: Cannot read properties of undefined (reading 'beforeMount') thrown when rendering charts in HA sections view (section_mode: true).

Root cause: ApexCharts v5 accesses chart.events.beforeMount unconditionally, but under certain config merging conditions chart.events ends up undefined.

Fix:

  • Always include chart.events: {} in the layout config
  • Add a defensive post-constructor guard before render()
  • Patch ApexCharts v5.3.3 ESM via patch-package to add null-guards on chart.events accesses (beforeMount, mounted, updated, legendClick)

Test plan

  • Enable experimental: { legend_isolate_on_click: true } on a multi-series chart
  • Click a legend item — only that series should remain visible, others greyed out
  • Click the same item again — all series restored
  • Click a different item while one is isolated — isolation switches to the new item
  • Verify no TypeError: beforeMount crash in sections view (section_mode: true)

ApexCharts v5 accesses chart.events.beforeMount directly without null-checking,
causing a TypeError crash in certain configurations (e.g. sections view).

- Always include chart.events: {} in the layout config so ApexCharts never
  receives an undefined events object
- Add a post-constructor guard to ensure chart.events is an object before
  render() is called
- Patch ApexCharts v5.3.3 ESM to add null-guards on chart.events accesses
  (beforeMount, mounted, updated, legendClick) via patch-package
@maxim-yegorov maxim-yegorov force-pushed the feat/legend-isolate-on-click branch from be6fd85 to 595b9da Compare March 4, 2026 23:38
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.

1 participant