Created
April 30, 2014 13:54
-
-
Save simonsarris/313b876e7b44b01ccc70 to your computer and use it in GitHub Desktop.
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
<!doctype html> | |
<html> | |
<head> | |
<title>Minimal GoJS Sample</title> | |
<!-- Copyright 1998-2014 by Northwoods Software Corporation. --> | |
<link href="goSamples.css" rel="stylesheet" type="text/css"/> | |
<script src="http://www.gojs.net/latest/release/go.js"></script> | |
<script id="code"> | |
function init() { | |
var $ = go.GraphObject.make; // for conciseness in defining templates | |
myDiagram = $(go.Diagram, "myDiagram", // create a Diagram for the DIV HTML element | |
{ | |
initialContentAlignment: go.Spot.Center, // center the content | |
"undoManager.isEnabled": true, // enable undo & redo | |
"clickCreatingTool.archetypeNodeData": { color: "lime" } | |
}); | |
// define a simple Node template | |
myDiagram.nodeTemplate = | |
$(go.Node, "Auto", // the Shape will go around the TextBlock | |
$(go.Shape, "RoundedRectangle", | |
// Shape.fill is bound to Node.data.color | |
new go.Binding("fill", "color")), | |
$(go.TextBlock, | |
{ margin: 3 }, // some room around the text | |
// TextBlock.text is bound to Node.data.id | |
new go.Binding("text", "id")) | |
); | |
var currentID = 0; | |
// returns a unique key | |
function makeUnique(model, nodedata) { | |
// really simple, just returns a number (skipping odd numbers) | |
if (currentID % 2 !== 0) currentID++; | |
return currentID++; | |
} | |
// create the model data that will be represented by Nodes and Links | |
myDiagram.model = $(go.GraphLinksModel, { | |
nodeKeyProperty: "id", | |
makeUniqueKeyFunction: makeUnique, | |
nodeDataArray: | |
[ | |
{ id: "Alpha", color: "lightblue" }, | |
{ id: "Beta", color: "orange" }, | |
{ id: "Gamma", color: "lightgreen" }, | |
{ id: "Delta", color: "pink" } | |
], | |
linkDataArray: | |
[ | |
{ from: "Alpha", to: "Beta" }, | |
{ from: "Alpha", to: "Gamma" }, | |
{ from: "Beta", to: "Beta" }, | |
{ from: "Gamma", to: "Delta" }, | |
{ from: "Delta", to: "Alpha" } | |
] } | |
); | |
} | |
// Show the diagram's model in JSON format that the user may edit | |
function save() { | |
myDiagram.model.nodeKeyProperty = "id"; | |
document.getElementById("mySavedModel").value = myDiagram.model.toJson(); | |
myDiagram.isModified = false; | |
} | |
function load() { | |
myDiagram.model = go.Model.fromJson(document.getElementById("mySavedModel").value); | |
} | |
</script> | |
</head> | |
<body onload="init()"> | |
<div id="sample"> | |
<p>Minimal <b>GoJS</b> Sample</p> | |
<!-- The DIV for the Diagram needs an explicit size or else we won't see anything. | |
Also add a border to help see the edges. --> | |
<div id="myDiagram" style="border: solid 1px black; width:400px; height:400px"></div> | |
<button id="SaveButton" onclick="save()">Save</button> | |
<button onclick="load()">Load</button> | |
<textarea id="mySavedModel" style="width:100%;height:300px"> | |
Press save | |
</textarea> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment