|
|
@ -59,8 +59,8 @@ class Node { |
|
|
|
this.grouplist = grouplist; |
|
|
|
|
|
|
|
// state options
|
|
|
|
this.x = undefined; |
|
|
|
this.y = undefined; |
|
|
|
this._x = undefined; |
|
|
|
this._y = undefined; |
|
|
|
this.baseSize = this.options.size; |
|
|
|
this.baseFontSize = this.options.font.size; |
|
|
|
this.predefinedPosition = false; // used to check if initial fit should just take the range or approximate
|
|
|
@ -71,6 +71,39 @@ class Node { |
|
|
|
this.setOptions(options); |
|
|
|
} |
|
|
|
|
|
|
|
get x() { |
|
|
|
return this._x; |
|
|
|
} |
|
|
|
|
|
|
|
set x(newX) { |
|
|
|
this._x = newX; |
|
|
|
this.body.emitter.emit('_positionUpdate', {id: this.id, x: this._x, y: this._y}); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Non emitting version for use by physics engine so we don't create infinite loops. |
|
|
|
* @param newX |
|
|
|
*/ |
|
|
|
setX(newX) { |
|
|
|
this._x = newX; |
|
|
|
} |
|
|
|
|
|
|
|
get y() { |
|
|
|
return this._y; |
|
|
|
} |
|
|
|
|
|
|
|
set y(newY) { |
|
|
|
this._y = newY; |
|
|
|
this.body.emitter.emit('_positionUpdate', {id: this.id, x: this._x, y: this._y}); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Non emitting version for use by physics engine so we don't create infinite loops. |
|
|
|
* @param newY |
|
|
|
*/ |
|
|
|
setY(newY) { |
|
|
|
this._y = newY; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Attach a edge to the node |
|
|
@ -136,7 +169,7 @@ class Node { |
|
|
|
} |
|
|
|
|
|
|
|
// this transforms all shorthands into fully defined options
|
|
|
|
Node.parseOptions(this.options, options, true, this.globalOptions); |
|
|
|
this.parseOptions(this.options, options, true, this.globalOptions); |
|
|
|
|
|
|
|
// load the images
|
|
|
|
if (this.options.image !== undefined) { |
|
|
@ -151,8 +184,16 @@ class Node { |
|
|
|
this.updateLabelModule(); |
|
|
|
this.updateShape(currentShape); |
|
|
|
|
|
|
|
if (options.mass !== undefined) { |
|
|
|
this.options.mass = options.mass; |
|
|
|
this.body.emitter.emit('_physicsUpdate', {id: this.id, options: {mass: options.mass}}); |
|
|
|
} |
|
|
|
if (options.physics !== undefined) { |
|
|
|
this.options.physics = options.physics; |
|
|
|
this.body.emitter.emit('_physicsUpdate', {id: this.id, options: {physics: options.physics}}); |
|
|
|
} |
|
|
|
|
|
|
|
if (options.hidden !== undefined || options.physics !== undefined) { |
|
|
|
if (options.hidden !== undefined) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
return false; |
|
|
@ -165,7 +206,7 @@ class Node { |
|
|
|
* @param parentOptions |
|
|
|
* @param newOptions |
|
|
|
*/ |
|
|
|
static parseOptions(parentOptions, newOptions, allowDeletion = false, globalOptions = {}) { |
|
|
|
parseOptions(parentOptions, newOptions, allowDeletion = false, globalOptions = {}) { |
|
|
|
var fields = [ |
|
|
|
'color', |
|
|
|
'font', |
|
|
@ -189,15 +230,26 @@ class Node { |
|
|
|
// handle the fixed options
|
|
|
|
if (newOptions.fixed !== undefined && newOptions.fixed !== null) { |
|
|
|
if (typeof newOptions.fixed === 'boolean') { |
|
|
|
parentOptions.fixed.x = newOptions.fixed; |
|
|
|
parentOptions.fixed.y = newOptions.fixed; |
|
|
|
if (parentOptions.fixed.x !== newOptions.fixed || parentOptions.fixed.y !== newOptions.fixed) { |
|
|
|
parentOptions.fixed.x = newOptions.fixed; |
|
|
|
parentOptions.fixed.y = newOptions.fixed; |
|
|
|
this.body.emitter.emit('_physicsUpdate', {id: this.id, options: {fixed: {x: newOptions.fixed, y: newOptions.fixed}}}); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
if (newOptions.fixed.x !== undefined && typeof newOptions.fixed.x === 'boolean') { |
|
|
|
if (newOptions.fixed.x !== undefined && |
|
|
|
typeof newOptions.fixed.x === 'boolean' && |
|
|
|
parentOptions.fixed.x !== newOptions.fixed.x) |
|
|
|
{ |
|
|
|
parentOptions.fixed.x = newOptions.fixed.x; |
|
|
|
this.body.emitter.emit('_physicsUpdate', {id: this.id, options: {fixed: {x: newOptions.fixed.x}}}); |
|
|
|
} |
|
|
|
if (newOptions.fixed.y !== undefined && typeof newOptions.fixed.y === 'boolean') { |
|
|
|
if (newOptions.fixed.y !== undefined && |
|
|
|
typeof newOptions.fixed.y === 'boolean' && |
|
|
|
parentOptions.fixed.y !== newOptions.fixed.y) |
|
|
|
{ |
|
|
|
parentOptions.fixed.y = newOptions.fixed.y; |
|
|
|
this.body.emitter.emit('_physicsUpdate', {id: this.id, options: {fixed: {y: newOptions.fixed.y}}}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|