mirror of
https://github.com/UnickSoft/graphonline.git
synced 2026-02-16 02:30:51 +00:00
Added export/import graph
This commit is contained in:
@@ -857,6 +857,17 @@ Application.prototype.SaveFullGraphImageOnDisk = function (showDialogCallback)
|
||||
|
||||
|
||||
|
||||
Application.prototype.LoadGraphFromString = function (str)
|
||||
{
|
||||
var graph = new Graph();
|
||||
graph.LoadFromXML(str);
|
||||
this.SetDefaultTransformations();
|
||||
this.graph = graph;
|
||||
this.AutoAdjustViewport();
|
||||
this.updateMessage();
|
||||
this.redrawGraph();
|
||||
}
|
||||
|
||||
Application.prototype.LoadGraphFromDisk = function (graphName)
|
||||
{
|
||||
var app = this;
|
||||
@@ -867,13 +878,7 @@ Application.prototype.LoadGraphFromDisk = function (graphName)
|
||||
})
|
||||
.done(function( msg )
|
||||
{
|
||||
var graph = new Graph();
|
||||
graph.LoadFromXML(msg);
|
||||
app.SetDefaultTransformations();
|
||||
app.graph = graph;
|
||||
app.AutoAdjustViewport();
|
||||
app.updateMessage();
|
||||
app.redrawGraph();
|
||||
app.LoadGraphFromString(msg);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -127,6 +127,21 @@ function createAlgorithmMenu()
|
||||
|
||||
}
|
||||
|
||||
|
||||
function handelImportGraph(files) {
|
||||
var graphFileToLoad = files[0];
|
||||
|
||||
var fileReader = new FileReader();
|
||||
fileReader.onload = function(fileLoadedEvent){
|
||||
var textFromFileLoaded = fileLoadedEvent.target.result;
|
||||
console.log(textFromFileLoaded);
|
||||
application.LoadGraphFromString(textFromFileLoaded);
|
||||
ImportGraphFiles.value = "";
|
||||
};
|
||||
|
||||
fileReader.readAsText(graphFileToLoad, "UTF-8");
|
||||
}
|
||||
|
||||
function postLoadPage()
|
||||
{
|
||||
application.userAction = userAction;
|
||||
@@ -436,6 +451,36 @@ function postLoadPage()
|
||||
}
|
||||
}
|
||||
|
||||
document.getElementById('ExportGraph').onclick = function ()
|
||||
{
|
||||
userAction(this.id);
|
||||
|
||||
var graphAsString = application.graph.SaveToXML();
|
||||
var savedGraphName = application.GetNewGraphName();
|
||||
|
||||
var element = document.createElement('a');
|
||||
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(graphAsString));
|
||||
element.setAttribute('download', "graph_" + savedGraphName + ".graphml");
|
||||
|
||||
element.style.display = 'none';
|
||||
document.body.appendChild(element);
|
||||
|
||||
element.click();
|
||||
|
||||
document.body.removeChild(element);
|
||||
}
|
||||
|
||||
document.getElementById('ImportGraph').onclick = function ()
|
||||
{
|
||||
userAction(this.id);
|
||||
|
||||
if (ImportGraphFiles) {
|
||||
ImportGraphFiles.click();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (document.getElementById('VoteButton') !== null)
|
||||
document.getElementById('VoteButton').onclick = function ()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user