@ -531,7 +531,7 @@ class Edge {
// draw everything
this . edgeType . drawLine ( ctx , values , this . selected , this . hover , viaNode ) ;
this . drawArrows ( ctx , arrowData , values ) ;
this . drawLabel ( ctx , viaNode ) ;
this . drawLabel ( ctx , viaNode ) ;
}
/ * *
@ -572,15 +572,24 @@ class Edge {
var point = this . edgeType . getPoint ( 0.5 , viaNode ) ;
ctx . save ( ) ;
// if the label has to be rotated:
if ( this . options . font . align !== "horizontal" ) {
this . labelModule . calculateLabelSize ( ctx , this . selected , this . hover , point . x , point . y ) ;
ctx . translate ( point . x , this . labelModule . size . yLine ) ;
this . _rotateForLabelAlignment ( ctx ) ;
let rotationPoint = this . _getRotation ( ctx ) ;
if ( rotationPoint . angle != 0 ) {
ctx . translate ( rotationPoint . x , rotationPoint . y ) ;
ctx . rotate ( rotationPoint . angle ) ;
}
// draw the label
this . labelModule . draw ( ctx , point . x , point . y , this . selected , this . hover ) ;
/ *
// Useful debug code: draw a border around the label
// This should **not** be enabled in production!
var size = this . labelModule . getSize ( ) ; ; // ;; intentional so lint catches it
ctx . strokeStyle = "#ff0000" ;
ctx . strokeRect ( size . left , size . top , size . width , size . height ) ;
// End debug code
* /
ctx . restore ( ) ;
}
else {
@ -603,6 +612,36 @@ class Edge {
}
/ * *
* Determine all visual elements of this edge instance , in which the given
* point falls within the bounding shape .
*
* @ param { point } point
* @ returns { Array . < edgeClickItem | edgeLabelClickItem > } list with the items which are on the point
* /
getItemsOnPoint ( point ) {
var ret = [ ] ;
if ( this . labelModule . visible ( ) ) {
let rotationPoint = this . _getRotation ( ) ;
if ( ComponentUtil . pointInRect ( this . labelModule . getSize ( ) , point , rotationPoint ) ) {
ret . push ( { edgeId : this . id , labelId : 0 } ) ;
}
}
let obj = {
left : point . x ,
top : point . y
} ;
if ( this . isOverlappingWith ( obj ) ) {
ret . push ( { edgeId : this . id } ) ;
}
return ret ;
}
/ * *
* Check if this object is overlapping with the provided object
* @ param { Object } obj an object with parameters left , top
@ -628,22 +667,46 @@ class Edge {
}
/ * *
* Rotates the canvas so the text is most readable
* @ param { CanvasRenderingContext2D } ctx
/ * *
* Determine the rotation point , if any .
*
* @ param { CanvasRenderingContext2D } [ ctx ] if passed , do a recalculation of the label size
* @ returns { rotationPoint } the point to rotate around and the angle in radians to rotate
* @ private
* /
_rotateForLabelAlignment ( ctx ) {
_getRotation ( ctx ) {
let viaNode = this . edgeType . getViaNode ( ) ;
let point = this . edgeType . getPoint ( 0.5 , viaNode ) ;
if ( ctx !== undefined ) {
this . labelModule . calculateLabelSize ( ctx , this . selected , this . hover , point . x , point . y ) ;
}
let ret = {
x : point . x ,
y : this . labelModule . size . yLine ,
angle : 0
} ;
if ( ! this . labelModule . visible ( ) ) {
return ret ; // Don't even bother doing the atan2, there's nothing to draw
}
if ( this . options . font . align === "horizontal" ) {
return ret ; // No need to calculate angle
}
var dy = this . from . y - this . to . y ;
var dx = this . from . x - this . to . x ;
var angleInDegrees = Math . atan2 ( dy , dx ) ;
var angle = Math . atan2 ( dy , dx ) ; // radians
// rotate so label it is readable
if ( ( angleInDegrees < - 1 && dx < 0 ) || ( angleInDegrees > 0 && dx < 0 ) ) {
angleInDegrees = angleInDegrees + Math . PI ;
// rotate so that label is readable
if ( ( angle < - 1 && dx < 0 ) || ( angle > 0 && dx < 0 ) ) {
angle += Math . PI ;
}
ret . angle = angle ;
ctx . rotate ( angleInDegrees ) ;
return ret ;
}