Skip to content

Fix bar chart tooltips: consistent hover/click + Svelte 5 mount API#1219

Open
gskjold wants to merge 1 commit into
mainfrom
fix/bar-chart-tooltip-consistency
Open

Fix bar chart tooltips: consistent hover/click + Svelte 5 mount API#1219
gskjold wants to merge 1 commit into
mainfrom
fix/bar-chart-tooltip-consistency

Conversation

@gskjold

@gskjold gskjold commented Jun 25, 2026

Copy link
Copy Markdown
Member

Summary

Fixes inconsistent tooltip behavior in bar charts that have both positive and negative bars, and repairs the custom tooltip which was broken by the Svelte 5 migration.

What was wrong

  1. Inconsistent tooltips (Discrepancy between kinds of tooltips #1215). In BarChart.svelte, the first bar segment used the custom use:tooltip action while the second segment (export in the day plot, negative price in the price plot) used a native SVG <title>. Result: import/positive bars showed the custom tooltip on click; export/negative bars only showed a native browser tooltip on hover — and only when barWidth > 15.

  2. Negative price never shown (Negative price not displayed #1185). Negative prices render entirely through the second segment (value2/title2), so they fell into the native-<title>-only path with no click handler — clicking did nothing, and on the 15-min price chart the bars are often too narrow (barWidth < 15) for even the native title to appear.

  3. Custom tooltip fully broken on main. tooltip.js still used the legacy Svelte class API (new Tooltip() / instance.$destroy()). On Svelte 5 (the repo is on svelte ^5.17, despite older "Svelte 4" wording) this throws at runtime:

    Uncaught TypeError: Cannot use 'in' operator to search for 'Symbol($state)' in undefined
    

    So the custom tooltip didn't work at all after the Svelte 5 upgrade.

Changes

  • BarChart.svelte: second <g> now uses data-title="{point.title2}" use:tooltip instead of native <title>. Both segments share one path; the barWidth > 15 gate on the tooltip is gone.
  • tooltip.js:
    • migrated to Svelte 5 mount() / unmount().
    • shows on click (and mobile tap) immediately.
    • shows on desktop hover after a short dwell (HOVER_DELAY = 500ms) so it doesn't fire while sweeping the mouse across bars.
    • guards against empty titles and cleans up on action teardown.

Mobile

Unchanged from the user's perspective: a tap synthesizes a click, so tooltips show instantly on tap. The hover dwell only affects desktop.

Testing

Verified on device by seeding 24h of import+export history (via a config-file dayplot line) so the "Energy use last 24 hours" chart had both positive and negative bars. Confirmed: no console error, hover-after-dwell and click both show the tooltip consistently on both segments.

Fixes #1215, #1185

🤖 Generated with Claude Code

The second bar segment in BarChart (export in the day plot, negative
price in the price plot) used a native SVG <title> while the first
segment used the custom `use:tooltip` action. This made the two behave
differently — the export/negative bars only showed a native hover
tooltip (and only when barWidth > 15), while the import/positive bars
showed the custom tooltip on click. Both segments now use `use:tooltip`.

The custom tooltip was also fully broken after the Svelte 5 migration:
tooltip.js still used the legacy class API (`new Tooltip()` / `$destroy()`),
which throws `Cannot use 'in' operator to search for 'Symbol($state)' in
undefined` on Svelte 5. Switched to `mount()` / `unmount()`.

Tooltip now shows on click (and mobile tap) immediately, and on desktop
hover after a short dwell (HOVER_DELAY) so it doesn't fire while sweeping
the mouse across bars.

Fixes #1215, #1185

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

🔧 PR Build Artifacts

Version: 91bf26b

All environments built successfully. Download the zip files:

Artifacts expire after 7 days. View workflow run

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.

Discrepancy between kinds of tooltips

1 participant