FlowViz

SetFvRef

method
module.exports.SetFvRef()

Option name Type Description
flowviz FlowViz The main FlowViz object

Sets this module's static reference to the main FlowViz object

module.exports.SetFvRef = function(flowviz) {
    fv = flowviz;
};

FlowNode

function
FlowNode()

Option name Type Description
nodeType NodeType The type of graph node that this node represents.
x Number The initial X position of this node in the visualization.
y Number The initial Y position of this node in the visualization.

Defines the FlowNode type. This type encapsulates nodes in the FlowViz graph

function FlowNode(nodeType, x, y) {
    this.id = "node-" + id_count;
    id_count += 1;

    this.type = nodeType;

    this.x = x;
    this.y = y;

    // Manage additional data items which can be attached to this node
    this.DataItems = this.type.GetDataObject();
}

FlowNode.prototype.getJSON = function() {
    return {
        "id": this.id,
        "type-id": this.type.id,
        "x": this.x,
        "y": this.y,
        "data": this.DataItems
    };
};

FlowNode.prototype.getEdges = function() {
    var myEdges = [];

    var that = this;
    _.forEach(fv.GraphManager.edges, function(edge) {
        if(edge.start === that || edge.end === that) {
            myEdges.push(edge);
        }
    });

    return myEdges;
};

FlowNode.prototype.getOutgoingEdges = function() {
    var myEdges = [];

    var that = this;
    _.forEach(fv.GraphManager.edges, function(edge) {
        if(edge.start === that) {
            myEdges.push(edge);
        }
    });

    return myEdges;
};

FlowNode.prototype.getIncomingEdges = function() {
    var myEdges = [];

    var that = this;
    _.forEach(fv.GraphManager.edges, function(edge) {
        if(edge.end === that) {
            myEdges.push(edge);
        }
    });

    return myEdges;
};

SetDataItem

method
FlowNode.prototype.SetDataItem()

Option name Type Description
key String The data item's key
value Object The data item's value

Sets a data item with the given key to the given value

FlowNode.prototype.SetDataItem = function(key, value) {
    if(this.DataItems.hasOwnProperty(key)) {
        var item = this.DataItems[key];

        // Basic validation
        if(typeof value !== item.type) {
            console.error("\"" + key + "\" can only be set with values of type \"" + item.type + "\"");
            return false;
        }

        var old = item.value;

        // Advanced validation
        if(item.hasOwnProperty("validator")) {
            var name = item.validator;

            if (!fv.App.Validate(name, old, value)) {

                var invalid = value + " is not a valid value for \"" + key + "\".";
                var issue = " It violates validator \"" + name + "\"";
                console.error(invalid + issue);

                return false;
            }
        }

        item.value = value;

        fv.emit('node-data-changed', this, item, old);

        return true;
    } else {
        console.error("The \"" + this.type.name + "\" NodeType does not have a data item with the key \"" + key + "\"!");
        return false;
    }
};

FlowNode.prototype.GetDataItemValue = function(key) {
    if (this.DataItems.hasOwnProperty(key)) {
        return this.DataItems[key].value;
    }
    return null;
};