dev: year view for gantt chart

This commit is contained in:
Aaryan Khandelwal 2023-08-28 22:07:10 +05:30
parent c65bbf865d
commit e2c04c08b7
5 changed files with 94 additions and 39 deletions

View File

@ -10,7 +10,7 @@ import { GanttSidebar } from "../sidebar";
// import { BiWeekChartView } from "./bi-week";
import { MonthChartView } from "./month";
// import { QuarterChartView } from "./quarter";
// import { YearChartView } from "./year";
import { YearChartView } from "./year";
// views
import {
// generateHourChart,
@ -105,8 +105,8 @@ export const ChartViewRoot: FC<ChartViewRootProps> = ({
if (selectedCurrentView === "month")
currentRender = generateMonthChart(selectedCurrentViewData, side);
// if (view === "quarter") currentRender = generateQuarterChart(selectedCurrentViewData, side);
// if (selectedCurrentView === "year")
// currentRender = generateYearChart(selectedCurrentViewData, side);
if (selectedCurrentView === "year")
currentRender = generateYearChart(selectedCurrentViewData, side);
// updating the prevData, currentData and nextData
if (currentRender.payload.length > 0) {
@ -316,7 +316,7 @@ export const ChartViewRoot: FC<ChartViewRootProps> = ({
{/* {currentView && currentView === "bi_week" && <BiWeekChartView />} */}
{currentView && currentView === "month" && <MonthChartView />}
{/* {currentView && currentView === "quarter" && <QuarterChartView />} */}
{/* {currentView && currentView === "year" && <YearChartView />} */}
{currentView && currentView === "year" && <YearChartView />}
{/* blocks */}
{currentView && currentViewData && (

View File

@ -1,43 +1,72 @@
import { FC } from "react";
// context
import { useChart } from "../hooks";
import { IYearBlock } from "../views";
export const YearChartView: FC<any> = () => {
const { currentView, currentViewData, renderView, dispatch, allViews } = useChart();
const { currentViewData, renderView } = useChart();
const yearBlocks: IYearBlock[] = renderView;
console.log("yearBlocks", yearBlocks);
return (
<>
<div className="absolute flex h-full flex-grow divide-x divide-custom-border-200">
{renderView &&
renderView.length > 0 &&
renderView.map((_itemRoot: any, _idxRoot: any) => (
<div key={`title-${_idxRoot}`} className="relative flex flex-col">
<div className="relative border-b border-custom-border-200">
<div className="sticky left-0 inline-flex whitespace-nowrap px-2 py-1 text-sm font-medium capitalize">
{_itemRoot?.title}
<div className="absolute flex h-full flex-grow divide-x divide-custom-border-100/50">
{yearBlocks &&
yearBlocks.length > 0 &&
yearBlocks.map((block, _idxRoot) => (
<div key={`year-${block.year}-${block.month}`} className="relative flex flex-col">
<div className="h-[60px] w-full">
<div className="relative h-[30px]">
<div className="sticky left-0 inline-flex whitespace-nowrap px-3 py-2 text-xs font-medium capitalize">
{block?.title}
</div>
</div>
<div className="flex w-full h-[30px]">
{block?.children &&
block.children.length > 0 &&
block.children.map((monthWeek, _idx: any) => (
<div
key={`sub-title-${_idxRoot}-${_idx}`}
className="flex-shrink-0 border-b py-1 text-center capitalize border-custom-border-200"
style={{ width: `${currentViewData?.data.width}px` }}
>
<div className="text-xs">
<span
className={
monthWeek.today
? "bg-custom-primary-100 text-white px-1 rounded-full"
: "text-custom-text-200"
}
>
{monthWeek.date.getDate()}
</span>
</div>
</div>
))}
</div>
</div>
<div className="flex h-full w-full divide-x divide-custom-border-200">
{_itemRoot.children &&
_itemRoot.children.length > 0 &&
_itemRoot.children.map((_item: any, _idx: any) => (
<div className="flex h-full w-full divide-x divide-custom-border-100/50">
{block.children &&
block.children.length > 0 &&
block.children.map((monthWeek, _idx) => (
<div
key={`sub-title-${_idxRoot}-${_idx}`}
key={`column-${_idxRoot}-${_idx}`}
className="relative flex h-full flex-col overflow-hidden whitespace-nowrap"
style={{ width: `${currentViewData?.data.width}px` }}
>
<div
className={`flex-shrink-0 border-b py-1 text-center text-sm capitalize font-medium ${
_item?.today ? `text-red-500 border-red-500` : `border-custom-border-200`
className={`relative h-full w-full flex-1 flex justify-center ${
["sat", "sun"].includes(monthWeek?.dayData?.shortTitle || "")
? `bg-custom-background-90`
: ``
}`}
>
<div>{_item.title}</div>
</div>
<div className={`relative h-full w-full flex-1 flex justify-center`}>
{_item?.today && (
<div className="absolute top-0 bottom-0 border border-red-500"> </div>
)}
{/* {monthDay?.today && (
<div className="absolute top-0 bottom-0 w-[1px] bg-red-500" />
)} */}
</div>
</div>
))}

View File

@ -24,7 +24,7 @@ const chartReducer = (
}
};
const initialView = "month";
const initialView = "year";
export const ChartContextProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
const [state, dispatch] = useState<ChartContextData>({

View File

@ -123,17 +123,17 @@ export const allViewsWithData: ChartDataType[] = [
// width: 100, // it will preview week starting dates all months data and there is 3 months limitation for preview ex: title (2, 9, 16, 23, 30)
// },
// },
// {
// key: "year",
// title: "Year",
// data: {
// startDate: new Date(),
// currentDate: new Date(),
// endDate: new Date(),
// approxFilterRange: 10,
// width: 80, // it will preview week starting dates all months data and there is no limitation for preview ex: title (2, 9, 16, 23, 30)
// },
// },
{
key: "year",
title: "Year",
data: {
startDate: new Date(),
currentDate: new Date(),
endDate: new Date(),
approxFilterRange: 10,
width: 55, // it will preview week starting dates all months data and there is no limitation for preview ex: title (2, 9, 16, 23, 30)
},
},
];
export const currentViewDataWithView = (view: string = "month") => {

View File

@ -5,7 +5,33 @@ import { weeks, months } from "../data";
// helpers
import { getDatesBetweenTwoDates, getWeeksByMonthAndYear } from "./helpers";
const generateMonthDataByMonthAndYearInMonthView = (month: number, year: number) => {
interface IYearChild {
active: boolean;
date: Date;
day: number;
dayData: {
key: number;
shortTitle: string;
title: string;
};
title: string;
today: boolean;
weekNumber: number;
}
export interface IYearBlock {
children: IYearChild[];
month: number;
monthData: {
key: number;
shortTitle: string;
title: string;
};
title: string;
year: number;
}
[];
const generateMonthDataByMonthAndYearInMonthView = (month: number, year: number): IYearBlock => {
const currentMonth: number = month;
const currentYear: number = year;
const today = new Date();