(null);
useEffect(() => {
@@ -18,7 +26,11 @@ export const VerticalScroll: React.FC<{
return (
= ({
task,
isProgressChangeable,
isDateChangeable,
+ rtl,
onEventStart,
isSelected,
}) => {
const progressPoint = getProgressPoint(
- task.progressWidth + task.x1,
+ +!rtl * task.progressWidth + task.progressX,
task.y,
task.height
);
diff --git a/src/components/task-item/task-item.tsx b/src/components/task-item/task-item.tsx
index 3314bbb..fc20311 100644
--- a/src/components/task-item/task-item.tsx
+++ b/src/components/task-item/task-item.tsx
@@ -15,6 +15,7 @@ export type TaskItemProps = {
isDateChangeable: boolean;
isDelete: boolean;
isSelected: boolean;
+ rtl: boolean;
onEventStart: (
action: GanttContentMoveAction,
selectedTask: BarTask,
@@ -29,6 +30,7 @@ export const TaskItem: React.FC = props => {
isDelete,
taskHeight,
isSelected,
+ rtl,
onEventStart,
} = {
...props,
@@ -63,9 +65,19 @@ export const TaskItem: React.FC = props => {
const getX = () => {
const width = task.x2 - task.x1;
const hasChild = task.barChildren.length > 0;
- return isTextInside
- ? task.x1 + width * 0.5
- : task.x1 + width + arrowIndent * +hasChild + arrowIndent * 0.2;
+ if (isTextInside) {
+ return task.x1 + width * 0.5;
+ }
+ if (rtl && textRef.current) {
+ return (
+ task.x1 -
+ textRef.current.getBBox().width -
+ arrowIndent * +hasChild -
+ arrowIndent * 0.2
+ );
+ } else {
+ return task.x1 + width + arrowIndent * +hasChild + arrowIndent * 0.2;
+ }
};
return (
diff --git a/src/components/task-list/task-list-table.tsx b/src/components/task-list/task-list-table.tsx
index 1a276e4..e2a7229 100644
--- a/src/components/task-list/task-list-table.tsx
+++ b/src/components/task-list/task-list-table.tsx
@@ -12,7 +12,7 @@ export const TaskListTableDefault: React.FC<{
selectedTaskId: string;
setSelectedTask: (taskId: string) => void;
}> = ({ rowHeight, rowWidth, tasks, fontFamily, fontSize, locale }) => {
- const dateTimeOptions = {
+ const dateTimeOptions: Intl.DateTimeFormatOptions = {
weekday: "short",
year: "numeric",
month: "long",
diff --git a/src/helpers/bar-helper.ts b/src/helpers/bar-helper.ts
index 69ee677..9531c0c 100644
--- a/src/helpers/bar-helper.ts
+++ b/src/helpers/bar-helper.ts
@@ -165,8 +165,8 @@ const convertToBar = (
let x1: number;
let x2: number;
if (rtl) {
- x2 = taskXCoordinate(task.start, dates, dateDelta, columnWidth);
- x1 = taskXCoordinate(task.end, dates, dateDelta, columnWidth);
+ x2 = taskXCoordinateRTL(task.start, dates, dateDelta, columnWidth);
+ x1 = taskXCoordinateRTL(task.end, dates, dateDelta, columnWidth);
} else {
x1 = taskXCoordinate(task.start, dates, dateDelta, columnWidth);
x2 = taskXCoordinate(task.end, dates, dateDelta, columnWidth);
@@ -177,14 +177,12 @@ const convertToBar = (
x2 = x1 + handleWidth * 2;
}
- const progressWidth = progressWithByParams(x1, x2, task.progress);
- let progressX: number;
- if (rtl) {
- progressX = x2 - progressWidth;
- } else {
- progressX = x1;
- }
-
+ const [progressWidth, progressX] = progressWithByParams(
+ x1,
+ x2,
+ task.progress,
+ rtl
+ );
const y = taskYCoordinate(index, rowHeight, taskHeight);
const styles = {
@@ -281,7 +279,16 @@ const taskXCoordinate = (
);
return x;
};
-
+const taskXCoordinateRTL = (
+ xDate: Date,
+ dates: Date[],
+ dateDelta: number,
+ columnWidth: number
+) => {
+ let x = taskXCoordinate(xDate, dates, dateDelta, columnWidth);
+ x += columnWidth;
+ return x;
+};
const taskYCoordinate = (
index: number,
rowHeight: number,
@@ -294,9 +301,17 @@ const taskYCoordinate = (
export const progressWithByParams = (
taskX1: number,
taskX2: number,
- progress: number
+ progress: number,
+ rtl: boolean
) => {
- return (taskX2 - taskX1) * progress * 0.01;
+ const progressWidth = (taskX2 - taskX1) * progress * 0.01;
+ let progressX: number;
+ if (rtl) {
+ progressX = taskX2 - progressWidth;
+ } else {
+ progressX = taskX1;
+ }
+ return [progressWidth, progressX];
};
export const progressByProgressWidth = (
@@ -319,6 +334,15 @@ const progressByX = (x: number, task: BarTask) => {
return progressPercent;
}
};
+const progressByXRTL = (x: number, task: BarTask) => {
+ if (x >= task.x2) return 0;
+ else if (x <= task.x1) return 100;
+ else {
+ const barWidth = task.x2 - task.x1;
+ const progressPercent = Math.round(((task.x2 - x) * 100) / barWidth);
+ return progressPercent;
+ }
+};
export const getProgressPoint = (
progressX: number,
@@ -431,19 +455,21 @@ const handleTaskBySVGMouseEventForBar = (
let isChanged = false;
switch (action) {
case "progress":
- changedTask.progress = progressByX(svgX, selectedTask);
+ if (rtl) {
+ changedTask.progress = progressByXRTL(svgX, selectedTask);
+ } else {
+ changedTask.progress = progressByX(svgX, selectedTask);
+ }
isChanged = changedTask.progress !== selectedTask.progress;
if (isChanged) {
- changedTask.progressWidth = progressWithByParams(
+ const [progressWidth, progressX] = progressWithByParams(
changedTask.x1,
changedTask.x2,
- changedTask.progress
+ changedTask.progress,
+ rtl
);
- if (rtl) {
- changedTask.progressX = changedTask.x2 - changedTask.progressWidth;
- } else {
- changedTask.progressX = changedTask.x1;
- }
+ changedTask.progressWidth = progressWidth;
+ changedTask.progressX = progressX;
}
break;
case "start": {
@@ -451,13 +477,31 @@ const handleTaskBySVGMouseEventForBar = (
changedTask.x1 = newX1;
isChanged = changedTask.x1 !== selectedTask.x1;
if (isChanged) {
- changedTask.start = dateByX(
- newX1,
- selectedTask.x1,
- selectedTask.start,
- xStep,
- timeStep
+ if (rtl) {
+ changedTask.end = dateByX(
+ newX1,
+ selectedTask.x1,
+ selectedTask.end,
+ xStep,
+ timeStep
+ );
+ } else {
+ changedTask.start = dateByX(
+ newX1,
+ selectedTask.x1,
+ selectedTask.start,
+ xStep,
+ timeStep
+ );
+ }
+ const [progressWidth, progressX] = progressWithByParams(
+ changedTask.x1,
+ changedTask.x2,
+ changedTask.progress,
+ rtl
);
+ changedTask.progressWidth = progressWidth;
+ changedTask.progressX = progressX;
}
break;
}
@@ -466,13 +510,31 @@ const handleTaskBySVGMouseEventForBar = (
changedTask.x2 = newX2;
isChanged = changedTask.x2 !== selectedTask.x2;
if (isChanged) {
- changedTask.end = dateByX(
- newX2,
- selectedTask.x2,
- selectedTask.end,
- xStep,
- timeStep
+ if (rtl) {
+ changedTask.start = dateByX(
+ newX2,
+ selectedTask.x2,
+ selectedTask.start,
+ xStep,
+ timeStep
+ );
+ } else {
+ changedTask.end = dateByX(
+ newX2,
+ selectedTask.x2,
+ selectedTask.end,
+ xStep,
+ timeStep
+ );
+ }
+ const [progressWidth, progressX] = progressWithByParams(
+ changedTask.x1,
+ changedTask.x2,
+ changedTask.progress,
+ rtl
);
+ changedTask.progressWidth = progressWidth;
+ changedTask.progressX = progressX;
}
break;
}
@@ -500,6 +562,14 @@ const handleTaskBySVGMouseEventForBar = (
);
changedTask.x1 = newMoveX1;
changedTask.x2 = newMoveX2;
+ const [progressWidth, progressX] = progressWithByParams(
+ changedTask.x1,
+ changedTask.x2,
+ changedTask.progress,
+ rtl
+ );
+ changedTask.progressWidth = progressWidth;
+ changedTask.progressX = progressX;
}
break;
}
diff --git a/src/helpers/date-helper.ts b/src/helpers/date-helper.ts
index 795fd65..400b47d 100644
--- a/src/helpers/date-helper.ts
+++ b/src/helpers/date-helper.ts
@@ -83,11 +83,17 @@ export const ganttDateRange = (tasks: Task[], viewMode: ViewMode) => {
newStartDate = addToDate(newStartDate, -1, "day");
newEndDate = addToDate(newEndDate, 19, "day");
break;
- default:
+ case ViewMode.QuarterDay:
newStartDate = startOfDate(newStartDate, "day");
newEndDate = startOfDate(newEndDate, "day");
newStartDate = addToDate(newStartDate, -1, "day");
- newEndDate = addToDate(newEndDate, 5, "day");
+ newEndDate = addToDate(newEndDate, 66, "hour"); // 24(1 day)*3 - 6
+ break;
+ case ViewMode.HalfDay:
+ newStartDate = startOfDate(newStartDate, "day");
+ newEndDate = startOfDate(newEndDate, "day");
+ newStartDate = addToDate(newStartDate, -1, "day");
+ newEndDate = addToDate(newEndDate, 108, "hour"); // 24(1 day)*5 - 12
break;
}
return [newStartDate, newEndDate];
@@ -163,3 +169,7 @@ export const getWeekNumberISO8601 = (date: Date) => {
return weekNumber;
}
};
+
+export const getDaysInMonth = (month: number, year: number) => {
+ return new Date(year, month + 1, 0).getDate();
+};