Created
June 5, 2014 06:24
-
-
Save davidjgraph/db8c1cc6754e6beed374 to your computer and use it in GitHub Desktop.
helloworld.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!-- | |
| $Id: helloworld.html,v 1.6 2013/10/28 08:44:54 gaudenz Exp $ | |
| Copyright (c) 2006-2013, JGraph Ltd | |
| Hello, World! example for mxGraph. This example demonstrates using | |
| a DOM node to create a graph and adding vertices and edges. | |
| --> | |
| <html> | |
| <head> | |
| <title>Hello, World! example for mxGraph</title> | |
| <!-- Sets the basepath for the library if not in same directory --> | |
| <script type="text/javascript"> | |
| mxBasePath = '../src'; | |
| </script> | |
| <!-- Loads and initializes the library --> | |
| <script type="text/javascript" src="../src/js/mxClient.js"></script> | |
| <!-- Example code --> | |
| <script type="text/javascript"> | |
| // START OF PATCH | |
| mxGraphView.prototype.isCellCollapsed = function(cell) | |
| { | |
| return this.graph.isCellCollapsed(cell); | |
| }; | |
| mxGraphView.prototype.getVisibleTerminal = function(edge, source) | |
| { | |
| var model = this.graph.getModel(); | |
| var result = model.getTerminal(edge, source); | |
| var best = result; | |
| while (result != null && result != this.currentRoot) | |
| { | |
| if (!this.graph.isCellVisible(best) || this.isCellCollapsed(result)) | |
| { | |
| best = result; | |
| } | |
| result = model.getParent(result); | |
| } | |
| // Checks if the result is not a layer | |
| if (model.getParent(best) == model.getRoot()) | |
| { | |
| best = null; | |
| } | |
| return best; | |
| }; | |
| mxGraphView.prototype.validateCell = function(cell, visible) | |
| { | |
| visible = (visible != null) ? visible : true; | |
| if (cell != null) | |
| { | |
| visible = visible && this.graph.isCellVisible(cell); | |
| var state = this.getState(cell, visible); | |
| if (state != null && !visible) | |
| { | |
| this.removeState(cell); | |
| } | |
| else | |
| { | |
| var model = this.graph.getModel(); | |
| var childCount = model.getChildCount(cell); | |
| for (var i = 0; i < childCount; i++) | |
| { | |
| this.validateCell(model.getChildAt(cell, i), visible && | |
| (!this.isCellCollapsed(cell) || cell == this.currentRoot)); | |
| } | |
| } | |
| } | |
| return cell; | |
| }; | |
| // END OF PATCH | |
| var mxGraphFoldCells = mxGraph.prototype.foldCells; | |
| mxGraph.prototype.foldCells = function(collapse, recurse, cells, checkFoldable) | |
| { | |
| this.model.beginUpdate(); | |
| try | |
| { | |
| for (var i = 0; i < cells.length; i++) | |
| { | |
| var childCount = this.model.getChildCount(cells[i]); | |
| for (var j = 0; j < childCount; j++) | |
| { | |
| var child = this.model.getChildAt(cells[i], j); | |
| if (child.value != null && child.value == '2') | |
| { | |
| this.model.setVisible(child, !collapse); | |
| } | |
| } | |
| } | |
| mxGraphFoldCells.apply(this, arguments); | |
| } | |
| finally | |
| { | |
| this.model.endUpdate(); | |
| } | |
| }; | |
| mxGraphView.prototype.isCellCollapsed = function(cell) | |
| { | |
| return false; | |
| } | |
| // Program starts here. Creates a sample graph in the | |
| // DOM node with the specified ID. This function is invoked | |
| // from the onLoad event handler of the document (see below). | |
| function main(container) | |
| { | |
| // Checks if the browser is supported | |
| if (!mxClient.isBrowserSupported()) | |
| { | |
| // Displays an error message if the browser is not supported. | |
| mxUtils.error('Browser is not supported!', 200, false); | |
| } | |
| else | |
| { | |
| // Disables the built-in context menu | |
| mxEvent.disableContextMenu(container); | |
| // Creates the graph inside the given container | |
| var graph = new mxGraph(container); | |
| // Enables rubberband selection | |
| new mxRubberband(graph); | |
| // Gets the default parent for inserting new cells. This | |
| // is normally the first child of the root (ie. layer 0). | |
| var parent = graph.getDefaultParent(); | |
| // Adds cells to the model in a single step | |
| graph.getModel().beginUpdate(); | |
| try | |
| { | |
| var v1 = graph.insertVertex(parent, null, '', 20, 20, 120, 100); | |
| v1.geometry.alternateBounds = new mxRectangle(20, 20, 120, 50); | |
| var v2 = graph.insertVertex(v1, null, '1', 20, 10, 80, 30); | |
| var v2 = graph.insertVertex(v1, null, '2', 20, 50, 80, 30); | |
| } | |
| finally | |
| { | |
| // Updates the display | |
| graph.getModel().endUpdate(); | |
| } | |
| } | |
| }; | |
| </script> | |
| </head> | |
| <!-- Page passes the container for the graph to the program --> | |
| <body onload="main(document.getElementById('graphContainer'))"> | |
| <!-- Creates a container for the graph with a grid wallpaper --> | |
| <div id="graphContainer" | |
| style="position:relative;overflow:hidden;width:321px;height:241px;background:url('editors/images/grid.gif');cursor:default;"> | |
| </div> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment