/** * This is base arc. * * */ function BaseEdge(vertex1, vertex2, isDirect, weight, useWeight) { this.vertex1 = vertex1; this.vertex2 = vertex2; this.arrayStyleStart = ""; this.arrayStyleFinish = ""; this.isDirect = isDirect; this.weight = Number(weight); this.text = ""; // For direct graph, has pair edge or not. this.hasPair = false; this.useWeight = useWeight; this.id = 0; this.model = new EdgeModel(); } BaseEdge.prototype.SaveToXML = function () { return ""; } BaseEdge.prototype.LoadFromXML = function (xml, graph) { var attr = xml.attr('vertex1'); this.vertex1 = graph.FindVertex(parseInt(typeof attr !== 'undefined' ? attr : xml.attr('graph1'))); var attr = xml.attr('vertex2'); this.vertex2 = graph.FindVertex(parseInt(typeof attr !== 'undefined' ? attr : xml.attr('graph2'))); this.isDirect = xml.attr('isDirect') == "true"; this.weight = parseFloat(xml.attr('weight')); this.hasPair = xml.attr('hasPair') == "true"; this.useWeight = xml.attr('useWeight') == "true"; this.id = parseInt(xml.attr('id')); this.text = xml.attr("text") == null ? "" : xml.attr("text"); this.arrayStyleStart = xml.attr("arrayStyleStart") == null ? "" : xml.attr("arrayStyleStart"); this.arrayStyleFinish = xml.attr("arrayStyleFinish") == null ? "" : xml.attr("arrayStyleFinish"); } BaseEdge.prototype.GetPixelLength = function () { if (this.vertex1 == this.vertex2) { return (new CommonEdgeStyle()).sizeOfLoop * 2 * Math.PI; } else { return Point.distance(this.vertex1.position, this.vertex2.position); } } BaseEdge.prototype.GetWeight = function () { return this.useWeight ? this.weight : 1; } BaseEdge.prototype.GetText = function () { return this.text.length > 0 ? this.text : (this.useWeight ? this.weight.toString() : ""); } BaseEdge.prototype.GetStartEdgeStyle = function () { return this.arrayStyleStart; } BaseEdge.prototype.GetFinishEdgeStyle = function () { return (this.arrayStyleFinish != "" ? this.arrayStyleFinish : (this.isDirect ? "arrow" : "")); }