Skip to content

Commit e4a2cc0

Browse files
committed
tooltip is not a part of foreignObject anymore
1 parent d63fe60 commit e4a2cc0

File tree

8 files changed

+142
-140
lines changed

8 files changed

+142
-140
lines changed

example/package-lock.json

Lines changed: 21 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gantt-task-react",
3-
"version": "0.3.1",
3+
"version": "0.3.2",
44
"description": "Interactive Gantt Chart for React with TypeScript.",
55
"author": "MaTeMaTuK <maksym.vikarii@gmail.com>",
66
"homepage": "https://github.com/MaTeMaTuK/gantt-task-react",

src/components/gantt/gantt.module.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@
1717
margin: 0;
1818
list-style: none;
1919
outline: none;
20+
position: relative;
2021
}

src/components/gantt/gantt.tsx

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { CalendarProps } from "../calendar/calendar";
66
import { TaskGanttContentProps } from "./task-gantt-content";
77
import { TaskListHeaderDefault } from "../task-list/task-list-header";
88
import { TaskListTableDefault } from "../task-list/task-list-table";
9-
import { StandardTooltipContent } from "../other/tooltip";
9+
import { StandardTooltipContent, Tooltip } from "../other/tooltip";
1010
import { VerticalScroll } from "../other/vertical-scroll";
1111
import { TaskListProps, TaskList } from "../task-list/task-list";
1212
import { TaskGantt } from "./task-gantt";
@@ -56,14 +56,15 @@ export const Gantt: React.FunctionComponent<GanttProps> = ({
5656
}) => {
5757
const wrapperRef = useRef<HTMLDivElement>(null);
5858
const taskListRef = useRef<HTMLDivElement>(null);
59-
const verticalGanttContainerRef = useRef<HTMLDivElement>(null);
6059
const [dateSetup, setDateSetup] = useState<DateSetup>(() => {
6160
const [startDate, endDate] = ganttDateRange(tasks, viewMode);
6261
return { viewMode, dates: seedDates(startDate, endDate, viewMode) };
6362
});
6463

6564
const [taskHeight, setTaskHeight] = useState((rowHeight * barFill) / 100);
6665
const [taskListWidth, setTaskListWidth] = useState(0);
66+
const [svgContainerWidth, setSvgContainerWidth] = useState(0);
67+
const [svgContainerHeight, setSvgContainerHeight] = useState(ganttHeight);
6768
const [barTasks, setBarTasks] = useState<BarTask[]>([]);
6869
const [ganttEvent, setGanttEvent] = useState<GanttEvent>({
6970
action: "",
@@ -76,7 +77,6 @@ export const Gantt: React.FunctionComponent<GanttProps> = ({
7677
const [scrollX, setScrollX] = useState(0);
7778
const [ignoreScrollEvent, setIgnoreScrollEvent] = useState(false);
7879

79-
const svgHeight = rowHeight * barTasks.length;
8080
const svgWidth = dateSetup.dates.length * columnWidth;
8181
const ganttFullHeight = barTasks.length * rowHeight;
8282

@@ -170,10 +170,27 @@ export const Gantt: React.FunctionComponent<GanttProps> = ({
170170
}, [rowHeight, barFill, taskHeight]);
171171

172172
useEffect(() => {
173+
if (!listCellWidth) {
174+
setTaskListWidth(0);
175+
}
173176
if (taskListRef.current) {
174177
setTaskListWidth(taskListRef.current.offsetWidth);
175178
}
176-
}, [taskListRef]);
179+
}, [taskListRef, listCellWidth]);
180+
181+
useEffect(() => {
182+
if (wrapperRef.current) {
183+
setSvgContainerWidth(wrapperRef.current.offsetWidth - taskListWidth);
184+
}
185+
}, [wrapperRef, taskListWidth]);
186+
187+
useEffect(() => {
188+
if (ganttHeight) {
189+
setSvgContainerHeight(ganttHeight + headerHeight);
190+
} else {
191+
setSvgContainerHeight(tasks.length * rowHeight + headerHeight);
192+
}
193+
}, [ganttHeight, tasks]);
177194

178195
// scroll events
179196
useEffect(() => {
@@ -326,7 +343,6 @@ export const Gantt: React.FunctionComponent<GanttProps> = ({
326343
fontFamily,
327344
fontSize,
328345
arrowIndent,
329-
svgHeight,
330346
svgWidth,
331347
setGanttEvent,
332348
setFailedTask,
@@ -335,7 +351,6 @@ export const Gantt: React.FunctionComponent<GanttProps> = ({
335351
onProgressChange,
336352
onDoubleClick,
337353
onDelete,
338-
TooltipContent,
339354
};
340355

341356
const tableProps: TaskListProps = {
@@ -371,8 +386,23 @@ export const Gantt: React.FunctionComponent<GanttProps> = ({
371386
ganttHeight={ganttHeight}
372387
scrollY={scrollY}
373388
scrollX={scrollX}
374-
verticalGanttContainerRef={verticalGanttContainerRef}
375389
/>
390+
{ganttEvent.changedTask && (
391+
<Tooltip
392+
arrowIndent={arrowIndent}
393+
rowHeight={rowHeight}
394+
svgContainerHeight={svgContainerHeight}
395+
svgContainerWidth={svgContainerWidth}
396+
fontFamily={fontFamily}
397+
fontSize={fontSize}
398+
scrollX={scrollX}
399+
scrollY={scrollY}
400+
task={ganttEvent.changedTask}
401+
headerHeight={headerHeight}
402+
taskListWidth={taskListWidth}
403+
TooltipContent={TooltipContent}
404+
/>
405+
)}
376406
<VerticalScroll
377407
ganttFullHeight={ganttFullHeight}
378408
ganttHeight={ganttHeight}

src/components/gantt/task-gantt-content.tsx

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import React, { useEffect, useState } from "react";
2-
import { Task, EventOption } from "../../types/public-types";
2+
import { EventOption } from "../../types/public-types";
33
import { BarTask } from "../../types/bar-task";
44
import { Arrow } from "../other/arrow";
55
import { handleTaskBySVGMouseEvent } from "../../helpers/bar-helper";
6-
import { Tooltip } from "../other/tooltip";
76
import { isKeyboardEvent } from "../../helpers/other-helper";
87
import { TaskItem } from "../task-item/task-item";
98
import {
@@ -21,12 +20,7 @@ export type TaskGanttContentProps = {
2120
columnWidth: number;
2221
timeStep: number;
2322
svg?: React.RefObject<SVGSVGElement>;
24-
svgHeight: number;
2523
svgWidth: number;
26-
displayXStartEndpoint?: {
27-
start: number;
28-
end: number;
29-
};
3024
taskHeight: number;
3125
arrowColor: string;
3226
arrowIndent: number;
@@ -35,11 +29,6 @@ export type TaskGanttContentProps = {
3529
setGanttEvent: (value: GanttEvent) => void;
3630
setFailedTask: (value: BarTask | null) => void;
3731
setSelectedTask: (taskId: string) => void;
38-
TooltipContent: React.FC<{
39-
task: Task;
40-
fontSize: string;
41-
fontFamily: string;
42-
}>;
4332
} & EventOption;
4433

4534
export const TaskGanttContent: React.FC<TaskGanttContentProps> = ({
@@ -51,8 +40,6 @@ export const TaskGanttContent: React.FC<TaskGanttContentProps> = ({
5140
columnWidth,
5241
timeStep,
5342
svg,
54-
svgHeight,
55-
displayXStartEndpoint,
5643
taskHeight,
5744
arrowColor,
5845
arrowIndent,
@@ -65,7 +52,6 @@ export const TaskGanttContent: React.FC<TaskGanttContentProps> = ({
6552
onProgressChange,
6653
onDoubleClick,
6754
onDelete,
68-
TooltipContent,
6955
}) => {
7056
const point = svg?.current?.createSVGPoint();
7157
const [xStep, setXStep] = useState(0);
@@ -292,20 +278,6 @@ export const TaskGanttContent: React.FC<TaskGanttContentProps> = ({
292278
);
293279
})}
294280
</g>
295-
<g className="toolTip">
296-
{ganttEvent.changedTask && displayXStartEndpoint && (
297-
<Tooltip
298-
arrowIndent={arrowIndent}
299-
rowHeight={rowHeight}
300-
svgHeight={svgHeight}
301-
displayXStartEndpoint={displayXStartEndpoint}
302-
task={ganttEvent.changedTask}
303-
fontFamily={fontFamily}
304-
fontSize={fontSize}
305-
TooltipContent={TooltipContent}
306-
/>
307-
)}
308-
</g>
309281
</g>
310282
);
311283
};

src/components/gantt/task-gantt.tsx

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useRef, useEffect, useState } from "react";
1+
import React, { useRef, useEffect } from "react";
22
import { GridProps, Grid } from "../grid/grid";
33
import { CalendarProps, Calendar } from "../calendar/calendar";
44
import { TaskGanttContentProps, TaskGanttContent } from "./task-gantt-content";
@@ -11,7 +11,6 @@ export type TaskGanttProps = {
1111
ganttHeight: number;
1212
scrollY: number;
1313
scrollX: number;
14-
verticalGanttContainerRef: React.RefObject<HTMLDivElement>;
1514
};
1615
export const TaskGantt: React.FC<TaskGanttProps> = ({
1716
gridProps,
@@ -20,15 +19,11 @@ export const TaskGantt: React.FC<TaskGanttProps> = ({
2019
ganttHeight,
2120
scrollY,
2221
scrollX,
23-
verticalGanttContainerRef,
2422
}) => {
2523
const ganttSVGRef = useRef<SVGSVGElement>(null);
2624
const horizontalContainerRef = useRef<HTMLDivElement>(null);
27-
const [displayXStartEndpoint, setDisplayXStartEndpoint] = useState({
28-
start: 0,
29-
end: 0,
30-
});
31-
const newBarProps = { ...barProps, svg: ganttSVGRef, displayXStartEndpoint };
25+
const verticalGanttContainerRef = useRef<HTMLDivElement>(null);
26+
const newBarProps = { ...barProps, svg: ganttSVGRef };
3227

3328
useEffect(() => {
3429
if (horizontalContainerRef.current) {
@@ -39,13 +34,8 @@ export const TaskGantt: React.FC<TaskGanttProps> = ({
3934
useEffect(() => {
4035
if (verticalGanttContainerRef.current) {
4136
verticalGanttContainerRef.current.scrollLeft = scrollX;
42-
setDisplayXStartEndpoint({
43-
start: scrollX,
44-
end: verticalGanttContainerRef.current.clientWidth + scrollX,
45-
});
4637
}
47-
// verticalContainerRef.current?.clientWidth need for resize window tracking
48-
}, [scrollX, verticalGanttContainerRef.current?.clientWidth]);
38+
}, [scrollX]);
4939

5040
return (
5141
<div

src/components/other/tooltip.module.css

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,20 @@
1111
}
1212

1313
.tooltipDetailsContainer {
14-
display: table;
14+
position: absolute;
15+
display: flex;
16+
flex-shrink: 0;
17+
pointer-events: none;
18+
-webkit-touch-callout: none;
19+
-webkit-user-select: none;
20+
-moz-user-select: none;
21+
-ms-user-select: none;
22+
user-select: none;
23+
}
24+
25+
.tooltipDetailsContainerHidden {
26+
visibility: hidden;
27+
position: absolute;
28+
display: flex;
29+
pointer-events: none;
1530
}

0 commit comments

Comments
 (0)