EN · DE · RU · FR · ES

#462: GanttChartXLabelBarRenderer.java

projectforge-business/src/main/java/org/projectforge/business/gantt/GanttChartXLabelBarRenderer.java Тип: Java · Роль: Диаграмма Ганта · Источник: projectforge-business/src/main/java/org/projectforge/business/gantt/GanttChartXLabelBarRenderer.java 380 строк · 304 кода · 44 комментария · 32 пустых
Файл исходного кода projectforge-business/src/main/java/org/projectforge/business/gantt/GanttChartXLabelBarRenderer.java, содержащий Java-код для слоя диаграммы Ганта.

Структура кода

Пакет: org.projectforge.business.gantt

Классы: GanttChartXLabelBarRenderer

Методы (7): init, getScale, draw, showNonWorkingDays, match, getXValue, getFromToDays

Поля (6): MIN_PIXEL_PER_UNIT, showNonWorkingDays, fromDate, toDate, diagramWidth, style

Импорты: 11 пакетов

Исходный код (сокращён)

package org.projectforge.business.gantt;

import org.projectforge.export.SVGColor;
import org.projectforge.export.SVGHelper;
import org.projectforge.framework.calendar.Holidays;
import org.projectforge.framework.persistence.user.api.ThreadLocalUserContext;
import org.projectforge.framework.time.DateTimeFormatter;
import org.projectforge.framework.time.PFDateTime;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

import java.time.LocalDate;
import java.time.Month;
import java.util.Date;

public class GanttChartXLabelBarRenderer
{
  private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(GanttChartXLabelBarRenderer.class);

  private static final double MIN_PIXEL_PER_UNIT = 10.0;

  private static final int[] QUARTER_SCALES = { 1, 2, 4, 8, 12};

  private static final int[] MONTH_SCALES = { 1, 2, 3, 6, 12, 24, 36, 48, 60};

  private static final int[] SCALES = { 1, 2, 5, 10, 20, 50, 100, 200, 500, 1000};

  GanttXUnit labelUnit;

  int labelScale;

  // Метки с подписями
  GanttXUnit ticksUnit;

  int ticksScale;

  // Мелкие метки
  GanttXUnit ticksUnit2;

  int ticksScale2;

  GanttXUnit gridUnit;

  int gridScale;

  String label;

  private boolean showNonWorkingDays;

  private LocalDate fromDate;

  private LocalDate toDate;

  int fromToDays = -1;

  private double diagramWidth;

  private GanttChartStyle style;

  public GanttChartXLabelBarRenderer(final LocalDate fromDate, final LocalDate toDate, final double diagramWidth, final GanttChartStyle style)
  {
    this.fromDate = fromDate;
    this.toDate = toDate;
    this.diagramWidth = diagramWidth;
    this.style = style;
    this.gridScale = style.getXGridScale();
    init();
  }

  private void init()
  {

    final int numberOfDays = getFromToDays(); // Инициализация fromToDays.
    final double numberOfWeeks = 0.25 * numberOfDays;
    final double numberOfMonths = 0.033 * numberOfDays;
    final double numberOfQuarters = numberOfMonths / 3;
    if (this.style.getXUnit() == GanttXUnit.AUTO) {
      if (diagramWidth / numberOfDays > MIN_PIXEL_PER_UNIT) {
        labelUnit = GanttXUnit.DAY;
        ticksUnit = GanttXUnit.DAY;
        ticksUnit2 = GanttXUnit.DAY;
      } else if (diagramWidth / numberOfWeeks > MIN_PIXEL_PER_UNIT) {
        labelUnit = GanttXUnit.WEEK;
        ticksUnit = GanttXUnit.WEEK;
        ticksUnit2 = GanttXUnit.DAY;
      } else if (diagramWidth / numberOfMonths > MIN_PIXEL_PER_UNIT) {
        labelUnit = GanttXUnit.MONTH;
        ticksUnit = GanttXUnit.MONTH;
        ticksUnit2 = GanttXUnit.WEEK;
      } else {
        labelUnit = GanttXUnit.QUARTER;
        ticksUnit = GanttXUnit.MONTH;
        ticksUnit2 = GanttXUnit.WEEK;
      }
    }
    this.gridUnit = ticksUnit;
    double numberOfUnits;
    if (labelUnit == GanttXUnit.DAY) {
      numberOfUnits = (double) numberOfDays;
    } else if (labelUnit == GanttXUnit.WEEK) {
      numberOfUnits = numberOfWeeks;
    } else if (labelUnit == GanttXUnit.MONTH) {
      numberOfUnits = numberOfMonths;
    } else {
      numberOfUnits = numberOfQuarters;
    }
    labelScale = style.getXLabelsScale();
    ticksScale = style.getXTicksScale();
    ticksScale2 = style.getXTicksScale2();
    if (labelUnit == GanttXUnit.QUARTER) {
      if (labelScale < 0) {
        if (style.isRelativeTimeValues()) {
          // Числа не требуют столько места, как подписи кварталов (03/2010)
          labelScale = getScale(numberOfQuarters, 50, labelUnit);
        } else {
          labelScale = getScale(numberOfQuarters, 100, labelUnit);
        }
      }
      if (ticksScale < 0) {
// ... (сокращено, всего 358 строк)

История Git

868d6abb7 2025 -> 2026
63081666f Заголовки файлов исходного кода: 2024 -> 2025.
b6092df09 Авторские права 2023 -> 2024
ab45d51fa Авторские права 2001-2022 -> 2001-2023.
5f7ef41b8 Авторские права 2021 -> 2022