UNPKG

gojs

Version:

Interactive diagrams, charts, and graphs, such as trees, flowcharts, orgcharts, UML, BPMN, or business diagrams

89 lines (83 loc) 3.9 kB
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Realtime Drag Selecting Tool</title> <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." /> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- 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="background-color: white; border: solid 1px black; width: 100%;height: 600px"></div> <p> This sample demonstrates the RealtimeDragSelectingTool, which replaces the standard <a>DragSelectingTool</a>. Press in the background, wait briefly, and then drag to start selecting Nodes or Links that intersect with the box. You can press or release Control (Command on Mac) or Shift while dragging to see how the selection changes. </p> <p> Load it in your own app by including <a href="RealtimeDragSelectingTool.ts">RealtimeDragSelectingTool.ts</a>. Initialize your Diagram by setting <a>ToolManager.dragSelectingTool</a> to a new instance of this tool. For example: </p> <pre> myDiagram.toolManager.dragSelectingTool = new RealtimeDragSelectingTool(); </pre> or <pre> $(go.Diagram, { . . ., "toolManager.dragSelectingTool": $(RealtimeDragSelectingTool, { isPartialInclusion: true }), . . . }) </pre> </div> <script type="module" id="code"> import * as go from "../release/go-module.js"; import { RealtimeDragSelectingTool } from './RealtimeDragSelectingTool.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', { initialDocumentSpot: go.Spot.Center, initialViewportSpot: go.Spot.Center, // replace the standard DragSelectingTool with one that selects while dragging, // and also only requires overlapping bounds with the dragged box to be selected dragSelectingTool: $(RealtimeDragSelectingTool, { isPartialInclusion: true, delay: 50, box: $(go.Part, // replace the magenta box with a red one { layerName: 'Tool', selectable: false }, $(go.Shape, { name: 'SHAPE', fill: 'rgba(255,0,0,0.1)', stroke: 'red', strokeWidth: 2 })) }), // Define the template for Nodes, just some text inside a colored rectangle nodeTemplate: $(go.Node, 'Spot', { width: 70, height: 20 }, $(go.Shape, 'Rectangle', new go.Binding('fill', 'c')), $(go.TextBlock, { margin: 2 }, new go.Binding('text', 'c')) ), // Define the template for Links, just a simple line linkTemplate: $(go.Link, $(go.Shape, { stroke: 'black' })), layout: $(go.TreeLayout) }); myDiagram.model = loadTree(); function loadTree() { // create some tree data const total = 49; const treedata = []; for (let i = 0; i < total; i++) { // these property names are also specified when creating the TreeModel const d = { key: i, c: go.Brush.randomColor(), parent: (i > 0 ? Math.floor(Math.random() * i / 2) : undefined) // the random parent's key }; treedata.push(d); } return new go.TreeModel(treedata); } window.myDiagram = myDiagram; // Attach to the window for console debugging </script> </body> </html>