GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing maxgraph.github.io — Editor | @maxgraph/core
Class EditorExtends EventSource to implement an application wrapper for a graph that
adds actions, I/O using Codec, auto-layout using LayoutManager,
command history using undoManager, and standard dialogs and widgets, e.g.
properties, help, outline, toolbar, and popupmenu. It also adds templates
to be used as cells in toolbars, auto-validation using the installChangeHandler
flag, attribute cycling using cycleAttributeValues, higher-level events
such as root, and backend integration using ActionsActions are functions stored in the A list of built-in actions is available in the Read/write DiagramsTo read a diagram from an XML string, for example from a text field within the page, the following code is used:
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 linefeed 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.
Creating imagesA 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). Special charactersNote 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 an 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:
Otherwise, try using hex escape sequences and the built-in unescape function for converting such strings. Local FilesFor 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.
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. Cell PropertiesThe 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 Editor.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 Cell node and its Geometry child contain graph information:
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:
The Task node can have any tag name, attributes and child nodes. The Codec will use the XML hierarchy as the user object, while removing the "known annotations", such as the Cell 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 CellAttributeChange action in the model. The dialog can be replaced by overriding the createProperties hook or by replacing the showProperties action in action. Alternatively, the entry in the config file's popupmenu section can be modified to invoke a different action. If you want to display the properties dialog on a double click, you can set Editor.dblClickAction to showProperties as follows:
Popupmenu and ToolbarThe toolbar and popupmenu are typically configured using the respective sections in the config file, that is, the popupmenu is defined as follows:
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 EditorPopupMenuCodec, the format of the configuration is explained in EditorPopupMenu.decode. The toolbar is defined in the EditorToolbar section. Items can be added and removed in this section.
The format of the configuration is described in EditorToolbarCodec.decode. Ids: For the IDs, there is an implicit behaviour in Codec: 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 Cell.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 GraphDataModel.getCell function. If there is a collision, a new Id will be created for the cell using GraphDataModel.createId. At encoding time, this new Id will replace the value previously stored under the id attribute in the Task node. See EditorCodec, EditorToolbarCodec and EditorPopupMenuCodec for information about configuring the editor and user interface. Programmatically inserting cellsFor 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.
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.
Translationsresources/editor - Language resources for Editor To load the resources for the Editor, the following code should be used:
Callback: onInitCalled from within the constructor. In the callback, "this" refers to the editor instance. Cookie: mxgraph=seenSet when the editor is started. Never expires. Use resetFirstTime to reset this cookie. This cookie only exists if onInit is implemented. EventsEvent: mxEvent.OPENFires after a file was opened in open. The Event: mxEvent.SAVEFires after the current file was saved in save. The Event: mxEvent.POSTFires if a successful response was received in postDiagram. The
Event: mxEvent.ROOTFires when the current root has changed, or when the title of the current root has changed. This event has no properties. Event: mxEvent.BEFORE_ADD_VERTEXFires before a vertex is added in addVertex. The Event: mxEvent.ADD_VERTEXFires between begin- and endUpdate in Event: mxEvent.AFTER_ADD_VERTEXFires after a vertex was inserted and selected in Example For starting an in-place edit after a new vertex has been added to the graph, the following code can be used.
Event: mxEvent.ESCAPEFires when the escape key is pressed. The Hierarchy (View Summary)
|
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |