@contrail/documents 1.3.7 → 1.3.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -8,3 +8,4 @@ export * from './util/dynamic-text/dynamic-text-util';
8
8
  export * from './document-element-constants';
9
9
  export * from './util/curved-line/point';
10
10
  export * from './util/curved-line/curved-line';
11
+ export * from './util/callout/callout';
package/lib/index.js CHANGED
@@ -24,3 +24,4 @@ __exportStar(require("./util/dynamic-text/dynamic-text-util"), exports);
24
24
  __exportStar(require("./document-element-constants"), exports);
25
25
  __exportStar(require("./util/curved-line/point"), exports);
26
26
  __exportStar(require("./util/curved-line/curved-line"), exports);
27
+ __exportStar(require("./util/callout/callout"), exports);
@@ -0,0 +1,16 @@
1
+ import { LineDefinition, ViewBox, LinkedEdgeDefinition, PositionDefinition, SizeDefinition } from '../../types';
2
+ export declare class Callout {
3
+ static getCalloutLocation({ x1, y1, x2, y2 }: LineDefinition): 'auto' | 'left' | 'right' | 'top' | 'bottom';
4
+ static getCalloutStart({ x, y }: {
5
+ x: any;
6
+ y: any;
7
+ }, elementId?: string, elementDimensions?: ViewBox): LinkedEdgeDefinition;
8
+ static getCalloutEnd({ x, y }: {
9
+ x: any;
10
+ y: any;
11
+ }, elementId?: string): LinkedEdgeDefinition;
12
+ static getCalloutLineEndPosition(location: 'auto' | 'left' | 'right' | 'top' | 'bottom', position: PositionDefinition, size: SizeDefinition): PositionDefinition;
13
+ static getCalloutEndElementPosition(location: 'auto' | 'left' | 'right' | 'top' | 'bottom', position: PositionDefinition, size: SizeDefinition): PositionDefinition;
14
+ private static rotate;
15
+ private static roundTo;
16
+ }
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Callout = void 0;
4
+ class Callout {
5
+ static getCalloutLocation({ x1, y1, x2, y2 }) {
6
+ let location;
7
+ const endCenterRelativeToStart = {
8
+ x: x2 - x1,
9
+ y: y2 - y1,
10
+ };
11
+ const rotatedPosition = this.rotate(endCenterRelativeToStart, -45);
12
+ if (rotatedPosition.x >= 0) {
13
+ if (rotatedPosition.y >= 0)
14
+ location = 'top';
15
+ else
16
+ location = 'left';
17
+ }
18
+ else {
19
+ if (rotatedPosition.y >= 0)
20
+ location = 'right';
21
+ else
22
+ location = 'bottom';
23
+ }
24
+ return location;
25
+ }
26
+ static getCalloutStart({ x, y }, elementId, elementDimensions) {
27
+ if (!elementId) {
28
+ return {
29
+ id: null,
30
+ position: {
31
+ x,
32
+ y,
33
+ },
34
+ };
35
+ }
36
+ return {
37
+ id: elementId,
38
+ position: {
39
+ x: this.roundTo(((x - elementDimensions.x) * 100) / elementDimensions.width),
40
+ y: this.roundTo(((y - elementDimensions.y) * 100) / elementDimensions.height),
41
+ },
42
+ };
43
+ }
44
+ static getCalloutEnd({ x, y }, elementId) {
45
+ if (!elementId) {
46
+ return {
47
+ id: null,
48
+ position: {
49
+ x,
50
+ y,
51
+ },
52
+ };
53
+ }
54
+ return {
55
+ id: elementId,
56
+ location: 'auto',
57
+ };
58
+ }
59
+ static getCalloutLineEndPosition(location, position, size) {
60
+ let x, y;
61
+ switch (location) {
62
+ case 'top':
63
+ x = position.x + size.width * 0.5;
64
+ y = position.y;
65
+ break;
66
+ case 'bottom':
67
+ x = position.x + size.width * 0.5;
68
+ y = position.y + size.height;
69
+ break;
70
+ case 'right':
71
+ x = position.x + size.width;
72
+ y = position.y + size.height * 0.5;
73
+ break;
74
+ case 'left':
75
+ default:
76
+ x = position.x;
77
+ y = position.y + size.height * 0.5;
78
+ break;
79
+ }
80
+ return { x, y };
81
+ }
82
+ static getCalloutEndElementPosition(location, position, size) {
83
+ let x, y;
84
+ switch (location) {
85
+ case 'top':
86
+ x = position.x - size.width * 0.5;
87
+ y = position.y;
88
+ break;
89
+ case 'bottom':
90
+ x = position.x - size.width * 0.5;
91
+ y = position.y - size.height;
92
+ break;
93
+ case 'right':
94
+ x = position.x - size.width;
95
+ y = position.y - size.height * 0.5;
96
+ break;
97
+ case 'left':
98
+ default:
99
+ x = position.x;
100
+ y = position.y - size.height * 0.5;
101
+ break;
102
+ }
103
+ return { x, y };
104
+ }
105
+ static rotate(position, angle, center = { x: 0, y: 0 }) {
106
+ const theta = (angle * Math.PI) / 180;
107
+ const dx = position.x - center.x;
108
+ const dy = position.y - center.y;
109
+ return {
110
+ x: dx * Math.cos(theta) - dy * Math.sin(theta) + center.x,
111
+ y: dx * Math.sin(theta) + dy * Math.cos(theta) + center.y,
112
+ };
113
+ }
114
+ static roundTo(v) {
115
+ return Math.round(v * 10000) / 10000;
116
+ }
117
+ }
118
+ exports.Callout = Callout;
@@ -25,14 +25,8 @@ class CurvedLine {
25
25
  const { p1, p2 } = curves[i];
26
26
  interpolation.push(r * p1.distance(p2));
27
27
  if (c0) {
28
- const diff0 = c0.p2
29
- .clone()
30
- .subtract(c0.p1)
31
- .normalize();
32
- const diff1 = p2
33
- .clone()
34
- .subtract(p1)
35
- .normalize();
28
+ const diff0 = c0.p2.clone().subtract(c0.p1).normalize();
29
+ const diff1 = p2.clone().subtract(p1).normalize();
36
30
  const d = diff0.add(diff1).normalize();
37
31
  distance.push(d);
38
32
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/documents",
3
- "version": "1.3.7",
3
+ "version": "1.3.9",
4
4
  "description": "Documents library for contrail platform",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",