2020-08-05 08:14:22 +03:00
|
|
|
import React, { useRef } from "react";
|
|
|
|
|
import { ViewMode, GanttProps } from "../../types/public-types";
|
|
|
|
|
import { Grid, GridProps } from "../Grid/grid";
|
|
|
|
|
import { Calendar, CalendarProps } from "../Calendar/calendar";
|
|
|
|
|
import { GanttContent, GanttContentProps } from "./gantt-content";
|
|
|
|
|
import { ganttDateRange, seedDates } from "../../helpers/date-helper";
|
2020-07-22 20:50:43 +03:00
|
|
|
|
|
|
|
|
export const Gantt: React.SFC<GanttProps> = ({
|
|
|
|
|
tasks,
|
|
|
|
|
headerHeight = 50,
|
|
|
|
|
columnWidth = 60,
|
|
|
|
|
rowHeight = 50,
|
|
|
|
|
viewMode = ViewMode.Day,
|
2020-08-05 08:14:22 +03:00
|
|
|
locale = "en-GB",
|
2020-07-22 20:50:43 +03:00
|
|
|
barFill = 60,
|
|
|
|
|
barCornerRadius = 3,
|
2020-08-05 08:14:22 +03:00
|
|
|
barProgressColor = "#a3a3ff",
|
|
|
|
|
barProgressSelectedColor = "#8282f5",
|
|
|
|
|
barBackgroundColor = "#b8c2cc",
|
|
|
|
|
barBackgroundSelectedColor = "#aeb8c2",
|
2020-07-22 20:50:43 +03:00
|
|
|
handleWidth = 8,
|
|
|
|
|
timeStep = 300000,
|
2020-08-05 08:14:22 +03:00
|
|
|
arrowColor = "grey",
|
|
|
|
|
fontFamily = "Arial, Roboto, Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue",
|
|
|
|
|
fontSize = "14px",
|
2020-07-22 20:50:43 +03:00
|
|
|
arrowIndent = 20,
|
2020-08-05 08:14:22 +03:00
|
|
|
todayColor = "rgba(252, 248, 227, 0.5)",
|
2020-07-22 20:50:43 +03:00
|
|
|
onDateChange,
|
|
|
|
|
onProgressChange,
|
|
|
|
|
onDoubleClick,
|
|
|
|
|
onTaskDelete,
|
|
|
|
|
getTooltipContent,
|
|
|
|
|
}) => {
|
|
|
|
|
const [startDate, endDate] = ganttDateRange(tasks, viewMode);
|
|
|
|
|
const dates = seedDates(startDate, endDate, viewMode);
|
2020-08-09 10:51:25 +03:00
|
|
|
const svg = useRef<SVGSVGElement>(null);
|
2020-07-22 20:50:43 +03:00
|
|
|
|
|
|
|
|
const gridProps: GridProps = {
|
|
|
|
|
columnWidth,
|
|
|
|
|
gridWidth: dates.length * columnWidth,
|
|
|
|
|
tasks,
|
|
|
|
|
rowHeight,
|
|
|
|
|
headerHeight,
|
|
|
|
|
dates,
|
2020-07-30 00:01:51 +03:00
|
|
|
todayColor,
|
2020-07-22 20:50:43 +03:00
|
|
|
};
|
|
|
|
|
const calendarProps: CalendarProps = {
|
|
|
|
|
dates,
|
|
|
|
|
locale,
|
|
|
|
|
viewMode,
|
|
|
|
|
headerHeight,
|
|
|
|
|
columnWidth,
|
|
|
|
|
fontFamily,
|
|
|
|
|
fontSize,
|
|
|
|
|
};
|
|
|
|
|
const barProps: GanttContentProps = {
|
|
|
|
|
tasks,
|
|
|
|
|
rowHeight,
|
|
|
|
|
barCornerRadius,
|
|
|
|
|
columnWidth,
|
|
|
|
|
dates,
|
|
|
|
|
barFill,
|
2020-07-30 00:01:51 +03:00
|
|
|
barProgressColor,
|
|
|
|
|
barProgressSelectedColor,
|
|
|
|
|
barBackgroundColor,
|
|
|
|
|
barBackgroundSelectedColor,
|
2020-07-22 20:50:43 +03:00
|
|
|
headerHeight,
|
|
|
|
|
handleWidth,
|
|
|
|
|
timeStep,
|
|
|
|
|
arrowColor,
|
|
|
|
|
fontFamily,
|
|
|
|
|
fontSize,
|
|
|
|
|
arrowIndent,
|
2020-08-09 10:51:25 +03:00
|
|
|
svg,
|
2020-07-22 20:50:43 +03:00
|
|
|
onDateChange,
|
|
|
|
|
onProgressChange,
|
|
|
|
|
onDoubleClick,
|
|
|
|
|
onTaskDelete,
|
|
|
|
|
getTooltipContent,
|
|
|
|
|
};
|
|
|
|
|
return (
|
|
|
|
|
<svg
|
|
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
|
|
|
width={columnWidth * dates.length}
|
|
|
|
|
height={headerHeight + rowHeight * tasks.length}
|
|
|
|
|
fontFamily={fontFamily}
|
2020-08-09 10:51:25 +03:00
|
|
|
ref={svg}
|
2020-07-22 20:50:43 +03:00
|
|
|
>
|
|
|
|
|
<Grid {...gridProps} />
|
|
|
|
|
<Calendar {...calendarProps} />
|
|
|
|
|
<GanttContent {...barProps} />
|
|
|
|
|
</svg>
|
|
|
|
|
);
|
|
|
|
|
};
|