tree_view 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +51 -0
- data/Rakefile +1 -0
- data/lib/assets/.DS_Store +0 -0
- data/lib/assets/javascripts/.DS_Store +0 -0
- data/lib/assets/javascripts/jquery.dimensions.min.js +12 -0
- data/lib/assets/javascripts/jquery.drawinglibrary.js +2208 -0
- data/lib/assets/javascripts/jquery.svg.min.js +7 -0
- data/lib/assets/javascripts/tree_view.drawline.js +49 -0
- data/lib/assets/stylesheets/.DS_Store +0 -0
- data/lib/assets/stylesheets/tree_view.sass +74 -0
- data/lib/generators/tree_view/install/install_generator.rb +20 -0
- data/lib/tree_view/version.rb +3 -0
- data/lib/tree_view/view_helpers/action_view.rb +53 -0
- data/lib/tree_view.rb +5 -0
- data/tree_view.gemspec +24 -0
- metadata +73 -0
@@ -0,0 +1,2208 @@
|
|
1
|
+
var supportsvg = detectSVG();
|
2
|
+
/*if ( !results.support && results.builtin )
|
3
|
+
alert( "You need to enable SVG support first!" );
|
4
|
+
else if ( !results.support )
|
5
|
+
alert( "You need a browser with SVG support" );
|
6
|
+
else if ( results.native == "Opera" && results.builtinVersion < 9 )
|
7
|
+
alert( "Opera 8 is not compatible with this program.. please upgrade Opera to at least version 9" );
|
8
|
+
else if ( results.support == "Plugin" && !results.IID )
|
9
|
+
alert( "Please disable the " + results.plugin + " SVG plugin as it is not compatible with this software for this browser" );
|
10
|
+
else alert( "Success! Starting the application.." );
|
11
|
+
*/
|
12
|
+
|
13
|
+
|
14
|
+
//explorercanvas, patch for canvas on ie (http://code.google.com/p/explorercanvas/)
|
15
|
+
if (/*(!window.CanvasRenderingContext2D) && */(jQuery.browser.msie)){
|
16
|
+
|
17
|
+
if(!window.CanvasRenderingContext2D)
|
18
|
+
{(function () {
|
19
|
+
|
20
|
+
// alias some functions to make (compiled) code shorter
|
21
|
+
var m = Math;
|
22
|
+
var mr = m.round;
|
23
|
+
var ms = m.sin;
|
24
|
+
var mc = m.cos;
|
25
|
+
|
26
|
+
// this is used for sub pixel precision
|
27
|
+
var Z = 10;
|
28
|
+
var Z2 = Z / 2;
|
29
|
+
|
30
|
+
var G_vmlCanvasManager_ = {
|
31
|
+
init: function (opt_doc) {
|
32
|
+
var doc = opt_doc || document;
|
33
|
+
if (/MSIE/.test(navigator.userAgent) && !window.opera) {
|
34
|
+
var self = this;
|
35
|
+
doc.attachEvent("onreadystatechange", function () {
|
36
|
+
self.init_(doc);
|
37
|
+
});
|
38
|
+
}
|
39
|
+
},
|
40
|
+
|
41
|
+
init_: function (doc) {
|
42
|
+
if (doc.readyState == "complete") {
|
43
|
+
// create xmlns
|
44
|
+
if (!doc.namespaces["g_vml_"]) {
|
45
|
+
doc.namespaces.add("g_vml_", "urn:schemas-microsoft-com:vml");
|
46
|
+
}
|
47
|
+
|
48
|
+
// setup default css
|
49
|
+
var ss = doc.createStyleSheet();
|
50
|
+
ss.cssText = "canvas{display:inline-block;overflow:hidden;" +
|
51
|
+
// default size is 300x150 in Gecko and Opera
|
52
|
+
"text-align:left;width:300px;height:150px}" +
|
53
|
+
"g_vml_\\:*{behavior:url(#default#VML)}";
|
54
|
+
|
55
|
+
// find all canvas elements
|
56
|
+
var listedivs = $(".canvas").get();
|
57
|
+
for (var i = 0; i < listedivs.length; i++) {
|
58
|
+
var newNode = document.createElement("canvas");
|
59
|
+
newNode.style.width = $(listedivs[i]).css('width');
|
60
|
+
newNode.style.height = $(listedivs[i]).css('height');
|
61
|
+
listedivs[i].appendChild(newNode);
|
62
|
+
}
|
63
|
+
|
64
|
+
var els = $(".canvas").find("canvas").get();
|
65
|
+
for (var i = 0; i < els.length; i++) {
|
66
|
+
|
67
|
+
|
68
|
+
if (!els[i].getContext) {
|
69
|
+
this.initElement(els[i]);
|
70
|
+
}
|
71
|
+
}
|
72
|
+
}
|
73
|
+
},
|
74
|
+
|
75
|
+
fixElement_: function (el) {
|
76
|
+
// in IE before version 5.5 we would need to add HTML: to the tag name
|
77
|
+
// but we do not care about IE before version 6
|
78
|
+
var outerHTML = el.outerHTML;
|
79
|
+
|
80
|
+
var newEl = el.ownerDocument.createElement(outerHTML);
|
81
|
+
// if the tag is still open IE has created the children as siblings and
|
82
|
+
// it has also created a tag with the name "/FOO"
|
83
|
+
if (outerHTML.slice(-2) != "/>") {
|
84
|
+
var tagName = "/" + el.tagName;
|
85
|
+
var ns;
|
86
|
+
// remove content
|
87
|
+
while ((ns = el.nextSibling) && ns.tagName != tagName) {
|
88
|
+
ns.removeNode();
|
89
|
+
}
|
90
|
+
// remove the incorrect closing tag
|
91
|
+
if (ns) {
|
92
|
+
ns.removeNode();
|
93
|
+
}
|
94
|
+
}
|
95
|
+
el.parentNode.replaceChild(newEl, el);
|
96
|
+
return newEl;
|
97
|
+
},
|
98
|
+
|
99
|
+
/**
|
100
|
+
* Public initializes a canvas element so that it can be used as canvas
|
101
|
+
* element from now on. This is called automatically before the page is
|
102
|
+
* loaded but if you are creating elements using createElement you need to
|
103
|
+
* make sure this is called on the element.
|
104
|
+
* @param {HTMLElement} el The canvas element to initialize.
|
105
|
+
* @return {HTMLElement} the element that was created.
|
106
|
+
*/
|
107
|
+
initElement: function (el) {
|
108
|
+
el = this.fixElement_(el);
|
109
|
+
el.getContext = function () {
|
110
|
+
if (this.context_) {
|
111
|
+
return this.context_;
|
112
|
+
}
|
113
|
+
return this.context_ = new CanvasRenderingContext2D_(this);
|
114
|
+
};
|
115
|
+
|
116
|
+
// do not use inline function because that will leak memory
|
117
|
+
el.attachEvent('onpropertychange', onPropertyChange);
|
118
|
+
el.attachEvent('onresize', onResize);
|
119
|
+
|
120
|
+
var attrs = el.attributes;
|
121
|
+
if (attrs.width && attrs.width.specified) {
|
122
|
+
// TODO: use runtimeStyle and coordsize
|
123
|
+
// el.getContext().setWidth_(attrs.width.nodeValue);
|
124
|
+
el.style.width = attrs.width.nodeValue + "px";
|
125
|
+
} else {
|
126
|
+
el.width = el.clientWidth;
|
127
|
+
}
|
128
|
+
if (attrs.height && attrs.height.specified) {
|
129
|
+
// TODO: use runtimeStyle and coordsize
|
130
|
+
// el.getContext().setHeight_(attrs.height.nodeValue);
|
131
|
+
el.style.height = attrs.height.nodeValue + "px";
|
132
|
+
} else {
|
133
|
+
el.height = el.clientHeight;
|
134
|
+
}
|
135
|
+
//el.getContext().setCoordsize_()
|
136
|
+
return el;
|
137
|
+
}
|
138
|
+
};
|
139
|
+
|
140
|
+
function onPropertyChange(e) {
|
141
|
+
var el = e.srcElement;
|
142
|
+
|
143
|
+
switch (e.propertyName) {
|
144
|
+
case 'width':
|
145
|
+
el.style.width = el.attributes.width.nodeValue + "px";
|
146
|
+
el.getContext().clearRect();
|
147
|
+
break;
|
148
|
+
case 'height':
|
149
|
+
el.style.height = el.attributes.height.nodeValue + "px";
|
150
|
+
el.getContext().clearRect();
|
151
|
+
break;
|
152
|
+
}
|
153
|
+
}
|
154
|
+
|
155
|
+
function onResize(e) {
|
156
|
+
var el = e.srcElement;
|
157
|
+
if (el.firstChild) {
|
158
|
+
el.firstChild.style.width = el.clientWidth + 'px';
|
159
|
+
el.firstChild.style.height = el.clientHeight + 'px';
|
160
|
+
}
|
161
|
+
}
|
162
|
+
|
163
|
+
G_vmlCanvasManager_.init();
|
164
|
+
|
165
|
+
// precompute "00" to "FF"
|
166
|
+
var dec2hex = [];
|
167
|
+
for (var i = 0; i < 16; i++) {
|
168
|
+
for (var j = 0; j < 16; j++) {
|
169
|
+
dec2hex[i * 16 + j] = i.toString(16) + j.toString(16);
|
170
|
+
}
|
171
|
+
}
|
172
|
+
|
173
|
+
function createMatrixIdentity() {
|
174
|
+
return [
|
175
|
+
[1, 0, 0],
|
176
|
+
[0, 1, 0],
|
177
|
+
[0, 0, 1]
|
178
|
+
];
|
179
|
+
}
|
180
|
+
|
181
|
+
function matrixMultiply(m1, m2) {
|
182
|
+
var result = createMatrixIdentity();
|
183
|
+
|
184
|
+
for (var x = 0; x < 3; x++) {
|
185
|
+
for (var y = 0; y < 3; y++) {
|
186
|
+
var sum = 0;
|
187
|
+
|
188
|
+
for (var z = 0; z < 3; z++) {
|
189
|
+
sum += m1[x][z] * m2[z][y];
|
190
|
+
}
|
191
|
+
|
192
|
+
result[x][y] = sum;
|
193
|
+
}
|
194
|
+
}
|
195
|
+
return result;
|
196
|
+
}
|
197
|
+
|
198
|
+
function copyState(o1, o2) {
|
199
|
+
o2.fillStyle = o1.fillStyle;
|
200
|
+
o2.lineCap = o1.lineCap;
|
201
|
+
o2.lineJoin = o1.lineJoin;
|
202
|
+
o2.lineWidth = o1.lineWidth;
|
203
|
+
o2.miterLimit = o1.miterLimit;
|
204
|
+
o2.shadowBlur = o1.shadowBlur;
|
205
|
+
o2.shadowColor = o1.shadowColor;
|
206
|
+
o2.shadowOffsetX = o1.shadowOffsetX;
|
207
|
+
o2.shadowOffsetY = o1.shadowOffsetY;
|
208
|
+
o2.strokeStyle = o1.strokeStyle;
|
209
|
+
o2.arcScaleX_ = o1.arcScaleX_;
|
210
|
+
o2.arcScaleY_ = o1.arcScaleY_;
|
211
|
+
}
|
212
|
+
|
213
|
+
function processStyle(styleString) {
|
214
|
+
var str, alpha = 1;
|
215
|
+
|
216
|
+
styleString = String(styleString);
|
217
|
+
if (styleString.substring(0, 3) == "rgb") {
|
218
|
+
var start = styleString.indexOf("(", 3);
|
219
|
+
var end = styleString.indexOf(")", start + 1);
|
220
|
+
var guts = styleString.substring(start + 1, end).split(",");
|
221
|
+
|
222
|
+
str = "#";
|
223
|
+
for (var i = 0; i < 3; i++) {
|
224
|
+
str += dec2hex[Number(guts[i])];
|
225
|
+
}
|
226
|
+
|
227
|
+
if ((guts.length == 4) && (styleString.substr(3, 1) == "a")) {
|
228
|
+
alpha = guts[3];
|
229
|
+
}
|
230
|
+
} else {
|
231
|
+
str = styleString;
|
232
|
+
}
|
233
|
+
|
234
|
+
return [str, alpha];
|
235
|
+
}
|
236
|
+
|
237
|
+
function processLineCap(lineCap) {
|
238
|
+
switch (lineCap) {
|
239
|
+
case "butt":
|
240
|
+
return "flat";
|
241
|
+
case "round":
|
242
|
+
return "round";
|
243
|
+
case "square":
|
244
|
+
default:
|
245
|
+
return "square";
|
246
|
+
}
|
247
|
+
}
|
248
|
+
|
249
|
+
/**
|
250
|
+
* This class implements CanvasRenderingContext2D interface as described by
|
251
|
+
* the WHATWG.
|
252
|
+
* @param {HTMLElement} surfaceElement The element that the 2D context should
|
253
|
+
* be associated with
|
254
|
+
*/
|
255
|
+
function CanvasRenderingContext2D_(surfaceElement) {
|
256
|
+
this.m_ = createMatrixIdentity();
|
257
|
+
|
258
|
+
this.mStack_ = [];
|
259
|
+
this.aStack_ = [];
|
260
|
+
this.currentPath_ = [];
|
261
|
+
|
262
|
+
// Canvas context properties
|
263
|
+
this.strokeStyle = "#000";
|
264
|
+
this.fillStyle = "#000";
|
265
|
+
|
266
|
+
this.lineWidth = 1;
|
267
|
+
this.lineJoin = "miter";
|
268
|
+
this.lineCap = "butt";
|
269
|
+
this.miterLimit = Z * 1;
|
270
|
+
this.globalAlpha = 1;
|
271
|
+
this.canvas = surfaceElement;
|
272
|
+
|
273
|
+
var el = surfaceElement.ownerDocument.createElement('div');
|
274
|
+
el.style.width = surfaceElement.clientWidth + 'px';
|
275
|
+
el.style.height = surfaceElement.clientHeight + 'px';
|
276
|
+
el.style.overflow = 'hidden';
|
277
|
+
el.style.position = 'absolute';
|
278
|
+
surfaceElement.appendChild(el);
|
279
|
+
|
280
|
+
this.element_ = el;
|
281
|
+
this.arcScaleX_ = 1;
|
282
|
+
this.arcScaleY_ = 1;
|
283
|
+
};
|
284
|
+
|
285
|
+
var contextPrototype = CanvasRenderingContext2D_.prototype;
|
286
|
+
contextPrototype.clearRect = function() {
|
287
|
+
this.element_.innerHTML = "";
|
288
|
+
this.currentPath_ = [];
|
289
|
+
};
|
290
|
+
|
291
|
+
contextPrototype.beginPath = function() {
|
292
|
+
// TODO: Branch current matrix so that save/restore has no effect
|
293
|
+
// as per safari docs.
|
294
|
+
|
295
|
+
this.currentPath_ = [];
|
296
|
+
};
|
297
|
+
|
298
|
+
contextPrototype.moveTo = function(aX, aY) {
|
299
|
+
this.currentPath_.push({type: "moveTo", x: aX, y: aY});
|
300
|
+
this.currentX_ = aX;
|
301
|
+
this.currentY_ = aY;
|
302
|
+
};
|
303
|
+
|
304
|
+
contextPrototype.lineTo = function(aX, aY) {
|
305
|
+
this.currentPath_.push({type: "lineTo", x: aX, y: aY});
|
306
|
+
this.currentX_ = aX;
|
307
|
+
this.currentY_ = aY;
|
308
|
+
};
|
309
|
+
|
310
|
+
contextPrototype.bezierCurveTo = function(aCP1x, aCP1y,
|
311
|
+
aCP2x, aCP2y,
|
312
|
+
aX, aY) {
|
313
|
+
this.currentPath_.push({type: "bezierCurveTo",
|
314
|
+
cp1x: aCP1x,
|
315
|
+
cp1y: aCP1y,
|
316
|
+
cp2x: aCP2x,
|
317
|
+
cp2y: aCP2y,
|
318
|
+
x: aX,
|
319
|
+
y: aY});
|
320
|
+
this.currentX_ = aX;
|
321
|
+
this.currentY_ = aY;
|
322
|
+
};
|
323
|
+
|
324
|
+
contextPrototype.quadraticCurveTo = function(aCPx, aCPy, aX, aY) {
|
325
|
+
// the following is lifted almost directly from
|
326
|
+
// http://developer.mozilla.org/en/docs/Canvas_tutorial:Drawing_shapes
|
327
|
+
var cp1x = this.currentX_ + 2.0 / 3.0 * (aCPx - this.currentX_);
|
328
|
+
var cp1y = this.currentY_ + 2.0 / 3.0 * (aCPy - this.currentY_);
|
329
|
+
var cp2x = cp1x + (aX - this.currentX_) / 3.0;
|
330
|
+
var cp2y = cp1y + (aY - this.currentY_) / 3.0;
|
331
|
+
this.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, aX, aY);
|
332
|
+
};
|
333
|
+
|
334
|
+
contextPrototype.arc = function(aX, aY, aRadius,
|
335
|
+
aStartAngle, aEndAngle, aClockwise) {
|
336
|
+
aRadius *= Z;
|
337
|
+
var arcType = aClockwise ? "at" : "wa";
|
338
|
+
|
339
|
+
var xStart = aX + (mc(aStartAngle) * aRadius) - Z2;
|
340
|
+
var yStart = aY + (ms(aStartAngle) * aRadius) - Z2;
|
341
|
+
|
342
|
+
var xEnd = aX + (mc(aEndAngle) * aRadius) - Z2;
|
343
|
+
var yEnd = aY + (ms(aEndAngle) * aRadius) - Z2;
|
344
|
+
|
345
|
+
// IE won't render arches drawn counter clockwise if xStart == xEnd.
|
346
|
+
if (xStart == xEnd && !aClockwise) {
|
347
|
+
xStart += 0.125; // Offset xStart by 1/80 of a pixel. Use something
|
348
|
+
// that can be represented in binary
|
349
|
+
}
|
350
|
+
|
351
|
+
this.currentPath_.push({type: arcType,
|
352
|
+
x: aX,
|
353
|
+
y: aY,
|
354
|
+
radius: aRadius,
|
355
|
+
xStart: xStart,
|
356
|
+
yStart: yStart,
|
357
|
+
xEnd: xEnd,
|
358
|
+
yEnd: yEnd});
|
359
|
+
|
360
|
+
};
|
361
|
+
|
362
|
+
contextPrototype.rect = function(aX, aY, aWidth, aHeight) {
|
363
|
+
this.moveTo(aX, aY);
|
364
|
+
this.lineTo(aX + aWidth, aY);
|
365
|
+
this.lineTo(aX + aWidth, aY + aHeight);
|
366
|
+
this.lineTo(aX, aY + aHeight);
|
367
|
+
this.closePath();
|
368
|
+
};
|
369
|
+
|
370
|
+
contextPrototype.strokeRect = function(aX, aY, aWidth, aHeight) {
|
371
|
+
// Will destroy any existing path (same as FF behaviour)
|
372
|
+
this.beginPath();
|
373
|
+
this.moveTo(aX, aY);
|
374
|
+
this.lineTo(aX + aWidth, aY);
|
375
|
+
this.lineTo(aX + aWidth, aY + aHeight);
|
376
|
+
this.lineTo(aX, aY + aHeight);
|
377
|
+
this.closePath();
|
378
|
+
this.stroke();
|
379
|
+
};
|
380
|
+
|
381
|
+
contextPrototype.fillRect = function(aX, aY, aWidth, aHeight) {
|
382
|
+
// Will destroy any existing path (same as FF behaviour)
|
383
|
+
this.beginPath();
|
384
|
+
this.moveTo(aX, aY);
|
385
|
+
this.lineTo(aX + aWidth, aY);
|
386
|
+
this.lineTo(aX + aWidth, aY + aHeight);
|
387
|
+
this.lineTo(aX, aY + aHeight);
|
388
|
+
this.closePath();
|
389
|
+
this.fill();
|
390
|
+
};
|
391
|
+
|
392
|
+
contextPrototype.createLinearGradient = function(aX0, aY0, aX1, aY1) {
|
393
|
+
var gradient = new CanvasGradient_("gradient");
|
394
|
+
return gradient;
|
395
|
+
};
|
396
|
+
|
397
|
+
contextPrototype.createRadialGradient = function(aX0, aY0,
|
398
|
+
aR0, aX1,
|
399
|
+
aY1, aR1) {
|
400
|
+
var gradient = new CanvasGradient_("gradientradial");
|
401
|
+
gradient.radius1_ = aR0;
|
402
|
+
gradient.radius2_ = aR1;
|
403
|
+
gradient.focus_.x = aX0;
|
404
|
+
gradient.focus_.y = aY0;
|
405
|
+
return gradient;
|
406
|
+
};
|
407
|
+
|
408
|
+
contextPrototype.drawImage = function (image, var_args) {
|
409
|
+
var dx, dy, dw, dh, sx, sy, sw, sh;
|
410
|
+
|
411
|
+
// to find the original width we overide the width and height
|
412
|
+
var oldRuntimeWidth = image.runtimeStyle.width;
|
413
|
+
var oldRuntimeHeight = image.runtimeStyle.height;
|
414
|
+
image.runtimeStyle.width = 'auto';
|
415
|
+
image.runtimeStyle.height = 'auto';
|
416
|
+
|
417
|
+
// get the original size
|
418
|
+
var w = image.width;
|
419
|
+
var h = image.height;
|
420
|
+
|
421
|
+
// and remove overides
|
422
|
+
image.runtimeStyle.width = oldRuntimeWidth;
|
423
|
+
image.runtimeStyle.height = oldRuntimeHeight;
|
424
|
+
|
425
|
+
if (arguments.length == 3) {
|
426
|
+
dx = arguments[1];
|
427
|
+
dy = arguments[2];
|
428
|
+
sx = sy = 0;
|
429
|
+
sw = dw = w;
|
430
|
+
sh = dh = h;
|
431
|
+
} else if (arguments.length == 5) {
|
432
|
+
dx = arguments[1];
|
433
|
+
dy = arguments[2];
|
434
|
+
dw = arguments[3];
|
435
|
+
dh = arguments[4];
|
436
|
+
sx = sy = 0;
|
437
|
+
sw = w;
|
438
|
+
sh = h;
|
439
|
+
} else if (arguments.length == 9) {
|
440
|
+
sx = arguments[1];
|
441
|
+
sy = arguments[2];
|
442
|
+
sw = arguments[3];
|
443
|
+
sh = arguments[4];
|
444
|
+
dx = arguments[5];
|
445
|
+
dy = arguments[6];
|
446
|
+
dw = arguments[7];
|
447
|
+
dh = arguments[8];
|
448
|
+
} else {
|
449
|
+
throw "Invalid number of arguments";
|
450
|
+
}
|
451
|
+
|
452
|
+
var d = this.getCoords_(dx, dy);
|
453
|
+
|
454
|
+
var w2 = sw / 2;
|
455
|
+
var h2 = sh / 2;
|
456
|
+
|
457
|
+
var vmlStr = [];
|
458
|
+
|
459
|
+
var W = 10;
|
460
|
+
var H = 10;
|
461
|
+
|
462
|
+
// For some reason that I've now forgotten, using divs didn't work
|
463
|
+
vmlStr.push(' <g_vml_:group',
|
464
|
+
' coordsize="', Z * W, ',', Z * H, '"',
|
465
|
+
' coordorigin="0,0"' ,
|
466
|
+
' style="width:', W, ';height:', H, ';position:absolute;');
|
467
|
+
|
468
|
+
// If filters are necessary (rotation exists), create them
|
469
|
+
// filters are bog-slow, so only create them if abbsolutely necessary
|
470
|
+
// The following check doesn't account for skews (which don't exist
|
471
|
+
// in the canvas spec (yet) anyway.
|
472
|
+
|
473
|
+
if (this.m_[0][0] != 1 || this.m_[0][1]) {
|
474
|
+
var filter = [];
|
475
|
+
|
476
|
+
// Note the 12/21 reversal
|
477
|
+
filter.push("M11='", this.m_[0][0], "',",
|
478
|
+
"M12='", this.m_[1][0], "',",
|
479
|
+
"M21='", this.m_[0][1], "',",
|
480
|
+
"M22='", this.m_[1][1], "',",
|
481
|
+
"Dx='", mr(d.x / Z), "',",
|
482
|
+
"Dy='", mr(d.y / Z), "'");
|
483
|
+
|
484
|
+
// Bounding box calculation (need to minimize displayed area so that
|
485
|
+
// filters don't waste time on unused pixels.
|
486
|
+
var max = d;
|
487
|
+
var c2 = this.getCoords_(dx + dw, dy);
|
488
|
+
var c3 = this.getCoords_(dx, dy + dh);
|
489
|
+
var c4 = this.getCoords_(dx + dw, dy + dh);
|
490
|
+
|
491
|
+
max.x = Math.max(max.x, c2.x, c3.x, c4.x);
|
492
|
+
max.y = Math.max(max.y, c2.y, c3.y, c4.y);
|
493
|
+
|
494
|
+
vmlStr.push("padding:0 ", mr(max.x / Z), "px ", mr(max.y / Z),
|
495
|
+
"px 0;filter:progid:DXImageTransform.Microsoft.Matrix(",
|
496
|
+
filter.join(""), ", sizingmethod='clip');")
|
497
|
+
} else {
|
498
|
+
vmlStr.push("top:", mr(d.y / Z), "px;left:", mr(d.x / Z), "px;")
|
499
|
+
}
|
500
|
+
|
501
|
+
vmlStr.push(' ">' ,
|
502
|
+
'<g_vml_:image src="', image.src, '"',
|
503
|
+
' style="width:', Z * dw, ';',
|
504
|
+
' height:', Z * dh, ';"',
|
505
|
+
' cropleft="', sx / w, '"',
|
506
|
+
' croptop="', sy / h, '"',
|
507
|
+
' cropright="', (w - sx - sw) / w, '"',
|
508
|
+
' cropbottom="', (h - sy - sh) / h, '"',
|
509
|
+
' />',
|
510
|
+
'</g_vml_:group>');
|
511
|
+
|
512
|
+
this.element_.insertAdjacentHTML("BeforeEnd",
|
513
|
+
vmlStr.join(""));
|
514
|
+
};
|
515
|
+
|
516
|
+
contextPrototype.stroke = function(aFill) {
|
517
|
+
var lineStr = [];
|
518
|
+
var lineOpen = false;
|
519
|
+
var a = processStyle(aFill ? this.fillStyle : this.strokeStyle);
|
520
|
+
var color = a[0];
|
521
|
+
var opacity = a[1] * this.globalAlpha;
|
522
|
+
|
523
|
+
var W = 10;
|
524
|
+
var H = 10;
|
525
|
+
|
526
|
+
lineStr.push('<g_vml_:shape',
|
527
|
+
' fillcolor="', color, '"',
|
528
|
+
' filled="', Boolean(aFill), '"',
|
529
|
+
' style="position:absolute;width:', W, ';height:', H, ';"',
|
530
|
+
' coordorigin="0 0" coordsize="', Z * W, ' ', Z * H, '"',
|
531
|
+
' stroked="', !aFill, '"',
|
532
|
+
' strokeweight="', this.lineWidth, '"',
|
533
|
+
' strokecolor="', color, '"',
|
534
|
+
' path="');
|
535
|
+
|
536
|
+
var newSeq = false;
|
537
|
+
var min = {x: null, y: null};
|
538
|
+
var max = {x: null, y: null};
|
539
|
+
|
540
|
+
for (var i = 0; i < this.currentPath_.length; i++) {
|
541
|
+
var p = this.currentPath_[i];
|
542
|
+
|
543
|
+
if (p.type == "moveTo") {
|
544
|
+
lineStr.push(" m ");
|
545
|
+
var c = this.getCoords_(p.x, p.y);
|
546
|
+
lineStr.push(mr(c.x), ",", mr(c.y));
|
547
|
+
} else if (p.type == "lineTo") {
|
548
|
+
lineStr.push(" l ");
|
549
|
+
var c = this.getCoords_(p.x, p.y);
|
550
|
+
lineStr.push(mr(c.x), ",", mr(c.y));
|
551
|
+
} else if (p.type == "close") {
|
552
|
+
lineStr.push(" x ");
|
553
|
+
} else if (p.type == "bezierCurveTo") {
|
554
|
+
lineStr.push(" c ");
|
555
|
+
var c = this.getCoords_(p.x, p.y);
|
556
|
+
var c1 = this.getCoords_(p.cp1x, p.cp1y);
|
557
|
+
var c2 = this.getCoords_(p.cp2x, p.cp2y);
|
558
|
+
lineStr.push(mr(c1.x), ",", mr(c1.y), ",",
|
559
|
+
mr(c2.x), ",", mr(c2.y), ",",
|
560
|
+
mr(c.x), ",", mr(c.y));
|
561
|
+
} else if (p.type == "at" || p.type == "wa") {
|
562
|
+
lineStr.push(" ", p.type, " ");
|
563
|
+
var c = this.getCoords_(p.x, p.y);
|
564
|
+
var cStart = this.getCoords_(p.xStart, p.yStart);
|
565
|
+
var cEnd = this.getCoords_(p.xEnd, p.yEnd);
|
566
|
+
|
567
|
+
lineStr.push(mr(c.x - this.arcScaleX_ * p.radius), ",",
|
568
|
+
mr(c.y - this.arcScaleY_ * p.radius), " ",
|
569
|
+
mr(c.x + this.arcScaleX_ * p.radius), ",",
|
570
|
+
mr(c.y + this.arcScaleY_ * p.radius), " ",
|
571
|
+
mr(cStart.x), ",", mr(cStart.y), " ",
|
572
|
+
mr(cEnd.x), ",", mr(cEnd.y));
|
573
|
+
}
|
574
|
+
|
575
|
+
|
576
|
+
// TODO: Following is broken for curves due to
|
577
|
+
// move to proper paths.
|
578
|
+
|
579
|
+
// Figure out dimensions so we can do gradient fills
|
580
|
+
// properly
|
581
|
+
if(c) {
|
582
|
+
if (min.x == null || c.x < min.x) {
|
583
|
+
min.x = c.x;
|
584
|
+
}
|
585
|
+
if (max.x == null || c.x > max.x) {
|
586
|
+
max.x = c.x;
|
587
|
+
}
|
588
|
+
if (min.y == null || c.y < min.y) {
|
589
|
+
min.y = c.y;
|
590
|
+
}
|
591
|
+
if (max.y == null || c.y > max.y) {
|
592
|
+
max.y = c.y;
|
593
|
+
}
|
594
|
+
}
|
595
|
+
}
|
596
|
+
lineStr.push(' ">');
|
597
|
+
|
598
|
+
if (typeof this.fillStyle == "object") {
|
599
|
+
var focus = {x: "50%", y: "50%"};
|
600
|
+
var width = (max.x - min.x);
|
601
|
+
var height = (max.y - min.y);
|
602
|
+
var dimension = (width > height) ? width : height;
|
603
|
+
|
604
|
+
focus.x = mr((this.fillStyle.focus_.x / width) * 100 + 50) + "%";
|
605
|
+
focus.y = mr((this.fillStyle.focus_.y / height) * 100 + 50) + "%";
|
606
|
+
|
607
|
+
var colors = [];
|
608
|
+
|
609
|
+
// inside radius (%)
|
610
|
+
if (this.fillStyle.type_ == "gradientradial") {
|
611
|
+
var inside = (this.fillStyle.radius1_ / dimension * 100);
|
612
|
+
|
613
|
+
// percentage that outside radius exceeds inside radius
|
614
|
+
var expansion = (this.fillStyle.radius2_ / dimension * 100) - inside;
|
615
|
+
} else {
|
616
|
+
var inside = 0;
|
617
|
+
var expansion = 100;
|
618
|
+
}
|
619
|
+
|
620
|
+
var insidecolor = {offset: null, color: null};
|
621
|
+
var outsidecolor = {offset: null, color: null};
|
622
|
+
|
623
|
+
// We need to sort 'colors' by percentage, from 0 > 100 otherwise ie
|
624
|
+
// won't interpret it correctly
|
625
|
+
this.fillStyle.colors_.sort(function (cs1, cs2) {
|
626
|
+
return cs1.offset - cs2.offset;
|
627
|
+
});
|
628
|
+
|
629
|
+
for (var i = 0; i < this.fillStyle.colors_.length; i++) {
|
630
|
+
var fs = this.fillStyle.colors_[i];
|
631
|
+
|
632
|
+
colors.push( (fs.offset * expansion) + inside, "% ", fs.color, ",");
|
633
|
+
|
634
|
+
if (fs.offset > insidecolor.offset || insidecolor.offset == null) {
|
635
|
+
insidecolor.offset = fs.offset;
|
636
|
+
insidecolor.color = fs.color;
|
637
|
+
}
|
638
|
+
|
639
|
+
if (fs.offset < outsidecolor.offset || outsidecolor.offset == null) {
|
640
|
+
outsidecolor.offset = fs.offset;
|
641
|
+
outsidecolor.color = fs.color;
|
642
|
+
}
|
643
|
+
}
|
644
|
+
colors.pop();
|
645
|
+
|
646
|
+
lineStr.push('<g_vml_:fill',
|
647
|
+
' color="', outsidecolor.color, '"',
|
648
|
+
' color2="', insidecolor.color, '"',
|
649
|
+
' type="', this.fillStyle.type_, '"',
|
650
|
+
' focusposition="', focus.x, ', ', focus.y, '"',
|
651
|
+
' colors="', colors.join(""), '"',
|
652
|
+
' opacity="', opacity, '" />');
|
653
|
+
} else if (aFill) {
|
654
|
+
lineStr.push('<g_vml_:fill color="', color, '" opacity="', opacity, '" />');
|
655
|
+
} else {
|
656
|
+
lineStr.push(
|
657
|
+
'<g_vml_:stroke',
|
658
|
+
' opacity="', opacity,'"',
|
659
|
+
' joinstyle="', this.lineJoin, '"',
|
660
|
+
' miterlimit="', this.miterLimit, '"',
|
661
|
+
' endcap="', processLineCap(this.lineCap) ,'"',
|
662
|
+
' weight="', this.lineWidth, 'px"',
|
663
|
+
' color="', color,'" />'
|
664
|
+
);
|
665
|
+
}
|
666
|
+
|
667
|
+
lineStr.push("</g_vml_:shape>");
|
668
|
+
|
669
|
+
this.element_.insertAdjacentHTML("beforeEnd", lineStr.join(""));
|
670
|
+
|
671
|
+
this.currentPath_ = [];
|
672
|
+
};
|
673
|
+
|
674
|
+
contextPrototype.fill = function() {
|
675
|
+
this.stroke(true);
|
676
|
+
}
|
677
|
+
|
678
|
+
contextPrototype.closePath = function() {
|
679
|
+
this.currentPath_.push({type: "close"});
|
680
|
+
};
|
681
|
+
|
682
|
+
/**
|
683
|
+
* @private
|
684
|
+
*/
|
685
|
+
contextPrototype.getCoords_ = function(aX, aY) {
|
686
|
+
return {
|
687
|
+
x: Z * (aX * this.m_[0][0] + aY * this.m_[1][0] + this.m_[2][0]) - Z2,
|
688
|
+
y: Z * (aX * this.m_[0][1] + aY * this.m_[1][1] + this.m_[2][1]) - Z2
|
689
|
+
}
|
690
|
+
};
|
691
|
+
|
692
|
+
contextPrototype.save = function() {
|
693
|
+
var o = {};
|
694
|
+
copyState(this, o);
|
695
|
+
this.aStack_.push(o);
|
696
|
+
this.mStack_.push(this.m_);
|
697
|
+
this.m_ = matrixMultiply(createMatrixIdentity(), this.m_);
|
698
|
+
};
|
699
|
+
|
700
|
+
contextPrototype.restore = function() {
|
701
|
+
copyState(this.aStack_.pop(), this);
|
702
|
+
this.m_ = this.mStack_.pop();
|
703
|
+
};
|
704
|
+
|
705
|
+
contextPrototype.translate = function(aX, aY) {
|
706
|
+
var m1 = [
|
707
|
+
[1, 0, 0],
|
708
|
+
[0, 1, 0],
|
709
|
+
[aX, aY, 1]
|
710
|
+
];
|
711
|
+
|
712
|
+
this.m_ = matrixMultiply(m1, this.m_);
|
713
|
+
};
|
714
|
+
|
715
|
+
contextPrototype.rotate = function(aRot) {
|
716
|
+
var c = mc(aRot);
|
717
|
+
var s = ms(aRot);
|
718
|
+
|
719
|
+
var m1 = [
|
720
|
+
[c, s, 0],
|
721
|
+
[-s, c, 0],
|
722
|
+
[0, 0, 1]
|
723
|
+
];
|
724
|
+
|
725
|
+
this.m_ = matrixMultiply(m1, this.m_);
|
726
|
+
};
|
727
|
+
|
728
|
+
contextPrototype.scale = function(aX, aY) {
|
729
|
+
this.arcScaleX_ *= aX;
|
730
|
+
this.arcScaleY_ *= aY;
|
731
|
+
var m1 = [
|
732
|
+
[aX, 0, 0],
|
733
|
+
[0, aY, 0],
|
734
|
+
[0, 0, 1]
|
735
|
+
];
|
736
|
+
|
737
|
+
this.m_ = matrixMultiply(m1, this.m_);
|
738
|
+
};
|
739
|
+
|
740
|
+
/******** STUBS ********/
|
741
|
+
contextPrototype.clip = function() {
|
742
|
+
// TODO: Implement
|
743
|
+
};
|
744
|
+
|
745
|
+
contextPrototype.arcTo = function() {
|
746
|
+
// TODO: Implement
|
747
|
+
};
|
748
|
+
|
749
|
+
contextPrototype.createPattern = function() {
|
750
|
+
return new CanvasPattern_;
|
751
|
+
};
|
752
|
+
|
753
|
+
// Gradient / Pattern Stubs
|
754
|
+
function CanvasGradient_(aType) {
|
755
|
+
this.type_ = aType;
|
756
|
+
this.radius1_ = 0;
|
757
|
+
this.radius2_ = 0;
|
758
|
+
this.colors_ = [];
|
759
|
+
this.focus_ = {x: 0, y: 0};
|
760
|
+
}
|
761
|
+
|
762
|
+
CanvasGradient_.prototype.addColorStop = function(aOffset, aColor) {
|
763
|
+
aColor = processStyle(aColor);
|
764
|
+
this.colors_.push({offset: 1-aOffset, color: aColor});
|
765
|
+
};
|
766
|
+
|
767
|
+
function CanvasPattern_() {}
|
768
|
+
|
769
|
+
// set up externs
|
770
|
+
G_vmlCanvasManager = G_vmlCanvasManager_;
|
771
|
+
CanvasRenderingContext2D = CanvasRenderingContext2D_;
|
772
|
+
CanvasGradient = CanvasGradient_;
|
773
|
+
CanvasPattern = CanvasPattern_;
|
774
|
+
|
775
|
+
})();
|
776
|
+
}
|
777
|
+
}
|
778
|
+
|
779
|
+
|
780
|
+
|
781
|
+
|
782
|
+
|
783
|
+
|
784
|
+
|
785
|
+
/* this notice must be untouched at all times.
|
786
|
+
|
787
|
+
wz_jsgraphics.js v. 3.02
|
788
|
+
The latest version is available at
|
789
|
+
http://www.walterzorn.com
|
790
|
+
or http://www.devira.com
|
791
|
+
or http://www.walterzorn.de
|
792
|
+
|
793
|
+
***************************
|
794
|
+
Adaptation for jQuery, background, opacity and <canvas> use on compatibles browsers by :
|
795
|
+
Arnault Pachot - OpenStudio
|
796
|
+
http://www.openstudio.fr
|
797
|
+
***************************
|
798
|
+
|
799
|
+
Copyright (c) 2002-2004 Walter Zorn. All rights reserved.
|
800
|
+
Created 3. 11. 2002 by Walter Zorn (Web: http://www.walterzorn.com )
|
801
|
+
Last modified: 26. 10. 2007
|
802
|
+
|
803
|
+
Performance optimizations for Internet Explorer
|
804
|
+
by Thomas Frank and John Holdsworth.
|
805
|
+
fillPolygon method implemented by Matthieu Haller.
|
806
|
+
|
807
|
+
High Performance JavaScript Graphics Library.
|
808
|
+
Provides methods
|
809
|
+
- to draw lines, rectangles, ellipses, polygons
|
810
|
+
with specifiable line thickness,
|
811
|
+
- to fill rectangles, polygons, ellipses and arcs
|
812
|
+
- to draw text.
|
813
|
+
NOTE: Operations, functions and branching have rather been optimized
|
814
|
+
to efficiency and speed than to shortness of source code.
|
815
|
+
|
816
|
+
LICENSE: LGPL
|
817
|
+
|
818
|
+
$(this) library is free software; you can redistribute it and/or
|
819
|
+
modify it under the terms of the GNU Lesser General Public
|
820
|
+
License (LGPL) as published by the Free Software Foundation; either
|
821
|
+
version 2.1 of the License, or (at your option) any later version.
|
822
|
+
|
823
|
+
$(this) library is distributed in the hope that it will be useful,
|
824
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
825
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
826
|
+
Lesser General Public License for more details.
|
827
|
+
|
828
|
+
You should have received a copy of the GNU Lesser General Public
|
829
|
+
License along with $(this) library; if not, write to the Free Software
|
830
|
+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA,
|
831
|
+
or see http://www.gnu.org/copyleft/lesser.html
|
832
|
+
*/
|
833
|
+
|
834
|
+
(function($) {
|
835
|
+
$.fn._mkDiv = function(x, y, w, h, settings) {
|
836
|
+
$(this).append('<div style="position:absolute;'+
|
837
|
+
'left:' + (x) + 'px;'+
|
838
|
+
'top:' + (y) + 'px;'+
|
839
|
+
'width:' + w + 'px;'+
|
840
|
+
'height:' + h + 'px;'+
|
841
|
+
'margin: 0 0 0 0; padding: 0 0 0 0;clip:rect(0,'+w+'px,'+h+'px,0);'+
|
842
|
+
'opacity:' + settings.opacity +';'+
|
843
|
+
'background-color: ' + settings.color +';'+
|
844
|
+
'background-image: url(' + settings.backgroundImage +');'+
|
845
|
+
'background-position: '+(-(x-settings.xorigin))+'px '+(-(y-settings.yorigin))+'px'+
|
846
|
+
';"><\/div>');
|
847
|
+
|
848
|
+
}
|
849
|
+
|
850
|
+
$.fn._mkLin = function(x1, y1, x2, y2, settings) {
|
851
|
+
if(x1 > x2)
|
852
|
+
{
|
853
|
+
var _x2 = x2;
|
854
|
+
var _y2 = y2;
|
855
|
+
x2 = x1;
|
856
|
+
y2 = y1;
|
857
|
+
x1 = _x2;
|
858
|
+
y1 = _y2;
|
859
|
+
}
|
860
|
+
var dx = x2-x1, dy = Math.abs(y2-y1),
|
861
|
+
x = x1, y = y1,
|
862
|
+
yIncr = (y1 > y2)? -1 : 1;
|
863
|
+
|
864
|
+
if(dx >= dy)
|
865
|
+
{
|
866
|
+
var pr = dy<<1,
|
867
|
+
pru = pr - (dx<<1),
|
868
|
+
p = pr-dx,
|
869
|
+
ox = x;
|
870
|
+
while(dx > 0)
|
871
|
+
{--dx;
|
872
|
+
++x;
|
873
|
+
if(p > 0)
|
874
|
+
{
|
875
|
+
$(this)._mkDiv(ox, y, x-ox, 1, settings);
|
876
|
+
y += yIncr;
|
877
|
+
p += pru;
|
878
|
+
ox = x;
|
879
|
+
}
|
880
|
+
else p += pr;
|
881
|
+
}
|
882
|
+
$(this)._mkDiv(ox, y, x2-ox+1, 1, settings);
|
883
|
+
}
|
884
|
+
|
885
|
+
else
|
886
|
+
{
|
887
|
+
var pr = dx<<1,
|
888
|
+
pru = pr - (dy<<1),
|
889
|
+
p = pr-dy,
|
890
|
+
oy = y;
|
891
|
+
if(y2 <= y1)
|
892
|
+
{
|
893
|
+
while(dy > 0)
|
894
|
+
{--dy;
|
895
|
+
if(p > 0)
|
896
|
+
{
|
897
|
+
$(this)._mkDiv(x++, y, 1, oy-y+1, settings);
|
898
|
+
y += yIncr;
|
899
|
+
p += pru;
|
900
|
+
oy = y;
|
901
|
+
}
|
902
|
+
else
|
903
|
+
{
|
904
|
+
y += yIncr;
|
905
|
+
p += pr;
|
906
|
+
}
|
907
|
+
}
|
908
|
+
$(this)._mkDiv(x2, y2, 1, oy-y2+1, settings);
|
909
|
+
}
|
910
|
+
else
|
911
|
+
{
|
912
|
+
while(dy > 0)
|
913
|
+
{--dy;
|
914
|
+
y += yIncr;
|
915
|
+
if(p > 0)
|
916
|
+
{
|
917
|
+
$(this)._mkDiv(x++, oy, 1, y-oy, settings);
|
918
|
+
p += pru;
|
919
|
+
oy = y;
|
920
|
+
}
|
921
|
+
else p += pr;
|
922
|
+
}
|
923
|
+
$(this)._mkDiv(x2, oy, 1, y2-oy+1, settings);
|
924
|
+
}
|
925
|
+
}
|
926
|
+
return $(this);
|
927
|
+
}
|
928
|
+
|
929
|
+
$.fn._mkLin2D = function(x1, y1, x2, y2, settings) {
|
930
|
+
if(x1 > x2)
|
931
|
+
{
|
932
|
+
var _x2 = x2;
|
933
|
+
var _y2 = y2;
|
934
|
+
x2 = x1;
|
935
|
+
y2 = y1;
|
936
|
+
x1 = _x2;
|
937
|
+
y1 = _y2;
|
938
|
+
}
|
939
|
+
var dx = x2-x1, dy = Math.abs(y2-y1),
|
940
|
+
x = x1, y = y1,
|
941
|
+
yIncr = (y1 > y2)? -1 : 1;
|
942
|
+
|
943
|
+
var s = settings.stroke;
|
944
|
+
if(dx >= dy)
|
945
|
+
{
|
946
|
+
if(dx > 0 && s-3 > 0)
|
947
|
+
{
|
948
|
+
var _s = (s*dx*Math.sqrt(1+dy*dy/(dx*dx))-dx-(s>>1)*dy) / dx;
|
949
|
+
_s = (!(s-4)? Math.ceil(_s) : Math.round(_s)) + 1;
|
950
|
+
}
|
951
|
+
else var _s = s;
|
952
|
+
var ad = Math.ceil(s/2);
|
953
|
+
|
954
|
+
var pr = dy<<1,
|
955
|
+
pru = pr - (dx<<1),
|
956
|
+
p = pr-dx,
|
957
|
+
ox = x;
|
958
|
+
while(dx > 0)
|
959
|
+
{--dx;
|
960
|
+
++x;
|
961
|
+
if(p > 0)
|
962
|
+
{
|
963
|
+
$(this)._mkDiv(ox, y, x-ox+ad, _s, settings);
|
964
|
+
y += yIncr;
|
965
|
+
p += pru;
|
966
|
+
ox = x;
|
967
|
+
}
|
968
|
+
else p += pr;
|
969
|
+
}
|
970
|
+
$(this)._mkDiv(ox, y, x2-ox+ad+1, _s, settings);
|
971
|
+
}
|
972
|
+
|
973
|
+
else
|
974
|
+
{
|
975
|
+
if(s-3 > 0)
|
976
|
+
{
|
977
|
+
var _s = (s*dy*Math.sqrt(1+dx*dx/(dy*dy))-(s>>1)*dx-dy) / dy;
|
978
|
+
_s = (!(s-4)? Math.ceil(_s) : Math.round(_s)) + 1;
|
979
|
+
}
|
980
|
+
else var _s = s;
|
981
|
+
var ad = Math.round(s/2);
|
982
|
+
|
983
|
+
var pr = dx<<1,
|
984
|
+
pru = pr - (dy<<1),
|
985
|
+
p = pr-dy,
|
986
|
+
oy = y;
|
987
|
+
if(y2 <= y1)
|
988
|
+
{
|
989
|
+
++ad;
|
990
|
+
while(dy > 0)
|
991
|
+
{--dy;
|
992
|
+
if(p > 0)
|
993
|
+
{
|
994
|
+
$(this)._mkDiv(x++, y, _s, oy-y+ad, settings);
|
995
|
+
y += yIncr;
|
996
|
+
p += pru;
|
997
|
+
oy = y;
|
998
|
+
}
|
999
|
+
else
|
1000
|
+
{
|
1001
|
+
y += yIncr;
|
1002
|
+
p += pr;
|
1003
|
+
}
|
1004
|
+
}
|
1005
|
+
$(this)._mkDiv(x2, y2, _s, oy-y2+ad, settings);
|
1006
|
+
}
|
1007
|
+
else
|
1008
|
+
{
|
1009
|
+
while(dy > 0)
|
1010
|
+
{--dy;
|
1011
|
+
y += yIncr;
|
1012
|
+
if(p > 0)
|
1013
|
+
{
|
1014
|
+
$(this)._mkDiv(x++, oy, _s, y-oy+ad, settings);
|
1015
|
+
p += pru;
|
1016
|
+
oy = y;
|
1017
|
+
}
|
1018
|
+
else p += pr;
|
1019
|
+
}
|
1020
|
+
$(this)._mkDiv(x2, oy, _s, y2-oy+ad+1, settings);
|
1021
|
+
}
|
1022
|
+
}
|
1023
|
+
return $(this);
|
1024
|
+
}
|
1025
|
+
|
1026
|
+
$.fn._mkLinDott = function(x1, y1, x2, y2, settings) {
|
1027
|
+
if(x1 > x2)
|
1028
|
+
{
|
1029
|
+
var _x2 = x2;
|
1030
|
+
var _y2 = y2;
|
1031
|
+
x2 = x1;
|
1032
|
+
y2 = y1;
|
1033
|
+
x1 = _x2;
|
1034
|
+
y1 = _y2;
|
1035
|
+
}
|
1036
|
+
var dx = x2-x1, dy = Math.abs(y2-y1),
|
1037
|
+
x = x1, y = y1,
|
1038
|
+
yIncr = (y1 > y2)? -1 : 1,
|
1039
|
+
drw = true;
|
1040
|
+
if(dx >= dy)
|
1041
|
+
{
|
1042
|
+
var pr = dy<<1,
|
1043
|
+
pru = pr - (dx<<1),
|
1044
|
+
p = pr-dx;
|
1045
|
+
while(dx > 0)
|
1046
|
+
{--dx;
|
1047
|
+
if(drw) $(this)._mkDiv(x, y, 1, 1, settings);
|
1048
|
+
drw = !drw;
|
1049
|
+
if(p > 0)
|
1050
|
+
{
|
1051
|
+
y += yIncr;
|
1052
|
+
p += pru;
|
1053
|
+
}
|
1054
|
+
else p += pr;
|
1055
|
+
++x;
|
1056
|
+
}
|
1057
|
+
}
|
1058
|
+
else
|
1059
|
+
{
|
1060
|
+
var pr = dx<<1,
|
1061
|
+
pru = pr - (dy<<1),
|
1062
|
+
p = pr-dy;
|
1063
|
+
while(dy > 0)
|
1064
|
+
{--dy;
|
1065
|
+
if(drw) $(this)._mkDiv(x, y, 1, 1, settings);
|
1066
|
+
drw = !drw;
|
1067
|
+
y += yIncr;
|
1068
|
+
if(p > 0)
|
1069
|
+
{
|
1070
|
+
++x;
|
1071
|
+
p += pru;
|
1072
|
+
}
|
1073
|
+
else p += pr;
|
1074
|
+
}
|
1075
|
+
}
|
1076
|
+
if(drw) $(this)._mkDiv(x, y, 1, 1, settings);
|
1077
|
+
return $(this);
|
1078
|
+
}
|
1079
|
+
|
1080
|
+
$.fn._mkOv = function(left, top, width, height, settings) {
|
1081
|
+
var a = (++width)>>1, b = (++height)>>1,
|
1082
|
+
wod = width&1, hod = height&1,
|
1083
|
+
cx = left+a, cy = top+b,
|
1084
|
+
x = 0, y = b,
|
1085
|
+
ox = 0, oy = b,
|
1086
|
+
aa2 = (a*a)<<1, aa4 = aa2<<1, bb2 = (b*b)<<1, bb4 = bb2<<1,
|
1087
|
+
st = (aa2>>1)*(1-(b<<1)) + bb2,
|
1088
|
+
tt = (bb2>>1) - aa2*((b<<1)-1),
|
1089
|
+
w, h;
|
1090
|
+
while(y > 0)
|
1091
|
+
{
|
1092
|
+
if(st < 0)
|
1093
|
+
{
|
1094
|
+
st += bb2*((x<<1)+3);
|
1095
|
+
tt += bb4*(++x);
|
1096
|
+
}
|
1097
|
+
else if(tt < 0)
|
1098
|
+
{
|
1099
|
+
st += bb2*((x<<1)+3) - aa4*(y-1);
|
1100
|
+
tt += bb4*(++x) - aa2*(((y--)<<1)-3);
|
1101
|
+
w = x-ox;
|
1102
|
+
h = oy-y;
|
1103
|
+
if((w&2) && (h&2))
|
1104
|
+
{
|
1105
|
+
$(this)._mkOvQds(cx, cy, x-2, y+2, 1, 1, wod, hod, settings);
|
1106
|
+
$(this)._mkOvQds(cx, cy, x-1, y+1, 1, 1, wod, hod, settings);
|
1107
|
+
}
|
1108
|
+
else $(this)._mkOvQds(cx, cy, x-1, oy, w, h, wod, hod, settings);
|
1109
|
+
ox = x;
|
1110
|
+
oy = y;
|
1111
|
+
}
|
1112
|
+
else
|
1113
|
+
{
|
1114
|
+
tt -= aa2*((y<<1)-3);
|
1115
|
+
st -= aa4*(--y);
|
1116
|
+
}
|
1117
|
+
}
|
1118
|
+
w = a-ox+1;
|
1119
|
+
h = (oy<<1)+hod;
|
1120
|
+
y = cy-oy;
|
1121
|
+
$(this)._mkDiv(cx-a, y, w, h, settings);
|
1122
|
+
$(this)._mkDiv(cx+ox+wod-1, y, w, h, settings);
|
1123
|
+
return $(this);
|
1124
|
+
}
|
1125
|
+
|
1126
|
+
$.fn._mkOv2D = function(left, top, width, height, settings) {
|
1127
|
+
var s = settings.stroke;
|
1128
|
+
width += s+1;
|
1129
|
+
height += s+1;
|
1130
|
+
var a = width>>1, b = height>>1,
|
1131
|
+
wod = width&1, hod = height&1,
|
1132
|
+
cx = left+a, cy = top+b,
|
1133
|
+
x = 0, y = b,
|
1134
|
+
aa2 = (a*a)<<1, aa4 = aa2<<1, bb2 = (b*b)<<1, bb4 = bb2<<1,
|
1135
|
+
st = (aa2>>1)*(1-(b<<1)) + bb2,
|
1136
|
+
tt = (bb2>>1) - aa2*((b<<1)-1);
|
1137
|
+
|
1138
|
+
if(s-4 < 0 && (!(s-2) || width-51 > 0 && height-51 > 0))
|
1139
|
+
{
|
1140
|
+
var ox = 0, oy = b,
|
1141
|
+
w, h,
|
1142
|
+
pxw;
|
1143
|
+
while(y > 0)
|
1144
|
+
{
|
1145
|
+
if(st < 0)
|
1146
|
+
{
|
1147
|
+
st += bb2*((x<<1)+3);
|
1148
|
+
tt += bb4*(++x);
|
1149
|
+
}
|
1150
|
+
else if(tt < 0)
|
1151
|
+
{
|
1152
|
+
st += bb2*((x<<1)+3) - aa4*(y-1);
|
1153
|
+
tt += bb4*(++x) - aa2*(((y--)<<1)-3);
|
1154
|
+
w = x-ox;
|
1155
|
+
h = oy-y;
|
1156
|
+
|
1157
|
+
if(w-1)
|
1158
|
+
{
|
1159
|
+
pxw = w+1+(s&1);
|
1160
|
+
h = s;
|
1161
|
+
}
|
1162
|
+
else if(h-1)
|
1163
|
+
{
|
1164
|
+
pxw = s;
|
1165
|
+
h += 1+(s&1);
|
1166
|
+
}
|
1167
|
+
else pxw = h = s;
|
1168
|
+
$(this)._mkOvQds(cx, cy, x-1, oy, pxw, h, wod, hod, settings);
|
1169
|
+
ox = x;
|
1170
|
+
oy = y;
|
1171
|
+
}
|
1172
|
+
else
|
1173
|
+
{
|
1174
|
+
tt -= aa2*((y<<1)-3);
|
1175
|
+
st -= aa4*(--y);
|
1176
|
+
}
|
1177
|
+
}
|
1178
|
+
$(this)._mkDiv(cx-a, cy-oy, s, (oy<<1)+hod, settings);
|
1179
|
+
$(this)._mkDiv(cx+a+wod-s, cy-oy, s, (oy<<1)+hod, settings);
|
1180
|
+
}
|
1181
|
+
|
1182
|
+
else
|
1183
|
+
{
|
1184
|
+
var _a = (width-(s<<1))>>1,
|
1185
|
+
_b = (height-(s<<1))>>1,
|
1186
|
+
_x = 0, _y = _b,
|
1187
|
+
_aa2 = (_a*_a)<<1, _aa4 = _aa2<<1, _bb2 = (_b*_b)<<1, _bb4 = _bb2<<1,
|
1188
|
+
_st = (_aa2>>1)*(1-(_b<<1)) + _bb2,
|
1189
|
+
_tt = (_bb2>>1) - _aa2*((_b<<1)-1),
|
1190
|
+
|
1191
|
+
pxl = new Array(),
|
1192
|
+
pxt = new Array(),
|
1193
|
+
_pxb = new Array();
|
1194
|
+
pxl[0] = 0;
|
1195
|
+
pxt[0] = b;
|
1196
|
+
_pxb[0] = _b-1;
|
1197
|
+
while(y > 0)
|
1198
|
+
{
|
1199
|
+
if(st < 0)
|
1200
|
+
{
|
1201
|
+
pxl[pxl.length] = x;
|
1202
|
+
pxt[pxt.length] = y;
|
1203
|
+
st += bb2*((x<<1)+3);
|
1204
|
+
tt += bb4*(++x);
|
1205
|
+
}
|
1206
|
+
else if(tt < 0)
|
1207
|
+
{
|
1208
|
+
pxl[pxl.length] = x;
|
1209
|
+
st += bb2*((x<<1)+3) - aa4*(y-1);
|
1210
|
+
tt += bb4*(++x) - aa2*(((y--)<<1)-3);
|
1211
|
+
pxt[pxt.length] = y;
|
1212
|
+
}
|
1213
|
+
else
|
1214
|
+
{
|
1215
|
+
tt -= aa2*((y<<1)-3);
|
1216
|
+
st -= aa4*(--y);
|
1217
|
+
}
|
1218
|
+
|
1219
|
+
if(_y > 0)
|
1220
|
+
{
|
1221
|
+
if(_st < 0)
|
1222
|
+
{
|
1223
|
+
_st += _bb2*((_x<<1)+3);
|
1224
|
+
_tt += _bb4*(++_x);
|
1225
|
+
_pxb[_pxb.length] = _y-1;
|
1226
|
+
}
|
1227
|
+
else if(_tt < 0)
|
1228
|
+
{
|
1229
|
+
_st += _bb2*((_x<<1)+3) - _aa4*(_y-1);
|
1230
|
+
_tt += _bb4*(++_x) - _aa2*(((_y--)<<1)-3);
|
1231
|
+
_pxb[_pxb.length] = _y-1;
|
1232
|
+
}
|
1233
|
+
else
|
1234
|
+
{
|
1235
|
+
_tt -= _aa2*((_y<<1)-3);
|
1236
|
+
_st -= _aa4*(--_y);
|
1237
|
+
_pxb[_pxb.length-1]--;
|
1238
|
+
}
|
1239
|
+
}
|
1240
|
+
}
|
1241
|
+
|
1242
|
+
var ox = -wod, oy = b,
|
1243
|
+
_oy = _pxb[0],
|
1244
|
+
l = pxl.length,
|
1245
|
+
w, h;
|
1246
|
+
for(var i = 0; i < l; i++)
|
1247
|
+
{
|
1248
|
+
if(typeof _pxb[i] != "undefined")
|
1249
|
+
{
|
1250
|
+
if(_pxb[i] < _oy || pxt[i] < oy)
|
1251
|
+
{
|
1252
|
+
x = pxl[i];
|
1253
|
+
$(this)._mkOvQds(cx, cy, x, oy, x-ox, oy-_oy, wod, hod, settings);
|
1254
|
+
ox = x;
|
1255
|
+
oy = pxt[i];
|
1256
|
+
_oy = _pxb[i];
|
1257
|
+
}
|
1258
|
+
}
|
1259
|
+
else
|
1260
|
+
{
|
1261
|
+
x = pxl[i];
|
1262
|
+
$(this)._mkDiv(cx-x, cy-oy, 1, (oy<<1)+hod, settings);
|
1263
|
+
$(this)._mkDiv(cx+ox+wod, cy-oy, 1, (oy<<1)+hod, settings);
|
1264
|
+
ox = x;
|
1265
|
+
oy = pxt[i];
|
1266
|
+
}
|
1267
|
+
}
|
1268
|
+
$(this)._mkDiv(cx-a, cy-oy, 1, (oy<<1)+hod, settings);
|
1269
|
+
$(this)._mkDiv(cx+ox+wod, cy-oy, 1, (oy<<1)+hod, settings);
|
1270
|
+
}
|
1271
|
+
return $(this);
|
1272
|
+
}
|
1273
|
+
|
1274
|
+
$.fn._mkOvDott = function(left, top, width, height, settings) {
|
1275
|
+
var a = (++width)>>1, b = (++height)>>1,
|
1276
|
+
wod = width&1, hod = height&1, hodu = hod^1,
|
1277
|
+
cx = left+a, cy = top+b,
|
1278
|
+
x = 0, y = b,
|
1279
|
+
aa2 = (a*a)<<1, aa4 = aa2<<1, bb2 = (b*b)<<1, bb4 = bb2<<1,
|
1280
|
+
st = (aa2>>1)*(1-(b<<1)) + bb2,
|
1281
|
+
tt = (bb2>>1) - aa2*((b<<1)-1),
|
1282
|
+
drw = true;
|
1283
|
+
while(y > 0)
|
1284
|
+
{
|
1285
|
+
if(st < 0)
|
1286
|
+
{
|
1287
|
+
st += bb2*((x<<1)+3);
|
1288
|
+
tt += bb4*(++x);
|
1289
|
+
}
|
1290
|
+
else if(tt < 0)
|
1291
|
+
{
|
1292
|
+
st += bb2*((x<<1)+3) - aa4*(y-1);
|
1293
|
+
tt += bb4*(++x) - aa2*(((y--)<<1)-3);
|
1294
|
+
}
|
1295
|
+
else
|
1296
|
+
{
|
1297
|
+
tt -= aa2*((y<<1)-3);
|
1298
|
+
st -= aa4*(--y);
|
1299
|
+
}
|
1300
|
+
if(drw && y >= hodu) $(this)._mkOvQds(cx, cy, x, y, 1, 1, wod, hod, settings);
|
1301
|
+
drw = !drw;
|
1302
|
+
}
|
1303
|
+
return $(this);
|
1304
|
+
}
|
1305
|
+
|
1306
|
+
$.fn._mkRect = function(x, y, w, h, settings) {
|
1307
|
+
var s = settings.stroke;
|
1308
|
+
$(this)._mkDiv(x, y, w, s, settings);
|
1309
|
+
$(this)._mkDiv(x+w, y, s, h, settings);
|
1310
|
+
$(this)._mkDiv(x, y+h, w+s, s, settings);
|
1311
|
+
$(this)._mkDiv(x, y+s, s, h-s, settings);
|
1312
|
+
return $(this);
|
1313
|
+
}
|
1314
|
+
|
1315
|
+
$.fn._mkRectDott = function(x, y, w, h, settings) {
|
1316
|
+
$(this).drawLine(x, y, x+w, y, settings);
|
1317
|
+
$(this).drawLine(x+w, y, x+w, y+h, settings);
|
1318
|
+
$(this).drawLine(x, y+h, x+w, y+h, settings);
|
1319
|
+
$(this).drawLine(x, y, x, y+h, settings);
|
1320
|
+
return $(this);
|
1321
|
+
}
|
1322
|
+
|
1323
|
+
|
1324
|
+
|
1325
|
+
$.fn.drawLine = function(x1, y1, x2, y2, settings) {
|
1326
|
+
|
1327
|
+
settings = jQuery.extend({stroke: 1, color: 'black', opacity: 1, backgroundImage: 'none'}, settings);
|
1328
|
+
settings.xorigin = x1; settings.yorigin = y1;
|
1329
|
+
|
1330
|
+
if (supportsvg.support && !jQuery.browser.msie)
|
1331
|
+
{
|
1332
|
+
|
1333
|
+
|
1334
|
+
var myrand = 'id'+parseInt(Math.random()*1000000);
|
1335
|
+
$(this).append("<div id ='"+myrand+"' style='position: absolute;top: 0; left: 0;'></div>");
|
1336
|
+
|
1337
|
+
$("#"+myrand).css('width', $(this).css('width')).css('height', $(this).css('height')).svg(function () {
|
1338
|
+
var svg = svgManager.getSVGFor("#"+myrand);
|
1339
|
+
var g = svg.group(null, {stroke: settings.color, stroke_width: settings.stroke});
|
1340
|
+
svg.line(g, x1, y1, x2, y2);
|
1341
|
+
});
|
1342
|
+
}
|
1343
|
+
else
|
1344
|
+
{
|
1345
|
+
if (!$(this).find('canvas').get(0))
|
1346
|
+
$(this).append("<canvas width='"+$(this).css('width')+"' height='"+$(this).css('height')+"' style='position: absolute; top: 0; left: 0;'></canvas>");
|
1347
|
+
var canvas = $(this).find("canvas").get(0);
|
1348
|
+
|
1349
|
+
|
1350
|
+
try {
|
1351
|
+
|
1352
|
+
var ctx = canvas.getContext("2d");
|
1353
|
+
|
1354
|
+
ctx.globalAlpha = settings.opacity; if (settings.stroke == 'dotted') ctx.lineWidth = .5; else if (settings.stroke == 'dotted') ctx.lineWidth = .5; else ctx.lineWidth = settings.stroke;
|
1355
|
+
ctx.beginPath();
|
1356
|
+
ctx.strokeStyle = settings.color;
|
1357
|
+
ctx.moveTo(x1, y1);
|
1358
|
+
ctx.lineTo(x2, y2);
|
1359
|
+
ctx.closePath();
|
1360
|
+
ctx.stroke();
|
1361
|
+
|
1362
|
+
}
|
1363
|
+
catch (e) {
|
1364
|
+
|
1365
|
+
|
1366
|
+
|
1367
|
+
if(settings.stroke=='dotted')
|
1368
|
+
{
|
1369
|
+
$(this)._mkLinDott(x1, y1, x2, y2, settings);
|
1370
|
+
}
|
1371
|
+
else if(settings.stroke-1 > 0)
|
1372
|
+
{
|
1373
|
+
$(this)._mkLin2D(x1, y1, x2, y2, settings);
|
1374
|
+
}
|
1375
|
+
else
|
1376
|
+
{
|
1377
|
+
$(this)._mkLin(x1, y1, x2, y2, settings);
|
1378
|
+
}
|
1379
|
+
}
|
1380
|
+
}
|
1381
|
+
|
1382
|
+
return $(this);
|
1383
|
+
};
|
1384
|
+
$.fn.drawRect = function(x1, y1, x2, y2, settings) {
|
1385
|
+
|
1386
|
+
settings = jQuery.extend({stroke: 1, color: 'black', opacity: 1, backgroundImage: 'none'}, settings);
|
1387
|
+
settings.xorigin = x1; settings.yorigin = y1;
|
1388
|
+
|
1389
|
+
if (supportsvg.support && !jQuery.browser.msie)
|
1390
|
+
{
|
1391
|
+
|
1392
|
+
var myrand = 'id'+parseInt(Math.random()*1000000);
|
1393
|
+
$(this).append("<div id ='"+myrand+"' style='position: absolute;top: 0; left: 0;'></div>");
|
1394
|
+
|
1395
|
+
$("#"+myrand).css('width', $(this).css('width')).css('height', $(this).css('height')).svg(function () {
|
1396
|
+
var svg = svgManager.getSVGFor("#"+myrand);
|
1397
|
+
var g = svg.group(null, {stroke: settings.color, stroke_width: settings.stroke});
|
1398
|
+
svg.rect(null, x1, y1, x2, y2, {fill: "none", stroke: settings.color, stroke_width: settings.stroke});
|
1399
|
+
});
|
1400
|
+
|
1401
|
+
}
|
1402
|
+
|
1403
|
+
else
|
1404
|
+
{
|
1405
|
+
if (!$(this).find('canvas').get(0))
|
1406
|
+
$(this).append("<canvas width='"+$(this).css('width')+"' height='"+$(this).css('height')+"' style='position: absolute; top: 0; left: 0;'></canvas>");
|
1407
|
+
var canvas = $(this).find("canvas").get(0);
|
1408
|
+
|
1409
|
+
|
1410
|
+
try {
|
1411
|
+
|
1412
|
+
var ctx = canvas.getContext("2d");
|
1413
|
+
ctx.globalAlpha = settings.opacity; if (settings.stroke == 'dotted') ctx.lineWidth = .5; else ctx.lineWidth = settings.stroke;
|
1414
|
+
ctx.strokeStyle = settings.color;
|
1415
|
+
ctx.strokeRect(x1, y1, x2, y2);
|
1416
|
+
ctx.closePath();
|
1417
|
+
ctx.stroke();
|
1418
|
+
}
|
1419
|
+
catch (e) {
|
1420
|
+
|
1421
|
+
|
1422
|
+
if(settings.stroke=='dotted')
|
1423
|
+
{
|
1424
|
+
$(this)._mkRectDott(x1, y1, x2, y2, settings);
|
1425
|
+
}
|
1426
|
+
else if(settings.stroke-1 > 0)
|
1427
|
+
{
|
1428
|
+
$(this)._mkRect(x1, y1, x2, y2, settings);
|
1429
|
+
}
|
1430
|
+
else
|
1431
|
+
{
|
1432
|
+
$(this)._mkRect(x1, y1, x2, y2, settings);
|
1433
|
+
}
|
1434
|
+
|
1435
|
+
}}
|
1436
|
+
return $(this);
|
1437
|
+
};
|
1438
|
+
|
1439
|
+
|
1440
|
+
|
1441
|
+
|
1442
|
+
|
1443
|
+
$.fn.drawPolyline = function(x, y, settings) {
|
1444
|
+
settings = jQuery.extend({stroke: 1, color: 'black', opacity: 1, backgroundImage: 'none'}, settings);
|
1445
|
+
settings.xorigin = x[0]; settings.yorigin = y[0];
|
1446
|
+
|
1447
|
+
|
1448
|
+
for (var i=x.length - 1; i;)
|
1449
|
+
{--i;
|
1450
|
+
$(this).drawLine(x[i], y[i], x[i+1], y[i+1], settings);
|
1451
|
+
|
1452
|
+
}
|
1453
|
+
return $(this);
|
1454
|
+
};
|
1455
|
+
|
1456
|
+
$.fn.fillRect = function(x, y, w, h, settings) {
|
1457
|
+
settings = jQuery.extend({stroke: 1, color: 'black', opacity: 1, backgroundImage: 'none'}, settings);
|
1458
|
+
settings.xorigin = x; settings.yorigin = y;
|
1459
|
+
|
1460
|
+
if (supportsvg.support && !jQuery.browser.msie)
|
1461
|
+
{
|
1462
|
+
var myrand = 'id'+parseInt(Math.random()*1000000);
|
1463
|
+
$(this).append("<div id ='"+myrand+"' style='position: absolute;top: 0; left: 0;'></div>");
|
1464
|
+
|
1465
|
+
$("#"+myrand).css('width', $(this).css('width')).css('height', $(this).css('height')).svg(function () {
|
1466
|
+
var svg = svgManager.getSVGFor("#"+myrand);
|
1467
|
+
var g = svg.group(null, {stroke: settings.color, stroke_width: settings.stroke});
|
1468
|
+
svg.rect(null, x, y, w, h, {fill: settings.color});
|
1469
|
+
});
|
1470
|
+
}
|
1471
|
+
else
|
1472
|
+
{
|
1473
|
+
if (!$(this).find('canvas').get(0))
|
1474
|
+
$(this).append("<canvas width='"+$(this).css('width')+"' height='"+$(this).css('height')+"' style='position: absolute; top: 0; left: 0;'></canvas>");
|
1475
|
+
var canvas = $(this).find("canvas").get(0);
|
1476
|
+
try {
|
1477
|
+
var ctx = canvas.getContext("2d");
|
1478
|
+
ctx.globalAlpha = settings.opacity; if (settings.stroke == 'dotted') ctx.lineWidth = .5; else ctx.lineWidth = settings.stroke;
|
1479
|
+
if (settings.backgroundImage != 'none')
|
1480
|
+
{
|
1481
|
+
var img = new Image();
|
1482
|
+
img.src = settings.backgroundImage;
|
1483
|
+
if (jQuery.browser.msie)
|
1484
|
+
erreur;
|
1485
|
+
else img.onload = function() {
|
1486
|
+
var ptrn = ctx.createPattern(img, 'repeat');
|
1487
|
+
ctx.fillStyle = ptrn;
|
1488
|
+
ctx.fillRect(x, y, w, h);
|
1489
|
+
}
|
1490
|
+
}
|
1491
|
+
else
|
1492
|
+
{
|
1493
|
+
ctx.fillStyle = settings.color;
|
1494
|
+
ctx.fillRect(x, y, w, h);
|
1495
|
+
}
|
1496
|
+
|
1497
|
+
}
|
1498
|
+
catch (e) {
|
1499
|
+
|
1500
|
+
$(this)._mkDiv(x, y, w, h, settings);
|
1501
|
+
}
|
1502
|
+
}
|
1503
|
+
return $(this);
|
1504
|
+
};
|
1505
|
+
|
1506
|
+
$.fn.drawPolygon = function(x, y, settings) {
|
1507
|
+
settings = jQuery.extend({stroke: 1, color: 'black', opacity: 1, backgroundImage: 'none'}, settings);
|
1508
|
+
settings.xorigin = x[0]; settings.yorigin = y[0];
|
1509
|
+
$(this).drawPolyline(x, y, settings);
|
1510
|
+
$(this).drawLine(x[x.length-1], y[x.length-1], x[0], y[0], settings);
|
1511
|
+
return $(this);
|
1512
|
+
};
|
1513
|
+
|
1514
|
+
$.fn.drawEllipse = function(x, y, w, h, settings) {
|
1515
|
+
settings = jQuery.extend({stroke: 1, color: 'black', opacity: 1, backgroundImage: 'none'}, settings);
|
1516
|
+
settings.xorigin = x; settings.yorigin = y;
|
1517
|
+
if (!$(this).find('canvas').get(0))
|
1518
|
+
$(this).append("<canvas width='"+$(this).css('width')+"' height='"+$(this).css('height')+"' style='position: absolute; top: 0; left: 0;'></canvas>");
|
1519
|
+
var canvas = $(this).find("canvas").get(0);
|
1520
|
+
|
1521
|
+
|
1522
|
+
if (supportsvg.support && !jQuery.browser.msie)
|
1523
|
+
{
|
1524
|
+
var myrand = 'id'+parseInt(Math.random()*1000000);
|
1525
|
+
$(this).append("<div id ='"+myrand+"' style='position: absolute;top: 0; left: 0;'></div>");
|
1526
|
+
|
1527
|
+
$("#"+myrand).css('width', $(this).css('width')).css('height', $(this).css('height')).svg(function () {
|
1528
|
+
var svg = svgManager.getSVGFor("#"+myrand);
|
1529
|
+
var g = svg.group(null, {stroke: settings.color, stroke_width: settings.stroke});
|
1530
|
+
svg.ellipse(null, x+w/2, y+h/2, w/2, h/2, {fill: "none", stroke: settings.color, stroke_width: settings.stroke});
|
1531
|
+
});
|
1532
|
+
}
|
1533
|
+
else
|
1534
|
+
{
|
1535
|
+
try {
|
1536
|
+
var ctx = canvas.getContext("2d");
|
1537
|
+
var left = x, top= y;
|
1538
|
+
w += x;
|
1539
|
+
h += y;
|
1540
|
+
ctx.globalAlpha = settings.opacity;
|
1541
|
+
if (settings.stroke == 'dotted') ctx.lineWidth = .5; else ctx.lineWidth = settings.stroke;
|
1542
|
+
var KAPPA = 4 * ((Math.sqrt(2) -1) / 3);
|
1543
|
+
|
1544
|
+
var rx = (w-left)/2;
|
1545
|
+
var ry = (h-top)/2;
|
1546
|
+
|
1547
|
+
var cx = left+rx;
|
1548
|
+
var cy = top+ry;
|
1549
|
+
|
1550
|
+
ctx.beginPath();
|
1551
|
+
ctx.strokeStyle = settings.color;
|
1552
|
+
ctx.moveTo(cx, cy - ry);
|
1553
|
+
ctx.bezierCurveTo(cx + (KAPPA * rx), cy - ry, cx + rx, cy - (KAPPA * ry), cx + rx, cy);
|
1554
|
+
ctx.bezierCurveTo(cx + rx, cy + (KAPPA * ry), cx + (KAPPA * rx), cy + ry, cx, cy + ry);
|
1555
|
+
ctx.bezierCurveTo(cx - (KAPPA * rx), cy + ry, cx - rx, cy + (KAPPA * ry), cx - rx, cy);
|
1556
|
+
ctx.bezierCurveTo(cx - rx, cy - (KAPPA * ry), cx - (KAPPA * rx), cy - ry, cx, cy - ry);
|
1557
|
+
|
1558
|
+
ctx.closePath();
|
1559
|
+
ctx.stokeStyle = settings.color;
|
1560
|
+
ctx.stroke();
|
1561
|
+
|
1562
|
+
} catch (e) {
|
1563
|
+
|
1564
|
+
|
1565
|
+
if(settings.stroke=='dotted')
|
1566
|
+
{
|
1567
|
+
$(this)._mkOvDott(x, y, w, h, settings);
|
1568
|
+
}
|
1569
|
+
else if(settings.stroke-1 > 0)
|
1570
|
+
{
|
1571
|
+
$(this)._mkOv2D(x, y, w, h, settings);
|
1572
|
+
}
|
1573
|
+
else
|
1574
|
+
{
|
1575
|
+
$(this)._mkOv(x, y, w, h, settings);
|
1576
|
+
}
|
1577
|
+
|
1578
|
+
}
|
1579
|
+
}
|
1580
|
+
return $(this);
|
1581
|
+
};
|
1582
|
+
|
1583
|
+
|
1584
|
+
$.fn.fillEllipse = function(left, top, w, h, settings) {
|
1585
|
+
settings = jQuery.extend({stroke: 1, color: 'black', opacity: 1, backgroundImage: 'none'}, settings);
|
1586
|
+
settings.xorigin = left; settings.yorigin = top;
|
1587
|
+
if (supportsvg.support && !jQuery.browser.msie)
|
1588
|
+
{
|
1589
|
+
var myrand = 'id'+parseInt(Math.random()*1000000);
|
1590
|
+
$(this).append("<div id ='"+myrand+"' style='position: absolute;top: 0; left: 0;'></div>");
|
1591
|
+
|
1592
|
+
$("#"+myrand).css('width', $(this).css('width')).css('height', $(this).css('height')).svg(function () {
|
1593
|
+
var svg = svgManager.getSVGFor("#"+myrand);
|
1594
|
+
var g = svg.group(null, {stroke: settings.color, stroke_width: settings.stroke});
|
1595
|
+
svg.ellipse(null, left+w/2, top+h/2, w/2, h/2, {fill: settings.color});
|
1596
|
+
});
|
1597
|
+
}
|
1598
|
+
else
|
1599
|
+
{
|
1600
|
+
|
1601
|
+
|
1602
|
+
if (!$(this).find('canvas').get(0))
|
1603
|
+
$(this).append("<canvas width='"+$(this).css('width')+"' height='"+$(this).css('height')+"' style='position: absolute; top: 0; left: 0;'></canvas>");
|
1604
|
+
var canvas = $(this).find("canvas").get(0);
|
1605
|
+
|
1606
|
+
try {
|
1607
|
+
var ctx = canvas.getContext("2d");
|
1608
|
+
w += left;
|
1609
|
+
h += top;
|
1610
|
+
ctx.globalAlpha = settings.opacity; if (settings.stroke == 'dotted') ctx.lineWidth = .5; else ctx.lineWidth = settings.stroke;
|
1611
|
+
if (settings.backgroundImage != 'none')
|
1612
|
+
{
|
1613
|
+
var img = new Image();
|
1614
|
+
img.src = settings.backgroundImage;
|
1615
|
+
$(img).ready(function() {
|
1616
|
+
var ptrn = ctx.createPattern(img, 'repeat');
|
1617
|
+
ctx.moveTo(left, top);
|
1618
|
+
var KAPPA = 4 * ((Math.sqrt(2) -1) / 3);
|
1619
|
+
|
1620
|
+
var rx = (w-left)/2;
|
1621
|
+
var ry = (h-top)/2;
|
1622
|
+
|
1623
|
+
var cx = left+rx;
|
1624
|
+
var cy = top+ry;
|
1625
|
+
|
1626
|
+
ctx.beginPath();
|
1627
|
+
ctx.fillStyle = ptrn;
|
1628
|
+
ctx.globalAlpha = settings.opacity; if (settings.stroke == 'dotted') ctx.lineWidth = .5; else ctx.lineWidth = settings.stroke;
|
1629
|
+
ctx.moveTo(cx, cy - ry);
|
1630
|
+
ctx.bezierCurveTo(cx + (KAPPA * rx), cy - ry, cx + rx, cy - (KAPPA * ry), cx + rx, cy);
|
1631
|
+
ctx.bezierCurveTo(cx + rx, cy + (KAPPA * ry), cx + (KAPPA * rx), cy + ry, cx, cy + ry);
|
1632
|
+
ctx.bezierCurveTo(cx - (KAPPA * rx), cy + ry, cx - rx, cy + (KAPPA * ry), cx - rx, cy);
|
1633
|
+
ctx.bezierCurveTo(cx - rx, cy - (KAPPA * ry), cx - (KAPPA * rx), cy - ry, cx, cy - ry);
|
1634
|
+
ctx.closePath();
|
1635
|
+
ctx.fill();
|
1636
|
+
|
1637
|
+
});
|
1638
|
+
}
|
1639
|
+
else
|
1640
|
+
{
|
1641
|
+
ctx.fillStyle = settings.color;
|
1642
|
+
ctx.globalAlpha = settings.opacity; if (settings.stroke == 'dotted') ctx.lineWidth = .5; else ctx.lineWidth = settings.stroke;
|
1643
|
+
ctx.fillStyle = settings.color;
|
1644
|
+
ctx.beginPath();
|
1645
|
+
ctx.moveTo(left, top);
|
1646
|
+
var KAPPA = 4 * ((Math.sqrt(2) -1) / 3);
|
1647
|
+
|
1648
|
+
var rx = (w-left)/2;
|
1649
|
+
var ry = (h-top)/2;
|
1650
|
+
|
1651
|
+
var cx = left+rx;
|
1652
|
+
var cy = top+ry;
|
1653
|
+
|
1654
|
+
ctx.beginPath();
|
1655
|
+
ctx.moveTo(cx, cy - ry);
|
1656
|
+
ctx.bezierCurveTo(cx + (KAPPA * rx), cy - ry, cx + rx, cy - (KAPPA * ry), cx + rx, cy);
|
1657
|
+
ctx.bezierCurveTo(cx + rx, cy + (KAPPA * ry), cx + (KAPPA * rx), cy + ry, cx, cy + ry);
|
1658
|
+
ctx.bezierCurveTo(cx - (KAPPA * rx), cy + ry, cx - rx, cy + (KAPPA * ry), cx - rx, cy);
|
1659
|
+
ctx.bezierCurveTo(cx - rx, cy - (KAPPA * ry), cx - (KAPPA * rx), cy - ry, cx, cy - ry);
|
1660
|
+
|
1661
|
+
ctx.closePath();
|
1662
|
+
ctx.fill();
|
1663
|
+
}
|
1664
|
+
|
1665
|
+
|
1666
|
+
} catch (e) {
|
1667
|
+
|
1668
|
+
|
1669
|
+
var a = w>>1, b = h>>1,
|
1670
|
+
wod = w&1, hod = h&1,
|
1671
|
+
cx = left+a, cy = top+b,
|
1672
|
+
x = 0, y = b, oy = b,
|
1673
|
+
aa2 = (a*a)<<1, aa4 = aa2<<1, bb2 = (b*b)<<1, bb4 = bb2<<1,
|
1674
|
+
st = (aa2>>1)*(1-(b<<1)) + bb2,
|
1675
|
+
tt = (bb2>>1) - aa2*((b<<1)-1),
|
1676
|
+
xl, dw, dh;
|
1677
|
+
if(w) while(y > 0)
|
1678
|
+
{
|
1679
|
+
if(st < 0)
|
1680
|
+
{
|
1681
|
+
st += bb2*((x<<1)+3);
|
1682
|
+
tt += bb4*(++x);
|
1683
|
+
}
|
1684
|
+
else if(tt < 0)
|
1685
|
+
{
|
1686
|
+
st += bb2*((x<<1)+3) - aa4*(y-1);
|
1687
|
+
xl = cx-x;
|
1688
|
+
dw = (x<<1)+wod;
|
1689
|
+
tt += bb4*(++x) - aa2*(((y--)<<1)-3);
|
1690
|
+
dh = oy-y;
|
1691
|
+
$(this)._mkDiv(xl, cy-oy, dw, dh, settings);
|
1692
|
+
$(this)._mkDiv(xl, cy+y+hod, dw, dh, settings);
|
1693
|
+
oy = y;
|
1694
|
+
}
|
1695
|
+
else
|
1696
|
+
{
|
1697
|
+
tt -= aa2*((y<<1)-3);
|
1698
|
+
st -= aa4*(--y);
|
1699
|
+
}
|
1700
|
+
}
|
1701
|
+
$(this)._mkDiv(cx-a, cy-oy, w, (oy<<1)+hod, settings);
|
1702
|
+
|
1703
|
+
}
|
1704
|
+
}
|
1705
|
+
return $(this);
|
1706
|
+
};
|
1707
|
+
|
1708
|
+
$.fn.fillArc = function(iL, iT, iW, fAngA, fAngZ, settings) {
|
1709
|
+
var iH = iW;
|
1710
|
+
settings = jQuery.extend({stroke: 1, color: 'black', opacity: 1, backgroundImage: 'none'}, settings);
|
1711
|
+
settings.xorigin = iL; settings.yorigin = iT;
|
1712
|
+
|
1713
|
+
|
1714
|
+
if (supportsvg.support && !jQuery.browser.msie)
|
1715
|
+
{
|
1716
|
+
var myrand = 'id'+parseInt(Math.random()*1000000);
|
1717
|
+
$(this).append("<div id ='"+myrand+"' style='position: absolute;top: 0; left: 0;'></div>");
|
1718
|
+
$("#"+myrand).css('width', $(this).css('width')).css('height', $(this).css('height')).svg(function () {
|
1719
|
+
var svg = svgManager.getSVGFor("#"+myrand);
|
1720
|
+
|
1721
|
+
|
1722
|
+
var g = svg.group(null, {stroke: settings.color, stroke_width: settings.stroke});
|
1723
|
+
var cx = iL+iW/2, cy = iT+iW/2, r = iW/2, startangle=Math.PI+ (((fAngA+90)%360)*Math.PI/180), endangle =Math.PI+(((fAngZ+90)%360)*Math.PI/180);
|
1724
|
+
var big = 0;
|
1725
|
+
if (endangle - startangle > Math.PI) big = 1;
|
1726
|
+
var x1 = cx + r * Math.sin(startangle);
|
1727
|
+
var y1 = cy - r * Math.cos(startangle);
|
1728
|
+
var x2 = cx + r * Math.sin(endangle);
|
1729
|
+
var y2 = cy - r * Math.cos(endangle);var d = "M " + cx + "," + cy + // Start at circle center
|
1730
|
+
" L " + x1 + "," + y1 + // Draw line to (x1,y1)
|
1731
|
+
" A " + r + "," + r + // Draw an arc of radius r
|
1732
|
+
" 0 " + big + " 1 " + // Arc details...
|
1733
|
+
x2 + "," + y2 + // Arc goes to to (x2,y2)
|
1734
|
+
" Z";
|
1735
|
+
svg.path(null, d, {fill: settings.color, stroke_linejoin: "round", background_fill: "none"});
|
1736
|
+
});
|
1737
|
+
|
1738
|
+
|
1739
|
+
}
|
1740
|
+
else
|
1741
|
+
{ if (!$(this).find('canvas').get(0))
|
1742
|
+
$(this).append("<canvas width='"+$(this).css('width')+"' height='"+$(this).css('height')+"' style='position: absolute; top: 0; left: 0;'></canvas>");
|
1743
|
+
var canvas = $(this).find("canvas").get(0);
|
1744
|
+
|
1745
|
+
|
1746
|
+
try {
|
1747
|
+
|
1748
|
+
var ctx = canvas.getContext("2d");
|
1749
|
+
ctx.globalAlpha = settings.opacity; if (settings.stroke == 'dotted') ctx.lineWidth = .5; else ctx.lineWidth = settings.stroke;
|
1750
|
+
var img;
|
1751
|
+
var ptrn;
|
1752
|
+
if (settings.backgroundImage != 'none')
|
1753
|
+
{
|
1754
|
+
|
1755
|
+
var img = new Image();
|
1756
|
+
img.src = settings.backgroundImage;
|
1757
|
+
if (jQuery.browser.msie)
|
1758
|
+
erreur;
|
1759
|
+
else img.onload = function(){
|
1760
|
+
//alert('ok');
|
1761
|
+
var ptrn = ctx.createPattern(img, 'repeat');
|
1762
|
+
ctx.fillStyle = ptrn;
|
1763
|
+
ctx.beginPath();
|
1764
|
+
ctx.moveTo(iL+iW/2, iT+iW/2);
|
1765
|
+
ctx.arc(iL+iW/2, iT+iW/2, iW/2,
|
1766
|
+
2*Math.PI-(fAngA*Math.PI)/180,
|
1767
|
+
2*Math.PI-(fAngZ*Math.PI)/180, true);
|
1768
|
+
ctx.lineTo(iL+iW/2, iT+iW/2);
|
1769
|
+
ctx.closePath();
|
1770
|
+
ctx.fill();
|
1771
|
+
};
|
1772
|
+
|
1773
|
+
}
|
1774
|
+
else
|
1775
|
+
{
|
1776
|
+
ctx.fillStyle = settings.color;
|
1777
|
+
ctx.beginPath();
|
1778
|
+
ctx.moveTo(iL+iW/2, iT+iW/2);
|
1779
|
+
ctx.arc(iL+iW/2, iT+iW/2, iW/2,
|
1780
|
+
2*Math.PI-(fAngA*Math.PI)/180,
|
1781
|
+
2*Math.PI-(fAngZ*Math.PI)/180,
|
1782
|
+
|
1783
|
+
true);
|
1784
|
+
ctx.lineTo(iL+iW/2, iT+iW/2);
|
1785
|
+
ctx.closePath();
|
1786
|
+
ctx.fill();
|
1787
|
+
}
|
1788
|
+
|
1789
|
+
} catch (e) {
|
1790
|
+
|
1791
|
+
|
1792
|
+
var a = iW>>1, b = iH>>1,
|
1793
|
+
iOdds = (iW&1) | ((iH&1) << 16),
|
1794
|
+
cx = iL+a, cy = iT+b,
|
1795
|
+
x = 0, y = b, ox = x, oy = y,
|
1796
|
+
aa2 = (a*a)<<1, aa4 = aa2<<1, bb2 = (b*b)<<1, bb4 = bb2<<1,
|
1797
|
+
st = (aa2>>1)*(1-(b<<1)) + bb2,
|
1798
|
+
tt = (bb2>>1) - aa2*((b<<1)-1),
|
1799
|
+
// Vars for radial boundary lines
|
1800
|
+
xEndA, yEndA, xEndZ, yEndZ,
|
1801
|
+
iSects = (1 << (Math.floor((fAngA %= 360.0)/180.0) << 3))
|
1802
|
+
| (2 << (Math.floor((fAngZ %= 360.0)/180.0) << 3))
|
1803
|
+
| ((fAngA >= fAngZ) << 16),
|
1804
|
+
aBndA = new Array(b+1), aBndZ = new Array(b+1);
|
1805
|
+
|
1806
|
+
// Set up radial boundary lines
|
1807
|
+
fAngA *= Math.PI/180.0;
|
1808
|
+
fAngZ *= Math.PI/180.0;
|
1809
|
+
xEndA = cx+Math.round(a*Math.cos(fAngA));
|
1810
|
+
yEndA = cy+Math.round(-b*Math.sin(fAngA));
|
1811
|
+
$(this)._mkLinVirt(aBndA, cx, cy, xEndA, yEndA, settings);
|
1812
|
+
xEndZ = cx+Math.round(a*Math.cos(fAngZ));
|
1813
|
+
yEndZ = cy+Math.round(-b*Math.sin(fAngZ));
|
1814
|
+
$(this)._mkLinVirt(aBndZ, cx, cy, xEndZ, yEndZ, settings);
|
1815
|
+
|
1816
|
+
while(y > 0)
|
1817
|
+
{
|
1818
|
+
if(st < 0) // Advance x
|
1819
|
+
{
|
1820
|
+
st += bb2*((x<<1)+3);
|
1821
|
+
tt += bb4*(++x);
|
1822
|
+
}
|
1823
|
+
else if(tt < 0) // Advance x and y
|
1824
|
+
{
|
1825
|
+
st += bb2*((x<<1)+3) - aa4*(y-1);
|
1826
|
+
ox = x;
|
1827
|
+
tt += bb4*(++x) - aa2*(((y--)<<1)-3);
|
1828
|
+
$(this)._mkArcDiv(ox, y, oy, cx, cy, iOdds, aBndA, aBndZ, iSects, settings);
|
1829
|
+
oy = y;
|
1830
|
+
}
|
1831
|
+
else // Advance y
|
1832
|
+
{
|
1833
|
+
tt -= aa2*((y<<1)-3);
|
1834
|
+
st -= aa4*(--y);
|
1835
|
+
if(y && (aBndA[y] != aBndA[y-1] || aBndZ[y] != aBndZ[y-1]))
|
1836
|
+
{
|
1837
|
+
$(this)._mkArcDiv(x, y, oy, cx, cy, iOdds, aBndA, aBndZ, iSects, settings);
|
1838
|
+
ox = x;
|
1839
|
+
oy = y;
|
1840
|
+
}
|
1841
|
+
}
|
1842
|
+
}
|
1843
|
+
}
|
1844
|
+
$(this)._mkArcDiv(x, 0, oy, cx, cy, iOdds, aBndA, aBndZ, iSects, settings);
|
1845
|
+
if(iOdds >> 16) // Odd height
|
1846
|
+
{
|
1847
|
+
if(iSects >> 16) // Start-angle > end-angle
|
1848
|
+
{
|
1849
|
+
var xl = (yEndA <= cy || yEndZ > cy)? (cx - x) : cx;
|
1850
|
+
$(this)._mkDiv(xl, cy, x + cx - xl + (iOdds & 0xffff), 1, settings);
|
1851
|
+
}
|
1852
|
+
else if((iSects & 0x01) && yEndZ > cy)
|
1853
|
+
$(this)._mkDiv(cx - x, cy, x, 1, settings);
|
1854
|
+
}
|
1855
|
+
}
|
1856
|
+
return $(this);
|
1857
|
+
};
|
1858
|
+
|
1859
|
+
/* fillPolygon method, implemented by Matthieu Haller.
|
1860
|
+
this javascript function is an adaptation of the gdImageFilledPolygon for Walter Zorn lib.
|
1861
|
+
C source of GD 1.8.4 found at http://www.boutell.com/gd/
|
1862
|
+
|
1863
|
+
THANKS to Kirsten Schulz for the polygon fixes!
|
1864
|
+
|
1865
|
+
The intersection finding technique of $(this) code could be improved
|
1866
|
+
by remembering the previous intertersection, and by using the slope.
|
1867
|
+
That could help to adjust intersections to produce a nice
|
1868
|
+
interior_extrema. */
|
1869
|
+
|
1870
|
+
|
1871
|
+
$.fn.fillPolygon = function(array_x, array_y, settings) {
|
1872
|
+
|
1873
|
+
settings = jQuery.extend({stroke: 1, color: 'black', opacity: 1, backgroundImage: 'none'}, settings);
|
1874
|
+
settings.xorigin = array_x[0]; settings.yorigin = array_y[0];
|
1875
|
+
|
1876
|
+
if (supportsvg.support && !jQuery.browser.msie)
|
1877
|
+
{
|
1878
|
+
var myrand = 'id'+parseInt(Math.random()*1000000);
|
1879
|
+
$(this).append("<div id ='"+myrand+"' style='position: absolute;top: 0; left: 0;'></div>");
|
1880
|
+
|
1881
|
+
$("#"+myrand).css('width', $(this).css('width')).css('height', $(this).css('height')).svg(function () {
|
1882
|
+
var svg = svgManager.getSVGFor("#"+myrand);
|
1883
|
+
var g = svg.group(null, {stroke: settings.color, stroke_width: settings.stroke});
|
1884
|
+
var points = new Array;
|
1885
|
+
for (var i=0; i<array_x.length; i++)
|
1886
|
+
{
|
1887
|
+
points[i] = new Array;
|
1888
|
+
points[i][0] = array_x[i];points[i][1] = array_y[i];
|
1889
|
+
}
|
1890
|
+
svg.polygon(null, points, {fill: settings.color});
|
1891
|
+
});
|
1892
|
+
}
|
1893
|
+
else
|
1894
|
+
{
|
1895
|
+
|
1896
|
+
if (!$(this).find('canvas').get(0))
|
1897
|
+
$(this).append("<canvas width='"+$(this).css('width')+"' height='"+$(this).css('height')+"' style='position: absolute; top: 0; left: 0;'></canvas>");
|
1898
|
+
var canvas = $(this).find("canvas").get(0);
|
1899
|
+
|
1900
|
+
|
1901
|
+
try {
|
1902
|
+
var ctx = canvas.getContext("2d");
|
1903
|
+
var n = array_x.length;
|
1904
|
+
ctx.globalAlpha = settings.opacity; if (settings.stroke == 'dotted') ctx.lineWidth = .5; else ctx.lineWidth = settings.stroke;
|
1905
|
+
ctx.beginPath();
|
1906
|
+
var img;
|
1907
|
+
var ptrn;
|
1908
|
+
if (settings.backgroundImage != 'none')
|
1909
|
+
{
|
1910
|
+
img = new Image();
|
1911
|
+
img.src = settings.backgroundImage;
|
1912
|
+
if (jQuery.browser.msie)
|
1913
|
+
erreur;
|
1914
|
+
else img.onload = function() {
|
1915
|
+
ptrn = ctx.createPattern(img, 'repeat');
|
1916
|
+
ctx.fillStyle = ptrn;
|
1917
|
+
|
1918
|
+
ctx.moveTo(array_x[0], array_y[0]);
|
1919
|
+
|
1920
|
+
for (var i=1; i<n; i++)
|
1921
|
+
{
|
1922
|
+
ctx.lineTo(array_x[i], array_y[i]);
|
1923
|
+
|
1924
|
+
}
|
1925
|
+
ctx.lineTo(array_x[0], array_y[0]);
|
1926
|
+
ctx.closePath();
|
1927
|
+
ctx.fill();}
|
1928
|
+
}
|
1929
|
+
else
|
1930
|
+
{
|
1931
|
+
ctx.fillStyle = settings.color;
|
1932
|
+
ctx.moveTo(array_x[0], array_y[0]);
|
1933
|
+
|
1934
|
+
for (var i=1; i<n; i++)
|
1935
|
+
{
|
1936
|
+
ctx.lineTo(array_x[i], array_y[i]);
|
1937
|
+
|
1938
|
+
}
|
1939
|
+
ctx.lineTo(array_x[0], array_y[0]);
|
1940
|
+
ctx.closePath();
|
1941
|
+
ctx.fill();
|
1942
|
+
}
|
1943
|
+
} catch (e) {
|
1944
|
+
var i;
|
1945
|
+
var y;
|
1946
|
+
var miny, maxy;
|
1947
|
+
var x1, y1;
|
1948
|
+
var x2, y2;
|
1949
|
+
var ind1, ind2;
|
1950
|
+
var ints;
|
1951
|
+
|
1952
|
+
var n = array_x.length;
|
1953
|
+
if(!n) return;
|
1954
|
+
|
1955
|
+
miny = array_y[0];
|
1956
|
+
maxy = array_y[0];
|
1957
|
+
for(i = 1; i < n; i++)
|
1958
|
+
{
|
1959
|
+
if(array_y[i] < miny)
|
1960
|
+
miny = array_y[i];
|
1961
|
+
|
1962
|
+
if(array_y[i] > maxy)
|
1963
|
+
maxy = array_y[i];
|
1964
|
+
}
|
1965
|
+
for(y = miny; y <= maxy; y++)
|
1966
|
+
{
|
1967
|
+
var polyInts = new Array();
|
1968
|
+
ints = 0;
|
1969
|
+
for(i = 0; i < n; i++)
|
1970
|
+
{
|
1971
|
+
if(!i)
|
1972
|
+
{
|
1973
|
+
ind1 = n-1;
|
1974
|
+
ind2 = 0;
|
1975
|
+
}
|
1976
|
+
else
|
1977
|
+
{
|
1978
|
+
ind1 = i-1;
|
1979
|
+
ind2 = i;
|
1980
|
+
}
|
1981
|
+
y1 = array_y[ind1];
|
1982
|
+
y2 = array_y[ind2];
|
1983
|
+
if(y1 < y2)
|
1984
|
+
{
|
1985
|
+
x1 = array_x[ind1];
|
1986
|
+
x2 = array_x[ind2];
|
1987
|
+
}
|
1988
|
+
else if(y1 > y2)
|
1989
|
+
{
|
1990
|
+
y2 = array_y[ind1];
|
1991
|
+
y1 = array_y[ind2];
|
1992
|
+
x2 = array_x[ind1];
|
1993
|
+
x1 = array_x[ind2];
|
1994
|
+
}
|
1995
|
+
else continue;
|
1996
|
+
|
1997
|
+
// Modified 11. 2. 2004 Walter Zorn
|
1998
|
+
if((y >= y1) && (y < y2))
|
1999
|
+
polyInts[ints++] = Math.round((y-y1) * (x2-x1) / (y2-y1) + x1);
|
2000
|
+
|
2001
|
+
else if((y == maxy) && (y > y1) && (y <= y2))
|
2002
|
+
polyInts[ints++] = Math.round((y-y1) * (x2-x1) / (y2-y1) + x1);
|
2003
|
+
}
|
2004
|
+
polyInts.sort(function CompInt(x, y) {
|
2005
|
+
return(x - y);
|
2006
|
+
|
2007
|
+
});
|
2008
|
+
for(i = 0; i < ints; i+=2)
|
2009
|
+
$(this)._mkDiv(polyInts[i], y, polyInts[i+1]-polyInts[i]+1, 1, settings);
|
2010
|
+
}
|
2011
|
+
|
2012
|
+
}
|
2013
|
+
}
|
2014
|
+
return $(this);
|
2015
|
+
};
|
2016
|
+
|
2017
|
+
|
2018
|
+
|
2019
|
+
|
2020
|
+
$.fn._mkOvQds = function(cx, cy, x, y, w, h, wod, hod, settings) {
|
2021
|
+
var xl = cx - x, xr = cx + x + wod - w, yt = cy - y, yb = cy + y + hod - h;
|
2022
|
+
if(xr > xl+w)
|
2023
|
+
{
|
2024
|
+
$(this)._mkDiv(xr, yt, w, h, settings);
|
2025
|
+
$(this)._mkDiv(xr, yb, w, h, settings);
|
2026
|
+
}
|
2027
|
+
else
|
2028
|
+
w = xr - xl + w;
|
2029
|
+
$(this)._mkDiv(xl, yt, w, h, settings);
|
2030
|
+
$(this)._mkDiv(xl, yb, w, h, settings);
|
2031
|
+
return $(this);
|
2032
|
+
};
|
2033
|
+
|
2034
|
+
$.fn._mkArcDiv = function(x, y, oy, cx, cy, iOdds, aBndA, aBndZ, iSects, settings) {
|
2035
|
+
var xrDef = cx + x + (iOdds & 0xffff), y2, h = oy - y, xl, xr, w;
|
2036
|
+
|
2037
|
+
if(!h) h = 1;
|
2038
|
+
x = cx - x;
|
2039
|
+
|
2040
|
+
if(iSects & 0xff0000) // Start-angle > end-angle
|
2041
|
+
{
|
2042
|
+
y2 = cy - y - h;
|
2043
|
+
if(iSects & 0x00ff)
|
2044
|
+
{
|
2045
|
+
if(iSects & 0x02)
|
2046
|
+
{
|
2047
|
+
xl = Math.max(x, aBndZ[y]);
|
2048
|
+
w = xrDef - xl;
|
2049
|
+
if(w > 0) $(this)._mkDiv(xl, y2, w, h, settings);
|
2050
|
+
}
|
2051
|
+
if(iSects & 0x01)
|
2052
|
+
{
|
2053
|
+
xr = Math.min(xrDef, aBndA[y]);
|
2054
|
+
w = xr - x;
|
2055
|
+
if(w > 0) $(this)._mkDiv(x, y2, w, h, settings);
|
2056
|
+
}
|
2057
|
+
}
|
2058
|
+
else
|
2059
|
+
$(this)._mkDiv(x, y2, xrDef - x, h, settings);
|
2060
|
+
y2 = cy + y + (iOdds >> 16);
|
2061
|
+
if(iSects & 0xff00)
|
2062
|
+
{
|
2063
|
+
if(iSects & 0x0100)
|
2064
|
+
{
|
2065
|
+
xl = Math.max(x, aBndA[y]);
|
2066
|
+
w = xrDef - xl;
|
2067
|
+
if(w > 0) $(this)._mkDiv(xl, y2, w, h, settings);
|
2068
|
+
}
|
2069
|
+
if(iSects & 0x0200)
|
2070
|
+
{
|
2071
|
+
xr = Math.min(xrDef, aBndZ[y]);
|
2072
|
+
w = xr - x;
|
2073
|
+
if(w > 0) $(this)._mkDiv(x, y2, w, h, settings);
|
2074
|
+
}
|
2075
|
+
}
|
2076
|
+
else
|
2077
|
+
$(this)._mkDiv(x, y2, xrDef - x, h, settings);
|
2078
|
+
}
|
2079
|
+
else
|
2080
|
+
{
|
2081
|
+
if(iSects & 0x00ff)
|
2082
|
+
{
|
2083
|
+
if(iSects & 0x02)
|
2084
|
+
xl = Math.max(x, aBndZ[y]);
|
2085
|
+
else
|
2086
|
+
xl = x;
|
2087
|
+
if(iSects & 0x01)
|
2088
|
+
xr = Math.min(xrDef, aBndA[y]);
|
2089
|
+
else
|
2090
|
+
xr = xrDef;
|
2091
|
+
y2 = cy - y - h;
|
2092
|
+
w = xr - xl;
|
2093
|
+
if(w > 0) $(this)._mkDiv(xl, y2, w, h, settings);
|
2094
|
+
}
|
2095
|
+
if(iSects & 0xff00)
|
2096
|
+
{
|
2097
|
+
if(iSects & 0x0100)
|
2098
|
+
xl = Math.max(x, aBndA[y]);
|
2099
|
+
else
|
2100
|
+
xl = x;
|
2101
|
+
if(iSects & 0x0200)
|
2102
|
+
xr = Math.min(xrDef, aBndZ[y]);
|
2103
|
+
else
|
2104
|
+
xr = xrDef;
|
2105
|
+
y2 = cy + y + (iOdds >> 16);
|
2106
|
+
w = xr - xl;
|
2107
|
+
if(w > 0) $(this)._mkDiv(xl, y2, w, h, settings);
|
2108
|
+
}
|
2109
|
+
}
|
2110
|
+
return $(this);
|
2111
|
+
};
|
2112
|
+
|
2113
|
+
|
2114
|
+
|
2115
|
+
|
2116
|
+
|
2117
|
+
$.fn._mkLinVirt = function(aLin, x1, y1, x2, y2, settings) {
|
2118
|
+
var dx = Math.abs(x2-x1), dy = Math.abs(y2-y1),
|
2119
|
+
x = x1, y = y1,
|
2120
|
+
xIncr = (x1 > x2)? -1 : 1,
|
2121
|
+
yIncr = (y1 > y2)? -1 : 1,
|
2122
|
+
p,
|
2123
|
+
i = 0;
|
2124
|
+
if(dx >= dy)
|
2125
|
+
{
|
2126
|
+
var pr = dy<<1,
|
2127
|
+
pru = pr - (dx<<1);
|
2128
|
+
p = pr-dx;
|
2129
|
+
while(dx > 0)
|
2130
|
+
{--dx;
|
2131
|
+
if(p > 0) // Increment y
|
2132
|
+
{
|
2133
|
+
aLin[i++] = x;
|
2134
|
+
y += yIncr;
|
2135
|
+
p += pru;
|
2136
|
+
}
|
2137
|
+
else p += pr;
|
2138
|
+
x += xIncr;
|
2139
|
+
}
|
2140
|
+
}
|
2141
|
+
else
|
2142
|
+
{
|
2143
|
+
var pr = dx<<1,
|
2144
|
+
pru = pr - (dy<<1);
|
2145
|
+
p = pr-dy;
|
2146
|
+
while(dy > 0)
|
2147
|
+
{--dy;
|
2148
|
+
y += yIncr;
|
2149
|
+
aLin[i++] = x;
|
2150
|
+
if(p > 0) // Increment x
|
2151
|
+
{
|
2152
|
+
x += xIncr;
|
2153
|
+
p += pru;
|
2154
|
+
}
|
2155
|
+
else p += pr;
|
2156
|
+
}
|
2157
|
+
}
|
2158
|
+
for(var len = aLin.length, i = len-i; i;)
|
2159
|
+
aLin[len-(i--)] = x;
|
2160
|
+
|
2161
|
+
};
|
2162
|
+
|
2163
|
+
|
2164
|
+
|
2165
|
+
|
2166
|
+
|
2167
|
+
|
2168
|
+
})(jQuery);
|
2169
|
+
|
2170
|
+
//from http://thomas.tanreisoftware.com/?p=79
|
2171
|
+
function detectSVG()
|
2172
|
+
{
|
2173
|
+
var results = { support:null, plugin:null, builtin:null };
|
2174
|
+
var obj = null;
|
2175
|
+
if ( navigator && navigator.mimeTypes && navigator.mimeTypes.length )
|
2176
|
+
{
|
2177
|
+
for ( var mime in { "image/svg+xml":null, "image/svg":null, "image/svg-xml":null } )
|
2178
|
+
{
|
2179
|
+
if ( navigator.mimeTypes[ mime ] && ( obj = navigator.mimeTypes[ mime ].enabledPlugin ) && obj )
|
2180
|
+
results = { plugin:( obj = obj.name.toLowerCase()) && obj.indexOf( "adobe" ) >= 0 ? "Adobe" : ( obj.indexOf( "renesis" ) >= 0 ? "Renesis" : "Unknown" ) };
|
2181
|
+
}
|
2182
|
+
}
|
2183
|
+
else if ( ( obj = document.createElement( "object" )) && obj && typeof obj.setAttribute( "type", "image/svg+xml" ))
|
2184
|
+
{
|
2185
|
+
if ( typeof obj.USE_SVGZ == "string" )
|
2186
|
+
results = { plugin:"Adobe", IID:"Adobe.SVGCtl", pluginVersion:obj.window && obj.window._window_impl ? ( obj.window.evalScript ? 6 : 3 ) : 2 };
|
2187
|
+
else if ( obj.window && obj.window.getSVGViewerVersion().indexOf( "enesis" ) > 0 )
|
2188
|
+
results = { plugin:"Renesis", IID:"RenesisX.RenesisCtrl.1" };
|
2189
|
+
}
|
2190
|
+
results.IID = ( results.plugin == "Adobe" ? "Adobe.SVGCtl" : ( results.plugin == "Renesis" ? "renesisX.RenesisCtrl.1" : null ));
|
2191
|
+
|
2192
|
+
// Does the browser support SVG natively? Gecko claims no support if a plugin is active, but still gives back an NSI inteface
|
2193
|
+
var claimed = document && document.implementation && document.implementation.hasFeature( "org.w3c.dom.svg", "1.0" );
|
2194
|
+
var nsi = window.Components && window.Components.interfaces && !!Components.interfaces.nsIDOMGetSVGDocument;
|
2195
|
+
results.builtin = claimed ? ( !!window.opera ? "Opera" : ( nsi ? "Gecko" : "Safari" )) : ( !!window.opera && window.opera.version ? "Opera" : ( nsi ? "Gecko" : null ));
|
2196
|
+
results.builtinVersion = results.builtin && !!window.opera ? parseFloat( window.opera.version()) : ( nsi ? ( typeof Iterator == "function" ? ( Array.reduce ? 3.0 : 2.0 ) : 1.5 ) : null );
|
2197
|
+
|
2198
|
+
// Which is active, the plugin or native support? Opera 9 makes it hard to tell..
|
2199
|
+
if ( !!window.opera && results.builtinVersion >= 9 && ( obj = document.createElement( "object" )) && obj && typeof obj.setAttribute( "type", "image/svg+xml" ) && document.appendChild( obj ))
|
2200
|
+
{
|
2201
|
+
results.support = obj.offsetWidth ? "Plugin" : "Builtin";
|
2202
|
+
document.removeChild( obj );
|
2203
|
+
}
|
2204
|
+
else results.support = results.plugin && !claimed ? "Plugin" : ( results.builtin && claimed ? "Builtin" : null );
|
2205
|
+
|
2206
|
+
return results;
|
2207
|
+
}
|
2208
|
+
|