Skip to content

Commit 3cbe524

Browse files
authored
Merge pull request #1 from krngd2/add-viewmode-QuarterYear
Add viewmode quarter year
2 parents fabcdfb + 7d7634f commit 3cbe524

File tree

5 files changed

+69
-5
lines changed

5 files changed

+69
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ npm start
8686

8787
| Parameter Name | Type | Description |
8888
| :------------- | :------ | :---------------------------------------------------------------------------------------------------------- |
89-
| viewMode | enum | Specifies the time scale. Hour, Quarter Day, Half Day, Day, Week(ISO-8601, 1st day is Monday), Month, Year. |
89+
| viewMode | enum | Specifies the time scale. Hour, Quarter Day, Half Day, Day, Week(ISO-8601, 1st day is Monday), Month, QuarterYear, Year. |
9090
| viewDate | date | Specifies display date and time for display. |
9191
| preStepsCount | number | Specifies empty space before the fist task |
9292
| locale | string | Specifies the month name language. Able formats: ISO 639-2, Java Locale. |

example/src/components/view-switcher.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ export const ViewSwitcher: React.FC<ViewSwitcherProps> = ({
5252
>
5353
Year
5454
</button>
55+
<button
56+
className="Button"
57+
onClick={() => onViewModeChange(ViewMode.QuarterYear)}
58+
>
59+
Year
60+
</button>
5561
<div className="Switch">
5662
<label className="Switch_Toggle">
5763
<input

src/components/calendar/calendar.tsx

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const Calendar: React.FC<CalendarProps> = ({
4141
const bottomValue = date.getFullYear();
4242
bottomValues.push(
4343
<text
44-
key={date.getFullYear()}
44+
key={date.getTime()}
4545
y={headerHeight * 0.8}
4646
x={columnWidth * i + columnWidth * 0.5}
4747
className={styles.calendarBottomText}
@@ -76,6 +76,51 @@ export const Calendar: React.FC<CalendarProps> = ({
7676
return [topValues, bottomValues];
7777
};
7878

79+
const getCalendarValuesForQuarterYear = () => {
80+
const topValues: ReactChild[] = [];
81+
const bottomValues: ReactChild[] = [];
82+
const topDefaultHeight = headerHeight * 0.5;
83+
for (let i = 0; i < dateSetup.dates.length; i++) {
84+
const date = dateSetup.dates[i];
85+
// const bottomValue = getLocaleMonth(date, locale);
86+
const quarter = "Q" + Math.floor((date.getMonth() + 3) / 3);
87+
bottomValues.push(
88+
<text
89+
key={date.getTime()}
90+
y={headerHeight * 0.8}
91+
x={columnWidth * i + columnWidth * 0.5}
92+
className={styles.calendarBottomText}
93+
>
94+
{quarter}
95+
</text>
96+
);
97+
if (
98+
i === 0 ||
99+
date.getFullYear() !== dateSetup.dates[i - 1].getFullYear()
100+
) {
101+
const topValue = date.getFullYear().toString();
102+
let xText: number;
103+
if (rtl) {
104+
xText = (6 + i + date.getMonth() + 1) * columnWidth;
105+
} else {
106+
xText = (6 + i - date.getMonth()) * columnWidth;
107+
}
108+
topValues.push(
109+
<TopPartOfCalendar
110+
key={topValue}
111+
value={topValue}
112+
x1Line={columnWidth * i}
113+
y1Line={0}
114+
y2Line={topDefaultHeight}
115+
xText={Math.abs(xText)}
116+
yText={topDefaultHeight * 0.9}
117+
/>
118+
);
119+
}
120+
}
121+
return [topValues, bottomValues];
122+
};
123+
79124
const getCalendarValuesForMonth = () => {
80125
const topValues: ReactChild[] = [];
81126
const bottomValues: ReactChild[] = [];
@@ -316,10 +361,13 @@ export const Calendar: React.FC<CalendarProps> = ({
316361
case ViewMode.Year:
317362
[topValues, bottomValues] = getCalendarValuesForYear();
318363
break;
364+
case ViewMode.QuarterYear:
365+
[topValues, bottomValues] = getCalendarValuesForQuarterYear();
366+
break;
319367
case ViewMode.Month:
320-
[topValues, bottomValues] = getCalendarValuesForMonth();
321-
break;
322-
case ViewMode.Week:
368+
[topValues, bottomValues] = getCalendarValuesForMonth();
369+
break;
370+
case ViewMode.Week:
323371
[topValues, bottomValues] = getCalendarValuesForWeek();
324372
break;
325373
case ViewMode.Day:

src/helpers/date-helper.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ export const ganttDateRange = (
9191
newEndDate = addToDate(newEndDate, 1, "year");
9292
newEndDate = startOfDate(newEndDate, "year");
9393
break;
94+
case ViewMode.QuarterYear:
95+
newStartDate = addToDate(newStartDate, -3, "month");
96+
newStartDate = startOfDate(newStartDate, "month");
97+
newEndDate = addToDate(newEndDate, 3, "year");
98+
newEndDate = startOfDate(newEndDate, "year");
99+
break;
94100
case ViewMode.Month:
95101
newStartDate = addToDate(newStartDate, -1 * preStepsCount, "month");
96102
newStartDate = startOfDate(newStartDate, "month");
@@ -147,6 +153,9 @@ export const seedDates = (
147153
case ViewMode.Year:
148154
currentDate = addToDate(currentDate, 1, "year");
149155
break;
156+
case ViewMode.QuarterYear:
157+
currentDate = addToDate(currentDate, 3, "month");
158+
break;
150159
case ViewMode.Month:
151160
currentDate = addToDate(currentDate, 1, "month");
152161
break;

src/types/public-types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export enum ViewMode {
66
/** ISO-8601 week */
77
Week = "Week",
88
Month = "Month",
9+
QuarterYear = "QuarterYear",
910
Year = "Year",
1011
}
1112
export type TaskType = "task" | "milestone" | "project";

0 commit comments

Comments
 (0)