|
@@ -21,10 +21,137 @@ const component = ({ node, graph }: { node: Node; graph: Graph }) => {
|
|
|
};
|
|
|
}, []);
|
|
|
|
|
|
- const path = useMemo(() => {
|
|
|
- switch (type) {
|
|
|
- case 1:
|
|
|
- return `
|
|
|
+ const linePosition = useMemo((): "left" | "right" | "top" | "bottom" => {
|
|
|
+ const originNode = graph.getCellById(origin);
|
|
|
+ if (originNode && originNode.isNode()) {
|
|
|
+ const x = originNode.position().x + originNode.size().width / 2;
|
|
|
+ const y = originNode.position().y + originNode.size().height / 2;
|
|
|
+ const { width, height } = node.size();
|
|
|
+ if (
|
|
|
+ x < node.position().x
|
|
|
+ && y > node.position().y
|
|
|
+ && y < node.position().y + height
|
|
|
+ ) {
|
|
|
+ return "left";
|
|
|
+ }
|
|
|
+ if (
|
|
|
+ y > node.position().y
|
|
|
+ && x > node.position().x
|
|
|
+ && x < node.position().x + width
|
|
|
+ ) {
|
|
|
+ return "bottom";
|
|
|
+ }
|
|
|
+ if (
|
|
|
+ y < node.position().y
|
|
|
+ && x > node.position().x
|
|
|
+ && x < node.position().x + width
|
|
|
+ ) {
|
|
|
+ return "top";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return "right";
|
|
|
+ }, [origin]);
|
|
|
+
|
|
|
+ const lineStyle = useMemo(() => {
|
|
|
+ console.log(linePosition)
|
|
|
+ switch (linePosition) {
|
|
|
+ case "right":
|
|
|
+ return {
|
|
|
+ right: "-40px",
|
|
|
+ };
|
|
|
+ case "left":
|
|
|
+ return {
|
|
|
+ left: "-40px",
|
|
|
+ };
|
|
|
+ case "top":
|
|
|
+ return {
|
|
|
+ top: "-40px",
|
|
|
+ };
|
|
|
+ default:
|
|
|
+ return {
|
|
|
+ bottom: "-40px",
|
|
|
+ };
|
|
|
+ }
|
|
|
+ }, [linePosition]);
|
|
|
+
|
|
|
+ const rightLine = useMemo(() => {
|
|
|
+ if (type === 2) {
|
|
|
+ return `
|
|
|
+ M 20 ${line.width}
|
|
|
+ L 36 ${height / 2}
|
|
|
+ L 20 ${height - line.width}
|
|
|
+ `;
|
|
|
+ }
|
|
|
+ if (type === 3) {
|
|
|
+ return `
|
|
|
+ M 20 ${line.width}
|
|
|
+ A 10 ${height / 2} 0 0 1 20 ${height - line.width}
|
|
|
+ M 30 ${height / 2}
|
|
|
+ L 40 ${height / 2}
|
|
|
+ `;
|
|
|
+ }
|
|
|
+ if (type === 4) {
|
|
|
+ return `
|
|
|
+ M 20 ${line.width}
|
|
|
+ Q 30 ${line.width} 30 10
|
|
|
+ L 30 ${height / 2 - 10}
|
|
|
+ Q 30 ${height / 2} 40 ${height / 2}
|
|
|
+ Q 30 ${height / 2} 30 ${height / 2 + 10}
|
|
|
+ L 30 ${height - 10}
|
|
|
+ Q 30 ${height - line.width} 20 ${height - line.width}
|
|
|
+ `;
|
|
|
+ }
|
|
|
+ return `
|
|
|
+ M 20 ${line.width}
|
|
|
+ L 30 ${line.width}
|
|
|
+ L 30 ${height / 2}
|
|
|
+ L 40 ${height / 2}
|
|
|
+ L 30 ${height / 2}
|
|
|
+ L 30 ${height - line.width}
|
|
|
+ L 20 ${height - line.width}
|
|
|
+ `;
|
|
|
+ }, [type]);
|
|
|
+
|
|
|
+ const leftLine = useMemo(() => {
|
|
|
+ if (type === 2) {
|
|
|
+ return `
|
|
|
+ M 20 ${line.width}
|
|
|
+ L 4 ${height / 2}
|
|
|
+ L 20 ${height - line.width}
|
|
|
+ `;
|
|
|
+ }
|
|
|
+ if (type === 3) {
|
|
|
+ return `
|
|
|
+ M 20 ${line.width}
|
|
|
+ A 10 ${height / 2} 0 0 0 20 ${height - line.width}
|
|
|
+ M 10 ${height / 2}
|
|
|
+ L 0 ${height / 2}
|
|
|
+ `;
|
|
|
+ }
|
|
|
+ if (type === 4) {
|
|
|
+ return `
|
|
|
+ M 20 ${line.width}
|
|
|
+ Q 10 ${line.width} 10 10
|
|
|
+ L 10 ${height / 2 - 10}
|
|
|
+ Q 10 ${height / 2} 0 ${height / 2}
|
|
|
+ Q 10 ${height / 2} 10 ${height / 2 + 10}
|
|
|
+ L 10 ${height - 10}
|
|
|
+ Q 10 ${height - line.width} 20 ${height - line.width}
|
|
|
+ `;
|
|
|
+ }
|
|
|
+ return `
|
|
|
+ M 20 ${line.width}
|
|
|
+ L 10 ${line.width}
|
|
|
+ L 10 ${height / 2}
|
|
|
+ L 00 ${height / 2}
|
|
|
+ L 10 ${height / 2}
|
|
|
+ L 10 ${height - line.width}
|
|
|
+ L 20 ${height - line.width}
|
|
|
+ `;
|
|
|
+ }, [type]);
|
|
|
+
|
|
|
+ const topLine = useMemo(() => {
|
|
|
+ return `
|
|
|
M 20 ${line.width}
|
|
|
L 30 ${line.width}
|
|
|
L 30 ${height / 2}
|
|
@@ -33,29 +160,26 @@ const component = ({ node, graph }: { node: Node; graph: Graph }) => {
|
|
|
L 30 ${height - line.width}
|
|
|
L 20 ${height - line.width}
|
|
|
`;
|
|
|
- case 2:
|
|
|
- return `
|
|
|
- M 20 ${line.width}
|
|
|
- L 38 ${height / 2}
|
|
|
- L 20 ${height - line.width}
|
|
|
- `;
|
|
|
- case 3:
|
|
|
- return `
|
|
|
- M 20 ${line.width}
|
|
|
- A 10 ${height / 2} 0 0 1 20 ${height - line.width}
|
|
|
- M 30 ${height / 2}
|
|
|
- L 40 ${height / 2}
|
|
|
- `;
|
|
|
- case 4:
|
|
|
- return `
|
|
|
- M 20 ${line.width}
|
|
|
- Q 30 ${line.width} 30 10
|
|
|
- L 30 ${height / 2 - 10}
|
|
|
- Q 30 ${height / 2} 40 ${height / 2}
|
|
|
- Q 30 ${height / 2} 30 ${height / 2 + 10}
|
|
|
- L 30 ${height - 10}
|
|
|
- Q 30 ${height - line.width} 20 ${height - line.width}
|
|
|
- `;
|
|
|
+ }, [type]);
|
|
|
+
|
|
|
+ const bottomLine = useMemo(() => {
|
|
|
+ return `
|
|
|
+ M 20 ${line.width}
|
|
|
+ L 30 ${line.width}
|
|
|
+ L 30 ${height / 2}
|
|
|
+ L 40 ${height / 2}
|
|
|
+ L 30 ${height / 2}
|
|
|
+ L 30 ${height - line.width}
|
|
|
+ L 20 ${height - line.width}
|
|
|
+ `;
|
|
|
+ }, [type]);
|
|
|
+
|
|
|
+ const path = useMemo(() => {
|
|
|
+ switch(linePosition) {
|
|
|
+ case 'bottom': return bottomLine;
|
|
|
+ case 'top': return topLine;
|
|
|
+ case 'left': return leftLine;
|
|
|
+ case 'right': return rightLine;
|
|
|
}
|
|
|
}, [type]);
|
|
|
|
|
@@ -151,7 +275,8 @@ const component = ({ node, graph }: { node: Node; graph: Graph }) => {
|
|
|
)}
|
|
|
|
|
|
<svg
|
|
|
- className="absolute right--40px w-40px h-full"
|
|
|
+ className="absolute w-40px h-full"
|
|
|
+ style={lineStyle}
|
|
|
viewBox={`0 0 ${40} ${height}`}
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
|
>
|
|
@@ -238,8 +363,11 @@ const component = ({ node, graph }: { node: Node; graph: Graph }) => {
|
|
|
}
|
|
|
>
|
|
|
<i
|
|
|
- className="z-9 iconfont icon-more text-12px absolute right--35px top-25% cursor-pointer"
|
|
|
- style={{ color: line.color || "#000" }}
|
|
|
+ className="z-9 iconfont icon-more text-12px absolute top-25% cursor-pointer"
|
|
|
+ style={{
|
|
|
+ color: line.color || "#000",
|
|
|
+ [linePosition]: '-36px'
|
|
|
+ }}
|
|
|
/>
|
|
|
</Popover>
|
|
|
)}
|
|
@@ -260,7 +388,7 @@ export default {
|
|
|
data: {
|
|
|
line: {
|
|
|
width: 2,
|
|
|
- color: "#939aa8",
|
|
|
+ color: "#63abf7",
|
|
|
},
|
|
|
type: 1,
|
|
|
},
|