171 lines
6.7 KiB
HTML
171 lines
6.7 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>GoJS Arrowheads</title>
|
|
<meta name="description" content="Show all of the predefined kinds of arrowheads for links." />
|
|
<!-- Copyright 1998-2017 by Northwoods Software Corporation. -->
|
|
<meta charset="UTF-8">
|
|
<script src="../release/go.js"></script>
|
|
<script src="../assets/js/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
|
|
|
|
var myDiagram =
|
|
$(go.Diagram, "myDiagramDiv", // create a Diagram for the DIV HTML element
|
|
{
|
|
isReadOnly: true, // don't allow move or delete
|
|
initialContentAlignment: go.Spot.Center,
|
|
layout: $(go.CircularLayout,
|
|
{
|
|
radius: 100, // minimum radius
|
|
spacing: 0, // circular nodes will touch each other
|
|
nodeDiameterFormula: go.CircularLayout.Circular, // assume nodes are circular
|
|
startAngle: 270 // first node will be at top
|
|
}),
|
|
// define a DiagramEvent listener
|
|
"LayoutCompleted": function(e) {
|
|
// now that the CircularLayout has finished, we know where its center is
|
|
var cntr = myDiagram.findNodeForKey("Center");
|
|
cntr.location = myDiagram.layout.actualCenter;
|
|
}
|
|
});
|
|
|
|
// construct a shared radial gradient brush
|
|
var radBrush = $(go.Brush, "Radial", { 0: "#550266", 1: "#80418C" });
|
|
|
|
// these are the nodes that are in a circle
|
|
myDiagram.nodeTemplate =
|
|
$(go.Node,
|
|
$(go.Shape, "Circle",
|
|
{
|
|
desiredSize: new go.Size(28, 28),
|
|
fill: radBrush, strokeWidth: 0, stroke: null
|
|
}), // no outline
|
|
{
|
|
locationSpot: go.Spot.Center,
|
|
click: showArrowInfo, // defined below
|
|
toolTip: // define a tooltip for each link that displays its information
|
|
$(go.Adornment, "Auto",
|
|
$(go.Shape, { fill: "#EFEFCC" }),
|
|
$(go.TextBlock, { margin: 4 },
|
|
new go.Binding("text", "", infoString).ofObject())
|
|
)
|
|
}
|
|
);
|
|
|
|
// use a special template for the center node
|
|
myDiagram.nodeTemplateMap.add("Center",
|
|
$(go.Node, "Spot",
|
|
{
|
|
selectable: false,
|
|
isLayoutPositioned: false, // the Diagram.layout will not position this node
|
|
locationSpot: go.Spot.Center
|
|
},
|
|
$(go.Shape, "Circle",
|
|
{ fill: radBrush, strokeWidth: 0, stroke: null, desiredSize: new go.Size(200, 200) }), // no outline
|
|
$(go.TextBlock, "Arrowheads",
|
|
{ margin: 1, stroke: "white", font: "bold 14px sans-serif" })
|
|
));
|
|
|
|
// all Links have both "toArrow" and "fromArrow" Shapes,
|
|
// where both arrow properties are data bound
|
|
myDiagram.linkTemplate =
|
|
$(go.Link, // the whole link panel
|
|
{ routing: go.Link.Normal },
|
|
$(go.Shape, // the link shape
|
|
// the first element is assumed to be main element: as if isPanelMain were true
|
|
{ stroke: "gray", strokeWidth: 2 }),
|
|
$(go.Shape, // the "from" arrowhead
|
|
new go.Binding("fromArrow", "fromArrow"),
|
|
{ scale: 2, fill: "#D4B52C" }),
|
|
$(go.Shape, // the "to" arrowhead
|
|
new go.Binding("toArrow", "toArrow"),
|
|
{ scale: 2, fill: "#D4B52C" }),
|
|
{
|
|
click: showArrowInfo,
|
|
toolTip: // define a tooltip for each link that displays its information
|
|
$(go.Adornment, "Auto",
|
|
$(go.Shape, { fill: "#EFEFCC" }),
|
|
$(go.TextBlock, { margin: 4 },
|
|
new go.Binding("text", "", infoString).ofObject())
|
|
)
|
|
}
|
|
);
|
|
|
|
// collect all of the predefined arrowhead names
|
|
var arrowheads = go.Shape.getArrowheadGeometries().toKeySet().toArray();
|
|
if (arrowheads.length % 2 === 1) arrowheads.push(""); // make sure there's an even number
|
|
|
|
// create all of the link data, two arrowheads per link
|
|
var linkdata = [];
|
|
var i = 0;
|
|
for (var j = 0; j < arrowheads.length; j = j + 2) {
|
|
linkdata.push({ from: "Center", to: i++, toArrow: arrowheads[j], fromArrow: arrowheads[j + 1] });
|
|
}
|
|
|
|
myDiagram.model =
|
|
$(go.GraphLinksModel,
|
|
{ // this gets copied automatically when there's a link data reference to a new node key
|
|
// and is then added to the nodeDataArray
|
|
archetypeNodeData: {},
|
|
// the node array starts with just the special Center node
|
|
nodeDataArray: [{ category: "Center", key: "Center"}],
|
|
// the link array was created above
|
|
linkDataArray: linkdata
|
|
});
|
|
}
|
|
|
|
// a conversion function used to get arrowhead information for a Part
|
|
function infoString(obj) {
|
|
var part = obj.part;
|
|
if (part instanceof go.Adornment) part = part.adornedPart;
|
|
var msg = "";
|
|
if (part instanceof go.Link) {
|
|
var link = part;
|
|
msg = "toArrow: " + link.data.toArrow + ";\nfromArrow: " + link.data.fromArrow;
|
|
} else if (part instanceof go.Node) {
|
|
var node = part;
|
|
var link = node.linksConnected.first();
|
|
msg = "toArrow: " + link.data.toArrow + ";\nfromArrow: " + link.data.fromArrow;
|
|
}
|
|
return msg;
|
|
}
|
|
|
|
// a GraphObject.click event handler to show arrowhead information
|
|
function showArrowInfo(e, obj) {
|
|
var msg = infoString(obj);
|
|
if (msg) {
|
|
var status = document.getElementById("myArrowheadInfo");
|
|
if (status) status.textContent = msg;
|
|
}
|
|
}
|
|
</script>
|
|
</head>
|
|
<body onload="init()">
|
|
<div id="sample">
|
|
<!-- 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="myDiagramDiv" style="border: solid 1px black; width:600px; height:500px"></div>
|
|
<div id="myArrowheadInfo" style="color:red"></div>
|
|
<p>
|
|
This sample displays all predefined GoJS arrowheads.
|
|
Select or hover over a Node or its Link to see the names of the arrowheads on the Link.
|
|
</p>
|
|
<p>
|
|
Each Link shows two arrowheads.
|
|
The Link template has a Shape whose <a>Shape.toArrow</a> property is bound to an arrowhead name.
|
|
A different Shape in the template has its <a>Shape.fromArrow</a> property bound to a different arrowhead name.
|
|
Each arrowhead has been scaled up to make it more easily visible.
|
|
</p>
|
|
<p>
|
|
See the definitions of all these arrowheads in the file: <a href="../extensions/Arrowheads.js" target="_blank">Arrowheads.js</a>.
|
|
</p>
|
|
<p>
|
|
For predefined shape geometries, see the <a href="shapes.html">Shapes</a> sample.
|
|
</p>
|
|
</div>
|
|
</body>
|
|
</html> |