-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy patharc.js
124 lines (108 loc) · 3.36 KB
/
arc.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/**
* Draw an arc
*
* r,t1,t2 - radius, theta1, theta2
*/
Donatello.Arc = function( parent, x, y, r, t1, t2, a ) {
a = Donatello.attrDefaults( a );
var s = a['stroke-width'];
var c = a['stroke'];
var f = a['fill'];
var style = a['stroke-style'];
this.properties = {
x: x, y: y, r: r, t1: t1, t2: t2,
'stroke-width': s,
'stroke-style': style,
'stroke': c,
'fill': f
};
var deg = t2;
// four circles and a clipping region
var clip = Donatello.createElement( x-2*r, y-2*r, 2*r, 2*r, 'div');
// make clipping visible for debugging and to better understand
// the technique
// clip.style.border = '1px solid orange';
// todo: need to move calculations to draw so attr() works correctly
var c1 = Donatello.createElement( r-s/2, r-s/2, 2*r-s, 2*r-s, 'div');
var c2 = Donatello.createElement( r-s/2, r-s/2, 2*r-s, 2*r-s, 'div');
var c3 = Donatello.createElement( r-s/2, r-s/2, 2*r-s, 2*r-s, 'div');
var c4 = Donatello.createElement( r-s/2, r-s/2, 2*r-s, 2*r-s, 'div');
clip.appendChild( c1 );
clip.appendChild( c2 );
clip.appendChild( c3 );
clip.appendChild( c4 );
this.styleableElements = [ c1, c2, c3, c4 ];
clip.style[ Donatello.transform + 'Origin' ]= '100% 100%';
parent.dom.appendChild( clip );
this._parent = parent;
this.dom = clip;
// attr calls draw ...
// this.attr( a );
this.draw( t2 );
}
Donatello.Arc.prototype = new Donatello( null );
Donatello.prototype.arc = function( x, y, r, t1, t2, a ) {
return new Donatello.Arc( this, x, y, r, t1, t2, a );
};
Donatello.Arc.prototype.draw = function( t2 ) {
var angle = t2;
var t1 = this.properties.t1;
// order of skew/rotation important
if( angle < 90 ) {
this.dom.style.overflow = 'hidden';
this.dom.style[ Donatello.transform ] =
// offset rotation by 180deg to conform to svg angle conventions
'rotate(' + (180+t1) + 'deg)' +
'skew(' + (90-angle) +'deg)';
}
else {
this.dom.style.overflow = 'visible';
this.dom.style[ Donatello.transform ] =
// offset rotation by 180deg to conform to svg angle conventions
'rotate(' + (180+t1) + 'deg)' +
// reset skew
'skew(0deg)';
}
// TODO: some of this doesn't belong here
// we don't have to recalculate when color changes
var x = this.properties.x;
var y = this.properties.y;
var r = this.properties.r;
var s = this.properties['stroke-width'];
var c = this.properties.stroke;
var f = this.properties.fill;
var style = this.properties['stroke-style'];
function setprops( el, ang ) {
el.style.borderRadius = r + s + 'px';
el.style.borderWidth = s + 'px';
/*
if( Donatello.CORRECT_FOR_STROKE ) {
el.style.left = x-r-s/2 + 'px';
console.log( 'arc left: ' + el.style.left );
el.style.top = y-r-s/2 + 'px';
el.style.width = 2*r - s + 'px';
el.style.height = 2*r - s + 'px';
}
else {
el.style.left = x-r-s + 'px';
el.style.top = y-r-s + 'px';
}
*/
el.style.borderStyle = style;
el.style.borderColor = c;
el.style.borderBottomColor = 'transparent';
el.style.borderLeftColor = 'transparent';
el.style.borderRightColor = 'transparent';
el.style.backgroundColor = f;
if( angle < 90 ) {
// order of skew/rotation is important
el.style[ Donatello.transform ]= 'skew(' + -(90-angle) + 'deg)rotate(' + (ang-45) +'deg)';
}
else {
el.style[ Donatello.transform ]= 'rotate(' + (ang-45) +'deg)';
}
}
for( var i=0; i < 4; i++ ) {
setprops( this.dom.children[i], (angle-90)*i/3 );
}
}