@ -1,12 +1,15 @@
/ * *
* The Base class for all Nodes .
*
* @ param { Object } options
* @ param { Object } body
* @ param { Label } labelModule
* @ constructor NodeBase
* @ class NodeBase
* /
class NodeBase {
/ * *
* @ param { Object } options
* @ param { Object } body
* @ param { Label } labelModule
* @ constructor NodeBase
* /
constructor ( options , body , labelModule ) {
this . body = body ;
this . labelModule = labelModule ;
@ -21,10 +24,19 @@ class NodeBase {
this . boundingBox = { top : 0 , left : 0 , right : 0 , bottom : 0 } ;
}
/ * *
*
* @ param { Object } options
* /
setOptions ( options ) {
this . options = options ;
}
/ * *
*
* @ param { Label } labelModule
* @ private
* /
_setMargins ( labelModule ) {
this . margin = { } ;
if ( this . options . margin ) {
@ -43,6 +55,13 @@ class NodeBase {
labelModule . adjustSizes ( this . margin )
}
/ * *
*
* @ param { CanvasRenderingContext2D } ctx
* @ param { Number } angle
* @ returns { Number }
* @ private
* /
_distanceToBorder ( ctx , angle ) {
var borderWidth = this . options . borderWidth ;
this . resize ( ctx ) ;
@ -51,6 +70,11 @@ class NodeBase {
Math . abs ( this . height / 2 / Math . sin ( angle ) ) ) + borderWidth ;
}
/ * *
*
* @ param { CanvasRenderingContext2D } ctx
* @ param { { toArrow : boolean , toArrowScale : ( allOptions . edges . arrows . to . scaleFactor | { number } | allOptions . edges . arrows . middle . scaleFactor | allOptions . edges . arrows . from . scaleFactor | Array | number ) , toArrowType : * , middleArrow : boolean , middleArrowScale : ( number | allOptions . edges . arrows . middle . scaleFactor | { number } | Array ) , middleArrowType : ( allOptions . edges . arrows . middle . type | { string } | string | * ) , fromArrow : boolean , fromArrowScale : ( allOptions . edges . arrows . to . scaleFactor | { number } | allOptions . edges . arrows . middle . scaleFactor | allOptions . edges . arrows . from . scaleFactor | Array | number ) , fromArrowType : * , arrowStrikethrough : ( * | boolean | allOptions . edges . arrowStrikethrough | { boolean } ) , color : undefined , inheritsColor : ( string | string | string | allOptions . edges . color . inherit | { string , boolean } | Array | * ) , opacity : * , hidden : * , length : * , shadow : * , shadowColor : * , shadowSize : * , shadowX : * , shadowY : * , dashes : ( * | boolean | Array | allOptions . edges . dashes | { boolean , array } ) , width : * } } values
* /
enableShadow ( ctx , values ) {
if ( values . shadow ) {
ctx . shadowColor = values . shadowColor ;
@ -60,6 +84,11 @@ class NodeBase {
}
}
/ * *
*
* @ param { CanvasRenderingContext2D } ctx
* @ param { { toArrow : boolean , toArrowScale : ( allOptions . edges . arrows . to . scaleFactor | { number } | allOptions . edges . arrows . middle . scaleFactor | allOptions . edges . arrows . from . scaleFactor | Array | number ) , toArrowType : * , middleArrow : boolean , middleArrowScale : ( number | allOptions . edges . arrows . middle . scaleFactor | { number } | Array ) , middleArrowType : ( allOptions . edges . arrows . middle . type | { string } | string | * ) , fromArrow : boolean , fromArrowScale : ( allOptions . edges . arrows . to . scaleFactor | { number } | allOptions . edges . arrows . middle . scaleFactor | allOptions . edges . arrows . from . scaleFactor | Array | number ) , fromArrowType : * , arrowStrikethrough : ( * | boolean | allOptions . edges . arrowStrikethrough | { boolean } ) , color : undefined , inheritsColor : ( string | string | string | allOptions . edges . color . inherit | { string , boolean } | Array | * ) , opacity : * , hidden : * , length : * , shadow : * , shadowColor : * , shadowSize : * , shadowX : * , shadowY : * , dashes : ( * | boolean | Array | allOptions . edges . dashes | { boolean , array } ) , width : * } } values
* /
disableShadow ( ctx , values ) {
if ( values . shadow ) {
ctx . shadowColor = 'rgba(0,0,0,0)' ;
@ -69,6 +98,11 @@ class NodeBase {
}
}
/ * *
*
* @ param { CanvasRenderingContext2D } ctx
* @ param { { toArrow : boolean , toArrowScale : ( allOptions . edges . arrows . to . scaleFactor | { number } | allOptions . edges . arrows . middle . scaleFactor | allOptions . edges . arrows . from . scaleFactor | Array | number ) , toArrowType : * , middleArrow : boolean , middleArrowScale : ( number | allOptions . edges . arrows . middle . scaleFactor | { number } | Array ) , middleArrowType : ( allOptions . edges . arrows . middle . type | { string } | string | * ) , fromArrow : boolean , fromArrowScale : ( allOptions . edges . arrows . to . scaleFactor | { number } | allOptions . edges . arrows . middle . scaleFactor | allOptions . edges . arrows . from . scaleFactor | Array | number ) , fromArrowType : * , arrowStrikethrough : ( * | boolean | allOptions . edges . arrowStrikethrough | { boolean } ) , color : undefined , inheritsColor : ( string | string | string | allOptions . edges . color . inherit | { string , boolean } | Array | * ) , opacity : * , hidden : * , length : * , shadow : * , shadowColor : * , shadowSize : * , shadowX : * , shadowY : * , dashes : ( * | boolean | Array | allOptions . edges . dashes | { boolean , array } ) , width : * } } values
* /
enableBorderDashes ( ctx , values ) {
if ( values . borderDashes !== false ) {
if ( ctx . setLineDash !== undefined ) {
@ -86,6 +120,11 @@ class NodeBase {
}
}
/ * *
*
* @ param { CanvasRenderingContext2D } ctx
* @ param { { toArrow : boolean , toArrowScale : ( allOptions . edges . arrows . to . scaleFactor | { number } | allOptions . edges . arrows . middle . scaleFactor | allOptions . edges . arrows . from . scaleFactor | Array | number ) , toArrowType : * , middleArrow : boolean , middleArrowScale : ( number | allOptions . edges . arrows . middle . scaleFactor | { number } | Array ) , middleArrowType : ( allOptions . edges . arrows . middle . type | { string } | string | * ) , fromArrow : boolean , fromArrowScale : ( allOptions . edges . arrows . to . scaleFactor | { number } | allOptions . edges . arrows . middle . scaleFactor | allOptions . edges . arrows . from . scaleFactor | Array | number ) , fromArrowType : * , arrowStrikethrough : ( * | boolean | allOptions . edges . arrowStrikethrough | { boolean } ) , color : undefined , inheritsColor : ( string | string | string | allOptions . edges . color . inherit | { string , boolean } | Array | * ) , opacity : * , hidden : * , length : * , shadow : * , shadowColor : * , shadowSize : * , shadowX : * , shadowY : * , dashes : ( * | boolean | Array | allOptions . edges . dashes | { boolean , array } ) , width : * } } values
* /
disableBorderDashes ( ctx , values ) {
if ( values . borderDashes !== false ) {
if ( ctx . setLineDash !== undefined ) {
@ -99,7 +138,6 @@ class NodeBase {
}
}
/ * *
* Determine if the shape of a node needs to be recalculated .
*
@ -119,7 +157,11 @@ class NodeBase {
return ( this . width === undefined ) || ( this . labelModule . differentState ( selected , hover ) ) ;
}
/ * *
*
* @ param { CanvasRenderingContext2D } ctx
* @ param { { toArrow : boolean , toArrowScale : ( allOptions . edges . arrows . to . scaleFactor | { number } | allOptions . edges . arrows . middle . scaleFactor | allOptions . edges . arrows . from . scaleFactor | Array | number ) , toArrowType : * , middleArrow : boolean , middleArrowScale : ( number | allOptions . edges . arrows . middle . scaleFactor | { number } | Array ) , middleArrowType : ( allOptions . edges . arrows . middle . type | { string } | string | * ) , fromArrow : boolean , fromArrowScale : ( allOptions . edges . arrows . to . scaleFactor | { number } | allOptions . edges . arrows . middle . scaleFactor | allOptions . edges . arrows . from . scaleFactor | Array | number ) , fromArrowType : * , arrowStrikethrough : ( * | boolean | allOptions . edges . arrowStrikethrough | { boolean } ) , color : undefined , inheritsColor : ( string | string | string | allOptions . edges . color . inherit | { string , boolean } | Array | * ) , opacity : * , hidden : * , length : * , shadow : * , shadowColor : * , shadowSize : * , shadowX : * , shadowY : * , dashes : ( * | boolean | Array | allOptions . edges . dashes | { boolean , array } ) , width : * } } values
* /
initContextForDraw ( ctx , values ) {
var borderWidth = values . borderWidth / this . body . view . scale ;
@ -128,7 +170,11 @@ class NodeBase {
ctx . fillStyle = values . color ;
}
/ * *
*
* @ param { CanvasRenderingContext2D } ctx
* @ param { { toArrow : boolean , toArrowScale : ( allOptions . edges . arrows . to . scaleFactor | { number } | allOptions . edges . arrows . middle . scaleFactor | allOptions . edges . arrows . from . scaleFactor | Array | number ) , toArrowType : * , middleArrow : boolean , middleArrowScale : ( number | allOptions . edges . arrows . middle . scaleFactor | { number } | Array ) , middleArrowType : ( allOptions . edges . arrows . middle . type | { string } | string | * ) , fromArrow : boolean , fromArrowScale : ( allOptions . edges . arrows . to . scaleFactor | { number } | allOptions . edges . arrows . middle . scaleFactor | allOptions . edges . arrows . from . scaleFactor | Array | number ) , fromArrowType : * , arrowStrikethrough : ( * | boolean | allOptions . edges . arrowStrikethrough | { boolean } ) , color : undefined , inheritsColor : ( string | string | string | allOptions . edges . color . inherit | { string , boolean } | Array | * ) , opacity : * , hidden : * , length : * , shadow : * , shadowColor : * , shadowSize : * , shadowX : * , shadowY : * , dashes : ( * | boolean | Array | allOptions . edges . dashes | { boolean , array } ) , width : * } } values
* /
performStroke ( ctx , values ) {
var borderWidth = values . borderWidth / this . body . view . scale ;
@ -145,7 +191,11 @@ class NodeBase {
ctx . restore ( ) ;
}
/ * *
*
* @ param { CanvasRenderingContext2D } ctx
* @ param { { toArrow : boolean , toArrowScale : ( allOptions . edges . arrows . to . scaleFactor | { number } | allOptions . edges . arrows . middle . scaleFactor | allOptions . edges . arrows . from . scaleFactor | Array | number ) , toArrowType : * , middleArrow : boolean , middleArrowScale : ( number | allOptions . edges . arrows . middle . scaleFactor | { number } | Array ) , middleArrowType : ( allOptions . edges . arrows . middle . type | { string } | string | * ) , fromArrow : boolean , fromArrowScale : ( allOptions . edges . arrows . to . scaleFactor | { number } | allOptions . edges . arrows . middle . scaleFactor | allOptions . edges . arrows . from . scaleFactor | Array | number ) , fromArrowType : * , arrowStrikethrough : ( * | boolean | allOptions . edges . arrowStrikethrough | { boolean } ) , color : undefined , inheritsColor : ( string | string | string | allOptions . edges . color . inherit | { string , boolean } | Array | * ) , opacity : * , hidden : * , length : * , shadow : * , shadowColor : * , shadowSize : * , shadowX : * , shadowY : * , dashes : ( * | boolean | Array | allOptions . edges . dashes | { boolean , array } ) , width : * } } values
* /
performFill ( ctx , values ) {
// draw shadow if enabled
this . enableShadow ( ctx , values ) ;
@ -158,6 +208,11 @@ class NodeBase {
}
/ * *
*
* @ param { Number } margin
* @ private
* /
_addBoundingBoxMargin ( margin ) {
this . boundingBox . left -= margin ;
this . boundingBox . top -= margin ;