react-flow-chart icon indicating copy to clipboard operation
react-flow-chart copied to clipboard

smart routing makes labels out of position

Open prativm opened this issue 5 years ago • 2 comments

When smart routing is false, labels are sticking with respective links. but when smart routing is true, link positions are not working as expected.

react-flow-chart version: 0.0.13

Screenshot 2020-07-16 at 4 10 14 AM

prativm avatar Jul 15 '20 22:07 prativm

@MrBlenny any update on this?

prativm avatar Jul 21 '20 08:07 prativm

I was able to create a work around to find the longest line for a link and use the center of that.

First you have to import generateSmartPath, generateRightAnglePath and generateCurvePath import { ILinkDefaultProps, IPosition, LinkDefault, generateSmartPath, generateRightAnglePath, generateCurvePath, } from "@mrblenny/react-flow-chart";

I then created two functions to find the longest line and the center. (Sorry for the screenshots but the code snippets would not format). image

image

In your component you will need to add these properties. const points = config.smartRouting ? !!toPort && !!matrix ? generateSmartPath(matrix, startPos, endPos, fromPort, toPort) : generateRightAnglePath(startPos, endPos) : generateCurvePath(startPos, endPos); console.log(points); const center = findCenter(points);

Then you will just need to set your labels x and y axis to the 'center' properties positions. <Label style={{ left: center.x, top: center.y }}>

Full component is attached. correct extension is .tsx WorkflowLink.txt

rekrap42 avatar Oct 06 '20 14:10 rekrap42