Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bulk commit of changes I had in my internal fork of library #249

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { Task, ViewMode, Gantt } from "gantt-task-react";
import {Task, ViewMode, Gantt} from "gantt-task-react";
import { ViewSwitcher } from "./components/view-switcher";
import { getStartEndDateForProject, initTasks } from "./helper";
import "gantt-task-react/dist/index.css";
Expand Down Expand Up @@ -101,6 +101,7 @@ const App = () => {
onExpanderClick={handleExpanderClick}
listCellWidth={isChecked ? "155px" : ""}
ganttHeight={300}
ganttWidth={1000}
columnWidth={columnWidth}
/>
</div>
Expand Down
2 changes: 1 addition & 1 deletion example/src/components/view-switcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const ViewSwitcher: React.FC<ViewSwitcherProps> = ({
className="Button"
onClick={() => onViewModeChange(ViewMode.QuarterYear)}
>
Year
Quarter of year
</button>
<div className="Switch">
<label className="Switch_Toggle">
Expand Down
2 changes: 1 addition & 1 deletion example/src/helper.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Task } from "../../dist/types/public-types";

export function initTasks() {
const currentDate = new Date();
const currentDate = new Date(2023, 7, 1);
const tasks: Task[] = [
{
start: new Date(currentDate.getFullYear(), currentDate.getMonth(), 1),
Expand Down
31 changes: 26 additions & 5 deletions src/components/calendar/calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type CalendarProps = {
viewMode: ViewMode;
rtl: boolean;
headerHeight: number;
svgWidth: number;
columnWidth: number;
fontFamily: string;
fontSize: string;
Expand All @@ -29,6 +30,7 @@ export const Calendar: React.FC<CalendarProps> = ({
rtl,
headerHeight,
columnWidth,
svgWidth,
fontFamily,
fontSize,
}) => {
Expand Down Expand Up @@ -82,8 +84,9 @@ export const Calendar: React.FC<CalendarProps> = ({
const topDefaultHeight = headerHeight * 0.5;
for (let i = 0; i < dateSetup.dates.length; i++) {
const date = dateSetup.dates[i];
// const bottomValue = getLocaleMonth(date, locale);
const quarter = "Q" + Math.floor((date.getMonth() + 3) / 3);

const quarterNumber = Math.floor((date.getMonth()) / 3);
const quarter = "Q" + (quarterNumber + 1);
bottomValues.push(
<text
key={date.getTime()}
Expand All @@ -101,9 +104,13 @@ export const Calendar: React.FC<CalendarProps> = ({
const topValue = date.getFullYear().toString();
let xText: number;
if (rtl) {
xText = (6 + i + date.getMonth() + 1) * columnWidth;
xText = (2 + i + quarterNumber + 1) * columnWidth;
} else {
xText = (6 + i - date.getMonth()) * columnWidth;
xText = (2 + i - quarterNumber) * columnWidth;
// For first year display year in the middle of the visible scope
if (i === 0) {
xText = ((4 - quarterNumber) / 2) * columnWidth;
}
}
topValues.push(
<TopPartOfCalendar
Expand Down Expand Up @@ -148,6 +155,11 @@ export const Calendar: React.FC<CalendarProps> = ({
xText = (6 + i + date.getMonth() + 1) * columnWidth;
} else {
xText = (6 + i - date.getMonth()) * columnWidth;

// For first year display year in the middle of the visible scope
if (i === 0) {
xText = ((12 - date.getMonth()) / 2) * columnWidth;
}
}
topValues.push(
<TopPartOfCalendar
Expand Down Expand Up @@ -380,16 +392,25 @@ export const Calendar: React.FC<CalendarProps> = ({
case ViewMode.Hour:
[topValues, bottomValues] = getCalendarValuesForHour();
}
const terminalX = dateSetup.dates.length * columnWidth;
return (
<g className="calendar" fontSize={fontSize} fontFamily={fontFamily}>
<rect
x={0}
y={0}
width={columnWidth * dateSetup.dates.length}
width={svgWidth}
height={headerHeight}
className={styles.calendarHeader}
/>
{bottomValues} {topValues}
<line
x1={terminalX}
y1={0}
x2={terminalX}
y2={headerHeight}
className={styles.calendarTopTick}
key={"terminal-line"}
/>
</g>
);
};
5 changes: 4 additions & 1 deletion src/components/gantt/gantt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const Gantt: React.FunctionComponent<GanttProps> = ({
listCellWidth = "155px",
rowHeight = 50,
ganttHeight = 0,
ganttWidth = 0,
viewMode = ViewMode.Day,
preStepsCount = 1,
locale = "en-GB",
Expand Down Expand Up @@ -91,7 +92,8 @@ export const Gantt: React.FunctionComponent<GanttProps> = ({
const [selectedTask, setSelectedTask] = useState<BarTask>();
const [failedTask, setFailedTask] = useState<BarTask | null>(null);

const svgWidth = dateSetup.dates.length * columnWidth;
const svgWidth = Math.max(dateSetup.dates.length * columnWidth, ganttWidth);

const ganttFullHeight = barTasks.length * rowHeight;

const [scrollY, setScrollY] = useState(0);
Expand Down Expand Up @@ -402,6 +404,7 @@ export const Gantt: React.FunctionComponent<GanttProps> = ({
viewMode,
headerHeight,
columnWidth,
svgWidth,
fontFamily,
fontSize,
rtl,
Expand Down
10 changes: 10 additions & 0 deletions src/components/grid/grid-body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ export const GridBody: React.FC<GridBodyProps> = ({
}
tickX += columnWidth;
}
const terminalX = dates.length * columnWidth;
ticks.push(
<line
key="terminal"
x1={terminalX}
y1={0}
x2={terminalX}
y2={y}
className={styles.gridTick}
/>);
return (
<g className="gridBody">
<g className="rows">{gridRows}</g>
Expand Down
1 change: 1 addition & 0 deletions src/types/public-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export interface StylingOption {
listCellWidth?: string;
rowHeight?: number;
ganttHeight?: number;
ganttWidth?: number;
barCornerRadius?: number;
handleWidth?: number;
fontFamily?: string;
Expand Down