mirror of
https://github.com/UnickSoft/graphonline.git
synced 2025-07-02 15:56:27 +00:00
Added export/import graph
This commit is contained in:
parent
0149bcc1f7
commit
cb3fbf03de
@ -126,4 +126,7 @@
|
||||
|
||||
$g_lang["sourceVertex"] = "Source";
|
||||
$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["sinkVertex"] = "Сток";
|
||||
|
||||
$g_lang["export_graph"] = "Экспортировать граф";
|
||||
$g_lang["import_graph"] = "Импортировать граф";
|
||||
?>
|
||||
|
@ -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 ()
|
||||
{
|
||||
|
10
tpl/home.php
10
tpl/home.php
@ -47,6 +47,16 @@
|
||||
<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>
|
||||
</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>
|
||||
<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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user