37 lines
947 B
TypeScript
Raw Normal View History

2020-08-05 08:14:22 +03:00
import React from "react";
import { BarTask } from "../../types/bar-task";
2020-07-22 20:50:43 +03:00
type ArrowProps = {
taskFrom: BarTask;
taskTo: BarTask;
rowHeight: number;
2021-03-01 21:55:27 +02:00
taskHeight: number;
2020-07-22 20:50:43 +03:00
arrowIndent: number;
};
export const Arrow: React.FC<ArrowProps> = ({
taskFrom,
taskTo,
rowHeight,
2021-03-01 21:55:27 +02:00
taskHeight,
2020-07-22 20:50:43 +03:00
arrowIndent,
}) => {
const indexCompare = taskFrom.index > taskTo.index ? -1 : 1;
2021-03-01 21:55:27 +02:00
const taskToEndPosition = taskTo.y + taskHeight / 2;
2020-07-22 20:50:43 +03:00
2021-03-01 21:55:27 +02:00
const path = `M ${taskFrom.x2} ${taskFrom.y + taskHeight / 2}
2020-07-22 20:50:43 +03:00
h ${arrowIndent}
v ${(indexCompare * rowHeight) / 2}
H ${taskTo.x1 - arrowIndent}
V ${taskToEndPosition}
h ${arrowIndent}`;
const trianglePoints = `${taskTo.x1},${taskToEndPosition}
${taskTo.x1 - 5},${taskToEndPosition - 5}
${taskTo.x1 - 5},${taskToEndPosition + 5}`;
return (
2020-08-05 08:14:22 +03:00
<g className="arrow">
2020-07-22 20:50:43 +03:00
<path strokeWidth="1.5" d={path} fill="none" />
<polygon points={trianglePoints} />
2020-08-05 08:14:22 +03:00
</g>
2020-07-22 20:50:43 +03:00
);
};