calendar element display fix

This commit is contained in:
VikariiCGI 2021-03-21 16:58:20 +02:00
parent dc2e567f7b
commit 69728bb7a3
5 changed files with 977 additions and 1358 deletions

1378
example/package-lock.json generated

File diff suppressed because it is too large Load Diff

912
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -5,10 +5,11 @@ import {
getLocaleMonth, getLocaleMonth,
getWeekNumberISO8601, getWeekNumberISO8601,
} from "../../helpers/date-helper"; } from "../../helpers/date-helper";
import { DateSetup } from "../../types/date-setup";
import styles from "./calendar.module.css"; import styles from "./calendar.module.css";
export type CalendarProps = { export type CalendarProps = {
dates: Date[]; dateSetup: DateSetup;
locale: string; locale: string;
viewMode: ViewMode; viewMode: ViewMode;
headerHeight: number; headerHeight: number;
@ -18,7 +19,7 @@ export type CalendarProps = {
}; };
export const Calendar: React.FC<CalendarProps> = ({ export const Calendar: React.FC<CalendarProps> = ({
dates, dateSetup,
locale, locale,
viewMode, viewMode,
headerHeight, headerHeight,
@ -31,8 +32,8 @@ export const Calendar: React.FC<CalendarProps> = ({
const bottomValues: ReactChild[] = []; const bottomValues: ReactChild[] = [];
const topDefaultWidth = columnWidth * 6; const topDefaultWidth = columnWidth * 6;
const topDefaultHeight = headerHeight * 0.5; const topDefaultHeight = headerHeight * 0.5;
for (let i = 0; i < dates.length; i++) { for (let i = 0; i < dateSetup.dates.length; i++) {
const date = dates[i]; const date = dateSetup.dates[i];
const bottomValue = getLocaleMonth(date, locale); const bottomValue = getLocaleMonth(date, locale);
bottomValues.push( bottomValues.push(
<text <text
@ -44,7 +45,10 @@ export const Calendar: React.FC<CalendarProps> = ({
{bottomValue} {bottomValue}
</text> </text>
); );
if (i === 0 || date.getFullYear() !== dates[i - 1].getFullYear()) { if (
i === 0 ||
date.getFullYear() !== dateSetup.dates[i - 1].getFullYear()
) {
const topValue = date.getFullYear().toString(); const topValue = date.getFullYear().toString();
topValues.push( topValues.push(
<TopPartOfCalendar <TopPartOfCalendar
@ -69,6 +73,7 @@ export const Calendar: React.FC<CalendarProps> = ({
const bottomValues: ReactChild[] = []; const bottomValues: ReactChild[] = [];
let weeksCount: number = 1; let weeksCount: number = 1;
const topDefaultHeight = headerHeight * 0.5; const topDefaultHeight = headerHeight * 0.5;
const dates = dateSetup.dates;
for (let i = dates.length - 1; i >= 0; i--) { for (let i = dates.length - 1; i >= 0; i--) {
const date = dates[i]; const date = dates[i];
let topValue = ""; let topValue = "";
@ -116,6 +121,7 @@ export const Calendar: React.FC<CalendarProps> = ({
const topValues: ReactChild[] = []; const topValues: ReactChild[] = [];
const bottomValues: ReactChild[] = []; const bottomValues: ReactChild[] = [];
const topDefaultHeight = headerHeight * 0.5; const topDefaultHeight = headerHeight * 0.5;
const dates = dateSetup.dates;
for (let i = 0; i < dates.length; i++) { for (let i = 0; i < dates.length; i++) {
const date = dates[i]; const date = dates[i];
const bottomValue = date.getDate().toString(); const bottomValue = date.getDate().toString();
@ -157,7 +163,7 @@ export const Calendar: React.FC<CalendarProps> = ({
const bottomValues: ReactChild[] = []; const bottomValues: ReactChild[] = [];
const ticks = viewMode === ViewMode.HalfDay ? 2 : 4; const ticks = viewMode === ViewMode.HalfDay ? 2 : 4;
const topDefaultHeight = headerHeight * 0.5; const topDefaultHeight = headerHeight * 0.5;
const dates = dateSetup.dates;
for (let i = 0; i < dates.length; i++) { for (let i = 0; i < dates.length; i++) {
const date = dates[i]; const date = dates[i];
const bottomValue = Intl.DateTimeFormat(locale, { const bottomValue = Intl.DateTimeFormat(locale, {
@ -194,7 +200,7 @@ export const Calendar: React.FC<CalendarProps> = ({
}; };
let topValues: ReactChild[] = []; let topValues: ReactChild[] = [];
let bottomValues: ReactChild[] = []; let bottomValues: ReactChild[] = [];
switch (viewMode) { switch (dateSetup.viewMode) {
case ViewMode.Month: case ViewMode.Month:
[topValues, bottomValues] = getCalendarValuesForMonth(); [topValues, bottomValues] = getCalendarValuesForMonth();
break; break;
@ -213,7 +219,7 @@ export const Calendar: React.FC<CalendarProps> = ({
<rect <rect
x={0} x={0}
y={0} y={0}
width={columnWidth * dates.length} width={columnWidth * dateSetup.dates.length}
height={headerHeight} height={headerHeight}
className={styles.calendarHeader} className={styles.calendarHeader}
/> />

View File

@ -14,6 +14,7 @@ import { TaskGantt } from "./task-gantt";
import { BarTask } from "../../types/bar-task"; import { BarTask } from "../../types/bar-task";
import { convertToBarTasks } from "../../helpers/bar-helper"; import { convertToBarTasks } from "../../helpers/bar-helper";
import { GanttEvent } from "../../types/gantt-task-actions"; import { GanttEvent } from "../../types/gantt-task-actions";
import { DateSetup } from "../../types/date-setup";
export const Gantt: React.FunctionComponent<GanttProps> = ({ export const Gantt: React.FunctionComponent<GanttProps> = ({
tasks, tasks,
@ -49,9 +50,9 @@ export const Gantt: React.FunctionComponent<GanttProps> = ({
onSelect, onSelect,
}) => { }) => {
const wrapperRef = useRef<HTMLDivElement>(null); const wrapperRef = useRef<HTMLDivElement>(null);
const [dates, setDates] = useState<Date[]>(() => { const [dateSetup, setDateSetup] = useState<DateSetup>(() => {
const [startDate, endDate] = ganttDateRange(tasks, viewMode); const [startDate, endDate] = ganttDateRange(tasks, viewMode);
return seedDates(startDate, endDate, viewMode); return { viewMode, dates: seedDates(startDate, endDate, viewMode) };
}); });
const [taskHeight, setTaskHeight] = useState((rowHeight * barFill) / 100); const [taskHeight, setTaskHeight] = useState((rowHeight * barFill) / 100);
@ -67,14 +68,14 @@ export const Gantt: React.FunctionComponent<GanttProps> = ({
const [ignoreScrollEvent, setIgnoreScrollEvent] = useState(false); const [ignoreScrollEvent, setIgnoreScrollEvent] = useState(false);
const svgHeight = rowHeight * barTasks.length; const svgHeight = rowHeight * barTasks.length;
const gridWidth = dates.length * columnWidth; const gridWidth = dateSetup.dates.length * columnWidth;
const ganttFullHeight = barTasks.length * rowHeight; const ganttFullHeight = barTasks.length * rowHeight;
// task change events // task change events
useEffect(() => { useEffect(() => {
const [startDate, endDate] = ganttDateRange(tasks, viewMode); const [startDate, endDate] = ganttDateRange(tasks, viewMode);
const newDates = seedDates(startDate, endDate, viewMode); const newDates = seedDates(startDate, endDate, viewMode);
setDates(newDates); setDateSetup({ dates: newDates, viewMode });
setBarTasks( setBarTasks(
convertToBarTasks( convertToBarTasks(
tasks, tasks,
@ -267,11 +268,11 @@ export const Gantt: React.FunctionComponent<GanttProps> = ({
gridWidth, gridWidth,
tasks: tasks, tasks: tasks,
rowHeight, rowHeight,
dates, dates: dateSetup.dates,
todayColor, todayColor,
}; };
const calendarProps: CalendarProps = { const calendarProps: CalendarProps = {
dates, dateSetup,
locale, locale,
viewMode, viewMode,
headerHeight, headerHeight,
@ -281,7 +282,7 @@ export const Gantt: React.FunctionComponent<GanttProps> = ({
}; };
const barProps: TaskGanttContentProps = { const barProps: TaskGanttContentProps = {
tasks: barTasks, tasks: barTasks,
dates, dates: dateSetup.dates,
ganttEvent, ganttEvent,
selectedTask, selectedTask,
rowHeight, rowHeight,
@ -319,7 +320,7 @@ export const Gantt: React.FunctionComponent<GanttProps> = ({
TaskListHeader, TaskListHeader,
TaskListTable, TaskListTable,
}; };
debugger;
return ( return (
<div <div
className={styles.wrapper} className={styles.wrapper}

6
src/types/date-setup.ts Normal file
View File

@ -0,0 +1,6 @@
import { ViewMode } from "./public-types";
export interface DateSetup {
dates: Date[];
viewMode: ViewMode;
}