-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSVGEllipse.js
27 lines (27 loc) · 948 Bytes
/
SVGEllipse.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
function SVGEllipse(ellipse) {
this.ellipse = ellipse;
this.tag = 'ellipse';
this.el = this.createEl();
this.$el = $(this.el);
this.update();
this.ellipse.on('change', function() {
this.update();
}.bind(this));
}
SVGEllipse.prototype.update = function update() {
var ellipse = this.ellipse;
this.$el.attr('cx', (ellipse.pt1.x + ellipse.pt2.x) / 2);
this.$el.attr('cy', (ellipse.pt1.y + ellipse.pt2.y) / 2);
this.$el.attr('rx', Math.abs((ellipse.pt1.x - ellipse.pt2.x) / 2));
this.$el.attr('ry', Math.abs((ellipse.pt1.y - ellipse.pt2.y) / 2));
var style = [
'fill:' + ellipse.color,
'stroke:' + ellipse.border_color,
'stroke-width:' + ellipse.border_width
];
this.$el.attr('style', style.join('; '));
};
// pull into shared SVGElement base class
SVGEllipse.prototype.createEl = function createEl() {
return document.createElementNS('http://www.w3.org/2000/svg', this.tag);
};