1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-16 23:22:24 +00:00

Merge pull request #440 from Nordes/feature/432-gantt_color_DaysOfWeek

[GANTT] Implement "[day] are colored in #AAAAFF"
This commit is contained in:
arnaudroques 2021-01-08 18:35:24 +01:00 committed by GitHub
commit 3a7e935cec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 9 deletions

View File

@ -118,6 +118,7 @@ public class GanttDiagram extends TitledDiagram implements ToTaskDraw, WithSprit
private final Map<String, Resource> resources = new LinkedHashMap<String, Resource>(); private final Map<String, Resource> resources = new LinkedHashMap<String, Resource>();
private final Map<Day, HColor> colorDays = new HashMap<Day, HColor>(); private final Map<Day, HColor> colorDays = new HashMap<Day, HColor>();
private final Map<DayOfWeek, HColor> colorDaysOfWeek = new HashMap<DayOfWeek, HColor>();
private final Map<Day, String> nameDays = new HashMap<Day, String>(); private final Map<Day, String> nameDays = new HashMap<Day, String>();
private PrintScale printScale = PrintScale.DAILY; private PrintScale printScale = PrintScale.DAILY;
@ -260,12 +261,12 @@ public class GanttDiagram extends TitledDiagram implements ToTaskDraw, WithSprit
if (openClose.getCalendar() == null) { if (openClose.getCalendar() == null) {
return new TimeHeaderSimple(min, max); return new TimeHeaderSimple(min, max);
} else if (printScale == PrintScale.WEEKLY) { } else if (printScale == PrintScale.WEEKLY) {
return new TimeHeaderWeekly(openClose.getCalendar(), min, max, openClose, colorDays, nameDays); return new TimeHeaderWeekly(openClose.getCalendar(), min, max, openClose, colorDays, colorDaysOfWeek, nameDays);
} else if (printScale == PrintScale.MONTHLY) { } else if (printScale == PrintScale.MONTHLY) {
return new TimeHeaderMonthly(openClose.getCalendar(), min, max, openClose, colorDays, nameDays); return new TimeHeaderMonthly(openClose.getCalendar(), min, max, openClose, colorDays, colorDaysOfWeek, nameDays);
} else { } else {
return new TimeHeaderDaily(openClose.getCalendar(), min, max, openClose, colorDays, nameDays, printStart, return new TimeHeaderDaily(openClose.getCalendar(), min, max, openClose, colorDays, colorDaysOfWeek, nameDays,
printEnd); printStart, printEnd);
} }
} }
@ -673,6 +674,10 @@ public class GanttDiagram extends TitledDiagram implements ToTaskDraw, WithSprit
colorDays.put(day, color); colorDays.put(day, color);
} }
public void colorDay(DayOfWeek day, HColor color) {
colorDaysOfWeek.put(day, color);
}
public void nameDay(Day day, String name) { public void nameDay(Day day, String name) {
nameDays.put(day, name); nameDays.put(day, name);
} }

View File

