mxUtils

Helper methods.

Summary
mxUtilsHelper methods.
Functions
getLabelSizeReturns the size of the given label.
getLabelPaintBoundsReturns the paint bounds for the given label.
getScaledLabelBoundsReturns the bounds for a label for the given location and size, taking into account the alignment and spacing in the specified style, as well as the width and height of the rectangle that contains the label.
getSizeForStringReturns an mxRectangle with the size (width and height in pixels) of the given string.
flipImageFlips the given image horizontally and/or vertically and returns a new image instance.
toRadiansConverts the given degree to radians.
getBoundingBoxReturns the bounding box for the rotated rectangle.
getRotatedPointRotates the given point by the given cos and sin.
translatePointsCreates a new list of new points obtained by translating the points in the given list by the given vector.
containsReturns true if the specified point (x, y) is contained in the given rectangle.
intersectionReturns the intersection of two lines as an mxPoint.
encodeImageEncodes the given image using the GD image encoding routines.
getStylenameReturns the stylename in a style of the form [stylename;|key=value;] or an empty string if the given style does not contain a stylename.
getStylenamesReturns the stylenames in a style of the form [stylename;|key=value;] or an empty array if the given style does not contain any stylenames.
indexOfStylenameReturns the index of the given stylename in the given style.
addStylenameAdds the specified stylename to the given style if it does not already contain the stylename.
removeStylenameRemoves all occurrences of the specified stylename in the given style and returns the updated style.
removeAllStylenamesRemoves all stylenames from the given style and returns the updated style.
setCellStylesAssigns the value for the given key in the styles of the given cells, or removes the key from the styles if the value is null.
setStyleAdds or removes the given key, value pair to the style and returns the new style.
setCellStyleFlagsSets or toggles the flag bit for the given key in the cell’s styles.
setStyleFlagSets or removes the given key from the specified style and returns the new style.
getValueReturns the value for key in dictionary or the given default value if no value is defined for the key.
getNumberReturns the value for key in dictionary or 0 if no value is defined for the key.
indexOfReturns the index of obj in array or -1 if the array does not contains the given object.
readFileReads the given filename into a string.
isNodeReturns true if the given value is an XML node with the node name and if the optional attribute has the specified value.
loadImageLoads an image from the local filesystem, a data URI or any other URL.
createXmlDocumentReturns a new, empty XML document.
loadXmlDocumentReturns a new DOM document for the given URI.
parseXmlReturns a new DOM document for the given XML string.
evaluateEvaluates an expression to a class member.
findNodeReturns the first node where attr equals value.
getTrueTypeFontReturns the truetype font to be used to draw the text with the given style.
getTrueTypeFontSizeReturns the truetype font size to be used to draw the text with the given style.
getFixedFontSizeReturns the fixed font size for GD (1 t0 5) for the given font properties
stackTracePrints a simple stack trace in the error log.

Functions

getLabelSize

static function getLabelSize($label,
$style)

Returns the size of the given label.

getLabelPaintBounds

static function getLabelPaintBounds($label,
$style,
$isHtml,
$offset,
$vertexBounds,
$scale)

Returns the paint bounds for the given label.

getScaledLabelBounds

static function getScaledLabelBounds($x,
$y,
$size,
$outerWidth,
$outerHeight,
$style,
$scale)

Returns the bounds for a label for the given location and size, taking into account the alignment and spacing in the specified style, as well as the width and height of the rectangle that contains the label.  (For edge labels this width and height is 0.)  The scale is used to scale the given size and the spacings in the specified style.

getSizeForString

static function getSizeForString($text,  
$fontSize =  0,
$fontFamily =  null)

Returns an mxRectangle with the size (width and height in pixels) of the given string.  The string may contain HTML markup.  Newlines should be converted to <br> before calling this method.

Parameters

