From 2346488de3fa9433df2cb51c603a727f034622ed Mon Sep 17 00:00:00 2001 From: Rebecca Williams Date: Tue, 24 Oct 2023 16:45:24 +0100 Subject: [PATCH] Resize the legend area when traces are hidden The legend area is determined using the legends of all the traces even if they are not being displayed. This fix addresses that by only considering the visible traces. --- .../src/org/csstudio/swt/rtplot/internal/LegendPart.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/applications/appunorganized/appunorganized-plugins/org.csstudio.swt.rtplot/src/org/csstudio/swt/rtplot/internal/LegendPart.java b/applications/appunorganized/appunorganized-plugins/org.csstudio.swt.rtplot/src/org/csstudio/swt/rtplot/internal/LegendPart.java index 751d13d5dd..a64e481084 100644 --- a/applications/appunorganized/appunorganized-plugins/org.csstudio.swt.rtplot/src/org/csstudio/swt/rtplot/internal/LegendPart.java +++ b/applications/appunorganized/appunorganized-plugins/org.csstudio.swt.rtplot/src/org/csstudio/swt/rtplot/internal/LegendPart.java @@ -66,14 +66,18 @@ public int getDesiredHeight(final GC gc, final int bounds_width, final Font orig_font = gc.getFont(); gc.setFont(font); + int items = 0; int max_width = 1, max_height = 1; // Start with 1 pixel to avoid later div-by-0 for (Trace trace : traces) { + if (!trace.isVisible()) + continue; final Point size = gc.textExtent(trace.getLabel()); if (size.x > max_width) max_width = size.x; if (size.y > max_height) max_height = size.y; + items++; } // Arrange in grid with some extra space grid_x = max_width + max_height / 2; @@ -81,7 +85,6 @@ public int getDesiredHeight(final GC gc, final int bounds_width, gc.setFont(orig_font); - final int items = traces.size(); final int items_per_row = Math.max(1, bounds_width / grid_x); // Round down, counting full items final int rows = (items + items_per_row-1) / items_per_row; // Round up return rows * grid_y;