gojs
Version:
Interactive diagrams, charts, and graphs, such as trees, flowcharts, orgcharts, UML, BPMN, or business diagrams
141 lines (134 loc) • 5.39 kB
HTML
<html>
<head>
<title>Beat Paths</title>
<meta name="description" content="A precedence diagram showing a hierarchical relationship between nodes." />
<!-- Copyright 1998-2016 by Northwoods Software Corporation. -->
<meta charset="UTF-8">
<script src="go.js"></script>
<link href="../assets/css/goSamples.css" rel="stylesheet" type="text/css" /> <!-- you don't need to use this -->
<script src="goSamples.js"></script> <!-- this is only for the GoJS Samples framework -->
<script id="code">
function init() {
if (window.goSamples) goSamples(); // init for these samples -- you don't need to call this
var $ = go.GraphObject.make; // for conciseness in defining templates
// Must name or refer to the DIV HTML element
myDiagram =
$(go.Diagram, "myDiagramDiv",
{ // automatically scale the diagram to fit the viewport's size
initialAutoScale: go.Diagram.Uniform,
// start everything in the middle of the viewport
initialContentAlignment: go.Spot.Center,
// disable user copying of parts
allowCopy: false,
// position all of the nodes and route all of the links
layout:
$(go.LayeredDigraphLayout,
{ direction: 90,
layerSpacing: 10,
columnSpacing: 15,
setsPortSpots: false })
});
// replace the default Node template in the nodeTemplateMap
myDiagram.nodeTemplate =
$(go.Node, "Vertical", // the whole node panel
$(go.TextBlock, // the text label
new go.Binding("text", "key")),
$(go.Picture, // the icon showing the logo
// You should set the desiredSize (or width and height)
// whenever you know what size the Picture should be.
{ desiredSize: new go.Size(50, 50) },
new go.Binding("source", "key", convertKeyImage))
);
// replace the default Link template in the linkTemplateMap
myDiagram.linkTemplate =
$(go.Link, // the whole link panel
{ curve: go.Link.Bezier, toShortLength: 2 },
$(go.Shape, // the link shape
{ strokeWidth: 1.5 }),
$(go.Shape, // the arrowhead
{ toArrow: "Standard", stroke: null })
);
// the array of link data objects: the relationships between the nodes
var linkDataArray = [
{ from: "NE", to: "CLE" },
{ from: "NE", to: "DAL" },
{ from: "NE", to: "IND" },
{ from: "PIT", to: "CLE" },
{ from: "DAL", to: "NYG" },
{ from: "DAL", to: "GB" },
{ from: "CLE", to: "SEA" },
{ from: "NYG", to: "DET" },
{ from: "GB", to: "MIN" },
{ from: "GB", to: "PHI" },
{ from: "SEA", to: "PHI" },
{ from: "SEA", to: "CIN" },
{ from: "IND", to: "TB" },
{ from: "IND", to: "JAC" },
{ from: "MIN", to: "SD" },
{ from: "PHI", to: "NYJ" },
{ from: "DET", to: "CHI" },
{ from: "DET", to: "DEN" },
{ from: "JAC", to: "DEN" },
{ from: "SD", to: "DEN" },
{ from: "CHI", to: "OAK" },
{ from: "TB", to: "TEN" },
{ from: "DEN", to: "TEN" },
{ from: "DEN", to: "KC" },
{ from: "DEN", to: "BUF" },
{ from: "TEN", to: "OAK" },
{ from: "TEN", to: "ATL" },
{ from: "TEN", to: "HOU" },
{ from: "BUF", to: "WAS" },
{ from: "OAK", to: "MIA" },
{ from: "HOU", to: "MIA" },
{ from: "HOU", to: "CAR" },
{ from: "WAS", to: "NYJ" },
{ from: "WAS", to: "ARI" },
{ from: "CIN", to: "BAL" },
{ from: "NYJ", to: "MIA" },
{ from: "CAR", to: "ARI" },
{ from: "CAR", to: "STL" },
{ from: "CAR", to: "SF" },
{ from: "NO", to: "SF" },
{ from: "BAL", to: "STL" },
{ from: "BAL", to: "SF" }
];
// create the model and assign it to the Diagram
myDiagram.model =
$(go.GraphLinksModel,
{ // automatically create node data objects for each "from" or "to" reference
// (set this property before setting the linkDataArray)
archetypeNodeData: {},
// process all of the link relationship data
linkDataArray: linkDataArray
});
}
function convertKeyImage(key) {
if (!key) key = "NE";
return "https://www.nwoods.com/go/beatpaths/" + key + "_logo-50x50.png";
}
</script>
</head>
<body onload="init()">
<div id="sample">
<h3>GoJS Beat Paths: The 2007 NFL Season</h3>
<div id="myDiagramDiv" style="border: solid 1px gray; margin: 10px; height: 700px"></div>
<p>
This sample demonstrates reading JSON data describing the relative rankings of NFL teams
during the 2007 season and generating a diagram from that data.
The ranking information came from www.beatpaths.com.
</p>
<p>
The JSON data is basically just a list of relationships.
Unlike most model data, there are no elements describing the nodes --
the node definitions are implicit in the references from the links.
Hence the <a>Diagram.model</a> has <a>GraphLinksModel.archetypeNodeData</a> set to a JavaScript object.
</p>
<p>
The node template uses the <b>convertKeyImage</b> function to convert the team name
into a URI referring to an image on our web site.
</p>
</div>
</body>
</html>