1/** 2 * Sample plugin. 3 */ 4Draw.loadPlugin(function(ui) { 5 6 /** 7 * Overrides SVG export to add metadata for each cell. 8 */ 9 var graphCreateSvgImageExport = Graph.prototype.createSvgImageExport; 10 11 Graph.prototype.createSvgImageExport = function() 12 { 13 var exp = graphCreateSvgImageExport.apply(this, arguments); 14 15 // Overrides rendering to add metadata 16 var expDrawCellState = exp.drawCellState; 17 18 exp.drawCellState = function(state, canvas) 19 { 20 var svgDoc = canvas.root.ownerDocument; 21 var g = (svgDoc.createElementNS != null) ? 22 svgDoc.createElementNS(mxConstants.NS_SVG, 'g') : svgDoc.createElement('g'); 23 g.setAttribute('id', 'cell-' + state.cell.id); 24 25 // Temporary replaces root for content rendering 26 var prev = canvas.root; 27 prev.appendChild(g); 28 canvas.root = g; 29 30 expDrawCellState.apply(this, arguments); 31 32 // Adds metadata if group is not empty 33 if (g.firstChild == null) 34 { 35 g.parentNode.removeChild(g); 36 } 37 else if (mxUtils.isNode(state.cell.value)) 38 { 39 g.setAttribute('content', mxUtils.getXml(state.cell.value)); 40 41 for (var i = 0; i < state.cell.value.attributes.length; i++) 42 { 43 var attrib = state.cell.value.attributes[i]; 44 g.setAttribute('data-' + attrib.name, attrib.value); 45 } 46 } 47 48 // Restores previous root 49 canvas.root = prev; 50 }; 51 52 return exp; 53 }; 54 55}); 56