@ -40,6 +40,7 @@ import java.util.Map;
import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.graphic.TextBlock;
import net.sourceforge.plantuml.project.LoadPlanable; import net.sourceforge.plantuml.project.LoadPlanable;
import net.sourceforge.plantuml.project.time.Day; import net.sourceforge.plantuml.project.time.Day;
import net.sourceforge.plantuml.project.time.DayOfWeek;
import net.sourceforge.plantuml.project.time.MonthYear; import net.sourceforge.plantuml.project.time.MonthYear;
import net.sourceforge.plantuml.project.timescale.TimeScaleDaily; import net.sourceforge.plantuml.project.timescale.TimeScaleDaily;
import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UGraphic;
@ -61,13 +62,15 @@ public class TimeHeaderDaily extends TimeHeader {
private final LoadPlanable defaultPlan; private final LoadPlanable defaultPlan;
private final Map<Day, HColor> colorDays; private final Map<Day, HColor> colorDays;
private final Map<DayOfWeek, HColor> colorDaysOfWeek;
private final Map<Day, String> nameDays; private final Map<Day, String> nameDays;
public TimeHeaderDaily(Day calendar, Day min, Day max, LoadPlanable defaultPlan, Map<Day, HColor> colorDays, public TimeHeaderDaily(Day calendar, Day min, Day max, LoadPlanable defaultPlan, Map<Day, HColor> colorDays,
Map<Day, String> nameDays, Day printStart, Day printEnd) { Map<DayOfWeek, HColor> colorDaysOfWeek, Map<Day, String> nameDays, Day printStart, Day printEnd) {
super(min, max, new TimeScaleDaily(calendar, printStart)); super(min, max, new TimeScaleDaily(calendar, printStart));
this.defaultPlan = defaultPlan; this.defaultPlan = defaultPlan;
this.colorDays = colorDays; this.colorDays = colorDays;
this.colorDaysOfWeek = colorDaysOfWeek;
this.nameDays = nameDays; this.nameDays = nameDays;
} }
@ -99,6 +102,11 @@ public class TimeHeaderDaily extends TimeHeader {
final double x1 = getTimeScale().getStartingPosition(wink); final double x1 = getTimeScale().getStartingPosition(wink);
final double x2 = getTimeScale().getEndingPosition(wink); final double x2 = getTimeScale().getEndingPosition(wink);
HColor back = colorDays.get(wink); HColor back = colorDays.get(wink);
// Day of week should be stronger than period of time (back color).
HColor backDoW = colorDaysOfWeek.get(wink.getDayOfWeek());
if (backDoW != null) {
back = backDoW;
}
if (back == null && defaultPlan.getLoadAt(wink) == 0) { if (back == null && defaultPlan.getLoadAt(wink) == 0) {
back = veryLightGray; back = veryLightGray;
} }

View File

@ -41,6 +41,7 @@ import net.sourceforge.plantuml.graphic.TextBlock;
import net.sourceforge.plantuml.project.LoadPlanable; import net.sourceforge.plantuml.project.LoadPlanable;
import net.sourceforge.plantuml.project.core.PrintScale; import net.sourceforge.plantuml.project.core.PrintScale;
import net.sourceforge.plantuml.project.time.Day; import net.sourceforge.plantuml.project.time.Day;
import net.sourceforge.plantuml.project.time.DayOfWeek;
import net.sourceforge.plantuml.project.time.MonthYear; import net.sourceforge.plantuml.project.time.MonthYear;
import net.sourceforge.plantuml.project.timescale.TimeScaleCompressed; import net.sourceforge.plantuml.project.timescale.TimeScaleCompressed;
import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UGraphic;
@ -60,7 +61,7 @@ public class TimeHeaderMonthly extends TimeHeader {
} }
public TimeHeaderMonthly(Day calendar, Day min, Day max, LoadPlanable defaultPlan, Map<Day, HColor> colorDays, public TimeHeaderMonthly(Day calendar, Day min, Day max, LoadPlanable defaultPlan, Map<Day, HColor> colorDays,
Map<Day, String> nameDays) { Map<DayOfWeek, HColor> colorDaysOfWeek, Map<Day, String> nameDays) {
super(min, max, new TimeScaleCompressed(calendar, PrintScale.MONTHLY.getCompress())); super(min, max, new TimeScaleCompressed(calendar, PrintScale.MONTHLY.getCompress()));
} }

View File

@ -54,6 +54,7 @@ public class TimeHeaderWeekly extends TimeHeader {
private final LoadPlanable defaultPlan; private final LoadPlanable defaultPlan;
private final Map<Day, HColor> colorDays; private final Map<Day, HColor> colorDays;
private final Map<DayOfWeek, HColor> colorDaysOfWeek;
protected double getTimeHeaderHeight() { protected double getTimeHeaderHeight() {
return 16 + 13; return 16 + 13;
@ -64,10 +65,11 @@ public class TimeHeaderWeekly extends TimeHeader {
} }
public TimeHeaderWeekly(Day calendar, Day min, Day max, LoadPlanable defaultPlan, Map<Day, HColor> colorDays, public TimeHeaderWeekly(Day calendar, Day min, Day max, LoadPlanable defaultPlan, Map<Day, HColor> colorDays,
Map<Day, String> nameDays) { Map<DayOfWeek, HColor> colorDaysOfWeek, Map<Day, String> nameDays) {
super(min, max, new TimeScaleCompressed(calendar, PrintScale.WEEKLY.getCompress())); super(min, max, new TimeScaleCompressed(calendar, PrintScale.WEEKLY.getCompress()));
this.defaultPlan = defaultPlan; this.defaultPlan = defaultPlan;
this.colorDays = colorDays; this.colorDays = colorDays;
this.colorDaysOfWeek = colorDaysOfWeek;
} }
@Override @Override
@ -98,8 +100,12 @@ public class TimeHeaderWeekly extends TimeHeader {
HColor lastColor = null; HColor lastColor = null;
for (Day wink = min; wink.compareTo(max) <= 0; wink = wink.increment()) { for (Day wink = min; wink.compareTo(max) <= 0; wink = wink.increment()) {
HColor back = colorDays.get(wink); HColor back = colorDays.get(wink);
// Day of week should be stronger than period of time (back color).
HColor backDoW = colorDaysOfWeek.get(wink.getDayOfWeek());
if (backDoW != null) {
back = backDoW;
}
if (back == null && defaultPlan.getLoadAt(wink) == 0) { if (back == null && defaultPlan.getLoadAt(wink) == 0) {
back = veryLightGray; back = veryLightGray;
} }

View File

@ -45,6 +45,7 @@ import net.sourceforge.plantuml.command.regex.RegexResult;
import net.sourceforge.plantuml.project.Failable; import net.sourceforge.plantuml.project.Failable;
import net.sourceforge.plantuml.project.GanttDiagram; import net.sourceforge.plantuml.project.GanttDiagram;
import net.sourceforge.plantuml.project.time.DayOfWeek; import net.sourceforge.plantuml.project.time.DayOfWeek;
import net.sourceforge.plantuml.ugraphic.color.HColor;
public class SubjectDayOfWeek implements Subject { public class SubjectDayOfWeek implements Subject {
@ -58,7 +59,7 @@ public class SubjectDayOfWeek implements Subject {
} }
public Collection<? extends SentenceSimple> getSentences() { public Collection<? extends SentenceSimple> getSentences() {
return Arrays.asList(new AreClose()); return Arrays.asList(new AreClose(), new InColor());
} }
class AreClose extends SentenceSimple { class AreClose extends SentenceSimple {
@ -76,4 +77,21 @@ public class SubjectDayOfWeek implements Subject {
} }
class InColor extends SentenceSimple {
public InColor() {
super(SubjectDayOfWeek.this, Verbs.isOrAre(), new ComplementInColors2());
}
@Override
public CommandExecutionResult execute(GanttDiagram project, Object subject, Object complement) {
final HColor color = ((CenterBorderColor) complement).getCenter();
final DayOfWeek day = (DayOfWeek) subject;
project.colorDay(day, color);
return CommandExecutionResult.ok();
}
}
} }