Gets an invisible dummy node
module.exports.GetDummy = function() {
var dummy = new NodeType(module.exports.DUMMY, "Dummy Node", "This is an invisible dummy node", null);
dummy.hasOffsetEdge = false;
dummy.hasPaddedEdge = false;
dummy.padding = 0;
dummy.width = 0;
dummy.height = 0;
dummy.scale = 1.0;
return dummy;
};
Option name | Type | Description |
---|---|---|
type | String | The name of this type (e.g. 'IfElseBranch') |
name | String | The display friendly name of this type (e.g. 'If ... Else ...') |
desc | String | This is a brief description of what this nodes of this type are for |
svg | Fragment | This is a document fragment of svg which is the visual representation of nodes of this type |
This class is responsible for managing the type information for possible nodes in the graph.
TODO: Add the means for tracking/accessing parent and children types
function NodeType(type, name, desc, svg) {
this.id = "type-" + id_count;
id_count += 1;
this.type = type;
this.name = name;
this.desc = desc;
this.hasOffsetEdge = false;
this.hasPaddedEdge = false;
// Default display parameters
this.padding = 0;
this.width = 0;
this.height = 0;
this.scale = 1.0;
// Default type hierarchy relationships
this.Parent = null;
this.Children = null;
this.DataProperties = null;
this.Connections = null;
this.Constraints = null;
if(_.includes(svg, "<svg") || _.includes(svg, "<xml")) {
this._svg = svg;
this._file = null;
} else {
this._svg = null;
this._file = svg;
}
}
NodeType.prototype.getJSON = function() {
return {
"id": this.id,
"type": this.type
};
};
NodeType.prototype.GetEdgeOffset = function(connType) {
if(this.hasOffsetEdge) {
if(connType !== undefined && this.Connections !== null) {
if(this.Connections.hasOwnProperty(connType)) {
return {
x: this.Connections[connType].x * this.scale,
y: this.Connections[connType].y * this.scale
}
}
}
return {
x: this.scale * this.width / 2,
y: this.scale * this.height / 2
}
}
return {
x: 0,
y: 0
};
};
NodeType.prototype.GetEdgePadding = function(connType) {
if(this.hasPaddedEdge) {
return this.padding;
}
return 0;
};
Option name | Type | Description |
---|---|---|
width | number | The width in pixels |
Sets the width in pixels of this type of node
NodeType.prototype.SetWidth = function(width) {
this.width = width;
};
Option name | Type | Description |
---|---|---|
height | number | The height in pixels |
Sets the height in pixels of this type of node
NodeType.prototype.SetHeight = function(height) {
this.height = height;
};
Option name | Type | Description |
---|---|---|
scale | number | A percentage between 0.0 and 1.0 |
Sets the percentage (0.0 to 1.0) by which the view for this node type should be scaled when added to the interface
NodeType.prototype.SetScale = function(scale) {
if(scale > 1.0 || scale < 0.0) scale = 1.0;
this.scale = scale;
};
Option name | Type | Description |
---|---|---|
json | number | JSON object describing the data properties for this type of node. |
Sets the data properties object for this type of node. This is derived from the config object.
NodeType.prototype.SetProperties = function(json) {
this.DataProperties = json;
};
NodeType.prototype.SetPadding = function(padding) {
if(padding > 0) {
this.hasPaddedEdge = true;
this.padding = padding;
} else {
this.hasPaddedEdge = false;
this.padding = 0;
}
};
NodeType.prototype.SetConnections = function(connections) {
if(connections !== null) {
this.hasOffsetEdge = true;
if(connections === "default") {
this.Connections = null;
} else {
this.Connections = connections;
}
} else {
this.hasOffsetEdge = false;
this.Connections = null;
}
};
Option name | Type | Description |
---|---|---|
json | number | JSON object describing the constraints for this type of node. |
Sets the node constraints object for this type of node. This is derived from the config object.
NodeType.prototype.SetConstraints = function(json) {
this.Constraints = json;
};
Option name | Type | Description |
---|---|---|
parent | number | A reference to the parent NodeType object |
Sets the parent node type for this type of node. This is derived from the type hierarchy in the config object.
NodeType.prototype.SetParent = function(parent) {
this.Parent = parent;
};
Option name | Type | Description |
---|---|---|
children | number | An array with references to the children NodeType objects |
Sets the children node types of this type of node. This is derived from the type hierarchy in the config object.
NodeType.prototype.SetChildren = function(children) {
this.Children = children;
};
Indicates if this type has a parent NodeType
NodeType.prototype.HasParent = function() {
return (this.Parent !== null);
};
If this NodeType has a parent NodeType, this wil return the parent.
NodeType.prototype.GetParent = function() {
return this.Parent;
};
Indicates if this type has any children NodeTypes
NodeType.prototype.HasChildren = function() {
return (this.Children !== null);
};
If this NodeType has child NodeTypes, this wil return the children.
NodeType.prototype.GetChildren = function() {
return this.Children;
};
Gets a clone of the DataProperties object which can be populated with data by the FlowNode object
NodeType.prototype.GetDataObject = function() {
var obj = $.extend(true, {}, this.DataProperties, null);
return obj;
};
Gets a clone of the Constraints object which can be used by the FlowNode object
NodeType.prototype.GetConstraintObject = function() {
return $.extend(true, {}, this.Constraints, null);
};
Option name | Type | Description |
---|---|---|
view | String | The view property from the config json file. Either contains a path to an svg file, or inline svg code. |
Gets an svg document fragment from the view string.
function GetFragment(view) {
var frag = Snap.parse(view);
var g = frag.select('g');
g.attr('class', 'node-svg');
return g;
}
This function returns the entirety of the SVG document provided in the config JSON file
NodeType.prototype.getRawSvg = function() {
return Snap.parse(this._svg);
};
Returns a group containing the svg for the a node of this type.
NodeType.prototype.getSvg = function() {
return GetFragment(this._svg);
};