11import * as React from 'react' ;
22import * as _ from 'lodash' ;
33import { observer } from 'mobx-react' ;
4- import { Edge , EdgeTerminalType , GraphElement , isEdge , isNode , NodeStatus } from '../../types' ;
4+ import { Edge , EdgeTerminalType , GraphElement , isEdge , isNode , NodeStatus , ScaleDetailsLevel } from '../../types' ;
55import { ConnectDragSource , OnSelect } from '../../behavior' ;
66import { getClosestVisibleParent , useHover } from '../../utils' ;
77import { Layer } from '../layers' ;
@@ -112,6 +112,8 @@ const DefaultEdgeInner: React.FunctionComponent<DefaultEdgeInnerProps> = observe
112112 return null ;
113113 }
114114
115+ const detailsLevel = element . getGraph ( ) . getDetailsLevel ( ) ;
116+
115117 const groupClassName = css (
116118 styles . topologyEdge ,
117119 className ,
@@ -126,9 +128,8 @@ const DefaultEdgeInner: React.FunctionComponent<DefaultEdgeInnerProps> = observe
126128
127129 const bendpoints = element . getBendpoints ( ) ;
128130
129- const d = `M${ startPoint . x } ${ startPoint . y } ${ bendpoints . map ( ( b : Point ) => `L${ b . x } ${ b . y } ` ) . join ( '' ) } L${
130- endPoint . x
131- } ${ endPoint . y } `;
131+ const d = `M${ startPoint . x } ${ startPoint . y } ${ bendpoints . map ( ( b : Point ) => `L${ b . x } ${ b . y } ` ) . join ( '' ) } L${ endPoint . x
132+ } ${ endPoint . y } `;
132133
133134 const bgStartPoint =
134135 ! startTerminalType || startTerminalType === EdgeTerminalType . none
@@ -141,6 +142,11 @@ const DefaultEdgeInner: React.FunctionComponent<DefaultEdgeInnerProps> = observe
141142 const backgroundPath = `M${ bgStartPoint [ 0 ] } ${ bgStartPoint [ 1 ] } ${ bendpoints
142143 . map ( ( b : Point ) => `L${ b . x } ${ b . y } ` )
143144 . join ( '' ) } L${ bgEndPoint [ 0 ] } ${ bgEndPoint [ 1 ] } `;
145+
146+ const showTag = tag && ( detailsLevel === ScaleDetailsLevel . high || hover ) ;
147+ const scale = element . getGraph ( ) . getScale ( ) ;
148+ const tagScale = hover && ! ( detailsLevel === ScaleDetailsLevel . high ) ? Math . max ( 1 , 1 / scale ) : 1 ;
149+ const tagPositionScale = hover && ! ( detailsLevel === ScaleDetailsLevel . high ) ? Math . min ( 1 , scale ) : 1 ;
144150
145151 return (
146152 < Layer id = { dragging || hover ? TOP_LAYER : undefined } >
@@ -158,14 +164,16 @@ const DefaultEdgeInner: React.FunctionComponent<DefaultEdgeInnerProps> = observe
158164 onMouseLeave = { onHideRemoveConnector }
159165 />
160166 < path className = { linkClassName } d = { d } style = { { animationDuration : `${ edgeAnimationDuration } s` } } />
161- { tag && (
162- < DefaultConnectorTag
163- className = { tagClass }
164- startPoint = { element . getStartPoint ( ) }
165- endPoint = { element . getEndPoint ( ) }
166- tag = { tag }
167- status = { tagStatus }
168- />
167+ { showTag && (
168+ < g transform = { `scale(${ hover ? tagScale : 1 } )` } >
169+ < DefaultConnectorTag
170+ className = { tagClass }
171+ startPoint = { element . getStartPoint ( ) . scale ( tagPositionScale ) }
172+ endPoint = { element . getEndPoint ( ) . scale ( tagPositionScale ) }
173+ tag = { tag }
174+ status = { tagStatus }
175+ />
176+ </ g >
169177 ) }
170178 < DefaultConnectorTerminal
171179 className = { startTerminalClass }
@@ -193,7 +201,7 @@ const DefaultEdgeInner: React.FunctionComponent<DefaultEdgeInnerProps> = observe
193201 ) ;
194202} ) ;
195203
196- const DefaultEdge : React . FunctionComponent < DefaultEdgeProps > = ( {
204+ const DefaultEdge : React . FunctionComponent < DefaultEdgeProps > = ( {
197205 element,
198206 startTerminalType = EdgeTerminalType . none ,
199207 startTerminalSize = 14 ,
0 commit comments