Base class for all shapes. A shape in mxGraph is a separate implementation for SVG, VML and HTML. Which implementation to use is controlled by the dialect property which is assigned from within the mxCellRenderer when the shape is created. The dialect must be assigned for a shape, and it does normally depend on the browser and the confiuration of the graph (see mxGraph rendering hint).
For each supported shape in SVG and VML, a corresponding shape exists in mxGraph, namely for text, image, rectangle, rhombus, ellipse and polyline. The other shapes are a combination of these shapes (eg. label and swimlane) or they consist of one or more (filled) path objects (eg. actor and cylinder). The HTML implementation is optional but may be required for a HTML-only view of the graph.
To extend from this class, the basic code looks as follows. In the special case where the custom shape consists only of one filled region or one filled region and an additional stroke the mxActor and mxCylinder should be subclassed, respectively. These implement redrawPath in order to create the path expression for VML and SVG via a unified API (see mxPath). mxCylinder.redrawPath has an additional boolean argument to draw the foreground and background separately.
function CustomShape() { } CustomShape.prototype = new mxShape(); CustomShape.prototype.constructor = CustomShape;
To register a custom shape in an existing graph instance, one must register the shape under a new name in the graph’s cell renderer as follows:
graph.cellRenderer.registerShape('customShape', CustomShape);
The second argument is the name of the constructor.
In order to use the shape you can refer to the given name above in a stylesheet. For example, to change the shape for the default vertex style, the following code is used:
var style = graph.getStylesheet().getDefaultVertexStyle(); style[mxConstants.STYLE_SHAPE] = 'customShape';
mxShape | Base class for all shapes. |
Functions | |
mxShape | Constructs a new shape. |
Variables | |
SVG_STROKE_TOLERANCE | Event-tolerance for SVG strokes (in px). |
scale | Holds the scale in which the shape is being painted. |
dialect | Holds the dialect in which the shape is to be painted. |
crisp | Special attribute for SVG rendering to set the shape-rendering attribute to crispEdges in the output. |
roundedCrispSvg | Specifies if crisp rendering should be enabled for rounded shapes. |
mixedModeHtml | Specifies if createHtml should be used in mixed Html mode. |
preferModeHtml | Specifies if createHtml should be used in prefer Html mode. |
bounds | Holds the mxRectangle that specifies the bounds of this shape. |
points | Holds the array of mxPoints that specify the points of this shape. |
node | Holds the outermost DOM node that represents this shape. |
label | Reference to the DOM node that should contain the label. |
innerNode | Holds the DOM node that graphically represents this shape. |
style | Holds the style of the cell state that corresponds to this shape. |
startOffset | Specifies the offset in pixels from the first point in points and the actual start of the shape. |
endOffset | Specifies the offset in pixels from the last point in points and the actual start of the shape. |
vmlNodes | Array if VML node names to fix in IE8 standards mode. |
Functions | |
setCursor | Sets the cursor on the given shape. |
getCursor | Returns the current cursor. |
init | Initializes the shape by creaing the DOM node using create and adding it into the given container. |
insertGradient | Inserts the given gradient node. |
isMixedModeHtml | Used to determine if a shape can be rendered using createHtml in mixed mode Html without compromising the display accuracy. |
create | Creates and returns the DOM node(s) for the shape in the given container. |
createHtml | Creates and returns the HTML DOM node(s) to represent this shape. |
destroy | Destroys the shape by removing it from the DOM and releasing the DOM node associated with the shape using mxEvent.release. |
apply | Applies the style of the given mxCellState to the shape. |
createSvgGroup | Creates a SVG group element and adds the given shape as a child of the element. |
createSvgShadow | Creates a clone of the given node and configures the node’s color to use mxConstants.SHADOWCOLOR. |
configureHtmlShape | Configures the specified HTML node by applying the current color, bounds, shadow, opacity etc. |
updateVmlFill | Updates the given VML fill node. |
updateVmlStrokeNode | Creates the stroke node for VML. |
updateVmlStrokeColor | Updates the VML stroke color for the given node. |
configureVmlShape | Configures the specified VML node by applying the current color, bounds, shadow, opacity etc. |
createVmlShadow | Creates the VML shadow node. |
configureTransparentBackground | Hook to make the background of a shape transparent. |
configureSvgShape | Configures the specified SVG node by applying the current color, bounds, shadow, opacity etc. |
getGradientId | Creates a unique ID for the gradient of this shape. |
createSvgPipe | Creates an invisible path which is used to increase the hit detection for edges in SVG. |
createSvgGradient | Creates a gradient object for SVG using the specified startcolor, endcolor and opacity. |
createPoints | Creates a path expression using the specified commands for this.points. |
updateHtmlShape | Updates the bounds or points of the specified HTML node and updates the inner children to reflect the changes. |
updateVmlDashStyle | Updates the dashstyle in the stroke node. |
updateVmlShape | Updates the bounds or points of the specified VML node and updates the inner children to reflect the changes. |
updateSvgBounds | Updates the bounds of the given node using bounds. |
updateSvgPath | Updates the path of the given node using points. |
updateSvgScale | Updates the properties of the given node that depend on the scale and checks the crisp rendering attribute. |
updateSvgShape | Updates the bounds or points of the specified SVG node and updates the inner children to reflect the changes. |
getSvgShadowTransform | Returns the current transformation for SVG shadows. |
updateSvgTransform | Updates the tranform of the given node. |
reconfigure | Reconfigures this shape. |
redraw | Invokes redrawSvg, redrawVml or redrawHtml depending on the dialect of the shape. |
redrawSvg | Redraws this SVG shape by invoking updateSvgShape on this.node, this.innerNode and this.shadowNode. |
updateVmlGlassPane | Draws the glass overlay if mxConstants.STYLE_GLASS is 1. |
updateSvgGlassPane | Draws the glass overlay if mxConstants.STYLE_GLASS is 1. |
redrawVml | Redraws this VML shape by invoking updateVmlShape on this.node. |
redrawHtml | Redraws this HTML shape by invoking updateHtmlShape on this.node. |
getRotation | Returns the current rotation including direction. |
createPath | Creates an mxPath for the specified format and origin. |
redrawPath | Draws the path for this shape. |
mxShape.prototype.dialect
Holds the dialect in which the shape is to be painted. This can be one of the DIALECT constants in mxConstants.
mxShape.prototype.crisp
Special attribute for SVG rendering to set the shape-rendering attribute to crispEdges in the output. This is ignored in IE. Default is false. To disable antialias in IE, the explorer.css file can be changed as follows:
[code] v\:* { behavior: url(#default#VML); antialias: false; } [/code]
mxShape.prototype.mixedModeHtml
Specifies if createHtml should be used in mixed Html mode. Default is true.
mxShape.prototype.preferModeHtml
Specifies if createHtml should be used in prefer Html mode. Default is true.
mxShape.prototype.bounds
Holds the mxRectangle that specifies the bounds of this shape.
mxShape.prototype.points
Holds the array of mxPoints that specify the points of this shape.
mxShape.prototype.innerNode
Holds the DOM node that graphically represents this shape. This may be null if the outermost DOM node represents this shape.
mxShape.prototype.startOffset
Specifies the offset in pixels from the first point in points and the actual start of the shape.
mxShape.prototype.endOffset
Specifies the offset in pixels from the last point in points and the actual start of the shape.
mxShape.prototype.init = function( container )
Initializes the shape by creaing the DOM node using create and adding it into the given container.
container | DOM node that will contain the shape. |
mxShape.prototype.isMixedModeHtml = function()
Used to determine if a shape can be rendered using createHtml in mixed mode Html without compromising the display accuracy. The default implementation will check if the shape is not rounded and has no gradient, and will use a DIV if that is the case. It will also check if mxShape.mixedModeHtml is true, which is the default settings. Subclassers can either override mixedModeHtml or this function if the result depends on dynamic values. The graph’s dialect is available via dialect.
mxShape.prototype.create = function( container )
Creates and returns the DOM node(s) for the shape in the given container. This implementation invokes <createSvg>, createHtml or <createVml> depending on the dialect and style settings.
container | DOM node that will contain the shape. |
mxShape.prototype.destroy = function()
Destroys the shape by removing it from the DOM and releasing the DOM node associated with the shape using mxEvent.release.
mxShape.prototype.apply = function( state )
Applies the style of the given mxCellState to the shape. This implementation assigns the following styles to local fields:
This keeps a reference to the style. If you need to keep a reference to the cell, you can override this method and store a local reference to state.cell or the mxCellState itself.
state | mxCellState of the corresponding cell. |
mxShape.prototype.createSvgGroup = function( shape )
Creates a SVG group element and adds the given shape as a child of the element. The child is stored in innerNode for later access.
mxShape.prototype.createSvgShadow = function( node )
Creates a clone of the given node and configures the node’s color to use mxConstants.SHADOWCOLOR.
mxShape.prototype.configureTransparentBackground = function( node )
Hook to make the background of a shape transparent. This hook was added as a workaround for the “display non secure items” warning dialog in IE which appears if the background:url(transparent.gif) is used in the overlay pane of a diagram. Since only mxImageShapes currently exist in the overlay pane this function is only overridden in mxImageShape.
mxShape.prototype.updateSvgBounds = function( node )
Updates the bounds of the given node using bounds.
mxShape.prototype.updateSvgPath = function( node )
Updates the path of the given node using points.
mxShape.prototype.redraw = function()
Invokes redrawSvg, redrawVml or redrawHtml depending on the dialect of the shape.
mxShape.prototype.redrawSvg = function()
Redraws this SVG shape by invoking updateSvgShape on this.node, this.innerNode and this.shadowNode.
mxShape.prototype.redrawVml = function()
Redraws this VML shape by invoking updateVmlShape on this.node.
mxShape.prototype.redrawHtml = function()
Redraws this HTML shape by invoking updateHtmlShape on this.node.
mxShape.prototype.createPath = function( arg )
Creates an mxPath for the specified format and origin. The path object is then passed to redrawPath and mxPath.getPath is returned.
mxShape.prototype.redrawPath = function( path, x, y, w, h )
Draws the path for this shape. This implementation is empty. See mxActor and mxCylinder for implementations.
Constructs a new shape.
function mxShape()
Event-tolerance for SVG strokes (in px).
mxShape.prototype.SVG_STROKE_TOLERANCE
Holds the scale in which the shape is being painted.
mxShape.prototype.scale
Holds the dialect in which the shape is to be painted.
mxShape.prototype.dialect
Special attribute for SVG rendering to set the shape-rendering attribute to crispEdges in the output.
mxShape.prototype.crisp
Specifies if crisp rendering should be enabled for rounded shapes.
mxShape.prototype.roundedCrispSvg
Specifies if createHtml should be used in mixed Html mode.
mxShape.prototype.mixedModeHtml
Creates and returns the HTML DOM node(s) to represent this shape.
mxShape.prototype.createHtml = function()
Specifies if createHtml should be used in prefer Html mode.
mxShape.prototype.preferModeHtml
Holds the mxRectangle that specifies the bounds of this shape.
mxShape.prototype.bounds
Holds the array of mxPoints that specify the points of this shape.
mxShape.prototype.points
Holds the outermost DOM node that represents this shape.
mxShape.prototype.node
Reference to the DOM node that should contain the label.
mxShape.prototype.label
Holds the DOM node that graphically represents this shape.
mxShape.prototype.innerNode
Holds the style of the cell state that corresponds to this shape.
mxShape.prototype.style
Specifies the offset in pixels from the first point in points and the actual start of the shape.
mxShape.prototype.startOffset
Specifies the offset in pixels from the last point in points and the actual start of the shape.
mxShape.prototype.endOffset
Array if VML node names to fix in IE8 standards mode.
mxShape.prototype.vmlNodes
Sets the cursor on the given shape.
mxShape.prototype.setCursor = function( cursor )
Returns the current cursor.
mxShape.prototype.getCursor = function()
Initializes the shape by creaing the DOM node using create and adding it into the given container.
mxShape.prototype.init = function( container )
Creates and returns the DOM node(s) for the shape in the given container.
mxShape.prototype.create = function( container )
Inserts the given gradient node.
mxShape.prototype.insertGradient = function( node )
Used to determine if a shape can be rendered using createHtml in mixed mode Html without compromising the display accuracy.
mxShape.prototype.isMixedModeHtml = function()
Destroys the shape by removing it from the DOM and releasing the DOM node associated with the shape using mxEvent.release.
mxShape.prototype.destroy = function()
Removes the known listeners from the given DOM node and its descendants.
release: function( element )
Applies the style of the given mxCellState to the shape.
mxShape.prototype.apply = function( state )
Creates a SVG group element and adds the given shape as a child of the element.
mxShape.prototype.createSvgGroup = function( shape )
Creates a clone of the given node and configures the node’s color to use mxConstants.SHADOWCOLOR.
mxShape.prototype.createSvgShadow = function( node )
Configures the specified HTML node by applying the current color, bounds, shadow, opacity etc.
mxShape.prototype.configureHtmlShape = function( node )
Updates the given VML fill node.
mxShape.prototype.updateVmlFill = function( node, c1, c2, dir, alpha )
Creates the stroke node for VML.
mxShape.prototype.updateVmlStrokeNode = function( parent )
Updates the VML stroke color for the given node.
mxShape.prototype.updateVmlStrokeColor = function( node )
Configures the specified VML node by applying the current color, bounds, shadow, opacity etc.
mxShape.prototype.configureVmlShape = function( node )
Creates the VML shadow node.
mxShape.prototype.createVmlShadow = function( node )
Hook to make the background of a shape transparent.
mxShape.prototype.configureTransparentBackground = function( node )
Configures the specified SVG node by applying the current color, bounds, shadow, opacity etc.
mxShape.prototype.configureSvgShape = function( node )
Creates a unique ID for the gradient of this shape.
mxShape.prototype.getGradientId = function( start, end )
Creates an invisible path which is used to increase the hit detection for edges in SVG.
mxShape.prototype.createSvgPipe = function( id, start, end, node )
Creates a gradient object for SVG using the specified startcolor, endcolor and opacity.
mxShape.prototype.createSvgGradient = function( id, start, end, node )
Creates a path expression using the specified commands for this.points.
mxShape.prototype.createPoints = function( moveCmd, lineCmd, curveCmd, isRelative )
Updates the bounds or points of the specified HTML node and updates the inner children to reflect the changes.
mxShape.prototype.updateHtmlShape = function( node )
Updates the dashstyle in the stroke node.
mxShape.prototype.updateVmlDashStyle = function()
Updates the bounds or points of the specified VML node and updates the inner children to reflect the changes.
mxShape.prototype.updateVmlShape = function( node )
Updates the bounds of the given node using bounds.
mxShape.prototype.updateSvgBounds = function( node )
Updates the path of the given node using points.
mxShape.prototype.updateSvgPath = function( node )
Updates the properties of the given node that depend on the scale and checks the crisp rendering attribute.
mxShape.prototype.updateSvgScale = function( node )
Updates the bounds or points of the specified SVG node and updates the inner children to reflect the changes.
mxShape.prototype.updateSvgShape = function( node )
Returns the current transformation for SVG shadows.
mxShape.prototype.getSvgShadowTransform = function( node, shadow )
Updates the tranform of the given node.
mxShape.prototype.updateSvgTransform = function( node, shadow )
Reconfigures this shape.
mxShape.prototype.reconfigure = function()
Invokes redrawSvg, redrawVml or redrawHtml depending on the dialect of the shape.
mxShape.prototype.redraw = function()
Redraws this SVG shape by invoking updateSvgShape on this.node, this.innerNode and this.shadowNode.
mxShape.prototype.redrawSvg = function()
Redraws this VML shape by invoking updateVmlShape on this.node.
mxShape.prototype.redrawVml = function()
Redraws this HTML shape by invoking updateHtmlShape on this.node.
mxShape.prototype.redrawHtml = function()
Draws the glass overlay if mxConstants.STYLE_GLASS is 1.
mxShape.prototype.updateVmlGlassPane = function()
Draws the glass overlay if mxConstants.STYLE_GLASS is 1.
mxShape.prototype.updateSvgGlassPane = function()
Returns the current rotation including direction.
mxShape.prototype.getRotation = function()
Creates an mxPath for the specified format and origin.
mxShape.prototype.createPath = function( arg )
Draws the path for this shape.
mxShape.prototype.redrawPath = function( path, x, y, w, h )
Draws the path for this shape.
mxCylinder.prototype.redrawPath = function( path, x, y, w, h, isForeground )
Returns string that represents the path in format.
mxPath.prototype.getPath = function()