-
Notifications
You must be signed in to change notification settings - Fork 0
/
model-shape-circle.js
106 lines (83 loc) · 2.1 KB
/
model-shape-circle.js
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import { ModelElement } from './model-element.js';
import {ShapeInfo} from 'kld-intersections';
export class ModelShapeCircle extends ModelElement {
constructor(id, createdLocally) {
super(id, createdLocally);
this._minDiameter = 80;
this._diameter = 80;
}
createSVGElement(viewport) {
let group = super.createSVGElement(viewport);
group.addClass('model-node');
this.circle = group.circle(this._diameter).stroke({ width: 1, color: 'black' });
return this.element;
}
get properties() {
return Object.assign(super.properties, {
x: {
type: Number
},
y: {
type: Number
},
diameter: {
type: Number
}
});
}
get descriptiveName() {
return 'Circle';
}
get resizable() {
return true;
}
showPortOnHover() {
return false;
}
get minDiameter() {
return this._minDiameter;
}
set width(width) {
this.diameter = width;
}
get width() {
return this.diameter;
}
set height(height) {
this.diameter = height;
}
get height() {
return this.diameter;
}
getOuterShape(offset) {
return ShapeInfo.circle({cx: (offset.x + this.x + this.circle.attr('cx')), cy: (offset.y + this.y + this.circle.attr('cy')), r: this.circle.attr('r')});
}
/**
* Direwolf-specific methods
*/
sharedStateAvailable(sharedState) {
super.sharedStateAvailable(sharedState);
if (this._createdLocally) {
if (this.diameter === undefined) {
this.diameter = this._diameter;
}
}
this.element.transform({translateX: this.x, translateY: this.y});
this.circle.radius(this.diameter / 2);
}
handleSharedStateChanged(event) {
event.keysChanged.forEach((key) => {
switch (key) {
case 'x':
this.element.transform({translateX: event.target.get(key), translateY: this.y});
break;
case 'y':
this.element.transform({translateX: this.x, translateY: event.target.get(key)});
break;
case 'diameter':
this.circle.radius(event.target.get(key) / 2);
break;
}
});
}
}