html5jp_graphs 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/.gitigore +2 -0
  2. data/README.rdoc +82 -0
  3. data/Rakefile +22 -0
  4. data/html5jp_graphs.gemspec +17 -0
  5. data/lib/examples/sample_graph_circle_1.html +54 -0
  6. data/lib/examples/sample_graph_circle_2.html +61 -0
  7. data/lib/examples/sample_graph_line_1.html +44 -0
  8. data/lib/examples/sample_graph_line_2.html +53 -0
  9. data/lib/examples/sample_graph_radar_1.html +47 -0
  10. data/lib/examples/sample_graph_radar_2.html +52 -0
  11. data/lib/examples/sample_graph_vbar_1.html +51 -0
  12. data/lib/examples/sample_graph_vbar_2.html +52 -0
  13. data/lib/examples/sample_graph_vbar_3.html +52 -0
  14. data/lib/examples/sample_graph_vbar_4.html +52 -0
  15. data/lib/generators/html5jp_graphs/USAGE +8 -0
  16. data/lib/generators/html5jp_graphs/html5jp_graphs_generator.rb +12 -0
  17. data/lib/generators/html5jp_graphs/templates/excanvas/AUTHORS +10 -0
  18. data/lib/generators/html5jp_graphs/templates/excanvas/COPYING +202 -0
  19. data/lib/generators/html5jp_graphs/templates/excanvas/README +22 -0
  20. data/lib/generators/html5jp_graphs/templates/excanvas/examples/example1.html +93 -0
  21. data/lib/generators/html5jp_graphs/templates/excanvas/examples/example2.html +513 -0
  22. data/lib/generators/html5jp_graphs/templates/excanvas/examples/example3.html +284 -0
  23. data/lib/generators/html5jp_graphs/templates/excanvas/examples/ff.jpg +0 -0
  24. data/lib/generators/html5jp_graphs/templates/excanvas/excanvas-compressed.js +19 -0
  25. data/lib/generators/html5jp_graphs/templates/excanvas/excanvas.js +785 -0
  26. data/lib/generators/html5jp_graphs/templates/excanvas/testcases/arc.html +49 -0
  27. data/lib/generators/html5jp_graphs/templates/excanvas/testcases/linewidth.html +47 -0
  28. data/lib/generators/html5jp_graphs/templates/excanvas/testcases/overflow.html +37 -0
  29. data/lib/generators/html5jp_graphs/templates/excanvas/testcases/quadraticcurve.html +74 -0
  30. data/lib/generators/html5jp_graphs/templates/excanvas/testcases/resizing.html +65 -0
  31. data/lib/generators/html5jp_graphs/templates/graph/circle.js +407 -0
  32. data/lib/generators/html5jp_graphs/templates/graph/line.js +577 -0
  33. data/lib/generators/html5jp_graphs/templates/graph/radar.js +545 -0
  34. data/lib/generators/html5jp_graphs/templates/graph/vbar.js +1156 -0
  35. data/lib/html5jp_graphs.rb +1 -0
  36. data/lib/html5jp_graphs/version.rb +3 -0
  37. data/lib/html5jp_graphs_helper.rb +255 -0
  38. data/tasks/html5jp_graphs_tasks.rake +4 -0
  39. data/test/html5jp_graphs_test.rb +8 -0
  40. metadata +88 -0
