@ -25,7 +25,10 @@ var util = require('../util');
* example for the color
* example for the color
*
*
* /
* /
function Node ( properties , imagelist , grouplist , constants ) {
function Node ( properties , imagelist , grouplist , networkConstants ) {
var constants = util . selectiveBridgeObject ( [ 'nodes' ] , networkConstants ) ;
this . options = constants . nodes ;
this . selected = false ;
this . selected = false ;
this . hover = false ;
this . hover = false ;
@ -33,33 +36,20 @@ function Node(properties, imagelist, grouplist, constants) {
this . dynamicEdges = [ ] ;
this . dynamicEdges = [ ] ;
this . reroutedEdges = { } ;
this . reroutedEdges = { } ;
this . group = constants . nodes . group ;
this . fontSize = Number ( constants . nodes . fontSize ) ;
this . fontFace = constants . nodes . fontFace ;
this . fontColor = constants . nodes . fontColor ;
this . fontDrawThreshold = 3 ;
this . fontDrawThreshold = 3 ;
this . color = constants . nodes . color ;
// set defaults for the properties
// set defaults for the properties
this . id = undefined ;
this . id = undefined ;
this . shape = constants . nodes . shape ;
this . image = constants . nodes . image ;
this . x = null ;
this . x = null ;
this . y = null ;
this . y = null ;
this . xFixed = false ;
this . xFixed = false ;
this . yFixed = false ;
this . yFixed = false ;
this . horizontalAlignLeft = true ; // these are for the navigation controls
this . horizontalAlignLeft = true ; // these are for the navigation controls
this . verticalAlignTop = true ; // these are for the navigation controls
this . verticalAlignTop = true ; // these are for the navigation controls
this . radius = constants . nodes . radius ;
this . baseRadiusValue = constants . nodes . radius ;
this . baseRadiusValue = networkConstants . nodes . radius ;
this . radiusFixed = false ;
this . radiusFixed = false ;
this . radiusMin = constants . nodes . radiusMin ;
this . radiusMax = constants . nodes . radiusMax ;
this . level = - 1 ;
this . level = - 1 ;
this . preassignedLevel = false ;
this . preassignedLevel = false ;
this . borderWidth = constants . nodes . borderWidth ;
this . borderWidthSelected = constants . nodes . borderWidthSelected ;
this . imagelist = imagelist ;
this . imagelist = imagelist ;
@ -70,9 +60,7 @@ function Node(properties, imagelist, grouplist, constants) {
this . fy = 0.0 ; // external force y
this . fy = 0.0 ; // external force y
this . vx = 0.0 ; // velocity x
this . vx = 0.0 ; // velocity x
this . vy = 0.0 ; // velocity y
this . vy = 0.0 ; // velocity y
this . minForce = constants . minForce ;
this . damping = constants . physics . damping ;
this . mass = 1 ; // kg
this . damping = networkConstants . physics . damping ; // written every time gravity is calculated
this . fixedData = { x : null , y : null } ;
this . fixedData = { x : null , y : null } ;
@ -82,10 +70,10 @@ function Node(properties, imagelist, grouplist, constants) {
this . resetCluster ( ) ;
this . resetCluster ( ) ;
this . dynamicEdgesLength = 0 ;
this . dynamicEdgesLength = 0 ;
this . clusterSession = 0 ;
this . clusterSession = 0 ;
this . clusterSizeWidthFactor = c onstants. clustering . nodeScaling . width ;
this . clusterSizeHeightFactor = c onstants. clustering . nodeScaling . height ;
this . clusterSizeRadiusFactor = c onstants. clustering . nodeScaling . radius ;
this . maxNodeSizeIncrements = c onstants. clustering . maxNodeSizeIncrements ;
this . clusterSizeWidthFactor = networkC onstants. clustering . nodeScaling . width ;
this . clusterSizeHeightFactor = networkC onstants. clustering . nodeScaling . height ;
this . clusterSizeRadiusFactor = networkC onstants. clustering . nodeScaling . radius ;
this . maxNodeSizeIncrements = networkC onstants. clustering . maxNodeSizeIncrements ;
this . growthIndicator = 0 ;
this . growthIndicator = 0 ;
// variables to tell the node about the network.
// variables to tell the node about the network.
@ -145,21 +133,21 @@ Node.prototype.setProperties = function(properties, constants) {
if ( ! properties ) {
if ( ! properties ) {
return ;
return ;
}
}
var fields = [ 'borderWidth' , 'borderWidthSelected' , 'shape' , 'image' , 'radius' , 'fontColor' ,
'fontSize' , 'fontFace' , 'group' , 'mass'
] ;
util . selectiveDeepExtend ( fields , this . options , properties ) ;
this . originalLabel = undefined ;
this . originalLabel = undefined ;
// basic properties
// basic properties
if ( properties . id !== undefined ) { this . id = properties . id ; }
if ( properties . id !== undefined ) { this . id = properties . id ; }
if ( properties . label !== undefined ) { this . label = properties . label ; this . originalLabel = properties . label ; }
if ( properties . label !== undefined ) { this . label = properties . label ; this . originalLabel = properties . label ; }
if ( properties . title !== undefined ) { this . title = properties . title ; }
if ( properties . title !== undefined ) { this . title = properties . title ; }
if ( properties . group !== undefined ) { this . group = properties . group ; }
if ( properties . x !== undefined ) { this . x = properties . x ; }
if ( properties . x !== undefined ) { this . x = properties . x ; }
if ( properties . y !== undefined ) { this . y = properties . y ; }
if ( properties . y !== undefined ) { this . y = properties . y ; }
if ( properties . value !== undefined ) { this . value = properties . value ; }
if ( properties . value !== undefined ) { this . value = properties . value ; }
if ( properties . level !== undefined ) { this . level = properties . level ; this . preassignedLevel = true ; }
if ( properties . level !== undefined ) { this . level = properties . level ; this . preassignedLevel = true ; }
if ( properties . borderWidth !== undefined ) { this . borderWidth = properties . borderWidth ; }
if ( properties . borderWidthSelected !== undefined ) { this . borderWidthSelected = properties . borderWidthSelected ; }
// physics
if ( properties . mass !== undefined ) { this . mass = properties . mass ; }
// navigation controls properties
// navigation controls properties
if ( properties . horizontalAlignLeft !== undefined ) { this . horizontalAlignLeft = properties . horizontalAlignLeft ; }
if ( properties . horizontalAlignLeft !== undefined ) { this . horizontalAlignLeft = properties . horizontalAlignLeft ; }
@ -169,30 +157,25 @@ Node.prototype.setProperties = function(properties, constants) {
if ( this . id === undefined ) {
if ( this . id === undefined ) {
throw "Node must have an id" ;
throw "Node must have an id" ;
}
}
// console.log(this.options);
// copy group properties
// copy group properties
if ( this . group !== undefined && this . group != "" ) {
var groupObj = this . grouplist . get ( this . group ) ;
if ( this . options . group !== undefined && this . option s . group != "" ) {
var groupObj = this . grouplist . get ( this . options . group ) ;
for ( var prop in groupObj ) {
for ( var prop in groupObj ) {
if ( groupObj . hasOwnProperty ( prop ) ) {
if ( groupObj . hasOwnProperty ( prop ) ) {
this [ prop ] = groupObj [ prop ] ;
this . options [ prop ] = groupObj [ prop ] ;
}
}
}
}
}
}
// individual shape properties
if ( properties . shape !== undefined ) { this . shape = properties . shape ; }
if ( properties . image !== undefined ) { this . image = properties . image ; }
if ( properties . radius !== undefined ) { this . radius = properties . radius ; this . baseRadiusValue = this . radius ; }
if ( properties . color !== undefined ) { this . color = util . parseColor ( properties . color ) ; }
if ( properties . fontColor !== undefined ) { this . fontColor = properties . fontColor ; }
if ( properties . fontSize !== undefined ) { this . fontSize = properties . fontSize ; }
if ( properties . fontFace !== undefined ) { this . fontFace = properties . fontFace ; }
// individual shape properties
if ( properties . radius !== undefined ) { this . baseRadiusValue = this . options . radius ; }
if ( properties . color !== undefined ) { this . options . color = util . parseColor ( properties . color ) ; }
if ( this . image !== undefined && this . image != "" ) {
if ( this . options . image !== undefined && this . options . image != "" ) {
if ( this . imagelist ) {
if ( this . imagelist ) {
this . imageObj = this . imagelist . load ( this . image ) ;
this . imageObj = this . imagelist . load ( this . options . image ) ;
}
}
else {
else {
throw "No imagelist provided" ;
throw "No imagelist provided" ;
@ -203,13 +186,14 @@ Node.prototype.setProperties = function(properties, constants) {
this . yFixed = this . yFixed || ( properties . y !== undefined && ! properties . allowedToMoveY ) ;
this . yFixed = this . yFixed || ( properties . y !== undefined && ! properties . allowedToMoveY ) ;
this . radiusFixed = this . radiusFixed || ( properties . radius !== undefined ) ;
this . radiusFixed = this . radiusFixed || ( properties . radius !== undefined ) ;
if ( this . shape == 'image' ) {
this . radiusMin = constants . nodes . widthMin ;
this . radiusMax = constants . nodes . widthMax ;
if ( this . options . shape == 'image' ) {
this . options . radiusMin = constants . nodes . widthMin ;
this . options . radiusMax = constants . nodes . widthMax ;
}
}
// choose draw method depending on the shape
// choose draw method depending on the shape
switch ( this . shape ) {
switch ( this . options . shape ) {
case 'database' : this . draw = this . _drawDatabase ; this . resize = this . _resizeDatabase ; break ;
case 'database' : this . draw = this . _drawDatabase ; this . resize = this . _resizeDatabase ; break ;
case 'box' : this . draw = this . _drawBox ; this . resize = this . _resizeBox ; break ;
case 'box' : this . draw = this . _drawBox ; this . resize = this . _resizeBox ; break ;
case 'circle' : this . draw = this . _drawCircle ; this . resize = this . _resizeCircle ; break ;
case 'circle' : this . draw = this . _drawCircle ; this . resize = this . _resizeCircle ; break ;
@ -283,10 +267,10 @@ Node.prototype.distanceToBorder = function (ctx, angle) {
this . resize ( ctx ) ;
this . resize ( ctx ) ;
}
}
switch ( this . shape ) {
switch ( this . options . shape ) {
case 'circle' :
case 'circle' :
case 'dot' :
case 'dot' :
return this . radius + borderWidth ;
return this . options . radius + borderWidth ;
case 'ellipse' :
case 'ellipse' :
var a = this . width / 2 ;
var a = this . width / 2 ;
@ -345,14 +329,14 @@ Node.prototype._addForce = function(fx, fy) {
Node . prototype . discreteStep = function ( interval ) {
Node . prototype . discreteStep = function ( interval ) {
if ( ! this . xFixed ) {
if ( ! this . xFixed ) {
var dx = this . damping * this . vx ; // damping force
var dx = this . damping * this . vx ; // damping force
var ax = ( this . fx - dx ) / this . mass ; // acceleration
var ax = ( this . fx - dx ) / this . options . mass ; // acceleration
this . vx += ax * interval ; // velocity
this . vx += ax * interval ; // velocity
this . x += this . vx * interval ; // position
this . x += this . vx * interval ; // position
}
}
if ( ! this . yFixed ) {
if ( ! this . yFixed ) {
var dy = this . damping * this . vy ; // damping force
var dy = this . damping * this . vy ; // damping force
var ay = ( this . fy - dy ) / this . mass ; // acceleration
var ay = ( this . fy - dy ) / this . options . mass ; // acceleration
this . vy += ay * interval ; // velocity
this . vy += ay * interval ; // velocity
this . y += this . vy * interval ; // position
this . y += this . vy * interval ; // position
}
}
@ -368,7 +352,7 @@ Node.prototype.discreteStep = function(interval) {
Node . prototype . discreteStepLimited = function ( interval , maxVelocity ) {
Node . prototype . discreteStepLimited = function ( interval , maxVelocity ) {
if ( ! this . xFixed ) {
if ( ! this . xFixed ) {
var dx = this . damping * this . vx ; // damping force
var dx = this . damping * this . vx ; // damping force
var ax = ( this . fx - dx ) / this . mass ; // acceleration
var ax = ( this . fx - dx ) / this . options . mass ; // acceleration
this . vx += ax * interval ; // velocity
this . vx += ax * interval ; // velocity
this . vx = ( Math . abs ( this . vx ) > maxVelocity ) ? ( ( this . vx > 0 ) ? maxVelocity : - maxVelocity ) : this . vx ;
this . vx = ( Math . abs ( this . vx ) > maxVelocity ) ? ( ( this . vx > 0 ) ? maxVelocity : - maxVelocity ) : this . vx ;
this . x += this . vx * interval ; // position
this . x += this . vx * interval ; // position
@ -379,7 +363,7 @@ Node.prototype.discreteStepLimited = function(interval, maxVelocity) {
if ( ! this . yFixed ) {
if ( ! this . yFixed ) {
var dy = this . damping * this . vy ; // damping force
var dy = this . damping * this . vy ; // damping force
var ay = ( this . fy - dy ) / this . mass ; // acceleration
var ay = ( this . fy - dy ) / this . options . mass ; // acceleration
this . vy += ay * interval ; // velocity
this . vy += ay * interval ; // velocity
this . vy = ( Math . abs ( this . vy ) > maxVelocity ) ? ( ( this . vy > 0 ) ? maxVelocity : - maxVelocity ) : this . vy ;
this . vy = ( Math . abs ( this . vy ) > maxVelocity ) ? ( ( this . vy > 0 ) ? maxVelocity : - maxVelocity ) : this . vy ;
this . y += this . vy * interval ; // position
this . y += this . vy * interval ; // position
@ -445,14 +429,14 @@ Node.prototype.getDistance = function(x, y) {
Node . prototype . setValueRange = function ( min , max ) {
Node . prototype . setValueRange = function ( min , max ) {
if ( ! this . radiusFixed && this . value !== undefined ) {
if ( ! this . radiusFixed && this . value !== undefined ) {
if ( max == min ) {
if ( max == min ) {
this . radius = ( this . radiusMin + this . radiusMax ) / 2 ;
this . options . radius = ( this . options . radiusMin + this . option s . radiusMax ) / 2 ;
}
}
else {
else {
var scale = ( this . radiusMax - this . radiusMin ) / ( max - min ) ;
this . radius = ( this . value - min ) * scale + this . radiusMin ;
var scale = ( this . options . radiusMax - this . option s . radiusMin ) / ( max - min ) ;
this . options . radius = ( this . value - min ) * scale + this . option s . radiusMin ;
}
}
}
}
this . baseRadiusValue = this . radius ;
this . baseRadiusValue = this . options . radius ;
} ;
} ;
/ * *
/ * *
@ -491,11 +475,11 @@ Node.prototype._resizeImage = function (ctx) {
if ( ! this . width || ! this . height ) { // undefined or 0
if ( ! this . width || ! this . height ) { // undefined or 0
var width , height ;
var width , height ;
if ( this . value ) {
if ( this . value ) {
this . radius = this . baseRadiusValue ;
this . options . radius = this . baseRadiusValue ;
var scale = this . imageObj . height / this . imageObj . width ;
var scale = this . imageObj . height / this . imageObj . width ;
if ( scale !== undefined ) {
if ( scale !== undefined ) {
width = this . radius || this . imageObj . width ;
height = this . radius * scale || this . imageObj . height ;
width = this . options . radius || this . imageObj . width ;
height = this . options . radius * scale || this . imageObj . height ;
}
}
else {
else {
width = 0 ;
width = 0 ;
@ -513,7 +497,7 @@ Node.prototype._resizeImage = function (ctx) {
if ( this . width > 0 && this . height > 0 ) {
if ( this . width > 0 && this . height > 0 ) {
this . width += Math . min ( this . clusterSize - 1 , this . maxNodeSizeIncrements ) * this . clusterSizeWidthFactor ;
this . width += Math . min ( this . clusterSize - 1 , this . maxNodeSizeIncrements ) * this . clusterSizeWidthFactor ;
this . height += Math . min ( this . clusterSize - 1 , this . maxNodeSizeIncrements ) * this . clusterSizeHeightFactor ;
this . height += Math . min ( this . clusterSize - 1 , this . maxNodeSizeIncrements ) * this . clusterSizeHeightFactor ;
this . radius += Math . min ( this . clusterSize - 1 , this . maxNodeSizeIncrements ) * this . clusterSizeRadiusFactor ;
this . options . radius += Math . min ( this . clusterSize - 1 , this . maxNodeSizeIncrements ) * this . clusterSizeRadiusFactor ;
this . growthIndicator = this . width - width ;
this . growthIndicator = this . width - width ;
}
}
}
}
@ -562,7 +546,7 @@ Node.prototype._resizeBox = function (ctx) {
this . width += Math . min ( this . clusterSize - 1 , this . maxNodeSizeIncrements ) * 0.5 * this . clusterSizeWidthFactor ;
this . width += Math . min ( this . clusterSize - 1 , this . maxNodeSizeIncrements ) * 0.5 * this . clusterSizeWidthFactor ;
this . height += Math . min ( this . clusterSize - 1 , this . maxNodeSizeIncrements ) * 0.5 * this . clusterSizeHeightFactor ;
this . height += Math . min ( this . clusterSize - 1 , this . maxNodeSizeIncrements ) * 0.5 * this . clusterSizeHeightFactor ;
this . growthIndicator = this . width - ( textSize . width + 2 * margin ) ;
this . growthIndicator = this . width - ( textSize . width + 2 * margin ) ;
// this.radius += Math.min(this.clusterSize - 1, this.maxNodeSizeIncrements) * 0.5 * this.clusterSizeRadiusFactor;
// this.options. radius+= Math.min(this.clusterSize - 1, this.maxNodeSizeIncrements) * 0.5 * this.clusterSizeRadiusFactor;
}
}
} ;
} ;
@ -574,10 +558,10 @@ Node.prototype._drawBox = function (ctx) {
this . top = this . y - this . height / 2 ;
this . top = this . y - this . height / 2 ;
var clusterLineWidth = 2.5 ;
var clusterLineWidth = 2.5 ;
var borderWidth = this . borderWidth ;
var selectionLineWidth = this . borderWidthSelected || 2 * this . borderWidth ;
var borderWidth = this . options . borderWidth ;
var selectionLineWidth = this . options . borderWidthSelected || 2 * this . option s . borderWidth ;
ctx . strokeStyle = this . selected ? this . color . highlight . border : this . hover ? this . color . hover . border : this . color . border ;
ctx . strokeStyle = this . selected ? this . options . color . highlight . border : this . hover ? this . options . color . hover . border : this . option s . color . border ;
// draw the outer border
// draw the outer border
if ( this . clusterSize > 1 ) {
if ( this . clusterSize > 1 ) {
@ -585,16 +569,16 @@ Node.prototype._drawBox = function (ctx) {
ctx . lineWidth *= this . networkScaleInv ;
ctx . lineWidth *= this . networkScaleInv ;
ctx . lineWidth = Math . min ( this . width , ctx . lineWidth ) ;
ctx . lineWidth = Math . min ( this . width , ctx . lineWidth ) ;
ctx . roundRect ( this . left - 2 * ctx . lineWidth , this . top - 2 * ctx . lineWidth , this . width + 4 * ctx . lineWidth , this . height + 4 * ctx . lineWidth , this . radius ) ;
ctx . roundRect ( this . left - 2 * ctx . lineWidth , this . top - 2 * ctx . lineWidth , this . width + 4 * ctx . lineWidth , this . height + 4 * ctx . lineWidth , this . options . radius ) ;
ctx . stroke ( ) ;
ctx . stroke ( ) ;
}
}
ctx . lineWidth = ( this . selected ? selectionLineWidth : borderWidth ) + ( ( this . clusterSize > 1 ) ? clusterLineWidth : 0.0 ) ;
ctx . lineWidth = ( this . selected ? selectionLineWidth : borderWidth ) + ( ( this . clusterSize > 1 ) ? clusterLineWidth : 0.0 ) ;
ctx . lineWidth *= this . networkScaleInv ;
ctx . lineWidth *= this . networkScaleInv ;
ctx . lineWidth = Math . min ( this . width , ctx . lineWidth ) ;
ctx . lineWidth = Math . min ( this . width , ctx . lineWidth ) ;
ctx . fillStyle = this . selected ? this . color . highlight . background : this . color . background ;
ctx . fillStyle = this . selected ? this . options . color . highlight . background : this . option s . color . background ;
ctx . roundRect ( this . left , this . top , this . width , this . height , this . radius ) ;
ctx . roundRect ( this . left , this . top , this . width , this . height , this . options . radius ) ;
ctx . fill ( ) ;
ctx . fill ( ) ;
ctx . stroke ( ) ;
ctx . stroke ( ) ;
@ -613,7 +597,7 @@ Node.prototype._resizeDatabase = function (ctx) {
// scaling used for clustering
// scaling used for clustering
this . width += Math . min ( this . clusterSize - 1 , this . maxNodeSizeIncrements ) * this . clusterSizeWidthFactor ;
this . width += Math . min ( this . clusterSize - 1 , this . maxNodeSizeIncrements ) * this . clusterSizeWidthFactor ;
this . height += Math . min ( this . clusterSize - 1 , this . maxNodeSizeIncrements ) * this . clusterSizeHeightFactor ;
this . height += Math . min ( this . clusterSize - 1 , this . maxNodeSizeIncrements ) * this . clusterSizeHeightFactor ;
this . radius += Math . min ( this . clusterSize - 1 , this . maxNodeSizeIncrements ) * this . clusterSizeRadiusFactor ;
this . options . radius += Math . min ( this . clusterSize - 1 , this . maxNodeSizeIncrements ) * this . clusterSizeRadiusFactor ;
this . growthIndicator = this . width - size ;
this . growthIndicator = this . width - size ;
}
}
} ;
} ;
@ -624,10 +608,10 @@ Node.prototype._drawDatabase = function (ctx) {
this . top = this . y - this . height / 2 ;
this . top = this . y - this . height / 2 ;
var clusterLineWidth = 2.5 ;
var clusterLineWidth = 2.5 ;
var borderWidth = this . borderWidth ;
var selectionLineWidth = this . borderWidthSelected || 2 * this . borderWidth ;
var borderWidth = this . options . borderWidth ;
var selectionLineWidth = this . options . borderWidthSelected || 2 * this . option s . borderWidth ;
ctx . strokeStyle = this . selected ? this . color . highlight . border : this . hover ? this . color . hover . border : this . color . border ;
ctx . strokeStyle = this . selected ? this . options . color . highlight . border : this . hover ? this . options . color . hover . border : this . option s . color . border ;
// draw the outer border
// draw the outer border
if ( this . clusterSize > 1 ) {
if ( this . clusterSize > 1 ) {
@ -642,7 +626,7 @@ Node.prototype._drawDatabase = function (ctx) {
ctx . lineWidth *= this . networkScaleInv ;
ctx . lineWidth *= this . networkScaleInv ;
ctx . lineWidth = Math . min ( this . width , ctx . lineWidth ) ;
ctx . lineWidth = Math . min ( this . width , ctx . lineWidth ) ;
ctx . fillStyle = this . selected ? this . color . highlight . background : this . hover ? this . color . hover . background : this . color . background ;
ctx . fillStyle = this . selected ? this . options . color . highlight . background : this . hover ? this . options . color . hover . background : this . option s . color . background ;
ctx . database ( this . x - this . width / 2 , this . y - this . height * 0.5 , this . width , this . height ) ;
ctx . database ( this . x - this . width / 2 , this . y - this . height * 0.5 , this . width , this . height ) ;
ctx . fill ( ) ;
ctx . fill ( ) ;
ctx . stroke ( ) ;
ctx . stroke ( ) ;
@ -656,7 +640,7 @@ Node.prototype._resizeCircle = function (ctx) {
var margin = 5 ;
var margin = 5 ;
var textSize = this . getTextSize ( ctx ) ;
var textSize = this . getTextSize ( ctx ) ;
var diameter = Math . max ( textSize . width , textSize . height ) + 2 * margin ;
var diameter = Math . max ( textSize . width , textSize . height ) + 2 * margin ;
this . radius = diameter / 2 ;
this . options . radius = diameter / 2 ;
this . width = diameter ;
this . width = diameter ;
this . height = diameter ;
this . height = diameter ;
@ -664,8 +648,8 @@ Node.prototype._resizeCircle = function (ctx) {
// scaling used for clustering
// scaling used for clustering
// this.width += Math.min(this.clusterSize - 1, this.maxNodeSizeIncrements) * 0.5 * this.clusterSizeWidthFactor;
// this.width += Math.min(this.clusterSize - 1, this.maxNodeSizeIncrements) * 0.5 * this.clusterSizeWidthFactor;
// this.height += Math.min(this.clusterSize - 1, this.maxNodeSizeIncrements) * 0.5 * this.clusterSizeHeightFactor;
// this.height += Math.min(this.clusterSize - 1, this.maxNodeSizeIncrements) * 0.5 * this.clusterSizeHeightFactor;
this . radius += Math . min ( this . clusterSize - 1 , this . maxNodeSizeIncrements ) * 0.5 * this . clusterSizeRadiusFactor ;
this . growthIndicator = this . radius - 0.5 * diameter ;
this . options . radius += Math . min ( this . clusterSize - 1 , this . maxNodeSizeIncrements ) * 0.5 * this . clusterSizeRadiusFactor ;
this . growthIndicator = this . options . radius - 0.5 * diameter ;
}
}
} ;
} ;
@ -675,10 +659,10 @@ Node.prototype._drawCircle = function (ctx) {
this . top = this . y - this . height / 2 ;
this . top = this . y - this . height / 2 ;
var clusterLineWidth = 2.5 ;
var clusterLineWidth = 2.5 ;
var borderWidth = this . borderWidth ;
var selectionLineWidth = this . borderWidthSelected || 2 * this . borderWidth ;
var borderWidth = this . options . borderWidth ;
var selectionLineWidth = this . options . borderWidthSelected || 2 * this . option s . borderWidth ;
ctx . strokeStyle = this . selected ? this . color . highlight . border : this . hover ? this . color . hover . border : this . color . border ;
ctx . strokeStyle = this . selected ? this . options . color . highlight . border : this . hover ? this . options . color . hover . border : this . option s . color . border ;
// draw the outer border
// draw the outer border
if ( this . clusterSize > 1 ) {
if ( this . clusterSize > 1 ) {
@ -686,15 +670,15 @@ Node.prototype._drawCircle = function (ctx) {
ctx . lineWidth *= this . networkScaleInv ;
ctx . lineWidth *= this . networkScaleInv ;
ctx . lineWidth = Math . min ( this . width , ctx . lineWidth ) ;
ctx . lineWidth = Math . min ( this . width , ctx . lineWidth ) ;
ctx . circle ( this . x , this . y , this . radius + 2 * ctx . lineWidth ) ;
ctx . circle ( this . x , this . y , this . options . radius + 2 * ctx . lineWidth ) ;
ctx . stroke ( ) ;
ctx . stroke ( ) ;
}
}
ctx . lineWidth = ( this . selected ? selectionLineWidth : borderWidth ) + ( ( this . clusterSize > 1 ) ? clusterLineWidth : 0.0 ) ;
ctx . lineWidth = ( this . selected ? selectionLineWidth : borderWidth ) + ( ( this . clusterSize > 1 ) ? clusterLineWidth : 0.0 ) ;
ctx . lineWidth *= this . networkScaleInv ;
ctx . lineWidth *= this . networkScaleInv ;
ctx . lineWidth = Math . min ( this . width , ctx . lineWidth ) ;
ctx . lineWidth = Math . min ( this . width , ctx . lineWidth ) ;
ctx . fillStyle = this . selected ? this . color . highlight . background : this . hover ? this . color . hover . background : this . color . background ;
ctx . circle ( this . x , this . y , this . radius ) ;
ctx . fillStyle = this . selected ? this . options . color . highlight . background : this . hover ? this . options . color . hover . background : this . option s . color . background ;
ctx . circle ( this . x , this . y , this . options . radius ) ;
ctx . fill ( ) ;
ctx . fill ( ) ;
ctx . stroke ( ) ;
ctx . stroke ( ) ;
@ -715,7 +699,7 @@ Node.prototype._resizeEllipse = function (ctx) {
// scaling used for clustering
// scaling used for clustering
this . width += Math . min ( this . clusterSize - 1 , this . maxNodeSizeIncrements ) * this . clusterSizeWidthFactor ;
this . width += Math . min ( this . clusterSize - 1 , this . maxNodeSizeIncrements ) * this . clusterSizeWidthFactor ;
this . height += Math . min ( this . clusterSize - 1 , this . maxNodeSizeIncrements ) * this . clusterSizeHeightFactor ;
this . height += Math . min ( this . clusterSize - 1 , this . maxNodeSizeIncrements ) * this . clusterSizeHeightFactor ;
this . radius += Math . min ( this . clusterSize - 1 , this . maxNodeSizeIncrements ) * this . clusterSizeRadiusFactor ;
this . options . radius += Math . min ( this . clusterSize - 1 , this . maxNodeSizeIncrements ) * this . clusterSizeRadiusFactor ;
this . growthIndicator = this . width - defaultSize ;
this . growthIndicator = this . width - defaultSize ;
}
}
} ;
} ;
@ -726,10 +710,10 @@ Node.prototype._drawEllipse = function (ctx) {
this . top = this . y - this . height / 2 ;
this . top = this . y - this . height / 2 ;
var clusterLineWidth = 2.5 ;
var clusterLineWidth = 2.5 ;
var borderWidth = this . borderWidth ;
var selectionLineWidth = this . borderWidthSelected || 2 * this . borderWidth ;
var borderWidth = this . options . borderWidth ;
var selectionLineWidth = this . options . borderWidthSelected || 2 * this . option s . borderWidth ;
ctx . strokeStyle = this . selected ? this . color . highlight . border : this . hover ? this . color . hover . border : this . color . border ;
ctx . strokeStyle = this . selected ? this . options . color . highlight . border : this . hover ? this . options . color . hover . border : this . option s . color . border ;
// draw the outer border
// draw the outer border
if ( this . clusterSize > 1 ) {
if ( this . clusterSize > 1 ) {
@ -744,7 +728,7 @@ Node.prototype._drawEllipse = function (ctx) {
ctx . lineWidth *= this . networkScaleInv ;
ctx . lineWidth *= this . networkScaleInv ;
ctx . lineWidth = Math . min ( this . width , ctx . lineWidth ) ;
ctx . lineWidth = Math . min ( this . width , ctx . lineWidth ) ;
ctx . fillStyle = this . selected ? this . color . highlight . background : this . hover ? this . color . hover . background : this . color . background ;
ctx . fillStyle = this . selected ? this . options . color . highlight . background : this . hover ? this . options . color . hover . background : this . option s . color . background ;
ctx . ellipse ( this . left , this . top , this . width , this . height ) ;
ctx . ellipse ( this . left , this . top , this . width , this . height ) ;
ctx . fill ( ) ;
ctx . fill ( ) ;
@ -774,15 +758,15 @@ Node.prototype._drawStar = function (ctx) {
Node . prototype . _resizeShape = function ( ctx ) {
Node . prototype . _resizeShape = function ( ctx ) {
if ( ! this . width ) {
if ( ! this . width ) {
this . radius = this . baseRadiusValue ;
var size = 2 * this . radius ;
this . options . radius = this . baseRadiusValue ;
var size = 2 * this . options . radius ;
this . width = size ;
this . width = size ;
this . height = size ;
this . height = size ;
// scaling used for clustering
// scaling used for clustering
this . width += Math . min ( this . clusterSize - 1 , this . maxNodeSizeIncrements ) * this . clusterSizeWidthFactor ;
this . width += Math . min ( this . clusterSize - 1 , this . maxNodeSizeIncrements ) * this . clusterSizeWidthFactor ;
this . height += Math . min ( this . clusterSize - 1 , this . maxNodeSizeIncrements ) * this . clusterSizeHeightFactor ;
this . height += Math . min ( this . clusterSize - 1 , this . maxNodeSizeIncrements ) * this . clusterSizeHeightFactor ;
this . radius += Math . min ( this . clusterSize - 1 , this . maxNodeSizeIncrements ) * 0.5 * this . clusterSizeRadiusFactor ;
this . options . radius += Math . min ( this . clusterSize - 1 , this . maxNodeSizeIncrements ) * 0.5 * this . clusterSizeRadiusFactor ;
this . growthIndicator = this . width - size ;
this . growthIndicator = this . width - size ;
}
}
} ;
} ;
@ -794,8 +778,8 @@ Node.prototype._drawShape = function (ctx, shape) {
this . top = this . y - this . height / 2 ;
this . top = this . y - this . height / 2 ;
var clusterLineWidth = 2.5 ;
var clusterLineWidth = 2.5 ;
var borderWidth = this . borderWidth ;
var selectionLineWidth = this . borderWidthSelected || 2 * this . borderWidth ;
var borderWidth = this . options . borderWidth ;
var selectionLineWidth = this . options . borderWidthSelected || 2 * this . option s . borderWidth ;
var radiusMultiplier = 2 ;
var radiusMultiplier = 2 ;
// choose draw method depending on the shape
// choose draw method depending on the shape
@ -807,23 +791,22 @@ Node.prototype._drawShape = function (ctx, shape) {
case 'star' : radiusMultiplier = 4 ; break ;
case 'star' : radiusMultiplier = 4 ; break ;
}
}
ctx . strokeStyle = this . selected ? this . color . highlight . border : this . hover ? this . color . hover . border : this . color . border ;
ctx . strokeStyle = this . selected ? this . options . color . highlight . border : this . hover ? this . options . color . hover . border : this . options . color . border ;
// draw the outer border
// draw the outer border
if ( this . clusterSize > 1 ) {
if ( this . clusterSize > 1 ) {
ctx . lineWidth = ( this . selected ? selectionLineWidth : borderWidth ) + ( ( this . clusterSize > 1 ) ? clusterLineWidth : 0.0 ) ;
ctx . lineWidth = ( this . selected ? selectionLineWidth : borderWidth ) + ( ( this . clusterSize > 1 ) ? clusterLineWidth : 0.0 ) ;
ctx . lineWidth *= this . networkScaleInv ;
ctx . lineWidth *= this . networkScaleInv ;
ctx . lineWidth = Math . min ( this . width , ctx . lineWidth ) ;
ctx . lineWidth = Math . min ( this . width , ctx . lineWidth ) ;
ctx [ shape ] ( this . x , this . y , this . radius + radiusMultiplier * ctx . lineWidth ) ;
ctx [ shape ] ( this . x , this . y , this . options . radius + radiusMultiplier * ctx . lineWidth ) ;
ctx . stroke ( ) ;
ctx . stroke ( ) ;
}
}
ctx . lineWidth = ( this . selected ? selectionLineWidth : borderWidth ) + ( ( this . clusterSize > 1 ) ? clusterLineWidth : 0.0 ) ;
ctx . lineWidth = ( this . selected ? selectionLineWidth : borderWidth ) + ( ( this . clusterSize > 1 ) ? clusterLineWidth : 0.0 ) ;
ctx . lineWidth *= this . networkScaleInv ;
ctx . lineWidth *= this . networkScaleInv ;
ctx . lineWidth = Math . min ( this . width , ctx . lineWidth ) ;
ctx . lineWidth = Math . min ( this . width , ctx . lineWidth ) ;
ctx . fillStyle = this . selected ? this . color . highlight . background : this . hover ? this . color . hover . background : this . color . background ;
ctx [ shape ] ( this . x , this . y , this . radius ) ;
ctx . fillStyle = this . selected ? this . options . color . highlight . background : this . hover ? this . options . color . hover . background : this . option s . color . background ;
ctx [ shape ] ( this . x , this . y , this . options . radius ) ;
ctx . fill ( ) ;
ctx . fill ( ) ;
ctx . stroke ( ) ;
ctx . stroke ( ) ;
@ -842,7 +825,7 @@ Node.prototype._resizeText = function (ctx) {
// scaling used for clustering
// scaling used for clustering
this . width += Math . min ( this . clusterSize - 1 , this . maxNodeSizeIncrements ) * this . clusterSizeWidthFactor ;
this . width += Math . min ( this . clusterSize - 1 , this . maxNodeSizeIncrements ) * this . clusterSizeWidthFactor ;
this . height += Math . min ( this . clusterSize - 1 , this . maxNodeSizeIncrements ) * this . clusterSizeHeightFactor ;
this . height += Math . min ( this . clusterSize - 1 , this . maxNodeSizeIncrements ) * this . clusterSizeHeightFactor ;
this . radius += Math . min ( this . clusterSize - 1 , this . maxNodeSizeIncrements ) * this . clusterSizeRadiusFactor ;
this . options . radius += Math . min ( this . clusterSize - 1 , this . maxNodeSizeIncrements ) * this . clusterSizeRadiusFactor ;
this . growthIndicator = this . width - ( textSize . width + 2 * margin ) ;
this . growthIndicator = this . width - ( textSize . width + 2 * margin ) ;
}
}
} ;
} ;
@ -857,15 +840,15 @@ Node.prototype._drawText = function (ctx) {
Node . prototype . _label = function ( ctx , text , x , y , align , baseline , labelUnderNode ) {
Node . prototype . _label = function ( ctx , text , x , y , align , baseline , labelUnderNode ) {
if ( text && this . fontSize * this . networkScale > this . fontDrawThreshold ) {
ctx . font = ( this . selected ? "bold " : "" ) + this . fontSize + "px " + this . fontFace ;
ctx . fillStyle = this . fontColor || "black" ;
if ( text && Number ( this . options . fontSize ) * this . networkScale > this . fontDrawThreshold ) {
ctx . font = ( this . selected ? "bold " : "" ) + this . options . fontSize + "px " + this . option s . fontFace ;
ctx . fillStyle = this . options . fontColor || "black" ;
ctx . textAlign = align || "center" ;
ctx . textAlign = align || "center" ;
ctx . textBaseline = baseline || "middle" ;
ctx . textBaseline = baseline || "middle" ;
var lines = text . split ( '\n' ) ;
var lines = text . split ( '\n' ) ;
var lineCount = lines . length ;
var lineCount = lines . length ;
var fontSize = ( this . fontSize + 4 ) ;
var fontSize = ( Number ( this . options . fontSize ) + 4 ) ;
var yLine = y + ( 1 - lineCount ) / 2 * fontSize ;
var yLine = y + ( 1 - lineCount ) / 2 * fontSize ;
if ( labelUnderNode == true ) {
if ( labelUnderNode == true ) {
yLine = y + ( 1 - lineCount ) / ( 2 * fontSize ) ;
yLine = y + ( 1 - lineCount ) / ( 2 * fontSize ) ;
@ -881,10 +864,10 @@ Node.prototype._label = function (ctx, text, x, y, align, baseline, labelUnderNo
Node . prototype . getTextSize = function ( ctx ) {
Node . prototype . getTextSize = function ( ctx ) {
if ( this . label !== undefined ) {
if ( this . label !== undefined ) {
ctx . font = ( this . selected ? "bold " : "" ) + this . fontSize + "px " + this . fontFace ;
ctx . font = ( this . selected ? "bold " : "" ) + this . options . fontSize + "px " + this . option s . fontFace ;
var lines = this . label . split ( '\n' ) ,
var lines = this . label . split ( '\n' ) ,
height = ( this . fontSize + 4 ) * lines . length ,
height = ( Number ( this . options . fontSize ) + 4 ) * lines . length ,
width = 0 ;
width = 0 ;
for ( var i = 0 , iMax = lines . length ; i < iMax ; i ++ ) {
for ( var i = 0 , iMax = lines . length ; i < iMax ; i ++ ) {
@ -971,11 +954,11 @@ Node.prototype.clearVelocity = function() {
* /
* /
Node . prototype . updateVelocity = function ( massBeforeClustering ) {
Node . prototype . updateVelocity = function ( massBeforeClustering ) {
var energyBefore = this . vx * this . vx * massBeforeClustering ;
var energyBefore = this . vx * this . vx * massBeforeClustering ;
//this.vx = (this.vx < 0) ? -Math.sqrt(energyBefore/this.mass) : Math.sqrt(energyBefore/this.mass);
this . vx = Math . sqrt ( energyBefore / this . mass ) ;
//this.vx = (this.vx < 0) ? -Math.sqrt(energyBefore/this.options. mass) : Math.sqrt(energyBefore/this.option s.mass);
this . vx = Math . sqrt ( energyBefore / this . options . mass ) ;
energyBefore = this . vy * this . vy * massBeforeClustering ;
energyBefore = this . vy * this . vy * massBeforeClustering ;
//this.vy = (this.vy < 0) ? -Math.sqrt(energyBefore/this.mass) : Math.sqrt(energyBefore/this.mass);
this . vy = Math . sqrt ( energyBefore / this . mass ) ;
//this.vy = (this.vy < 0) ? -Math.sqrt(energyBefore/this.options. mass) : Math.sqrt(energyBefore/this.option s.mass);
this . vy = Math . sqrt ( energyBefore / this . options . mass ) ;
} ;
} ;
module . exports = Node ;
module . exports = Node ;