Skip to content

Commit bd49daf

Browse files
Tweak x-axis labels of charts
* Avoid overlapping of labels Signed-off-by: Holger Friedrich <[email protected]>
1 parent cb42343 commit bd49daf

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/chart/defaultchartprovider/DefaultChartProvider.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,11 @@ public BufferedImage createChart(@Nullable String serviceId, @Nullable String th
206206
}
207207
styler.setYAxisTickMarkSpacingHint(yAxisSpacing);
208208
styler.setYAxisLabelAlignment(TextAlignment.Right);
209+
// avoid overlapping labels on x-axis;
210+
// Font.getSize() is related to font height, but will also give an indication of the width;
211+
// pattern is not the actual label, but also gives a rough estimation of the width of the label
212+
int xAxisSpacing = Math.max(width / 15, chartTheme.getAxisTickLabelsFont(dpi).getSize() * pattern.length());
213+
styler.setXAxisTickMarkSpacingHint(xAxisSpacing);
209214
// chart
210215
styler.setChartBackgroundColor(chartTheme.getChartBackgroundColor());
211216
styler.setChartFontColor(chartTheme.getChartFontColor());

0 commit comments

Comments
 (0)