mirror of
https://github.com/UnickSoft/graphonline.git
synced 2026-06-16 13:51:34 +00:00
Fix edges direction field for xml export.
This commit is contained in:
@@ -54,7 +54,7 @@ BaseEdge.prototype.SaveToXML = function ()
|
||||
return "<edge " +
|
||||
"source=\"" + this.vertex1.id + "\" " +
|
||||
"target=\"" + this.vertex2.id + "\" " +
|
||||
"isDirect=\"" + this.isDirect + "\" " +
|
||||
"directed=\"" + this.isDirect + "\" " +
|
||||
"weight=\"" + this.weight + "\" " +
|
||||
"useWeight=\"" + this.useWeight + "\" " +
|
||||
"id=\"" + this.id + "\" " +
|
||||
@@ -67,7 +67,7 @@ BaseEdge.prototype.SaveToXML = function ()
|
||||
"></edge>";
|
||||
}
|
||||
|
||||
BaseEdge.prototype.LoadFromXML = function (xml, graph)
|
||||
BaseEdge.prototype.LoadFromXML = function (xml, graph, defaultLoadEdges)
|
||||
{
|
||||
var attr = xml.attr('vertex1');
|
||||
if (typeof attr === 'undefined')
|
||||
@@ -81,7 +81,30 @@ BaseEdge.prototype.LoadFromXML = function (xml, graph)
|
||||
attr = xml.attr('target');
|
||||
}
|
||||
this.vertex2 = graph.FindVertex(typeof attr !== 'undefined' ? attr : xml.attr('graph2'));
|
||||
this.isDirect = xml.attr('isDirect') == "true";
|
||||
|
||||
/*
|
||||
if (directed)
|
||||
else if (isDirect)
|
||||
else edgedefault
|
||||
*/
|
||||
var directedAttribute = xml.attr('directed');
|
||||
if (typeof directedAttribute !== 'undefined')
|
||||
{
|
||||
this.isDirect = directedAttribute == "true";
|
||||
}
|
||||
else
|
||||
{
|
||||
var isDirectedAttribute = xml.attr('isDirect');
|
||||
if (typeof isDirectedAttribute !== 'undefined')
|
||||
{
|
||||
this.isDirect = isDirectedAttribute == "true";
|
||||
}
|
||||
else
|
||||
{
|
||||
this.isDirect = defaultLoadEdges == "directed";
|
||||
}
|
||||
}
|
||||
|
||||
this.weight = parseFloat(xml.attr('weight'));
|
||||
if (isNaN(this.weight))
|
||||
{
|
||||
|
||||
@@ -1074,10 +1074,12 @@ Graph.prototype.LoadFromXML = function (xmlText, additionalData)
|
||||
|
||||
var loadedGraphId = 0;
|
||||
var loadedEdgeId = 0;
|
||||
var defaultLoadEdges = "";
|
||||
|
||||
$graphs.each(function(){
|
||||
loadedGraphId = parseInt($(this).attr('uidGraph'));
|
||||
loadedEdgeId = parseInt($(this).attr('uidEdge'));
|
||||
defaultLoadEdges = $(this).attr('edgedefault');
|
||||
});
|
||||
|
||||
// Backward compatibility
|
||||
@@ -1089,6 +1091,11 @@ Graph.prototype.LoadFromXML = function (xmlText, additionalData)
|
||||
loadedEdgeId = this.edgesOffset;
|
||||
}
|
||||
|
||||
if (defaultLoadEdges != "directed" && defaultLoadEdges != "undirected")
|
||||
{
|
||||
defaultLoadEdges = "undirected";
|
||||
}
|
||||
|
||||
this.uidGraph = loadedGraphId;
|
||||
this.uidEdge = loadedEdgeId;
|
||||
|
||||
@@ -1109,7 +1116,7 @@ Graph.prototype.LoadFromXML = function (xmlText, additionalData)
|
||||
var graph = this;
|
||||
$edges.each(function(){
|
||||
var edge = new BaseEdge();
|
||||
edge.LoadFromXML($(this), graph);
|
||||
edge.LoadFromXML($(this), graph, defaultLoadEdges);
|
||||
// Fix case with wrong id.
|
||||
if (edge.id < graph.uidEdge) {
|
||||
edge.id = graph.uidEdge;
|
||||
|
||||
Reference in New Issue
Block a user