diff --git a/lib/graph.js b/lib/graph.js index 65f90282..2eebf919 100644 --- a/lib/graph.js +++ b/lib/graph.js @@ -304,14 +304,9 @@ Graph.prototype.setPath = function(vs, value) { * setEdge(v, w, [value, [name]]) * setEdge({ v, w, [name] }, [value]) */ -Graph.prototype.setEdge = function(v, w, value, name) { - var valueSpecified = arguments.length > 2; - - v = String(v); - w = String(w); - if (!_.isUndefined(name)) { - name = String(name); - } +Graph.prototype.setEdge = function() { + var v, w, name, value, + valueSpecified = false; if (_.isPlainObject(arguments[0])) { v = arguments[0].v; @@ -321,6 +316,20 @@ Graph.prototype.setEdge = function(v, w, value, name) { value = arguments[1]; valueSpecified = true; } + } else { + v = arguments[0]; + w = arguments[1]; + name = arguments[3]; + if (arguments.length > 2) { + value = arguments[2]; + valueSpecified = true; + } + } + + v = "" + v; + w = "" + w; + if (!_.isUndefined(name)) { + name = "" + name; } var e = edgeArgsToId(this._isDirected, v, w, name);