Issue #545: restore custom per-point tooltips for bubble charts#1001
Merged
Conversation
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>
There was a problem hiding this comment.
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
BubbleSeriescustom-tooltip API (setCustomToolTips,setToolTips) and surfaced stored tooltip strings via getters. - Updated
PlotContent_Bubbleto 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>
Member
Author
|
Thanks for the review — addressed in a63cdfb:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #545
Problem
The 3.7.0 tooltip overhaul removed
BubbleSeries.setCustomToolTips(boolean)andBubbleSeries.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 like2% (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: restoresetCustomToolTips(boolean)/isCustomToolTips()andsetToolTips(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-outsetCustomToolTips/setToolTipssnippet now that the API exists again.Verification
mvn test -Dtest=BubbleChartTest→ 4/4 pass. RenderedBubbleChart02to 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