Skip to content

Commit

Permalink
Merge pull request #83 from matoos32/81-xytitlebuilder-not-using-the-…
Browse files Browse the repository at this point in the history
…max-width-and-height

Add setting of XYTitleAnnotation max width and height
  • Loading branch information
matoos32 authored Dec 5, 2022
2 parents 0e64aa4 + 6b35e3a commit cc31414
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,10 @@ private static ChartBuilder getDailyStockChartBuilder(StockChartConfig cfg) {
.annotation(XYTitleBuilder.get()
.title(new TextTitle("OHLC Title")).x(0.5).y(0.9).anchor(RectangleAnchor.BOTTOM))

.annotation(XYTitleBuilder.get()
.title(new TextTitle("Subtitle")).x(0.5).y(0.8).maxHeight(0.05).maxWidth(0.05)
.anchor(RectangleAnchor.BOTTOM))

.annotation(XYPolygonBuilder.get().polygon(ohlcPolygon))

.annotation(XYDrawableBuilder.get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,20 @@ private void checkBuildPreconditions() throws IllegalStateException {
public XYAnnotation build() throws IllegalStateException {

checkBuildPreconditions();
// FIXME: Add missing calls to set the max width and height.
return new XYTitleAnnotation(x, y, title, anchor);

XYTitleAnnotation annotation = new XYTitleAnnotation(x, y, title, anchor);

// Check if max width/height are using defaults to avoid XYTitleAnnotation firing change events.

if (Double.compare(maxWidth, DEFAULT_MAX_WIDTH) != 0) {
annotation.setMaxWidth(maxWidth);
}

if (Double.compare(maxHeight, DEFAULT_MAX_HEIGHT) != 0) {
annotation.setMaxHeight(maxHeight);
}

return annotation;
}

@Override
Expand Down

0 comments on commit cc31414

Please sign in to comment.