@@ -5,6 +5,7 @@ import { line, curveBasis, select } from 'd3';
55import { getConfig } from '../config.js' ;
66import utils from '../utils.js' ;
77import { evaluate } from '../diagrams/common/common.js' ;
8+ import { getLineFunctionsWithOffset } from '../utils/lineWithOffset.js' ;
89
910let edgeLabels = { } ;
1011let terminalLabels = { } ;
@@ -368,20 +369,6 @@ const cutPathAtIntersect = (_points, boundryNode) => {
368369 return points ;
369370} ;
370371
371- /**
372- * Calculate the deltas and angle between two points
373- * @param {{x: number, y:number} } point1
374- * @param {{x: number, y:number} } point2
375- * @returns {{angle: number, deltaX: number, deltaY: number} }
376- */
377- function calculateDeltaAndAngle ( point1 , point2 ) {
378- const [ x1 , y1 ] = [ point1 . x , point1 . y ] ;
379- const [ x2 , y2 ] = [ point2 . x , point2 . y ] ;
380- const deltaX = x2 - x1 ;
381- const deltaY = y2 - y1 ;
382- return { angle : Math . atan ( deltaY / deltaX ) , deltaX, deltaY } ;
383- }
384-
385372export const insertEdge = function ( elem , e , edge , clusterDb , diagramType , graph ) {
386373 let points = edge . points ;
387374 let pointsHasChanged = false ;
@@ -456,56 +443,8 @@ export const insertEdge = function (elem, e, edge, clusterDb, diagramType, graph
456443 curve = edge . curve ;
457444 }
458445
459- // We need to draw the lines a bit shorter to avoid drawing
460- // under any transparent markers.
461- // The offsets are calculated from the markers' dimensions.
462- const markerOffsets = {
463- aggregation : 18 ,
464- extension : 18 ,
465- composition : 18 ,
466- dependency : 6 ,
467- lollipop : 13.5 ,
468- arrow_point : 5.3 ,
469- } ;
470-
471- const lineFunction = line ( )
472- . x ( function ( d , i , data ) {
473- let offset = 0 ;
474- if ( i === 0 && Object . hasOwn ( markerOffsets , edge . arrowTypeStart ) ) {
475- // Handle first point
476- // Calculate the angle and delta between the first two points
477- const { angle, deltaX } = calculateDeltaAndAngle ( data [ 0 ] , data [ 1 ] ) ;
478- // Calculate the offset based on the angle and the marker's dimensions
479- offset = markerOffsets [ edge . arrowTypeStart ] * Math . cos ( angle ) * ( deltaX >= 0 ? 1 : - 1 ) || 0 ;
480- } else if ( i === data . length - 1 && Object . hasOwn ( markerOffsets , edge . arrowTypeEnd ) ) {
481- // Handle last point
482- // Calculate the angle and delta between the last two points
483- const { angle, deltaX } = calculateDeltaAndAngle (
484- data [ data . length - 1 ] ,
485- data [ data . length - 2 ]
486- ) ;
487- offset = markerOffsets [ edge . arrowTypeEnd ] * Math . cos ( angle ) * ( deltaX >= 0 ? 1 : - 1 ) || 0 ;
488- }
489- return d . x + offset ;
490- } )
491- . y ( function ( d , i , data ) {
492- // Same handling as X above
493- let offset = 0 ;
494- if ( i === 0 && Object . hasOwn ( markerOffsets , edge . arrowTypeStart ) ) {
495- const { angle, deltaY } = calculateDeltaAndAngle ( data [ 0 ] , data [ 1 ] ) ;
496- offset =
497- markerOffsets [ edge . arrowTypeStart ] * Math . abs ( Math . sin ( angle ) ) * ( deltaY >= 0 ? 1 : - 1 ) ;
498- } else if ( i === data . length - 1 && Object . hasOwn ( markerOffsets , edge . arrowTypeEnd ) ) {
499- const { angle, deltaY } = calculateDeltaAndAngle (
500- data [ data . length - 1 ] ,
501- data [ data . length - 2 ]
502- ) ;
503- offset =
504- markerOffsets [ edge . arrowTypeEnd ] * Math . abs ( Math . sin ( angle ) ) * ( deltaY >= 0 ? 1 : - 1 ) ;
505- }
506- return d . y + offset ;
507- } )
508- . curve ( curve ) ;
446+ const { x, y } = getLineFunctionsWithOffset ( edge ) ;
447+ const lineFunction = line ( ) . x ( x ) . y ( y ) . curve ( curve ) ;
509448
510449 // Construct stroke classes based on properties
511450 let strokeClasses ;
0 commit comments