Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/#366 #367

Open
wants to merge 2 commits into
base: v1.5.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ History
-------
##### Version 1.5.5 (not yet released)
- fix cross hair painting ([#340](https://github.com/jfree/jfreechart/issues/340))
- fix calculating if label fits inside bar for XYBarRenderer ([#366](https://github.com/jfree/jfreechart/issues/366))

##### Version 1.5.4 (8 January 2023)
- add new methods to access maps for datasets, renderers and axes in plots ([#201](https://github.com/jfree/jfreechart/issues/201));
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/org/jfree/chart/renderer/xy/XYBarRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -1028,18 +1028,17 @@ private String calculateLabeltoDraw(String label, Point2D anchorPoint,
}

String result = label;
while (result != null) {
Shape bounds = TextUtils.calculateRotatedStringBounds(result,
while (result != null && !result.isEmpty()) {
Rectangle2D labelBounds = TextUtils.calculateRotatedStringBounds(result,
g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(),
position.getTextAnchor(), position.getAngle(),
position.getRotationAnchor());
Rectangle2D bounds2D = bounds == null ? null : bounds.getBounds2D();
position.getRotationAnchor()).getBounds2D();

if (bounds2D != null && labelBar.contains(bounds2D)) {
if (labelBar.getHeight() >= labelBounds.getHeight() && labelBar.getWidth() >= labelBounds.getWidth()) {
// Label fits
return result;
} else if (bounds2D != null && labelBar.getHeight() < bounds2D.getHeight()) {
// Label will never fit, insufficient height
} else if (labelBar.getHeight() < labelBounds.getHeight()) {
// Optimization: label will never fit due to insufficient height
return null;
} else {
switch (position.getItemLabelClip()) {
Expand Down