Skip to content

Fix #881: restore deprecated AnnotationType shims and fix outside label font color#972

Merged
timmolter merged 2 commits into
developfrom
timmolter-fix-881-deprecated-annotation-type-shims
Jun 19, 2026
Merged

Fix #881: restore deprecated AnnotationType shims and fix outside label font color#972
timmolter merged 2 commits into
developfrom
timmolter-fix-881-deprecated-annotation-type-shims

Conversation

@timmolter

Copy link
Copy Markdown
Member

Closes #881

Changes

1. PieStyler — deprecated compatibility shims

The 3.8.1 rename of annotation*label* silently dropped AnnotationType and setAnnotationDistance(), breaking all code written against the old API without any migration path.

Restored as @Deprecated shims that delegate to the new API:

Old New
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 bug

When isLabelsFontColorAutomaticEnabled is true and labelsDistance > 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 configured labelsFontColor.

3. Demo

TestForIssue881.java — exercises the deprecated API end-to-end. Note: setPlotContentSize(.7) is required when using labelsDistance > 1.0 (same pattern as the existing PieChart03 example).

…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>

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 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.AnnotationType plus deprecated setAnnotationType(...) / 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.

Comment thread xchart/src/main/java/org/knowm/xchart/style/PieStyler.java
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>
@timmolter timmolter merged commit e3f7901 into develop Jun 19, 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.

Class "org.knowm.xchart.style.PieStyler.AnnotationType" missing

2 participants