From c06ef5c7c928d27e7af515d83b3ca23ced4e1c50 Mon Sep 17 00:00:00 2001 From: rahulramesha Date: Mon, 18 Mar 2024 12:42:18 +0530 Subject: [PATCH] fix gantt chart view position fix --- web/components/gantt-chart/chart/root.tsx | 4 ++-- web/components/gantt-chart/views/month-view.ts | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/web/components/gantt-chart/chart/root.tsx b/web/components/gantt-chart/chart/root.tsx index ab04c2ec1..5c9872cf4 100644 --- a/web/components/gantt-chart/chart/root.tsx +++ b/web/components/gantt-chart/chart/root.tsx @@ -64,9 +64,9 @@ export const ChartViewRoot: FC = observer((props) => { useGanttChart(); // rendering the block structure - const renderBlockStructure = (view: any, blocks: IGanttBlock[] | null) => + const renderBlockStructure = (view: ChartDataType, blocks: IGanttBlock[] | null) => blocks - ? blocks.map((block: any) => ({ + ? blocks.map((block: IGanttBlock) => ({ ...block, position: getMonthChartItemPositionWidthInMonth(view, block), })) diff --git a/web/components/gantt-chart/views/month-view.ts b/web/components/gantt-chart/views/month-view.ts index 1e7e6d878..e856ad40b 100644 --- a/web/components/gantt-chart/views/month-view.ts +++ b/web/components/gantt-chart/views/month-view.ts @@ -1,4 +1,5 @@ // types +import { findTotalDaysInRange } from "helpers/date-time.helper"; import { weeks, months } from "../data"; import { ChartDataType, IGanttBlock } from "../types"; // data @@ -167,15 +168,16 @@ export const getMonthChartItemPositionWidthInMonth = (chartData: ChartDataType, const { startDate } = chartData.data; const { start_date: itemStartDate, target_date: itemTargetDate } = itemData; - if (!itemStartDate || !itemTargetDate) return null; + if (!itemStartDate || !itemTargetDate) return; startDate.setHours(0, 0, 0, 0); itemStartDate.setHours(0, 0, 0, 0); itemTargetDate.setHours(0, 0, 0, 0); - // position code starts - const positionTimeDifference: number = startDate.getTime() - itemStartDate.getTime(); - const positionDaysDifference: number = Math.abs(Math.floor(positionTimeDifference / (1000 * 60 * 60 * 24))); + const positionDaysDifference = findTotalDaysInRange(startDate, itemStartDate, false); + + if (!positionDaysDifference) return; + scrollPosition = positionDaysDifference * chartData.data.width; let diffMonths = (itemStartDate.getFullYear() - startDate.getFullYear()) * 12;