Skip to content
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
2 changes: 2 additions & 0 deletions src/components/gantt/gantt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const Gantt: React.FunctionComponent<GanttProps> = ({
onProgressChange,
onDoubleClick,
onClick,
onClickLine,
onDelete,
onSelect,
onExpanderClick,
Expand Down Expand Up @@ -428,6 +429,7 @@ export const Gantt: React.FunctionComponent<GanttProps> = ({
onProgressChange,
onDoubleClick,
onClick,
onClickLine,
onDelete,
};

Expand Down
4 changes: 3 additions & 1 deletion src/components/gantt/task-gantt-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const TaskGanttContent: React.FC<TaskGanttContentProps> = ({
onProgressChange,
onDoubleClick,
onClick,
onClickLine,
onDelete,
}) => {
const point = svg?.current?.createSVGPoint();
Expand Down Expand Up @@ -266,7 +267,8 @@ export const TaskGanttContent: React.FC<TaskGanttContentProps> = ({
{tasks.map(task => {
return task.barChildren.map(child => {
return (
<Arrow
<Arrow
onClickLine={(tasks: BarTask[]) => onClickLine ? onClickLine(tasks) : null}
key={`Arrow from ${task.id} to ${tasks[child.index].id}`}
taskFrom={task}
taskTo={tasks[child.index]}
Expand Down
21 changes: 18 additions & 3 deletions src/components/other/arrow.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useState } from "react";
import { BarTask } from "../../types/bar-task";

type ArrowProps = {
Expand All @@ -8,6 +8,7 @@ type ArrowProps = {
taskHeight: number;
arrowIndent: number;
rtl: boolean;
onClickLine?: (tasks: BarTask[]) => void;
};
export const Arrow: React.FC<ArrowProps> = ({
taskFrom,
Expand All @@ -16,9 +17,13 @@ export const Arrow: React.FC<ArrowProps> = ({
taskHeight,
arrowIndent,
rtl,
onClickLine,
}) => {
let path: string;
let trianglePoints: string;
const strokeWidthDefault = "1.5";
const [strokeWidth, setStrokeWidth] = useState<string>(strokeWidthDefault);

if (rtl) {
[path, trianglePoints] = drownPathAndTriangleRTL(
taskFrom,
Expand All @@ -37,9 +42,19 @@ export const Arrow: React.FC<ArrowProps> = ({
);
}

const clickLine = () => {
if (onClickLine) {
onClickLine([taskFrom, taskTo]);
}
}

return (
<g className="arrow">
<path strokeWidth="1.5" d={path} fill="none" />
<g className="arrow"
stroke={strokeWidth}
onMouseEnter={() => setStrokeWidth("2")}
onMouseLeave={() => setStrokeWidth(strokeWidthDefault)}
onClick={clickLine}>
<path strokeWidth={strokeWidth} d={path} fill="none" />
<polygon points={trianglePoints} />
</g>
);
Expand Down
4 changes: 4 additions & 0 deletions src/types/public-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ export interface EventOption {
* Invokes on bar click.
*/
onClick?: (task: Task) => void;
/**
* Invokes on bar click.
*/
onClickLine?: (tasks: Task[]) => void;
/**
* Invokes on end and start time change. Chart undoes operation if method return false or error.
*/
Expand Down