Skip to content

Issue #1004: fix AnnotationImage screen-space vertical centering (width vs height)#1005

Merged
timmolter merged 1 commit into
developfrom
issue-1004-annotationimage-screenspace-vcenter
Jul 16, 2026
Merged

Issue #1004: fix AnnotationImage screen-space vertical centering (width vs height)#1005
timmolter merged 1 commit into
developfrom
issue-1004-annotationimage-screenspace-vcenter

Conversation

@timmolter

Copy link
Copy Markdown
Member

Summary

Fixes #1004.

AnnotationImage.paint() centered the image vertically using image.getWidth() instead of image.getHeight() in the screen-space branch. A non-square image placed with isValueInScreenSpace = true was therefore mis-centered vertically by (width - height) / 2 pixels. The data-space branch already used getHeight() correctly, and square images were unaffected — which is why it went unnoticed.

  if (isValueInScreenSpace) {
    xOffset = (int) x - image.getWidth() / 2;
-   yOffset = chart.getHeight() - (int) y - image.getWidth() / 2;
+   yOffset = chart.getHeight() - (int) y - image.getHeight() / 2;

Demo

Adds TestForIssue1004, which places a tall (40×140) image in screen space at a fixed point marked by a crosshair; the image has a red line across its true center.

Before After
red center line sits ~50px below the crosshair red center line lands on the crosshair

Origin

Found while triaging #506 (which is resolved on develop — the old ChartImage/addPlotPart API is now AnnotationImage/addAnnotation).

🤖 Generated with Claude Code

The screen-space branch of AnnotationImage.paint() centered the image
vertically using image.getWidth() instead of image.getHeight(), so a
non-square image placed with isValueInScreenSpace=true was mis-centered
vertically by (width - height) / 2 pixels. Square images were unaffected.

Add TestForIssue1004 demo showing a tall image against a crosshair marking
the intended center (before: image center sits 50px below the crosshair;
after: it lines up).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@timmolter
timmolter merged commit 74d5d1b into develop Jul 16, 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.

AnnotationImage: screen-space vertical centering uses image width instead of height

1 participant