diff --git a/src/common/GanttChart.jsx b/src/common/GanttChart.jsx new file mode 100644 index 000000000..4bb8923c1 --- /dev/null +++ b/src/common/GanttChart.jsx @@ -0,0 +1,123 @@ +const DATA = [ + { + id: 1, + name: "Task 1", + start: "2025-04-07T12:00:00Z", + end: "2025-04-07T13:00:00Z", + }, + { + id: 2, + name: "Task 2", + start: "2025-04-07T13:00:00Z", + end: "2025-04-07T14:00:00Z", + }, + { + id: 3, + name: "Task 3", + start: "2025-04-07T14:00:00Z", + end: "2025-04-07T15:00:00Z", + }, + { + id: 4, + name: "Task 4 very long name that should be truncated long name. lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.", + start: "2025-04-07T15:00:00Z", + end: "2025-04-07T16:00:00Z", + }, +]; + +/** + * GanttChart component + */ +const GanttChart = ({ data }) => { + data = data || DATA; + + // endDate is now or the max end date of the tasks + let endDate = new Date(); + data.forEach((task) => { + const taskEndDate = new Date(task.end); + if (taskEndDate > endDate) { + endDate = taskEndDate; + } + }); + + // startDate is now minus 1 day + let startDate = new Date(); + startDate.setDate(startDate.getDate() - 1); + data.forEach((task) => { + const taskStartDate = new Date(task.start); + if (taskStartDate < startDate) { + startDate = taskStartDate; + } + }); + + // Get the number of hours between startDate and endDate + const hours = Math.abs(endDate - startDate) / 36e5; + + // Gantt chart with a floating sidebar and a scrollable chart + return ( +