Change version to 1.0 RC1
[raphael] / plugins / raphael.path.methods.js
1 Raphael.el.isAbsolute = true;
2 Raphael.el.absolutely = function () {
3     this.isAbsolute = 1;
4     return this;
5 };
6 Raphael.el.relatively = function () {
7     this.isAbsolute = 0;
8     return this;
9 };
10 Raphael.el.moveTo = function (x, y) {
11     this._last = {x: x, y: y};
12     return this.attr({path: this.attrs.path + ["m", "M"][+this.isAbsolute] + parseFloat(x) + " " + parseFloat(y)});
13 };
14 Raphael.el.lineTo = function (x, y) {
15     this._last = {x: x, y: y};
16     return this.attr({path: this.attrs.path + ["l", "L"][+this.isAbsolute] + parseFloat(x) + " " + parseFloat(y)});
17 };
18 Raphael.el.arcTo = function (rx, ry, large_arc_flag, sweep_flag, x, y, angle) {
19     this._last = {x: x, y: y};
20     return this.attr({path: this.attrs.path + ["a", "A"][+this.isAbsolute] + [parseFloat(rx), parseFloat(ry), +angle, large_arc_flag, sweep_flag, parseFloat(x), parseFloat(y)].join(" ")});
21 };
22 Raphael.el.curveTo = function () {
23     var args = Array.prototype.splice.call(arguments, 0, arguments.length),
24         d = [0, 0, 0, 0, "s", 0, "c"][args.length] || "";
25     this.isAbsolute && (d = d.toUpperCase());
26     this._last = {x: args[args.length - 2], y: args[args.length - 1]};
27     return this.attr({path: this.attrs.path + d + args});
28 };
29 Raphael.el.cplineTo = function (x, y, w) {
30     this.attr({path: this.attrs.path + ["C", this._last.x + w, this._last.y, x - w, y, x, y]});
31     this._last = {x: x, y: y};
32     return this;
33 };
34 Raphael.el.qcurveTo = function () {
35     var d = [0, 1, "t", 3, "q"][arguments.length],
36         args = Array.prototype.splice.call(arguments, 0, arguments.length);
37     if (this.isAbsolute) {
38         d = d.toUpperCase();
39     }
40     this._last = {x: args[args.length - 2], y: args[args.length - 1]};
41     return this.attr({path: this.attrs.path + d + args});
42 };
43 Raphael.el.addRoundedCorner = function (r, dir) {
44     var rollback = this.isAbsolute;
45     rollback && this.relatively();
46     this._last = {x: r * (!!(dir.indexOf("r") + 1) * 2 - 1), y: r * (!!(dir.indexOf("d") + 1) * 2 - 1)};
47     this.arcTo(r, r, 0, {"lu": 1, "rd": 1, "ur": 1, "dl": 1}[dir] || 0, this._last.x, this._last.y);
48     rollback && this.absolutely();
49     return this;
50 };
51 Raphael.el.andClose = function () {
52     return this.attr({path: this.attrs.path + "z"});
53 };