mirror of
https://github.com/UnickSoft/graphonline.git
synced 2026-06-16 22:01:00 +00:00
Added export/import graph
This commit is contained in:
@@ -126,4 +126,7 @@
|
|||||||
|
|
||||||
$g_lang["sourceVertex"] = "Source";
|
$g_lang["sourceVertex"] = "Source";
|
||||||
$g_lang["sinkVertex"] = "Sink";
|
$g_lang["sinkVertex"] = "Sink";
|
||||||
|
|
||||||
|
$g_lang["export_graph"] = "Export to file";
|
||||||
|
$g_lang["import_graph"] = "Import from file";
|
||||||
?>
|
?>
|
||||||
|
|||||||
@@ -129,4 +129,7 @@
|
|||||||
|
|
||||||
$g_lang["sourceVertex"] = "Исток";
|
$g_lang["sourceVertex"] = "Исток";
|
||||||
$g_lang["sinkVertex"] = "Сток";
|
$g_lang["sinkVertex"] = "Сток";
|
||||||
|
|
||||||
|
$g_lang["export_graph"] = "Экспортировать граф";
|
||||||
|
$g_lang["import_graph"] = "Импортировать граф";
|
||||||
?>
|
?>
|
||||||
|
|||||||
+12
-7
@@ -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)
|
Application.prototype.LoadGraphFromDisk = function (graphName)
|
||||||
{
|
{
|
||||||
var app = this;
|
var app = this;
|
||||||
@@ -867,13 +878,7 @@ Application.prototype.LoadGraphFromDisk = function (graphName)
|
|||||||
})
|
})
|
||||||
.done(function( msg )
|
.done(function( msg )
|
||||||
{
|
{
|
||||||
var graph = new Graph();
|
app.LoadGraphFromString(msg);
|
||||||
graph.LoadFromXML(msg);
|
|
||||||
app.SetDefaultTransformations();
|
|
||||||
app.graph = graph;
|
|
||||||
app.AutoAdjustViewport();
|
|
||||||
app.updateMessage();
|
|
||||||
app.redrawGraph();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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()
|
function postLoadPage()
|
||||||
{
|
{
|
||||||
application.userAction = userAction;
|
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)
|
if (document.getElementById('VoteButton') !== null)
|
||||||
document.getElementById('VoteButton').onclick = function ()
|
document.getElementById('VoteButton').onclick = function ()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -47,6 +47,16 @@
|
|||||||
<li>
|
<li>
|
||||||
<button type="button" class="btn btn-default btn-sm btn-submenu" id="SaveFullGraphImage"><span class="glyphicon glyphicon-floppy-disk fa-fw"></span> <?= L('save_full_image')?></button>
|
<button type="button" class="btn btn-default btn-sm btn-submenu" id="SaveFullGraphImage"><span class="glyphicon glyphicon-floppy-disk fa-fw"></span> <?= L('save_full_image')?></button>
|
||||||
</li>
|
</li>
|
||||||
|
<li class="divider hidden-phone"></li>
|
||||||
|
<li class="hidden-phone">
|
||||||
|
<button type="button" class="btn btn-default btn-sm btn-submenu" id="ExportGraph"><span class="glyphicon glyphicon-download fa-fw"></span> <?= L('export_graph')?></button>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li class="hidden-phone">
|
||||||
|
<input type="file" id="ImportGraphFiles" accept=".graphml" style="display:none" onchange="handelImportGraph(this.files)">
|
||||||
|
<button type="button" class="btn btn-default btn-sm btn-submenu" id="ImportGraph"><span class="glyphicon glyphicon-upload fa-fw"></span> <?= L('import_graph')?></button>
|
||||||
|
</li>
|
||||||
|
|
||||||
<li class="divider"></li>
|
<li class="divider"></li>
|
||||||
<li>
|
<li>
|
||||||
<button type="button" class="btn btn-default btn-sm btn-submenu" id="ShowAdjacencyMatrix"><span class="glyphicon glyphicon-th fa-fw"></span> <?= L('show_adjacency_matrix')?></button>
|
<button type="button" class="btn btn-default btn-sm btn-submenu" id="ShowAdjacencyMatrix"><span class="glyphicon glyphicon-th fa-fw"></span> <?= L('show_adjacency_matrix')?></button>
|
||||||
|
|||||||
Reference in New Issue
Block a user