From 5fb770cb5784af4fd0576aafedbe4e4978f95930 Mon Sep 17 00:00:00 2001 From: Arnaud Roques Date: Mon, 4 Oct 2021 23:01:59 +0200 Subject: [PATCH] Fix arrow constraint position --- .../timingdiagram/TimeConstraint.java | 4 ++++ .../timingdiagram/graphic/Histogram.java | 24 ++++++++++++------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/net/sourceforge/plantuml/timingdiagram/TimeConstraint.java b/src/net/sourceforge/plantuml/timingdiagram/TimeConstraint.java index f44927e53..3cbdd1a93 100644 --- a/src/net/sourceforge/plantuml/timingdiagram/TimeConstraint.java +++ b/src/net/sourceforge/plantuml/timingdiagram/TimeConstraint.java @@ -76,6 +76,10 @@ public class TimeConstraint { this.styleBuilder = skinParam.getCurrentStyleBuilder(); } + public final boolean containsStrict(TimeTick other) { + return tick1.compareTo(other) < 0 && tick2.compareTo(other) > 0; + } + public final TimeTick getTick1() { return tick1; } diff --git a/src/net/sourceforge/plantuml/timingdiagram/graphic/Histogram.java b/src/net/sourceforge/plantuml/timingdiagram/graphic/Histogram.java index 7b0a26283..d0e3ae801 100644 --- a/src/net/sourceforge/plantuml/timingdiagram/graphic/Histogram.java +++ b/src/net/sourceforge/plantuml/timingdiagram/graphic/Histogram.java @@ -347,18 +347,16 @@ public class Histogram implements PDrawing { private void drawConstraints(UGraphic ug) { for (TimeConstraint constraint : constraints) { - final String state1 = last(getStatesAt(constraint.getTick1())); - final String state2 = getStatesAt(constraint.getTick2()).get(0); - final double y1 = yOfState(state1); - final double y2 = yOfState(state2); - constraint.drawU(ug.apply(UTranslate.dy(y1)), ruler); + double y = yOfState(constraint.getTick1()); + for (ChangeState change : changes) { + if (constraint.containsStrict(change.getWhen())) { + y = Math.min(y, yOfState(change.getWhen())); + } + } + constraint.drawU(ug.apply(UTranslate.dy(y)), ruler); } } - private static String last(List list) { - return list.get(list.size() - 1); - } - private Point2D.Double getInitialPoint() { return new Point2D.Double(-getInitialWidth(), yOfState(initialState)); } @@ -380,6 +378,14 @@ public class Histogram implements PDrawing { return stepHeight() * nb; } + private double yOfState(TimeTick when) { + return yOfState(last(getStatesAt(when))); + } + + private static String last(List list) { + return list.get(list.size() - 1); + } + private double stepHeight() { if (suggestedHeight == 0 || allStates.size() <= 1) { return 20;