Created
January 15, 2015 11:15
-
-
Save davidjgraph/c8543531f9c471a1cb28 to your computer and use it in GitHub Desktop.
The draw.io code invoked on a download as SVG
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
else if (format == 'svg') | |
{ | |
var bg = this.editor.graph.background; | |
if (bg == 'none') | |
{ | |
bg = null; | |
} | |
// JPG does not support transparent backgrounds | |
if (bg == null && format == 'jpg') | |
{ | |
bg = '#ffffff'; | |
} | |
// Sets or disables alternate text for foreignObjects. Disabling is needed | |
// because PhantomJS seems to ignore switch statements and paint all text. | |
mxSvgCanvas2D.prototype.foAltText = (format == 'svg') ? '[Not supported by viewer]' : null; | |
var svgRoot = this.editor.graph.getSvg(bg, null, null, (format == 'pdf' && this.editor.graph.pageVisible)); | |
var svg = mxUtils.getXml(svgRoot); | |
if (svg.length <= MAX_REQUEST_SIZE) | |
{ | |
if (format == 'svg') | |
{ | |
if (urlParams['save'] == 'local' || this.isOfflineApp() || mxClient.IS_IOS) | |
{ | |
this.saveLocalFile(svg, filename, 'image/svg+xml'); | |
} | |
else | |
{ | |
var param = (typeof(Zlib) === 'undefined') ? '&xml=' + encodeURIComponent(svg) : | |
'&data=' + encodeURIComponent(this.editor.compress(svg)); | |
new mxXmlRequest(SAVE_URL, 'filename=' + encodeURIComponent(filename) + | |
'&format=' + format + param).simulate(document, '_blank'); | |
} | |
} | |
else | |
{ | |
var w = parseInt(svgRoot.getAttribute('width')); | |
var h = parseInt(svgRoot.getAttribute('height')); | |
if (w > 0 && h > 0 && w * h < MAX_AREA) | |
{ | |
var bgParam = (bg != null) ? '&bg=' + bg : ''; | |
var param = (typeof(Zlib) === 'undefined') ? '&svg=' + encodeURIComponent(svg) : | |
'&svgdata=' + encodeURIComponent(this.editor.compress(svg)); | |
new mxXmlRequest(EXPORT_URL, 'filename=' + encodeURIComponent(filename) + | |
'&format=' + format + bgParam + '&w=' + w + '&h=' + h + param). | |
simulate(document, '_blank'); | |
} | |
} | |
} | |
else | |
{ | |
mxUtils.alert(mxResources.get('drawingTooLarge')); | |
mxUtils.popup(svg); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment