TimeHeaderDaily.java
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009-2024, Arnaud Roques
*
* Project Info: https://plantuml.com
*
* If you like this project or if you find it useful, you can support us at:
*
* https://plantuml.com/patreon (only 1$ per month!)
* https://plantuml.com/paypal
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*
* Original Author: Arnaud Roques
*
*
*/
package net.sourceforge.plantuml.gantt.draw.header;
import java.time.LocalDate;
import net.sourceforge.plantuml.gantt.data.DayCalendarData;
import net.sourceforge.plantuml.gantt.data.TimeBoundsData;
import net.sourceforge.plantuml.gantt.data.TimeScaleConfigData;
import net.sourceforge.plantuml.gantt.data.TimelineStyleData;
import net.sourceforge.plantuml.gantt.data.WeekConfigData;
import net.sourceforge.plantuml.gantt.time.TimePoint;
import net.sourceforge.plantuml.gantt.time.TimePointFormat;
import net.sourceforge.plantuml.gantt.timescale.TimeScale;
import net.sourceforge.plantuml.klimt.UTranslate;
import net.sourceforge.plantuml.klimt.drawing.UGraphic;
import net.sourceforge.plantuml.klimt.font.FontConfiguration;
import net.sourceforge.plantuml.klimt.font.StringBounder;
import net.sourceforge.plantuml.style.SName;
class TimeHeaderDaily extends TimeHeaderCalendar {
public TimeHeaderDaily(TimeScale timeScale, WeekConfigData weekConfigData, DayCalendarData dayCalendar,
TimeBoundsData timeBounds, TimeScaleConfigData scaleConfig, TimelineStyleData timelineStyle) {
super(weekConfigData, dayCalendar, timeBounds, scaleConfig, timelineStyle, timeScale);
}
private double getH1() {
return timelineStyle.getFontSizeMonth() + 2;
}
private double getH2() {
return getH1() + timelineStyle.getFontSizeDay() + 2;
}
private double getH3() {
return getH2() + timelineStyle.getFontSizeDay() + 3;
}
@Override
public double getTimeHeaderHeight(StringBounder stringBounder) {
return getH3();
}
@Override
public double getTimeFooterHeight(StringBounder stringBounder) {
final double h1 = timelineStyle.getFontSizeDay();
final double h2 = timelineStyle.getFontSizeDay();
final double h3 = timelineStyle.getFontSizeMonth();
return h1 + h2 + h3 + 8;
}
private double getHeaderNameDayHeight() {
if (dayCalendar.getNameDays().size() > 0) {
final double h = timelineStyle.getFontSizeDay() + 6;
return h;
}
return 0;
}
@Override
public double getFullHeaderHeight(StringBounder stringBounder) {
return getTimeHeaderHeight(stringBounder) + getHeaderNameDayHeight();
}
@Override
public void drawTimeHeaderInternal(final UGraphic ug, double totalHeightWithoutFooter) {
drawMonths(ug);
drawTextsDayOfWeek(ug.apply(UTranslate.dy(getH1())));
drawTextDayOfMonth(ug.apply(UTranslate.dy(getH2())));
printVerticalSeparators(ug, totalHeightWithoutFooter);
printNamedDays(ug);
drawHline(ug, getFullHeaderHeight(ug.getStringBounder()));
drawHline(ug, totalHeightWithoutFooter);
}
@Override
protected void printVerticalSeparators(final UGraphic ug, double totalHeightWithoutFooter) {
final UGraphic ugVerticalSeparator = timelineStyle.applyVerticalSeparatorStyle(ug);
final UGraphic ugLineColor = ug.apply(getLineColor());
for (LocalDate day = getMinDay(); day.compareTo(getMaxDay()) <= 0; day = day.plusDays(1)) {
final TimePoint wink = TimePoint.ofStartOfDay(day);
if (isBold(day) || getTimeScale().getWidth(wink.decrement()) == 0)
drawVline(ugVerticalSeparator, getTimeScale().getPosition(wink),
getFullHeaderHeight(ug.getStringBounder()), totalHeightWithoutFooter);
else
drawVline(ugLineColor, getTimeScale().getPosition(wink), getFullHeaderHeight(ug.getStringBounder()),
totalHeightWithoutFooter);
}
final double end = getTimeScale().getPosition(TimePoint.ofStartOfDay(getMaxDay().plusDays(1)));
drawVline(ugLineColor, end, getFullHeaderHeight(ug.getStringBounder()), totalHeightWithoutFooter);
}
@Override
public void drawTimeFooter(UGraphic ug) {
final double h = timelineStyle.getFontSizeDay() + 2;
drawTextsDayOfWeek(ug);
drawTextDayOfMonth(ug.apply(UTranslate.dy(h + 2)));
drawMonths(ug.apply(UTranslate.dy(2 * h + 3)));
}
private void drawTextsDayOfWeek(UGraphic ug) {
for (LocalDate day = getMinDay(); day.compareTo(getMaxDay()) <= 0; day = day.plusDays(1)) {
final TimePoint wink = TimePoint.ofStartOfDay(day);
if (isHidden(wink))
continue;
final double x1 = getTimeScale().getPosition(wink);
final double x2 = getTimeScale().getPosition(wink.increment());
final FontConfiguration fc = getFc(wink);
printCentered(ug, false, x1, x2, wink, fc, TimePointFormat.DAY_OF_WEEK_SHORT);
}
}
private void drawTextDayOfMonth(UGraphic ug) {
for (LocalDate day = getMinDay(); day.compareTo(getMaxDay()) <= 0; day = day.plusDays(1)) {
final TimePoint wink = TimePoint.ofStartOfDay(day);
if (isHidden(wink))
continue;
final double x1 = getTimeScale().getPosition(wink);
final double x2 = getTimeScale().getPosition(wink.increment());
final FontConfiguration fc = getFc(wink);
printCentered(ug, false, x1, x2, wink, fc, TimePointFormat.DAY_OF_MONTH);
}
}
private boolean isHidden(TimePoint wink) {
if (scaleConfig.isHideClosed() && dayCalendar.getOpenClose().isClosed(wink.toDay()))
return true;
return false;
}
private FontConfiguration fc1;
private FontConfiguration fc2;
private FontConfiguration getFc(TimePoint wink) {
if (isZeroOnDay(wink)) {
if (fc1 == null)
fc1 = getFontConfigurationSLOW(SName.day, false, closedFontColor());
return fc1;
}
if (fc2 == null)
fc2 = getFontConfigurationSLOW(SName.day, false, openFontColor());
return fc2;
}
private void drawMonths(final UGraphic ug) {
final FontConfiguration fc = getFontConfigurationSLOW(SName.month, true, openFontColor());
TimePoint last = null;
double lastChangeMonth = -1;
for (LocalDate day = getMinDay(); day.compareTo(getMaxDay()) <= 0; day = day.plusDays(1)) {
final TimePoint wink = TimePoint.ofStartOfDay(day);
if (isHidden(wink))
continue;
final double x1 = getTimeScale().getPosition(wink);
if (last == null || wink.monthYear().equals(last.monthYear()) == false) {
if (last != null)
printMonth(ug, last, lastChangeMonth, x1, fc);
lastChangeMonth = x1;
last = wink;
}
}
final double x1 = getTimeScale().getPosition(TimePoint.ofStartOfDay(getMaxDay().plusDays(1)));
if (x1 > lastChangeMonth)
printMonth(ug, last, lastChangeMonth, x1, fc);
}
private void printMonth(UGraphic ug, TimePoint monthYear, double start, double end, FontConfiguration fc) {
printCentered(ug, false, start, end, monthYear, fc, TimePointFormat.MONTH_SHORT, TimePointFormat.MONTH_LONG,
TimePointFormat.MONTH_YEAR_LONG);
}
}