mxStencil

Implements a generic shape which is based on a XML node as a description.  The node contains a background and a foreground node, which contain the definition to render the respective part of the shape.  Note that the fill, stroke or fillstroke of the background is be the first statement of the foreground.  This is because the content of the background node maybe used to not only render the shape itself, but also its shadow and other elements which do not require a fill, stroke or fillstroke.

The shape uses a coordinate system with a width of 100 and a height of 100 by default.  This can be changed by setting the w and h attribute of the shape element.  The aspect attribute can be set to “variable” (default) or “fixed”.  If fixed is used, then the aspect which is defined via the w and h attribute is kept constant while the shape is scaled.

The possible contents of the background and foreground elements are rect, ellipse, roundrect, text, image, include-shape or paths.  A path element contains move, line, curve, quad, arc and close elements.  The rect, ellipse and roundrect elements may be thought of as special path elements.  All these path elements must be followed by either fill, stroke or fillstroke (note that text, image and include-shape or not path elements).

The background element can be empty or contain at most one path element.  It should not contain a text, image or include-shape element.  If the background element is empty, then no shadow or glass effect will be rendered.  If the background element is non-empty, then the corresponding fill, stroke or fillstroke should be the first element in the subsequent foreground element.

The format of the XML is “a simplified HTML 5 Canvas”.  Each command changes the “current” state, so eg. a linecap, linejoin will be used for all subsequent line drawing, unless a save/restore appears, which saves/restores a state in a stack.

The connections section contains the fixed connection points for a stencil.  The perimeter attribute of the constraint element should have a value of 0 or 1 (default), where 1 (true) specifies that the given point should be projected into the perimeter of the given shape.

The x- and y-coordinates are typically between 0 and 1 and define the location of the connection point relative to the width and height of the shape.

The dashpattern directive sets the current dashpattern.  The format for the pattern attribute is a space-separated sequence of numbers, eg.  5 5 5 5, that specifies the lengths of alternating dashes and spaces in dashed lines.  The dashpattern should be used together with the dashed directive to enabled/disable the dashpattern.  The default dashpattern is 3 3.

The strokewidth attribute defines a strokewidth behaviour for the shape.  It can contain a numeric value or the keyword “inherit”, which means that the strokeWidth of the cell is only changed on scaling, not on resizing.  If numeric values are used, the strokeWidth of the cell is changed on both scaling and resizing and the value defines the multiple that is applied to the width.

To support i18n in the text element, use the localized attribute of 1 to use the str as a key in mxResources.get.  To handle all str attributes of all text nodes like this, set the mxStencil.defaultLocalized value to true.

Summary
mxStencilImplements a generic shape which is based on a XML node as a description.
Functions
mxStencilConstructs a new generic shape by setting desc to the given XML node and invoking parseDescription and parseConstraints.
Variables
defaultLocalizedStatic global variable that specifies the default value for the localized attribute of the text element.
Functions
allowEvalStatic global switch that specifies if the use of eval is allowed for evaluating text content.
Variables
descHolds the XML node with the stencil description.
constraintsHolds an array of mxConnectionConstraints as defined in the shape.
aspectHolds the aspect of the shape.
w0Holds the width of the shape.
h0Holds the height of the shape.
bgNodesHolds the XML node with the stencil description.
fgNodesHolds the XML node with the stencil description.
strokewidthHolds the strokewidth direction from the description.
Functions
parseDescriptionReads w0, h0, aspect, bgNodes and fgNodes from desc.
parseConstraintsReads the constraints from desc into constraints using parseConstraint.
parseConstraintParses the given XML node and returns its mxConnectionConstraint.
evaluateTextAttributeGets the given attribute as a text.
evaluateAttributeGets the attribute for the given name from the given node.
drawShapeDraws this stencil inside the given bounds.
drawShapeDraws this stencil inside the given bounds.
computeAspectReturns a rectangle that contains the offset in x and y and the horizontal and vertical scale in width and height used to draw this shape inside the given mxRectangle.
drawNodeDraws this stencil inside the given bounds.

Functions

mxStencil

function mxStencil(desc)

Constructs a new generic shape by setting desc to the given XML node and invoking parseDescription and parseConstraints.

Parameters

descXML node that contains the stencil description.

Variables

defaultLocalized

mxStencil.defaultLocalized

Static global variable that specifies the default value for the localized attribute of the text element.  Default is false.

Functions

allowEval

Static global switch that specifies if the use of eval is allowed for evaluating text content.  Default is true.  Set this to false if stencils may contain user input (see the section on security in the manual).

