UNPKG

7.36 kBHTMLView Raw
1<!DOCTYPE html>
2<html lang="en">
3<head>
4<meta charset="utf-8"/>
5<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, viewport-fit=cover"/>
6<meta name="description" content="TypeScript: A demonstration of the SectorReshapingTool extension."/>
7<link rel="stylesheet" href="../assets/css/style.css"/>
8<!-- Copyright 1998-2021 by Northwoods Software Corporation. -->
9<title>Tool for Reshaping a Sector of a Circle</title>
10</head>
11
12<body>
13 <!-- This top nav is not part of the sample code -->
14 <nav id="navTop" class="w-full z-30 top-0 text-white bg-nwoods-primary">
15 <div class="w-full container max-w-screen-lg mx-auto flex flex-wrap sm:flex-nowrap items-center justify-between mt-0 py-2">
16 <div class="md:pl-4">
17 <a class="text-white hover:text-white no-underline hover:no-underline
18 font-bold text-2xl lg:text-4xl rounded-lg hover:bg-nwoods-secondary " href="../">
19 <h1 class="mb-0 p-1 ">GoJS</h1>
20 </a>
21 </div>
22 <button id="topnavButton" class="rounded-lg sm:hidden focus:outline-none focus:ring" aria-label="Navigation">
23 <svg fill="currentColor" viewBox="0 0 20 20" class="w-6 h-6">
24 <path id="topnavOpen" fill-rule="evenodd" d="M3 5a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM3 10a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM9 15a1 1 0 011-1h6a1 1 0 110 2h-6a1 1 0 01-1-1z" clip-rule="evenodd"></path>
25 <path id="topnavClosed" class="hidden" fill-rule="evenodd" d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clip-rule="evenodd"></path>
26 </svg>
27 </button>
28 <div id="topnavList" class="hidden sm:block items-center w-auto mt-0 text-white p-0 z-20">
29 <ul class="list-reset list-none font-semibold flex justify-end flex-wrap sm:flex-nowrap items-center px-0 pb-0">
30 <li class="p-1 sm:p-0"><a class="topnav-link" href="../learn/">Learn</a></li>
31 <li class="p-1 sm:p-0"><a class="topnav-link" href="../samples/">Samples</a></li>
32 <li class="p-1 sm:p-0"><a class="topnav-link" href="../intro/">Intro</a></li>
33 <li class="p-1 sm:p-0"><a class="topnav-link" href="../api/">API</a></li>
34 <li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/products/register.html">Register</a></li>
35 <li class="p-1 sm:p-0"><a class="topnav-link" href="../download.html">Download</a></li>
36 <li class="p-1 sm:p-0"><a class="topnav-link" href="https://forum.nwoods.com/c/gojs/11">Forum</a></li>
37 <li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/contact.html"
38 target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/contact.html', 'contact');">Contact</a></li>
39 <li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/sales/index.html"
40 target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/sales/index.html', 'buy');">Buy</a></li>
41 </ul>
42 </div>
43 </div>
44 <hr class="border-b border-gray-600 opacity-50 my-0 py-0" />
45 </nav>
46 <div class="md:flex flex-col md:flex-row md:min-h-screen w-full max-w-screen-xl mx-auto">
47 <div id="navSide" class="flex flex-col w-full md:w-48 text-gray-700 bg-white flex-shrink-0"></div>
48 <!-- * * * * * * * * * * * * * -->
49 <!-- Start of GoJS sample code -->
50
51
52 <div class="p-4 w-full">
53 <div id="sample">
54 <div id="myDiagramDiv" style="border: solid 1px black; width:100%; height:600px"></div>
55 <p>
56 Two of the handles permit changing the angles of the sector; one handle permits changing the radius of the sector.
57 </p>
58 <p>
59 Note that the <a>Geometry</a> returned by <code>makeSector</code> always returns a Geometry that
60 occupies the area that would be occupied by a full circle. That Geometry-creating function also
61 depends on three data properties, <code>radius</code>, <code>angle</code>, and <code>sweep</code>.
62 </p>
63 </div>
64
65 <script type="module" id="code">
66 import * as go from "../release/go-module.js";
67 import { SectorReshapingTool } from './SectorReshapingTool.js';
68
69 if (window.goSamples) goSamples(); // init for the samples -- you don't need to call this
70 const $ = go.GraphObject.make;
71
72 const myDiagram = $(go.Diagram, 'myDiagramDiv', {
73 'animationManager.isEnabled': false,
74 'undoManager.isEnabled': true
75 });
76
77 // install the SectorReshapingTool as a mouse-down tool
78 myDiagram.toolManager.mouseDownTools.add(new SectorReshapingTool());
79
80 function makeSector(data) {
81 const radius = SectorReshapingTool.getRadius(data);
82 const angle = SectorReshapingTool.getAngle(data);
83 const sweep = SectorReshapingTool.getSweep(data);
84 const start = new go.Point(radius, 0).rotate(angle);
85 // this is much more efficient than calling go.GraphObject.make:
86 const geo = new go.Geometry()
87 .add(new go.PathFigure(radius + start.x, radius + start.y) // start point
88 .add(new go.PathSegment(go.PathSegment.Arc, angle, sweep, // angles
89 radius, radius, // center
90 radius, radius)) // radius
91 .add(new go.PathSegment(go.PathSegment.Line, radius, radius).close()))
92 .add(new go.PathFigure(0, 0)) // make sure the Geometry always includes the whole circle
93 .add(new go.PathFigure(2 * radius, 2 * radius)); // even if only a small sector is "lit"
94 return geo;
95 }
96
97 myDiagram.nodeTemplate =
98 $(go.Node, 'Spot',
99 {
100 locationSpot: go.Spot.Center, locationObjectName: 'LAMP',
101 selectionObjectName: 'LAMP', selectionAdorned: false
102 },
103 new go.Binding('location', 'loc', go.Point.parse).makeTwoWay(go.Point.stringify),
104 // selecting a Node brings it forward in the z-order
105 new go.Binding('layerName', 'isSelected', (s) => s ? 'Foreground' : '').ofObject(),
106 $(go.Panel, 'Spot', { name: 'LAMP' },
107 $(go.Shape, // arc
108 { fill: 'yellow', stroke: 'lightgray', strokeWidth: 0.5 },
109 new go.Binding('geometry', '', makeSector)),
110 $(go.Shape, 'Circle', { name: 'SHAPE', width: 6, height: 6 })),
111 $(go.TextBlock,
112 {
113 alignment: new go.Spot(0.5, 0.5, 0, 3), alignmentFocus: go.Spot.Top,
114 stroke: 'blue', background: 'rgba(255,255,255,0.3)'
115 },
116 new go.Binding('alignment', 'spot', go.Spot.parse).makeTwoWay(go.Spot.stringify),
117 new go.Binding('text', 'name'))
118 );
119
120 myDiagram.model = new go.GraphLinksModel([
121 { name: 'Alpha', radius: 70, sweep: 120 },
122 { name: 'Beta', radius: 70, sweep: 80, angle: 200 }
123 ]);
124 myDiagram.commandHandler.selectAll(); // to show the tool handles
125
126 window.myDiagram = myDiagram; // Attach to the window for console debugging
127 </script>
128 </div>
129 <!-- * * * * * * * * * * * * * -->
130 <!-- End of GoJS sample code -->
131 </div>
132</body>
133<!-- This script is part of the gojs.net website, and is not needed to run the sample -->
134<script src="../assets/js/goSamples.js"></script>
135</html>