-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathistar-dependency.js
More file actions
80 lines (61 loc) · 2.02 KB
/
Copy pathistar-dependency.js
File metadata and controls
80 lines (61 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { ModelShapePath } from 'direwolf-modeler/model-shape-path';
export class IStarDependency extends ModelShapePath {
constructor(id, createdLocally, pathArray = []) {
super(id, createdLocally, pathArray);
}
createSVGElement(viewport) {
let group = super.createSVGElement(viewport);
// add dependency label
this.text = group.text('D').font({weight: 'bold', size: '16px'});
this.redrawPath();
return group;
}
get descriptiveName() {
return `Dependency`;
}
get properties() {
return Object.assign(super.properties, {
});
}
redrawPath() {
super.redrawPath();
if (this._pathArray && (this._pathArray.length > 0)) {
let mid = this._midPoint(this._pathArray[0], this._pathArray[1]);
if (this.text) {
this.text.cx(mid[0]);
this.text.cy(mid[1]);
// calculate angle
// kudos https://bl.ocks.org/shancarter/1034db3e675f2d3814e6006cf31dbfdc
const source = {x: 1, y: 0};
const compare = {x: (this._pathArray[1][0] - this._pathArray[0][0]), y: (this._pathArray[0][1]) - this._pathArray[1][1]};
const a2 = Math.atan2(source.y, source.x);
const a1 = Math.atan2(compare.y, compare.x);
const sign = a1 > a2 ? 1 : -1;
let angle = a1 - a2;
const K = -sign * Math.PI * 2;
angle = (Math.abs(K + angle) < Math.abs(angle))? K + angle : angle;
let degree = Math.abs(Math.round(360 * angle / (Math.PI * 2)));
degree = (angle < 0) ? (360 - degree) : degree;
this.text.transform({rotate: (360 - degree)});
}
}
}
_midPoint(start, end) {
// kudos https://stackoverflow.com/questions/43920474/svg-js-line-marker-mid/44010722
return [
(start[0] + end[0]) / 2,
(start[1] + end[1]) / 2
];
}
/**
* Direwolf-specific methods
*/
sharedStateAvailable(sharedState) {
super.sharedStateAvailable(sharedState);
if (this._createdLocally) {
}
}
handleSharedStateChanged(event) {
super.handleSharedStateChanged(event);
}
}