textString whose size should be returned.
fontSizeInteger that specifies the font size in pixels.  Default is mxConstants.DEFAULT_FONTSIZE.
fontFamilyString that specifies the name of the font famil.y Default is mxConstants.DEFAULT_FONTFAMILY.

flipImage

static function flipImage($img,
$flipH,
$flipV)

Flips the given image horizontally and/or vertically and returns a new image instance.

toRadians

static function toRadians($deg)

Converts the given degree to radians.

getBoundingBox

static function getBoundingBox($rect,
$rotation)

Returns the bounding box for the rotated rectangle.

getRotatedPoint

static function getRotatedPoint($pt,  
$cos,  
$sin,  
$cx =  null)

Rotates the given point by the given cos and sin.

translatePoints

static function translatePoints($pts,
$dx,
$dy)

Creates a new list of new points obtained by translating the points in the given list by the given vector.  Elements that are not mxPoints are added to the result as-is.

contains

static function contains($state,
$x,
$y)

Returns true if the specified point (x, y) is contained in the given rectangle.

Parameters

boundsmxRectangle that represents the area.
xX-coordinate of the point.
yY-coordinate of the point.

intersection

static function intersection($x0,
$y0,
$x1,
$y1,
$x2,
$y2,
$x3,
$y3)

Returns the intersection of two lines as an mxPoint.

Parameters

x0X-coordinate of the first line’s startpoint.
y0X-coordinate of the first line’s startpoint.
x1X-coordinate of the first line’s endpoint.
y1Y-coordinate of the first line’s endpoint.
x2X-coordinate of the second line’s startpoint.
y2Y-coordinate of the second line’s startpoint.
x3X-coordinate of the second line’s endpoint.
y3Y-coordinate of the second line’s endpoint.

encodeImage

static function encodeImage($image,  
$format = null)

Encodes the given image using the GD image encoding routines.  Supported formats are gif, jpg and png (default).

Parameters

imageGD image to be encoded.
formatString that defines the encoding format.  Default is png.

getStylename

static function getStylename($style)

Returns the stylename in a style of the form [stylename;|key=value;] or an empty string if the given style does not contain a stylename.

Parameters

styleString of the form [stylename;|key=value;].

getStylenames

static function getStylenames($style)

Returns the stylenames in a style of the form [stylename;|key=value;] or an empty array if the given style does not contain any stylenames.

Parameters

styleString of the form [stylename;|key=value;].

indexOfStylename

static function indexOfStylename($style,
$stylename)

Returns the index of the given stylename in the given style.  This returns -1 if the given stylename does not occur (as a stylename) in the given style, otherwise it returns the index of the first character.

addStylename

static function addStylename($style,
$stylename)

Adds the specified stylename to the given style if it does not already contain the stylename.

removeStylename

static function removeStylename($style,
$stylename)

Removes all occurrences of the specified stylename in the given style and returns the updated style.  Trailing semicolons are preserved.

removeAllStylenames

static function removeAllStylenames($style)

Removes all stylenames from the given style and returns the updated style.

setCellStyles

static function setCellStyles($model,
$cells,
$key,
$value)

Assigns the value for the given key in the styles of the given cells, or removes the key from the styles if the value is null.

Parameters

modelmxGraphModel to execute the transaction in.
cellsArray of mxCells to be updated.
keyKey of the style to be changed.
valueNew value for the given key.

setStyle

static function setStyle($style,
$key,
$value)

Adds or removes the given key, value pair to the style and returns the new style.  If value is null or zero length then the key is removed from the style.

Parameters

styleString of the form stylename[;key=value]
keyKey of the style to be changed.
valueNew value for the given key.

setCellStyleFlags

static function setCellStyleFlags($model,
$cells,
$key,
$flag,
$value)

Sets or toggles the flag bit for the given key in the cell’s styles.  If value is null then the flag is toggled.

Example

var cells = graph.getSelectionCells();
mxUtils.setCellStyleFlags(graph.model,
         cells,
         mxConstants.STYLE_FONTSTYLE,
         mxConstants.FONT_BOLD);

