ngx-svg-graphics 2.1.0 → 3.0.0
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/fesm2022/ngx-svg-graphics.mjs +595 -0
- package/fesm2022/ngx-svg-graphics.mjs.map +1 -0
- package/index.d.ts +5 -0
- package/lib/components/arrows/arrow-between-boxes/arrow-between-boxes.component.d.ts +24 -0
- package/lib/components/arrows/arrow-between-elems/arrow-between-elems.component.d.ts +33 -0
- package/lib/components/arrows/arrow-between-points/arrow-between-points.component.d.ts +20 -0
- package/lib/components/draggable/draggable.component.d.ts +19 -0
- package/lib/components/rectangle/rectangle.component.d.ts +8 -0
- package/lib/components/rectangle-with-text/rectangle-with-text.component.d.ts +12 -0
- package/lib/components/text-area-svg/text-area-svg.component.d.ts +19 -0
- package/lib/models/arrow-style-configuration.d.ts +6 -0
- package/lib/models/bounding-box.d.ts +6 -0
- package/lib/models/dragger.d.ts +13 -0
- package/{src/lib/models/identifiable.ts → lib/models/identifiable.d.ts} +1 -1
- package/lib/models/positionable.d.ts +6 -0
- package/{src/lib/services/arrow-style-configuration.service.ts → lib/services/arrow-style-configuration.service.d.ts} +7 -16
- package/lib/services/svg-access.service.d.ts +13 -0
- package/lib/utils/path-layouter.d.ts +7 -0
- package/lib/utils/position-helper.d.ts +11 -0
- package/lib/utils/text-distributor.d.ts +7 -0
- package/package.json +21 -4
- package/{src/public-api.ts → public-api.d.ts} +6 -11
- package/ng-package.json +0 -7
- package/src/lib/components/arrows/arrow-between-boxes/arrow-between-boxes.component.css +0 -0
- package/src/lib/components/arrows/arrow-between-boxes/arrow-between-boxes.component.spec.ts +0 -32
- package/src/lib/components/arrows/arrow-between-boxes/arrow-between-boxes.component.svg +0 -12
- package/src/lib/components/arrows/arrow-between-boxes/arrow-between-boxes.component.ts +0 -60
- package/src/lib/components/arrows/arrow-between-elems/arrow-between-elems.component.css +0 -0
- package/src/lib/components/arrows/arrow-between-elems/arrow-between-elems.component.spec.ts +0 -23
- package/src/lib/components/arrows/arrow-between-elems/arrow-between-elems.component.svg +0 -9
- package/src/lib/components/arrows/arrow-between-elems/arrow-between-elems.component.ts +0 -96
- package/src/lib/components/arrows/arrow-between-points/arrow-between-points.component.css +0 -0
- package/src/lib/components/arrows/arrow-between-points/arrow-between-points.component.spec.ts +0 -23
- package/src/lib/components/arrows/arrow-between-points/arrow-between-points.component.svg +0 -15
- package/src/lib/components/arrows/arrow-between-points/arrow-between-points.component.ts +0 -39
- package/src/lib/components/draggable/draggable.component.css +0 -0
- package/src/lib/components/draggable/draggable.component.spec.ts +0 -33
- package/src/lib/components/draggable/draggable.component.svg +0 -8
- package/src/lib/components/draggable/draggable.component.ts +0 -49
- package/src/lib/components/rectangle/rectangle.component.css +0 -0
- package/src/lib/components/rectangle/rectangle.component.spec.ts +0 -23
- package/src/lib/components/rectangle/rectangle.component.svg +0 -3
- package/src/lib/components/rectangle/rectangle.component.ts +0 -14
- package/src/lib/components/text-area-svg/text-area-svg.component.css +0 -0
- package/src/lib/components/text-area-svg/text-area-svg.component.spec.ts +0 -59
- package/src/lib/components/text-area-svg/text-area-svg.component.svg +0 -6
- package/src/lib/components/text-area-svg/text-area-svg.component.ts +0 -57
- package/src/lib/models/arrow-style-configuration.ts +0 -8
- package/src/lib/models/bounding-box.ts +0 -7
- package/src/lib/models/dragger.spec.ts +0 -9
- package/src/lib/models/dragger.ts +0 -54
- package/src/lib/models/positionable.ts +0 -8
- package/src/lib/services/arrow-style-configuration.service.spec.ts +0 -16
- package/src/lib/services/svg-access.service.spec.ts +0 -16
- package/src/lib/services/svg-access.service.ts +0 -35
- package/src/lib/utils/path-layouter.spec.ts +0 -7
- package/src/lib/utils/path-layouter.ts +0 -41
- package/src/lib/utils/position-helper.spec.ts +0 -140
- package/src/lib/utils/position-helper.ts +0 -45
- package/src/lib/utils/text-distributor.spec.ts +0 -96
- package/src/lib/utils/text-distributor.ts +0 -68
- package/tsconfig.lib.json +0 -15
- package/tsconfig.lib.prod.json +0 -11
- package/tsconfig.spec.json +0 -15
|
@@ -0,0 +1,595 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { Injectable, EventEmitter, Output, Component, Input, ViewChild } from '@angular/core';
|
|
3
|
+
import { BehaviorSubject } from 'rxjs';
|
|
4
|
+
import { NgIf, NgFor } from '@angular/common';
|
|
5
|
+
import { v4 } from 'uuid';
|
|
6
|
+
import * as i1 from '@angular/forms';
|
|
7
|
+
import { FormsModule } from '@angular/forms';
|
|
8
|
+
|
|
9
|
+
class Dragger {
|
|
10
|
+
elem;
|
|
11
|
+
dragActive = false;
|
|
12
|
+
wasReallyDragged = false;
|
|
13
|
+
dragStartX = 0;
|
|
14
|
+
dragStartY = 0;
|
|
15
|
+
constructor(element) {
|
|
16
|
+
this.elem = element;
|
|
17
|
+
}
|
|
18
|
+
startDrag(event) {
|
|
19
|
+
this.dragStartX = event.clientX;
|
|
20
|
+
this.dragStartY = event.clientY;
|
|
21
|
+
this.dragActive = true;
|
|
22
|
+
}
|
|
23
|
+
// returns true in the case of a real drag event, false otherwise
|
|
24
|
+
drag(event) {
|
|
25
|
+
if (this.dragActive) {
|
|
26
|
+
this.wasReallyDragged = true;
|
|
27
|
+
event.preventDefault();
|
|
28
|
+
const dragX = event.clientX;
|
|
29
|
+
this.elem.position.x += (dragX - this.dragStartX);
|
|
30
|
+
this.dragStartX = dragX;
|
|
31
|
+
const dragY = event.clientY;
|
|
32
|
+
this.elem.position.y += (dragY - this.dragStartY);
|
|
33
|
+
this.dragStartY = dragY;
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
endDrag(event) {
|
|
39
|
+
this.dragActive = false;
|
|
40
|
+
// todo was working for click vs drag, not now setTimeout(() => {this.dragActive = false;}, 50);
|
|
41
|
+
event.preventDefault();
|
|
42
|
+
}
|
|
43
|
+
//returns true if the click should be treated as click, false if it was from drag
|
|
44
|
+
clickElem(event) {
|
|
45
|
+
if (this.wasReallyDragged) {
|
|
46
|
+
this.wasReallyDragged = false;
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
event.preventDefault();
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
class PositionHelper {
|
|
57
|
+
static getSvgBBPosition(elem, node) {
|
|
58
|
+
let abs = PositionHelper.absolutePosition(elem);
|
|
59
|
+
PositionHelper.makeRelativeToElem(abs, node);
|
|
60
|
+
return abs;
|
|
61
|
+
}
|
|
62
|
+
static absolutePosition(elem) {
|
|
63
|
+
let relativePosition = elem.getBBox();
|
|
64
|
+
const svg = elem.ownerSVGElement;
|
|
65
|
+
const toSvg = svg.getScreenCTM().inverse();
|
|
66
|
+
const toScreen = elem.getCTM();
|
|
67
|
+
let translationMatrix = toSvg.multiply(toScreen);
|
|
68
|
+
let x = relativePosition.x;
|
|
69
|
+
let y = relativePosition.y;
|
|
70
|
+
let x_abs = translationMatrix.a * x + translationMatrix.c * y + translationMatrix.e;
|
|
71
|
+
let y_abs = translationMatrix.b * x + translationMatrix.d * y + translationMatrix.f;
|
|
72
|
+
return { x: x_abs, y: y_abs, w: relativePosition.width * translationMatrix.a, h: relativePosition.height * translationMatrix.d };
|
|
73
|
+
}
|
|
74
|
+
static makeRelativeToElem(p, elem) {
|
|
75
|
+
const svg = elem.ownerSVGElement;
|
|
76
|
+
const fromSvg = svg.getScreenCTM();
|
|
77
|
+
const fromScreen = elem.getCTM().inverse();
|
|
78
|
+
const transformer = fromScreen.multiply(fromSvg);
|
|
79
|
+
this.matrixTransform(p, transformer);
|
|
80
|
+
}
|
|
81
|
+
static matrixTransform(p, translationMatrix) {
|
|
82
|
+
let x = p.x;
|
|
83
|
+
let y = p.y;
|
|
84
|
+
let x_trans = translationMatrix.a * x + translationMatrix.c * y + translationMatrix.e;
|
|
85
|
+
let y_trans = translationMatrix.b * x + translationMatrix.d * y + translationMatrix.f;
|
|
86
|
+
p.x = x_trans;
|
|
87
|
+
p.y = y_trans;
|
|
88
|
+
}
|
|
89
|
+
static newBoundingBox(x = 0, y = 0, width = 5, height = 5) {
|
|
90
|
+
return { x: x, y: y, w: width, h: height };
|
|
91
|
+
}
|
|
92
|
+
static computeOffset(index, length) {
|
|
93
|
+
const middle = (length - 1) / 2;
|
|
94
|
+
return index - middle;
|
|
95
|
+
}
|
|
96
|
+
static computeChildBBox(index, length, parentBox) {
|
|
97
|
+
return {
|
|
98
|
+
x: parentBox.x + this.computeOffset(index, length) * (parentBox.w + 5),
|
|
99
|
+
y: parentBox.y + parentBox.h * 2,
|
|
100
|
+
w: parentBox.w,
|
|
101
|
+
h: parentBox.h
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
class SVGAccessService {
|
|
107
|
+
positionChange = new BehaviorSubject('');
|
|
108
|
+
constructor() { }
|
|
109
|
+
notifyPositionChange(id) {
|
|
110
|
+
this.positionChange.next(id);
|
|
111
|
+
}
|
|
112
|
+
listenToPositionChange() {
|
|
113
|
+
return this.positionChange.asObservable();
|
|
114
|
+
}
|
|
115
|
+
getElemById(id) {
|
|
116
|
+
let elem = document.getElementById(id);
|
|
117
|
+
return elem;
|
|
118
|
+
}
|
|
119
|
+
getRelativePosition(id, node) {
|
|
120
|
+
let elem = this.getElemById(id);
|
|
121
|
+
if (elem) {
|
|
122
|
+
return PositionHelper.getSvgBBPosition(elem, node);
|
|
123
|
+
}
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: SVGAccessService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
127
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: SVGAccessService, providedIn: 'root' });
|
|
128
|
+
}
|
|
129
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: SVGAccessService, decorators: [{
|
|
130
|
+
type: Injectable,
|
|
131
|
+
args: [{
|
|
132
|
+
providedIn: 'root'
|
|
133
|
+
}]
|
|
134
|
+
}], ctorParameters: () => [] });
|
|
135
|
+
|
|
136
|
+
class DraggableComponent {
|
|
137
|
+
svgAccessService;
|
|
138
|
+
chooseElem = new EventEmitter();
|
|
139
|
+
//the caller must initialize both required elements (elem and elementDragger) either in the constructor
|
|
140
|
+
// (or if they are inputs) in the ngOnInit life cycle hook
|
|
141
|
+
elem;
|
|
142
|
+
elemDragger;
|
|
143
|
+
constructor(svgAccessService) {
|
|
144
|
+
this.svgAccessService = svgAccessService;
|
|
145
|
+
}
|
|
146
|
+
ngAfterViewInit() {
|
|
147
|
+
this.svgAccessService.notifyPositionChange(this.elem.$gId);
|
|
148
|
+
}
|
|
149
|
+
startDrag(event) {
|
|
150
|
+
this.elemDragger.startDrag(event);
|
|
151
|
+
}
|
|
152
|
+
drag(event) {
|
|
153
|
+
if (this.elemDragger.drag(event)) {
|
|
154
|
+
this.svgAccessService.notifyPositionChange(this.elem.$gId);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
endDrag(event) {
|
|
158
|
+
this.elemDragger.endDrag(event);
|
|
159
|
+
}
|
|
160
|
+
clickElem(event) {
|
|
161
|
+
if (this.elemDragger.clickElem(event)) {
|
|
162
|
+
this.chooseElem.emit(this.elem);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: DraggableComponent, deps: [{ token: SVGAccessService }], target: i0.ɵɵFactoryTarget.Component });
|
|
166
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.4", type: DraggableComponent, isStandalone: true, selector: "[draggable]", outputs: { chooseElem: "chooseElem" }, ngImport: i0, template: "<svg:g>\n <g [attr.id]=\"elem.$gId\"\n (mousedown)=\"startDrag($event)\"\n (mousemove)=\"drag($event)\"\n (mouseup)=\"endDrag($event)\"\n (click)=\"clickElem($event)\">\n </g>\n</svg:g>\n", styles: [""] });
|
|
167
|
+
}
|
|
168
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: DraggableComponent, decorators: [{
|
|
169
|
+
type: Component,
|
|
170
|
+
args: [{ imports: [], selector: '[draggable]', template: "<svg:g>\n <g [attr.id]=\"elem.$gId\"\n (mousedown)=\"startDrag($event)\"\n (mousemove)=\"drag($event)\"\n (mouseup)=\"endDrag($event)\"\n (click)=\"clickElem($event)\">\n </g>\n</svg:g>\n" }]
|
|
171
|
+
}], ctorParameters: () => [{ type: SVGAccessService }], propDecorators: { chooseElem: [{
|
|
172
|
+
type: Output
|
|
173
|
+
}] } });
|
|
174
|
+
|
|
175
|
+
class PathLayouter {
|
|
176
|
+
static bestPoints(p1, p2) {
|
|
177
|
+
//assumption is that both boxes do not intersect
|
|
178
|
+
//since we only deal with bounding boxes, all relevant lines are parallel/orthogonal
|
|
179
|
+
let xPoints = this.getPointsInOneDimension(p1.x, p1.w, p2.x, p2.w);
|
|
180
|
+
let yPoints = this.getPointsInOneDimension(p1.y, p1.h, p2.y, p2.h);
|
|
181
|
+
let result1 = { x: xPoints[0], y: yPoints[0] };
|
|
182
|
+
let result2 = { x: xPoints[1], y: yPoints[1] };
|
|
183
|
+
return [result1, result2];
|
|
184
|
+
}
|
|
185
|
+
// assumes that x1 is smaller than x2
|
|
186
|
+
//works for width (careful with height, y axis is wrong way)
|
|
187
|
+
static determineOverlapX(x1, w1, x2, w2) {
|
|
188
|
+
let x1right = x1 + w1;
|
|
189
|
+
if (x1right >= x2) {
|
|
190
|
+
//find end of overlap
|
|
191
|
+
let x2right = x2 + w2;
|
|
192
|
+
let end = Math.min(x1right, x2right);
|
|
193
|
+
//overlap interval is [x2, end]
|
|
194
|
+
let middle = (x2 + end) / 2;
|
|
195
|
+
return [middle, middle];
|
|
196
|
+
}
|
|
197
|
+
else
|
|
198
|
+
return [x1right, x2];
|
|
199
|
+
}
|
|
200
|
+
static getPointsInOneDimension(x1, w1, x2, w2) {
|
|
201
|
+
//determine overlap (and then middle of it) or closest points in one dimension
|
|
202
|
+
if (x1 < x2) {
|
|
203
|
+
return this.determineOverlapX(x1, w1, x2, w2);
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
return this.determineOverlapX(x2, w2, x1, w1).reverse();
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/*****
|
|
212
|
+
default implementation
|
|
213
|
+
You can extend this base case with an own service implementation.
|
|
214
|
+
Make sure to configure DI to use your service instead of this one
|
|
215
|
+
In 20205, the way to do so is to declare it as provider in app.config.ts or app.component.ts
|
|
216
|
+
providers: [{ provide: ArrowStyleConfigurationService, useClass: YourServiceImplementation }],
|
|
217
|
+
See https://angular.dev/guide/di/dependency-injection-providers
|
|
218
|
+
***/
|
|
219
|
+
class ArrowStyleConfigurationService {
|
|
220
|
+
constructor() { }
|
|
221
|
+
styleArrow(arrowType) {
|
|
222
|
+
return {
|
|
223
|
+
color: 'black',
|
|
224
|
+
dashed: [0]
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: ArrowStyleConfigurationService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
228
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: ArrowStyleConfigurationService, providedIn: 'root' });
|
|
229
|
+
}
|
|
230
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: ArrowStyleConfigurationService, decorators: [{
|
|
231
|
+
type: Injectable,
|
|
232
|
+
args: [{
|
|
233
|
+
providedIn: 'root'
|
|
234
|
+
}]
|
|
235
|
+
}], ctorParameters: () => [] });
|
|
236
|
+
|
|
237
|
+
class ArrowBetweenPointsComponent {
|
|
238
|
+
arrowStyleConfigService;
|
|
239
|
+
startX;
|
|
240
|
+
startY;
|
|
241
|
+
endX;
|
|
242
|
+
endY;
|
|
243
|
+
text;
|
|
244
|
+
style;
|
|
245
|
+
arrowType;
|
|
246
|
+
arrowStyleConfiguration;
|
|
247
|
+
id = v4();
|
|
248
|
+
constructor(arrowStyleConfigService) {
|
|
249
|
+
this.arrowStyleConfigService = arrowStyleConfigService;
|
|
250
|
+
this.arrowStyleConfiguration = this.arrowStyleConfigService.styleArrow();
|
|
251
|
+
}
|
|
252
|
+
ngOnChanges() {
|
|
253
|
+
this.arrowStyleConfiguration = this.arrowStyleConfigService.styleArrow(this.arrowType);
|
|
254
|
+
}
|
|
255
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: ArrowBetweenPointsComponent, deps: [{ token: ArrowStyleConfigurationService }], target: i0.ɵɵFactoryTarget.Component });
|
|
256
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.4", type: ArrowBetweenPointsComponent, isStandalone: true, selector: "[arrow-between-points]", inputs: { startX: "startX", startY: "startY", endX: "endX", endY: "endY", text: "text", style: "style", arrowType: "arrowType" }, usesOnChanges: true, ngImport: i0, template: "<svg:g>\n <path [attr.id]=\"id+'-path'\"\n [attr.d]=\"'M '+startX+','+startY+' L '+endX+','+endY\"\n [attr.stroke]=\"arrowStyleConfiguration.color\"\n [attr.stroke-dasharray]=\"arrowStyleConfiguration.dashed\"\n [attr.marker-start]='\"url(#\"+arrowStyleConfiguration.startPointer+\")\"'\n [attr.marker-end]='\"url(#\"+arrowStyleConfiguration.endPointer+\")\"'\n style=\"{{style}}\">\n </path>\n <text *ngIf=\"text\">\n <textPath [attr.href]=\"'#'+id+'-path'\">\n {{text}}\n </textPath>\n </text>\n</svg:g>", styles: [""], dependencies: [{ kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }] });
|
|
257
|
+
}
|
|
258
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: ArrowBetweenPointsComponent, decorators: [{
|
|
259
|
+
type: Component,
|
|
260
|
+
args: [{ selector: '[arrow-between-points]', imports: [
|
|
261
|
+
NgIf
|
|
262
|
+
], template: "<svg:g>\n <path [attr.id]=\"id+'-path'\"\n [attr.d]=\"'M '+startX+','+startY+' L '+endX+','+endY\"\n [attr.stroke]=\"arrowStyleConfiguration.color\"\n [attr.stroke-dasharray]=\"arrowStyleConfiguration.dashed\"\n [attr.marker-start]='\"url(#\"+arrowStyleConfiguration.startPointer+\")\"'\n [attr.marker-end]='\"url(#\"+arrowStyleConfiguration.endPointer+\")\"'\n style=\"{{style}}\">\n </path>\n <text *ngIf=\"text\">\n <textPath [attr.href]=\"'#'+id+'-path'\">\n {{text}}\n </textPath>\n </text>\n</svg:g>" }]
|
|
263
|
+
}], ctorParameters: () => [{ type: ArrowStyleConfigurationService }], propDecorators: { startX: [{
|
|
264
|
+
type: Input
|
|
265
|
+
}], startY: [{
|
|
266
|
+
type: Input
|
|
267
|
+
}], endX: [{
|
|
268
|
+
type: Input
|
|
269
|
+
}], endY: [{
|
|
270
|
+
type: Input
|
|
271
|
+
}], text: [{
|
|
272
|
+
type: Input
|
|
273
|
+
}], style: [{
|
|
274
|
+
type: Input
|
|
275
|
+
}], arrowType: [{
|
|
276
|
+
type: Input
|
|
277
|
+
}] } });
|
|
278
|
+
|
|
279
|
+
class ArrowBetweenBoxesComponent {
|
|
280
|
+
cdr;
|
|
281
|
+
start;
|
|
282
|
+
end;
|
|
283
|
+
arrowType;
|
|
284
|
+
text;
|
|
285
|
+
style;
|
|
286
|
+
x1 = 0;
|
|
287
|
+
y1 = 0;
|
|
288
|
+
x2 = 5;
|
|
289
|
+
y2 = 5;
|
|
290
|
+
id = v4();
|
|
291
|
+
positioned = false;
|
|
292
|
+
constructor(cdr) {
|
|
293
|
+
this.cdr = cdr;
|
|
294
|
+
}
|
|
295
|
+
ngAfterViewInit() {
|
|
296
|
+
this.computePositions();
|
|
297
|
+
this.positioned = true;
|
|
298
|
+
this.cdr.detectChanges();
|
|
299
|
+
}
|
|
300
|
+
ngOnChanges() {
|
|
301
|
+
if (this.positioned) {
|
|
302
|
+
this.computePositions();
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
computePositions() {
|
|
306
|
+
let res = PathLayouter.bestPoints(this.start, this.end);
|
|
307
|
+
this.applyBestPoints(res);
|
|
308
|
+
}
|
|
309
|
+
applyBestPoints(res) {
|
|
310
|
+
this.x1 = res[0].x;
|
|
311
|
+
this.y1 = res[0].y;
|
|
312
|
+
this.x2 = res[1].x;
|
|
313
|
+
this.y2 = res[1].y;
|
|
314
|
+
}
|
|
315
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: ArrowBetweenBoxesComponent, deps: [{ token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
|
|
316
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.4", type: ArrowBetweenBoxesComponent, isStandalone: true, selector: "[arrow-between-boxes]", inputs: { start: "start", end: "end", arrowType: "arrowType", text: "text", style: "style" }, usesOnChanges: true, ngImport: i0, template: "<svg:g>\n <g arrow-between-points\n [startX]=\"x1\"\n [startY]=\"y1\"\n [endX]=\"x2\"\n [endY]=\"y2\"\n [text]=\"text\"\n [arrowType]=\"arrowType\"\n [style]=\"style\"\n >\n </g>\n</svg:g>\n", styles: [""], dependencies: [{ kind: "component", type: ArrowBetweenPointsComponent, selector: "[arrow-between-points]", inputs: ["startX", "startY", "endX", "endY", "text", "style", "arrowType"] }] });
|
|
317
|
+
}
|
|
318
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: ArrowBetweenBoxesComponent, decorators: [{
|
|
319
|
+
type: Component,
|
|
320
|
+
args: [{ selector: '[arrow-between-boxes]', imports: [ArrowBetweenPointsComponent], template: "<svg:g>\n <g arrow-between-points\n [startX]=\"x1\"\n [startY]=\"y1\"\n [endX]=\"x2\"\n [endY]=\"y2\"\n [text]=\"text\"\n [arrowType]=\"arrowType\"\n [style]=\"style\"\n >\n </g>\n</svg:g>\n" }]
|
|
321
|
+
}], ctorParameters: () => [{ type: i0.ChangeDetectorRef }], propDecorators: { start: [{
|
|
322
|
+
type: Input
|
|
323
|
+
}], end: [{
|
|
324
|
+
type: Input
|
|
325
|
+
}], arrowType: [{
|
|
326
|
+
type: Input
|
|
327
|
+
}], text: [{
|
|
328
|
+
type: Input
|
|
329
|
+
}], style: [{
|
|
330
|
+
type: Input
|
|
331
|
+
}] } });
|
|
332
|
+
|
|
333
|
+
class ArrowBetweenElemsComponent {
|
|
334
|
+
svgAccessService;
|
|
335
|
+
cdr;
|
|
336
|
+
startGID;
|
|
337
|
+
startSuffix;
|
|
338
|
+
endGID;
|
|
339
|
+
endSuffix;
|
|
340
|
+
arrowType;
|
|
341
|
+
breaks = [];
|
|
342
|
+
text;
|
|
343
|
+
style; //todo move into ArrowStyleConfig?
|
|
344
|
+
startId;
|
|
345
|
+
endId;
|
|
346
|
+
start;
|
|
347
|
+
end;
|
|
348
|
+
positioned = false;
|
|
349
|
+
node;
|
|
350
|
+
changeNotifier;
|
|
351
|
+
changeSubscription;
|
|
352
|
+
//idea: compute the two input positions as relative to the current elem
|
|
353
|
+
constructor(svgAccessService, cdr) {
|
|
354
|
+
this.svgAccessService = svgAccessService;
|
|
355
|
+
this.cdr = cdr;
|
|
356
|
+
this.changeNotifier = this.svgAccessService.listenToPositionChange();
|
|
357
|
+
this.changeSubscription = this.changeNotifier.subscribe(nextString => {
|
|
358
|
+
if (nextString == this.startGID || nextString == this.endGID) {
|
|
359
|
+
setTimeout(() => {
|
|
360
|
+
this.computePositionsByIds();
|
|
361
|
+
this.cdr.detectChanges();
|
|
362
|
+
}, 0);
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
ngOnInit() {
|
|
367
|
+
this.startId = this.startGID + this.startSuffix;
|
|
368
|
+
this.endId = this.endGID + this.endSuffix;
|
|
369
|
+
}
|
|
370
|
+
ngOnChanges(_) {
|
|
371
|
+
this.startId = this.startGID + this.startSuffix;
|
|
372
|
+
this.endId = this.endGID + this.endSuffix;
|
|
373
|
+
this.computePositionsByIds();
|
|
374
|
+
this.cdr.detectChanges();
|
|
375
|
+
}
|
|
376
|
+
ngAfterViewInit() {
|
|
377
|
+
this.positioned = true;
|
|
378
|
+
this.computePositionsByIds();
|
|
379
|
+
this.cdr.detectChanges();
|
|
380
|
+
}
|
|
381
|
+
computePositionsByIds() {
|
|
382
|
+
if (this.node?.nativeElement) {
|
|
383
|
+
let rel = this.node.nativeElement;
|
|
384
|
+
let startOpt = this.svgAccessService.getRelativePosition(this.startId, rel);
|
|
385
|
+
if (startOpt) {
|
|
386
|
+
this.start = startOpt;
|
|
387
|
+
}
|
|
388
|
+
let endOpt = this.svgAccessService.getRelativePosition(this.endId, rel);
|
|
389
|
+
if (endOpt) {
|
|
390
|
+
this.end = endOpt;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
else
|
|
394
|
+
console.log('No native element yet');
|
|
395
|
+
}
|
|
396
|
+
ngOnDestroy() {
|
|
397
|
+
this.changeSubscription.unsubscribe();
|
|
398
|
+
}
|
|
399
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: ArrowBetweenElemsComponent, deps: [{ token: SVGAccessService }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
|
|
400
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.4", type: ArrowBetweenElemsComponent, isStandalone: true, selector: "[arrowElems]", inputs: { startGID: "startGID", startSuffix: "startSuffix", endGID: "endGID", endSuffix: "endSuffix", arrowType: "arrowType", breaks: "breaks", text: "text", style: "style" }, viewQueries: [{ propertyName: "node", first: true, predicate: ["arrow"], descendants: true }], usesOnChanges: true, ngImport: i0, template: "<svg:g #arrow>\n <g arrow-between-boxes *ngIf=\"start && end\"\n [start]=\"start\"\n [end]=\"end\"\n [arrowType]=\"arrowType\"\n [text]=\"text\"\n [style]=\"style\">\n </g>\n></svg:g>\n", styles: [""], dependencies: [{ kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: ArrowBetweenBoxesComponent, selector: "[arrow-between-boxes]", inputs: ["start", "end", "arrowType", "text", "style"] }] });
|
|
401
|
+
}
|
|
402
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: ArrowBetweenElemsComponent, decorators: [{
|
|
403
|
+
type: Component,
|
|
404
|
+
args: [{ selector: '[arrowElems]', imports: [NgIf, ArrowBetweenBoxesComponent], template: "<svg:g #arrow>\n <g arrow-between-boxes *ngIf=\"start && end\"\n [start]=\"start\"\n [end]=\"end\"\n [arrowType]=\"arrowType\"\n [text]=\"text\"\n [style]=\"style\">\n </g>\n></svg:g>\n" }]
|
|
405
|
+
}], ctorParameters: () => [{ type: SVGAccessService }, { type: i0.ChangeDetectorRef }], propDecorators: { startGID: [{
|
|
406
|
+
type: Input
|
|
407
|
+
}], startSuffix: [{
|
|
408
|
+
type: Input
|
|
409
|
+
}], endGID: [{
|
|
410
|
+
type: Input
|
|
411
|
+
}], endSuffix: [{
|
|
412
|
+
type: Input
|
|
413
|
+
}], arrowType: [{
|
|
414
|
+
type: Input
|
|
415
|
+
}], breaks: [{
|
|
416
|
+
type: Input
|
|
417
|
+
}], text: [{
|
|
418
|
+
type: Input
|
|
419
|
+
}], style: [{
|
|
420
|
+
type: Input
|
|
421
|
+
}], node: [{
|
|
422
|
+
type: ViewChild,
|
|
423
|
+
args: ['arrow']
|
|
424
|
+
}] } });
|
|
425
|
+
|
|
426
|
+
class TextDistributor {
|
|
427
|
+
static determineHowManyChars(w) {
|
|
428
|
+
return Math.floor(w / 7.6);
|
|
429
|
+
}
|
|
430
|
+
static determineLines(h) {
|
|
431
|
+
return Math.floor(h / 20);
|
|
432
|
+
}
|
|
433
|
+
// idea: distribute words over lines,
|
|
434
|
+
// if a single word is too long for a line, cut it early enough to have three dots afterwards
|
|
435
|
+
// if you need to indicate that there is more text after the last complete word, also use three dots, but after a break
|
|
436
|
+
static distributeText(text, w, h) {
|
|
437
|
+
let distributedText = [];
|
|
438
|
+
let broken = text?.split(' ');
|
|
439
|
+
let maxLines = this.determineLines(h);
|
|
440
|
+
if (maxLines <= 0) {
|
|
441
|
+
console.error('Text area too low for text ' + text);
|
|
442
|
+
distributedText = ['...'];
|
|
443
|
+
}
|
|
444
|
+
for (let i = 0; i < maxLines; i++) {
|
|
445
|
+
if (broken.length > 0) {
|
|
446
|
+
distributedText[i] = this.takeNextLine(broken, w);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
// now deal with last line: here we need special care for adding ... if necessary
|
|
450
|
+
if (broken.length > 0) {
|
|
451
|
+
// we need to indicate that there is more text - this could be the 4 signs to many...
|
|
452
|
+
distributedText[maxLines - 1] += ' ...';
|
|
453
|
+
}
|
|
454
|
+
return distributedText.filter(w => w != '');
|
|
455
|
+
}
|
|
456
|
+
// if a single word is too long for a line, cut it early enough to have three dots afterwards
|
|
457
|
+
static limitSingleWord(word, w) {
|
|
458
|
+
let maxSize = this.determineHowManyChars(w);
|
|
459
|
+
if (word.length > maxSize) {
|
|
460
|
+
let ending = '...';
|
|
461
|
+
// care for far too short width:
|
|
462
|
+
if (maxSize <= 3) {
|
|
463
|
+
return ending.substring(0, maxSize);
|
|
464
|
+
}
|
|
465
|
+
else {
|
|
466
|
+
return word.substring(0, maxSize - 3) + '...';
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
else {
|
|
470
|
+
return word;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
// adapts input words array in place by removing all those that are taken into the result
|
|
474
|
+
static takeNextLine(words, w) {
|
|
475
|
+
if (words?.length > 0) {
|
|
476
|
+
let res = this.limitSingleWord(words[0], w);
|
|
477
|
+
let i = 1;
|
|
478
|
+
let maxSize = this.determineHowManyChars(w);
|
|
479
|
+
let testRes = res + ' ' + words[i];
|
|
480
|
+
while (testRes.length <= maxSize && i < words.length - 1) {
|
|
481
|
+
res = testRes;
|
|
482
|
+
i++;
|
|
483
|
+
testRes = res + ' ' + words[i];
|
|
484
|
+
}
|
|
485
|
+
words.splice(0, i);
|
|
486
|
+
return res;
|
|
487
|
+
}
|
|
488
|
+
else
|
|
489
|
+
return '';
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
class TextAreaSvgComponent {
|
|
494
|
+
/*
|
|
495
|
+
a fixed size svg. If the text exceeds the possible size, we will do a ... for now
|
|
496
|
+
*/
|
|
497
|
+
text;
|
|
498
|
+
x;
|
|
499
|
+
y;
|
|
500
|
+
w;
|
|
501
|
+
h;
|
|
502
|
+
singleEdit = false;
|
|
503
|
+
textChange = new EventEmitter();
|
|
504
|
+
//only with singleEdit since that opens an overlay where one can change the text in place
|
|
505
|
+
distributedText = [];
|
|
506
|
+
isActive = false;
|
|
507
|
+
ngOnChanges() {
|
|
508
|
+
this.distributeText();
|
|
509
|
+
}
|
|
510
|
+
handleClick() {
|
|
511
|
+
if (this.singleEdit) {
|
|
512
|
+
this.isActive = true;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
leaveTextInput() {
|
|
516
|
+
this.textChange.emit(this.text);
|
|
517
|
+
this.isActive = false;
|
|
518
|
+
}
|
|
519
|
+
distributeText() {
|
|
520
|
+
this.distributedText = TextDistributor.distributeText(this.text, this.w, this.h);
|
|
521
|
+
}
|
|
522
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: TextAreaSvgComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
523
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.4", type: TextAreaSvgComponent, isStandalone: true, selector: "[text-area-svg]", inputs: { text: "text", x: "x", y: "y", w: "w", h: "h", singleEdit: "singleEdit" }, outputs: { textChange: "textChange" }, usesOnChanges: true, ngImport: i0, template: "<svg:text [attr.x]=\"x\" [attr.y]=\"y\" [attr.width]=\"w\" [attr.height]=\"h\" dy=\"0\" [attr.style]=\"\" (click)=\"handleClick()\">\n <tspan dy=\"1.2em\" [attr.x]=\"x\" *ngFor=\"let line of distributedText\">{{line}}</tspan>\n</svg:text>\n<svg:foreignObject *ngIf=\"isActive\" [attr.x]=\"x\" [attr.y]=\"y\" [attr.width]=\"w\" [attr.height]=\"h\">\n <input id=\"text-area\" type=\"text\" [(ngModel)]=\"this.text\" (focusout)=\"leaveTextInput()\"/>\n</svg:foreignObject>\n", styles: [""], dependencies: [{ kind: "directive", type: NgFor, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i1.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }] });
|
|
524
|
+
}
|
|
525
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: TextAreaSvgComponent, decorators: [{
|
|
526
|
+
type: Component,
|
|
527
|
+
args: [{ selector: '[text-area-svg]', imports: [NgFor, NgIf, FormsModule], template: "<svg:text [attr.x]=\"x\" [attr.y]=\"y\" [attr.width]=\"w\" [attr.height]=\"h\" dy=\"0\" [attr.style]=\"\" (click)=\"handleClick()\">\n <tspan dy=\"1.2em\" [attr.x]=\"x\" *ngFor=\"let line of distributedText\">{{line}}</tspan>\n</svg:text>\n<svg:foreignObject *ngIf=\"isActive\" [attr.x]=\"x\" [attr.y]=\"y\" [attr.width]=\"w\" [attr.height]=\"h\">\n <input id=\"text-area\" type=\"text\" [(ngModel)]=\"this.text\" (focusout)=\"leaveTextInput()\"/>\n</svg:foreignObject>\n" }]
|
|
528
|
+
}], propDecorators: { text: [{
|
|
529
|
+
type: Input
|
|
530
|
+
}], x: [{
|
|
531
|
+
type: Input
|
|
532
|
+
}], y: [{
|
|
533
|
+
type: Input
|
|
534
|
+
}], w: [{
|
|
535
|
+
type: Input
|
|
536
|
+
}], h: [{
|
|
537
|
+
type: Input
|
|
538
|
+
}], singleEdit: [{
|
|
539
|
+
type: Input
|
|
540
|
+
}], textChange: [{
|
|
541
|
+
type: Output
|
|
542
|
+
}] } });
|
|
543
|
+
|
|
544
|
+
class RectangleComponent {
|
|
545
|
+
position;
|
|
546
|
+
color = '#ccffff';
|
|
547
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: RectangleComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
548
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.4", type: RectangleComponent, isStandalone: true, selector: "[rectangleG]", inputs: { position: "position", color: "color" }, ngImport: i0, template: "<svg:g>\n <rect [attr.x]=\"position.x\" [attr.y]=\"position.y\" [attr.width]=\"position.w\" [attr.height]=\"position.h\" [attr.fill]=\"color\"></rect>\n</svg:g>\n", styles: [""] });
|
|
549
|
+
}
|
|
550
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: RectangleComponent, decorators: [{
|
|
551
|
+
type: Component,
|
|
552
|
+
args: [{ selector: '[rectangleG]', imports: [], template: "<svg:g>\n <rect [attr.x]=\"position.x\" [attr.y]=\"position.y\" [attr.width]=\"position.w\" [attr.height]=\"position.h\" [attr.fill]=\"color\"></rect>\n</svg:g>\n" }]
|
|
553
|
+
}], propDecorators: { position: [{
|
|
554
|
+
type: Input
|
|
555
|
+
}], color: [{
|
|
556
|
+
type: Input
|
|
557
|
+
}] } });
|
|
558
|
+
|
|
559
|
+
class RectangleWithTextComponent {
|
|
560
|
+
id;
|
|
561
|
+
text;
|
|
562
|
+
textChange = new EventEmitter();
|
|
563
|
+
position;
|
|
564
|
+
color;
|
|
565
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: RectangleWithTextComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
566
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.4", type: RectangleWithTextComponent, isStandalone: true, selector: "[rectangle-with-text]", inputs: { id: "id", text: "text", position: "position", color: "color" }, outputs: { textChange: "textChange" }, ngImport: i0, template: "<svg:g [attr.id]=\"id\">\n <g rectangleG\n [position]=\"position\"\n [color]=\"color\">\n </g>\n <!-- class name -->\n <g text-area-svg\n [(text)]=\"text\"\n [x]=\"position.x\"\n [y]=\"position.y\"\n [w]=\"position.w\"\n [h]=\"position.h\">\n </g>\n</svg:g>", styles: [""], dependencies: [{ kind: "component", type: TextAreaSvgComponent, selector: "[text-area-svg]", inputs: ["text", "x", "y", "w", "h", "singleEdit"], outputs: ["textChange"] }, { kind: "component", type: RectangleComponent, selector: "[rectangleG]", inputs: ["position", "color"] }] });
|
|
567
|
+
}
|
|
568
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: RectangleWithTextComponent, decorators: [{
|
|
569
|
+
type: Component,
|
|
570
|
+
args: [{ selector: '[rectangle-with-text]', imports: [
|
|
571
|
+
TextAreaSvgComponent,
|
|
572
|
+
RectangleComponent
|
|
573
|
+
], template: "<svg:g [attr.id]=\"id\">\n <g rectangleG\n [position]=\"position\"\n [color]=\"color\">\n </g>\n <!-- class name -->\n <g text-area-svg\n [(text)]=\"text\"\n [x]=\"position.x\"\n [y]=\"position.y\"\n [w]=\"position.w\"\n [h]=\"position.h\">\n </g>\n</svg:g>" }]
|
|
574
|
+
}], propDecorators: { id: [{
|
|
575
|
+
type: Input
|
|
576
|
+
}], text: [{
|
|
577
|
+
type: Input
|
|
578
|
+
}], textChange: [{
|
|
579
|
+
type: Output
|
|
580
|
+
}], position: [{
|
|
581
|
+
type: Input
|
|
582
|
+
}], color: [{
|
|
583
|
+
type: Input
|
|
584
|
+
}] } });
|
|
585
|
+
|
|
586
|
+
/*
|
|
587
|
+
* Public API Surface of arrows
|
|
588
|
+
*/
|
|
589
|
+
|
|
590
|
+
/**
|
|
591
|
+
* Generated bundle index. Do not edit.
|
|
592
|
+
*/
|
|
593
|
+
|
|
594
|
+
export { ArrowBetweenBoxesComponent, ArrowBetweenElemsComponent, ArrowBetweenPointsComponent, ArrowStyleConfigurationService, DraggableComponent, Dragger, PathLayouter, PositionHelper, RectangleComponent, RectangleWithTextComponent, SVGAccessService, TextAreaSvgComponent, TextDistributor };
|
|
595
|
+
//# sourceMappingURL=ngx-svg-graphics.mjs.map
|