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