Toggles the bold font style.

Parameters

modelmxGraphModel that contains the cells.
cellsArray of mxCells to change the style for.
keyKey of the style to be changed.
flagInteger for the bit to be changed.
valueOptional boolean value for the flag.

setStyleFlag

static function setStyleFlag($style,
$key,
$flag,
$value)

Sets or removes the given key from the specified style and returns the new style.  If value is null then the flag is toggled.

Parameters

styleString of the form stylename[;key=value].
keyKey of the style to be changed.
flagInteger for the bit to be changed.
valueOptional boolean value for the given flag.

getValue

static function getValue($dict,  
$key,  
$default = null)

Returns the value for key in dictionary or the given default value if no value is defined for the key.

Parameters

dictDictionary that contains the key, value pairs.
keyKey whose value should be returned.
defaultDefault value to return if the key is undefined.  Default is null.

getNumber

static function getNumber($dict,  
$key,  
$default = )

Returns the value for key in dictionary or 0 if no value is defined for the key.

Parameters

dictDictionary that contains the key, value pairs.
keyKey whose value should be returned.
defaultOptional default value to return if no value is defined for the given key.  Default is 0.

indexOf

static function indexOf($array,
$object)

Returns the index of obj in array or -1 if the array does not contains the given object.

Parameters

arrayArray to check for the given obj.
objObject to find in the given array.

readFile

static function readFile($filename)

Reads the given filename into a string.  Shortcut for file_get_contents.

Parameters

filenameThe name of the file to read.

isNode

static function isNode($value,  
$nodeName =  null,
$attributeName =  null,
$attributeValue =  null)

Returns true if the given value is an XML node with the node name and if the optional attribute has the specified value.

This implementation assumes that the given value is a DOM node if the nodeName property is not null.

Parameters

valueObject that should be examined as a node.
nodeNameString that specifies the node name.
attributeNameOptional attribute name to check.
attributeValueOptional attribute value to check.

loadImage

static function loadImage($url)

Loads an image from the local filesystem, a data URI or any other URL.

createXmlDocument

static function createXmlDocument()

Returns a new, empty XML document.

loadXmlDocument

static function loadXmlDocument($uri)

Returns a new DOM document for the given URI.

parseXml

static function parseXml($xml)

Returns a new DOM document for the given XML string.

evaluate

static function evaluate($expression)

Evaluates an expression to a class member.  The range of supported expressions is limited to static class members with a dot-notation, such as mxEdgeStyle.ElbowConnector.

findNode

static function findNode($node,
$attr,
$value)

Returns the first node where attr equals value.  This implementation does not use XPath.

getTrueTypeFont

static function getTrueTypeFont($style)

Returns the truetype font to be used to draw the text with the given style.

getTrueTypeFontSize

static function getTrueTypeFontSize($size)

Returns the truetype font size to be used to draw the text with the given style.  This returns the fontSize in the style of the default fontsize multiplied with <ttfSizeFactor>.

getFixedFontSize

static function getFixedFontSize($fontSize,  
$fontFamily,  
$fontStyle = null)

Returns the fixed font size for GD (1 t0 5) for the given font properties

stackTrace

static function stackTrace()

Prints a simple stack trace in the error log.

