Extends mxAbstractCanvas2D to implement a canvas for SVG. This canvas writes all calls as SVG output to the given SVG root node.
var svgDoc = mxUtils.createXmlDocument(); var root = (svgDoc.createElementNS != null) ? svgDoc.createElementNS(mxConstants.NS_SVG, 'svg') : svgDoc.createElement('svg'); if (svgDoc.createElementNS == null) { root.setAttribute('xmlns', mxConstants.NS_SVG); } var bounds = graph.getGraphBounds(); root.setAttribute('width', (bounds.x + bounds.width + 4) + 'px'); root.setAttribute('height', (bounds.y + bounds.height + 4) + 'px'); root.setAttribute('xmlns:xlink', mxConstants.NS_XLINK); root.setAttribute('version', '1.1'); svgDoc.appendChild(root); var svgCanvas = new mxSvgCanvas2D(root);
A description of the public API is available in mxXmlCanvas2D.
To disable anti-aliasing in the output, use the following code.
graph.view.canvas.ownerSVGElement.setAttribute('shape-rendering', 'crispEdges');
Or set the respective attribute in the SVG element directly.
mxSvgCanvas2D | Extends mxAbstractCanvas2D to implement a canvas for SVG. |
Functions | |
mxSvgCanvas2D | Constructs a new SVG canvas. |
Variables | |
root | Reference to the container for the SVG content. |
gradients | Local cache of gradients for quick lookups. |
defs | Reference to the defs section of the SVG document. |
styleEnabled | Stores the value of styleEnabled passed to the constructor. |
path | Holds the current DOM node. |
matchHtmlAlignment | Specifies if plain text output should match HTML alignment. |
textEnabled | Specifies if text output should be enabled. |
foEnabled | Specifies if use of foreignObject for HTML markup is allowed. |
foAltText | Specifies the fallback text for unsupported foreignObjects in exported documents. |
strokeTolerance | Adds transparent paths for strokes. |
refCount | Local counter for references in SVG export. |
blockImagePointerEvents | Specifies if a transparent rectangle should be added on top of images to absorb all pointer events. |
Functions | |
reset | Returns any offsets for rendering pixels. |
createStyle | Creates the optional style section. |
createElement | Private helper function to create SVG elements |
getAlternateContent | Returns the alternate content for the given foreignObject. |
createGradientId | Private helper function to create SVG elements |
getSvgGradient | Private helper function to create SVG elements |
createSvgGradient | Creates the given SVG gradient. |
addNode | Private helper function to create SVG elements |
updateFill | Transfers the stroke attributes from <state> to <node>. |
updateStroke | Transfers the stroke attributes from <state> to <node>. |
updateStrokeAttributes | Transfers the stroke attributes from <state> to <node>. |
createDashPattern | Creates the SVG dash pattern for the given state. |
createTolerance | Creates a hit detection tolerance shape for the given node. |
createShadow | Creates a shadow for the given node. |
rotate | Sets the rotation of the canvas. |
begin | Extends superclass to create path. |
rect | Private helper function to create SVG elements |
roundrect | Private helper function to create SVG elements |
ellipse | Private helper function to create SVG elements |
image | Private helper function to create SVG elements |
createDiv | Private helper function to create SVG elements |
text | Paints the given text. |
createClip | Creates a clip for the given coordinates. |
text | Paints the given text. |
updateFont | Updates the text properties for the given node. |
addTextBackground | Background color and border |
stroke | Paints the outline of the current path. |
fill | Fills the current path. |
fillAndStroke | Fills and paints the outline of the current path. |
function mxSvgCanvas2D( root, styleEnabled )
Constructs a new SVG canvas.
root | SVG container for the output. |
styleEnabled | Optional boolean that specifies if a style section should be added. The style section sets the default font-size, font-family and stroke-miterlimit globally. Default is false. |
mxSvgCanvas2D.prototype.text = function( x, y, w, h, str, align, valign, wrap, format, overflow, clip, rotation )
Paints the given text. Possible values for format are empty string for plain text and html for HTML markup. Note that HTML markup is only supported if foreignObject is supported and foEnabled is true. (This means IE9 and later does currently not support HTML text as part of shapes.)
Constructs a new SVG canvas.
function mxSvgCanvas2D( root, styleEnabled )
Reference to the container for the SVG content.
this.root
Local cache of gradients for quick lookups.
this.gradients
Reference to the defs section of the SVG document.
this.defs
Stores the value of styleEnabled passed to the constructor.
this.styleEnabled
Specifies if plain text output should match HTML alignment.
mxSvgCanvas2D.prototype.matchHtmlAlignment
Specifies if text output should be enabled.
mxSvgCanvas2D.prototype.textEnabled
Specifies if use of foreignObject for HTML markup is allowed.
mxSvgCanvas2D.prototype.foEnabled
Specifies the fallback text for unsupported foreignObjects in exported documents.
mxSvgCanvas2D.prototype.foAltText
Adds transparent paths for strokes.
mxSvgCanvas2D.prototype.strokeTolerance
Local counter for references in SVG export.
mxSvgCanvas2D.prototype.refCount
Specifies if a transparent rectangle should be added on top of images to absorb all pointer events.
mxSvgCanvas2D.prototype.blockImagePointerEvents
Returns any offsets for rendering pixels.
mxSvgCanvas2D.prototype.reset = function()
Creates the optional style section.
mxSvgCanvas2D.prototype.createStyle = function( x )
Private helper function to create SVG elements
mxSvgCanvas2D.prototype.createElement = function( tagName, namespace )
Private helper function to create SVG elements
mxSvgCanvas2D.prototype.createGradientId = function( start, end, alpha1, alpha2, direction )
Private helper function to create SVG elements
mxSvgCanvas2D.prototype.getSvgGradient = function( start, end, alpha1, alpha2, direction )
Creates the given SVG gradient.
mxSvgCanvas2D.prototype.createSvgGradient = function( start, end, alpha1, alpha2, direction )
Private helper function to create SVG elements
mxSvgCanvas2D.prototype.addNode = function( filled, stroked )
Transfers the stroke attributes from state to node.
mxSvgCanvas2D.prototype.updateFill = function()
Transfers the stroke attributes from state to node.
mxSvgCanvas2D.prototype.updateStroke = function()
Transfers the stroke attributes from state to node.
mxSvgCanvas2D.prototype.updateStrokeAttributes = function()
Creates the SVG dash pattern for the given state.
mxSvgCanvas2D.prototype.createDashPattern = function( scale )
Creates a hit detection tolerance shape for the given node.
mxSvgCanvas2D.prototype.createTolerance = function( node )
Creates a shadow for the given node.
mxSvgCanvas2D.prototype.createShadow = function( node )
Sets the rotation of the canvas.
mxSvgCanvas2D.prototype.rotate = function( theta, flipH, flipV, cx, cy )
Extends superclass to create path.
mxSvgCanvas2D.prototype.begin = function()
Private helper function to create SVG elements
mxSvgCanvas2D.prototype.rect = function( x, y, w, h )
Private helper function to create SVG elements
mxSvgCanvas2D.prototype.roundrect = function( x, y, w, h, dx, dy )
Private helper function to create SVG elements
mxSvgCanvas2D.prototype.ellipse = function( x, y, w, h )
Private helper function to create SVG elements
mxSvgCanvas2D.prototype.image = function( x, y, w, h, src, aspect, flipH, flipV )
Private helper function to create SVG elements
mxSvgCanvas2D.prototype.createDiv = function( str, align, valign, style, overflow )
Paints the given text.
mxSvgCanvas2D.prototype.text = function( x, y, w, h, str, align, valign, wrap, format, overflow, clip, rotation )
Creates a clip for the given coordinates.
mxSvgCanvas2D.prototype.createClip = function( x, y, w, h )
Updates the text properties for the given node.
mxSvgCanvas2D.prototype.updateFont = function( node )
Background color and border
mxSvgCanvas2D.prototype.addTextBackground = function( node, str, x, y, w, h, align, valign, overflow )
Paints the outline of the current path.
mxSvgCanvas2D.prototype.stroke = function()
Fills the current path.
mxSvgCanvas2D.prototype.fill = function()
Fills and paints the outline of the current path.
mxSvgCanvas2D.prototype.fillAndStroke = function()