UNPKG

7.24 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: This customized DragSelectingTool selects and deselects parts continuously while the user is dragging a box, rather than when the tool finishes."/>
7<link rel="stylesheet" href="../assets/css/style.css"/>
8<!-- Copyright 1998-2021 by Northwoods Software Corporation. -->
9<title>Realtime Drag Selecting Tool</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="background-color: white; border: solid 1px black; width: 100%;height: 600px"></div>
55 <p>
56 This sample demonstrates the RealtimeDragSelectingTool, which replaces the standard <a>DragSelectingTool</a>. Press
57 in the background, wait briefly, and then drag to start selecting Nodes or Links that intersect with the box. You can
58 press or release Control (Command on Mac) or Shift while dragging to see how the selection changes.
59 </p>
60 <p>
61 Load it in your own app by including <a href="RealtimeDragSelectingTool.ts">RealtimeDragSelectingTool.ts</a>. Initialize
62 your Diagram by setting <a>ToolManager.dragSelectingTool</a> to a new instance of this tool. For example:
63 </p>
64 <pre>
65myDiagram.toolManager.dragSelectingTool = new RealtimeDragSelectingTool();
66 </pre>
67 or
68 <pre>
69$(go.Diagram, { . . .,
70 "toolManager.dragSelectingTool": $(RealtimeDragSelectingTool, { isPartialInclusion: true }),
71 . . . })
72 </pre>
73 </div>
74
75 <script type="module" id="code">
76 import * as go from "../release/go-module.js";
77 import { RealtimeDragSelectingTool } from './RealtimeDragSelectingTool.js';
78
79 if (window.goSamples) goSamples(); // init for the samples -- you don't need to call this
80 const $ = go.GraphObject.make; // for conciseness in defining templates
81
82 const myDiagram = $(go.Diagram, 'myDiagramDiv',
83 {
84 initialDocumentSpot: go.Spot.Center,
85 initialViewportSpot: go.Spot.Center,
86 // replace the standard DragSelectingTool with one that selects while dragging,
87 // and also only requires overlapping bounds with the dragged box to be selected
88 dragSelectingTool: $(RealtimeDragSelectingTool,
89 {
90 isPartialInclusion: true, delay: 50,
91 box: $(go.Part, // replace the magenta box with a red one
92 { layerName: 'Tool', selectable: false }, $(go.Shape, {
93 name: 'SHAPE', fill: 'rgba(255,0,0,0.1)',
94 stroke: 'red', strokeWidth: 2
95 }))
96 }),
97 // Define the template for Nodes, just some text inside a colored rectangle
98 nodeTemplate:
99 $(go.Node, 'Spot',
100 { width: 70, height: 20 },
101 $(go.Shape, 'Rectangle', new go.Binding('fill', 'c')),
102 $(go.TextBlock, { margin: 2 }, new go.Binding('text', 'c'))
103 ),
104 // Define the template for Links, just a simple line
105 linkTemplate: $(go.Link, $(go.Shape, { stroke: 'black' })),
106 layout: $(go.TreeLayout)
107 });
108
109 myDiagram.model = loadTree();
110
111 function loadTree() {
112 // create some tree data
113 const total = 49;
114 const treedata = [];
115 for (let i = 0; i < total; i++) {
116 // these property names are also specified when creating the TreeModel
117 const d = {
118 key: i,
119 c: go.Brush.randomColor(),
120 parent: (i > 0 ? Math.floor(Math.random() * i / 2) : undefined) // the random parent's key
121 };
122 treedata.push(d);
123 }
124 return new go.TreeModel(treedata);
125 }
126
127 window.myDiagram = myDiagram; // Attach to the window for console debugging
128 </script>
129 </div>
130 <!-- * * * * * * * * * * * * * -->
131 <!-- End of GoJS sample code -->
132 </div>
133</body>
134<!-- This script is part of the gojs.net website, and is not needed to run the sample -->
135<script src="../assets/js/goSamples.js"></script>
136</html>