static function getLabelSize($label,
$style)
Returns the size of the given label.
static function getLabelPaintBounds($label,
$style,
$isHtml,
$offset,
$vertexBounds,
$scale)
Returns the paint bounds for the given label.
static function getScaledLabelBounds($x,
$y,
$size,
$outerWidth,
$outerHeight,
$style,
$scale)
Returns the bounds for a label for the given location and size, taking into account the alignment and spacing in the specified style, as well as the width and height of the rectangle that contains the label.
static function getSizeForString($text,  
$fontSize =  0,
$fontFamily =  null)
Returns an mxRectangle with the size (width and height in pixels) of the given string.
Implements a 2-dimensional rectangle with double precision coordinates.
static function flipImage($img,
$flipH,
$flipV)
Flips the given image horizontally and/or vertically and returns a new image instance.
static function toRadians($deg)
Converts the given degree to radians.
static function getBoundingBox($rect,
$rotation)
Returns the bounding box for the rotated rectangle.
static function getRotatedPoint($pt,  
$cos,  
$sin,  
$cx =  null)
Rotates the given point by the given cos and sin.
static function translatePoints($pts,
$dx,
$dy)
Creates a new list of new points obtained by translating the points in the given list by the given vector.
static function contains($state,
$x,
$y)
Returns true if the specified point (x, y) is contained in the given rectangle.
static function intersection($x0,
$y0,
$x1,
$y1,
$x2,
$y2,
$x3,
$y3)
Returns the intersection of two lines as an mxPoint.
Implements a 2-dimensional point with double precision coordinates.
static function encodeImage($image,  
$format = null)
Encodes the given image using the GD image encoding routines.
static function getStylename($style)
Returns the stylename in a style of the form [stylename;|key=value;] or an empty string if the given style does not contain a stylename.
static function getStylenames($style)
Returns the stylenames in a style of the form [stylename;|key=value;] or an empty array if the given style does not contain any stylenames.
static function indexOfStylename($style,
$stylename)
Returns the index of the given stylename in the given style.
static function addStylename($style,
$stylename)
Adds the specified stylename to the given style if it does not already contain the stylename.
static function removeStylename($style,
$stylename)
Removes all occurrences of the specified stylename in the given style and returns the updated style.
static function removeAllStylenames($style)
Removes all stylenames from the given style and returns the updated style.
static function setCellStyles($model,
$cells,
$key,
$value)
Assigns the value for the given key in the styles of the given cells, or removes the key from the styles if the value is null.
static function setStyle($style,
$key,
$value)
Adds or removes the given key, value pair to the style and returns the new style.
static function setCellStyleFlags($model,
$cells,
$key,
$flag,
$value)
Sets or toggles the flag bit for the given key in the cell’s styles.
static function setStyleFlag($style,
$key,
$flag,
$value)
Sets or removes the given key from the specified style and returns the new style.
static function getValue($dict,  
$key,  
$default = null)
Returns the value for key in dictionary or the given default value if no value is defined for the key.
static function getNumber($dict,  
$key,  
$default = )
Returns the value for key in dictionary or 0 if no value is defined for the key.
static function indexOf($array,
$object)
Returns the index of obj in array or -1 if the array does not contains the given object.
static function readFile($filename)
Reads the given filename into a string.
static function isNode($value,  
$nodeName =  null,
$attributeName =  null,
$attributeValue =  null)
Returns true if the given value is an XML node with the node name and if the optional attribute has the specified value.
static function loadImage($url)
Loads an image from the local filesystem, a data URI or any other URL.
static function createXmlDocument()
Returns a new, empty XML document.
static function loadXmlDocument($uri)
Returns a new DOM document for the given URI.
static function parseXml($xml)
Returns a new DOM document for the given XML string.
static function evaluate($expression)
Evaluates an expression to a class member.
static function findNode($node,
$attr,
$value)
Returns the first node where attr equals value.
static function getTrueTypeFont($style)
Returns the truetype font to be used to draw the text with the given style.
static function getTrueTypeFontSize($size)
Returns the truetype font size to be used to draw the text with the given style.
static function getFixedFontSize($fontSize,  
$fontFamily,  
$fontStyle = null)
Returns the fixed font size for GD (1 t0 5) for the given font properties
static function stackTrace()
Prints a simple stack trace in the error log.
public static $DEFAULT_FONTSIZE
Defines the default size for all fonts in points.
public static $DEFAULT_FONTFAMILY
Defines the default family for all truetype fonts.
Cells are the elements of the graph model.
Cells are the elements of the graph model.
Close