UNPKG

3.29 kBJavaScriptView Raw
1/*
2* Copyright (C) 1998-2021 by Northwoods Software Corporation. All Rights Reserved.
3*/
4/*
5* This is an extension and not part of the main GoJS library.
6* Note that the API for this class may change with any version, even point releases.
7* If you intend to use an extension in production, you should copy the code to your own source directory.
8* Extensions can be found in the GoJS kit under the extensions or extensionsTS folders.
9* See the Extensions intro page (https://gojs.net/latest/intro/extensions.html) for more information.
10*/
11import * as go from '../release/go-module.js';
12/**
13 * The OverviewResizingTool class lets the user resize the box within an overview.
14 *
15 * If you want to experiment with this extension, try the <a href="../../extensionsJSM/OverviewResizing.html">Overview Resizing</a> sample.
16 * @category Tool Extension
17 */
18export class OverviewResizingTool extends go.ResizingTool {
19 /**
20 * Constructs an OverviewResizingTool and sets the name for the tool.
21 */
22 constructor() {
23 super();
24 this.name = 'OverviewResizing';
25 this._handleSize = new go.Size(6, 6);
26 }
27 /**
28 * @hidden @internal
29 * @param {Shape} resizeBox
30 * @return {Adornment}
31 */
32 makeAdornment(resizeBox) {
33 this._handleSize.setTo(resizeBox.strokeWidth * 3, resizeBox.strokeWidth * 3);
34 // Set up the resize adornment
35 const ad = new go.Adornment();
36 ad.type = go.Panel.Spot;
37 ad.locationSpot = go.Spot.Center;
38 const ph = new go.Placeholder();
39 ph.isPanelMain = true;
40 ad.add(ph);
41 const hnd = new go.Shape();
42 hnd.name = 'RSZHND';
43 hnd.figure = 'Rectangle';
44 hnd.desiredSize = this._handleSize;
45 hnd.cursor = 'se-resize';
46 hnd.alignment = go.Spot.BottomRight;
47 hnd.alignmentFocus = go.Spot.Center;
48 ad.add(hnd);
49 ad.adornedObject = resizeBox;
50 return ad;
51 }
52 /**
53 * @hidden @internal
54 * Keep the resize handle properly sized as the scale is changing.
55 * This overrides an undocumented method on the ResizingTool.
56 * @param {Adornment} elt
57 * @param {number} angle
58 */
59 updateResizeHandles(elt, angle) {
60 if (elt === null)
61 return;
62 const handle = elt.findObject('RSZHND');
63 const box = elt.adornedObject;
64 this._handleSize.setTo(box.strokeWidth * 3, box.strokeWidth * 3);
65 handle.desiredSize = this._handleSize;
66 }
67 /**
68 * Overrides {@link ResizingTool#resize} to resize the overview box via setting the observed diagram's scale.
69 * @param {Rect} newr the intended new rectangular bounds the overview box.
70 */
71 resize(newr) {
72 const overview = this.diagram;
73 const observed = overview.observed;
74 if (observed === null)
75 return;
76 const oldr = observed.viewportBounds.copy();
77 const oldscale = observed.scale;
78 if (oldr.width !== newr.width || oldr.height !== newr.height) {
79 if (newr.width > 0 && newr.height > 0) {
80 observed.scale = Math.min(oldscale * oldr.width / newr.width, oldscale * oldr.height / newr.height);
81 }
82 }
83 }
84}