- var pathMethods = {
- absolutely: function () {
- this.isAbsolute = true;
- return this;
- },
- relatively: function () {
- this.isAbsolute = false;
- return this;
- },
- moveTo: function (x, y) {
- var d = this.isAbsolute ? "M" : "m";
- d += parseFloat(x).toFixed(3) + " " + parseFloat(y).toFixed(3) + " ";
- var oldD = this[0].getAttribute("d") || "";
- (oldD == "M0,0") && (oldD = "");
- this[0].setAttribute("d", oldD + d);
- this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(x);
- this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(y);
- this.attrs.path = oldD + d;
- return this;
- },
- lineTo: function (x, y) {
- this.last.x = (!this.isAbsolute * this.last.x) + parseFloat(x);
- this.last.y = (!this.isAbsolute * this.last.y) + parseFloat(y);
- var d = this.isAbsolute ? "L" : "l";
- d += parseFloat(x).toFixed(3) + " " + parseFloat(y).toFixed(3) + " ";
- var oldD = this.node.getAttribute("d") || "";
- this.node.setAttribute("d", oldD + d);
- this.attrs.path = oldD + d;
- return this;
- },
- arcTo: function (rx, ry, large_arc_flag, sweep_flag, x, y) {
- var d = this.isAbsolute ? "A" : "a";
- d += [parseFloat(rx).toFixed(3), parseFloat(ry).toFixed(3), 0, large_arc_flag, sweep_flag, parseFloat(x).toFixed(3), parseFloat(y).toFixed(3)].join(" ");
- var oldD = this[0].getAttribute("d") || "";
- this.node.setAttribute("d", oldD + d);
- this.last.x = parseFloat(x);
- this.last.y = parseFloat(y);
- this.attrs.path = oldD + d;
- return this;
- },
- cplineTo: function (x1, y1, w1) {
- if (!w1) {
- return this.lineTo(x1, y1);
- } else {
- var p = {},
- x = parseFloat(x1),
- y = parseFloat(y1),
- w = parseFloat(w1),
- d = this.isAbsolute ? "C" : "c",
- attr = [+this.last.x + w, +this.last.y, x - w, y, x, y];
- for (var i = 0, ii = attr.length; i < ii; i++) {
- d += attr[i] + " ";
- }
- this.last.x = (this.isAbsolute ? 0 : this.last.x) + attr[4];
- this.last.y = (this.isAbsolute ? 0 : this.last.y) + attr[5];
- this.last.bx = attr[2];
- this.last.by = attr[3];
- var oldD = this.node.getAttribute("d") || "";
- this.node.setAttribute("d", oldD + d);
- this.attrs.path = oldD + d;
- return this;
- }
- },
- curveTo: function () {
- var p = {},
- d = [0, 1, 2, 3, "s", 5, "c"][arguments.length];
- if (this.isAbsolute) {
- d = d.toUpperCase();
- }
- for (var i = 0, ii = arguments.length; i < ii; i++) {
- d += parseFloat(arguments[i]).toFixed(3) + " ";
- }
- this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[arguments.length - 2]);
- this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[arguments.length - 1]);
- this.last.bx = parseFloat(arguments[arguments.length - 4]);
- this.last.by = parseFloat(arguments[arguments.length - 3]);
- var oldD = this.node.getAttribute("d") || "";
- this.node.setAttribute("d", oldD + d);
- this.attrs.path = oldD + d;
- return this;
- },
- qcurveTo: function () {
- var p = {},
- d = [0, 1, "t", 3, "q"][arguments.length];
- if (this.isAbsolute) {
- d = d.toUpperCase();
- }
- for (var i = 0, ii = arguments.length; i < ii; i++) {
- d += parseFloat(arguments[i]).toFixed(3) + " ";
- }
- this.last.x = (this.isAbsolute ? 0 : this.last.x) + parseFloat(arguments[arguments.length - 2]);
- this.last.y = (this.isAbsolute ? 0 : this.last.y) + parseFloat(arguments[arguments.length - 1]);
- if (arguments.length != 2) {
- this.last.qx = parseFloat(arguments[arguments.length - 4]);
- this.last.qy = parseFloat(arguments[arguments.length - 3]);
- }
- var oldD = this.node.getAttribute("d") || "";
- this.node.setAttribute("d", oldD + d);
- this.attrs.path = oldD + d;
- return this;
- },
- addRoundedCorner: addRoundedCorner,
- andClose: function () {
- var oldD = this[0].getAttribute("d") || "";
- this[0].setAttribute("d", oldD + "Z ");
- this.attrs.path = oldD + "Z ";
- return this;
- }
- };