@@ -0,0 +1,284 @@
1
+ <!DOCTYPE html>
2
+
3
+ <!--
4
+
5
+ Copyright 2006 Google Inc.
6
+
7
+ Licensed under the Apache License, Version 2.0 (the "License");
8
+ you may not use this file except in compliance with the License.
9
+ You may obtain a copy of the License at
10
+
11
+ http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ Unless required by applicable law or agreed to in writing, software
14
+ distributed under the License is distributed on an "AS IS" BASIS,
15
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ See the License for the specific language governing permissions and
17
+ limitations under the License.
18
+
19
+ -->
20
+
21
+ <html>
22
+ <head>
23
+ <title></title>
24
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
25
+ <!--[if IE]><script type="text/javascript" src="../excanvas.js"></script><![endif]-->
26
+ <style type="text/css">
27
+
28
+ body {
29
+ overflow: hidden;
30
+ width: 100%;
31
+ height: 100%;
32
+ margin: 0;
33
+ }
34
+
35
+ #image-rotator {
36
+ position: absolute;
37
+ left: 0;
38
+ top: 0;
39
+ width: 100%;
40
+ height: 100%;
41
+ }
42
+
43
+ #image-rotator .tool-bar {
44
+ text-align: center;
45
+ }
46
+
47
+ .tool-bar button {
48
+ margin: 0.5em 0.5em 0 0;
49
+ }
50
+
51
+ #image-rotator img,
52
+ #image-rotator canvas {
53
+ position: absolute;
54
+ }
55
+
56
+ </style>
57
+ <script type="text/javascript">
58
+
59
+ function sawFunc(a) {
60
+ var PI = Math.PI;
61
+ var PI2 = PI / 2;
62
+ // make sure a is within 0 to PI
63
+ a = a % PI;
64
+ if (a < 0) {
65
+ a += PI;
66
+ }
67
+ if (a < PI2) {
68
+ return a / PI2;
69
+ } else {
70
+ return (PI - a) / PI2;
71
+ }
72
+ }
73
+
74
+ function easeInEaseOut(t) {
75
+ var t2 = t * t;
76
+ return 3 * t2 - 2 * t * t2;
77
+ }
78
+
79
+ function ImageRotator(el, src, w, h) {
80
+ this.element = el;
81
+ this.toolBar = el.getElementsByTagName("div")[0];
82
+ this.canvas = el.getElementsByTagName("canvas")[0];
83
+ var images = el.getElementsByTagName("img");
84
+ this.image = images[images.length - 1];
85
+ var btns = el.getElementsByTagName("button");
86
+ this.btnCw = btns[0];
87
+ this.btnCcw = btns[1];
88
+ var self = this;
89
+ this.btnCcw.onclick = function () {
90
+ self.rotateCcw();
91
+ };
92
+ this.btnCw.onclick = function () {
93
+ self.rotateCw();
94
+ };
95
+ this.image.onload = function (e) {
96
+ self.onImageLoad(e);
97
+ };
98
+ this.image.onerror = function (e) {
99
+ self.onImageError(e);
100
+ };
101
+ this.image.onabort = function (e) {
102
+ self.onImageAbort(e);
103
+ };
104
+ this.setImage(src, w, h);
105
+ this.layout();
106
+
107
+ var onResize = function () {
108
+ self.layout();
109
+ };
110
+ var onLoad = function () {
111
+ self.onWindowLoad();
112
+ };
113
+ if (window.addEventListener) {
114
+ window.addEventListener("resize", onResize, false);
115
+ window.addEventListener("load", onLoad, false);
116
+ } else if (window.attachEvent) {
117
+ window.attachEvent("onresize", onResize);
118
+ window.attachEvent("onload", onLoad);
119
+ }
120
+ }
121
+
122
+ ImageRotator.prototype = {
123
+ getLoaded: function () {
124
+ return this.imageLoaded && this.windowLoaded;
125
+ },
126
+ setImage: function (src, w, h) {
127
+ this.imageLoaded = false;
128
+ this.image.src = src;
129
+ this.imageWidth = w;
130
+ this.imageHeight = h;
131
+ },
132
+
133
+ layout: function () {
134
+ var PI2 = Math.PI / 2;
135
+ var h = this.element.clientHeight;
136
+ var w = this.element.clientWidth;
137
+ var th = this.toolBar.offsetHeight;
138
+ h -= this.toolBar.offsetHeight;
139
+ if (!this.ctx || !this.getLoaded()) {
140
+ this.btnCw.disabled = true;
141
+ this.btnCcw.disabled = true;
142
+ this.canvas.style.display = "none";
143
+ this.image.style.display = "block";
144
+ var ratio = Math.min(w / this.imageWidth, h / this.imageHeight, 1);
145
+ var imgW = this.imageWidth * ratio;
146
+ var imgH = this.imageHeight * ratio;
147
+ var y = th + (h - imgH) / 2;
148
+ var x = (w - imgW) / 2;
149
+ this.image.style.left = Math.round(x) + "px";
150
+ this.image.style.top = Math.round(y) + "px";
151
+ this.image.style.width = Math.round(imgW) + "px";
152
+ this.image.style.height = Math.round(imgH) + "px";
153
+ } else {
154
+ this.btnCw.disabled = this.isAnimating_;
155
+ this.btnCcw.disabled = this.isAnimating_;
156
+ this.canvas.style.display = "block";
157
+ this.image.style.display = "none";
158
+
159
+ this.canvas.style.left = 0 + "px";
160
+ this.canvas.style.top = th + "px";
161
+ this.canvas.style.width = w + "px";
162
+ this.canvas.width = w;
163
+ this.canvas.style.height = h + "px";
164
+ this.canvas.height = h;
165
+
166
+ this.ctx.save();
167
+ this.ctx.clearRect(0, 0, w, h);
168
+ this.ctx.translate(w / 2, h / 2);
169
+ this.ctx.rotate(this.rotation);
170
+ // 0 -> 1, sin(0) = 0
171
+ // PI / 2 -> H / W, sin(PI/2) = 1
172
+
173
+ // sin(PI/2) = 1 -> limit factor is w and imgH
174
+
175
+ var iw = this.imageWidth;
176
+ var ih = this.imageHeight;
177
+ var scale;
178
+ if (iw <= w && iw <= h && ih <= h && ih <= w) {
179
+ scale = 1;
180
+ } else {
181
+ var sinr = sawFunc(this.rotation);
182
+ var cosr = sawFunc(this.rotation + PI2);
183
+ var ratio1 = sinr * Math.min(w / ih, h / iw);
184
+ var ratio2 = cosr * Math.min(w / iw, h / ih);
185
+ var ratio = Math.min(1, ratio1 + ratio2);
186
+ scale = ratio;
187
+ }
188
+ this.ctx.scale(scale, scale);
189
+ this.ctx.translate(-iw / 2, -ih / 2);
190
+ this.ctx.drawImage(this.image, 0, 0, iw, ih);
191
+ this.ctx.restore();
192
+ }
193
+ },
194
+
195
+ rotation: 0,
196
+ animationDuration: 500,
197
+
198
+ rotateCcw: function () {
199
+ if (!this.isAnimating_) {
200
+ this.startTime_ = (new Date).valueOf();
201
+ this.currentAngle_ = this.rotation;
202
+ this.deltaAngle_ = Math.PI / 2;
203
+ this.isAnimating_ = true;
204
+ this.animCounter_ = 0;
205
+ this.rotate_();
206
+ }
207
+ },
208
+
209
+ rotateCw: function () {
210
+ if (!this.isAnimating_) {
211
+ this.startTime_ = (new Date).valueOf();
212
+ this.currentAngle_ = this.rotation;
213
+ this.deltaAngle_ = -Math.PI / 2;
214
+ this.isAnimating_ = true;
215
+ this.animCounter_ = 0;
216
+ this.rotate_();
217
+ }
218
+ },
219
+
220
+ rotate_: function () {
221
+ if (this.isAnimating_) {
222
+ var t = easeInEaseOut(Math.min(1, (new Date - this.startTime_) /
223
+ this.animationDuration));
224
+ this.rotation = t * this.deltaAngle_ + this.currentAngle_;
225
+ if (t < 1) {
226
+ var self = this;
227
+ window.setTimeout(function () {
228
+ self.rotate_();
229
+ }, 10);
230
+ } else {
231
+ this.isAnimating_ = false;
232
+ }
233
+ this.layout();
234
+ }
235
+ },
236
+
237
+ onImageLoad: function (e) {
238
+ this.imageLoaded = true;
239
+ this.initCanvas();
240
+ },
241
+ onImageError: function (e) {
242
+ this.imageLoaded = false;
243
+ },
244
+ onImageAbort: function (e) {
245
+ this.imageLoaded = false;
246
+ },
247
+ onWindowLoad: function (e) {
248
+ this.windowLoaded = true;
249
+ this.initCanvas();
250
+ },
251
+
252
+ initCanvas: function () {
253
+ if (!this.ctx && this.getLoaded()) {
254
+ // IE recreates the element?
255
+ this.canvas = this.element.getElementsByTagName("canvas")[0];
256
+ this.ctx = this.canvas.getContext("2d");
257
+
258
+ if (!this.ctx) {
259
+ return;
260
+ }
261
+ this.layout();
262
+ }
263
+ }
264
+ };
265
+
266
+ </script>
267
+ </head>
268
+ <body>
269
+
270
+ <div id="image-rotator">
271
+ <div class="tool-bar">
272
+ <button>Rotate Left</button><button>Rotate Right</button>
273
+ </div>
274
+ <canvas id="c"></canvas>
275
+ <img src="" alt="">
276
+ </div>
277
+ <script type="text/javascript">
278
+ new ImageRotator(document.getElementById("image-rotator"),
279
+ "ff.jpg", 608, 380);
280
+ </script>
281
+
282
+ </body>
283
+ </html>
284
+
@@ -0,0 +1,19 @@
1
+ if(!window.CanvasRenderingContext2D){(function(){var I=Math,i=I.round,L=I.sin,M=I.cos,m=10,A=m/2,Q={init:function(a){var b=a||document;if(/MSIE/.test(navigator.userAgent)&&!window.opera){var c=this;b.attachEvent("onreadystatechange",function(){c.r(b)})}},r:function(a){if(a.readyState=="complete"){if(!a.namespaces["s"]){a.namespaces.add("g_vml_","urn:schemas-microsoft-com:vml")}var b=a.createStyleSheet();b.cssText="canvas{display:inline-block;overflow:hidden;text-align:left;width:300px;height:150px}g_vml_\\:*{behavior:url(#default#VML)}";
2
+ var c=a.getElementsByTagName("canvas");for(var d=0;d<c.length;d++){if(!c[d].getContext){this.initElement(c[d])}}}},q:function(a){var b=a.outerHTML,c=a.ownerDocument.createElement(b);if(b.slice(-2)!="/>"){var d="/"+a.tagName,e;while((e=a.nextSibling)&&e.tagName!=d){e.removeNode()}if(e){e.removeNode()}}a.parentNode.replaceChild(c,a);return c},initElement:function(a){a=this.q(a);a.getContext=function(){if(this.l){return this.l}return this.l=new K(this)};a.attachEvent("onpropertychange",V);a.attachEvent("onresize",
3
+ W);var b=a.attributes;if(b.width&&b.width.specified){a.style.width=b.width.nodeValue+"px"}else{a.width=a.clientWidth}if(b.height&&b.height.specified){a.style.height=b.height.nodeValue+"px"}else{a.height=a.clientHeight}return a}};function V(a){var b=a.srcElement;switch(a.propertyName){case "width":b.style.width=b.attributes.width.nodeValue+"px";b.getContext().clearRect();break;case "height":b.style.height=b.attributes.height.nodeValue+"px";b.getContext().clearRect();break}}function W(a){var b=a.srcElement;
4
+ if(b.firstChild){b.firstChild.style.width=b.clientWidth+"px";b.firstChild.style.height=b.clientHeight+"px"}}Q.init();var R=[];for(var E=0;E<16;E++){for(var F=0;F<16;F++){R[E*16+F]=E.toString(16)+F.toString(16)}}function J(){return[[1,0,0],[0,1,0],[0,0,1]]}function G(a,b){var c=J();for(var d=0;d<3;d++){for(var e=0;e<3;e++){var g=0;for(var h=0;h<3;h++){g+=a[d][h]*b[h][e]}c[d][e]=g}}return c}function N(a,b){b.fillStyle=a.fillStyle;b.lineCap=a.lineCap;b.lineJoin=a.lineJoin;b.lineWidth=a.lineWidth;b.miterLimit=
5
+ a.miterLimit;b.shadowBlur=a.shadowBlur;b.shadowColor=a.shadowColor;b.shadowOffsetX=a.shadowOffsetX;b.shadowOffsetY=a.shadowOffsetY;b.strokeStyle=a.strokeStyle;b.d=a.d;b.e=a.e}function O(a){var b,c=1;a=String(a);if(a.substring(0,3)=="rgb"){var d=a.indexOf("(",3),e=a.indexOf(")",d+1),g=a.substring(d+1,e).split(",");b="#";for(var h=0;h<3;h++){b+=R[Number(g[h])]}if(g.length==4&&a.substr(3,1)=="a"){c=g[3]}}else{b=a}return[b,c]}function S(a){switch(a){case "butt":return"flat";case "round":return"round";
6
+ case "square":default:return"square"}}function K(a){this.a=J();this.m=[];this.k=[];this.c=[];this.strokeStyle="#000";this.fillStyle="#000";this.lineWidth=1;this.lineJoin="miter";this.lineCap="butt";this.miterLimit=m*1;this.globalAlpha=1;this.canvas=a;var b=a.ownerDocument.createElement("div");b.style.width=a.clientWidth+"px";b.style.height=a.clientHeight+"px";b.style.overflow="hidden";b.style.position="absolute";a.appendChild(b);this.j=b;this.d=1;this.e=1}var j=K.prototype;j.clearRect=function(){this.j.innerHTML=
7
+ "";this.c=[]};j.beginPath=function(){this.c=[]};j.moveTo=function(a,b){this.c.push({type:"moveTo",x:a,y:b});this.f=a;this.g=b};j.lineTo=function(a,b){this.c.push({type:"lineTo",x:a,y:b});this.f=a;this.g=b};j.bezierCurveTo=function(a,b,c,d,e,g){this.c.push({type:"bezierCurveTo",cp1x:a,cp1y:b,cp2x:c,cp2y:d,x:e,y:g});this.f=e;this.g=g};j.quadraticCurveTo=function(a,b,c,d){var e=this.f+0.6666666666666666*(a-this.f),g=this.g+0.6666666666666666*(b-this.g),h=e+(c-this.f)/3,l=g+(d-this.g)/3;this.bezierCurveTo(e,
8
+ g,h,l,c,d)};j.arc=function(a,b,c,d,e,g){c*=m;var h=g?"at":"wa",l=a+M(d)*c-A,n=b+L(d)*c-A,o=a+M(e)*c-A,f=b+L(e)*c-A;if(l==o&&!g){l+=0.125}this.c.push({type:h,x:a,y:b,radius:c,xStart:l,yStart:n,xEnd:o,yEnd:f})};j.rect=function(a,b,c,d){this.moveTo(a,b);this.lineTo(a+c,b);this.lineTo(a+c,b+d);this.lineTo(a,b+d);this.closePath()};j.strokeRect=function(a,b,c,d){this.beginPath();this.moveTo(a,b);this.lineTo(a+c,b);this.lineTo(a+c,b+d);this.lineTo(a,b+d);this.closePath();this.stroke()};j.fillRect=function(a,
9
+ b,c,d){this.beginPath();this.moveTo(a,b);this.lineTo(a+c,b);this.lineTo(a+c,b+d);this.lineTo(a,b+d);this.closePath();this.fill()};j.createLinearGradient=function(a,b,c,d){var e=new H("gradient");return e};j.createRadialGradient=function(a,b,c,d,e,g){var h=new H("gradientradial");h.n=c;h.o=g;h.i.x=a;h.i.y=b;return h};j.drawImage=function(a,b){var c,d,e,g,h,l,n,o,f=a.runtimeStyle.width,k=a.runtimeStyle.height;a.runtimeStyle.width="auto";a.runtimeStyle.height="auto";var q=a.width,r=a.height;a.runtimeStyle.width=
10
+ f;a.runtimeStyle.height=k;if(arguments.length==3){c=arguments[1];d=arguments[2];h=(l=0);n=(e=q);o=(g=r)}else if(arguments.length==5){c=arguments[1];d=arguments[2];e=arguments[3];g=arguments[4];h=(l=0);n=q;o=r}else if(arguments.length==9){h=arguments[1];l=arguments[2];n=arguments[3];o=arguments[4];c=arguments[5];d=arguments[6];e=arguments[7];g=arguments[8]}else{throw"Invalid number of arguments";}var s=this.b(c,d),t=[],v=10,w=10;t.push(" <g_vml_:group",' coordsize="',m*v,",",m*w,'"',' coordorigin="0,0"',
11
+ ' style="width:',v,";height:",w,";position:absolute;");if(this.a[0][0]!=1||this.a[0][1]){var x=[];x.push("M11='",this.a[0][0],"',","M12='",this.a[1][0],"',","M21='",this.a[0][1],"',","M22='",this.a[1][1],"',","Dx='",i(s.x/m),"',","Dy='",i(s.y/m),"'");var p=s,y=this.b(c+e,d),z=this.b(c,d+g),B=this.b(c+e,d+g);p.x=Math.max(p.x,y.x,z.x,B.x);p.y=Math.max(p.y,y.y,z.y,B.y);t.push("padding:0 ",i(p.x/m),"px ",i(p.y/m),"px 0;filter:progid:DXImageTransform.Microsoft.Matrix(",x.join(""),", sizingmethod='clip');")}else{t.push("top:",
12
+ i(s.y/m),"px;left:",i(s.x/m),"px;")}t.push(' ">','<g_vml_:image src="',a.src,'"',' style="width:',m*e,";"," height:",m*g,';"',' cropleft="',h/q,'"',' croptop="',l/r,'"',' cropright="',(q-h-n)/q,'"',' cropbottom="',(r-l-o)/r,'"'," />","</g_vml_:group>");this.j.insertAdjacentHTML("BeforeEnd",t.join(""))};j.stroke=function(a){var b=[],c=O(a?this.fillStyle:this.strokeStyle),d=c[0],e=c[1]*this.globalAlpha,g=10,h=10;b.push("<g_vml_:shape",' fillcolor="',d,'"',' filled="',Boolean(a),'"',' style="position:absolute;width:',
13
+ g,";height:",h,';"',' coordorigin="0 0" coordsize="',m*g," ",m*h,'"',' stroked="',!a,'"',' strokeweight="',this.lineWidth,'"',' strokecolor="',d,'"',' path="');var l={x:null,y:null},n={x:null,y:null};for(var o=0;o<this.c.length;o++){var f=this.c[o];if(f.type=="moveTo"){b.push(" m ");var k=this.b(f.x,f.y);b.push(i(k.x),",",i(k.y))}else if(f.type=="lineTo"){b.push(" l ");var k=this.b(f.x,f.y);b.push(i(k.x),",",i(k.y))}else if(f.type=="close"){b.push(" x ")}else if(f.type=="bezierCurveTo"){b.push(" c ");
14
+ var k=this.b(f.x,f.y),q=this.b(f.cp1x,f.cp1y),r=this.b(f.cp2x,f.cp2y);b.push(i(q.x),",",i(q.y),",",i(r.x),",",i(r.y),",",i(k.x),",",i(k.y))}else if(f.type=="at"||f.type=="wa"){b.push(" ",f.type," ");var k=this.b(f.x,f.y),s=this.b(f.xStart,f.yStart),t=this.b(f.xEnd,f.yEnd);b.push(i(k.x-this.d*f.radius),",",i(k.y-this.e*f.radius)," ",i(k.x+this.d*f.radius),",",i(k.y+this.e*f.radius)," ",i(s.x),",",i(s.y)," ",i(t.x),",",i(t.y))}if(k){if(l.x==null||k.x<l.x){l.x=k.x}if(n.x==null||k.x>n.x){n.x=k.x}if(l.y==
15
+ null||k.y<l.y){l.y=k.y}if(n.y==null||k.y>n.y){n.y=k.y}}}b.push(' ">');if(typeof this.fillStyle=="object"){var v={x:"50%",y:"50%"},w=n.x-l.x,x=n.y-l.y,p=w>x?w:x;v.x=i(this.fillStyle.i.x/w*100+50)+"%";v.y=i(this.fillStyle.i.y/x*100+50)+"%";var y=[];if(this.fillStyle.p=="gradientradial"){var z=this.fillStyle.n/p*100,B=this.fillStyle.o/p*100-z}else{var z=0,B=100}var C={offset:null,color:null},D={offset:null,color:null};this.fillStyle.h.sort(function(T,U){return T.offset-U.offset});for(var o=0;o<this.fillStyle.h.length;o++){var u=
16
+ this.fillStyle.h[o];y.push(u.offset*B+z,"% ",u.color,",");if(u.offset>C.offset||C.offset==null){C.offset=u.offset;C.color=u.color}if(u.offset<D.offset||D.offset==null){D.offset=u.offset;D.color=u.color}}y.pop();b.push("<g_vml_:fill",' color="',D.color,'"',' color2="',C.color,'"',' type="',this.fillStyle.p,'"',' focusposition="',v.x,", ",v.y,'"',' colors="',y.join(""),'"',' opacity="',e,'" />')}else if(a){b.push('<g_vml_:fill color="',d,'" opacity="',e,'" />')}else{b.push("<g_vml_:stroke",' opacity="',
17
+ e,'"',' joinstyle="',this.lineJoin,'"',' miterlimit="',this.miterLimit,'"',' endcap="',S(this.lineCap),'"',' weight="',this.lineWidth,'px"',' color="',d,'" />')}b.push("</g_vml_:shape>");this.j.insertAdjacentHTML("beforeEnd",b.join(""));this.c=[]};j.fill=function(){this.stroke(true)};j.closePath=function(){this.c.push({type:"close"})};j.b=function(a,b){return{x:m*(a*this.a[0][0]+b*this.a[1][0]+this.a[2][0])-A,y:m*(a*this.a[0][1]+b*this.a[1][1]+this.a[2][1])-A}};j.save=function(){var a={};N(this,a);
18
+ this.k.push(a);this.m.push(this.a);this.a=G(J(),this.a)};j.restore=function(){N(this.k.pop(),this);this.a=this.m.pop()};j.translate=function(a,b){var c=[[1,0,0],[0,1,0],[a,b,1]];this.a=G(c,this.a)};j.rotate=function(a){var b=M(a),c=L(a),d=[[b,c,0],[-c,b,0],[0,0,1]];this.a=G(d,this.a)};j.scale=function(a,b){this.d*=a;this.e*=b;var c=[[a,0,0],[0,b,0],[0,0,1]];this.a=G(c,this.a)};j.clip=function(){};j.arcTo=function(){};j.createPattern=function(){return new P};function H(a){this.p=a;this.n=0;this.o=
19
+ 0;this.h=[];this.i={x:0,y:0}}H.prototype.addColorStop=function(a,b){b=O(b);this.h.push({offset:1-a,color:b})};function P(){}G_vmlCanvasManager=Q;CanvasRenderingContext2D=K;CanvasGradient=H;CanvasPattern=P})()};
@@ -0,0 +1,785 @@
1
+ // Copyright 2006 Google Inc.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+
16
+ // Known Issues:
17
+ //
18
+ // * Patterns are not implemented.
19
+ // * Radial gradient are not implemented. The VML version of these look very
20
+ // different from the canvas one.
21
+ // * Clipping paths are not implemented.
22
+ // * Coordsize. The width and height attribute have higher priority than the
23
+ // width and height style values which isn't correct.
24
+ // * Painting mode isn't implemented.
25
+ // * Canvas width/height should is using content-box by default. IE in
26
+ // Quirks mode will draw the canvas using border-box. Either change your
27
+ // doctype to HTML5
28
+ // (http://www.whatwg.org/specs/web-apps/current-work/#the-doctype)
29
+ // or use Box Sizing Behavior from WebFX
30
+ // (http://webfx.eae.net/dhtml/boxsizing/boxsizing.html)
31
+ // * Optimize. There is always room for speed improvements.
32
+
33
+ // only add this code if we do not already have a canvas implementation
34
+ if (!window.CanvasRenderingContext2D) {
35
+
36
+ (function () {
37
+
38
+ // alias some functions to make (compiled) code shorter
39
+ var m = Math;
40
+ var mr = m.round;
41
+ var ms = m.sin;
42
+ var mc = m.cos;
43
+
44
+ // this is used for sub pixel precision
45
+ var Z = 10;
46
+ var Z2 = Z / 2;
47
+
48
+ var G_vmlCanvasManager_ = {
49
+ init: function (opt_doc) {
50
+ var doc = opt_doc || document;
51
+ if (/MSIE/.test(navigator.userAgent) && !window.opera) {
52
+ var self = this;
53
+ doc.attachEvent("onreadystatechange", function () {
54
+ self.init_(doc);
55
+ });
56
+ }
57
+ },
58
+
59
+ init_: function (doc) {
60
+ if (doc.readyState == "complete") {
61
+ // create xmlns
62
+ if (!doc.namespaces["g_vml_"]) {
63
+ doc.namespaces.add("g_vml_", "urn:schemas-microsoft-com:vml");
64
+ }
65
+
66
+ // setup default css
67
+ var ss = doc.createStyleSheet();
68
+ ss.cssText = "canvas{display:inline-block;overflow:hidden;" +
69
+ // default size is 300x150 in Gecko and Opera
70
+ "text-align:left;width:300px;height:150px}" +
71
+ "g_vml_\\:*{behavior:url(#default#VML)}";
72
+
73
+ // find all canvas elements
74
+ var els = doc.getElementsByTagName("canvas");
75
+ for (var i = 0; i < els.length; i++) {
76
+ if (!els[i].getContext) {
77
+ this.initElement(els[i]);
78
+ }
79
+ }
80
+ }
81
+ },
82
+
83
+ fixElement_: function (el) {
84
+ // in IE before version 5.5 we would need to add HTML: to the tag name
85
+ // but we do not care about IE before version 6
86
+ var outerHTML = el.outerHTML;
87
+
88
+ var newEl = el.ownerDocument.createElement(outerHTML);
89
+ // if the tag is still open IE has created the children as siblings and
90
+ // it has also created a tag with the name "/FOO"
91
+ if (outerHTML.slice(-2) != "/>") {
92
+ var tagName = "/" + el.tagName;
93
+ var ns;
94
+ // remove content
95
+ while ((ns = el.nextSibling) && ns.tagName != tagName) {
96
+ ns.removeNode();
97
+ }
98
+ // remove the incorrect closing tag
99
+ if (ns) {
100
+ ns.removeNode();
101
+ }
102
+ }
103
+ el.parentNode.replaceChild(newEl, el);
104
+ return newEl;
105
+ },
106
+
107
+ /**
108
+ * Public initializes a canvas element so that it can be used as canvas
109
+ * element from now on. This is called automatically before the page is
110
+ * loaded but if you are creating elements using createElement you need to
111
+ * make sure this is called on the element.
112
+ * @param {HTMLElement} el The canvas element to initialize.
113
+ * @return {HTMLElement} the element that was created.
114
+ */
115
+ initElement: function (el) {
116
+ el = this.fixElement_(el);
117
+ el.getContext = function () {
118
+ if (this.context_) {
119
+ return this.context_;
120
+ }
121
+ return this.context_ = new CanvasRenderingContext2D_(this);
122
+ };
123
+
124
+ // do not use inline function because that will leak memory
125
+ el.attachEvent('onpropertychange', onPropertyChange);
126
+ el.attachEvent('onresize', onResize);
127
+
128
+ var attrs = el.attributes;
129
+ if (attrs.width && attrs.width.specified) {
130
+ // TODO: use runtimeStyle and coordsize
131
+ // el.getContext().setWidth_(attrs.width.nodeValue);
132
+ el.style.width = attrs.width.nodeValue + "px";
133
+ } else {
134
+ el.width = el.clientWidth;
135
+ }
136
+ if (attrs.height && attrs.height.specified) {
137
+ // TODO: use runtimeStyle and coordsize
138
+ // el.getContext().setHeight_(attrs.height.nodeValue);
139
+ el.style.height = attrs.height.nodeValue + "px";
140
+ } else {
141
+ el.height = el.clientHeight;
142
+ }
143
+ //el.getContext().setCoordsize_()
144
+ return el;
145
+ }
146
+ };
147
+
148
+ function onPropertyChange(e) {
149
+ var el = e.srcElement;
150
+
151
+ switch (e.propertyName) {
152
+ case 'width':
153
+ el.style.width = el.attributes.width.nodeValue + "px";
154
+ el.getContext().clearRect();
155
+ break;
156
+ case 'height':
157
+ el.style.height = el.attributes.height.nodeValue + "px";
158
+ el.getContext().clearRect();
159
+ break;
160
+ }
161
+ }
162
+
163
+ function onResize(e) {
164
+ var el = e.srcElement;
165
+ if (el.firstChild) {
166
+ el.firstChild.style.width = el.clientWidth + 'px';
167
+ el.firstChild.style.height = el.clientHeight + 'px';
168
+ }
169
+ }
170
+
171
+ G_vmlCanvasManager_.init();
172
+
173
+ // precompute "00" to "FF"
174
+ var dec2hex = [];
175
+ for (var i = 0; i < 16; i++) {
176
+ for (var j = 0; j < 16; j++) {
177
+ dec2hex[i * 16 + j] = i.toString(16) + j.toString(16);
178
+ }
179
+ }
180
+
181
+ function createMatrixIdentity() {
182
+ return [
183
+ [1, 0, 0],
184
+ [0, 1, 0],
185
+ [0, 0, 1]
186
+ ];
187
+ }
188
+
189
+ function matrixMultiply(m1, m2) {
190
+ var result = createMatrixIdentity();
191
+
192
+ for (var x = 0; x < 3; x++) {
193
+ for (var y = 0; y < 3; y++) {
194
+ var sum = 0;
195
+
196
+ for (var z = 0; z < 3; z++) {
197
+ sum += m1[x][z] * m2[z][y];
198
+ }
199
+
200
+ result[x][y] = sum;
201
+ }
202
+ }
203
+ return result;
204
+ }
205
+
206
+ function copyState(o1, o2) {
207
+ o2.fillStyle = o1.fillStyle;
208
+ o2.lineCap = o1.lineCap;
209
+ o2.lineJoin = o1.lineJoin;
210
+ o2.lineWidth = o1.lineWidth;
211
+ o2.miterLimit = o1.miterLimit;
212
+ o2.shadowBlur = o1.shadowBlur;
213
+ o2.shadowColor = o1.shadowColor;
214
+ o2.shadowOffsetX = o1.shadowOffsetX;
215
+ o2.shadowOffsetY = o1.shadowOffsetY;
216
+ o2.strokeStyle = o1.strokeStyle;
217
+ o2.arcScaleX_ = o1.arcScaleX_;
218
+ o2.arcScaleY_ = o1.arcScaleY_;
219
+ }
220
+
221
+ function processStyle(styleString) {
222
+ var str, alpha = 1;
223
+
224
+ styleString = String(styleString);
225
+ if (styleString.substring(0, 3) == "rgb") {
226
+ var start = styleString.indexOf("(", 3);
227
+ var end = styleString.indexOf(")", start + 1);
228
+ var guts = styleString.substring(start + 1, end).split(",");
229
+
230
+ str = "#";
231
+ for (var i = 0; i < 3; i++) {
232
+ str += dec2hex[Number(guts[i])];
233
+ }
234
+
235
+ if ((guts.length == 4) && (styleString.substr(3, 1) == "a")) {
236
+ alpha = guts[3];
237
+ }
238
+ } else {
239
+ str = styleString;
240
+ }
241
+
242
+ return [str, alpha];
243
+ }
244
+
245
+ function processLineCap(lineCap) {
246
+ switch (lineCap) {
247
+ case "butt":
248
+ return "flat";
249
+ case "round":
250
+ return "round";
251
+ case "square":
252
+ default:
253
+ return "square";
254
+ }
255
+ }
256
+
257
+ /**
258
+ * This class implements CanvasRenderingContext2D interface as described by
259
+ * the WHATWG.
260
+ * @param {HTMLElement} surfaceElement The element that the 2D context should
261
+ * be associated with
262
+ */
263
+ function CanvasRenderingContext2D_(surfaceElement) {
264
+ this.m_ = createMatrixIdentity();
265
+
266
+ this.mStack_ = [];
267
+ this.aStack_ = [];
268
+ this.currentPath_ = [];
269
+
270
+ // Canvas context properties
271
+ this.strokeStyle = "#000";
272
+ this.fillStyle = "#000";
273
+
274
+ this.lineWidth = 1;
275
+ this.lineJoin = "miter";
276
+ this.lineCap = "butt";
277
+ this.miterLimit = Z * 1;
278
+ this.globalAlpha = 1;
279
+ this.canvas = surfaceElement;
280
+
281
+ var el = surfaceElement.ownerDocument.createElement('div');
282
+ el.style.width = surfaceElement.clientWidth + 'px';
283
+ el.style.height = surfaceElement.clientHeight + 'px';
284
+ el.style.overflow = 'hidden';
285
+ el.style.position = 'absolute';
286
+ surfaceElement.appendChild(el);
287
+
288
+ this.element_ = el;
289
+ this.arcScaleX_ = 1;
290
+ this.arcScaleY_ = 1;
291
+ };
292
+
293
+ var contextPrototype = CanvasRenderingContext2D_.prototype;
294
+ contextPrototype.clearRect = function() {
295
+ this.element_.innerHTML = "";
296
+ this.currentPath_ = [];
297
+ };
298
+
299
+ contextPrototype.beginPath = function() {
300
+ // TODO: Branch current matrix so that save/restore has no effect
301
+ // as per safari docs.
302
+
303
+ this.currentPath_ = [];
304
+ };
305
+
306
+ contextPrototype.moveTo = function(aX, aY) {
307
+ this.currentPath_.push({type: "moveTo", x: aX, y: aY});
308
+ this.currentX_ = aX;
309
+ this.currentY_ = aY;
310
+ };
311
+
312
+ contextPrototype.lineTo = function(aX, aY) {
313
+ this.currentPath_.push({type: "lineTo", x: aX, y: aY});
314
+ this.currentX_ = aX;
315
+ this.currentY_ = aY;
316
+ };
317
+
318
+ contextPrototype.bezierCurveTo = function(aCP1x, aCP1y,
319
+ aCP2x, aCP2y,
320
+ aX, aY) {
321
+ this.currentPath_.push({type: "bezierCurveTo",
322
+ cp1x: aCP1x,
323
+ cp1y: aCP1y,
324
+ cp2x: aCP2x,
325
+ cp2y: aCP2y,
326
+ x: aX,
327
+ y: aY});
328
+ this.currentX_ = aX;
329
+ this.currentY_ = aY;
330
+ };
331
+
332
+ contextPrototype.quadraticCurveTo = function(aCPx, aCPy, aX, aY) {
333
+ // the following is lifted almost directly from
334
+ // http://developer.mozilla.org/en/docs/Canvas_tutorial:Drawing_shapes
335
+ var cp1x = this.currentX_ + 2.0 / 3.0 * (aCPx - this.currentX_);
336
+ var cp1y = this.currentY_ + 2.0 / 3.0 * (aCPy - this.currentY_);
337
+ var cp2x = cp1x + (aX - this.currentX_) / 3.0;
338
+ var cp2y = cp1y + (aY - this.currentY_) / 3.0;
339
+ this.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, aX, aY);
340
+ };
341
+
342
+ contextPrototype.arc = function(aX, aY, aRadius,
343
+ aStartAngle, aEndAngle, aClockwise) {
344
+ aRadius *= Z;
345
+ var arcType = aClockwise ? "at" : "wa";
346
+
347
+ var xStart = aX + (mc(aStartAngle) * aRadius) - Z2;
348
+ var yStart = aY + (ms(aStartAngle) * aRadius) - Z2;
349
+
350
+ var xEnd = aX + (mc(aEndAngle) * aRadius) - Z2;
351
+ var yEnd = aY + (ms(aEndAngle) * aRadius) - Z2;
352
+
353
+ // IE won't render arches drawn counter clockwise if xStart == xEnd.
354
+ if (xStart == xEnd && !aClockwise) {
355
+ xStart += 0.125; // Offset xStart by 1/80 of a pixel. Use something
356
+ // that can be represented in binary
357
+ }
358
+
359
+ this.currentPath_.push({type: arcType,
360
+ x: aX,
361
+ y: aY,
362
+ radius: aRadius,
363
+ xStart: xStart,
364
+ yStart: yStart,
365
+ xEnd: xEnd,
366
+ yEnd: yEnd});
367
+
368
+ };
369
+
370
+ contextPrototype.rect = function(aX, aY, aWidth, aHeight) {
371
+ this.moveTo(aX, aY);
372
+ this.lineTo(aX + aWidth, aY);
373
+ this.lineTo(aX + aWidth, aY + aHeight);
374
+ this.lineTo(aX, aY + aHeight);
375
+ this.closePath();
376
+ };
377
+
378
+ contextPrototype.strokeRect = function(aX, aY, aWidth, aHeight) {
379
+ // Will destroy any existing path (same as FF behaviour)
380
+ this.beginPath();
381
+ this.moveTo(aX, aY);
382
+ this.lineTo(aX + aWidth, aY);
383
+ this.lineTo(aX + aWidth, aY + aHeight);
384
+ this.lineTo(aX, aY + aHeight);
385
+ this.closePath();
386
+ this.stroke();
387
+ };
388
+
389
+ contextPrototype.fillRect = function(aX, aY, aWidth, aHeight) {
390
+ // Will destroy any existing path (same as FF behaviour)
391
+ this.beginPath();
392
+ this.moveTo(aX, aY);
393
+ this.lineTo(aX + aWidth, aY);
394
+ this.lineTo(aX + aWidth, aY + aHeight);
395
+ this.lineTo(aX, aY + aHeight);
396
+ this.closePath();
397
+ this.fill();
398
+ };
399
+
400
+ contextPrototype.createLinearGradient = function(aX0, aY0, aX1, aY1) {
401
+ var gradient = new CanvasGradient_("gradient");
402
+ return gradient;
403
+ };
404
+
405
+ contextPrototype.createRadialGradient = function(aX0, aY0,
406
+ aR0, aX1,
407
+ aY1, aR1) {
408
+ var gradient = new CanvasGradient_("gradientradial");
409
+ gradient.radius1_ = aR0;
410
+ gradient.radius2_ = aR1;
411
+ gradient.focus_.x = aX0;
412
+ gradient.focus_.y = aY0;
413
+ return gradient;
414
+ };
415
+
416
+ contextPrototype.drawImage = function (image, var_args) {
417
+ var dx, dy, dw, dh, sx, sy, sw, sh;
418
+
419
+ // to find the original width we overide the width and height
420
+ var oldRuntimeWidth = image.runtimeStyle.width;
421
+ var oldRuntimeHeight = image.runtimeStyle.height;
422
+ image.runtimeStyle.width = 'auto';
423
+ image.runtimeStyle.height = 'auto';
424
+
425
+ // get the original size
426
+ var w = image.width;
427
+ var h = image.height;
428
+
429
+ // and remove overides
430
+ image.runtimeStyle.width = oldRuntimeWidth;
431
+ image.runtimeStyle.height = oldRuntimeHeight;
432
+
433
+ if (arguments.length == 3) {
434
+ dx = arguments[1];
435
+ dy = arguments[2];
436
+ sx = sy = 0;
437
+ sw = dw = w;
438
+ sh = dh = h;
439
+ } else if (arguments.length == 5) {
440
+ dx = arguments[1];
441
+ dy = arguments[2];
442
+ dw = arguments[3];
443
+ dh = arguments[4];
444
+ sx = sy = 0;
445
+ sw = w;
446
+ sh = h;
447
+ } else if (arguments.length == 9) {
448
+ sx = arguments[1];
449
+ sy = arguments[2];
450
+ sw = arguments[3];
451
+ sh = arguments[4];
452
+ dx = arguments[5];
453
+ dy = arguments[6];
454
+ dw = arguments[7];
455
+ dh = arguments[8];
456
+ } else {
457
+ throw "Invalid number of arguments";
458
+ }
459
+
460
+ var d = this.getCoords_(dx, dy);
461
+
462
+ var w2 = sw / 2;
463
+ var h2 = sh / 2;
464
+
465
+ var vmlStr = [];
466
+
467
+ var W = 10;
468
+ var H = 10;
469
+
470
+ // For some reason that I've now forgotten, using divs didn't work
471
+ vmlStr.push(' <g_vml_:group',
472
+ ' coordsize="', Z * W, ',', Z * H, '"',
473
+ ' coordorigin="0,0"' ,
474
+ ' style="width:', W, ';height:', H, ';position:absolute;');
475
+
476
+ // If filters are necessary (rotation exists), create them
477
+ // filters are bog-slow, so only create them if abbsolutely necessary
478
+ // The following check doesn't account for skews (which don't exist
479
+ // in the canvas spec (yet) anyway.
480
+
481
+ if (this.m_[0][0] != 1 || this.m_[0][1]) {
482
+ var filter = [];
483
+
484
+ // Note the 12/21 reversal
485
+ filter.push("M11='", this.m_[0][0], "',",
486
+ "M12='", this.m_[1][0], "',",
487
+ "M21='", this.m_[0][1], "',",
488
+ "M22='", this.m_[1][1], "',",
489
+ "Dx='", mr(d.x / Z), "',",
490
+ "Dy='", mr(d.y / Z), "'");
491
+
492
+ // Bounding box calculation (need to minimize displayed area so that
493
+ // filters don't waste time on unused pixels.
494
+ var max = d;
495
+ var c2 = this.getCoords_(dx + dw, dy);
496
+ var c3 = this.getCoords_(dx, dy + dh);
497
+ var c4 = this.getCoords_(dx + dw, dy + dh);
498
+
499
+ max.x = Math.max(max.x, c2.x, c3.x, c4.x);
500
+ max.y = Math.max(max.y, c2.y, c3.y, c4.y);
501
+
502
+ vmlStr.push("padding:0 ", mr(max.x / Z), "px ", mr(max.y / Z),
503
+ "px 0;filter:progid:DXImageTransform.Microsoft.Matrix(",
504
+ filter.join(""), ", sizingmethod='clip');")
505
+ } else {
506
+ vmlStr.push("top:", mr(d.y / Z), "px;left:", mr(d.x / Z), "px;")
507
+ }
508
+
509
+ vmlStr.push(' ">' ,
510
+ '<g_vml_:image src="', image.src, '"',
511
+ ' style="width:', Z * dw, ';',
512
+ ' height:', Z * dh, ';"',
513
+ ' cropleft="', sx / w, '"',
514
+ ' croptop="', sy / h, '"',
515
+ ' cropright="', (w - sx - sw) / w, '"',
516
+ ' cropbottom="', (h - sy - sh) / h, '"',
517
+ ' />',
518
+ '</g_vml_:group>');
519
+
520
+ this.element_.insertAdjacentHTML("BeforeEnd",
521
+ vmlStr.join(""));
522
+ };
523
+
524
+ contextPrototype.stroke = function(aFill) {
525
+ var lineStr = [];
526
+ var lineOpen = false;
527
+ var a = processStyle(aFill ? this.fillStyle : this.strokeStyle);
528
+ var color = a[0];
529
+ var opacity = a[1] * this.globalAlpha;
530
+
531
+ var W = 10;
532
+ var H = 10;
533
+
534
+ lineStr.push('<g_vml_:shape',
535
+ ' fillcolor="', color, '"',
536
+ ' filled="', Boolean(aFill), '"',
537
+ ' style="position:absolute;width:', W, ';height:', H, ';"',
538
+ ' coordorigin="0 0" coordsize="', Z * W, ' ', Z * H, '"',
539
+ ' stroked="', !aFill, '"',
540
+ ' strokeweight="', this.lineWidth, '"',
541
+ ' strokecolor="', color, '"',
542
+ ' path="');
543
+
544
+ var newSeq = false;
545
+ var min = {x: null, y: null};
546
+ var max = {x: null, y: null};
547
+
548
+ for (var i = 0; i < this.currentPath_.length; i++) {
549
+ var p = this.currentPath_[i];
550
+
551
+ if (p.type == "moveTo") {
552
+ lineStr.push(" m ");
553
+ var c = this.getCoords_(p.x, p.y);
554
+ lineStr.push(mr(c.x), ",", mr(c.y));
555
+ } else if (p.type == "lineTo") {
556
+ lineStr.push(" l ");
557
+ var c = this.getCoords_(p.x, p.y);
558
+ lineStr.push(mr(c.x), ",", mr(c.y));
559
+ } else if (p.type == "close") {
560
+ lineStr.push(" x ");
561
+ } else if (p.type == "bezierCurveTo") {
562
+ lineStr.push(" c ");
563
+ var c = this.getCoords_(p.x, p.y);
564
+ var c1 = this.getCoords_(p.cp1x, p.cp1y);
565
+ var c2 = this.getCoords_(p.cp2x, p.cp2y);
566
+ lineStr.push(mr(c1.x), ",", mr(c1.y), ",",
567
+ mr(c2.x), ",", mr(c2.y), ",",
568
+ mr(c.x), ",", mr(c.y));
569
+ } else if (p.type == "at" || p.type == "wa") {
570
+ lineStr.push(" ", p.type, " ");
571
+ var c = this.getCoords_(p.x, p.y);
572
+ var cStart = this.getCoords_(p.xStart, p.yStart);
573
+ var cEnd = this.getCoords_(p.xEnd, p.yEnd);
574
+
575
+ lineStr.push(mr(c.x - this.arcScaleX_ * p.radius), ",",
576
+ mr(c.y - this.arcScaleY_ * p.radius), " ",
577
+ mr(c.x + this.arcScaleX_ * p.radius), ",",
578
+ mr(c.y + this.arcScaleY_ * p.radius), " ",
579
+ mr(cStart.x), ",", mr(cStart.y), " ",
580
+ mr(cEnd.x), ",", mr(cEnd.y));
581
+ }
582
+
583
+
584
+ // TODO: Following is broken for curves due to
585
+ // move to proper paths.
586
+
587
+ // Figure out dimensions so we can do gradient fills
588
+ // properly
589
+ if(c) {
590
+ if (min.x == null || c.x < min.x) {
591
+ min.x = c.x;
592
+ }
593
+ if (max.x == null || c.x > max.x) {
594
+ max.x = c.x;
595
+ }
596
+ if (min.y == null || c.y < min.y) {
597
+ min.y = c.y;
598
+ }
599
+ if (max.y == null || c.y > max.y) {
600
+ max.y = c.y;
601
+ }
602
+ }
603
+ }
604
+ lineStr.push(' ">');
605
+
606
+ if (typeof this.fillStyle == "object") {
607
+ var focus = {x: "50%", y: "50%"};
608
+ var width = (max.x - min.x);
609
+ var height = (max.y - min.y);
610
+ var dimension = (width > height) ? width : height;
611
+
612
+ focus.x = mr((this.fillStyle.focus_.x / width) * 100 + 50) + "%";
613
+ focus.y = mr((this.fillStyle.focus_.y / height) * 100 + 50) + "%";
614
+
615
+ var colors = [];
616
+
617
+ // inside radius (%)
618
+ if (this.fillStyle.type_ == "gradientradial") {
619
+ var inside = (this.fillStyle.radius1_ / dimension * 100);
620
+
621
+ // percentage that outside radius exceeds inside radius
622
+ var expansion = (this.fillStyle.radius2_ / dimension * 100) - inside;
623
+ } else {
624
+ var inside = 0;
625
+ var expansion = 100;
626
+ }
627
+
628
+ var insidecolor = {offset: null, color: null};
629
+ var outsidecolor = {offset: null, color: null};
630
+
631
+ // We need to sort 'colors' by percentage, from 0 > 100 otherwise ie
632
+ // won't interpret it correctly
633
+ this.fillStyle.colors_.sort(function (cs1, cs2) {
634
+ return cs1.offset - cs2.offset;
635
+ });
636
+
637
+ for (var i = 0; i < this.fillStyle.colors_.length; i++) {
638
+ var fs = this.fillStyle.colors_[i];
639
+
640
+ colors.push( (fs.offset * expansion) + inside, "% ", fs.color, ",");
641
+
642
+ if (fs.offset > insidecolor.offset || insidecolor.offset == null) {
643
+ insidecolor.offset = fs.offset;
644
+ insidecolor.color = fs.color;
645
+ }
646
+
647
+ if (fs.offset < outsidecolor.offset || outsidecolor.offset == null) {
648
+ outsidecolor.offset = fs.offset;
649
+ outsidecolor.color = fs.color;
650
+ }
651
+ }
652
+ colors.pop();
653
+
654
+ lineStr.push('<g_vml_:fill',
655
+ ' color="', outsidecolor.color, '"',
656
+ ' color2="', insidecolor.color, '"',
657
+ ' type="', this.fillStyle.type_, '"',
658
+ ' focusposition="', focus.x, ', ', focus.y, '"',
659
+ ' colors="', colors.join(""), '"',
660
+ ' opacity="', opacity, '" />');
661
+ } else if (aFill) {
662
+ lineStr.push('<g_vml_:fill color="', color, '" opacity="', opacity, '" />');
663
+ } else {
664
+ lineStr.push(
665
+ '<g_vml_:stroke',
666
+ ' opacity="', opacity,'"',
667
+ ' joinstyle="', this.lineJoin, '"',
668
+ ' miterlimit="', this.miterLimit, '"',
669
+ ' endcap="', processLineCap(this.lineCap) ,'"',
670
+ ' weight="', this.lineWidth, 'px"',
671
+ ' color="', color,'" />'
672
+ );
673
+ }
674
+
675
+ lineStr.push("</g_vml_:shape>");
676
+
677
+ this.element_.insertAdjacentHTML("beforeEnd", lineStr.join(""));
678
+
679
+ this.currentPath_ = [];
680
+ };
681
+
682
+ contextPrototype.fill = function() {
683
+ this.stroke(true);
684
+ }
685
+
686
+ contextPrototype.closePath = function() {
687
+ this.currentPath_.push({type: "close"});
688
+ };
689
+
690
+ /**
691
+ * @private
692
+ */
693
+ contextPrototype.getCoords_ = function(aX, aY) {
694
+ return {
695
+ x: Z * (aX * this.m_[0][0] + aY * this.m_[1][0] + this.m_[2][0]) - Z2,
696
+ y: Z * (aX * this.m_[0][1] + aY * this.m_[1][1] + this.m_[2][1]) - Z2
697
+ }
698
+ };
699
+
700
+ contextPrototype.save = function() {
701
+ var o = {};
702
+ copyState(this, o);
703
+ this.aStack_.push(o);
704
+ this.mStack_.push(this.m_);
705
+ this.m_ = matrixMultiply(createMatrixIdentity(), this.m_);
706
+ };
707
+
708
+ contextPrototype.restore = function() {
709
+ copyState(this.aStack_.pop(), this);
710
+ this.m_ = this.mStack_.pop();
711
+ };
712
+
713
+ contextPrototype.translate = function(aX, aY) {
714
+ var m1 = [
715
+ [1, 0, 0],
716
+ [0, 1, 0],
717
+ [aX, aY, 1]
718
+ ];
719
+
720
+ this.m_ = matrixMultiply(m1, this.m_);
721
+ };
722
+
723
+ contextPrototype.rotate = function(aRot) {
724
+ var c = mc(aRot);
725
+ var s = ms(aRot);
726
+
727
+ var m1 = [
728
+ [c, s, 0],
729
+ [-s, c, 0],
730
+ [0, 0, 1]
731
+ ];
732
+
733
+ this.m_ = matrixMultiply(m1, this.m_);
734
+ };
735
+
736
+ contextPrototype.scale = function(aX, aY) {
737
+ this.arcScaleX_ *= aX;
738
+ this.arcScaleY_ *= aY;
739
+ var m1 = [
740
+ [aX, 0, 0],
741
+ [0, aY, 0],
742
+ [0, 0, 1]
743
+ ];
744
+
745
+ this.m_ = matrixMultiply(m1, this.m_);
746
+ };
747
+
748
+ /******** STUBS ********/
749
+ contextPrototype.clip = function() {
750
+ // TODO: Implement
751
+ };
752
+
753
+ contextPrototype.arcTo = function() {
754
+ // TODO: Implement
755
+ };
756
+
757
+ contextPrototype.createPattern = function() {
758
+ return new CanvasPattern_;
759
+ };
760
+
761
+ // Gradient / Pattern Stubs
762
+ function CanvasGradient_(aType) {
763
+ this.type_ = aType;
764
+ this.radius1_ = 0;
765
+ this.radius2_ = 0;
766
+ this.colors_ = [];
767
+ this.focus_ = {x: 0, y: 0};
768
+ }
769
+
770
+ CanvasGradient_.prototype.addColorStop = function(aOffset, aColor) {
771
+ aColor = processStyle(aColor);
772
+ this.colors_.push({offset: 1-aOffset, color: aColor});
773
+ };
774
+
775
+ function CanvasPattern_() {}
776
+
777
+ // set up externs
778
+ G_vmlCanvasManager = G_vmlCanvasManager_;
779
+ CanvasRenderingContext2D = CanvasRenderingContext2D_;
780
+ CanvasGradient = CanvasGradient_;
781
+ CanvasPattern = CanvasPattern_;
782
+
783
+ })();
784
+
785
+ } // if