]> git.proxmox.com Git - extjs.git/blame - extjs/classic/classic/src/sparkline/VmlCanvas.js
add extjs 6.0.1 sources
[extjs.git] / extjs / classic / classic / src / sparkline / VmlCanvas.js
CommitLineData
6527f429
DM
1/**\r
2 * @private\r
3 */\r
4Ext.define('Ext.sparkline.VmlCanvas', {\r
5 extend: 'Ext.sparkline.CanvasBase',\r
6\r
7 setWidth: function(width) {\r
8 var me = this;\r
9\r
10 me.callParent(arguments);\r
11 me.owner.groupEl.dom.coordsize = me.width + ' ' + (me.height || 0);\r
12 me.owner.groupEl.dom.style.width = width + 'px';\r
13 },\r
14\r
15 setHeight: function(height) {\r
16 var me = this;\r
17\r
18 me.callParent(arguments);\r
19 me.owner.groupEl.dom.coordsize = (me.width || 0) + ' ' + me.height;\r
20 me.owner.groupEl.dom.style.height = height + 'px';\r
21 },\r
22\r
23 onOwnerUpdate: function () {\r
24 var me = this;\r
25\r
26 me.group = me.owner.groupEl;\r
27 me.el = me.owner.element;\r
28 me.prerender = [];\r
29 },\r
30\r
31 _drawShape: function (shapeid, path, lineColor, fillColor, lineWidth) {\r
32 var vpath = [],\r
33 initial, stroke, fill, closed, plen, i;\r
34\r
35 for (i = 0, plen = path.length; i < plen; i++) {\r
36 vpath[i] = (path[i][0]) + ',' + (path[i][1]);\r
37 }\r
38 initial = vpath.splice(0, 1);\r
39 lineWidth = lineWidth == null ? 1 : lineWidth;\r
40 stroke = lineColor == null ? ' stroked="false" ' : ' strokeWeight="' + lineWidth + 'px" strokeColor="' + lineColor + '" ';\r
41 fill = fillColor == null ? ' filled="false"' : ' fillColor="' + fillColor + '" filled="true" ';\r
42 closed = vpath[0] === vpath[vpath.length - 1] ? 'x ' : '';\r
43 return ['<svml:shape coordorigin="0 0" coordsize="', this.pixelWidth, ' ', this.pixelHeight,\r
44 '" id="jqsshape', shapeid, '" ',\r
45 stroke,\r
46 fill,\r
47 ' style="position:absolute;height:', this.pixelHeight, 'px;width:', this.pixelWidth, 'px" ',\r
48 ' path="m ', initial, ' l ', vpath.join(', '), ' ', closed, 'e"></svml:shape>'\r
49 ].join('');\r
50 },\r
51\r
52 _drawCircle: function (shapeid, x, y, radius, lineColor, fillColor, lineWidth) {\r
53 var circumference = radius * 2,\r
54 stroke, fill;\r
55\r
56 x -= radius;\r
57 y -= radius;\r
58 stroke = lineColor == null ? ' stroked="false" ' : ' strokeWeight="' + lineWidth + 'px" strokeColor="' + lineColor + '" ';\r
59 fill = fillColor == null ? ' filled="false"' : ' fillColor="' + fillColor + '" filled="true" ';\r
60 return ['<svml:oval id="jqsshape', shapeid, '" ',\r
61 stroke,\r
62 fill,\r
63 ' style="position:absolute;top:', y, 'px; left:', x, 'px;width:', circumference, 'px;height:', circumference, 'px"></svml:oval>'\r
64 ].join('');\r
65 },\r
66\r
67 _drawPieSlice: function (shapeid, x, y, radius, startAngle, endAngle, lineColor, fillColor) {\r
68 var vpath,\r
69 width = this.pixelWidth,\r
70 height = this.pixelHeight,\r
71 startx,\r
72 starty,\r
73 endx,\r
74 endy,\r
75 stroke = lineColor == null ? ' stroked="false" ' : ' strokeWeight="1px" strokeColor="' + lineColor + '" ',\r
76 fill = fillColor == null ? ' filled="false"' : ' fillColor="' + fillColor + '" filled="true" ';\r
77\r
78 // VML cannot handle start & end angle the same.\r
79 if (startAngle === endAngle) {\r
80 return '';\r
81 }\r
82 if ((endAngle - startAngle) === (2 * Math.PI)) {\r
83 startAngle = 0.0; // VML seems to have a problem when drawing a full circle that doesn't start 0\r
84 endAngle = (2 * Math.PI);\r
85 }\r
86\r
87 startx = x + Math.round(Math.cos(startAngle) * radius);\r
88 starty = y + Math.round(Math.sin(startAngle) * radius);\r
89 endx = x + Math.round(Math.cos(endAngle) * radius);\r
90 endy = y + Math.round(Math.sin(endAngle) * radius);\r
91\r
92 if (startx === endx && starty === endy) {\r
93 if ((endAngle - startAngle) < Math.PI) {\r
94 // Prevent very small slices from being mistaken as a whole pie\r
95 return '';\r
96 }\r
97 // essentially going to be the entire circle, so ignore startAngle\r
98 startx = endx = x + radius;\r
99 starty = endy = y;\r
100 }\r
101\r
102 if (startx === endx && starty === endy && (endAngle - startAngle) < Math.PI) {\r
103 return '';\r
104 }\r
105\r
106 vpath = [x - radius, y - radius, x + radius, y + radius, startx, starty, endx, endy];\r
107 return ['<svml:shape coordorigin="0 0" coordsize="', width, ' ', height,\r
108 '" id="jqsshape', shapeid, '" ',\r
109 stroke,\r
110 fill,\r
111 ' style="position:absolute;height:', height, 'px;width:', width,\r
112 'px" path="m ', x, ',', y, ' wa ', vpath.join(', '), ' x e"></svml:shape>'\r
113 ].join('');\r
114 },\r
115\r
116 _drawRect: function (shapeid, x, y, width, height, lineColor, fillColor) {\r
117 return this._drawShape(shapeid, [[x, y], [x, y + height], [x + width, y + height], [x + width, y], [x, y]], lineColor, fillColor);\r
118 },\r
119\r
120 reset: function () {\r
121 Ext.fly(this.group).empty();\r
122 },\r
123\r
124 appendShape: function (shape) {\r
125 this.prerender.push(this['_draw' + shape.type].apply(this, shape.args));\r
126 this.lastShapeId = shape.id;\r
127 return shape.id;\r
128 },\r
129\r
130 replaceWithShape: function (shapeid, shape) {\r
131 var existing = this.el.getById('jqsshape' + shapeid, true),\r
132 vel = this['_draw' + shape.type].apply(this, shape.args);\r
133\r
134 existing.outerHTML = vel;\r
135 },\r
136\r
137 replaceWithShapes: function (shapeids, shapes) {\r
138 // replace the first shapeid with all the new shapes then toast the remaining old shapes\r
139 var existing = this.el.getById('jqsshape' + shapeids[0], true),\r
140 replace = '',\r
141 slen = shapes.length,\r
142 i;\r
143\r
144 for (i = 0; i < slen; i++) {\r
145 replace += this['_draw' + shapes[i].type].apply(this, shapes[i].args);\r
146 }\r
147 existing.outerHTML = replace;\r
148 for (i = 1; i < shapeids.length; i++) {\r
149 this.el.getById('jqsshape' + shapeids[i]).destroy();\r
150 }\r
151 },\r
152\r
153 insertAfterShape: function (shapeid, shape) {\r
154 var existing = this.el.getById('jqsshape' + shapeid, true),\r
155 vel = this['_draw' + shape.type].apply(this, shape.args);\r
156 existing.insertAdjacentHTML('afterEnd', vel);\r
157 },\r
158\r
159 removeShapeId: function (shapeid) {\r
160 var existing = this.el.getById('jqsshape' + shapeid, true);\r
161 this.group.removeChild(existing);\r
162 },\r
163\r
164 getShapeAt: function (x, y) {\r
165 var shapeid = this.el.id.substr(8);\r
166 return shapeid;\r
167 },\r
168\r
169 render: function () {\r
170 this.group.dom.innerHTML = this.prerender.join('');\r
171 }\r
172}, function() {\r
173 Ext.onInternalReady(function() {\r
174 var doc = document;\r
175 \r
176 if (doc.namespaces && !doc.namespaces.svml) {\r
177 doc.namespaces.add("svml", "urn:schemas-microsoft-com:vml", '#default#VML');\r
178 }\r
179 });\r
180});\r