From ec32ed05a8458ffd316121ae9714923d29902229 Mon Sep 17 00:00:00 2001 From: rstein Date: Tue, 22 Sep 2020 20:53:48 +0200 Subject: [PATCH] fixes wrong label overlap detection that prevented inverted x-axes (see #261) --- .../src/main/java/de/gsi/chart/axes/spi/AbstractAxis.java | 5 ++++- .../src/main/java/de/gsi/chart/plugins/Zoomer.java | 8 +++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/chartfx-chart/src/main/java/de/gsi/chart/axes/spi/AbstractAxis.java b/chartfx-chart/src/main/java/de/gsi/chart/axes/spi/AbstractAxis.java index fd66958db..e8971a5b4 100644 --- a/chartfx-chart/src/main/java/de/gsi/chart/axes/spi/AbstractAxis.java +++ b/chartfx-chart/src/main/java/de/gsi/chart/axes/spi/AbstractAxis.java @@ -1305,6 +1305,9 @@ private static boolean checkOverlappingLabels(final int start, final int stride, } else { labelHidden = true; current.setVisible(!makeInvisible); + if (!makeInvisible == false) { + System.err.println("mark + " + current.getValue() + " - " + !makeInvisible); + } } } return labelHidden; @@ -1403,7 +1406,7 @@ private static boolean isTickLabelsOverlap(final Side side, final boolean isInve final double m1End = m1.getPosition() + (m1Size / 2); final double m2Start = m2.getPosition() - (m2Size / 2); final double m2End = m2.getPosition() + (m2Size / 2); - return side.isVertical() && !isInverted ? (m1Start - m2End) <= gap : (m2Start - m1End) <= gap; + return side.isVertical() && !isInverted ? Math.abs(m1Start - m2End) <= gap : Math.abs(m2Start - m1End) <= gap; } protected static void drawAxisLabel(final GraphicsContext gc, final double x, final double y, final Text label) { diff --git a/chartfx-chart/src/main/java/de/gsi/chart/plugins/Zoomer.java b/chartfx-chart/src/main/java/de/gsi/chart/plugins/Zoomer.java index 4d0624608..9efba8703 100644 --- a/chartfx-chart/src/main/java/de/gsi/chart/plugins/Zoomer.java +++ b/chartfx-chart/src/main/java/de/gsi/chart/plugins/Zoomer.java @@ -434,9 +434,7 @@ public HBox getZoomInteractorBar() { zoomOut.setOnAction(evt -> { zoomOrigin(); - for (final Axis axis : getChart().getAxes()) { - axis.setAutoRanging(true); - } + getChart().getAxes().forEach(axis -> axis.setAutoRanging(true)); }); zoomModeXY.setOnAction(evt -> setAxisMode(AxisMode.XY)); zoomModeX.setOnAction(evt -> setAxisMode(AxisMode.X)); @@ -1198,8 +1196,8 @@ public class ZoomState { private ZoomState(final double zoomRangeMin, final double zoomRangeMax, final boolean isAutoRanging, final boolean isAutoGrowRanging) { - this.zoomRangeMin = zoomRangeMin; - this.zoomRangeMax = zoomRangeMax; + this.zoomRangeMin = Math.min(zoomRangeMin, zoomRangeMax); + this.zoomRangeMax = Math.max(zoomRangeMin, zoomRangeMax); this.wasAutoRanging = isAutoRanging; this.wasAutoGrowRanging = isAutoGrowRanging; }