drawio/war/plugins/svgdata.js
Gaudenz Alder b3a060a194 5.6.0.0 release
Former-commit-id: 648b0f02cb
2016-09-06 16:07:11 +02:00

49 lines
1.1 KiB
JavaScript

/**
* Sample plugin.
*/
Draw.loadPlugin(function(ui) {
/**
* Overrides SVG export to add metadata for each cell.
*/
var graphCreateSvgImageExport = Graph.prototype.createSvgImageExport;
Graph.prototype.createSvgImageExport = function()
{
var exp = graphCreateSvgImageExport.apply(this, arguments);
// Overrides rendering to add metadata
var expDrawCellState = exp.drawCellState;
exp.drawCellState = function(state, canvas)
{
var svgDoc = canvas.root.ownerDocument;
var g = (svgDoc.createElementNS != null) ?
svgDoc.createElementNS(mxConstants.NS_SVG, 'g') : svgDoc.createElement('g');
g.setAttribute('id', 'cell-' + state.cell.id);
// Temporary replaces root for content rendering
var prev = canvas.root;
prev.appendChild(g);
canvas.root = g;
expDrawCellState.apply(this, arguments);
// Adds metadata if group is not empty
if (g.firstChild == null)
{
g.parentNode.removeChild(g);
}
else if (mxUtils.isNode(state.cell.value))
{
g.setAttribute('content', mxUtils.getXml(state.cell.value));
}
// Restores previous root
canvas.root = prev;
};
return exp;
};
});