@ -1,7 +1,7 @@
let util = require ( '../../../../util' ) ;
class Label {
constructor ( body , options ) {
constructor ( body , options , edgelabel = false ) {
this . body = body ;
this . pointToSelf = false ;
@ -9,6 +9,7 @@ class Label {
this . fontOptions = { } ;
this . setOptions ( options ) ;
this . size = { top : 0 , left : 0 , width : 0 , height : 0 , yLine : 0 } ; // could be cached
this . isEdgeLabel = edgelabel ;
}
setOptions ( options , allowDeletion = false ) {
@ -87,19 +88,23 @@ class Label {
let lineMargin = 2 ;
switch ( this . fontOptions . align ) {
case 'middle' :
ctx . fillRect ( - this . size . width * 0.5 , - this . size . height * 0.5 , this . size . width , this . size . height ) ;
break ;
case 'top' :
ctx . fillRect ( - this . size . width * 0.5 , - ( this . size . height + lineMargin ) , this . size . width , this . size . height ) ;
break ;
case 'bottom' :
ctx . fillRect ( - this . size . width * 0.5 , lineMargin , this . size . width , this . size . height ) ;
break ;
default :
ctx . fillRect ( this . size . left , this . size . top - 0.5 * lineMargin , this . size . width , this . size . height ) ;
break ;
if ( this . isEdgeLabel ) {
switch ( this . fontOptions . align ) {
case 'middle' :
ctx . fillRect ( - this . size . width * 0.5 , - this . size . height * 0.5 , this . size . width , this . size . height ) ;
break ;
case 'top' :
ctx . fillRect ( - this . size . width * 0.5 , - ( this . size . height + lineMargin ) , this . size . width , this . size . height ) ;
break ;
case 'bottom' :
ctx . fillRect ( - this . size . width * 0.5 , lineMargin , this . size . width , this . size . height ) ;
break ;
default :
ctx . fillRect ( this . size . left , this . size . top - 0.5 * lineMargin , this . size . width , this . size . height ) ;
break ;
}
} else {
ctx . fillRect ( this . size . left , this . size . top - 0.5 * lineMargin , this . size . width , this . size . height ) ;
}
}
}
@ -128,8 +133,8 @@ class Label {
ctx . font = ( selected && this . nodeOptions . labelHighlightBold ? 'bold ' : '' ) + fontSize + "px " + this . fontOptions . face ;
ctx . fillStyle = fontColor ;
// When the textAlign property is 'left', make label left-justified
if ( this . option s . font . textA lign === 'left' ) {
ctx . textAlign = this . options . font . textAlign ;
if ( ( ! this . isEdgeLabel ) && th is . fontOptions . a lign === 'left' ) {
ctx . textAlign = this . f ontO ptions. align ;
x = x - 0.5 * this . size . width ; // Shift label 1/2-distance to the left
} else {
ctx . textAlign = 'center' ;
@ -155,7 +160,7 @@ class Label {
_setAlignment ( ctx , x , yLine , baseline ) {
// check for label alignment (for edges)
// TODO: make alignment for nodes
if ( this . fontOptions . align !== 'horizontal' && this . pointToSelf === false ) {
if ( this . isEdgeLabel && this . fontOptions . align !== 'horizontal' && this . pointToSelf === false ) {
x = 0 ;
yLine = 0 ;