try
This commit is contained in:
parent
6ec83ff541
commit
a9a27821c4
5 changed files with 219 additions and 180 deletions
|
|
@ -99,14 +99,53 @@ func createCircularArc(edge *d2graph.Edge) {
|
|||
path[len(path)-1] = newDst
|
||||
|
||||
// Trim redundant path points that fall inside node boundaries.
|
||||
// path = trimPathPoints(path, edge.Src.Box)
|
||||
// path = trimPathPoints(path, edge.Dst.Box)
|
||||
|
||||
// edge.Route = path
|
||||
// edge.IsCurve = true
|
||||
// }
|
||||
path = trimPathPoints(path, edge.Src.Box)
|
||||
path = trimPathPoints(path, edge.Dst.Box)
|
||||
|
||||
// Adjust the last two points to align the arrow direction with the arc's tangent
|
||||
if len(path) >= 2 {
|
||||
dstPoint := path[len(path)-1]
|
||||
prevPoint := path[len(path)-2]
|
||||
|
||||
// Calculate the vector between the last two points
|
||||
dx := dstPoint.X - prevPoint.X
|
||||
dy := dstPoint.Y - prevPoint.Y
|
||||
|
||||
// Calculate the perpendicular vector (rotated 90 degrees counter-clockwise)
|
||||
// This gives us the center direction of the circular arc
|
||||
centerDirX := -dy
|
||||
centerDirY := dx
|
||||
|
||||
// Normalize the center direction vector
|
||||
centerLength := math.Hypot(centerDirX, centerDirY)
|
||||
if centerLength > 0 {
|
||||
centerDirX /= centerLength
|
||||
centerDirY /= centerLength
|
||||
}
|
||||
|
||||
// Calculate the tangent direction (perpendicular to center direction)
|
||||
tangentX := -centerDirY
|
||||
tangentY := centerDirX
|
||||
|
||||
// Adjust the penultimate point to create proper arrow alignment
|
||||
step := 10.0
|
||||
newPrevX := dstPoint.X - tangentX*step
|
||||
newPrevY := dstPoint.Y - tangentY*step
|
||||
|
||||
// Update the path with the adjusted point
|
||||
path[len(path)-2] = geo.NewPoint(newPrevX, newPrevY)
|
||||
}
|
||||
|
||||
edge.Route = path
|
||||
edge.IsCurve = true
|
||||
}
|
||||
|
||||
|
||||
// clampPointOutsideBox walks forward along the path until it finds a point outside the box,
|
||||
// then replaces the point with a precise intersection.
|
||||
func clampPointOutsideBox(box *geo.Box, path []*geo.Point, startIdx int) (int, *geo.Point) {
|
||||
|
|
|
|||
24
e2etests/testdata/txtar/cycle-diagram/dagre/board.exp.json
generated
vendored
24
e2etests/testdata/txtar/cycle-diagram/dagre/board.exp.json
generated
vendored
|
|
@ -864,8 +864,8 @@
|
|||
"y": -37.47600173950195
|
||||
},
|
||||
{
|
||||
"x": 197.02099609375,
|
||||
"y": -34.3849983215332
|
||||
"x": 198.8939971923828,
|
||||
"y": -23.135000228881836
|
||||
},
|
||||
{
|
||||
"x": 197.2519989013672,
|
||||
|
|
@ -1228,8 +1228,8 @@
|
|||
"y": 197.53700256347656
|
||||
},
|
||||
{
|
||||
"x": 28.18000030517578,
|
||||
"y": 198.00399780273438
|
||||
"x": 16.589000701904297,
|
||||
"y": 199.56100463867188
|
||||
},
|
||||
{
|
||||
"x": 26.5,
|
||||
|
|
@ -1592,8 +1592,8 @@
|
|||
"y": 37.47600173950195
|
||||
},
|
||||
{
|
||||
"x": -197.02099609375,
|
||||
"y": 34.3849983215332
|
||||
"x": -198.8939971923828,
|
||||
"y": 23.135000228881836
|
||||
},
|
||||
{
|
||||
"x": -197.2519989013672,
|
||||
|
|
@ -1972,8 +1972,8 @@
|
|||
"y": 111.8030014038086
|
||||
},
|
||||
{
|
||||
"x": 701.875,
|
||||
"y": 115.77300262451172
|
||||
"x": 698.0460205078125,
|
||||
"y": 126.40799713134766
|
||||
},
|
||||
{
|
||||
"x": 701.4329833984375,
|
||||
|
|
@ -2336,8 +2336,8 @@
|
|||
"y": 186.90899658203125
|
||||
},
|
||||
{
|
||||
"x": 364.3710021972656,
|
||||
"y": 183.8260040283203
|
||||
"x": 357.02899169921875,
|
||||
"y": 175.4980010986328
|
||||
},
|
||||
{
|
||||
"x": 363.6419982910156,
|
||||
|
|
@ -2740,8 +2740,8 @@
|
|||
"y": 196.45700073242188
|
||||
},
|
||||
{
|
||||
"x": 1003.2860107421875,
|
||||
"y": 197.53700256347656
|
||||
"x": 988.5989990234375,
|
||||
"y": 199.6269989013672
|
||||
},
|
||||
{
|
||||
"x": 998.5,
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 25 KiB |
24
e2etests/testdata/txtar/cycle-diagram/elk/board.exp.json
generated
vendored
24
e2etests/testdata/txtar/cycle-diagram/elk/board.exp.json
generated
vendored
|
|
@ -864,8 +864,8 @@
|
|||
"y": -25.47599983215332
|
||||
},
|
||||
{
|
||||
"x": 209.02099609375,
|
||||
"y": -22.385000228881836
|
||||
"x": 210.8939971923828,
|
||||
"y": -11.135000228881836
|
||||
},
|
||||
{
|
||||
"x": 209.2519989013672,
|
||||
|
|
@ -1228,8 +1228,8 @@
|
|||
"y": 209.53700256347656
|
||||
},
|
||||
{
|
||||
"x": 40.18000030517578,
|
||||
"y": 210.00399780273438
|
||||
"x": 28.589000701904297,
|
||||
"y": 211.56100463867188
|
||||
},
|
||||
{
|
||||
"x": 38.5,
|
||||
|
|
@ -1592,8 +1592,8 @@
|
|||
"y": 49.47600173950195
|
||||
},
|
||||
{
|
||||
"x": -185.02099609375,
|
||||
"y": 46.3849983215332
|
||||
"x": -186.8939971923828,
|
||||
"y": 35.1349983215332
|
||||
},
|
||||
{
|
||||
"x": -185.2519989013672,
|
||||
|
|
@ -1972,8 +1972,8 @@
|
|||
"y": 123.8030014038086
|
||||
},
|
||||
{
|
||||
"x": 674.375,
|
||||
"y": 127.77300262451172
|
||||
"x": 670.5460205078125,
|
||||
"y": 138.4080047607422
|
||||
},
|
||||
{
|
||||
"x": 673.9329833984375,
|
||||
|
|
@ -2336,8 +2336,8 @@
|
|||
"y": 198.90899658203125
|
||||
},
|
||||
{
|
||||
"x": 336.8710021972656,
|
||||
"y": 195.8260040283203
|
||||
"x": 329.52899169921875,
|
||||
"y": 187.4980010986328
|
||||
},
|
||||
{
|
||||
"x": 336.1419982910156,
|
||||
|
|
@ -2740,8 +2740,8 @@
|
|||
"y": 208.45700073242188
|
||||
},
|
||||
{
|
||||
"x": 936.197021484375,
|
||||
"y": 209.53700256347656
|
||||
"x": 921.5089721679688,
|
||||
"y": 211.6269989013672
|
||||
},
|
||||
{
|
||||
"x": 931.4099731445312,
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 25 KiB |
Loading…
Reference in a new issue