Skip to content

Issue #545: restore custom per-point tooltips for bubble charts#1001

Merged
timmolter merged 2 commits into
developfrom
issue-545-bubble-custom-tooltips
Jul 15, 2026
Merged

Issue #545: restore custom per-point tooltips for bubble charts#1001
timmolter merged 2 commits into
developfrom
issue-545-bubble-custom-tooltips

Conversation

@timmolter

Copy link
Copy Markdown
Member

Fixes #545

Problem

The 3.7.0 tooltip overhaul removed BubbleSeries.setCustomToolTips(boolean) and BubbleSeries.setToolTips(String[]), so user code that attached a custom label to each bubble stopped compiling. The default tooltip only shows the formatted x/y axis values, which can't express a combined label like 2% (279/1298) — exactly the use case the reporter needed.

The rendering pipeline already supports arbitrary per-point label strings (PlotInteractionData.addToolTip(shape, x, y, w, label), used by Pie/Radar/Dial). Only the public series API and the wiring were missing.

Changes

  • BubbleSeries: restore setCustomToolTips(boolean) / isCustomToolTips() and setToolTips(String[]) / getToolTips().
  • PlotContent_Bubble: use the custom label when custom tooltips are enabled and a non-null entry exists for that index; otherwise fall back to the existing x/y axis-value tooltip. Safe when the array is null, shorter than the data, or has null entries.
  • BubbleChart02 (new standalone demo): reproduces the reporter's scenario — volume/rate/hits bubbles with "<rate>% (<hits>/<volume>)" labels.
  • BubbleChartTest (new): default-off, getter/setter round-trip, render-with-custom-tooltips, and partial/null fallback all covered.
  • TestForIssue545: reactivate the previously commented-out setCustomToolTips / setToolTips snippet now that the API exists again.

Verification

mvn test -Dtest=BubbleChartTest → 4/4 pass. Rendered BubbleChart02 to a static PNG (always-visible tooltips) and confirmed each bubble shows its custom label (2% (279/1298), 4% (346/843), 3% (502/1520), 2% (468/2755)) instead of raw axis values.

🤖 Generated with Claude Code

The 3.7.0 tooltip overhaul removed BubbleSeries.setCustomToolTips() and
setToolTips(), leaving no way to show a custom label per data point (only
the formatted x/y axis values). This restores that API.

- Add customToolTips flag + per-point toolTips[] to BubbleSeries
- Wire PlotContent_Bubble to prefer the custom label when set, falling
  back to the x/y axis values when disabled, null, or out of range
- Add BubbleChart02 demo and BubbleChartTest coverage
- Reactivate the previously commented-out snippet in TestForIssue545

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Restores the pre-3.7.0 public API for per-point custom tooltips on bubble charts and wires those labels into the bubble plot interaction/tooltip pipeline, with demos and tests to cover the behavior described in issue #545.

Changes:

  • Reintroduced BubbleSeries custom-tooltip API (setCustomToolTips, setToolTips) and surfaced stored tooltip strings via getters.
  • Updated PlotContent_Bubble to prefer a per-point custom label (when enabled and present) and otherwise fall back to the existing x/y formatted tooltip.
  • Added a new bubble tooltip demo and a new unit test suite, and reactivated the issue #545 standalone repro snippet.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
xchart/src/main/java/org/knowm/xchart/BubbleSeries.java Restores the public series API for enabling and supplying per-point custom tooltip strings.
xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent_Bubble.java Uses the custom per-point tooltip label when available; otherwise uses existing axis-value tooltip behavior.
xchart/src/test/java/org/knowm/xchart/BubbleChartTest.java Adds test coverage for default-off behavior, getter/setter round-trip, and render/fallback paths.
xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bubble/BubbleChart02.java Adds a demo showcasing per-point custom bubble tooltip labels in a realistic “rate (hits/volume)” scenario.
xchart-demo/src/main/java/org/knowm/xchart/standalone/issues/TestForIssue545.java Reactivates the original issue repro snippet to compile/run again with the restored API.

Comment on lines +50 to +54
* #setToolTips(String[])} instead of the default formatted x/y axis values. Requires tooltips to
* be enabled on the styler.
*
* @param customToolTips
*/
Comment on lines +68 to +72
* data. A null entry (or a null array) falls back to the default formatted x/y axis values for
* that data point. Also requires {@link #setCustomToolTips(boolean)} to be set to true.
*
* @param toolTips
*/
Comment on lines +65 to +66
BubbleSeries series =
chart.addSeries("s", new double[] {1, 2, 3}, new double[] {3, 4, 5}, new double[] {5, 6, 7});
Comment on lines +36 to +38
BubbleSeries bubbleSeries =
chart.addSeries(
"seriesName", new double[] {1298}, new double[] {data[1]}, new double[] {data[2]});
- Fill in the @param descriptions on BubbleSeries.setCustomToolTips and
  setToolTips (including the null/fallback behavior)
- Keep TestForIssue545 series x-data in sync with the tooltip source by
  using data[0] instead of a hard-coded 1298

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

Copy link
Copy Markdown
Member Author

Thanks for the review — addressed in a63cdfb:

  1. setCustomToolTips @param — filled in with a real description (true → per-point strings, false → default axis values).
  2. setToolTips @param — filled in, including the null-entry / null-array fallback behavior.
  3. TestForIssue545 data[0] vs hard-coded 1298 — the x-value now uses data[0] so the series data and the tooltip source stay in sync.
  4. BubbleChartTest long addSeries line — this one is a false positive: the line is ≤100 chars, so google-java-format leaves it as-is and mvn com.spotify.fmt:fmt-maven-plugin:check passes cleanly (verified). Left unchanged to avoid fighting the formatter.

@timmolter timmolter merged commit e0a3341 into develop Jul 15, 2026
1 check passed
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.

Custom tooltips removed since 3.7.0 ?

2 participants