Variables

desc

mxStencil.prototype.desc

Holds the XML node with the stencil description.

constraints

mxStencil.prototype.constraints

Holds an array of mxConnectionConstraints as defined in the shape.

aspect

mxStencil.prototype.aspect

Holds the aspect of the shape.  Default is ‘auto’.

w0

mxStencil.prototype.w0

Holds the width of the shape.  Default is 100.

h0

mxStencil.prototype.h0

Holds the height of the shape.  Default is 100.

bgNodes

Holds the XML node with the stencil description.

fgNodes

Holds the XML node with the stencil description.

strokewidth

mxStencil.prototype.strokewidth

Holds the strokewidth direction from the description.

Functions

parseDescription

mxStencil.prototype.parseDescription = function()

Reads w0, h0, aspect, bgNodes and fgNodes from desc.

parseConstraints

mxStencil.prototype.parseConstraints = function()

Reads the constraints from desc into constraints using parseConstraint.

parseConstraint

mxStencil.prototype.parseConstraint = function(node)

Parses the given XML node and returns its mxConnectionConstraint.

evaluateTextAttribute

mxStencil.prototype.evaluateTextAttribute = function(node,
attribute,
state)

Gets the given attribute as a text.  The return value from evaluateAttribute is used as a key to mxResources.get if the localized attribute in the text node is 1 or if defaultLocalized is true.

evaluateAttribute

mxStencil.prototype.evaluateAttribute = function(node,
attribute,
shape)

Gets the attribute for the given name from the given node.  If the attribute does not exist then the text content of the node is evaluated and if it is a function it is invoked with <state> as the only argument and the return value is used as the attribute value to be returned.

drawShape

mxStencil.prototype.drawShape = function(canvas,
shape,
x,
y,
w,
h)

Draws this stencil inside the given bounds.

drawShape

Draws this stencil inside the given bounds.

computeAspect

mxStencil.prototype.computeAspect = function(shape,
x,
y,
w,
h,
direction)

Returns a rectangle that contains the offset in x and y and the horizontal and vertical scale in width and height used to draw this shape inside the given mxRectangle.

Parameters

shapemxShape to be drawn.
boundsmxRectangle that should contain the stencil.
directionOptional direction of the shape to be darwn.

drawNode

mxStencil.prototype.drawNode = function(canvas,
shape,
node,
aspect,
disableShadow)

Draws this stencil inside the given bounds.

function mxStencil(desc)
Constructs a new generic shape by setting desc to the given XML node and invoking parseDescription and parseConstraints.
mxStencil.prototype.desc
Holds the XML node with the stencil description.
mxStencil.prototype.parseDescription = function()
Reads w0, h0, aspect, bgNodes and fgNodes from desc.
mxStencil.prototype.parseConstraints = function()
Reads the constraints from desc into constraints using parseConstraint.
mxStencil.defaultLocalized
Static global variable that specifies the default value for the localized attribute of the text element.
mxStencil.prototype.constraints
Holds an array of mxConnectionConstraints as defined in the shape.
Defines an object that contains the constraints about how to connect one side of an edge to its terminal.
mxStencil.prototype.aspect
Holds the aspect of the shape.
mxStencil.prototype.w0
Holds the width of the shape.
mxStencil.prototype.h0
Holds the height of the shape.
mxStencil.prototype.strokewidth
Holds the strokewidth direction from the description.
Holds the XML node with the stencil description.
Holds the XML node with the stencil description.
mxStencil.prototype.parseConstraint = function(node)
Parses the given XML node and returns its mxConnectionConstraint.
mxStencil.prototype.evaluateTextAttribute = function(node,
attribute,
state)
Gets the given attribute as a text.
mxStencil.prototype.evaluateAttribute = function(node,
attribute,
shape)
Gets the attribute for the given name from the given node.
mxStencil.prototype.drawShape = function(canvas,
shape,
x,
y,
w,
h)
Draws this stencil inside the given bounds.
mxStencil.prototype.computeAspect = function(shape,
x,
y,
w,
h,
direction)
Returns a rectangle that contains the offset in x and y and the horizontal and vertical scale in width and height used to draw this shape inside the given mxRectangle.
Extends mxPoint to implement a 2-dimensional rectangle with double precision coordinates.
mxStencil.prototype.drawNode = function(canvas,
shape,
node,
aspect,
disableShadow)
Draws this stencil inside the given bounds.
get: function(key,
params,
defaultValue)
Returns the value for the specified resource key.
Base class for all shapes.
Close