Plugins
authorDmitry Baranovskiy <dbaranovskiy@Fresh-Air.sydney.atlassian.com>
Tue, 15 Dec 2009 01:30:31 +0000 (12:30 +1100)
committerDmitry Baranovskiy <dbaranovskiy@Fresh-Air.sydney.atlassian.com>
Tue, 15 Dec 2009 01:30:31 +0000 (12:30 +1100)
plugins/raphael.blur.js [new file with mode: 0644]
plugins/raphael.path.methods.js
plugins/raphael.primitives.js
plugins/raphael.shadow.js [new file with mode: 0644]

diff --git a/plugins/raphael.blur.js b/plugins/raphael.blur.js
new file mode 100644 (file)
index 0000000..98fd7f9
--- /dev/null
@@ -0,0 +1,41 @@
+/*!
+ * Raphael Blur Plugin 0.1
+ *
+ * Copyright (c) 2009 Dmitry Baranovskiy (http://raphaeljs.com)
+ * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
+ */
+
+if (Raphael.vml) {
+    Raphael.el.blur = function (size) {
+        var s = this.node.style,
+            f = s.filter;
+        f = f.replace(/ progid:\S+Blur\([^\)]+\)/g, "");
+        if (size != "none") {
+            s.filter = f + " progid:DXImageTransform.Microsoft.Blur(pixelradius=" + (+size || 1.5) + ")";
+            s.margin = Raphael.format("-{0}px 0 0 -{0}px", Math.round(+size || 1.5));
+        } else {
+            s.filter = f;
+            s.margin = 0;
+        }
+    };
+} else {
+    Raphael.el.blur = function (size) {
+        // Experimental. No WebKit support.
+        if (size != "none") {
+            var fltr = $("filter"),
+                blur = $("feGaussianBlur");
+            fltr.id = "r" + (Raphael.idGenerator++).toString(36);
+            $(blur, {stdDeviation: +size || 1.5});
+            fltr.appendChild(blur);
+            this.paper.defs.appendChild(fltr);
+            this._blur = fltr;
+            $(this.node, {filter: "url(#" + fltr.id + ")"});
+        } else {
+            if (this._blur) {
+                this._blur.parentNode.removeChild(this._blur);
+                delete this._blur;
+            }
+            this.node.removeAttribute("filter");
+        }
+    };
+}
\ No newline at end of file
index bce7036..90f15c2 100644 (file)
@@ -1,3 +1,10 @@
+/*!
+ * Raphael Path Methods Plugin 0.2
+ *
+ * Copyright (c) 2009 Dmitry Baranovskiy (http://raphaeljs.com)
+ * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
+ */
+
 Raphael.el.isAbsolute = true;
 Raphael.el.absolutely = function () {
     this.isAbsolute = 1;
index c639315..af752cf 100644 (file)
@@ -1,14 +1,21 @@
-Raphael.fn.star = function (cx, cy, rout, rin, n) {
-    rin = rin || rout * .5;
-    n = +n < 3 || !n ? 5 : n;
-    var points = ["M", cx, cy + rin, "L"],
+/*!
+ * Raphael Primitives Plugin 0.2
+ *
+ * Copyright (c) 2009 Dmitry Baranovskiy (http://raphaeljs.com)
+ * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
+ */
+
+Raphael.fn.g.star = function (cx, cy, r, r2, rays) {
+    r2 = r2 || r * .382;
+    rays = rays || 5;
+    var points = ["M", cx, cy + r2, "L"],
         R;
-    for (var i = 1; i < n * 2; i++) {
-        R = i % 2 ? rout : rin;
-        points = points.concat([+(cx + R * Math.sin(i * Math.PI / n)).toFixed(3), +(cy + R * Math.cos(i * Math.PI / n)).toFixed(3)]);
+    for (var i = 1; i < rays * 2; i++) {
+        R = i % 2 ? r : r2;
+        points = points.concat([(cx + R * Math.sin(i * Math.PI / rays)), (cy + R * Math.cos(i * Math.PI / rays))]);
     }
     points.push("z");
-    return this.path(points);
+    return this.path(points.join());
 };
 Raphael.fn.flower = function (cx, cy, rout, rin, n) {
     rin = rin || rout * .5;
@@ -79,9 +86,6 @@ Raphael.fn.plus = function (cx, cy, r) {
     r = r / 2;
     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"]));
 };
-Raphael.fn.arrow = function (cx, cy, r, angle) {
-    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")).rotate(angle || 0);
+Raphael.fn.g.arrow = function (cx, cy, r) {
+    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"));
 };
-Raphael.fn.i = function (cx, cy, r) {
-    return this.path("M13.052,15.376c0,0.198-0.466,0.66-1.397,1.388c-0.932,0.728-1.773,1.092-2.526,1.092c-0.518,0-0.895-0.133-1.129-0.398s-0.352-0.564-0.352-0.897c0-0.209,0.031-0.404,0.092-0.583c0.062-0.179,0.13-0.361,0.204-0.546l1.758-3.646c0.099-0.209,0.169-0.379,0.213-0.509c0.043-0.129,0.064-0.244,0.064-0.342s-0.019-0.169-0.055-0.213c-0.037-0.043-0.087-0.064-0.148-0.064c-0.16,0-0.472,0.244-0.935,0.731c-0.462,0.487-0.737,0.731-0.823,0.731c-0.099,0-0.198-0.068-0.296-0.204s-0.148-0.222-0.148-0.259c0-0.123,0.117-0.324,0.352-0.602c0.234-0.277,0.531-0.57,0.888-0.879C9.135,9.892,9.521,9.627,9.971,9.38c0.45-0.247,0.848-0.37,1.194-0.37c0.555,0,0.972,0.158,1.249,0.472c0.278,0.314,0.417,0.694,0.417,1.138c0,0.185-0.019,0.382-0.056,0.592c-0.037,0.209-0.117,0.425-0.24,0.647l-1.407,3.09c-0.111,0.259-0.191,0.469-0.241,0.629c-0.049,0.161-0.074,0.271-0.074,0.333c0,0.074,0.019,0.121,0.055,0.139c0.037,0.018,0.074,0.027,0.111,0.027c0.271,0,0.589-0.194,0.953-0.583c0.364-0.389,0.595-0.583,0.694-0.583c0.086,0,0.179,0.064,0.278,0.194C13.002,15.237,13.052,15.327,13.052,15.376z M14.477,5.827c0,0.457-0.164,0.852-0.49,1.185c-0.327,0.333-0.725,0.5-1.194,0.5c-0.457,0-0.851-0.167-1.185-0.5c-0.333-0.333-0.5-0.728-0.5-1.185c0-0.456,0.167-0.851,0.5-1.184c0.333-0.333,0.728-0.5,1.185-0.5c0.469,0,0.867,0.167,1.194,0.5C14.313,4.976,14.477,5.371,14.477,5.827z").translate(cx - 11, cy - 11).scale((r || 20) / 20);
-};
\ No newline at end of file
diff --git a/plugins/raphael.shadow.js b/plugins/raphael.shadow.js
new file mode 100644 (file)
index 0000000..b3d7a05
--- /dev/null
@@ -0,0 +1,43 @@
+/*!
+ * Raphael Shadow Plugin 0.2
+ *
+ * Copyright (c) 2009 Dmitry Baranovskiy (http://raphaeljs.com)
+ * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
+ */
+
+Raphael.shadow = function (x, y, w, h, options) {
+    // options format: {
+    //     size: 0..1, shadow size
+    //     color: "#000", placeholder colour
+    //     stroke: "#000", placeholder stroke colour
+    //     shadow: "#000", shadow colour
+    //     r: 5, radius of placeholder rounded corners
+    // }
+    options = options || {};
+    var t = ~~(size * .3 + .5),
+        size = (options.size || 1) * 10,
+        color = options.color || "#fff",
+        stroke = options.stroke || color,
+        shadowColor = options.shadow || "#000",
+        R = options.r || 3,
+        s = size,
+        b = size * 2,
+        r = b + s,
+        rg = this.format("r{0}-{0}", shadowColor),
+        rect = "rect",
+        circ = "circle",
+        none = "none";
+    var res = this([
+        x - s, y - t, w + (x = s) * 2, h + (y = t) + b,
+        {type: rect, x: x - s, y: y - t, width: b + s, height: h + y + b, stroke: none, fill: this.format("180-{0}-{0}", shadowColor), opacity: 0, "clip-rect": [x - s + 1, y - t + r, b, h + y + b - r * 2 + .9]},
+        {type: rect, x: x + w - b, y: y - t, width: b + s, height: h + y + b, stroke: none, fill: this.format("0-{0}-{0}", shadowColor), opacity: 0, "clip-rect": [x + w - s + 1, y - t + r, b, h + y + b - r * 2]},
+        {type: rect, x: x + b - 1, y: y + h - s, width: w + b, height: b + s, stroke: none, fill: this.format("270-{0}-{0}", shadowColor), opacity: 0, "clip-rect": [x + b, y + h - s, w + b - r * 2, b + s]},
+        {type: rect, x: x + s - 1, y: y - t, width: w + b, height: b + s, stroke: none, fill: this.format("90-{0}-{0}", shadowColor), opacity: 0, "clip-rect": [x + b, y - t, w + b - r * 2, s + t + 1]},
+        {type: circ, cx: x + b, cy: y + h - s, r: r, stroke: none, fill: rg, opacity: 0, "clip-rect": [x - s, y + h - s + .999, r, r]},
+        {type: circ, cx: x + w - b, cy: y + h - s, r: r, stroke: none, fill: rg, opacity: 0, "clip-rect": [x + w - b, y + h - s, r, r]},
+        {type: circ, cx: x + b, cy: y - t + r, r: r, stroke: none, fill: rg, opacity: 0, "clip-rect": [x - s, y - t, r, r]},
+        {type: circ, cx: x + w - b, cy: y - t + r, r: r , stroke: none, fill: rg, opacity: 0, "clip-rect": [x + w - b, y - t, r, r]},
+        {type: rect, x: x, y: y, width: w, height: h, r: R, fill: color, stroke: stroke}
+        ]);
+    return res[0].paper;
+};
\ No newline at end of file