UNPKG

3.17 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// This file holds the definitions of two useful figures: "RoundedTopRectangle" and "RoundedBottomRectangle".
13// These are demonstrated at ../samples/twoHalves.html and ../samples/roundedGroups.html.
14go.Shape.defineFigureGenerator('RoundedTopRectangle', function (shape, w, h) {
15 // this figure takes one parameter, the size of the corner
16 let p1 = 5; // default corner size
17 if (shape !== null) {
18 const param1 = shape.parameter1;
19 if (!isNaN(param1) && param1 >= 0)
20 p1 = param1; // can't be negative or NaN
21 }
22 p1 = Math.min(p1, w / 2);
23 p1 = Math.min(p1, h / 2); // limit by whole height or by half height?
24 const geo = new go.Geometry();
25 // a single figure consisting of straight lines and quarter-circle arcs
26 geo.add(new go.PathFigure(0, p1)
27 .add(new go.PathSegment(go.PathSegment.Arc, 180, 90, p1, p1, p1, p1))
28 .add(new go.PathSegment(go.PathSegment.Line, w - p1, 0))
29 .add(new go.PathSegment(go.PathSegment.Arc, 270, 90, w - p1, p1, p1, p1))
30 .add(new go.PathSegment(go.PathSegment.Line, w, h))
31 .add(new go.PathSegment(go.PathSegment.Line, 0, h).close()));
32 // don't intersect with two top corners when used in an "Auto" Panel
33 geo.spot1 = new go.Spot(0, 0, 0.3 * p1, 0.3 * p1);
34 geo.spot2 = new go.Spot(1, 1, -0.3 * p1, 0);
35 return geo;
36});
37go.Shape.defineFigureGenerator('RoundedBottomRectangle', function (shape, w, h) {
38 // this figure takes one parameter, the size of the corner
39 let p1 = 5; // default corner size
40 if (shape !== null) {
41 const param1 = shape.parameter1;
42 if (!isNaN(param1) && param1 >= 0)
43 p1 = param1; // can't be negative or NaN
44 }
45 p1 = Math.min(p1, w / 2);
46 p1 = Math.min(p1, h / 2); // limit by whole height or by half height?
47 const geo = new go.Geometry();
48 // a single figure consisting of straight lines and quarter-circle arcs
49 geo.add(new go.PathFigure(0, 0)
50 .add(new go.PathSegment(go.PathSegment.Line, w, 0))
51 .add(new go.PathSegment(go.PathSegment.Line, w, h - p1))
52 .add(new go.PathSegment(go.PathSegment.Arc, 0, 90, w - p1, h - p1, p1, p1))
53 .add(new go.PathSegment(go.PathSegment.Line, p1, h))
54 .add(new go.PathSegment(go.PathSegment.Arc, 90, 90, p1, h - p1, p1, p1).close()));
55 // don't intersect with two bottom corners when used in an "Auto" Panel
56 geo.spot1 = new go.Spot(0, 0, 0.3 * p1, 0);
57 geo.spot2 = new go.Spot(1, 1, -0.3 * p1, -0.3 * p1);
58 return geo;
59});