mirror of
https://github.com/UnickSoft/graphonline.git
synced 2026-02-16 10:40:57 +00:00
Add export graph to svg
This commit is contained in:
@@ -233,6 +233,22 @@ Application.prototype._PrintRedrawGraph = function()
|
||||
return canvas;
|
||||
}
|
||||
|
||||
Application.prototype._printToSVG = function()
|
||||
{
|
||||
var bbox = this.graph.getGraphBBox();
|
||||
var context = new C2S(bbox.size().x, bbox.size().y);
|
||||
|
||||
context.save();
|
||||
|
||||
context.translate(bbox.minPoint.inverse().x, bbox.minPoint.inverse().y);
|
||||
|
||||
this._RedrawGraph(context, bbox.minPoint.inverse(), this.backgroundCommonStyle, false);
|
||||
|
||||
context.restore();
|
||||
|
||||
return context.getSerializedSvg();
|
||||
}
|
||||
|
||||
Application.prototype.updateRenderPathLength = function()
|
||||
{
|
||||
this.renderPathLength = 0;
|
||||
@@ -707,6 +723,11 @@ Application.prototype.SetHandlerMode = function(mode)
|
||||
var savedDialogGraphImageHandler = new SavedDialogGraphImageHandler(this);
|
||||
savedDialogGraphImageHandler.showPrint();
|
||||
}
|
||||
else if (mode == "saveSvgGraphImage")
|
||||
{
|
||||
var savedDialogGraphImageHandler = new SavedDialogGraphImageHandler(this);
|
||||
savedDialogGraphImageHandler.showSvg();
|
||||
}
|
||||
else if (mode == "eulerianLoop")
|
||||
{
|
||||
this.handler = new EulerianLoopGraphHandler(this);
|
||||
@@ -1075,6 +1096,32 @@ Application.prototype.SaveFullGraphImageOnDisk = function (showDialogCallback, f
|
||||
|
||||
return imageName;
|
||||
}
|
||||
|
||||
Application.prototype.SaveSVGGraphOnDisk = function (showDialogCallback)
|
||||
{
|
||||
var imageName = this.GetNewName();
|
||||
|
||||
this.stopRenderTimer();
|
||||
var svgText = this._printToSVG();
|
||||
|
||||
var bbox = this.graph.getGraphBBox();
|
||||
|
||||
var imageBase64Data = canvas.toDataURL();
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/" + SiteDir + "cgi-bin/saveSvg.php?name=" + imageName,
|
||||
data: {
|
||||
svgdata : svgText
|
||||
},
|
||||
dataType: "text",
|
||||
success: function(data){
|
||||
showDialogCallback();
|
||||
}
|
||||
});
|
||||
|
||||
return imageName;
|
||||
}
|
||||
|
||||
Application.prototype.LoadGraphFromString = function (str)
|
||||
{
|
||||
|
||||
@@ -1457,7 +1457,7 @@ SavedDialogGraphImageHandler.prototype.pathObjects = null;
|
||||
// Objects.
|
||||
SavedDialogGraphImageHandler.prototype.objects = null;
|
||||
|
||||
SavedDialogGraphImageHandler.prototype.showDialogCallback = function ()
|
||||
SavedDialogGraphImageHandler.prototype.showDialogCallback = function (imageExtention)
|
||||
{
|
||||
var dialogButtons = {};
|
||||
|
||||
@@ -1465,7 +1465,7 @@ SavedDialogGraphImageHandler.prototype.showDialogCallback = function ()
|
||||
$( this ).dialog( "close" );
|
||||
};
|
||||
|
||||
var fileLocation = "tmp/saved/" + this.imageName.substr(0, 2) + "/"+ this.imageName + ".png"
|
||||
var fileLocation = "tmp/saved/" + this.imageName.substr(0, 2) + "/"+ this.imageName + "." + imageExtention
|
||||
|
||||
document.getElementById("showSavedImageGraph").src = "/" + fileLocation;
|
||||
document.getElementById("showSavedImageGraphRef").href = "/" + fileLocation;
|
||||
@@ -1492,7 +1492,7 @@ SavedDialogGraphImageHandler.prototype.showWorkspace = function()
|
||||
{
|
||||
var object = this;
|
||||
var callback = function() {
|
||||
object.showDialogCallback();
|
||||
object.showDialogCallback("png");
|
||||
};
|
||||
|
||||
this.imageName = this.app.SaveGraphImageOnDisk(callback);
|
||||
@@ -1502,7 +1502,7 @@ SavedDialogGraphImageHandler.prototype.showFullgraph = function()
|
||||
{
|
||||
var object = this;
|
||||
var callback = function() {
|
||||
object.showDialogCallback();
|
||||
object.showDialogCallback("png");
|
||||
};
|
||||
|
||||
this.imageName = this.app.SaveFullGraphImageOnDisk(callback, false);
|
||||
@@ -1512,12 +1512,22 @@ SavedDialogGraphImageHandler.prototype.showPrint = function()
|
||||
{
|
||||
var object = this;
|
||||
var callback = function() {
|
||||
object.showDialogCallback();
|
||||
object.showDialogCallback("png");
|
||||
};
|
||||
|
||||
this.imageName = this.app.SaveFullGraphImageOnDisk(callback, true);
|
||||
}
|
||||
|
||||
SavedDialogGraphImageHandler.prototype.showSvg = function()
|
||||
{
|
||||
var object = this;
|
||||
var callback = function() {
|
||||
object.showDialogCallback("svg");
|
||||
};
|
||||
|
||||
this.imageName = this.app.SaveSVGGraphOnDisk(callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Algorithm Graph handler.
|
||||
*
|
||||
|
||||
1214
script/canvas2svg.js
Normal file
1214
script/canvas2svg.js
Normal file
File diff suppressed because it is too large
Load Diff
@@ -404,6 +404,12 @@ function postLoadPage()
|
||||
userAction(this.id);
|
||||
application.SetHandlerMode("savePrintGraphImage");
|
||||
}
|
||||
|
||||
document.getElementById('SaveSvgGraphImage').onclick = function ()
|
||||
{
|
||||
userAction(this.id);
|
||||
application.SetHandlerMode("saveSvgGraphImage");
|
||||
}
|
||||
|
||||
document.getElementById('Zoom100').onclick = function ()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user