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 ( +
+ {/* Sidebar with task names */} +
+
+ {data.map((task) => ( +
+ {task.name} +
+ ))} +
+ + {/* Gantt chart */} +
{ + if (el) { + el.scrollLeft = el.scrollWidth; + } + }} + > +
+
+ {[...Array(hours).keys()].map((i) => ( +
+ {new Date(startDate.getTime() + i * 36e5).toLocaleTimeString( + "en-US", + { + hour: "2-digit", + minute: "2-digit", + } + )} +
+ ))} +
+ + {data.map((task) => ( +
+
+
+ ))} +
+
+
+ ); +}; + +export default GanttChart; diff --git a/src/layout/Router.jsx b/src/layout/Router.jsx index 946855fd6..8e46f0e74 100644 --- a/src/layout/Router.jsx +++ b/src/layout/Router.jsx @@ -27,6 +27,7 @@ import { appActions } from "../store/appSlice"; import { useEffect } from "react"; import Footer from "./Footer"; import TopAnnouncement from "./TopAnnouncement"; +import ExperimentGanttView from "../pages/ExperimentGanttView"; const router = createBrowserRouter( [ @@ -102,6 +103,10 @@ const router = createBrowserRouter( path: "/experiment/:expid/performance", element: , }, + { + path: "/experiment/:expid/gantt", + element: , + } ], }, ], diff --git a/src/pages/ExperimentGanttView.jsx b/src/pages/ExperimentGanttView.jsx new file mode 100644 index 000000000..05498546b --- /dev/null +++ b/src/pages/ExperimentGanttView.jsx @@ -0,0 +1,12 @@ + +import GanttChart from "../common/GanttChart" + + +const ExperimentGanttView = () => { + return ( +
+ +
+ ) +} +export default ExperimentGanttView; \ No newline at end of file