From 638bd2e9eaf5b8fa1fcea714e75c29a8b52cb188 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Loi=CC=88c=20PE=CC=81RON?= Date: Fri, 2 Apr 2021 16:34:14 +0200 Subject: [PATCH] Add compress parameter to print scale command in gantt diagram --- .../plantuml/project/GanttDiagram.java | 20 +++++++++++++++---- .../project/command/CommandPrintScale.java | 11 ++++++++++ .../project/draw/TimeHeaderMonthly.java | 4 ++-- .../project/draw/TimeHeaderQuarterly.java | 4 ++-- .../project/draw/TimeHeaderWeekly.java | 4 ++-- .../project/draw/TimeHeaderYearly.java | 4 ++-- 6 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/net/sourceforge/plantuml/project/GanttDiagram.java b/src/net/sourceforge/plantuml/project/GanttDiagram.java index 7e5a15b76..fe41d573d 100644 --- a/src/net/sourceforge/plantuml/project/GanttDiagram.java +++ b/src/net/sourceforge/plantuml/project/GanttDiagram.java @@ -118,6 +118,7 @@ public class GanttDiagram extends TitledDiagram implements ToTaskDraw, WithSprit private final Map nameDays = new HashMap(); private PrintScale printScale = PrintScale.DAILY; + private Integer compress; private Day today; private double totalHeightWithoutFooter; private Day min = Day.create(0); @@ -176,6 +177,17 @@ public class GanttDiagram extends TitledDiagram implements ToTaskDraw, WithSprit this.printScale = printScale; } + + public void setCompress(int compress) { + this.compress = compress; + } + + private int getCompress() { + if (this.compress != null) { + return this.compress; + } + return printScale.getCompress(); + } private boolean isHidden(Task task) { if (printStart == null || task instanceof TaskSeparator) { return false; @@ -235,13 +247,13 @@ public class GanttDiagram extends TitledDiagram implements ToTaskDraw, WithSprit if (openClose.getCalendar() == null) { return new TimeHeaderSimple(min, max); } else if (printScale == PrintScale.WEEKLY) { - return new TimeHeaderWeekly(openClose.getCalendar(), min, max, openClose, colorDays, colorDaysOfWeek); + return new TimeHeaderWeekly(openClose.getCalendar(), min, max, openClose, colorDays, colorDaysOfWeek, getCompress()); } else if (printScale == PrintScale.MONTHLY) { - return new TimeHeaderMonthly(openClose.getCalendar(), min, max, openClose, colorDays, colorDaysOfWeek); + return new TimeHeaderMonthly(openClose.getCalendar(), min, max, openClose, colorDays, colorDaysOfWeek, getCompress()); } else if (printScale == PrintScale.QUARTERLY) { - return new TimeHeaderQuarterly(openClose.getCalendar(), min, max, openClose, colorDays, colorDaysOfWeek); + return new TimeHeaderQuarterly(openClose.getCalendar(), min, max, openClose, colorDays, colorDaysOfWeek, getCompress()); } else if (printScale == PrintScale.YEARLY) { - return new TimeHeaderYearly(openClose.getCalendar(), min, max, openClose, colorDays, colorDaysOfWeek); + return new TimeHeaderYearly(openClose.getCalendar(), min, max, openClose, colorDays, colorDaysOfWeek, getCompress()); } else { return new TimeHeaderDaily(openClose.getCalendar(), min, max, openClose, colorDays, colorDaysOfWeek, nameDays, printStart, printEnd); diff --git a/src/net/sourceforge/plantuml/project/command/CommandPrintScale.java b/src/net/sourceforge/plantuml/project/command/CommandPrintScale.java index 1b7f14547..bc426fd9f 100644 --- a/src/net/sourceforge/plantuml/project/command/CommandPrintScale.java +++ b/src/net/sourceforge/plantuml/project/command/CommandPrintScale.java @@ -41,7 +41,9 @@ import net.sourceforge.plantuml.command.SingleLineCommand2; import net.sourceforge.plantuml.command.regex.IRegex; import net.sourceforge.plantuml.command.regex.RegexConcat; import net.sourceforge.plantuml.command.regex.RegexLeaf; +import net.sourceforge.plantuml.command.regex.RegexOptional; import net.sourceforge.plantuml.command.regex.RegexOr; +import net.sourceforge.plantuml.command.regex.RegexPartialMatch; import net.sourceforge.plantuml.command.regex.RegexResult; import net.sourceforge.plantuml.project.GanttDiagram; import net.sourceforge.plantuml.project.core.PrintScale; @@ -64,6 +66,11 @@ public class CommandPrintScale extends SingleLineCommand2 { new RegexLeaf("monthly"), // new RegexLeaf("daily"), // new RegexLeaf("weekly")), // + new RegexOptional(new RegexConcat( // + RegexLeaf.spaceOneOrMore(), // + new RegexLeaf("compress"), // + RegexLeaf.spaceOneOrMore(), // + new RegexLeaf("COMPRESS", "(\\d+)"))), // RegexLeaf.end()); // } @@ -72,6 +79,10 @@ public class CommandPrintScale extends SingleLineCommand2 { final String scaleString = arg.get("SCALE", 0); final PrintScale scale = PrintScale.fromString(scaleString); diagram.setPrintScale(scale); + RegexPartialMatch compress = arg.get("COMPRESS"); + if (compress.size() > 0 && compress.get(0) != null) { + diagram.setCompress(Integer.parseInt(compress.get(0))); + } return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/project/draw/TimeHeaderMonthly.java b/src/net/sourceforge/plantuml/project/draw/TimeHeaderMonthly.java index a24c26035..ece1f1c3c 100644 --- a/src/net/sourceforge/plantuml/project/draw/TimeHeaderMonthly.java +++ b/src/net/sourceforge/plantuml/project/draw/TimeHeaderMonthly.java @@ -61,9 +61,9 @@ public class TimeHeaderMonthly extends TimeHeaderCalendar { } public TimeHeaderMonthly(Day calendar, Day min, Day max, LoadPlanable defaultPlan, Map colorDays, - Map colorDaysOfWeek) { + Map colorDaysOfWeek, int compress) { super(calendar, min, max, defaultPlan, colorDays, colorDaysOfWeek, - new TimeScaleCompressed(calendar, PrintScale.MONTHLY.getCompress())); + new TimeScaleCompressed(calendar, compress)); } @Override diff --git a/src/net/sourceforge/plantuml/project/draw/TimeHeaderQuarterly.java b/src/net/sourceforge/plantuml/project/draw/TimeHeaderQuarterly.java index ff3769638..e89cce510 100644 --- a/src/net/sourceforge/plantuml/project/draw/TimeHeaderQuarterly.java +++ b/src/net/sourceforge/plantuml/project/draw/TimeHeaderQuarterly.java @@ -61,9 +61,9 @@ public class TimeHeaderQuarterly extends TimeHeaderCalendar { } public TimeHeaderQuarterly(Day calendar, Day min, Day max, LoadPlanable defaultPlan, Map colorDays, - Map colorDaysOfWeek) { + Map colorDaysOfWeek, int compress) { super(calendar, min, max, defaultPlan, colorDays, colorDaysOfWeek, - new TimeScaleCompressed(calendar, PrintScale.MONTHLY.getCompress())); + new TimeScaleCompressed(calendar, compress)); } @Override diff --git a/src/net/sourceforge/plantuml/project/draw/TimeHeaderWeekly.java b/src/net/sourceforge/plantuml/project/draw/TimeHeaderWeekly.java index cf606757c..da46357c6 100644 --- a/src/net/sourceforge/plantuml/project/draw/TimeHeaderWeekly.java +++ b/src/net/sourceforge/plantuml/project/draw/TimeHeaderWeekly.java @@ -61,9 +61,9 @@ public class TimeHeaderWeekly extends TimeHeaderCalendar { } public TimeHeaderWeekly(Day calendar, Day min, Day max, LoadPlanable defaultPlan, Map colorDays, - Map colorDaysOfWeek) { + Map colorDaysOfWeek, int compress) { super(calendar, min, max, defaultPlan, colorDays, colorDaysOfWeek, - new TimeScaleCompressed(calendar, PrintScale.WEEKLY.getCompress())); + new TimeScaleCompressed(calendar, compress)); } @Override diff --git a/src/net/sourceforge/plantuml/project/draw/TimeHeaderYearly.java b/src/net/sourceforge/plantuml/project/draw/TimeHeaderYearly.java index 138d643d9..fd78428eb 100644 --- a/src/net/sourceforge/plantuml/project/draw/TimeHeaderYearly.java +++ b/src/net/sourceforge/plantuml/project/draw/TimeHeaderYearly.java @@ -61,9 +61,9 @@ public class TimeHeaderYearly extends TimeHeaderCalendar { } public TimeHeaderYearly(Day calendar, Day min, Day max, LoadPlanable defaultPlan, Map colorDays, - Map colorDaysOfWeek) { + Map colorDaysOfWeek, int compress) { super(calendar, min, max, defaultPlan, colorDays, colorDaysOfWeek, - new TimeScaleCompressed(calendar, PrintScale.MONTHLY.getCompress())); + new TimeScaleCompressed(calendar, compress)); } @Override