Defines the appearance of the cells in a graph. See putCellStyle for an example of creating a new cell style. It is recommended to use objects, not arrays for holding cell styles. Existing styles can be cloned using mxUtils.clone and turned into a string for debugging using mxUtils.toString.
The stylesheet contains two built-in styles, which are used if no style is defined for a cell:
defaultVertex | Default style for vertices |
defaultEdge | Default style for edges |
var vertexStyle = stylesheet.getDefaultVertexStyle(); vertexStyle[mxConstants.STYLE_ROUNDED] = true; var edgeStyle = stylesheet.getDefaultEdgeStyle(); edgeStyle[mxConstants.STYLE_EDGE] = mxEdgeStyle.EntityRelation;
Modifies the built-in default styles.
To avoid the default style for a cell, add a leading semicolon to the style definition, eg.
;shadow=1
For removing a key in a cell style of the form [stylename;|key=value;] the special value none can be used, eg. highlight;fillColor=none
See also the helper methods in mxUtils to modify strings of this format, namely mxUtils.setStyle, mxUtils.indexOfStylename, mxUtils.addStylename, mxUtils.removeStylename, mxUtils.removeAllStylenames and mxUtils.setStyleFlag.
mxStylesheet | Defines the appearance of the cells in a graph. |
Functions | |
mxStylesheet | Constructs a new stylesheet and assigns default styles. |
styles | Maps from names to cell styles. |
createDefaultVertexStyle | Creates and returns the default vertex style. |
createDefaultEdgeStyle | Creates and returns the default edge style. |
putDefaultVertexStyle | Sets the default style for vertices using defaultVertex as the stylename. |
putDefaultEdgeStyle | Sets the default style for edges using defaultEdge as the stylename. |
getDefaultVertexStyle | Returns the default style for vertices. |
getDefaultEdgeStyle | Sets the default style for edges. |
putCellStyle | Stores the given map of key, value pairs under the given name in styles. |
getCellStyle | Returns the cell style for the specified stylename or the given defaultStyle if no style can be found for the given stylename. |
mxStylesheet.prototype.putCellStyle = function( name, style )
Stores the given map of key, value pairs under the given name in styles.
The following example adds a new style called ‘rounded’ into an existing stylesheet:
var style = new Object(); style[mxConstants.STYLE_SHAPE] = mxConstants.SHAPE_RECTANGLE; style[mxConstants.STYLE_PERIMETER] = mxPerimeter.RectanglePerimeter; style[mxConstants.STYLE_ROUNDED] = true; graph.getStylesheet().putCellStyle('rounded', style);
In the above example, the new style is an object. The possible keys of the object are all the constants in mxConstants that start with STYLE and the values are either JavaScript objects, such as <mxPerimeter.RightAngleRectanglePerimeter> (which is in fact a function) or expressions, such as true. Note that not all keys will be interpreted by all shapes (eg. the line shape ignores the fill color). The final call to this method associates the style with a name in the stylesheet. The style is used in a cell with the following code:
model.setStyle(cell, 'rounded');
name | Name for the style to be stored. |
style | Key, value pairs that define the style. |
mxStylesheet.prototype.getCellStyle = function( name, defaultStyle )
Returns the cell style for the specified stylename or the given defaultStyle if no style can be found for the given stylename.
name | String of the form [(stylename|key=value);] that represents the style. |
defaultStyle | Default style to be returned if no style can be found. |
Constructs a new stylesheet and assigns default styles.
function mxStylesheet()
Creates and returns the default vertex style.
mxStylesheet.prototype.createDefaultVertexStyle = function()
Creates and returns the default edge style.
mxStylesheet.prototype.createDefaultEdgeStyle = function()
Sets the default style for vertices using defaultVertex as the stylename.
mxStylesheet.prototype.putDefaultVertexStyle = function( style )
Sets the default style for edges using defaultEdge as the stylename.
mxStylesheet.prototype.putDefaultEdgeStyle = function( style )
Returns the default style for vertices.
mxStylesheet.prototype.getDefaultVertexStyle = function()
Sets the default style for edges.
mxStylesheet.prototype.getDefaultEdgeStyle = function()
Stores the given map of key, value pairs under the given name in styles.
mxStylesheet.prototype.putCellStyle = function( name, style )
Returns the cell style for the specified stylename or the given defaultStyle if no style can be found for the given stylename.
mxStylesheet.prototype.getCellStyle = function( name, defaultStyle )
Recursively clones the specified object ignoring all fieldnames in the given array of transient fields.
clone: function( obj, transients, shallow )
Returns a textual representation of the specified object.
toString: function( obj )
Adds or removes the given key, value pair to the style and returns the new style.
setStyle: function( style, key, value )
Returns the index of the given stylename in the given style.
indexOfStylename: function( style, stylename )
Adds the specified stylename to the given style if it does not already contain the stylename.
addStylename: function( style, stylename )
Removes all occurrences of the specified stylename in the given style and returns the updated style.
removeStylename: function( style, stylename )
Removes all stylenames from the given style and returns the updated style.
removeAllStylenames: function( style )
Sets or removes the given key from the specified style and returns the new style.
setStyleFlag: function( style, key, flag, value )