mirror of
https://github.com/UnickSoft/graphonline.git
synced 2026-06-17 06:11:37 +00:00
Improved load GraphML graphs.
This commit is contained in:
@@ -851,7 +851,6 @@ Application.prototype.Test = function ()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Application.prototype.SetAdjacencyMatrixSmart = function (matrix, separator)
|
Application.prototype.SetAdjacencyMatrixSmart = function (matrix, separator)
|
||||||
{
|
{
|
||||||
if (separator === undefined)
|
if (separator === undefined)
|
||||||
@@ -1002,6 +1001,10 @@ Application.prototype.LoadGraphFromString = function (str)
|
|||||||
this.LoadUserSettings(userSettings["data"]);
|
this.LoadUserSettings(userSettings["data"]);
|
||||||
this.SetDefaultTransformations();
|
this.SetDefaultTransformations();
|
||||||
this.graph = graph;
|
this.graph = graph;
|
||||||
|
if (this.graph.isNeedReposition())
|
||||||
|
{
|
||||||
|
this.graph.VertexesReposition(new Point(this.GetRealWidth(), this.GetRealHeight()), this.graph.vertices);
|
||||||
|
}
|
||||||
this.AutoAdjustViewport();
|
this.AutoAdjustViewport();
|
||||||
this.updateMessage();
|
this.updateMessage();
|
||||||
this.redrawGraph();
|
this.redrawGraph();
|
||||||
|
|||||||
+17
-5
@@ -25,8 +25,8 @@ function BaseEdge(vertex1, vertex2, isDirect, weight)
|
|||||||
BaseEdge.prototype.SaveToXML = function ()
|
BaseEdge.prototype.SaveToXML = function ()
|
||||||
{
|
{
|
||||||
return "<edge " +
|
return "<edge " +
|
||||||
"vertex1=\"" + this.vertex1.id + "\" " +
|
"source=\"" + this.vertex1.id + "\" " +
|
||||||
"vertex2=\"" + this.vertex2.id + "\" " +
|
"target=\"" + this.vertex2.id + "\" " +
|
||||||
"isDirect=\"" + this.isDirect + "\" " +
|
"isDirect=\"" + this.isDirect + "\" " +
|
||||||
"weight=\"" + this.weight + "\" " +
|
"weight=\"" + this.weight + "\" " +
|
||||||
"useWeight=\"" + this.useWeight + "\" " +
|
"useWeight=\"" + this.useWeight + "\" " +
|
||||||
@@ -41,14 +41,26 @@ BaseEdge.prototype.SaveToXML = function ()
|
|||||||
BaseEdge.prototype.LoadFromXML = function (xml, graph)
|
BaseEdge.prototype.LoadFromXML = function (xml, graph)
|
||||||
{
|
{
|
||||||
var attr = xml.attr('vertex1');
|
var attr = xml.attr('vertex1');
|
||||||
this.vertex1 = graph.FindVertex(parseInt(typeof attr !== 'undefined' ? attr : xml.attr('graph1')));
|
if (typeof attr === 'undefined')
|
||||||
|
{
|
||||||
|
attr = xml.attr('source');
|
||||||
|
}
|
||||||
|
this.vertex1 = graph.FindVertex(typeof attr !== 'undefined' ? attr : xml.attr('graph1'));
|
||||||
var attr = xml.attr('vertex2');
|
var attr = xml.attr('vertex2');
|
||||||
this.vertex2 = graph.FindVertex(parseInt(typeof attr !== 'undefined' ? attr : xml.attr('graph2')));
|
if (typeof attr === 'undefined')
|
||||||
|
{
|
||||||
|
attr = xml.attr('target');
|
||||||
|
}
|
||||||
|
this.vertex2 = graph.FindVertex(typeof attr !== 'undefined' ? attr : xml.attr('graph2'));
|
||||||
this.isDirect = xml.attr('isDirect') == "true";
|
this.isDirect = xml.attr('isDirect') == "true";
|
||||||
this.weight = parseFloat(xml.attr('weight'));
|
this.weight = parseFloat(xml.attr('weight'));
|
||||||
|
if (isNaN(this.weight))
|
||||||
|
{
|
||||||
|
this.weight = 1;
|
||||||
|
}
|
||||||
this.hasPair = xml.attr('hasPair') == "true";
|
this.hasPair = xml.attr('hasPair') == "true";
|
||||||
this.useWeight = xml.attr('useWeight') == "true";
|
this.useWeight = xml.attr('useWeight') == "true";
|
||||||
this.id = parseInt(xml.attr('id'));
|
this.id = xml.attr('id');
|
||||||
this.text = xml.attr("text") == null ? "" : xml.attr("text");
|
this.text = xml.attr("text") == null ? "" : xml.attr("text");
|
||||||
this.arrayStyleStart = xml.attr("arrayStyleStart") == null ? "" : xml.attr("arrayStyleStart");
|
this.arrayStyleStart = xml.attr("arrayStyleStart") == null ? "" : xml.attr("arrayStyleStart");
|
||||||
this.arrayStyleFinish = xml.attr("arrayStyleFinish") == null ? "" : xml.attr("arrayStyleFinish");
|
this.arrayStyleFinish = xml.attr("arrayStyleFinish") == null ? "" : xml.attr("arrayStyleFinish");
|
||||||
|
|||||||
+16
-2
@@ -12,6 +12,7 @@ function BaseVertex(x, y, vertexEnumType)
|
|||||||
this.upText = "";
|
this.upText = "";
|
||||||
this.vertexEnumType = vertexEnumType;
|
this.vertexEnumType = vertexEnumType;
|
||||||
this.model = new VertexModel();
|
this.model = new VertexModel();
|
||||||
|
this.hasUndefinedPosition = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
BaseVertex.prototype.position = new Point(0, 0);
|
BaseVertex.prototype.position = new Point(0, 0);
|
||||||
@@ -30,10 +31,18 @@ BaseVertex.prototype.SaveToXML = function ()
|
|||||||
|
|
||||||
BaseVertex.prototype.LoadFromXML = function (xml)
|
BaseVertex.prototype.LoadFromXML = function (xml)
|
||||||
{
|
{
|
||||||
this.position = new Point(parseFloat(xml.attr('positionX')), parseFloat(xml.attr('positionY')));
|
var xmlX = xml.attr('positionX');
|
||||||
this.id = parseInt(xml.attr('id'));
|
var xmlY = xml.attr('positionY');
|
||||||
|
this.hasUndefinedPosition = (typeof xmlX === 'undefined') || (typeof xmlY === 'undefined');
|
||||||
|
this.position = new Point(parseFloat(xmlX), parseFloat(xmlY));
|
||||||
|
this.id = xml.attr('id');
|
||||||
this.mainText = xml.attr('mainText');
|
this.mainText = xml.attr('mainText');
|
||||||
this.upText = xml.attr('upText');
|
this.upText = xml.attr('upText');
|
||||||
|
|
||||||
|
if (typeof this.mainText === 'undefined')
|
||||||
|
this.mainText = this.id;
|
||||||
|
if (typeof this.upText === 'undefined')
|
||||||
|
this.upText = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseVertex.prototype.SetId = function (id)
|
BaseVertex.prototype.SetId = function (id)
|
||||||
@@ -46,3 +55,8 @@ BaseVertex.prototype.diameterFactor = function ()
|
|||||||
{
|
{
|
||||||
return 1.0 + (this.mainText.length ? this.mainText.length / 8.0 : 0);
|
return 1.0 + (this.mainText.length ? this.mainText.length / 8.0 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BaseVertex.prototype.IsUndefinedPosition = function ()
|
||||||
|
{
|
||||||
|
return this.hasUndefinedPosition;
|
||||||
|
}
|
||||||
|
|||||||
+12
-1
@@ -870,7 +870,7 @@ Graph.prototype.LoadFromXML = function (xmlText, additionalData)
|
|||||||
$nodes.each(function(){
|
$nodes.each(function(){
|
||||||
var vertex = new BaseVertex();
|
var vertex = new BaseVertex();
|
||||||
vertex.LoadFromXML($(this));
|
vertex.LoadFromXML($(this));
|
||||||
vertexs.push(vertex);
|
vertexs.push(vertex);
|
||||||
});
|
});
|
||||||
this.vertices = vertexs;
|
this.vertices = vertexs;
|
||||||
|
|
||||||
@@ -1030,3 +1030,14 @@ Graph.prototype.isMulti = function ()
|
|||||||
{
|
{
|
||||||
return this.isMultiGraph;
|
return this.isMultiGraph;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Graph.prototype.isNeedReposition = function ()
|
||||||
|
{
|
||||||
|
var res = false;
|
||||||
|
for (var i = 0; i < this.vertices.length; i++)
|
||||||
|
{
|
||||||
|
res = res || this.vertices[i].IsUndefinedPosition();
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user