@api-client/ui 0.2.2 → 0.2.3

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.
Files changed (170) hide show
  1. package/package.json +7 -2
  2. package/test/env.ts +15 -0
  3. package/test/tsconfig.json +1 -7
  4. package/web-test-runner.config.js +5 -1
  5. package/build/src/visualization/elements/VizAssociationElement.d.ts +0 -4
  6. package/build/src/visualization/elements/VizAssociationElement.d.ts.map +0 -1
  7. package/build/src/visualization/elements/VizAssociationElement.js +0 -4
  8. package/build/src/visualization/elements/VizAssociationElement.js.map +0 -1
  9. package/build/src/visualization/elements/VizWorkspaceElement.d.ts +0 -110
  10. package/build/src/visualization/elements/VizWorkspaceElement.d.ts.map +0 -1
  11. package/build/src/visualization/elements/VizWorkspaceElement.js +0 -321
  12. package/build/src/visualization/elements/VizWorkspaceElement.js.map +0 -1
  13. package/build/src/visualization/elements/WorkspaceStyles.d.ts +0 -3
  14. package/build/src/visualization/elements/WorkspaceStyles.d.ts.map +0 -1
  15. package/build/src/visualization/elements/WorkspaceStyles.js +0 -168
  16. package/build/src/visualization/elements/WorkspaceStyles.js.map +0 -1
  17. package/build/src/visualization/lib/AnchorFinder.d.ts +0 -64
  18. package/build/src/visualization/lib/AnchorFinder.d.ts.map +0 -1
  19. package/build/src/visualization/lib/AnchorFinder.js +0 -107
  20. package/build/src/visualization/lib/AnchorFinder.js.map +0 -1
  21. package/build/src/visualization/lib/AnchorUtils.d.ts +0 -10
  22. package/build/src/visualization/lib/AnchorUtils.d.ts.map +0 -1
  23. package/build/src/visualization/lib/AnchorUtils.js +0 -44
  24. package/build/src/visualization/lib/AnchorUtils.js.map +0 -1
  25. package/build/src/visualization/lib/AssociationAnchors.d.ts +0 -134
  26. package/build/src/visualization/lib/AssociationAnchors.d.ts.map +0 -1
  27. package/build/src/visualization/lib/AssociationAnchors.js +0 -351
  28. package/build/src/visualization/lib/AssociationAnchors.js.map +0 -1
  29. package/build/src/visualization/lib/LabelSketch.d.ts +0 -16
  30. package/build/src/visualization/lib/LabelSketch.d.ts.map +0 -1
  31. package/build/src/visualization/lib/LabelSketch.js +0 -53
  32. package/build/src/visualization/lib/LabelSketch.js.map +0 -1
  33. package/build/src/visualization/lib/LineSketch.d.ts +0 -26
  34. package/build/src/visualization/lib/LineSketch.d.ts.map +0 -1
  35. package/build/src/visualization/lib/LineSketch.js +0 -55
  36. package/build/src/visualization/lib/LineSketch.js.map +0 -1
  37. package/build/src/visualization/lib/Point.d.ts +0 -74
  38. package/build/src/visualization/lib/Point.d.ts.map +0 -1
  39. package/build/src/visualization/lib/Point.js +0 -121
  40. package/build/src/visualization/lib/Point.js.map +0 -1
  41. package/build/src/visualization/lib/PositionUtils.d.ts +0 -65
  42. package/build/src/visualization/lib/PositionUtils.d.ts.map +0 -1
  43. package/build/src/visualization/lib/PositionUtils.js +0 -205
  44. package/build/src/visualization/lib/PositionUtils.js.map +0 -1
  45. package/build/src/visualization/lib/SelectionManager.d.ts +0 -183
  46. package/build/src/visualization/lib/SelectionManager.d.ts.map +0 -1
  47. package/build/src/visualization/lib/SelectionManager.js +0 -481
  48. package/build/src/visualization/lib/SelectionManager.js.map +0 -1
  49. package/build/src/visualization/lib/ShapeArtist.d.ts +0 -45
  50. package/build/src/visualization/lib/ShapeArtist.d.ts.map +0 -1
  51. package/build/src/visualization/lib/ShapeArtist.js +0 -209
  52. package/build/src/visualization/lib/ShapeArtist.js.map +0 -1
  53. package/build/src/visualization/lib/SvgMarkers.d.ts +0 -14
  54. package/build/src/visualization/lib/SvgMarkers.d.ts.map +0 -1
  55. package/build/src/visualization/lib/SvgMarkers.js +0 -77
  56. package/build/src/visualization/lib/SvgMarkers.js.map +0 -1
  57. package/build/src/visualization/lib/TipSketch.d.ts +0 -26
  58. package/build/src/visualization/lib/TipSketch.d.ts.map +0 -1
  59. package/build/src/visualization/lib/TipSketch.js +0 -77
  60. package/build/src/visualization/lib/TipSketch.js.map +0 -1
  61. package/build/src/visualization/lib/TouchSupport.d.ts +0 -14
  62. package/build/src/visualization/lib/TouchSupport.d.ts.map +0 -1
  63. package/build/src/visualization/lib/TouchSupport.js +0 -55
  64. package/build/src/visualization/lib/TouchSupport.js.map +0 -1
  65. package/build/src/visualization/lib/Utils.d.ts +0 -25
  66. package/build/src/visualization/lib/Utils.d.ts.map +0 -1
  67. package/build/src/visualization/lib/Utils.js +0 -59
  68. package/build/src/visualization/lib/Utils.js.map +0 -1
  69. package/build/src/visualization/lib/VisualizationTypes.d.ts +0 -216
  70. package/build/src/visualization/lib/VisualizationTypes.d.ts.map +0 -1
  71. package/build/src/visualization/lib/VisualizationTypes.js +0 -3
  72. package/build/src/visualization/lib/VisualizationTypes.js.map +0 -1
  73. package/build/src/visualization/lib/WorkspaceAlignment.d.ts +0 -51
  74. package/build/src/visualization/lib/WorkspaceAlignment.d.ts.map +0 -1
  75. package/build/src/visualization/lib/WorkspaceAlignment.js +0 -243
  76. package/build/src/visualization/lib/WorkspaceAlignment.js.map +0 -1
  77. package/build/src/visualization/lib/WorkspaceDebugging.d.ts +0 -104
  78. package/build/src/visualization/lib/WorkspaceDebugging.d.ts.map +0 -1
  79. package/build/src/visualization/lib/WorkspaceDebugging.js +0 -286
  80. package/build/src/visualization/lib/WorkspaceDebugging.js.map +0 -1
  81. package/build/src/visualization/lib/WorkspaceEdges.d.ts +0 -293
  82. package/build/src/visualization/lib/WorkspaceEdges.d.ts.map +0 -1
  83. package/build/src/visualization/lib/WorkspaceEdges.js +0 -1073
  84. package/build/src/visualization/lib/WorkspaceEdges.js.map +0 -1
  85. package/build/src/visualization/lib/WorkspaceGestures.d.ts +0 -119
  86. package/build/src/visualization/lib/WorkspaceGestures.d.ts.map +0 -1
  87. package/build/src/visualization/lib/WorkspaceGestures.js +0 -376
  88. package/build/src/visualization/lib/WorkspaceGestures.js.map +0 -1
  89. package/build/src/visualization/lib/WorkspaceSizing.d.ts +0 -66
  90. package/build/src/visualization/lib/WorkspaceSizing.d.ts.map +0 -1
  91. package/build/src/visualization/lib/WorkspaceSizing.js +0 -168
  92. package/build/src/visualization/lib/WorkspaceSizing.js.map +0 -1
  93. package/build/src/visualization/lib/lines/RectilinearLine.d.ts +0 -114
  94. package/build/src/visualization/lib/lines/RectilinearLine.d.ts.map +0 -1
  95. package/build/src/visualization/lib/lines/RectilinearLine.js +0 -605
  96. package/build/src/visualization/lib/lines/RectilinearLine.js.map +0 -1
  97. package/build/src/visualization/lib/tips/RectilinearTip.d.ts +0 -26
  98. package/build/src/visualization/lib/tips/RectilinearTip.d.ts.map +0 -1
  99. package/build/src/visualization/lib/tips/RectilinearTip.js +0 -149
  100. package/build/src/visualization/lib/tips/RectilinearTip.js.map +0 -1
  101. package/build/src/visualization/lib/tips/TipArtist.d.ts +0 -22
  102. package/build/src/visualization/lib/tips/TipArtist.d.ts.map +0 -1
  103. package/build/src/visualization/lib/tips/TipArtist.js +0 -31
  104. package/build/src/visualization/lib/tips/TipArtist.js.map +0 -1
  105. package/build/src/visualization/lib/types.d.ts +0 -164
  106. package/build/src/visualization/lib/types.d.ts.map +0 -1
  107. package/build/src/visualization/lib/types.js +0 -2
  108. package/build/src/visualization/lib/types.js.map +0 -1
  109. package/build/src/visualization/plugin/dnd/DragAndDropPlugin.d.ts +0 -126
  110. package/build/src/visualization/plugin/dnd/DragAndDropPlugin.d.ts.map +0 -1
  111. package/build/src/visualization/plugin/dnd/DragAndDropPlugin.js +0 -260
  112. package/build/src/visualization/plugin/dnd/DragAndDropPlugin.js.map +0 -1
  113. package/build/src/visualization/plugin/group-selection/GroupSelection.d.ts +0 -93
  114. package/build/src/visualization/plugin/group-selection/GroupSelection.d.ts.map +0 -1
  115. package/build/src/visualization/plugin/group-selection/GroupSelection.js +0 -250
  116. package/build/src/visualization/plugin/group-selection/GroupSelection.js.map +0 -1
  117. package/build/src/visualization/plugin/positioning/DataModelLayout.d.ts +0 -10
  118. package/build/src/visualization/plugin/positioning/DataModelLayout.d.ts.map +0 -1
  119. package/build/src/visualization/plugin/positioning/DataModelLayout.js +0 -105
  120. package/build/src/visualization/plugin/positioning/DataModelLayout.js.map +0 -1
  121. package/build/src/visualization/plugin/positioning/WorkspaceLayout.d.ts +0 -93
  122. package/build/src/visualization/plugin/positioning/WorkspaceLayout.d.ts.map +0 -1
  123. package/build/src/visualization/plugin/positioning/WorkspaceLayout.js +0 -96
  124. package/build/src/visualization/plugin/positioning/WorkspaceLayout.js.map +0 -1
  125. package/build/src/visualization/viz-association.d.ts +0 -7
  126. package/build/src/visualization/viz-association.d.ts.map +0 -1
  127. package/build/src/visualization/viz-association.js +0 -3
  128. package/build/src/visualization/viz-association.js.map +0 -1
  129. package/build/src/visualization/viz-workspace.d.ts +0 -7
  130. package/build/src/visualization/viz-workspace.d.ts.map +0 -1
  131. package/build/src/visualization/viz-workspace.js +0 -3
  132. package/build/src/visualization/viz-workspace.js.map +0 -1
  133. package/src/visualization/elements/VizAssociationElement.ts +0 -3
  134. package/src/visualization/elements/VizWorkspaceElement.ts +0 -302
  135. package/src/visualization/elements/WorkspaceStyles.ts +0 -168
  136. package/src/visualization/lib/AnchorFinder.ts +0 -112
  137. package/src/visualization/lib/AnchorUtils.ts +0 -53
  138. package/src/visualization/lib/AssociationAnchors.ts +0 -418
  139. package/src/visualization/lib/LabelSketch.ts +0 -67
  140. package/src/visualization/lib/LineSketch.ts +0 -62
  141. package/src/visualization/lib/Point.ts +0 -134
  142. package/src/visualization/lib/PositionUtils.ts +0 -218
  143. package/src/visualization/lib/SelectionManager.ts +0 -513
  144. package/src/visualization/lib/ShapeArtist.ts +0 -222
  145. package/src/visualization/lib/SvgMarkers.ts +0 -80
  146. package/src/visualization/lib/TipSketch.ts +0 -91
  147. package/src/visualization/lib/TouchSupport.ts +0 -72
  148. package/src/visualization/lib/Utils.ts +0 -63
  149. package/src/visualization/lib/VisualizationTypes.ts +0 -232
  150. package/src/visualization/lib/WorkspaceAlignment.ts +0 -261
  151. package/src/visualization/lib/WorkspaceDebugging.ts +0 -313
  152. package/src/visualization/lib/WorkspaceEdges.ts +0 -1153
  153. package/src/visualization/lib/WorkspaceGestures.ts +0 -400
  154. package/src/visualization/lib/WorkspaceSizing.ts +0 -181
  155. package/src/visualization/lib/lines/RectilinearLine.ts +0 -589
  156. package/src/visualization/lib/tips/RectilinearTip.ts +0 -156
  157. package/src/visualization/lib/tips/TipArtist.ts +0 -34
  158. package/src/visualization/lib/types.ts +0 -173
  159. package/src/visualization/plugin/dnd/DragAndDropPlugin.ts +0 -294
  160. package/src/visualization/plugin/group-selection/GroupSelection.ts +0 -271
  161. package/src/visualization/plugin/positioning/DataModelLayout.ts +0 -114
  162. package/src/visualization/plugin/positioning/WorkspaceLayout.ts +0 -149
  163. package/src/visualization/viz-association.ts +0 -9
  164. package/src/visualization/viz-workspace.ts +0 -9
  165. package/test/env.d.ts +0 -9
  166. package/test/env.js +0 -7
  167. package/test/visualization/lib/AnchorFinder.test.ts +0 -313
  168. package/test/visualization/lib/AnchorUtils.test.ts +0 -178
  169. package/test/visualization/lib/PositionUtils.test.ts +0 -406
  170. package/test/visualization/lib/test-styles.css +0 -80
