test: regression test for issue #707 (last bar label overwritten in CategoryChart)#977
Merged
Merged
Conversation
Adds a headless render test that exercises the exact scenario from issue #707: a Bar-style CategoryChart with setLabelsVisible(true). The bug (using shared 'path' so closePath() repainted the last bar over its label) was fixed in ff2536f by switching to a local 'barPath'. This test guards against any future regression. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds a JUnit regression test in the XChart test suite intended to prevent reintroducing issue #707, where the last bar label in a Bar-style CategoryChart could be overwritten due to an extra post-loop fill.
Changes:
- Add a new regression test to
CategoryChartTesttargeting issue #707’s “last bar label overwritten” scenario. - Introduce an import for
Styler.ChartThemeto construct aCategoryChartwith the Matlab theme in the new test.
Replace the no-throw assertion with a pixel-level regression check that actually detects the visual bug: - Render the 5-bar chart twice (labels ON and OFF) and count differing pixels -> diff5 (covers all 5 label contributions). - Render the same chart with the last value as NaN (bar 5 skipped) twice (labels ON and OFF) -> diffNaN (covers only 4 label contributions). - Assert diff5 > diffNaN. When the original bug is reintroduced (bar loop reuses shared 'path' and closePath() repaints the last bar over its label), the 5th label's pixels vanish and diff5 equals diffNaN, making the assertion fail. The 5th label currently contributes 64 distinct pixels, providing a clear margin. Addresses Copilot PR review comment. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Summary
Adds a regression test for issue #707 — the last bar in a Bar-style
CategoryChartwithsetLabelsVisible(true)was rendered twice, causing its label to be overwritten.Root Cause
The bar rendering loop reused the shared
pathvariable (also used byArearender style). After the inner loop,closePath()was called unconditionally and would re-fillpath— which at that point held the last bar'sPath2D— painting solid fill over the already-drawn label.Fix (already in codebase)
Commit
ff2536f4changed bar rendering to use a localbarPathvariable instead of the sharedpath. This keepspath == nullthroughout bar rendering soclosePath()becomes a no-op for bar series.A demo file (
TestForIssue707.java) also already exists.What This PR Adds
A headless render regression test in
CategoryChartTestthat exercises the exact scenario from the issue report (Matlab theme,setLabelsVisible(true), 5 data points). The test usesBitmapEncoder.getBitmapBytesto trigger the full AWT rendering path and will catch any re-introduction of the shared-path bug.Closes #707