/*
- * Raphael 0.7 - JavaScript Vector Library
+ * Raphael 0.7.dev - JavaScript Vector Library
*
* Copyright (c) 2008 – 2009 Dmitry Baranovskiy (http://raphaeljs.com)
* Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
*/
-function Raphael() {
- return Raphael._create.apply(Raphael, arguments);
-};
-(function (R) {
- R.version = "0.7";
+var Raphael = (function () {
+ var separator = /[, ]+/,
+ create,
+ R = function () {
+ return create.apply(R, arguments);
+ };
+ R.version = "0.7.dev";
R.type = (window.SVGAngle ? "SVG" : "VML");
R.svg = !(R.vml = R.type == "VML");
R.idGenerator = 0;
var paper = {};
R.fn = {};
var availableAttrs = {cx: 0, cy: 0, fill: "#fff", "fill-opacity": 1, font: '16px "Arial"', "font-family": '"Arial"', "font-size": "16", gradient: 0, height: 0, opacity: 1, path: "M0,0", r: 0, rotation: 0, rx: 0, ry: 0, scale: "1 1", stroke: "#000", "stroke-dasharray": "", "stroke-linecap": "butt", "stroke-linejoin": "butt", "stroke-miterlimit": 0, "stroke-opacity": 1, "stroke-width": 1, translation: "0 0", width: 0, x: 0, y: 0},
- availableAnimAttrs = {cx: "number", cy: "number", fill: "colour", "fill-opacity": "number", "font-size": "number", height: "number", opacity: "number", path: "path", r: "number", rotation: "number", rx: "number", ry: "number", scale: "csv", stroke: "colour", "stroke-opacity": "number", "stroke-width": "number", translation: "csv", width: "number", x: "number", y: "number"};
+ availableAnimAttrs = {cx: "number", cy: "number", fill: "colour", "fill-opacity": "number", "font-size": "number", height: "number", opacity: "number", path: "path", r: "number", rotation: "csv", rx: "number", ry: "number", scale: "csv", stroke: "colour", "stroke-opacity": "number", "stroke-width": "number", translation: "csv", width: "number", x: "number", y: "number"};
R.toString = function () {
return "Your browser " + (this.vml ? "doesn't ": "") + "support" + (this.svg ? "s": "") +
" SVG.\nYou are running " + unescape("Rapha%EBl%20") + this.version;
};
- // generic utilities
- R.hsb2rgb = function (hue, saturation, brightness) {
+ // colour utilities
+ var hsb2rgb = function (hue, saturation, brightness) {
if (typeof hue == "object" && "h" in hue && "s" in hue && "b" in hue) {
brightness = hue.b;
saturation = hue.s;
blue;
if (brightness == 0) {
return {r: 0, g: 0, b: 0, hex: "#000"};
- } else {
- var i = Math.floor(hue * 6),
- f = (hue * 6) - i,
- p = brightness * (1 - saturation),
- q = brightness * (1 - (saturation * f)),
- t = brightness * (1 - (saturation * (1 - f)));
- [
- function () {red = brightness; green = t; blue = p;},
- function () {red = q; green = brightness; blue = p;},
- function () {red = p; green = brightness; blue = t;},
- function () {red = p; green = q; blue = brightness;},
- function () {red = t; green = p; blue = brightness;},
- function () {red = brightness; green = p; blue = q;},
- function () {red = brightness; green = t; blue = p;}
- ][i]();
}
- var rgb = {r: red, g: green, b: blue};
+ if (hue > 1 || saturation > 1 || brightness > 1) {
+ hue /= 255;
+ saturation /= 255;
+ brightness /= 255;
+ }
+ var i = Math.floor(hue * 6),
+ f = (hue * 6) - i,
+ p = brightness * (1 - saturation),
+ q = brightness * (1 - (saturation * f)),
+ t = brightness * (1 - (saturation * (1 - f)));
+ red = [brightness, q, p, p, t, brightness, brightness][i];
+ green = [t, brightness, brightness, q, p, p, t][i];
+ blue = [p, p, t, brightness, brightness, q, p][i];
red *= 255;
green *= 255;
blue *= 255;
+ var rgb = {r: red, g: green, b: blue};
var r = Math.round(red).toString(16);
if (r.length == 1) {
r = "0" + r;
rgb.hex = "#" + r + g + b;
return rgb;
};
- R.rgb2hsb = function (red, green, blue) {
- if (typeof red == "object" && "r" in red && "g" in red && "b" in red) {
- blue = red.b;
- green = red.g;
- red = red.r;
+ var getRGB = function (colour) {
+ var htmlcolors = {aliceblue: "#f0f8ff", amethyst: "#96c", antiquewhite: "#faebd7", aqua: "#0ff", aquamarine: "#7fffd4", azure: "#f0ffff", beige: "#f5f5dc", bisque: "#ffe4c4", black: "#000", blanchedalmond: "#ffebcd", blue: "#00f", blueviolet: "#8a2be2", brown: "#a52a2a", burlywood: "#deb887", cadetblue: "#5f9ea0", chartreuse: "#7fff00", chocolate: "#d2691e", coral: "#ff7f50", cornflowerblue: "#6495ed", cornsilk: "#fff8dc", crimson: "#dc143c", cyan: "#0ff", darkblue: "#00008b", darkcyan: "#008b8b", darkgoldenrod: "#b8860b", darkgray: "#a9a9a9", darkgreen: "#006400", darkkhaki: "#bdb76b", darkmagenta: "#8b008b", darkolivegreen: "#556b2f", darkorange: "#ff8c00", darkorchid: "#9932cc", darkred: "#8b0000", darksalmon: "#e9967a", darkseagreen: "#8fbc8f", darkslateblue: "#483d8b", darkslategray: "#2f4f4f", darkturquoise: "#00ced1", darkviolet: "#9400d3", deeppink: "#ff1493", deepskyblue: "#00bfff", dimgray: "#696969", dodgerblue: "#1e90ff", firebrick: "#b22222", floralwhite: "#fffaf0", forestgreen: "#228b22", fuchsia: "#f0f", gainsboro: "#dcdcdc", ghostwhite: "#f8f8ff", gold: "#ffd700", goldenrod: "#daa520", gray: "#808080", green: "#008000", greenyellow: "#adff2f", honeydew: "#f0fff0", hotpink: "#ff69b4", indianred: "#cd5c5c", indigo: "#4b0082", ivory: "#fffff0", khaki: "#f0e68c", lavender: "#e6e6fa", lavenderblush: "#fff0f5", lawngreen: "#7cfc00", lemonchiffon: "#fffacd", lightblue: "#add8e6", lightcoral: "#f08080", lightcyan: "#e0ffff", lightgoldenrodyellow: "#fafad2", lightgreen: "#90ee90", lightgrey: "#d3d3d3", lightpink: "#ffb6c1", lightsalmon: "#ffa07a", lightsalmon: "#ffa07a", lightseagreen: "#20b2aa", lightskyblue: "#87cefa", lightslategray: "#789", lightsteelblue: "#b0c4de", lightyellow: "#ffffe0", lime: "#0f0", limegreen: "#32cd32", linen: "#faf0e6", magenta: "#f0f", maroon: "#800000", mediumaquamarine: "#66cdaa", mediumblue: "#0000cd", mediumorchid: "#ba55d3", mediumpurple: "#9370db", mediumseagreen: "#3cb371", mediumslateblue: "#7b68ee", mediumslateblue: "#7b68ee", mediumspringgreen: "#00fa9a", mediumturquoise: "#48d1cc", mediumvioletred: "#c71585", midnightblue: "#191970", mintcream: "#f5fffa", mistyrose: "#ffe4e1", moccasin: "#ffe4b5", navajowhite: "#ffdead", navy: "#000080", oldlace: "#fdf5e6", olive: "#808000", olivedrab: "#6b8e23", orange: "#ffa500", orangered: "#ff4500", orchid: "#da70d6", palegoldenrod: "#eee8aa", palegreen: "#98fb98", paleturquoise: "#afeeee", palevioletred: "#db7093", papayawhip: "#ffefd5", peachpuff: "#ffdab9", peru: "#cd853f", pink: "#ffc0cb", plum: "#dda0dd", powderblue: "#b0e0e6", purple: "#800080", red: "#f00", rosybrown: "#bc8f8f", royalblue: "#4169e1", saddlebrown: "#8b4513", salmon: "#fa8072", sandybrown: "#f4a460", seagreen: "#2e8b57", seashell: "#fff5ee", sienna: "#a0522d", silver: "#c0c0c0", skyblue: "#87ceeb", slateblue: "#6a5acd", slategray: "#708090", snow: "#fffafa", springgreen: "#00ff7f", steelblue: "#4682b4", tan: "#d2b48c", teal: "#008080", thistle: "#d8bfd8", tomato: "#ff6347", turquoise: "#40e0d0", violet: "#ee82ee", wheat: "#f5deb3", white: "#fff", whitesmoke: "#f5f5f5", yellow: "#ff0", yellowgreen: "#9acd32"};
+ if (colour.toString().toLowerCase() in htmlcolors) {
+ colour = htmlcolors[colour.toString().toLowerCase()];
}
- if (typeof red == "string" && red.charAt(0) == "#") {
- if (red.length == 4) {
- blue = parseInt(red.substring(3), 16);
- green = parseInt(red.substring(2, 3), 16);
- red = parseInt(red.substring(1, 2), 16);
- } else {
- blue = parseInt(red.substring(5), 16);
- green = parseInt(red.substring(3, 5), 16);
- red = parseInt(red.substring(1, 3), 16);
- }
- }
- if (red > 1 || green > 1 || blue > 1) {
- red /= 255;
- green /= 255;
- blue /= 255;
+ if (!colour) {
+ return {r: 0, g: 0, b: 0, hex: "#000"};
}
- var max = Math.max(red, green, blue),
- min = Math.min(red, green, blue),
- hue,
- saturation,
- brightness = max;
- if (min == max) {
- return {h: 0, s: 0, b: max};
- } else {
- var delta = (max - min);
- saturation = delta / max;
- if (red == max) {
- hue = (green - blue) / delta;
- } else if (green == max) {
- hue = 2 + ((blue - red) / delta);
- } else {
- hue = 4 + ((red - green) / delta);
- }
- hue /= 6;
- if (hue < 0) {
- hue += 1;
- }
- if (hue > 1) {
- hue -= 1;
- }
+ if (colour == "none") {
+ return {r: -1, g: -1, b: -1, hex: "none"};
}
- return {h: hue, s: saturation, b: brightness};
- };
- R.getRGB = function (colour) {
var red, green, blue,
- rgb = colour.match(/^\s*((#[a-f\d]{6})|(#[a-f\d]{3})|rgb\(\s*(\d+,\s*\d+,\s*\d+)\s*\)|rgb\(\s*(\d+%,\s*\d+%,\s*\d+%)\s*\)|hsb\(\s*(\d+,\s*\d+,\s*\d+)\s*\)|hsb\(\s*(\d+%,\s*\d+%,\s*\d+%)\s*\))\s*$/i);
+ rgb = colour.match(/^\s*((#[a-f\d]{6})|(#[a-f\d]{3})|rgb\(\s*([\d\.]+\s*,\s*[\d\.]+\s*,\s*[\d\.]+)\s*\)|rgb\(\s*([\d\.]+%\s*,\s*[\d\.]+%\s*,\s*[\d\.]+%)\s*\)|hsb\(\s*([\d\.]+\s*,\s*[\d\.]+\s*,\s*[\d\.]+)\s*\)|hsb\(\s*([\d\.]+%\s*,\s*[\d\.]+%\s*,\s*[\d\.]+%)\s*\))\s*$/i);
if (rgb) {
if (rgb[2]) {
blue = parseInt(rgb[2].substring(5), 16);
}
if (rgb[4]) {
rgb = rgb[4].split(/\s*,\s*/);
- red = parseInt(rgb[0], 10);
- green = parseInt(rgb[1], 10);
- blue = parseInt(rgb[2], 10);
+ red = parseFloat(rgb[0], 10);
+ green = parseFloat(rgb[1], 10);
+ blue = parseFloat(rgb[2], 10);
}
if (rgb[5]) {
rgb = rgb[5].split(/\s*,\s*/);
- red = parseInt(rgb[0], 10) * 2.55;
- green = parseInt(rgb[1], 10) * 2.55;
- blue = parseInt(rgb[2], 10) * 2.55;
+ red = parseFloat(rgb[0], 10) * 2.55;
+ green = parseFloat(rgb[1], 10) * 2.55;
+ blue = parseFloat(rgb[2], 10) * 2.55;
}
if (rgb[6]) {
rgb = rgb[6].split(/\s*,\s*/);
- red = parseInt(rgb[0], 10);
- green = parseInt(rgb[1], 10);
- blue = parseInt(rgb[2], 10);
- return this.hsb2rgb(red, green, blue);
+ red = parseFloat(rgb[0], 10);
+ green = parseFloat(rgb[1], 10);
+ blue = parseFloat(rgb[2], 10);
+ return hsb2rgb(red, green, blue);
}
if (rgb[7]) {
rgb = rgb[7].split(/\s*,\s*/);
- red = parseInt(rgb[0], 10) * 2.55;
- green = parseInt(rgb[1], 10) * 2.55;
- blue = parseInt(rgb[2], 10) * 2.55;
- return this.hsb2rgb(red, green, blue);
+ red = parseFloat(rgb[0], 10) * 2.55;
+ green = parseFloat(rgb[1], 10) * 2.55;
+ blue = parseFloat(rgb[2], 10) * 2.55;
+ return hsb2rgb(red, green, blue);
}
var rgb = {r: red, g: green, b: blue};
var r = Math.round(red).toString(16);
(b.length == 1) && (b = "0" + b);
rgb.hex = "#" + r + g + b;
return rgb;
+ } else {
+ return {r: -1, g: -1, b: -1, hex: "none"};
}
};
R.getColor = function (value) {
var start = arguments.callee.start = arguments.callee.start || {h: 0, s: 1, b: value || .75};
- var rgb = this.hsb2rgb(start.h, start.s, start.b);
+ var rgb = hsb2rgb(start.h, start.s, start.b);
start.h += .075;
if (start.h > 1) {
start.h = 0;
R.getColor.reset = function () {
this.start = undefined;
};
+ // path utilities
R.parsePathString = function (pathString) {
var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, q: 4, s: 4, t: 2, v: 1, z: 0},
data = [],
data.toString = toString;
return data;
};
- R.pathDimensions = function (path) {
+ var pathDimensions = function (path) {
var pathArray = path;
if (typeof path == "string") {
- pathArray = this.parsePathString(path);
+ pathArray = Raphael.parsePathString(path);
}
- pathArray = this.pathToAbsolute(pathArray);
+ pathArray = pathToAbsolute(pathArray);
var x = [], y = [], length = 0;
for (var i = 0, ii = pathArray.length; i < ii; i++) {
switch (pathArray[i][0]) {
Y: y
};
};
- R.pathToRelative = function (pathArray) {
+ var pathToRelative = function (pathArray) {
var res = [];
if (typeof pathArray == "string") {
- pathArray = this.parsePathString(pathArray);
+ pathArray = R.parsePathString(pathArray);
}
var x = 0, y = 0, start = 0;
if (pathArray[0][0] == "M") {
res.toString = pathArray.toString;
return res;
};
- R.pathToAbsolute = function (pathArray) {
+ var pathToAbsolute = function (pathArray) {
var res = [];
if (typeof pathArray == "string") {
- pathArray = this.parsePathString(pathArray);
+ pathArray = R.parsePathString(pathArray);
}
var x = 0, y = 0, start = 0;
if (pathArray[0][0] == "M") {
res.toString = pathArray.toString;
return res;
};
- R.pathEqualiser = function (path1, path2) {
- var data = [this.pathToAbsolute(this.parsePathString(path1)), this.pathToAbsolute(this.parsePathString(path2))],
+ var pathEqualiser = function (path1, path2) {
+ var data = [pathToAbsolute(Raphael.parsePathString(path1)), pathToAbsolute(Raphael.parsePathString(path2))],
attrs = [{x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0}, {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0}],
processPath = function (path, d) {
if (!path) {
for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
var stop = document.createElementNS(SVG.svgns, "stop");
stop.setAttribute("offset", gradient.dots[i].offset ? gradient.dots[i].offset : (i == 0) ? "0%" : "100%");
- stop.setAttribute("stop-color", gradient.dots[i].color || "#fff");
+ stop.setAttribute("stop-color", getRGB(gradient.dots[i].color).hex || "#fff");
if (typeof gradient.dots[i].opacity != "undefined") {
stop.setAttribute("stop-opacity", gradient.dots[i].opacity);
}
o.rotate(value, true);
break;
case "translation":
- var xy = value.split(/[, ]+/);
+ var xy = value.split(separator);
o.translate(xy[0], xy[1]);
break;
case "scale":
- var xy = value.split(/[, ]+/);
+ var xy = value.split(separator);
o.scale(xy[0], xy[1]);
break;
case "fill":
updatePosition(o);
break;
}
+ case "stroke":
+ o.node.style[att] = getRGB(value).hex;
+ // Need following line for Firefox
+ o.node.setAttribute(att, getRGB(value).hex);
+ break;
default :
var cssrule = att.replace(/(\-.)/g, function (w) {
return w.substring(1).toUpperCase();
this.attr({x: this.attrs.x + x, y: this.attrs.y + y});
break;
case "path":
- var path = Raphael.pathToRelative(this.attrs.path);
+ var path = pathToRelative(this.attrs.path);
path[0][1] += +x;
path[0][2] += +y;
this.attr({path: path.join(" ")});
}
return this;
};
- Element.prototype.rotate = function (deg, isAbsolute) {
- if (deg == undefined) {
+ Element.prototype.rotate = function (deg, cx, cy) {
+ if (deg == null) {
return this._.rt.deg;
}
var bbox = this.getBBox();
- if (isAbsolute) {
+ deg = deg.toString().split(separator);
+ if (deg.length - 1) {
+ cx = parseFloat(deg[1], 10);
+ cy = parseFloat(deg[2], 10);
+ }
+ deg = parseFloat(deg[0], 10);
+ if (cx != null) {
this._.rt.deg = deg;
} else {
this._.rt.deg += deg;
}
-
+ if (cy == null) {
+ cx = null;
+ }
+ cx = cx == null ? bbox.x + bbox.width / 2 : cx;
+ cy = cy == null ? bbox.y + bbox.height / 2 : cy;
if (this._.rt.deg) {
- this.transformations[0] = ("rotate(" + this._.rt.deg + " " + (bbox.x + bbox.width / 2) + " " + (bbox.y + bbox.height / 2) + ")");
+ this.transformations[0] = ("rotate(" + this._.rt.deg + " " + cx + " " + cy + ")");
} else {
this.transformations[0] = "";
}
i.type = "group";
return i;
};
- R._create = function () {
+ create = function () {
// container, width, height
// x, y, width, height
if (typeof arguments[0] == "string") {
p.attrs.path = "";
paper.pathfinder(p, "" + pathString);
}
- p.setBox();
+ // p.setBox();
setFillAndStroke(p, params);
if (params.gradient) {
addGrdientFill(p, params.gradient);
paper.pathfinder(o, params.path);
}
if (params.rotation != null) {
- o.Group.style.rotation = params.rotation;
+ o.rotate(params.rotation, true);
}
if (params.translation) {
- var xy = params.translation.split(/[, ]+/);
+ var xy = params.translation.split(separator);
o.translate(xy[0], xy[1]);
}
if (params.scale) {
- var xy = params.scale.split(/[, ]+/);
+ var xy = params.scale.split(separator);
o.scale(xy[0], xy[1]);
}
if (o.type == "image" && params.opacity) {
fill.src = isURL[1];
fill.type = "tile";
} else {
- fill.color = params.fill;
+ fill.color = getRGB(params.fill).hex;
fill.src = "";
fill.type = "solid";
}
stroke.on = false;
}
if (stroke.on && params.stroke) {
- stroke.color = params.stroke;
+ stroke.color = getRGB(params.stroke).hex;
}
stroke.opacity = ((params["stroke-opacity"] + 1 || 2) - 1) * ((params.opacity + 1 || 2) - 1);
params["stroke-linejoin"] && (stroke.joinstyle = params["stroke-linejoin"] || "miter");
fill.method = "none";
fill.type = (gradient.type.toLowerCase() == "linear") ? "gradient" : "gradientTitle";
if (typeof gradient.dots[0].color != "undefined") {
- fill.color = gradient.dots[0].color || "#000";
+ fill.color = getRGB(gradient.dots[0].color).hex;
}
if (typeof gradient.dots[gradient.dots.length - 1].color != "undefined") {
- fill.color2 = gradient.dots[gradient.dots.length - 1].color || "#000";
+ fill.color2 = getRGB(gradient.dots[gradient.dots.length - 1].color).hex;
}
var colors = [];
for (var i = 0, ii = gradient.dots.length; i < ii; i++) {
if (gradient.dots[i].offset) {
- colors.push(gradient.dots[i].offset + " " + gradient.dots[i].color);
+ colors.push(gradient.dots[i].offset + " " + getRGB(gradient.dots[i].color).hex);
}
};
var fillOpacity = typeof gradient.dots[0].opacity == "undefined" ? 1 : gradient.dots[0].opacity;
this._ = {
tx: 0,
ty: 0,
- rt: 0,
+ rt: {deg:0},
sx: 1,
sy: 1
};
};
- Element.prototype.rotate = function (deg, isAbsolute) {
- if (deg == undefined) {
- return this._.rt;
+ Element.prototype.rotate = function (deg, cx, cy) {
+ if (deg == null) {
+ return this._.rt.deg;
+ }
+ deg = deg.toString().split(separator);
+ if (deg.length - 1) {
+ cx = parseFloat(deg[1], 10);
+ cy = parseFloat(deg[2], 10);
}
- if (isAbsolute) {
- this._.rt = deg;
+ deg = parseFloat(deg[0], 10);
+ if (cy == null) {
+ cx = null;
+ }
+ if (cx != null) {
+ this._.rt.deg = deg;
} else {
- this._.rt += deg;
+ this._.rt.deg += deg;
}
- this.Group.style.rotation = this._.rt;
+ this._.rt.cx = cx;
+ this._.rt.cy = cy;
+ this.setBox(null, cx, cy);
+ this.Group.style.rotation = this._.rt.deg;
return this;
};
- Element.prototype.setBox = function (params) {
+ Element.prototype.setBox = function (params, cx, cy) {
var gs = this.Group.style,
os = (this.shape && this.shape.style) || this.node.style;
for (var i in params) {
this.attrs[i] = params[i];
}
+ cx = cx || this._.rt.cx;
+ cy = cy || this._.rt.cy;
var attr = this.attrs, x, y, w, h;
switch (this.type) {
case "circle":
w = this.vml.width;
h = this.vml.height;
} else {
- var dim = Raphael.pathDimensions(this.attrs.path),
+ var dim = pathDimensions(this.attrs.path),
x = dim.x;
y = dim.y;
w = dim.width;
h = this.vml.height;
break;
}
+ cx = (cx == null) ? x + w / 2 : cx;
+ cy = (cy == null) ? y + h / 2 : cy;
+ var left = cx - this.vml.width / 2,
+ top = cy - this.vml.height / 2;
if (this.type == "path" || this.type == "text") {
- var left = Math.round(this.vml.width / 2 - w / 2 - x),
- top = Math.round(this.vml.height / 2 - h / 2 - y);
- gs.left = - left + "px";
- gs.top = - top + "px";
- this.X = this.type == "text" ? x : left;
- this.Y = this.type == "text" ? y : top;
+ gs.left = left + "px";
+ gs.top = top + "px";
+ this.X = this.type == "text" ? x : -left;
+ this.Y = this.type == "text" ? y : -top;
this.W = w;
this.H = h;
- os.top = top + "px";
- os.left = left + "px";
+ os.left = -left + "px";
+ os.top = -top + "px";
} else {
- var left = this.vml.width / 2 - w / 2,
- top = this.vml.height / 2 - h / 2;
- gs.position = "absolute";
- gs.left = x - left + "px";
- gs.top = y - top + "px";
+ gs.left = left + "px";
+ gs.top = top + "px";
this.X = x - left;
this.Y = y - top;
this.W = w;
this.H = h;
gs.width = this.vml.width + "px";
gs.height = this.vml.height + "px";
- os.position = "absolute";
- os.top = top + "px";
- os.left = left + "px";
+ os.left = x - left + "px";
+ os.top = y - top + "px";
os.width = w + "px";
os.height = h + "px";
}
this._.ty += +y;
if (this.type == "path") {
var path = this.attrs.path;
- path = Raphael.pathToRelative(path);
+ path = pathToRelative(path);
path[0][1] += +x;
path[0][2] += +y;
this.attr({path: path.join(" ")});
};
return values;
}
- if (this.node.tagName.toLowerCase() == "group") {
- var children = this[0].childNodes;
- this.attrs = this.attrs || {};
- if (arguments.length == 2) {
- this.attrs[arguments[0]] = arguments[1];
- } else if (arguments.length == 1 || typeof arguments[0] == "object") {
- for (var j in arguments[0]) {
- this.attrs[j] = arguments[0][j];
- }
- }
- for (var i = 0, ii = children.length; i < ii; i++) {
- this.attr.apply(new item(children[i], this[0], this.vml), arguments);
- }
- } else {
- var params;
- if (arguments.length == 2) {
- params = {};
- params[arguments[0]] = arguments[1];
+ var params;
+ if (arguments.length == 2) {
+ params = {};
+ params[arguments[0]] = arguments[1];
+ }
+ if (arguments.length == 1 && typeof arguments[0] == "object") {
+ params = arguments[0];
+ }
+ if (params) {
+ if (params.gradient) {
+ addGrdientFill(this, params.gradient);
}
- if (arguments.length == 1 && typeof arguments[0] == "object") {
- params = arguments[0];
+ if (params.text && this.type == "text") {
+ this.node.string = params.text;
}
- if (params) {
- if (params.gradient) {
- addGrdientFill(this, params.gradient);
- }
- if (params.text && this.type == "text") {
- this.node.string = params.text;
- }
- if (params.id) {
- this.node.id = params.id;
- }
- setFillAndStroke(this, params);
- this.setBox(params);
+ if (params.id) {
+ this.node.id = params.id;
}
+ setFillAndStroke(this, params);
+ this.setBox(params);
}
return this;
};
var res = new Element(o, g, vml);
res.type = "circle";
setFillAndStroke(res, {stroke: "#000", fill: "none"});
- res.setBox({x: x - r, y: y - r, width: r * 2, height: r * 2});
res.attrs.cx = x;
res.attrs.cy = y;
res.attrs.r = r;
+ res.setBox({x: x - r, y: y - r, width: r * 2, height: r * 2});
return res;
};
var theRect = function (vml, x, y, w, h, r) {
var res = new Element(o, g, vml);
res.type = "rect";
setFillAndStroke(res, {stroke: "#000"});
- res.setBox({x: x, y: y, width: w, height: h});
res.attrs.x = x;
res.attrs.y = y;
res.attrs.w = w;
res.attrs.h = h;
res.attrs.r = r;
+ res.setBox({x: x, y: y, width: w, height: h});
return res;
};
var theEllipse = function (vml, x, y, rx, ry) {
var res = new Element(o, g, vml);
res.type = "ellipse";
setFillAndStroke(res, {stroke: "#000"});
- res.setBox({x: x - rx, y: y - ry, width: rx * 2, height: ry * 2});
res.attrs.cx = x;
res.attrs.cy = y;
res.attrs.rx = rx;
res.attrs.ry = ry;
+ res.setBox({x: x - rx, y: y - ry, width: rx * 2, height: ry * 2});
return res;
};
var theImage = function (vml, src, x, y, w, h) {
vml.canvas.appendChild(g);
var res = new Element(o, g, vml);
res.type = "image";
- res.setBox({x: x, y: y, width: w, height: h});
res.attrs.x = x;
res.attrs.y = y;
res.attrs.w = w;
res.attrs.h = h;
+ res.setBox({x: x, y: y, width: w, height: h});
return res;
};
var theText = function (vml, x, y, text) {
setFillAndStroke(res, {font: '10px "Arial"', stroke: "none", fill: "#000"});
return res;
};
- var theGroup = function (vml) {
- return this;
- };
- R._create = function () {
+ create = function () {
// container, width, height
// x, y, width, height
var container, width, height;
// Events
var addEvent = (function () {
if (document.addEventListener) {
- return function (obj, type, fn) {
- obj.addEventListener(type, fn, false);
+ return function (obj, type, fn, element) {
+ obj.addEventListener(type, function (e) {
+ return fn.call(element, e);
+ }, false);
};
} else if (document.attachEvent) {
- return function (obj, type, fn) {
- var f = function (e) {
- fn.call(this, e || window.event);
- };
- obj.attachEvent("on" + type, f);
+ return function (obj, type, fn, element) {
+ obj.attachEvent("on" + type, function (e) {
+ return fn.call(element, e || window.event);
+ });
};
}
})();
for (var i = events.length; i--;) {
(function (eventName) {
Element.prototype[eventName] = function (fn) {
- addEvent(this.node, eventName, fn);
+ addEvent(this.node, eventName, fn, this);
return this;
};
})(events[i]);
}
-
- // Set
- var Set = function (itemsArray) {
- this.items = [];
- if (itemsArray && itemsArray.constructor == Array) {
- for (var i = itemsArray.length; i--;) {
- if (itemsArray[i].constructor == Element) {
- this.items[this.items.length] = itemsArray[i];
- }
- }
- }
- };
- Set.prototype.add = function (item) {
- if (item && item.constructor == Element) {
- this.items[this.items.length] = item;
- }
- return this;
- };
- Set.prototype.remove = function (item) {
- if (item && item.constructor == Element) {
- for (var i = this.items.length; i--;) {
- if (this.items[i] == item) {
- this.items.splice(i, 1);
- return this;
- }
- }
- }
- return this;
- };
- for (var method in Element.prototype) {
- Set.prototype[method] = (function (methodname) {
- return function () {
- for (var i = this.items.length; i--;) {
- this.items[i][methodname].apply(this.items[i], arguments);
- }
- return this;
- };
- })(method);
- }
- Set.prototype.getBBox = function () {
- var x = [], y = [], w = [], h = [];
- for (var i = this.items.length; i--;) {
- var box = this.items[i].getBBox();
- x.push(box.x);
- y.push(box.y);
- w.push(box.x + box.width);
- h.push(box.y + box.height);
- }
- x = Math.min(x);
- y = Math.min(y);
- return {
- x: x,
- y: y,
- w: Math.max(w) - x,
- h: Math.max(h) - y
- };
- };
-
paper.circle = function (x, y, r) {
return theCircle(this, x, y, r);
};
}
};
- path = Raphael.pathToAbsolute(path);
+ path = pathToAbsolute(path);
for (var i = 0, ii = path.length; i < ii; i++) {
var b = path[i].shift();
commands[b].apply(p, path[i]);
});
break;
case "path":
- var path = Raphael.pathToRelative(Raphael.parsePathString(this.attr("path"))),
+ var path = pathToRelative(Raphael.parsePathString(this.attr("path"))),
skip = true,
- dim = Raphael.pathDimensions(this.attrs.path),
+ dim = pathDimensions(this.attrs.path),
dx = -dim.width * (x - 1) / 2,
dy = -dim.height * (y - 1) / 2;
for (var i = 0, ii = path.length; i < ii; i++) {
}
}
}
- var dim2 = Raphael.pathDimensions(path),
+ var dim2 = pathDimensions(path),
dx = dim.x + dim.width / 2 - dim2.x - dim2.width / 2,
dy = dim.y + dim.height / 2 - dim2.y - dim2.height / 2;
- path = Raphael.pathToRelative(path);
+ path = pathToRelative(path);
path[0][1] += dx;
path[0][2] += dy;
};
Element.prototype.animate = function (params, ms, callback) {
clearTimeout(this.animation_in_progress);
- var from = {}, to = {}, diff = {}, t = {x: 0, y: 0};
+ var from = {},
+ to = {},
+ diff = {},
+ t = {x: 0, y: 0};
for (var attr in params) {
if (attr in availableAnimAttrs) {
from[attr] = this.attr(attr);
diff[attr] = (to[attr] - from[attr]) / ms;
break;
case "colour":
- from[attr] = Raphael.getRGB(from[attr]);
- var toColour = Raphael.getRGB(to[attr]);
+ from[attr] = getRGB(from[attr]);
+ var toColour = getRGB(to[attr]);
diff[attr] = {
r: (toColour.r - from[attr].r) / ms,
g: (toColour.g - from[attr].g) / ms,
};
break;
case "path":
- var pathes = Raphael.pathEqualiser(from[attr], to[attr]);
+ var pathes = pathEqualiser(from[attr], to[attr]);
from[attr] = pathes[0];
to[attr] = pathes[1];
diff[attr] = [];
}
break;
case "csv":
- var values = params[attr].split(/[, ]+/);
+ var values = params[attr].toString().split(separator),
+ from2 = from[attr].toString().split(separator);
if (attr == "translation") {
from[attr] = [0, 0];
diff[attr] = [values[0] / ms, values[1] / ms];
+ } else if (attr == "rotation") {
+ from[attr] = (from2[1] == values[1] && from2[2] == values[2]) ? from2 : [0, values[1], values[2]];
+ diff[attr] = [(values[0] - from[attr][0]) / ms, 0, 0];
} else {
- from[attr] = from[attr].split(/[, ]+/);
+ from[attr] = from[attr].split(separator);
diff[attr] = [(values[0] - from[attr][0]) / ms, (values[1] - from[attr][0]) / ms];
}
to[attr] = values;
t.x += x;
t.y += y;
now = [x, y].join(" ");
+ } else if (attr == "rotation") {
+ now = +from[attr][0] + time * diff[attr][0];
+ from[attr][1] && (now += "," + from[attr][1] + "," + from[attr][2]);
} else {
now = [+from[attr][0] + time * diff[attr][0], +from[attr][1] + time * diff[attr][1]].join(" ");
}
that.animation_in_progress = setTimeout(arguments.callee, 0);
paper.safari();
} else {
- if (t.x || t.y) {
- that.translate(-t.x, -t.y);
- }
+ (t.x || t.y) && that.translate(-t.x, -t.y);
that.attr(params);
clearTimeout(that.animation_in_progress);
paper.safari();
return this;
};
+ // Set
+ var Set = function (itemsArray) {
+ this.items = [];
+ if (itemsArray && itemsArray.constructor == Array) {
+ for (var i = itemsArray.length; i--;) {
+ if (itemsArray[i].constructor == Element) {
+ this.items[this.items.length] = itemsArray[i];
+ }
+ }
+ }
+ };
+ Set.prototype.push = function (item) {
+ if (item && item.constructor == Element) {
+ var len = this.items.length;
+ this.items[len] = item;
+ this[len] = item;
+ }
+ return this;
+ };
+ Set.prototype.pull = function (id) {
+ var res = this.items.splice(id, 1)[0];
+ for (var j = id, jj = this.items.length; j < jj; j++) {
+ this[j] = this[j + 1];
+ }
+ delete this[jj + 1];
+ return res;
+ };
+ for (var method in Element.prototype) {
+ Set.prototype[method] = (function (methodname) {
+ return function () {
+ for (var i = this.items.length; i--;) {
+ this.items[i][methodname].apply(this.items[i], arguments);
+ }
+ return this;
+ };
+ })(method);
+ }
+ Set.prototype.getBBox = function () {
+ var x = [], y = [], w = [], h = [];
+ for (var i = this.items.length; i--;) {
+ var box = this.items[i].getBBox();
+ x.push(box.x);
+ y.push(box.y);
+ w.push(box.x + box.width);
+ h.push(box.y + box.height);
+ }
+ x = Math.min.apply(Math, x);
+ y = Math.min.apply(Math, y);
+ return {
+ x: x,
+ y: y,
+ width: Math.max.apply(Math, w) - x,
+ height: Math.max.apply(Math, h) - y
+ };
+ };
-
-})(Raphael);
\ No newline at end of file
+ return R;
+})();
\ No newline at end of file