@@ -46,6 +46,7 @@ const style = [
4646 style : {
4747 curveStyle : 'bezier' ,
4848 targetArrowShape : 'triangle' ,
49+ arrowScale : 1.2 ,
4950 } ,
5051 } ,
5152 {
@@ -54,26 +55,113 @@ const style = [
5455 width : 'data(style.thickness)' ,
5556 lineColor : 'data(style.backgroundColor)' ,
5657 targetArrowColor : 'data(style.backgroundColor)' ,
57- curveStyle : 'segments' ,
58- segmentDistances : 'data(bendData.bendDistance)' ,
58+ curveStyle : ( ele ) => {
59+ const source = ele . source ( ) ;
60+ const target = ele . target ( ) ;
61+
62+ // Check if there are parallel edges
63+ const parallelEdges = source . edgesWith ( target ) ;
64+ const hasParallelEdges = parallelEdges . length > 1 ;
65+
66+ // Get positions
67+ const p1 = source . position ( ) ;
68+ const p2 = target . position ( ) ;
69+
70+ // Calculate distance between nodes
71+ const distance = Math . sqrt (
72+ ( p2 . x - p1 . x ) ** 2 + ( p2 . y - p1 . y ) ** 2 ,
73+ ) ;
74+
75+ // Calculate difference
76+ const dx = Math . abs ( p1 . x - p2 . x ) ;
77+ const dy = Math . abs ( p1 . y - p2 . y ) ;
78+
79+ // Define a threshold for what counts as "aligned"
80+ const threshold = 10 ;
81+
82+ // Check if edge has custom bend data
83+ const bendDistance = ele . data ( 'bendData' ) ?. bendDistance || 0 ;
84+ const hasBend = Math . abs ( bendDistance ) > 0 ;
85+
86+ // When nodes are very close, always use straight style to prevent edge disappearance
87+ if ( distance < 50 ) {
88+ return 'straight' ;
89+ }
90+
91+ // For parallel edges or edges with bend, use bezier curves
92+ if ( hasParallelEdges || hasBend ) {
93+ return 'unbundled-bezier' ;
94+ }
95+
96+ // If aligned horizontally OR vertically, be straight
97+ if ( dx < threshold || dy < threshold ) {
98+ return 'straight' ;
99+ }
100+
101+ // use unbundled-bezier to respect bend points
102+ return 'unbundled-bezier' ;
103+ } ,
104+ segmentDistances : ( ele ) => {
105+ // When nodes are very close, don't apply bend to prevent edge disappearance
106+ const source = ele . source ( ) ;
107+ const target = ele . target ( ) ;
108+ const p1 = source . position ( ) ;
109+ const p2 = target . position ( ) ;
110+ const distance = Math . sqrt (
111+ ( p2 . x - p1 . x ) ** 2 + ( p2 . y - p1 . y ) ** 2 ,
112+ ) ;
113+
114+ if ( distance < 50 ) {
115+ return 0 ;
116+ }
117+
118+ return ele . data ( 'bendData.bendDistance' ) ;
119+ } ,
59120 segmentWeights : 'data(bendData.bendWeight)' ,
60121 edgeDistances : 'node-position' ,
61122 lineStyle : 'data(style.shape)' ,
123+ controlPointDistances : ( ele ) => {
124+ // For parallel edges, ensure adequate control point spacing
125+ const bendDistance = ele . data ( 'bendData' ) ?. bendDistance || 0 ;
126+ return Math . abs ( bendDistance ) > 0 ? bendDistance : undefined ;
127+ } ,
128+ controlPointWeights : ( ele ) => {
129+ const bendWeight = ele . data ( 'bendData' ) ?. bendWeight ;
130+ return bendWeight !== undefined ? bendWeight : 0.5 ;
131+ } ,
62132 } ,
63133 } ,
64134 {
65135 selector : 'edge[label]' ,
66136 style : {
67- label : 'data(label)' ,
137+ label : ( ele ) => {
138+ // Get source and target nodes
139+ const source = ele . source ( ) ;
140+ const target = ele . target ( ) ;
141+
142+ // Calculate distance between nodes
143+ const p1 = source . position ( ) ;
144+ const p2 = target . position ( ) ;
145+ const distance = Math . sqrt (
146+ ( p2 . x - p1 . x ) ** 2 + ( p2 . y - p1 . y ) ** 2 ,
147+ ) ;
148+
149+ // Define minimum distance threshold (in pixels)
150+ // Below this distance, hide the label to prevent visual clutter
151+ const minDistanceForLabel = 80 ;
152+
153+ // Return label only if nodes are far enough apart
154+ return distance >= minDistanceForLabel ? ele . data ( 'label' ) : '' ;
155+ } ,
68156 edgeTextRotation : 'autorotate' ,
69157 zIndex : 999 ,
158+ fontSize : 12 ,
70159 textBackgroundOpacity : 1 ,
71- color : '#000' ,
160+ textBackgroundPadding : '3px' ,
161+ textBorderWidth : 0 ,
162+ color : '#333' ,
72163 textBackgroundColor : '#fff' ,
73164 textBackgroundShape : 'roundrectangle' ,
74- textBorderColor : '#fff' ,
75- textBorderWidth : 2 ,
76- textBorderOpacity : 1 ,
77165 } ,
78166 } ,
79167 {
0 commit comments