@@ -1,589 +0,0 @@
1
- import { findDirection } from '../PositionUtils.js'
2
- import { Point } from '../Point.js'
3
- import { ILineSketchOptions, IVisualizationRectilinearLineShape } from '../VisualizationTypes.js'
4
- import { GeoDirection, IWorkspaceEdge } from '../types.js'
5
-
6
- export const startWest = Symbol('startWest')
7
- export const startEast = Symbol('startEast')
8
- export const startSouth = Symbol('startSouth')
9
- export const startNorth = Symbol('startNorth')
10
- export const sketchEastEast = Symbol('sketchEastEast')
11
- export const sketchEastWest = Symbol('sketchEastWest')
12
- export const sketchEastSouth = Symbol('sketchEastSouth')
13
- export const sketchEastNorth = Symbol('sketchEastNorth')
14
- export const sketchNorthWest = Symbol('sketchNorthWest')
15
- export const sketchNorthEast = Symbol('sketchNorthEast')
16
- export const sketchNorthSouth = Symbol('sketchNorthSouth')
17
- export const sketchNorthNorth = Symbol('sketchNorthNorth')
18
- export const sketchWestSouth = Symbol('sketchWestSouth')
19
- export const sketchWestWest = Symbol('sketchWestWest')
20
- export const sketchWestEast = Symbol('sketchWestEast')
21
- export const sketchWestNorth = Symbol('sketchWestNorth')
22
- export const sketchSouthNorth = Symbol('sketchSouthNorth')
23
- export const sketchSouthWest = Symbol('sketchSouthWest')
24
- export const sketchSouthSouth = Symbol('sketchSouthSouth')
25
- export const sketchSouthEast = Symbol('sketchSouthEast')
26
-
27
- export const ElbowThreshold = 24
28
-
29
- /**
30
- * A class that draws a rectilinear line
31
- */
32
- export class RectilinearLine {
33
- ep: Point
34
-
35
- sp: Point
36
-
37
- source: DOMRect
38
-
39
- target: DOMRect
40
-
41
- others?: IWorkspaceEdge[]
42
-
43
- /**
44
- * The default padding to use when computing distance between the line and an object.
45
- */
46
- overlapPadding = 20
47
-
48
- /**
49
- * The list of all points (start + end + control points)
50
- */
51
- coordinates: Point[]
52
-
53
- /**
54
- * The list of all control points.
55
- */
56
- controlPoints: Point[] = []
57
-
58
- transformOrigin: string
59
-
60
- /**
61
- * The delta between Y coordinates
62
- */
63
- dx: number
64
-
65
- /**
66
- * The delta between Y coordinates
67
- */
68
- dy: number
69
-
70
- /**
71
- * Half distance between start.x and end.x
72
- */
73
- halfX: number
74
-
75
- /**
76
- * Half distance between start.y and end.y
77
- */
78
- halfY: number
79
-
80
- constructor(config: ILineSketchOptions) {
81
- const { endPoint, target, startPoint, source, others } = config
82
- this.ep = endPoint
83
- this.sp = startPoint
84
- this.source = source
85
- this.target = target
86
- this.others = others
87
- this.coordinates = [startPoint]
88
- this.transformOrigin = `${startPoint.x}px ${endPoint.y}px`
89
- this.dx = endPoint.x - startPoint.x
90
- this.dy = endPoint.y - startPoint.y
91
- this.halfX = Math.abs(this.dx) / 2
92
- this.halfY = Math.abs(this.dy) / 2
93
- }
94
-
95
- /**
96
- * Sketches a regular line.
97
- * @returns Computed model for the association.
98
- */
99
- sketch(): IVisualizationRectilinearLineShape | null {
100
- const { sp, ep, source, target } = this
101
- if (!sp.validate() || !ep.validate()) {
102
- return null
103
- }
104
- const directions = findDirection(sp, ep, source, target)
105
- const { start, end } = directions
106
- // console.log(start, end);
107
- if (start === 'west') {
108
- this[startWest](end)
109
- } else if (start === 'south') {
110
- this[startSouth](end)
111
- } else if (start === 'east') {
112
- this[startEast](end)
113
- } else {
114
- this[startNorth](end)
115
- }
116
-
117
- const { coordinates, controlPoints, transformOrigin } = this
118
- coordinates.push(this.ep)
119
- const path = coordinates.map((item) => `${item.x},${item.y}`).join(' ')
120
- const result: IVisualizationRectilinearLineShape = {
121
- controlPoints,
122
- transformOrigin,
123
- type: 'rectilinear',
124
- coordinates,
125
- rotate: 0,
126
- path,
127
- startPoint: sp,
128
- endPoint: ep,
129
- }
130
- return result
131
- }
132
-
133
- /**
134
- * Adds a control point to the list of points.
135
- */
136
- addCP(x = 0, y = 0): Point {
137
- const cp = new Point(x, y)
138
- this.coordinates.push(cp)
139
- this.controlPoints.push(cp)
140
- return cp
141
- }
142
-
143
- /**
144
- * Computes the line that starts on the west side of the source object
145
- * and end in the `end`
146
- * @param end The direction where the line ends.
147
- */
148
- [startWest](end: GeoDirection): void {
149
- if (end === 'west') {
150
- this[sketchWestWest]()
151
- } else if (end === 'south') {
152
- this[sketchWestSouth]()
153
- } else if (end === 'east') {
154
- this[sketchWestEast]()
155
- } else {
156
- this[sketchWestNorth]()
157
- }
158
- }
159
-
160
- [sketchWestSouth](): void {
161
- const { target, sp, ep, overlapPadding, dx, dy } = this
162
- if (dx >= 0) {
163
- if (dy < 0) {
164
- // go around the source to the right
165
- const cp1 = this.addCP(sp.x - overlapPadding, sp.y)
166
- const cp2 = this.addCP(cp1.x, target.bottom + overlapPadding)
167
- this.addCP(ep.x, cp2.y)
168
- } else {
169
- const cp1 = this.addCP(sp.x - overlapPadding, sp.y)
170
- const cp2 = this.addCP(cp1.x, target.bottom + overlapPadding)
171
- this.addCP(ep.x, cp2.y)
172
- }
173
- } else if (dy < 0) {
174
- this.addCP(ep.x, sp.y)
175
- } else {
176
- const cp1 = this.addCP(sp.x - overlapPadding, sp.y)
177
- const cp2 = this.addCP(cp1.x, target.bottom + overlapPadding)
178
- this.addCP(ep.x, cp2.y)
179
- }
180
- }
181
-
182
- [sketchWestWest](): void {
183
- const { source, target, sp, ep, overlapPadding, halfX, dy } = this
184
- const overlap = source.left < target.right
185
- if (overlap) {
186
- const cp1 = this.addCP(sp.x - overlapPadding, sp.y)
187
- const cp2 = this.addCP(cp1.x, source.top - overlapPadding)
188
- const cp3 = this.addCP(Math.max(target.right, source.right) + overlapPadding, cp2.y)
189
- this.addCP(cp3.x, ep.y)
190
- } else {
191
- // draw a straight line when distance between the two is below the threshold
192
- if (Math.abs(dy) > ElbowThreshold) {
193
- this.addCP(sp.x - halfX, sp.y)
194
- this.addCP(ep.x + halfX, ep.y)
195
- }
196
- }
197
- }
198
-
199
- [sketchWestEast](): void {
200
- const { source, target, sp, ep, overlapPadding } = this
201
- const overlap = source.left < target.left
202
- if (overlap) {
203
- const cp1 = this.addCP(sp.x - overlapPadding, sp.y)
204
- this.addCP(cp1.x, ep.y)
205
- } else {
206
- const cp1 = this.addCP(ep.x - overlapPadding, sp.y)
207
- this.addCP(cp1.x, ep.y)
208
- }
209
- }
210
-
211
- [sketchWestNorth](): void {
212
- const { source, target, sp, ep, overlapPadding } = this
213
- const overlap = source.left < target.right
214
- if (overlap) {
215
- const cp1 = this.addCP(sp.x - overlapPadding, sp.y)
216
- const cp2 = this.addCP(cp1.x, ep.y - overlapPadding)
217
- this.addCP(ep.x, cp2.y)
218
- } else {
219
- this.addCP(ep.x, sp.y)
220
- }
221
- }
222
-
223
- /**
224
- * Computes the line that starts on the west side of the source object
225
- * and end in the `end`
226
- * @param end The direction where the line ends.
227
- */
228
- [startSouth](end: GeoDirection): void {
229
- if (end === 'west') {
230
- this[sketchSouthWest]()
231
- } else if (end === 'south') {
232
- this[sketchSouthSouth]()
233
- } else if (end === 'east') {
234
- this[sketchSouthEast]()
235
- } else {
236
- this[sketchSouthNorth]()
237
- }
238
- }
239
-
240
- [sketchSouthNorth](): void {
241
- const { source, target, sp, ep, halfY, overlapPadding, dx } = this
242
- const overlapping = source.bottom + overlapPadding > target.top - overlapPadding
243
- if (overlapping) {
244
- const cp1 = this.addCP(sp.x, sp.y + overlapPadding)
245
- let cp2
246
- if (source.right < target.left) {
247
- // the target is on the right
248
- cp2 = this.addCP(target.left - overlapPadding, cp1.y)
249
- } else {
250
- // the target is on the left
251
- cp2 = this.addCP(target.right + overlapPadding, cp1.y)
252
- }
253
- const cp3 = this.addCP(cp2.x, target.top - overlapPadding)
254
- this.addCP(ep.x, cp3.y)
255
- } else {
256
- // draw a straight line instead of the elbow when the distance is below the threshold
257
- if (Math.abs(dx) > ElbowThreshold) {
258
- const cp1 = this.addCP(sp.x, sp.y + halfY)
259
- this.addCP(ep.x, cp1.y)
260
- }
261
- }
262
- }
263
-
264
- [sketchSouthWest](): void {
265
- const { sp, ep, dx, dy, halfY, halfX, overlapPadding } = this
266
- if (dx >= 0) {
267
- if (dy < 0) {
268
- const cp1 = this.addCP(sp.x, sp.y + overlapPadding)
269
- const cp2 = this.addCP(ep.x + overlapPadding, cp1.y)
270
- this.addCP(cp2.x, ep.y)
271
- } else {
272
- const cp1 = this.addCP(sp.x, sp.y + halfY)
273
- const cp2 = this.addCP(ep.x + overlapPadding, cp1.y)
274
- this.addCP(cp2.x, ep.y)
275
- }
276
- } else if (dy < 0) {
277
- const cp1 = this.addCP(sp.x, sp.y + overlapPadding)
278
- const cp2 = this.addCP(ep.x + halfX, cp1.y)
279
- this.addCP(cp2.x, ep.y)
280
- } else {
281
- this.addCP(sp.x, ep.y)
282
- }
283
- }
284
-
285
- [sketchSouthSouth](): void {
286
- const { source, target, sp, ep, overlapPadding } = this
287
- if (source.bottom + 2 * overlapPadding > target.bottom) {
288
- const cp1 = this.addCP(sp.x, sp.y + overlapPadding)
289
- this.addCP(ep.x, cp1.y)
290
- } else {
291
- const cp1 = this.addCP(sp.x, ep.y + overlapPadding)
292
- this.addCP(ep.x, cp1.y)
293
- }
294
- }
295
-
296
- [sketchSouthEast](): void {
297
- const { source, sp, ep, dx, dy, overlapPadding, halfX, halfY } = this
298
- if (dx >= 0) {
299
- if (dy < 0) {
300
- const cp1 = this.addCP(sp.x, sp.y + overlapPadding)
301
- let c2x = sp.x + halfX
302
- if (c2x < source.right + overlapPadding) {
303
- c2x = ep.x - overlapPadding
304
- }
305
- const cp2 = this.addCP(c2x, cp1.y)
306
- this.addCP(cp2.x, ep.y)
307
- } else {
308
- this.addCP(sp.x, ep.y)
309
- }
310
- } else if (dy < 0) {
311
- const cp1 = this.addCP(sp.x, sp.y + overlapPadding)
312
- const cp2 = this.addCP(ep.x - overlapPadding, cp1.y)
313
- this.addCP(cp2.x, ep.y)
314
- } else {
315
- const cp1 = this.addCP(sp.x, sp.y + halfY)
316
- const cp2 = this.addCP(ep.x - overlapPadding, cp1.y)
317
- this.addCP(cp2.x, ep.y)
318
- }
319
- }
320
-
321
- /**
322
- * Computes the line that starts on the west side of the source object
323
- * and end in the `end`
324
- * @param end The direction where the line ends.
325
- */
326
- [startEast](end: GeoDirection): void {
327
- if (end === 'west') {
328
- this[sketchEastWest]()
329
- } else if (end === 'east') {
330
- this[sketchEastEast]()
331
- } else if (end === 'south') {
332
- this[sketchEastSouth]()
333
- } else {
334
- this[sketchEastNorth]()
335
- }
336
- }
337
-
338
- [sketchEastEast](): void {
339
- const { source, target, sp, ep, overlapPadding, halfX, dy } = this
340
-
341
- if (sp.x + 2 * overlapPadding > target.x) {
342
- const cp1 = this.addCP(sp.x + overlapPadding, sp.y)
343
- const cp2 = this.addCP(cp1.x, source.top - overlapPadding)
344
- const cp3 = this.addCP(ep.x - overlapPadding, cp2.y)
345
- this.addCP(cp3.x, ep.y)
346
- } else {
347
- // draw a straight line when distance between the two is below the threshold
348
- if (Math.abs(dy) > ElbowThreshold) {
349
- const cp1 = this.addCP(sp.x + halfX, sp.y)
350
- this.addCP(cp1.x, ep.y)
351
- }
352
- }
353
- }
354
-
355
- [sketchEastWest](): void {
356
- const { source, target, sp, ep, overlapPadding, dx } = this
357
- if (dx >= 0) {
358
- // target on the right
359
- if (sp.y > target.top - overlapPadding && sp.y < target.bottom + overlapPadding) {
360
- // line is going through the target object
361
- const targetAbove = ep.y < sp.y
362
- const cp1 = this.addCP(target.left - overlapPadding, sp.y)
363
- const cp2 = this.addCP(cp1.x)
364
- if (targetAbove) {
365
- cp2.y = target.bottom + overlapPadding
366
- } else {
367
- cp2.y = target.top - overlapPadding
368
- }
369
- const cp3 = this.addCP(ep.x + overlapPadding, cp2.y)
370
- this.addCP(cp3.x, ep.y)
371
- } else {
372
- const cp1 = this.addCP(ep.x + overlapPadding, sp.y)
373
- this.addCP(cp1.x, ep.y)
374
- }
375
- } else {
376
- // target on the left
377
- const cp1 = this.addCP(sp.x + overlapPadding, sp.y)
378
- if (ep.y > source.top - overlapPadding && ep.y < source.bottom + overlapPadding) {
379
- // line is going through the source object
380
- const targetAbove = ep.y < sp.y
381
- const cp2 = this.addCP(cp1.x)
382
- if (targetAbove) {
383
- cp2.y = source.top - overlapPadding
384
- } else {
385
- cp2.y = source.bottom + overlapPadding
386
- }
387
- const cp3 = this.addCP(source.left - overlapPadding, cp2.y)
388
- this.addCP(cp3.x, ep.y)
389
- } else {
390
- this.addCP(cp1.x, ep.y)
391
- }
392
- }
393
- }
394
-
395
- [sketchEastSouth](): void {
396
- const { source, target, sp, ep, overlapPadding } = this
397
- const targetAround = ep.y > sp.y
398
- const sourceAround = sp.x > ep.x
399
-
400
- if (targetAround && sourceAround) {
401
- const cp1 = this.addCP(sp.x + overlapPadding, sp.y)
402
- const cp2 = this.addCP(cp1.x, Math.max(ep.y, source.bottom) + overlapPadding)
403
- this.addCP(ep.x, cp2.y)
404
- } else if (targetAround) {
405
- const overlapping = sp.x + overlapPadding > target.left
406
- if (overlapping) {
407
- const cp1 = this.addCP(sp.x + overlapPadding, sp.y)
408
- const cp2 = this.addCP(cp1.x, target.bottom + overlapPadding)
409
- const cp3 = this.addCP(target.left - overlapPadding, cp2.y)
410
- const cp4 = this.addCP(cp3.x, ep.y - overlapPadding)
411
- this.addCP(ep.x, cp4.y)
412
- } else {
413
- const cp1 = this.addCP(target.left - overlapPadding, sp.y)
414
- const cp2 = this.addCP(cp1.x, ep.y + overlapPadding)
415
- this.addCP(ep.x, cp2.y)
416
- }
417
- } else if (sourceAround) {
418
- const cp1 = this.addCP(sp.x + overlapPadding, sp.y)
419
- const cp2 = this.addCP(cp1.x, source.bottom + overlapPadding)
420
- const cp3 = this.addCP(target.right + overlapPadding, cp2.y)
421
- const cp4 = this.addCP(cp3.x, target.bottom + overlapPadding)
422
- this.addCP(ep.x, cp4.y)
423
- } else {
424
- this.addCP(ep.x, sp.y)
425
- }
426
- }
427
-
428
- [sketchEastNorth](): void {
429
- const { source, target, sp, ep, overlapPadding, dx, dy } = this
430
- if (dx >= 0) {
431
- if (dy < 0) {
432
- const cp1 = this.addCP(target.right + overlapPadding, sp.y)
433
- const cp2 = this.addCP(cp1.x, target.top - overlapPadding)
434
- this.addCP(ep.x, cp2.y)
435
- } else if (source.right > target.left - overlapPadding) {
436
- // go around the source
437
- const cp1 = this.addCP(sp.x + overlapPadding, sp.y)
438
- const cp2 = this.addCP(cp1.x, source.bottom + overlapPadding)
439
- const cp3 = this.addCP(target.left - overlapPadding, cp2.y)
440
- const cp4 = this.addCP(cp3.x, target.bottom + overlapPadding)
441
- this.addCP(ep.x, cp4.y)
442
- } else {
443
- this.addCP(ep.x, sp.y)
444
- }
445
- } else if (source.bottom + 2 * overlapPadding < target.top) {
446
- const cp1 = this.addCP(sp.x + overlapPadding, sp.y)
447
- const cp2 = this.addCP(cp1.x, source.bottom + overlapPadding)
448
- this.addCP(ep.x, cp2.y)
449
- } else {
450
- const cp1 = this.addCP(sp.x + overlapPadding, sp.y)
451
- const cp2 = this.addCP(cp1.x, Math.min(target.top, source.top) - overlapPadding)
452
- this.addCP(ep.x, cp2.y)
453
- }
454
- }
455
-
456
- /**
457
- * Computes the line that starts on the west side of the source object
458
- * and end in the `end`
459
- * @param end The direction where the line ends.
460
- */
461
- [startNorth](end: GeoDirection): void {
462
- if (end === 'west') {
463
- this[sketchNorthWest]()
464
- } else if (end === 'north') {
465
- this[sketchNorthNorth]()
466
- } else if (end === 'east') {
467
- this[sketchNorthEast]()
468
- } else {
469
- this[sketchNorthSouth]()
470
- }
471
- }
472
-
473
- [sketchNorthWest](): void {
474
- const { source, target, sp, ep, overlapPadding, dx, dy } = this
475
- if (dx >= 0) {
476
- if (dy < 0) {
477
- if (target.bottom + 2 * overlapPadding > sp.y) {
478
- // go above the target
479
- const cp1 = this.addCP(sp.x, target.top - overlapPadding)
480
- const cp2 = this.addCP(ep.x + overlapPadding, cp1.y)
481
- this.addCP(cp2.x, ep.y)
482
- } else {
483
- // go below the target
484
- const cp1 = this.addCP(sp.x, target.bottom + overlapPadding)
485
- const cp2 = this.addCP(ep.x + overlapPadding, cp1.y)
486
- this.addCP(cp2.x, ep.y)
487
- }
488
- } else {
489
- const cp1 = this.addCP(sp.x, Math.min(sp.y, target.top) - overlapPadding)
490
- const cp2 = this.addCP(Math.max(ep.x, source.right) + overlapPadding, cp1.y)
491
- this.addCP(cp2.x, ep.y)
492
- }
493
- } else if (dx < 0) {
494
- if (ep.y < sp.y - overlapPadding) {
495
- this.addCP(sp.x, ep.y)
496
- } else {
497
- const cp1 = this.addCP(sp.x, Math.min(sp.y, target.top) - overlapPadding)
498
- if (ep.x + 2 * overlapPadding > source.left) {
499
- const cp2 = this.addCP(source.left - overlapPadding, cp1.y)
500
- const cp3 = this.addCP(cp2.x, target.top - overlapPadding)
501
- const cp4 = this.addCP(target.right + overlapPadding, cp3.y)
502
- this.addCP(cp4.x, ep.y)
503
- } else {
504
- const cp2 = this.addCP(Math.min(ep.x, source.left) + overlapPadding, cp1.y)
505
- this.addCP(cp2.x, ep.y)
506
- }
507
- }
508
- }
509
- }
510
-
511
- [sketchNorthEast](): void {
512
- const { source, target, sp, ep, overlapPadding, dx, dy } = this
513
- const cp1 = this.addCP(sp.x, sp.y - overlapPadding)
514
- if (dx >= 0) {
515
- if (dy < 0) {
516
- this.addCP(sp.x, ep.y)
517
- } else if (source.right > target.left - overlapPadding) {
518
- const cp2 = this.addCP(source.right + overlapPadding, cp1.y)
519
- const cp3 = this.addCP(cp2.x, source.bottom + overlapPadding)
520
- const cp4 = this.addCP(ep.x - overlapPadding, cp3.y)
521
- this.addCP(cp4.x, ep.y)
522
- } else {
523
- const cp2 = this.addCP(ep.x - overlapPadding, cp1.y)
524
- this.addCP(cp2.x, ep.y)
525
- }
526
- } else {
527
- if (cp1.y > target.top - overlapPadding && cp1.y < target.bottom + overlapPadding) {
528
- const cp2 = this.addCP(target.right + overlapPadding, cp1.y)
529
- const posy = ep.y < sp.y ? target.bottom + overlapPadding : target.top - overlapPadding
530
- const cp3 = this.addCP(cp2.x, posy)
531
- this.addCP(ep.x - overlapPadding, cp3.y)
532
- } else {
533
- const overlapping = ep.x - overlapPadding > source.left
534
- if (overlapping) {
535
- const cp2 = this.addCP(source.left - overlapPadding, cp1.y)
536
- this.addCP(cp2.x, ep.y)
537
- } else {
538
- this.addCP(ep.x - overlapPadding, cp1.y)
539
- }
540
- }
541
- this.addCP(ep.x - overlapPadding, ep.y)
542
- }
543
- }
544
-
545
- [sketchNorthSouth](): void {
546
- const { source, target, sp, ep, overlapPadding, dy, dx, halfY } = this
547
- // (dy < 0) - the source is below target
548
- // (ep.y + 2*overlapPadding < sp.y) - there is a room to render the line between the boxes
549
- if (dy < 0 && ep.y + 2 * overlapPadding < sp.y) {
550
- // draw a straight line instead of the elbow when the distance is below the threshold
551
- if (Math.abs(dx) > ElbowThreshold) {
552
- const cp1 = this.addCP(sp.x, ep.y + halfY) // ep.y + overlapPadding
553
- this.addCP(ep.x, cp1.y)
554
- }
555
- } else {
556
- const cp1 = this.addCP(sp.x, sp.y - overlapPadding)
557
- let cp2
558
- if (sp.x < ep.x) {
559
- // to the left
560
- cp2 = this.addCP(Math.max(target.left - overlapPadding, source.right + overlapPadding), cp1.y)
561
- } else {
562
- // to the right
563
- cp2 = this.addCP(Math.min(target.right + overlapPadding, source.left - overlapPadding), cp1.y)
564
- }
565
- const cp3 = this.addCP(cp2.x, ep.y - overlapPadding)
566
- this.addCP(ep.x, cp3.y)
567
- }
568
- }
569
-
570
- [sketchNorthNorth](): void {
571
- const { source, target, sp, ep, overlapPadding, dy } = this
572
- if (dy < 0 && ep.y + 2 * overlapPadding < sp.y) {
573
- const cp1 = this.addCP(sp.x, ep.y - overlapPadding)
574
- this.addCP(ep.x, cp1.y)
575
- } else {
576
- const cp1 = this.addCP(sp.x, sp.y - overlapPadding)
577
- let cp2
578
- if (sp.x < ep.x) {
579
- // to the left
580
- cp2 = this.addCP(Math.max(target.left - overlapPadding, source.right + overlapPadding), cp1.y)
581
- } else {
582
- // to the right
583
- cp2 = this.addCP(Math.min(target.right + overlapPadding, source.left - overlapPadding), cp1.y)
584
- }
585
- const cp3 = this.addCP(cp2.x, ep.y - overlapPadding)
586
- this.addCP(ep.x, cp3.y)
587
- }
588
- }
589
- }