1 /*!
  2  * Raphael Primitives Plugin 0.2
  3  *
  4  * Copyright (c) 2009 Dmitry Baranovskiy (http://raphaeljs.com)
  5  * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
  6  */
  7 
  8 Raphael.fn.star = function (cx, cy, r, r2, rays) {
  9     r2 = r2 || r * .382;
 10     rays = rays || 5;
 11     var points = ["M", cx, cy + r2, "L"],
 12         R;
 13     for (var i = 1; i < rays * 2; i++) {
 14         R = i % 2 ? r : r2;
 15         points = points.concat([(cx + R * Math.sin(i * Math.PI / rays)), (cy + R * Math.cos(i * Math.PI / rays))]);
 16     }
 17     points.push("z");
 18     return this.path(points.join());
 19 };
 20 Raphael.fn.flower = function (cx, cy, rout, rin, n) {
 21     rin = rin || rout * .5;
 22     n = +n < 3 || !n ? 5 : n;
 23     var points = ["M", cx, cy + rin, "Q"],
 24         R;
 25     for (var i = 1; i < n * 2 + 1; i++) {
 26         R = i % 2 ? rout : rin;
 27         points = points.concat([+(cx + R * Math.sin(i * Math.PI / n)).toFixed(3), +(cy + R * Math.cos(i * Math.PI / n)).toFixed(3)]);
 28     }
 29     points.push("z");
 30     return this.path(points);
 31 };
 32 Raphael.fn.spike = function (cx, cy, rout, rin, n) {
 33     rin = rin || rout * .5;
 34     n = +n < 3 || !n ? 5 : n;
 35     var points = ["M", cx, cy - rout, "Q"],
 36         R;
 37     for (var i = 1; i < n * 2 + 1; i++) {
 38         R = i % 2 ? rin : rout;
 39         points = points.concat([cx + R * Math.sin(i * Math.PI / n - Math.PI), cy + R * Math.cos(i * Math.PI / n - Math.PI)]);
 40     }
 41     points.push("z");
 42     return this.path(points);
 43 };
 44 Raphael.fn.polyline = function () {
 45     var points = "M".concat(arguments[0] || 0, ",", arguments[1] || 0, "L");
 46     for (var i = 2, ii = arguments.length - 1; i < ii; i++) {
 47         points += arguments[i] + "," + arguments[++i];
 48     }
 49     arguments[ii].toLowerCase() == "z" && (points += "z");
 50     return this.path(points);
 51 };
 52 Raphael.fn.polygon = function (cx, cy, r, n) {
 53     n = +n < 3 || !n ? 5 : n;
 54     var points = ["M", cx, cy - r, "L"],
 55         R;
 56     for (var i = 1; i < n; i++) {
 57         points = points.concat([cx + r * Math.sin(i * Math.PI * 2 / n - Math.PI), cy + r * Math.cos(i * Math.PI * 2 / n - Math.PI)]);
 58     }
 59     points.push("z");
 60     return this.path(points);
 61 };
 62 Raphael.fn.line = function (x1, y1, x2, y2) {
 63     return this.path(["M", x1, y1, "L", x2, y2]);
 64 };
 65 Raphael.fn.drawGrid = function (x, y, w, h, wv, hv, color) {
 66     color = color || "#000";
 67     var path = ["M", x, y, "L", x + w, y, x + w, y + h, x, y + h, x, y],
 68         rowHeight = h / hv,
 69         columnWidth = w / wv;
 70     for (var i = 1; i < hv; i++) {
 71         path = path.concat(["M", x, y + i * rowHeight, "L", x + w, y + i * rowHeight]);
 72     }
 73     for (var i = 1; i < wv; i++) {
 74         path = path.concat(["M", x + i * columnWidth, y, "L", x + i * columnWidth, y + h]);
 75     }
 76     return this.path(path.join(",")).attr({stroke: color});
 77 };
 78 Raphael.fn.square = function (cx, cy, r) {
 79     r = r * .7;
 80     return this.rect(cx - r, cy - r, 2 * r, 2 * r);
 81 };
 82 Raphael.fn.triangle = function (cx, cy, r) {
 83     r *= 1.75;
 84     return this.path("M".concat(cx, ",", cy, "m0-", r * .58, "l", r * .5, ",", r * .87, "-", r, ",0z"));
 85 };
 86 Raphael.fn.diamond = function (cx, cy, r) {
 87     return this.path(["M", cx, cy - r, "l", r, r, -r, r, -r, -r, r, -r, "z"]);
 88 };
 89 Raphael.fn.cross = function (cx, cy, r) {
 90     r = r / 2.5;
 91     return this.path("M".concat(cx - r, ",", cy, "l", [-r, -r, r, -r, r, r, r, -r, r, r, -r, r, r, r, -r, r, -r, -r, -r, r, -r, -r, "z"]));
 92 };
 93 Raphael.fn.plus = function (cx, cy, r) {
 94     r = r / 2;
 95     return this.path("M".concat(cx - r / 2, ",", cy - r / 2, "l", [0, -r, r, 0, 0, r, r, 0, 0, r, -r, 0, 0, r, -r, 0, 0, -r, -r, 0, 0, -r, "z"]));
 96 };
 97 Raphael.fn.arrow = function (cx, cy, r) {
 98     return this.path("M".concat(cx - r * .7, ",", cy - r * .4, "l", [r * .6, 0, 0, -r * .4, r, r * .8, -r, r * .8, 0, -r * .4, -r * .6, 0], "z"));
 99 };
100