-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsvgdata.js
55 lines (44 loc) · 1.33 KB
/
svgdata.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
* 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));
for (var i = 0; i < state.cell.value.attributes.length; i++)
{
var attrib = state.cell.value.attributes[i];
g.setAttribute('data-' + attrib.name, attrib.value);
}
}
// Restores previous root
canvas.root = prev;
};
return exp;
};
});