You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
3.4 KiB
84 lines
3.4 KiB
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Serpentine Layout</title>
|
|
<meta name="description" content="Arrange a chain of nodes in rows, alternating directions, back and forth." />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<!-- Copyright 1998-2019 by Northwoods Software Corporation. -->
|
|
|
|
<script src="../release/go.js"></script>
|
|
<script src="../assets/js/goSamples.js"></script> <!-- this is only for the GoJS Samples framework -->
|
|
<script src="SerpentineLayout.js"></script>
|
|
|
|
<script id="code">
|
|
function init() {
|
|
if (window.goSamples) goSamples(); // init for these samples -- you don't need to call this
|
|
var $ = go.GraphObject.make;
|
|
|
|
myDiagram =
|
|
$(go.Diagram, "myDiagramDiv", // create a Diagram for the DIV HTML element
|
|
{
|
|
isTreePathToChildren: false, // links go from child to parent
|
|
layout: $(SerpentineLayout) // defined in SerpentineLayout.js
|
|
});
|
|
|
|
myDiagram.nodeTemplate =
|
|
$(go.Node, go.Panel.Auto,
|
|
$(go.Shape, { figure: "RoundedRectangle", fill: "white" },
|
|
new go.Binding("fill", "color")),
|
|
$(go.TextBlock, { margin: 4 },
|
|
new go.Binding("text", "key")));
|
|
|
|
myDiagram.linkTemplate =
|
|
$(go.Link, go.Link.Orthogonal,
|
|
{ corner: 5 },
|
|
$(go.Shape),
|
|
$(go.Shape, { toArrow: "Standard" }));
|
|
|
|
var model = new go.TreeModel();
|
|
model.nodeParentKeyProperty = "next";
|
|
model.nodeDataArray = [
|
|
{ key: "Alpha", next: "Beta", color: "coral" },
|
|
{ key: "Beta", next: "Gamma", color: "tomato" },
|
|
{ key: "Gamma", next: "Delta", color: "goldenrod" },
|
|
{ key: "Delta", next: "Epsilon", color: "orange" },
|
|
{ key: "Epsilon", next: "Zeta", color: "coral" },
|
|
{ key: "Zeta", next: "Eta", color: "tomato" },
|
|
{ key: "Eta", next: "Theta", color: "goldenrod" },
|
|
{ key: "Theta", next: "Iota", color: "orange" },
|
|
{ key: "Iota", next: "Kappa", color: "coral" },
|
|
{ key: "Kappa", next: "Lambda", color: "tomato" },
|
|
{ key: "Lambda", next: "Mu", color: "goldenrod" },
|
|
{ key: "Mu", next: "Nu", color: "orange" },
|
|
{ key: "Nu", next: "Xi", color: "coral" },
|
|
{ key: "Xi", next: "Omicron", color: "tomato" },
|
|
{ key: "Omicron", next: "Pi", color: "goldenrod" },
|
|
{ key: "Pi", next: "Rho", color: "orange" },
|
|
{ key: "Rho", next: "Sigma", color: "coral" },
|
|
{ key: "Sigma", next: "Tau", color: "tomato" },
|
|
{ key: "Tau", next: "Upsilon", color: "goldenrod" },
|
|
{ key: "Upsilon", next: "Phi", color: "orange" },
|
|
{ key: "Phi", next: "Chi", color: "coral" },
|
|
{ key: "Chi", next: "Psi", color: "tomato" },
|
|
{ key: "Psi", next: "Omega", color: "goldenrod" },
|
|
{ key: "Omega", color: "orange" }
|
|
];
|
|
myDiagram.model = model;
|
|
}
|
|
</script>
|
|
</head>
|
|
<body onload="init()">
|
|
<div id="sample">
|
|
<div id="myDiagramDiv" style="border: solid 1px black; width:100%; height:500px; min-width: 200px"></div>
|
|
<p>
|
|
This sample demonstrates a custom Layout, SerpentineLayout, which assumes the graph consists of a chain of nodes.
|
|
The layout is defined in its own file, as <a href="SerpentineLayout.js">SerpentineLayout.js</a>.
|
|
</p>
|
|
<p>
|
|
It also has <a>Layout.isViewportSized</a> set to true, so that resizing the Diagram DIV will automatically re-layout.
|
|
</p>
|
|
</div>
|
|
</body>
|
|
</html>
|