Skip to content

Commit

Permalink
feat: several gantt improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudroques committed Nov 27, 2023
1 parent f0b3e69 commit e991c46
Show file tree
Hide file tree
Showing 30 changed files with 731 additions and 349 deletions.
7 changes: 7 additions & 0 deletions skin/plantuml.skin
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,13 @@ ganttDiagram {
timeline {
BackgroundColor transparent
LineColor #C0C0C0
FontSize 10
month {
FontSize 12
}
year {
FontSize 14
}
}
closed {
BackGroundColor #F1E5E5
Expand Down
51 changes: 24 additions & 27 deletions src/net/sourceforge/plantuml/project/GanttDiagram.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
import net.sourceforge.plantuml.svek.GraphvizCrash;
import net.sourceforge.plantuml.text.BackSlash;

public class GanttDiagram extends TitledDiagram implements ToTaskDraw, WithSprite {
public class GanttDiagram extends TitledDiagram implements ToTaskDraw, WithSprite, GanttStyle {

private final Map<Task, TaskDraw> draws = new LinkedHashMap<Task, TaskDraw>();
private final Map<TaskCode, Task> tasks = new LinkedHashMap<TaskCode, Task>();
Expand Down Expand Up @@ -233,8 +233,9 @@ private TextBlock getTextBlock(StringBounder stringBounder) {
this.min = printStart;
this.max = printEnd;
}
final TimeHeader timeHeader = getTimeHeader();
initTaskAndResourceDraws(timeHeader.getTimeScale(), timeHeader.getFullHeaderHeight(), stringBounder);
final TimeHeader timeHeader = getTimeHeader(stringBounder);
initTaskAndResourceDraws(timeHeader.getTimeScale(), timeHeader.getFullHeaderHeight(stringBounder),
stringBounder);
return new AbstractTextBlock() {

public void drawU(UGraphic ug) {
Expand All @@ -250,12 +251,12 @@ public void drawU(UGraphic ug) {
final HColor back = timelineStyle.value(PName.BackGroundColor).asColor(getIHtmlColorSet());
if (back.isTransparent() == false) {
final URectangle rect1 = URectangle.build(calculateDimension(ug.getStringBounder()).getWidth(),
timeHeader.getTimeHeaderHeight());
timeHeader.getTimeHeaderHeight(ug.getStringBounder()));
ug.apply(back.bg()).draw(rect1);
if (showFootbox) {
final URectangle rect2 = URectangle.build(
calculateDimension(ug.getStringBounder()).getWidth(),
timeHeader.getTimeFooterHeight());
timeHeader.getTimeFooterHeight(ug.getStringBounder()));
ug.apply(back.bg()).apply(UTranslate.dy(totalHeightWithoutFooter)).draw(rect2);
}
}
Expand Down Expand Up @@ -297,7 +298,7 @@ private double getTitlesColumnWidth(StringBounder stringBounder) {

public XDimension2D calculateDimension(StringBounder stringBounder) {
return new XDimension2D(getTitlesColumnWidth(stringBounder) + getBarsColumnWidth(timeHeader),
getTotalHeight(timeHeader));
getTotalHeight(stringBounder, timeHeader));
}

private double getBarsColumnWidth(final TimeHeader timeHeader) {
Expand All @@ -309,53 +310,49 @@ private double getBarsColumnWidth(final TimeHeader timeHeader) {
};
}

private TimeHeader getTimeHeader() {
private TimeHeader getTimeHeader(StringBounder stringBounder) {
if (openClose.getStartingDay() == null)
return new TimeHeaderSimple(thParam(), printScale);
return new TimeHeaderSimple(stringBounder, thParam(), printScale);
else if (printScale == PrintScale.DAILY)
return new TimeHeaderDaily(thParam(), nameDays, printStart, printEnd);
return new TimeHeaderDaily(stringBounder, thParam(), nameDays, printStart, printEnd);
else if (printScale == PrintScale.WEEKLY)
return new TimeHeaderWeekly(thParam(), weekNumberStrategy, withCalendarDate);
return new TimeHeaderWeekly(stringBounder, thParam(), weekNumberStrategy, withCalendarDate);
else if (printScale == PrintScale.MONTHLY)
return new TimeHeaderMonthly(thParam());
return new TimeHeaderMonthly(stringBounder, thParam());
else if (printScale == PrintScale.QUARTERLY)
return new TimeHeaderQuarterly(thParam());
return new TimeHeaderQuarterly(stringBounder, thParam());
else if (printScale == PrintScale.YEARLY)
return new TimeHeaderYearly(thParam());
return new TimeHeaderYearly(stringBounder, thParam());
else
throw new IllegalStateException();

}

private TimeHeaderParameters thParam() {
return new TimeHeaderParameters(colorDays(), getFactorScale(), min, max, getIHtmlColorSet(), getTimelineStyle(),
getClosedStyle(), locale, openClose, colorDaysOfWeek, verticalSeparatorBefore,
getVerticalSeparatorStyle());
return new TimeHeaderParameters(colorDays(), getFactorScale(), min, max, getIHtmlColorSet(), locale, openClose,
colorDaysOfWeek, verticalSeparatorBefore, this);
}

private Map<Day, HColor> colorDays() {
colorDaysInternal.putAll(colorDaysToday);
return Collections.unmodifiableMap(colorDaysInternal);
}

private Style getClosedStyle() {
return StyleSignatureBasic.of(SName.root, SName.element, SName.ganttDiagram, SName.closed)
.getMergedStyle(getCurrentStyleBuilder());
}

private Style getTimelineStyle() {
return StyleSignatureBasic.of(SName.root, SName.element, SName.ganttDiagram, SName.timeline)
@Override
public final Style getStyle(SName param) {
return StyleSignatureBasic.of(SName.root, SName.element, SName.ganttDiagram, param)
.getMergedStyle(getCurrentStyleBuilder());
}

private Style getVerticalSeparatorStyle() {
return StyleSignatureBasic.of(SName.root, SName.element, SName.ganttDiagram, SName.verticalSeparator)
@Override
public final Style getStyle(SName param1, SName param2) {
return StyleSignatureBasic.of(SName.root, SName.element, SName.ganttDiagram, param1, param2)
.getMergedStyle(getCurrentStyleBuilder());
}

private double getTotalHeight(TimeHeader timeHeader) {
private double getTotalHeight(StringBounder stringBounder, TimeHeader timeHeader) {
if (showFootbox)
return totalHeightWithoutFooter + timeHeader.getTimeFooterHeight();
return totalHeightWithoutFooter + timeHeader.getTimeFooterHeight(stringBounder);

return totalHeightWithoutFooter;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@
*
*
*/
package net.sourceforge.plantuml.project.lang;
package net.sourceforge.plantuml.project;

import net.sourceforge.plantuml.regex.IRegex;
import net.sourceforge.plantuml.style.SName;
import net.sourceforge.plantuml.style.Style;

public interface Adverbial {
public interface GanttStyle {

public IRegex toRegex();
public Style getStyle(SName param);

public Style getStyle(SName param1, SName param2);

}
40 changes: 27 additions & 13 deletions src/net/sourceforge/plantuml/project/TimeHeaderParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,41 +43,39 @@
import net.sourceforge.plantuml.klimt.color.HColor;
import net.sourceforge.plantuml.klimt.color.HColorSet;
import net.sourceforge.plantuml.klimt.drawing.UGraphic;
import net.sourceforge.plantuml.klimt.font.StringBounder;
import net.sourceforge.plantuml.project.time.Day;
import net.sourceforge.plantuml.project.time.DayOfWeek;
import net.sourceforge.plantuml.style.PName;
import net.sourceforge.plantuml.style.SName;
import net.sourceforge.plantuml.style.Style;

public class TimeHeaderParameters {
public class TimeHeaderParameters implements GanttStyle {

private final Map<Day, HColor> colorDays;
private final double scale;
private final Day min;
private final Day max;
private final HColorSet colorSet;
private final Style timelineStyle;
private final Style closedStyle;
private final Style verticalSeparatorStyle;
private final GanttStyle ganttStyle;
private final Locale locale;
private final OpenClose openClose;
private final Map<DayOfWeek, HColor> colorDaysOfWeek;
private final Set<Day> verticalSeparatorBefore;

public TimeHeaderParameters(Map<Day, HColor> colorDays, double scale, Day min, Day max, HColorSet colorSet,
Style timelineStyle, Style closedStyle, Locale locale, OpenClose openClose,
Map<DayOfWeek, HColor> colorDaysOfWeek, Set<Day> verticalSeparatorBefore, Style verticalSeparatorStyle) {
Locale locale, OpenClose openClose, Map<DayOfWeek, HColor> colorDaysOfWeek,
Set<Day> verticalSeparatorBefore, GanttStyle ganttStyle) {
this.colorDays = colorDays;
this.scale = scale;
this.min = min;
this.max = max;
this.colorSet = colorSet;
this.timelineStyle = timelineStyle;
this.closedStyle = closedStyle;
this.ganttStyle = ganttStyle;
this.locale = locale;
this.openClose = openClose;
this.colorDaysOfWeek = colorDaysOfWeek;
this.verticalSeparatorBefore = verticalSeparatorBefore;
this.verticalSeparatorStyle = verticalSeparatorStyle;
}

public HColor getColor(Day wink) {
Expand Down Expand Up @@ -105,11 +103,11 @@ public final HColorSet getColorSet() {
}

public final Style getTimelineStyle() {
return timelineStyle;
return getStyle(SName.timeline);
}

public final Style getClosedStyle() {
return closedStyle;
return getStyle(SName.closed);
}

public final Locale getLocale() {
Expand All @@ -129,9 +127,25 @@ public final Set<Day> getVerticalSeparatorBefore() {
}

public final UGraphic forVerticalSeparator(UGraphic ug) {
final HColor color = verticalSeparatorStyle.value(PName.LineColor).asColor(getColorSet());
final UStroke stroke = verticalSeparatorStyle.getStroke();
final Style style = getStyle(SName.verticalSeparator);
final HColor color = style.value(PName.LineColor).asColor(getColorSet());
final UStroke stroke = style.getStroke();
return ug.apply(color).apply(stroke);
}

@Override
public final Style getStyle(SName param1, SName param2) {
return ganttStyle.getStyle(param1, param2);
}

@Override
public Style getStyle(SName param) {
return ganttStyle.getStyle(param);
}

public double getCellWidth(StringBounder stringBounder) {
final double w = getStyle(SName.timeline, SName.day).value(PName.FontSize).asDouble();
return w * 1.6;
}

}
15 changes: 15 additions & 0 deletions src/net/sourceforge/plantuml/project/core/AbstractTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,42 @@ public abstract class AbstractTask implements Task {
private final StyleBuilder styleBuilder;

private Task row;
private String displayString;

protected AbstractTask(StyleBuilder styleBuilder, TaskCode code) {
this.styleBuilder = styleBuilder;
this.code = code;
}

@Override
final public void putInSameRowAs(Task row) {
if (this != row)
this.row = row;
}

@Override
public final Task getRow() {
return row;
}

@Override
public final TaskCode getCode() {
return code;
}

@Override
public final StyleBuilder getStyleBuilder() {
return styleBuilder;
}

@Override
public void setDisplay(String displayString) {
this.displayString = displayString;
}

@Override
public String getDisplayString() {
return this.displayString;
}

}
4 changes: 4 additions & 0 deletions src/net/sourceforge/plantuml/project/core/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,8 @@ public interface Task extends Moment {

public boolean isAssignedTo(Resource res);

public void setDisplay(String displayString);

public String getDisplayString();

}
28 changes: 19 additions & 9 deletions src/net/sourceforge/plantuml/project/draw/TaskDrawDiamond.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,29 +134,39 @@ protected TextBlock getTitle() {
@Override
public void drawU(UGraphic ug) {

if (url != null)
ug.startUrl(url);

final String displayString = getTask().getDisplayString();

final Style style = getStyle();
final ClockwiseTopRightBottomLeft margin = style.getMargin();
ug = ug.apply(UTranslate.dy(margin.getTop()));

final double x1 = timeScale.getStartingPosition(start);
final double x2 = timeScale.getEndingPosition(start);
final double width = getDiamondHeight();
final double delta = x2 - x1 - width;

if (url != null)
ug.startUrl(url);

drawShape(applyColors(ug).apply(UTranslate.dx(x1 + delta / 2)));
ug = ug.apply(UTranslate.dx(x1));

if (displayString == null) {
final double x2 = timeScale.getEndingPosition(start);
final double width = getDiamondHeight();
final double delta = x2 - x1 - width;
ug = ug.apply(UTranslate.dx(delta / 2));
drawShape(applyColors(ug));
} else {
final TextBlock draw = Display.getWithNewlines(displayString).create(getFontConfiguration(),
HorizontalAlignment.LEFT, new SpriteContainerEmpty());
draw.drawU(ug);
}
if (url != null)
ug.closeUrl();
}

private UGraphic applyColors(UGraphic ug) {
final CenterBorderColor col = this.getColors();
if (col != null && col.isOk()) {
if (col != null && col.isOk())
return col.apply(ug);
}

return ug.apply(getLineColor()).apply(getBackgroundColor().bg());
}

Expand Down
Loading

0 comments on commit e991c46

Please sign in to comment.