Extends mxEventSource to implement an application wrapper for a graph that adds actions, I/O using mxCodec, auto-layout using mxLayoutManager, command history using undoManager, and standard dialogs and widgets, eg. properties, help, outline, toolbar, and popupmenu. It also adds templates to be used as cells in toolbars, auto-validation using the <validation> flag, attribute cycling using cycleAttributeValues, higher-level events such as <root>, and backend integration using urlPost and urlImage.
Actions are functions stored in the actions array under their names. The functions take the mxEditor as the first, and an optional mxCell as the second argument and are invoked using execute. Any additional arguments passed to execute are passed on to the action as-is.
A list of built-in actions is available in the addActions description.
To read a diagram from an XML string, for example from a textfield within the page, the following code is used:
var doc = mxUtils.parseXML(xmlString); var node = doc.documentElement; editor.readGraphModel(node);
For reading a diagram from a remote location, use the open method.
To save diagrams in XML on a server, you can set the urlPost variable. This variable will be used in getUrlPost to construct a URL for the post request that is issued in the save method. The post request contains the XML representation of the diagram as returned by writeGraphModel in the xml parameter.
On the server side, the post request is processed using standard technologies such as Java Servlets, CGI, .NET or ASP.
Here are some examples of processing a post request in various languages.
Note that the linefeeds should only be replaced if the XML is processed in Java, for example when creating an image, but not if the XML is passed back to the client-side.
A backend (Java, PHP or C#) is required for creating images. The distribution contains an example for each backend (ImageHandler.java, ImageHandler.cs and graph.php). More information about using a backend to create images can be found in the readme.html files. Note that the preview is implemented using VML/SVG in the browser and does not require a backend. The backend is only required to creates images (bitmaps).
Note There are five characters that should always appear in XML content as escapes, so that they do not interact with the syntax of the markup. These are part of the language for all documents based on XML and for HTML.
Although it is part of the XML language, ' is not defined in HTML. For this reason the XHTML specification recommends instead the use of ' if text may be passed to a HTML user agent.
If you are having problems with special characters on the server-side then you may want to try the escapePostData flag.
For converting decimal escape sequences inside strings, a user has provided us with the following function:
function html2js(text) { var entitySearch = /&#[0-9]+;/; var entity; while (entity = entitySearch.exec(text)) { var charCode = entity[0].substring(2, entity[0].length -1); text = text.substring(0, entity.index) + String.fromCharCode(charCode) + text.substring(entity.index + entity[0].length); } return text; }
Otherwise try using hex escape sequences and the built-in unescape function for converting such strings.
For saving and opening local files, no standardized method exists that works across all browsers. The recommended way of dealing with local files is to create a backend that streams the XML data back to the browser (echo) as an attachment so that a Save-dialog is displayed on the client-side and the file can be saved to the local disk.
For example, in PHP the code that does this looks as follows.
$xml = stripslashes($_POST["xml"]); header("Content-Disposition: attachment; filename=\"diagram.xml\""); echo($xml);
To open a local file, the file should be uploaded via a form in the browser and then opened from the server in the editor.
The properties displayed in the properties dialog are the attributes and values of the cell’s user object, which is an XML node. The XML node is defined in the templates section of the config file.
The templates are stored in mxEditor.templates and contain cells which are cloned at insertion time to create new vertices by use of drag and drop from the toolbar. Each entry in the toolbar for adding a new vertex must refer to an existing template.
In the following example, the task node is a business object and only the mxCell node and its mxGeometry child contain graph information:
<Task label="Task" description=""> <mxCell vertex="true"> <mxGeometry as="geometry" width="72" height="32"/> </mxCell> </Task>
The idea is that the XML representation is inverse from the in-memory representation: The outer XML node is the user object and the inner node is the cell. This means the user object of the cell is the Task node with no children for the above example:
<Task label="Task" description=""/>
The Task node can have any tag name, attributes and child nodes. The mxCodec will use the XML hierarchy as the user object, while removing the “known annotations”, such as the mxCell node. At save-time the cell data will be “merged” back into the user object. The user object is only modified via the properties dialog during the lifecycle of the cell.
In the default implementation of createProperties, the user object’s attributes are put into a form for editing. Attributes are changed using the mxCellAttributeChange action in the model. The dialog can be replaced by overriding the createProperties hook or by replacing the showProperties action in actions. Alternatively, the entry in the config file’s popupmenu section can be modified to invoke a different action.
If you want to displey the properties dialog on a doubleclick, you can set mxEditor.dblClickAction to showProperties as follows:
editor.dblClickAction = 'showProperties';
The toolbar and popupmenu are typically configured using the respective sections in the config file, that is, the popupmenu is defined as follows:
<mxEditor> <mxDefaultPopupMenu as="popupHandler"> <add as="cut" action="cut" icon="images/cut.gif"/> ...
New entries can be added to the toolbar by inserting an add-node into the above configuration. Existing entries may be removed and changed by modifying or removing the respective entries in the configuration. The configuration is read by the mxDefaultPopupMenuCodec, the format of the configuration is explained in <mxDefaultPopupMenu.decode>.
The toolbar is defined in the mxDefaultToolbar section. Items can be added and removed in this section.
<mxEditor> <mxDefaultToolbar> <add as="save" action="save" icon="images/save.gif"/> <add as="Swimlane" template="swimlane" icon="images/swimlane.gif"/> ...
The format of the configuration is described in mxDefaultToolbarCodec.decode.
For the IDs, there is an implicit behaviour in mxCodec: It moves the Id from the cell to the user object at encoding time and vice versa at decoding time. For example, if the Task node from above has an id attribute, then the mxCell.id of the corresponding cell will have this value. If there is no Id collision in the model, then the cell may be retrieved using this Id with the mxGraphModel.getCell function. If there is a collision, a new Id will be created for the cell using mxGraphModel.createId. At encoding time, this new Id will replace the value previously stored under the id attribute in the Task node.
See mxEditorCodec, mxDefaultToolbarCodec and mxDefaultPopupMenuCodec for information about configuring the editor and user interface.
For inserting a new cell, say, by clicking a button in the document, the following code can be used. This requires an reference to the editor.
var userObject = new Object(); var parent = editor.graph.getDefaultParent(); var model = editor.graph.model; model.beginUpdate(); try { editor.graph.insertVertex(parent, null, userObject, 20, 20, 80, 30); } finally { model.endUpdate(); }
If a template cell from the config file should be inserted, then a clone of the template can be created as follows. The clone is then inserted using the add function instead of addVertex.
var template = editor.templates['task']; var clone = editor.graph.model.cloneCell(template);
resources/editor | Language resources for mxEditor |
mxEditor | Extends mxEventSource to implement an application wrapper for a graph that adds actions, I/O using mxCodec, auto-layout using mxLayoutManager, command history using undoManager, and standard dialogs and widgets, eg. |
onInit | Called from within the constructor. |
mxgraph=seen | Set when the editor is started. |
mxEvent.OPEN | Fires after a file was opened in open. |
mxEvent.SAVE | Fires after the current file was saved in save. |
mxEvent.POST | Fires if a successful response was received in postDiagram. |
mxEvent.ROOT | Fires when the current root has changed, or when the title of the current root has changed. |
mxEvent. | Fires before a vertex is added in addVertex. |
mxEvent. | Fires between begin- and endUpdate in addVertex. |
mxEvent. | Fires after a vertex was inserted and selected in addVertex. |
mxEvent. | Fires when the escape key is pressed. |
mxEditor | Constructs a new editor. |
Controls and Handlers | |
askZoomResource | Specifies the resource key for the zoom dialog. |
lastSavedResource | Specifies the resource key for the last saved info. |
currentFileResource | Specifies the resource key for the current file info. |
propertiesResource | Specifies the resource key for the properties window title. |
tasksResource | Specifies the resource key for the tasks window title. |
helpResource | Specifies the resource key for the help window title. |
outlineResource | Specifies the resource key for the outline window title. |
outline | Reference to the mxWindow that contains the outline. |
graph | Holds a mxGraph for displaying the diagram. |
graphRenderHint | Holds the render hint used for creating the graph in setGraphContainer. |
toolbar | Holds a mxDefaultToolbar for displaying the toolbar. |
status | DOM container that holds the statusbar. |
popupHandler | Holds a mxDefaultPopupMenu for displaying popupmenus. |
undoManager | Holds an mxUndoManager for the command history. |
keyHandler | Holds a mxDefaultKeyHandler for handling keyboard events. |
Actions and Options | |
actions | Maps from actionnames to actions, which are functions taking the editor and the cell as arguments. |
dblClickAction | Specifies the name of the action to be executed when a cell is double clicked. |
swimlaneRequired | Specifies if new cells must be inserted into an existing swimlane. |
disableContextMenu | Specifies if the context menu should be disabled in the graph container. |
Templates | |
insertFunction | Specifies the function to be used for inserting new cells into the graph. |
forcedInserting | Specifies if a new cell should be inserted on a single click even using insertFunction if there is a cell under the mousepointer, otherwise the cell under the mousepointer is selected. |
templates | Maps from names to protoype cells to be used in the toolbar for inserting new cells into the diagram. |
defaultEdge | Prototype edge cell that is used for creating new edges. |
defaultEdgeStyle | Specifies the edge style to be returned in getEdgeStyle. |
defaultGroup | Prototype group cell that is used for creating new groups. |
groupBorderSize | Default size for the border of new groups. |
Backend Integration | |
filename | Contains the URL of the last opened file as a string. |
lineFeed | Character to be used for encoding linefeeds in save. |
postParameterName | Specifies if the name of the post parameter that contains the diagram data in a post request to the server. |
escapePostData | Specifies if the data in the post request for saving a diagram should be converted using encodeURIComponent. |
urlPost | Specifies the URL to be used for posting the diagram to a backend in save. |
urlImage | Specifies the URL to be used for creating a bitmap of the graph in the image action. |
Autolayout | |
horizontalFlow | Specifies the direction of the flow in the diagram. |
layoutDiagram | Specifies if the top-level elements in the diagram should be layed out using a vertical or horizontal stack depending on the setting of horizontalFlow. |
swimlaneSpacing | Specifies the spacing between swimlanes if automatic layout is turned on in layoutDiagram. |
maintainSwimlanes | Specifies if the swimlanes should be kept at the same width or height depending on the setting of horizontalFlow. |
layoutSwimlanes | Specifies if the children of swimlanes should be layed out, either vertically or horizontally depending on horizontalFlow. |
Attribute Cycling | |
cycleAttributeValues | Specifies the attribute values to be cycled when inserting new swimlanes. |
cycleAttributeIndex | Index of the last consumed attribute index. |
cycleAttributeName | Name of the attribute to be assigned a cycleAttributeValues when inserting new swimlanes. |
Windows | |
tasks | Holds the mxWindow created in showTasks. |
tasksWindowImage | Icon for the tasks window. |
tasksTop | Specifies the top coordinate of the tasks window in pixels. |
help | Holds the mxWindow created in showHelp. |
helpWindowImage | Icon for the help window. |
urlHelp | Specifies the URL to be used for the contents of the Online Help window. |
helpWidth | Specifies the width of the help window in pixels. |
helpHeight | Specifies the height of the help window in pixels. |
propertiesWidth | Specifies the width of the properties window in pixels. |
propertiesHeight | Specifies the height of the properties window in pixels. |
movePropertiesDialog | Specifies if the properties dialog should be automatically moved near the cell it is displayed for, otherwise the dialog is not moved. |
validating | Specifies if mxGraph.validateGraph should automatically be invoked after each change. |
modified | True if the graph has been modified since it was last saved. |
isModified | Returns modified. |
setModified | Sets modified to the specified boolean value. |
addActions | Adds the built-in actions to the editor instance. |
configure | Configures the editor using the specified node. |
resetFirstTime | Resets the cookie that is used to remember if the editor has already been used. |
resetHistory | Resets the command history, modified state and counters. |
addAction | Binds the specified actionname to the specified function. |
execute | Executes the function with the given name in actions passing the editor instance and given cell as the first and second argument. |
addTemplate | Adds the specified template under the given name in templates. |
getTemplate | Returns the template for the given name. |
createGraph | Creates the graph for the editor. |
createSwimlaneManager | Sets the graph’s container using mxGraph.init. |
createLayoutManager | Creates a layout manager for the swimlane and diagram layouts, that is, the locally defined inter- and intraswimlane layouts. |
setGraphContainer | Sets the graph’s container using mxGraph.init. |
installDblClickHandler | Overrides mxGraph.dblClick to invoke dblClickAction on a cell and reset the selection tool in the toolbar. |
installUndoHandler | Adds the undoManager to the graph model and the view. |
installDrillHandler | Installs listeners for dispatching the <root> event. |
installChangeHandler | Installs the listeners required to automatically validate the graph. |
installInsertHandler | Installs the handler for invoking insertFunction if one is defined. |
createDiagramLayout | Creates the layout instance used to layout the swimlanes in the diagram. |
createSwimlaneLayout | Creates the layout instance used to layout the children of each swimlane. |
createToolbar | Creates the toolbar with no container. |
setToolbarContainer | Initializes the toolbar for the given container. |
setStatusContainer | Creates the status using the specified container. |
setStatus | Display the specified message in the status bar. |
setTitleContainer | Creates a listener to update the inner HTML of the specified DOM node with the value of getTitle. |
treeLayout | Executes a vertical or horizontal compact tree layout using the specified cell as an argument. |
getTitle | Returns the string value for the current root of the diagram. |
getRootTitle | Returns the string value of the root cell in mxGraph.model. |
undo | Undo the last change in graph. |
redo | Redo the last change in graph. |
groupCells | Invokes createGroup to create a new group cell and the invokes mxGraph.groupCells, using the grid size of the graph as the spacing in the group’s content area. |
createGroup | Creates and returns a clone of defaultGroup to be used as a new group cell in <group>. |
open | Opens the specified file synchronously and parses it using readGraphModel. |
readGraphModel | Reads the specified XML node into the existing graph model and resets the command history and modified state. |
save | Posts the string returned by writeGraphModel to the given URL or the URL returned by getUrlPost. |
postDiagram | Hook for subclassers to override the posting of a diagram represented by the given node to the given URL. |
writeGraphModel | Hook to create the string representation of the diagram. |
getUrlPost | Returns the URL to post the diagram to. |
getUrlImage | Returns the URL to create the image with. |
swapStyles | Swaps the styles for the given names in the graph’s stylesheet and refreshes the graph. |
showProperties | Creates and shows the properties dialog for the given cell. |
isPropertiesVisible | Returns true if the properties dialog is currently visible. |
createProperties | Creates and returns the DOM node that represents the contents of the properties dialog for the given cell. |
hideProperties | Hides the properties dialog. |
showTasks | Shows the tasks window. |
refreshTasks | Updates the contents of the tasks window using createTasks. |
createTasks | Updates the contents of the given DOM node to display the tasks associated with the current editor state. |
showHelp | Shows the help window. |
showOutline | Shows the outline window. |
setMode | Puts the graph into the specified mode. |
createPopupMenu | Uses popupHandler to create the menu in the graph’s panning handler. |
createEdge | Uses defaultEdge as the prototype for creating new edges in the connection handler of the graph. |
getEdgeStyle | Returns a string identifying the style of new edges. |
consumeCycleAttribute | Returns the next attribute in cycleAttributeValues or null, if not attribute should be used in the specified cell. |
cycleAttribute | Uses the returned value from consumeCycleAttribute as the value for the cycleAttributeName key in the given cell’s style. |
addVertex | Adds the given vertex as a child of parent at the specified x and y coordinate and fires an addVertex event. |
destroy | Removes the editor and all its associated resources. |
Set when the editor is started. Never expires. Use resetFirstTime to reset this cookie. This cookie only exists if onInit is implemented.
Fires after the current file was saved in save. The <code>url</code> property contains the URL that was used for saving.
Fires if a successful response was received in postDiagram. The <code>request</code> property contains the mxXmlRequest, the <code>url</code> and <code>data</code> properties contain the URL and the data that were used in the post request.
Fires before a vertex is added in addVertex. The <code>vertex</code> property contains the new vertex and the <code>parent</code> property contains its parent.
Fires between begin- and endUpdate in addVertex. The <code>vertex</code> property contains the vertex that is being inserted.
Fires after a vertex was inserted and selected in addVertex. The <code>vertex</code> property contains the new vertex.
For starting an in-place edit after a new vertex has been added to the graph, the following code can be used.
editor.addListener(mxEvent.AFTER_ADD_VERTEX, function(sender, evt) { var vertex = evt.getProperty('vertex'); if (editor.graph.isCellEditable(vertex)) { editor.graph.startEditingAtCell(vertex); } });
function mxEditor( config )
Constructs a new editor. This function invokes the onInit callback upon completion.
var config = mxUtils.load('config/diagrameditor.xml').getDocumentElement(); var editor = new mxEditor(config);
config | Optional XML node that contains the configuration. |
mxEditor.prototype.graph
Holds a mxGraph for displaying the diagram. The graph is created in setGraphContainer.
mxEditor.prototype.graphRenderHint
Holds the render hint used for creating the graph in setGraphContainer. See mxGraph. Default is null.
mxEditor.prototype.toolbar
Holds a mxDefaultToolbar for displaying the toolbar. The toolbar is created in setToolbarContainer.
mxEditor.prototype.status
DOM container that holds the statusbar. Default is null. Use setStatusContainer to set this value.
mxEditor.prototype.popupHandler
Holds a mxDefaultPopupMenu for displaying popupmenus.
mxEditor.prototype.undoManager
Holds an mxUndoManager for the command history.
mxEditor.prototype.keyHandler
Holds a mxDefaultKeyHandler for handling keyboard events. The handler is created in setGraphContainer.
mxEditor.prototype.dblClickAction
Specifies the name of the action to be executed when a cell is double clicked. Default is ‘edit’.
To handle a singleclick, use the following code.
editor.graph.addListener(mxEvent.CLICK, function(sender, evt) { var e = evt.getProperty('event'); var cell = evt.getProperty('cell'); if (cell != null && !e.isConsumed()) { // Do something useful with cell... e.consume(); } });
mxEditor.prototype.insertFunction
Specifies the function to be used for inserting new cells into the graph. This is assigned from the mxDefaultToolbar if a vertex-tool is clicked.
mxEditor.prototype.forcedInserting
Specifies if a new cell should be inserted on a single click even using insertFunction if there is a cell under the mousepointer, otherwise the cell under the mousepointer is selected. Default is false.
mxEditor.prototype.defaultEdgeStyle
Specifies the edge style to be returned in getEdgeStyle. Default is null.
mxEditor.prototype.groupBorderSize
Default size for the border of new groups. If null, then then mxGraph.gridSize is used. Default is null.
Character to be used for encoding linefeeds in save. Default is ‘
’.
mxEditor.prototype.urlPost
Specifies the URL to be used for posting the diagram to a backend in save.
mxEditor.prototype.layoutDiagram
Specifies if the top-level elements in the diagram should be layed out using a vertical or horizontal stack depending on the setting of horizontalFlow. The spacing between the swimlanes is specified by swimlaneSpacing. Default is false.
If the top-level elements are swimlanes, then the intra-swimlane layout is activated by the layoutSwimlanes switch.
mxEditor.prototype.swimlaneSpacing
Specifies the spacing between swimlanes if automatic layout is turned on in layoutDiagram. Default is 0.
mxEditor.prototype.maintainSwimlanes
Specifies if the swimlanes should be kept at the same width or height depending on the setting of horizontalFlow. Default is false.
For horizontal flows, all swimlanes have the same height and for vertical flows, all swimlanes have the same width. Furthermore, the swimlanes are automatically “stacked” if layoutDiagram is true.
mxEditor.prototype.layoutSwimlanes
Specifies if the children of swimlanes should be layed out, either vertically or horizontally depending on horizontalFlow. Default is false.
mxEditor.prototype.cycleAttributeIndex
Index of the last consumed attribute index. If a new swimlane is inserted, then the cycleAttributeValues at this index will be used as the value for cycleAttributeName. Default is 0.
mxEditor.prototype.cycleAttributeName
Name of the attribute to be assigned a cycleAttributeValues when inserting new swimlanes. Default is ‘fillColor’.
mxEditor.prototype.validating
Specifies if mxGraph.validateGraph should automatically be invoked after each change. Default is false.
mxEditor.prototype.isModified = function ()
Returns modified.
mxEditor.prototype.setModified = function ( value )
Sets modified to the specified boolean value.
mxEditor.prototype.addActions = function ()
Adds the built-in actions to the editor instance.
save | Saves the graph using urlPost. |
Shows the graph in a new print preview window. | |
show | Shows the graph in a new window. |
exportImage | Shows the graph as a bitmap image using getUrlImage. |
refresh | Refreshes the graph’s display. |
cut | Copies the current selection into the clipboard and removes it from the graph. |
copy | Copies the current selection into the clipboard. |
paste | Pastes the clipboard into the graph. |
delete | Removes the current selection from the graph. |
group | Puts the current selection into a new group. |
ungroup | Removes the selected groups and selects the children. |
undo | Undoes the last change on the graph model. |
redo | Redoes the last change on the graph model. |
zoom | Sets the zoom via a dialog. |
zoomIn | Zooms into the graph. |
zoomOut | Zooms out of the graph |
actualSize | Resets the scale and translation on the graph. |
fit | Changes the scale so that the graph fits into the window. |
showProperties | Shows the properties dialog. |
selectAll | Selects all cells. |
selectNone | Clears the selection. |
selectVertices | Selects all vertices. selectEdges = Selects all edges. |
edit | Starts editing the current selection cell. |
enterGroup | Drills down into the current selection cell. |
exitGroup | Moves up in the drilling hierachy |
home | Moves to the topmost parent in the drilling hierarchy |
selectPrevious | Selects the previous cell. |
selectNext | Selects the next cell. |
selectParent | Selects the parent of the selection cell. |
selectChild | Selects the first child of the selection cell. |
collapse | Collapses the currently selected cells. |
expand | Expands the currently selected cells. |
bold | Toggle bold text style. |
italic | Toggle italic text style. |
underline | Toggle underline text style. |
alignCellsLeft | Aligns the selection cells at the left. |
alignCellsCenter | Aligns the selection cells in the center. |
alignCellsRight | Aligns the selection cells at the right. |
alignCellsTop | Aligns the selection cells at the top. |
alignCellsMiddle | Aligns the selection cells in the middle. |
alignCellsBottom | Aligns the selection cells at the bottom. |
alignFontLeft | Sets the horizontal text alignment to left. |
alignFontCenter | Sets the horizontal text alignment to center. |
alignFontRight | Sets the horizontal text alignment to right. |
alignFontTop | Sets the vertical text alignment to top. |
alignFontMiddle | Sets the vertical text alignment to middle. |
alignFontBottom | Sets the vertical text alignment to bottom. |
toggleTasks | Shows or hides the tasks window. |
toggleHelp | Shows or hides the help window. |
toggleOutline | Shows or hides the outline window. |
toggleConsole | Shows or hides the console window. |
mxEditor.prototype.configure = function ( node )
Configures the editor using the specified node. To load the configuration from a given URL the following code can be used to obtain the XML node.
var node = mxUtils.load(url).getDocumentElement();
node | XML node that contains the configuration. |
mxEditor.prototype.addAction = function ( actionname, funct )
Binds the specified actionname to the specified function.
actionname | String that specifies the name of the action to be added. |
funct | Function that implements the new action. The first argument of the function is the editor it is used with, the second argument is the cell it operates upon. |
editor.addAction('test', function(editor, cell) { mxUtils.alert("test "+cell); });
mxEditor.prototype.execute = function ( actionname, cell, evt )
Executes the function with the given name in actions passing the editor instance and given cell as the first and second argument. All additional arguments are passed to the action as well. This method contains a try-catch block and displays an error message if an action causes an exception. The exception is re-thrown after the error message was displayed.
editor.execute("showProperties", cell);
mxEditor.prototype.addTemplate = function ( name, template )
Adds the specified template under the given name in templates.
mxEditor.prototype.createGraph = function ()
Creates the graph for the editor. The graph is created with no container and is initialized from setGraphContainer.
mxEditor.prototype.createSwimlaneManager = function ( graph )
Sets the graph’s container using mxGraph.init.
mxEditor.prototype.setGraphContainer = function ( container )
Sets the graph’s container using mxGraph.init.
mxEditor.prototype.installDblClickHandler = function ( graph )
Overrides mxGraph.dblClick to invoke dblClickAction on a cell and reset the selection tool in the toolbar.
mxEditor.prototype.installUndoHandler = function ( graph )
Adds the undoManager to the graph model and the view.
mxEditor.prototype.installInsertHandler = function ( graph )
Installs the handler for invoking insertFunction if one is defined.
mxEditor.prototype.createToolbar = function ()
Creates the toolbar with no container.
mxEditor.prototype.setStatusContainer = function ( container )
Creates the status using the specified container.
This implementation adds listeners in the editor to display the last saved time and the current filename in the status bar.
container | DOM node that will contain the statusbar. |
mxEditor.prototype.setTitleContainer = function ( container )
Creates a listener to update the inner HTML of the specified DOM node with the value of getTitle.
container | DOM node that will contain the title. |
mxEditor.prototype.treeLayout = function ( cell, horizontal )
Executes a vertical or horizontal compact tree layout using the specified cell as an argument. The cell may either be a group or the root of a tree.
cell | mxCell to use in the compact tree layout. |
horizontal | Optional boolean to specify the tree’s orientation. Default is true. |
mxEditor.prototype.getRootTitle = function ()
Returns the string value of the root cell in mxGraph.model.
mxEditor.prototype.undo = function ()
Undo the last change in graph.
mxEditor.prototype.redo = function ()
Redo the last change in graph.
mxEditor.prototype.groupCells = function ()
Invokes createGroup to create a new group cell and the invokes mxGraph.groupCells, using the grid size of the graph as the spacing in the group’s content area.
mxEditor.prototype.createGroup = function ()
Creates and returns a clone of defaultGroup to be used as a new group cell in <group>.
mxEditor.prototype.open = function ( filename )
Opens the specified file synchronously and parses it using readGraphModel. It updates filename and fires an open-event after the file has been opened. Exceptions should be handled as follows:
try { editor.open(filename); } catch (e) { mxUtils.error('Cannot open ' + filename + ': ' + e.message, 280, true); }
filename | URL of the file to be opened. |
mxEditor.prototype.save = function ( url, linefeed )
Posts the string returned by writeGraphModel to the given URL or the URL returned by getUrlPost. The actual posting is carried out by postDiagram. If the URL is null then the resulting XML will be displayed using mxUtils.popup. Exceptions should be handled as follows:
try { editor.save(); } catch (e) { mxUtils.error('Cannot save : ' + e.message, 280, true); }
mxEditor.prototype.postDiagram = function ( url, data )
Hook for subclassers to override the posting of a diagram represented by the given node to the given URL. This fires an asynchronous <post> event if the diagram has been posted.
To replace the diagram with the diagram in the response, use the following code.
editor.addListener(mxEvent.POST, function(sender, evt) { // Process response (replace diagram) var req = evt.getProperty('request'); var root = req.getDocumentElement(); editor.graph.readGraphModel(root) });
mxEditor.prototype.writeGraphModel = function ( linefeed )
Hook to create the string representation of the diagram. The default implementation uses an mxCodec to encode the graph model as follows:
var enc = new mxCodec(); var node = enc.encode(this.graph.getModel()); return mxUtils.getXml(node, this.linefeed);
linefeed | Optional character to be used as the linefeed. Default is <linefeed>. |
mxEditor.prototype.getUrlImage = function ()
Returns the URL to create the image with. This is typically the URL of a backend which accepts an XML representation of a graph view to create an image. The function is used in the image action to create an image. This implementation returns urlImage.
mxEditor.prototype.showProperties = function ( cell )
Creates and shows the properties dialog for the given cell. The content area of the dialog is created using createProperties.
mxEditor.prototype.showTasks = function ()
Shows the tasks window. The tasks window is created using createTasks. The default width of the window is 200 pixels, the y-coordinate of the location can be specifies in tasksTop and the x-coordinate is right aligned with a 20 pixel offset from the right border. To change the location of the tasks window, the following code can be used:
var oldShowTasks = mxEditor.prototype.showTasks; mxEditor.prototype.showTasks = function() { oldShowTasks.apply(this, arguments); // "supercall" if (this.tasks != null) { this.tasks.setLocation(10, 10); } };
mxEditor.prototype.refreshTasks = function ( div )
Updates the contents of the tasks window using createTasks.
mxEditor.prototype.showHelp = function ( tasks )
Shows the help window. If the help window does not exist then it is created using an iframe pointing to the resource for the <code>urlHelp</code> key or urlHelp if the resource is undefined.
mxEditor.prototype.showOutline = function ()
Shows the outline window. If the window does not exist, then it is created using an mxOutline.
mxEditor.prototype.setMode = function( modename )
Puts the graph into the specified mode. The following modenames are supported:
select | Selects using the left mouse button, new connections are disabled. |
connect | Selects using the left mouse button or creates new connections if mouse over cell hotspot. See mxConnectionHandler. |
pan | Pans using the left mouse button, new connections are disabled. |
mxEditor.prototype.createPopupMenu = function ( menu, cell, evt )
Uses popupHandler to create the menu in the graph’s panning handler. The redirection is setup in setToolbarContainer.
mxEditor.prototype.createEdge = function ( source, target )
Uses defaultEdge as the prototype for creating new edges in the connection handler of the graph. The style of the edge will be overridden with the value returned by getEdgeStyle.
mxEditor.prototype.getEdgeStyle = function ()
Returns a string identifying the style of new edges. The function is used in createEdge when new edges are created in the graph.
mxEditor.prototype.consumeCycleAttribute = function ( cell )
Returns the next attribute in cycleAttributeValues or null, if not attribute should be used in the specified cell.
mxEditor.prototype.cycleAttribute = function ( cell )
Uses the returned value from consumeCycleAttribute as the value for the cycleAttributeName key in the given cell’s style.
mxEditor.prototype.addVertex = function ( parent, vertex, x, y )
Adds the given vertex as a child of parent at the specified x and y coordinate and fires an addVertex event.
Maps from actionnames to actions, which are functions taking the editor and the cell as arguments.
mxEditor.prototype.actions
Holds an mxUndoManager for the command history.
mxEditor.prototype.undoManager
Opens the specified file synchronously and parses it using readGraphModel.
mxEditor.prototype.open = function ( filename )
Posts the string returned by writeGraphModel to the given URL or the URL returned by getUrlPost.
mxEditor.prototype.save = function ( url, linefeed )
Hook for subclassers to override the posting of a diagram represented by the given node to the given URL.
mxEditor.prototype.postDiagram = function ( url, data )
Adds the given vertex as a child of parent at the specified x and y coordinate and fires an addVertex event.
mxEditor.prototype.addVertex = function ( parent, vertex, x, y )
Constructs a new editor.
function mxEditor( config )
Specifies the resource key for the zoom dialog.
mxEditor.prototype.askZoomResource
Specifies the resource key for the last saved info.
mxEditor.prototype.lastSavedResource
Specifies the resource key for the current file info.
mxEditor.prototype.currentFileResource
Specifies the resource key for the properties window title.
mxEditor.prototype.propertiesResource
Specifies the resource key for the tasks window title.
mxEditor.prototype.tasksResource
Specifies the resource key for the help window title.
mxEditor.prototype.helpResource
Specifies the resource key for the outline window title.
mxEditor.prototype.outlineResource
Reference to the mxWindow that contains the outline.
mxEditor.prototype.outline
Holds a mxGraph for displaying the diagram.
mxEditor.prototype.graph
Holds the render hint used for creating the graph in setGraphContainer.
mxEditor.prototype.graphRenderHint
Sets the graph’s container using mxGraph.init.
mxEditor.prototype.setGraphContainer = function ( container )
Holds a mxDefaultToolbar for displaying the toolbar.
mxEditor.prototype.toolbar
DOM container that holds the statusbar.
mxEditor.prototype.status
Holds a mxDefaultPopupMenu for displaying popupmenus.
mxEditor.prototype.popupHandler
Holds a mxDefaultKeyHandler for handling keyboard events.
mxEditor.prototype.keyHandler
Specifies the name of the action to be executed when a cell is double clicked.
mxEditor.prototype.dblClickAction
Specifies if new cells must be inserted into an existing swimlane.
mxEditor.prototype.swimlaneRequired
Specifies if the context menu should be disabled in the graph container.
mxEditor.prototype.disableContextMenu
Specifies the function to be used for inserting new cells into the graph.
mxEditor.prototype.insertFunction
Specifies if a new cell should be inserted on a single click even using insertFunction if there is a cell under the mousepointer, otherwise the cell under the mousepointer is selected.
mxEditor.prototype.forcedInserting
Maps from names to protoype cells to be used in the toolbar for inserting new cells into the diagram.
mxEditor.prototype.templates
Prototype edge cell that is used for creating new edges.
mxEditor.prototype.defaultEdge
Specifies the edge style to be returned in getEdgeStyle.
mxEditor.prototype.defaultEdgeStyle
Returns a string identifying the style of new edges.
mxEditor.prototype.getEdgeStyle = function ()
Prototype group cell that is used for creating new groups.
mxEditor.prototype.defaultGroup
Default size for the border of new groups.
mxEditor.prototype.groupBorderSize
Contains the URL of the last opened file as a string.
mxEditor.prototype.filename
Specifies if the name of the post parameter that contains the diagram data in a post request to the server.
mxEditor.prototype.postParameterName
Specifies if the data in the post request for saving a diagram should be converted using encodeURIComponent.
mxEditor.prototype.escapePostData
Specifies the URL to be used for posting the diagram to a backend in save.
mxEditor.prototype.urlPost
Specifies the URL to be used for creating a bitmap of the graph in the image action.
mxEditor.prototype.urlImage
Specifies the direction of the flow in the diagram.
mxEditor.prototype.horizontalFlow
Specifies if the top-level elements in the diagram should be layed out using a vertical or horizontal stack depending on the setting of horizontalFlow.
mxEditor.prototype.layoutDiagram
Specifies the spacing between swimlanes if automatic layout is turned on in layoutDiagram.
mxEditor.prototype.swimlaneSpacing
Specifies if the swimlanes should be kept at the same width or height depending on the setting of horizontalFlow.
mxEditor.prototype.maintainSwimlanes
Specifies if the children of swimlanes should be layed out, either vertically or horizontally depending on horizontalFlow.
mxEditor.prototype.layoutSwimlanes
Specifies the attribute values to be cycled when inserting new swimlanes.
mxEditor.prototype.cycleAttributeValues
Index of the last consumed attribute index.
mxEditor.prototype.cycleAttributeIndex
Name of the attribute to be assigned a cycleAttributeValues when inserting new swimlanes.
mxEditor.prototype.cycleAttributeName
Holds the mxWindow created in showTasks.
mxEditor.prototype.tasks
Shows the tasks window.
mxEditor.prototype.showTasks = function ()
Icon for the tasks window.
mxEditor.prototype.tasksWindowImage
Specifies the top coordinate of the tasks window in pixels.
mxEditor.prototype.tasksTop
Holds the mxWindow created in showHelp.
mxEditor.prototype.help
Shows the help window.
mxEditor.prototype.showHelp = function ( tasks )
Icon for the help window.
mxEditor.prototype.helpWindowImage
Specifies the URL to be used for the contents of the Online Help window.
mxEditor.prototype.urlHelp
Specifies the width of the help window in pixels.
mxEditor.prototype.helpWidth
Specifies the height of the help window in pixels.
mxEditor.prototype.helpHeight
Specifies the width of the properties window in pixels.
mxEditor.prototype.propertiesWidth
Specifies the height of the properties window in pixels.
mxEditor.prototype.propertiesHeight
Specifies if the properties dialog should be automatically moved near the cell it is displayed for, otherwise the dialog is not moved.
mxEditor.prototype.movePropertiesDialog
Specifies if mxGraph.validateGraph should automatically be invoked after each change.
mxEditor.prototype.validating
Validates the graph by validating each descendant of the given cell or the root of the model.
mxGraph.prototype.validateGraph = function( cell, context )
True if the graph has been modified since it was last saved.
mxEditor.prototype.modified
Returns modified.
mxEditor.prototype.isModified = function ()
Sets modified to the specified boolean value.
mxEditor.prototype.setModified = function ( value )
Adds the built-in actions to the editor instance.
mxEditor.prototype.addActions = function ()
Configures the editor using the specified node.
mxEditor.prototype.configure = function ( node )
Resets the cookie that is used to remember if the editor has already been used.
mxEditor.prototype.resetFirstTime = function ()
Resets the command history, modified state and counters.
mxEditor.prototype.resetHistory = function ()
Binds the specified actionname to the specified function.
mxEditor.prototype.addAction = function ( actionname, funct )
Executes the function with the given name in actions passing the editor instance and given cell as the first and second argument.
mxEditor.prototype.execute = function ( actionname, cell, evt )
Adds the specified template under the given name in templates.
mxEditor.prototype.addTemplate = function ( name, template )
Returns the template for the given name.
mxEditor.prototype.getTemplate = function ( name )
Creates the graph for the editor.
mxEditor.prototype.createGraph = function ()
Sets the graph’s container using mxGraph.init.
mxEditor.prototype.createSwimlaneManager = function ( graph )
Initializes the container and creates the respective datastructures.
mxGraph.prototype.init = function( container )
Creates a layout manager for the swimlane and diagram layouts, that is, the locally defined inter- and intraswimlane layouts.
mxEditor.prototype.createLayoutManager = function ( graph )
Overrides mxGraph.dblClick to invoke dblClickAction on a cell and reset the selection tool in the toolbar.
mxEditor.prototype.installDblClickHandler = function ( graph )
Processes a doubleclick on an optional cell and fires a dblclick event.
mxGraph.prototype.dblClick = function( evt, cell )
Adds the undoManager to the graph model and the view.
mxEditor.prototype.installUndoHandler = function ( graph )
Installs listeners for dispatching the root event.
mxEditor.prototype.installDrillHandler = function ( graph )
Installs the listeners required to automatically validate the graph.
mxEditor.prototype.installChangeHandler = function ( graph )
Installs the handler for invoking insertFunction if one is defined.
mxEditor.prototype.installInsertHandler = function ( graph )
Creates the layout instance used to layout the swimlanes in the diagram.
mxEditor.prototype.createDiagramLayout = function ()
Creates the layout instance used to layout the children of each swimlane.
mxEditor.prototype.createSwimlaneLayout = function ()
Creates the toolbar with no container.
mxEditor.prototype.createToolbar = function ()
Initializes the toolbar for the given container.
mxEditor.prototype.setToolbarContainer = function ( container )
Creates the status using the specified container.
mxEditor.prototype.setStatusContainer = function ( container )
Display the specified message in the status bar.
mxEditor.prototype.setStatus = function ( message )
Creates a listener to update the inner HTML of the specified DOM node with the value of getTitle.
mxEditor.prototype.setTitleContainer = function ( container )
Returns the string value for the current root of the diagram.
mxEditor.prototype.getTitle = function ()
Executes a vertical or horizontal compact tree layout using the specified cell as an argument.
mxEditor.prototype.treeLayout = function ( cell, horizontal )
Returns the string value of the root cell in mxGraph.model.
mxEditor.prototype.getRootTitle = function ()
Holds the mxGraphModel that contains the cells to be displayed.
mxGraph.prototype.model
Undo the last change in graph.
mxEditor.prototype.undo = function ()
Redo the last change in graph.
mxEditor.prototype.redo = function ()
Invokes createGroup to create a new group cell and the invokes mxGraph.groupCells, using the grid size of the graph as the spacing in the group’s content area.
mxEditor.prototype.groupCells = function ()
Creates and returns a clone of defaultGroup to be used as a new group cell in group.
mxEditor.prototype.createGroup = function ()
Adds the cells into the given group.
mxGraph.prototype.groupCells = function( group, border, cells )
Reads the specified XML node into the existing graph model and resets the command history and modified state.
mxEditor.prototype.readGraphModel = function ( node )
Hook to create the string representation of the diagram.
mxEditor.prototype.writeGraphModel = function ( linefeed )
Returns the URL to post the diagram to.
mxEditor.prototype.getUrlPost = function ()
Returns the URL to create the image with.
mxEditor.prototype.getUrlImage = function ()
Swaps the styles for the given names in the graph’s stylesheet and refreshes the graph.
mxEditor.prototype.swapStyles = function ( first, second )
Creates and shows the properties dialog for the given cell.
mxEditor.prototype.showProperties = function ( cell )
Returns true if the properties dialog is currently visible.
mxEditor.prototype.isPropertiesVisible = function ()
Creates and returns the DOM node that represents the contents of the properties dialog for the given cell.
mxEditor.prototype.createProperties = function ( cell )
Hides the properties dialog.
mxEditor.prototype.hideProperties = function ()
Updates the contents of the tasks window using createTasks.
mxEditor.prototype.refreshTasks = function ( div )
Updates the contents of the given DOM node to display the tasks associated with the current editor state.
mxEditor.prototype.createTasks = function ( div )
Shows the outline window.
mxEditor.prototype.showOutline = function ()
Puts the graph into the specified mode.
mxEditor.prototype.setMode = function( modename )
Uses popupHandler to create the menu in the graph’s panning handler.
mxEditor.prototype.createPopupMenu = function ( menu, cell, evt )
Uses defaultEdge as the prototype for creating new edges in the connection handler of the graph.
mxEditor.prototype.createEdge = function ( source, target )
Returns the next attribute in cycleAttributeValues or null, if not attribute should be used in the specified cell.
mxEditor.prototype.consumeCycleAttribute = function ( cell )
Uses the returned value from consumeCycleAttribute as the value for the cycleAttributeName key in the given cell’s style.
mxEditor.prototype.cycleAttribute = function ( cell )
Removes the editor and all its associated resources.
mxEditor.prototype.destroy = function ()
Reads a sequence of the following child nodes and attributes:
codec.decode = function( dec, node, into )
Holds the Id.
mxCell.prototype.id
Returns the mxCell for the specified Id or null if no cell can be found for the given Id.
mxGraphModel.prototype.getCell = function( id )
Hook method to create an Id for the specified cell.
mxGraphModel.prototype.createId = function( cell )
Specifies the grid size.
mxGraph.prototype.gridSize
Shows the specified text content in a new mxWindow or a new browser window if isInternalWindow is false.
popup: function( content, isInternalWindow )