Fix #881: restore deprecated AnnotationType shims and fix outside label font color#972
Merged
timmolter merged 2 commits intoJun 19, 2026
Merged
Conversation
…el color 1. PieStyler: add @deprecated AnnotationType enum and setAnnotationType() / setAnnotationDistance() methods that delegate to the new LabelType / setLabelType() / setLabelsDistance() API introduced in 3.8.1. Restores source compatibility for code written against pre-3.8.1 releases. Mapping: AnnotationType.Label → LabelType.Name AnnotationType.LabelAndPercentage → LabelType.NameAndPercentage AnnotationType.LabelAndValue → LabelType.NameAndValue AnnotationType.Value/Percentage → LabelType.Value/Percentage 2. PlotContent_Pie: fix outside labels (labelsDistance > 1.0) using the wrong font color when isLabelsFontColorAutomaticEnabled is true. The auto-detect was using the slice fill color as the background, which produced white text on a white plot background. Outside labels always sit on the plot background so they should use the configured labelsFontColor. 3. TestForIssue881: demo exercising the deprecated API end-to-end. Closes #881 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Restores backwards compatibility for the pre-3.8.1 Pie chart annotation API (deprecated shims), and fixes an auto-label font color issue for outside pie labels so they don’t disappear against the plot background.
Changes:
- Reintroduced
PieStyler.AnnotationTypeplus deprecatedsetAnnotationType(...)/setAnnotationDistance(...)shims delegating to the newer label APIs. - Updated pie label painting to only use automatic font-color selection for inside labels (
labelsDistance <= 1.0), using configured label color for outside labels. - Added a standalone demo reproducing #881 and exercising the deprecated API.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| xchart/src/main/java/org/knowm/xchart/style/PieStyler.java | Adds deprecated compatibility shims for the removed AnnotationType API. |
| xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent_Pie.java | Fixes outside-label font color selection when automatic font color is enabled. |
| xchart-demo/src/main/java/org/knowm/xchart/standalone/issues/TestForIssue881.java | Demo that compiles/runs against the restored deprecated API and shows outside labels. |
Add Value and Percentage to the full mapping table so all five AnnotationType values have documented equivalents in LabelType. 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.
Closes #881
Changes
1.
PieStyler— deprecated compatibility shimsThe 3.8.1 rename of
annotation*→label*silently droppedAnnotationTypeandsetAnnotationDistance(), breaking all code written against the old API without any migration path.Restored as
@Deprecatedshims that delegate to the new API:setAnnotationType(AnnotationType.LabelAndPercentage)setLabelType(LabelType.NameAndPercentage)setAnnotationType(AnnotationType.Label)setLabelType(LabelType.Name)setAnnotationType(AnnotationType.LabelAndValue)setLabelType(LabelType.NameAndValue)setAnnotationDistance(d)setLabelsDistance(d)Old code now compiles again (with deprecation warnings pointing to the replacement API).
2.
PlotContent_Pie— outside label font color bugWhen
isLabelsFontColorAutomaticEnabledistrueandlabelsDistance > 1.0, the auto font-color detection was passing the slice fill color as the background. This produced white text on a white plot background, making outside labels invisible.Fix: auto-color detection is only applied for inside labels (
labelsDistance <= 1.0). Outside labels always sit on the plot background so they use the configuredlabelsFontColor.3. Demo
TestForIssue881.java— exercises the deprecated API end-to-end. Note:setPlotContentSize(.7)is required when usinglabelsDistance > 1.0(same pattern as the existingPieChart03example).