gojs
Version:
Interactive diagrams, charts, and graphs, such as trees, flowcharts, orgcharts, UML, BPMN, or business diagrams
68 lines (61 loc) • 2.66 kB
HTML
<html>
<head>
<meta charset="UTF-8">
<title>Balloon Link</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="TypeScript: A demonstration of the BalloonLink extension for implementing word balloons or speech bubbles as comments in diagrams about particular objects." />
<!-- Copyright 1998-2020 by Northwoods Software Corporation. -->
<script src="../assets/js/goSamples.js"></script> <!-- this is only for the GoJS Samples framework -->
</head>
<body>
<div id="sample">
<div id="myDiagramDiv" style="border: solid 1px black; width:300px; height:300px"></div>
<p>
A <b>BalloonLink</b> is a custom <a>Link</a> that draws a "balloon" shape around the Link.fromNode. It will create
a triangular shape with the base at the fromNode and the other point at the toNode. It is defined in its own file,
as <a href="BalloonLink.ts">BalloonLink.ts</a>.
</p>
<p>
Usage can also be seen in the <a href="../samples/comments.html">Comments</a> sample.
</p>
</div>
<script type="module" id="code">
import * as go from "../release/go-module.js";
import { BalloonLink } from "./BalloonLink.js";
if (window.goSamples) goSamples(); // init for the samples -- you don't need to call this
const $ = go.GraphObject.make; // for conciseness in defining templates
const myDiagram =
$(go.Diagram, 'myDiagramDiv', // create a Diagram for the DIV HTML element
{
'undoManager.isEnabled': true // enable undo & redo
});
// define a simple Node template
myDiagram.nodeTemplate =
$(go.Node, 'Auto', // the Shape will go around the TextBlock
$(go.Shape, 'Rectangle', { strokeWidth: 0 },
// Shape.fill is bound to Node.data.color
new go.Binding('fill', 'color')),
$(go.TextBlock,
{ margin: 8 }, // some room around the text
// TextBlock.text is bound to Node.data.key
new go.Binding('text', 'key'))
);
myDiagram.linkTemplate =
$(BalloonLink,
$(go.Shape,
{ stroke: 'limegreen', strokeWidth: 3, fill: 'limegreen' })
);
// create the model data that will be represented by Nodes and Links
myDiagram.model = new go.GraphLinksModel(
[
{ key: 'Alpha', color: 'lightblue' },
{ key: 'Beta', color: 'orange' }
],
[
{ from: 'Alpha', to: 'Beta' }
]);
window.myDiagram = myDiagram; // Attach to the window for console debugging
</script>
</body>
</html>