rlm@29: /*! rlm@29: * Raphael 1.3.0 - JavaScript Vector Library rlm@29: * rlm@29: * Copyright (c) 2008 - 2009 Dmitry Baranovskiy (http://raphaeljs.com) rlm@29: * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license. rlm@29: */ rlm@29: rlm@29: rlm@29: window.Raphael = (function () { rlm@29: var separator = /[, ]+/, rlm@29: elements = /^(circle|rect|path|ellipse|text|image)$/, rlm@29: doc = document, rlm@29: win = window, rlm@29: oldRaphael = { rlm@29: was: "Raphael" in win, rlm@29: is: win.Raphael rlm@29: }, rlm@29: R = function () { rlm@29: if (R.is(arguments[0], "array")) { rlm@29: var a = arguments[0], rlm@29: cnv = create[apply](R, a.splice(0, 3 + R.is(a[0], nu))), rlm@29: res = cnv.set(); rlm@29: for (var i = 0, ii = a[length]; i < ii; i++) { rlm@29: var j = a[i] || {}; rlm@29: elements.test(j.type) && res[push](cnv[j.type]().attr(j)); rlm@29: } rlm@29: return res; rlm@29: } rlm@29: return create[apply](R, arguments); rlm@29: }, rlm@29: Paper = function () {}, rlm@29: appendChild = "appendChild", rlm@29: apply = "apply", rlm@29: concat = "concat", rlm@29: E = "", rlm@29: S = " ", rlm@29: split = "split", rlm@29: events = "click dblclick mousedown mousemove mouseout mouseover mouseup"[split](S), rlm@29: has = "hasOwnProperty", rlm@29: join = "join", rlm@29: length = "length", rlm@29: proto = "prototype", rlm@29: lowerCase = String[proto].toLowerCase, rlm@29: math = Math, rlm@29: mmax = math.max, rlm@29: mmin = math.min, rlm@29: nu = "number", rlm@29: toString = "toString", rlm@29: objectToString = Object[proto][toString], rlm@29: paper = {}, rlm@29: pow = math.pow, rlm@29: push = "push", rlm@29: rg = /^(?=[\da-f]$)/, rlm@29: ISURL = /^url\(['"]?([^\)]+)['"]?\)$/i, rlm@29: colourRegExp = /^\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*\)|hs[bl]\(\s*([\d\.]+\s*,\s*[\d\.]+\s*,\s*[\d\.]+)\s*\)|hs[bl]\(\s*([\d\.]+%\s*,\s*[\d\.]+%\s*,\s*[\d\.]+%)\s*\))\s*$/i, rlm@29: round = math.round, rlm@29: setAttribute = "setAttribute", rlm@29: toFloat = parseFloat, rlm@29: toInt = parseInt, rlm@29: upperCase = String[proto].toUpperCase, rlm@29: availableAttrs = {"clip-rect": "0 0 1e9 1e9", cursor: "default", cx: 0, cy: 0, fill: "#fff", "fill-opacity": 1, font: '10px "Arial"', "font-family": '"Arial"', "font-size": "10", "font-style": "normal", "font-weight": 400, gradient: 0, height: 0, href: "http://raphaeljs.com/", opacity: 1, path: "M0,0", r: 0, rotation: 0, rx: 0, ry: 0, scale: "1 1", src: "", stroke: "#000", "stroke-dasharray": "", "stroke-linecap": "butt", "stroke-linejoin": "butt", "stroke-miterlimit": 0, "stroke-opacity": 1, "stroke-width": 1, target: "_blank", "text-anchor": "middle", title: "Raphael", translation: "0 0", width: 0, x: 0, y: 0}, rlm@29: availableAnimAttrs = {along: "along", "clip-rect": "csv", cx: nu, cy: nu, fill: "colour", "fill-opacity": nu, "font-size": nu, height: nu, opacity: nu, path: "path", r: nu, rotation: "csv", rx: nu, ry: nu, scale: "csv", stroke: "colour", "stroke-opacity": nu, "stroke-width": nu, translation: "csv", width: nu, x: nu, y: nu}, rlm@29: rp = "replace"; rlm@29: R.version = "1.3.0"; rlm@29: R.type = (win.SVGAngle || doc.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1") ? "SVG" : "VML"); rlm@29: if (R.type == "VML") { rlm@29: var d = document.createElement("div"); rlm@29: d.innerHTML = ''; rlm@29: if (d.childNodes[length] != 2) { rlm@29: return null; rlm@29: } rlm@29: } rlm@29: R.svg = !(R.vml = R.type == "VML"); rlm@29: Paper[proto] = R[proto]; rlm@29: R._id = 0; rlm@29: R._oid = 0; rlm@29: R.fn = {}; rlm@29: R.is = function (o, type) { rlm@29: type = lowerCase.call(type); rlm@29: return ((type == "object" || type == "undefined") && typeof o == type) || (o == null && type == "null") || lowerCase.call(objectToString.call(o).slice(8, -1)) == type; rlm@29: }; rlm@29: R.setWindow = function (newwin) { rlm@29: win = newwin; rlm@29: doc = win.document; rlm@29: }; rlm@29: // colour utilities rlm@29: var toHex = function (color) { rlm@29: if (R.vml) { rlm@29: // http://dean.edwards.name/weblog/2009/10/convert-any-colour-value-to-hex-in-msie/ rlm@29: var trim = /^\s+|\s+$/g; rlm@29: toHex = cacher(function (color) { rlm@29: var bod; rlm@29: color = (color + E)[rp](trim, E); rlm@29: try { rlm@29: var docum = new ActiveXObject("htmlfile"); rlm@29: docum.write("
"); rlm@29: docum.close(); rlm@29: bod = docum.body; rlm@29: } catch(e) { rlm@29: bod = createPopup().document.body; rlm@29: } rlm@29: var range = bod.createTextRange(); rlm@29: try { rlm@29: bod.style.color = color; rlm@29: var value = range.queryCommandValue("ForeColor"); rlm@29: value = ((value & 255) << 16) | (value & 65280) | ((value & 16711680) >>> 16); rlm@29: return "#" + ("000000" + value[toString](16)).slice(-6); rlm@29: } catch(e) { rlm@29: return "none"; rlm@29: } rlm@29: }); rlm@29: } else { rlm@29: var i = doc.createElement("i"); rlm@29: i.title = "Rapha\xebl Colour Picker"; rlm@29: i.style.display = "none"; rlm@29: doc.body[appendChild](i); rlm@29: toHex = cacher(function (color) { rlm@29: i.style.color = color; rlm@29: return doc.defaultView.getComputedStyle(i, E).getPropertyValue("color"); rlm@29: }); rlm@29: } rlm@29: return toHex(color); rlm@29: }; rlm@29: R.hsb2rgb = cacher(function (hue, saturation, brightness) { rlm@29: if (R.is(hue, "object") && "h" in hue && "s" in hue && "b" in hue) { rlm@29: brightness = hue.b; rlm@29: saturation = hue.s; rlm@29: hue = hue.h; rlm@29: } rlm@29: var red, rlm@29: green, rlm@29: blue; rlm@29: if (brightness == 0) { rlm@29: return {r: 0, g: 0, b: 0, hex: "#000"}; rlm@29: } rlm@29: if (hue > 1 || saturation > 1 || brightness > 1) { rlm@29: hue /= 255; rlm@29: saturation /= 255; rlm@29: brightness /= 255; rlm@29: } rlm@29: var i = ~~(hue * 6), rlm@29: f = (hue * 6) - i, rlm@29: p = brightness * (1 - saturation), rlm@29: q = brightness * (1 - (saturation * f)), rlm@29: t = brightness * (1 - (saturation * (1 - f))); rlm@29: red = [brightness, q, p, p, t, brightness, brightness][i]; rlm@29: green = [t, brightness, brightness, q, p, p, t][i]; rlm@29: blue = [p, p, t, brightness, brightness, q, p][i]; rlm@29: red *= 255; rlm@29: green *= 255; rlm@29: blue *= 255; rlm@29: var rgb = {r: red, g: green, b: blue}, rlm@29: r = (~~red)[toString](16), rlm@29: g = (~~green)[toString](16), rlm@29: b = (~~blue)[toString](16); rlm@29: r = r[rp](rg, "0"); rlm@29: g = g[rp](rg, "0"); rlm@29: b = b[rp](rg, "0"); rlm@29: rgb.hex = "#" + r + g + b; rlm@29: return rgb; rlm@29: }, R); rlm@29: R.rgb2hsb = cacher(function (red, green, blue) { rlm@29: if (R.is(red, "object") && "r" in red && "g" in red && "b" in red) { rlm@29: blue = red.b; rlm@29: green = red.g; rlm@29: red = red.r; rlm@29: } rlm@29: if (R.is(red, "string")) { rlm@29: var clr = R.getRGB(red); rlm@29: red = clr.r; rlm@29: green = clr.g; rlm@29: blue = clr.b; rlm@29: } rlm@29: if (red > 1 || green > 1 || blue > 1) { rlm@29: red /= 255; rlm@29: green /= 255; rlm@29: blue /= 255; rlm@29: } rlm@29: var max = mmax(red, green, blue), rlm@29: min = mmin(red, green, blue), rlm@29: hue, rlm@29: saturation, rlm@29: brightness = max; rlm@29: if (min == max) { rlm@29: return {h: 0, s: 0, b: max}; rlm@29: } else { rlm@29: var delta = (max - min); rlm@29: saturation = delta / max; rlm@29: if (red == max) { rlm@29: hue = (green - blue) / delta; rlm@29: } else if (green == max) { rlm@29: hue = 2 + ((blue - red) / delta); rlm@29: } else { rlm@29: hue = 4 + ((red - green) / delta); rlm@29: } rlm@29: hue /= 6; rlm@29: hue < 0 && hue++; rlm@29: hue > 1 && hue--; rlm@29: } rlm@29: return {h: hue, s: saturation, b: brightness}; rlm@29: }, R); rlm@29: var p2s = /,?([achlmqrstvxz]),?/gi; rlm@29: R._path2string = function () { rlm@29: return this.join(",")[rp](p2s, "$1"); rlm@29: }; rlm@29: function cacher(f, scope, postprocessor) { rlm@29: function newf() { rlm@29: var arg = Array[proto].slice.call(arguments, 0), rlm@29: args = arg[join]("\u25ba"), rlm@29: cache = newf.cache = newf.cache || {}, rlm@29: count = newf.count = newf.count || []; rlm@29: if (cache[has](args)) { rlm@29: return postprocessor ? postprocessor(cache[args]) : cache[args]; rlm@29: } rlm@29: count[length] >= 1e3 && delete cache[count.shift()]; rlm@29: count[push](args); rlm@29: cache[args] = f[apply](scope, arg); rlm@29: return postprocessor ? postprocessor(cache[args]) : cache[args]; rlm@29: } rlm@29: return newf; rlm@29: } rlm@29: rlm@29: R.getRGB = cacher(function (colour) { rlm@29: if (!colour || !!((colour = colour + E).indexOf("-") + 1)) { rlm@29: return {r: -1, g: -1, b: -1, hex: "none", error: 1}; rlm@29: } rlm@29: if (colour == "none") { rlm@29: return {r: -1, g: -1, b: -1, hex: "none"}; rlm@29: } rlm@29: !(({hs: 1, rg: 1})[has](colour.substring(0, 2)) || colour.charAt() == "#") && (colour = toHex(colour)); rlm@29: var res, rlm@29: red, rlm@29: green, rlm@29: blue, rlm@29: t, rlm@29: rgb = colour.match(colourRegExp); rlm@29: if (rgb) { rlm@29: if (rgb[2]) { rlm@29: blue = toInt(rgb[2].substring(5), 16); rlm@29: green = toInt(rgb[2].substring(3, 5), 16); rlm@29: red = toInt(rgb[2].substring(1, 3), 16); rlm@29: } rlm@29: if (rgb[3]) { rlm@29: blue = toInt((t = rgb[3].charAt(3)) + t, 16); rlm@29: green = toInt((t = rgb[3].charAt(2)) + t, 16); rlm@29: red = toInt((t = rgb[3].charAt(1)) + t, 16); rlm@29: } rlm@29: if (rgb[4]) { rlm@29: rgb = rgb[4][split](/\s*,\s*/); rlm@29: red = toFloat(rgb[0]); rlm@29: green = toFloat(rgb[1]); rlm@29: blue = toFloat(rgb[2]); rlm@29: } rlm@29: if (rgb[5]) { rlm@29: rgb = rgb[5][split](/\s*,\s*/); rlm@29: red = toFloat(rgb[0]) * 2.55; rlm@29: green = toFloat(rgb[1]) * 2.55; rlm@29: blue = toFloat(rgb[2]) * 2.55; rlm@29: } rlm@29: if (rgb[6]) { rlm@29: rgb = rgb[6][split](/\s*,\s*/); rlm@29: red = toFloat(rgb[0]); rlm@29: green = toFloat(rgb[1]); rlm@29: blue = toFloat(rgb[2]); rlm@29: return R.hsb2rgb(red, green, blue); rlm@29: } rlm@29: if (rgb[7]) { rlm@29: rgb = rgb[7][split](/\s*,\s*/); rlm@29: red = toFloat(rgb[0]) * 2.55; rlm@29: green = toFloat(rgb[1]) * 2.55; rlm@29: blue = toFloat(rgb[2]) * 2.55; rlm@29: return R.hsb2rgb(red, green, blue); rlm@29: } rlm@29: rgb = {r: red, g: green, b: blue}; rlm@29: var r = (~~red)[toString](16), rlm@29: g = (~~green)[toString](16), rlm@29: b = (~~blue)[toString](16); rlm@29: r = r[rp](rg, "0"); rlm@29: g = g[rp](rg, "0"); rlm@29: b = b[rp](rg, "0"); rlm@29: rgb.hex = "#" + r + g + b; rlm@29: return rgb; rlm@29: } rlm@29: return {r: -1, g: -1, b: -1, hex: "none", error: 1}; rlm@29: }, R); rlm@29: R.getColor = function (value) { rlm@29: var start = this.getColor.start = this.getColor.start || {h: 0, s: 1, b: value || .75}, rlm@29: rgb = this.hsb2rgb(start.h, start.s, start.b); rlm@29: start.h += .075; rlm@29: if (start.h > 1) { rlm@29: start.h = 0; rlm@29: start.s -= .2; rlm@29: start.s <= 0 && (this.getColor.start = {h: 0, s: 1, b: start.b}); rlm@29: } rlm@29: return rgb.hex; rlm@29: }; rlm@29: R.getColor.reset = function () { rlm@29: delete this.start; rlm@29: }; rlm@29: // path utilities rlm@29: R.parsePathString = cacher(function (pathString) { rlm@29: if (!pathString) { rlm@29: return null; rlm@29: } rlm@29: var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, q: 4, s: 4, t: 2, v: 1, z: 0}, rlm@29: data = []; rlm@29: if (R.is(pathString, "array") && R.is(pathString[0], "array")) { // rough assumption rlm@29: data = pathClone(pathString); rlm@29: } rlm@29: if (!data[length]) { rlm@29: (pathString + E)[rp](/([achlmqstvz])[\s,]*((-?\d*\.?\d*(?:e[-+]?\d+)?\s*,?\s*)+)/ig, function (a, b, c) { rlm@29: var params = [], rlm@29: name = lowerCase.call(b); rlm@29: c[rp](/(-?\d*\.?\d*(?:e[-+]?\d+)?)\s*,?\s*/ig, function (a, b) { rlm@29: b && params[push](+b); rlm@29: }); rlm@29: while (params[length] >= paramCounts[name]) { rlm@29: data[push]([b][concat](params.splice(0, paramCounts[name]))); rlm@29: if (!paramCounts[name]) { rlm@29: break; rlm@29: }; rlm@29: } rlm@29: }); rlm@29: } rlm@29: data[toString] = R._path2string; rlm@29: return data; rlm@29: }); rlm@29: R.findDotsAtSegment = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) { rlm@29: var t1 = 1 - t, rlm@29: x = pow(t1, 3) * p1x + pow(t1, 2) * 3 * t * c1x + t1 * 3 * t * t * c2x + pow(t, 3) * p2x, rlm@29: y = pow(t1, 3) * p1y + pow(t1, 2) * 3 * t * c1y + t1 * 3 * t * t * c2y + pow(t, 3) * p2y, rlm@29: mx = p1x + 2 * t * (c1x - p1x) + t * t * (c2x - 2 * c1x + p1x), rlm@29: my = p1y + 2 * t * (c1y - p1y) + t * t * (c2y - 2 * c1y + p1y), rlm@29: nx = c1x + 2 * t * (c2x - c1x) + t * t * (p2x - 2 * c2x + c1x), rlm@29: ny = c1y + 2 * t * (c2y - c1y) + t * t * (p2y - 2 * c2y + c1y), rlm@29: ax = (1 - t) * p1x + t * c1x, rlm@29: ay = (1 - t) * p1y + t * c1y, rlm@29: cx = (1 - t) * c2x + t * p2x, rlm@29: cy = (1 - t) * c2y + t * p2y, rlm@29: alpha = (90 - math.atan((mx - nx) / (my - ny)) * 180 / math.PI); rlm@29: (mx > nx || my < ny) && (alpha += 180); rlm@29: return {x: x, y: y, m: {x: mx, y: my}, n: {x: nx, y: ny}, start: {x: ax, y: ay}, end: {x: cx, y: cy}, alpha: alpha}; rlm@29: }; rlm@29: var pathDimensions = cacher(function (path) { rlm@29: if (!path) { rlm@29: return {x: 0, y: 0, width: 0, height: 0}; rlm@29: } rlm@29: path = path2curve(path); rlm@29: var x = 0, rlm@29: y = 0, rlm@29: X = [], rlm@29: Y = [], rlm@29: p; rlm@29: for (var i = 0, ii = path[length]; i < ii; i++) { rlm@29: p = path[i]; rlm@29: if (p[0] == "M") { rlm@29: x = p[1]; rlm@29: y = p[2]; rlm@29: X[push](x); rlm@29: Y[push](y); rlm@29: } else { rlm@29: var dim = curveDim(x, y, p[1], p[2], p[3], p[4], p[5], p[6]); rlm@29: X = X[concat](dim.min.x, dim.max.x); rlm@29: Y = Y[concat](dim.min.y, dim.max.y); rlm@29: x = p[5]; rlm@29: y = p[6]; rlm@29: } rlm@29: } rlm@29: var xmin = mmin[apply](0, X), rlm@29: ymin = mmin[apply](0, Y); rlm@29: return { rlm@29: x: xmin, rlm@29: y: ymin, rlm@29: width: mmax[apply](0, X) - xmin, rlm@29: height: mmax[apply](0, Y) - ymin rlm@29: }; rlm@29: }), rlm@29: pathClone = function (pathArray) { rlm@29: var res = []; rlm@29: if (!R.is(pathArray, "array") || !R.is(pathArray && pathArray[0], "array")) { // rough assumption rlm@29: pathArray = R.parsePathString(pathArray); rlm@29: } rlm@29: for (var i = 0, ii = pathArray[length]; i < ii; i++) { rlm@29: res[i] = []; rlm@29: for (var j = 0, jj = pathArray[i][length]; j < jj; j++) { rlm@29: res[i][j] = pathArray[i][j]; rlm@29: } rlm@29: } rlm@29: res[toString] = R._path2string; rlm@29: return res; rlm@29: }, rlm@29: pathToRelative = cacher(function (pathArray) { rlm@29: if (!R.is(pathArray, "array") || !R.is(pathArray && pathArray[0], "array")) { // rough assumption rlm@29: pathArray = R.parsePathString(pathArray); rlm@29: } rlm@29: var res = [], rlm@29: x = 0, rlm@29: y = 0, rlm@29: mx = 0, rlm@29: my = 0, rlm@29: start = 0; rlm@29: if (pathArray[0][0] == "M") { rlm@29: x = pathArray[0][1]; rlm@29: y = pathArray[0][2]; rlm@29: mx = x; rlm@29: my = y; rlm@29: start++; rlm@29: res[push](["M", x, y]); rlm@29: } rlm@29: for (var i = start, ii = pathArray[length]; i < ii; i++) { rlm@29: var r = res[i] = [], rlm@29: pa = pathArray[i]; rlm@29: if (pa[0] != lowerCase.call(pa[0])) { rlm@29: r[0] = lowerCase.call(pa[0]); rlm@29: switch (r[0]) { rlm@29: case "a": rlm@29: r[1] = pa[1]; rlm@29: r[2] = pa[2]; rlm@29: r[3] = pa[3]; rlm@29: r[4] = pa[4]; rlm@29: r[5] = pa[5]; rlm@29: r[6] = +(pa[6] - x).toFixed(3); rlm@29: r[7] = +(pa[7] - y).toFixed(3); rlm@29: break; rlm@29: case "v": rlm@29: r[1] = +(pa[1] - y).toFixed(3); rlm@29: break; rlm@29: case "m": rlm@29: mx = pa[1]; rlm@29: my = pa[2]; rlm@29: default: rlm@29: for (var j = 1, jj = pa[length]; j < jj; j++) { rlm@29: r[j] = +(pa[j] - ((j % 2) ? x : y)).toFixed(3); rlm@29: } rlm@29: } rlm@29: } else { rlm@29: r = res[i] = []; rlm@29: if (pa[0] == "m") { rlm@29: mx = pa[1] + x; rlm@29: my = pa[2] + y; rlm@29: } rlm@29: for (var k = 0, kk = pa[length]; k < kk; k++) { rlm@29: res[i][k] = pa[k]; rlm@29: } rlm@29: } rlm@29: var len = res[i][length]; rlm@29: switch (res[i][0]) { rlm@29: case "z": rlm@29: x = mx; rlm@29: y = my; rlm@29: break; rlm@29: case "h": rlm@29: x += +res[i][len - 1]; rlm@29: break; rlm@29: case "v": rlm@29: y += +res[i][len - 1]; rlm@29: break; rlm@29: default: rlm@29: x += +res[i][len - 2]; rlm@29: y += +res[i][len - 1]; rlm@29: } rlm@29: } rlm@29: res[toString] = R._path2string; rlm@29: return res; rlm@29: }, 0, pathClone), rlm@29: pathToAbsolute = cacher(function (pathArray) { rlm@29: if (!R.is(pathArray, "array") || !R.is(pathArray && pathArray[0], "array")) { // rough assumption rlm@29: pathArray = R.parsePathString(pathArray); rlm@29: } rlm@29: var res = [], rlm@29: x = 0, rlm@29: y = 0, rlm@29: mx = 0, rlm@29: my = 0, rlm@29: start = 0; rlm@29: if (pathArray[0][0] == "M") { rlm@29: x = +pathArray[0][1]; rlm@29: y = +pathArray[0][2]; rlm@29: mx = x; rlm@29: my = y; rlm@29: start++; rlm@29: res[0] = ["M", x, y]; rlm@29: } rlm@29: for (var i = start, ii = pathArray[length]; i < ii; i++) { rlm@29: var r = res[i] = [], rlm@29: pa = pathArray[i]; rlm@29: if (pa[0] != upperCase.call(pa[0])) { rlm@29: r[0] = upperCase.call(pa[0]); rlm@29: switch (r[0]) { rlm@29: case "A": rlm@29: r[1] = pa[1]; rlm@29: r[2] = pa[2]; rlm@29: r[3] = pa[3]; rlm@29: r[4] = pa[4]; rlm@29: r[5] = pa[5]; rlm@29: r[6] = +(pa[6] + x); rlm@29: r[7] = +(pa[7] + y); rlm@29: break; rlm@29: case "V": rlm@29: r[1] = +pa[1] + y; rlm@29: break; rlm@29: case "H": rlm@29: r[1] = +pa[1] + x; rlm@29: break; rlm@29: case "M": rlm@29: mx = +pa[1] + x; rlm@29: my = +pa[2] + y; rlm@29: default: rlm@29: for (var j = 1, jj = pa[length]; j < jj; j++) { rlm@29: r[j] = +pa[j] + ((j % 2) ? x : y); rlm@29: } rlm@29: } rlm@29: } else { rlm@29: for (var k = 0, kk = pa[length]; k < kk; k++) { rlm@29: res[i][k] = pa[k]; rlm@29: } rlm@29: } rlm@29: switch (r[0]) { rlm@29: case "Z": rlm@29: x = mx; rlm@29: y = my; rlm@29: break; rlm@29: case "H": rlm@29: x = r[1]; rlm@29: break; rlm@29: case "V": rlm@29: y = r[1]; rlm@29: break; rlm@29: default: rlm@29: x = res[i][res[i][length] - 2]; rlm@29: y = res[i][res[i][length] - 1]; rlm@29: } rlm@29: } rlm@29: res[toString] = R._path2string; rlm@29: return res; rlm@29: }, null, pathClone), rlm@29: l2c = function (x1, y1, x2, y2) { rlm@29: return [x1, y1, x2, y2, x2, y2]; rlm@29: }, rlm@29: q2c = function (x1, y1, ax, ay, x2, y2) { rlm@29: var _13 = 1 / 3, rlm@29: _23 = 2 / 3; rlm@29: return [ rlm@29: _13 * x1 + _23 * ax, rlm@29: _13 * y1 + _23 * ay, rlm@29: _13 * x2 + _23 * ax, rlm@29: _13 * y2 + _23 * ay, rlm@29: x2, rlm@29: y2 rlm@29: ]; rlm@29: }, rlm@29: a2c = function (x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2, recursive) { rlm@29: // for more information of where this math came from visit: rlm@29: // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes rlm@29: var PI = math.PI, rlm@29: _120 = PI * 120 / 180, rlm@29: rad = PI / 180 * (+angle || 0), rlm@29: res = [], rlm@29: xy, rlm@29: rotate = cacher(function (x, y, rad) { rlm@29: var X = x * math.cos(rad) - y * math.sin(rad), rlm@29: Y = x * math.sin(rad) + y * math.cos(rad); rlm@29: return {x: X, y: Y}; rlm@29: }); rlm@29: if (!recursive) { rlm@29: xy = rotate(x1, y1, -rad); rlm@29: x1 = xy.x; rlm@29: y1 = xy.y; rlm@29: xy = rotate(x2, y2, -rad); rlm@29: x2 = xy.x; rlm@29: y2 = xy.y; rlm@29: var cos = math.cos(PI / 180 * angle), rlm@29: sin = math.sin(PI / 180 * angle), rlm@29: x = (x1 - x2) / 2, rlm@29: y = (y1 - y2) / 2; rlm@29: rx = mmax(rx, math.abs(x)); rlm@29: ry = mmax(ry, math.abs(y)); rlm@29: var rx2 = rx * rx, rlm@29: ry2 = ry * ry, rlm@29: k = (large_arc_flag == sweep_flag ? -1 : 1) * rlm@29: math.sqrt(math.abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x))), rlm@29: cx = k * rx * y / ry + (x1 + x2) / 2, rlm@29: cy = k * -ry * x / rx + (y1 + y2) / 2, rlm@29: f1 = math.asin(((y1 - cy) / ry).toFixed(7)), rlm@29: f2 = math.asin(((y2 - cy) / ry).toFixed(7)); rlm@29: rlm@29: f1 = x1 < cx ? PI - f1 : f1; rlm@29: f2 = x2 < cx ? PI - f2 : f2; rlm@29: f1 < 0 && (f1 = PI * 2 + f1); rlm@29: f2 < 0 && (f2 = PI * 2 + f2); rlm@29: if (sweep_flag && f1 > f2) { rlm@29: f1 = f1 - PI * 2; rlm@29: } rlm@29: if (!sweep_flag && f2 > f1) { rlm@29: f2 = f2 - PI * 2; rlm@29: } rlm@29: } else { rlm@29: f1 = recursive[0]; rlm@29: f2 = recursive[1]; rlm@29: cx = recursive[2]; rlm@29: cy = recursive[3]; rlm@29: } rlm@29: var df = f2 - f1; rlm@29: if (math.abs(df) > _120) { rlm@29: var f2old = f2, rlm@29: x2old = x2, rlm@29: y2old = y2; rlm@29: f2 = f1 + _120 * (sweep_flag && f2 > f1 ? 1 : -1); rlm@29: x2 = cx + rx * math.cos(f2); rlm@29: y2 = cy + ry * math.sin(f2); rlm@29: res = a2c(x2, y2, rx, ry, angle, 0, sweep_flag, x2old, y2old, [f2, f2old, cx, cy]); rlm@29: } rlm@29: df = f2 - f1; rlm@29: var c1 = math.cos(f1), rlm@29: s1 = math.sin(f1), rlm@29: c2 = math.cos(f2), rlm@29: s2 = math.sin(f2), rlm@29: t = math.tan(df / 4), rlm@29: hx = 4 / 3 * rx * t, rlm@29: hy = 4 / 3 * ry * t, rlm@29: m1 = [x1, y1], rlm@29: m2 = [x1 + hx * s1, y1 - hy * c1], rlm@29: m3 = [x2 + hx * s2, y2 - hy * c2], rlm@29: m4 = [x2, y2]; rlm@29: m2[0] = 2 * m1[0] - m2[0]; rlm@29: m2[1] = 2 * m1[1] - m2[1]; rlm@29: if (recursive) { rlm@29: return [m2, m3, m4][concat](res); rlm@29: } else { rlm@29: res = [m2, m3, m4][concat](res)[join]()[split](","); rlm@29: var newres = []; rlm@29: for (var i = 0, ii = res[length]; i < ii; i++) { rlm@29: newres[i] = i % 2 ? rotate(res[i - 1], res[i], rad).y : rotate(res[i], res[i + 1], rad).x; rlm@29: } rlm@29: return newres; rlm@29: } rlm@29: }, rlm@29: findDotAtSegment = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) { rlm@29: var t1 = 1 - t; rlm@29: return { rlm@29: x: pow(t1, 3) * p1x + pow(t1, 2) * 3 * t * c1x + t1 * 3 * t * t * c2x + pow(t, 3) * p2x, rlm@29: y: pow(t1, 3) * p1y + pow(t1, 2) * 3 * t * c1y + t1 * 3 * t * t * c2y + pow(t, 3) * p2y rlm@29: }; rlm@29: }, rlm@29: curveDim = cacher(function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) { rlm@29: var a = (c2x - 2 * c1x + p1x) - (p2x - 2 * c2x + c1x), rlm@29: b = 2 * (c1x - p1x) - 2 * (c2x - c1x), rlm@29: c = p1x - c1x, rlm@29: t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a, rlm@29: t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a, rlm@29: y = [p1y, p2y], rlm@29: x = [p1x, p2x], rlm@29: dot; rlm@29: math.abs(t1) > 1e12 && (t1 = .5); rlm@29: math.abs(t2) > 1e12 && (t2 = .5); rlm@29: if (t1 > 0 && t1 < 1) { rlm@29: dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1); rlm@29: x[push](dot.x); rlm@29: y[push](dot.y); rlm@29: } rlm@29: if (t2 > 0 && t2 < 1) { rlm@29: dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2); rlm@29: x[push](dot.x); rlm@29: y[push](dot.y); rlm@29: } rlm@29: a = (c2y - 2 * c1y + p1y) - (p2y - 2 * c2y + c1y); rlm@29: b = 2 * (c1y - p1y) - 2 * (c2y - c1y); rlm@29: c = p1y - c1y; rlm@29: t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a; rlm@29: t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a; rlm@29: math.abs(t1) > 1e12 && (t1 = .5); rlm@29: math.abs(t2) > 1e12 && (t2 = .5); rlm@29: if (t1 > 0 && t1 < 1) { rlm@29: dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1); rlm@29: x[push](dot.x); rlm@29: y[push](dot.y); rlm@29: } rlm@29: if (t2 > 0 && t2 < 1) { rlm@29: dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2); rlm@29: x[push](dot.x); rlm@29: y[push](dot.y); rlm@29: } rlm@29: return { rlm@29: min: {x: mmin[apply](0, x), y: mmin[apply](0, y)}, rlm@29: max: {x: mmax[apply](0, x), y: mmax[apply](0, y)} rlm@29: }; rlm@29: }), rlm@29: path2curve = cacher(function (path, path2) { rlm@29: var p = pathToAbsolute(path), rlm@29: p2 = path2 && pathToAbsolute(path2), rlm@29: attrs = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null}, rlm@29: attrs2 = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null}, rlm@29: processPath = function (path, d) { rlm@29: var nx, ny; rlm@29: if (!path) { rlm@29: return ["C", d.x, d.y, d.x, d.y, d.x, d.y]; rlm@29: } rlm@29: !(path[0] in {T:1, Q:1}) && (d.qx = d.qy = null); rlm@29: switch (path[0]) { rlm@29: case "M": rlm@29: d.X = path[1]; rlm@29: d.Y = path[2]; rlm@29: break; rlm@29: case "A": rlm@29: path = ["C"][concat](a2c[apply](0, [d.x, d.y][concat](path.slice(1)))); rlm@29: break; rlm@29: case "S": rlm@29: nx = d.x + (d.x - (d.bx || d.x)); rlm@29: ny = d.y + (d.y - (d.by || d.y)); rlm@29: path = ["C", nx, ny][concat](path.slice(1)); rlm@29: break; rlm@29: case "T": rlm@29: d.qx = d.x + (d.x - (d.qx || d.x)); rlm@29: d.qy = d.y + (d.y - (d.qy || d.y)); rlm@29: path = ["C"][concat](q2c(d.x, d.y, d.qx, d.qy, path[1], path[2])); rlm@29: break; rlm@29: case "Q": rlm@29: d.qx = path[1]; rlm@29: d.qy = path[2]; rlm@29: path = ["C"][concat](q2c(d.x, d.y, path[1], path[2], path[3], path[4])); rlm@29: break; rlm@29: case "L": rlm@29: path = ["C"][concat](l2c(d.x, d.y, path[1], path[2])); rlm@29: break; rlm@29: case "H": rlm@29: path = ["C"][concat](l2c(d.x, d.y, path[1], d.y)); rlm@29: break; rlm@29: case "V": rlm@29: path = ["C"][concat](l2c(d.x, d.y, d.x, path[1])); rlm@29: break; rlm@29: case "Z": rlm@29: path = ["C"][concat](l2c(d.x, d.y, d.X, d.Y)); rlm@29: break; rlm@29: } rlm@29: return path; rlm@29: }, rlm@29: fixArc = function (pp, i) { rlm@29: if (pp[i][length] > 7) { rlm@29: pp[i].shift(); rlm@29: var pi = pp[i]; rlm@29: while (pi[length]) { rlm@29: pp.splice(i++, 0, ["C"][concat](pi.splice(0, 6))); rlm@29: } rlm@29: pp.splice(i, 1); rlm@29: ii = mmax(p[length], p2 && p2[length] || 0); rlm@29: } rlm@29: }, rlm@29: fixM = function (path1, path2, a1, a2, i) { rlm@29: if (path1 && path2 && path1[i][0] == "M" && path2[i][0] != "M") { rlm@29: path2.splice(i, 0, ["M", a2.x, a2.y]); rlm@29: a1.bx = 0; rlm@29: a1.by = 0; rlm@29: a1.x = path1[i][1]; rlm@29: a1.y = path1[i][2]; rlm@29: ii = mmax(p[length], p2 && p2[length] || 0); rlm@29: } rlm@29: }; rlm@29: for (var i = 0, ii = mmax(p[length], p2 && p2[length] || 0); i < ii; i++) { rlm@29: p[i] = processPath(p[i], attrs); rlm@29: fixArc(p, i); rlm@29: p2 && (p2[i] = processPath(p2[i], attrs2)); rlm@29: p2 && fixArc(p2, i); rlm@29: fixM(p, p2, attrs, attrs2, i); rlm@29: fixM(p2, p, attrs2, attrs, i); rlm@29: var seg = p[i], rlm@29: seg2 = p2 && p2[i], rlm@29: seglen = seg[length], rlm@29: seg2len = p2 && seg2[length]; rlm@29: attrs.x = seg[seglen - 2]; rlm@29: attrs.y = seg[seglen - 1]; rlm@29: attrs.bx = toFloat(seg[seglen - 4]) || attrs.x; rlm@29: attrs.by = toFloat(seg[seglen - 3]) || attrs.y; rlm@29: attrs2.bx = p2 && (toFloat(seg2[seg2len - 4]) || attrs2.x); rlm@29: attrs2.by = p2 && (toFloat(seg2[seg2len - 3]) || attrs2.y); rlm@29: attrs2.x = p2 && seg2[seg2len - 2]; rlm@29: attrs2.y = p2 && seg2[seg2len - 1]; rlm@29: } rlm@29: return p2 ? [p, p2] : p; rlm@29: }, null, pathClone), rlm@29: parseDots = cacher(function (gradient) { rlm@29: var dots = []; rlm@29: for (var i = 0, ii = gradient[length]; i < ii; i++) { rlm@29: var dot = {}, rlm@29: par = gradient[i].match(/^([^:]*):?([\d\.]*)/); rlm@29: dot.color = R.getRGB(par[1]); rlm@29: if (dot.color.error) { rlm@29: return null; rlm@29: } rlm@29: dot.color = dot.color.hex; rlm@29: par[2] && (dot.offset = par[2] + "%"); rlm@29: dots[push](dot); rlm@29: } rlm@29: for (var i = 1, ii = dots[length] - 1; i < ii; i++) { rlm@29: if (!dots[i].offset) { rlm@29: var start = toFloat(dots[i - 1].offset || 0), rlm@29: end = 0; rlm@29: for (var j = i + 1; j < ii; j++) { rlm@29: if (dots[j].offset) { rlm@29: end = dots[j].offset; rlm@29: break; rlm@29: } rlm@29: } rlm@29: if (!end) { rlm@29: end = 100; rlm@29: j = ii; rlm@29: } rlm@29: end = toFloat(end); rlm@29: var d = (end - start) / (j - i + 1); rlm@29: for (; i < j; i++) { rlm@29: start += d; rlm@29: dots[i].offset = start + "%"; rlm@29: } rlm@29: } rlm@29: } rlm@29: return dots; rlm@29: }), rlm@29: getContainer = function () { rlm@29: var container, rlm@29: x, rlm@29: y, rlm@29: width, rlm@29: height; rlm@29: if (R.is(arguments[0], "string") || R.is(arguments[0], "object")) { rlm@29: if (R.is(arguments[0], "string")) { rlm@29: container = doc.getElementById(arguments[0]); rlm@29: } else { rlm@29: container = arguments[0]; rlm@29: } rlm@29: if (container.tagName) { rlm@29: if (arguments[1] == null) { rlm@29: return { rlm@29: container: container, rlm@29: width: container.style.pixelWidth || container.offsetWidth, rlm@29: height: container.style.pixelHeight || container.offsetHeight rlm@29: }; rlm@29: } else { rlm@29: return {container: container, width: arguments[1], height: arguments[2]}; rlm@29: } rlm@29: } rlm@29: } else if (R.is(arguments[0], nu) && arguments[length] > 3) { rlm@29: return {container: 1, x: arguments[0], y: arguments[1], width: arguments[2], height: arguments[3]}; rlm@29: } rlm@29: }, rlm@29: plugins = function (con, add) { rlm@29: var that = this; rlm@29: for (var prop in add) if (add[has](prop) && !(prop in con)) { rlm@29: switch (typeof add[prop]) { rlm@29: case "function": rlm@29: (function (f) { rlm@29: con[prop] = con === that ? f : function () { return f[apply](that, arguments); }; rlm@29: })(add[prop]); rlm@29: break; rlm@29: case "object": rlm@29: con[prop] = con[prop] || {}; rlm@29: plugins.call(this, con[prop], add[prop]); rlm@29: break; rlm@29: default: rlm@29: con[prop] = add[prop]; rlm@29: break; rlm@29: } rlm@29: } rlm@29: }, rlm@29: tear = function (el, paper) { rlm@29: el == paper.top && (paper.top = el.prev); rlm@29: el == paper.bottom && (paper.bottom = el.next); rlm@29: el.next && (el.next.prev = el.prev); rlm@29: el.prev && (el.prev.next = el.next); rlm@29: }, rlm@29: tofront = function (el, paper) { rlm@29: if (paper.top === el) { rlm@29: return; rlm@29: } rlm@29: tear(el, paper); rlm@29: el.next = null; rlm@29: el.prev = paper.top; rlm@29: paper.top.next = el; rlm@29: paper.top = el; rlm@29: }, rlm@29: toback = function (el, paper) { rlm@29: if (paper.bottom === el) { rlm@29: return; rlm@29: } rlm@29: tear(el, paper); rlm@29: el.next = paper.bottom; rlm@29: el.prev = null; rlm@29: paper.bottom.prev = el; rlm@29: paper.bottom = el; rlm@29: }, rlm@29: insertafter = function (el, el2, paper) { rlm@29: tear(el, paper); rlm@29: el2 == paper.top && (paper.top = el); rlm@29: el2.next && (el2.next.prev = el); rlm@29: el.next = el2.next; rlm@29: el.prev = el2; rlm@29: el2.next = el; rlm@29: }, rlm@29: insertbefore = function (el, el2, paper) { rlm@29: tear(el, paper); rlm@29: el2 == paper.bottom && (paper.bottom = el); rlm@29: el2.prev && (el2.prev.next = el); rlm@29: el.prev = el2.prev; rlm@29: el2.prev = el; rlm@29: el.next = el2; rlm@29: }, rlm@29: removed = function (methodname) { rlm@29: return function () { rlm@29: throw new Error("Rapha\xebl: you are calling to method \u201c" + methodname + "\u201d of removed object"); rlm@29: }; rlm@29: }, rlm@29: radial_gradient = /^r(?:\(([^,]+?)\s*,\s*([^\)]+?)\))?/; rlm@29: rlm@29: // SVG rlm@29: if (R.svg) { rlm@29: Paper[proto].svgns = "http://www.w3.org/2000/svg"; rlm@29: Paper[proto].xlink = "http://www.w3.org/1999/xlink"; rlm@29: var round = function (num) { rlm@29: return +num + (~~num === num) * .5; rlm@29: }, rlm@29: roundPath = function (path) { rlm@29: for (var i = 0, ii = path[length]; i < ii; i++) { rlm@29: if (lowerCase.call(path[i][0]) != "a") { rlm@29: for (var j = 1, jj = path[i][length]; j < jj; j++) { rlm@29: path[i][j] = round(path[i][j]); rlm@29: } rlm@29: } else { rlm@29: path[i][6] = round(path[i][6]); rlm@29: path[i][7] = round(path[i][7]); rlm@29: } rlm@29: } rlm@29: return path; rlm@29: }, rlm@29: $ = function (el, attr) { rlm@29: if (attr) { rlm@29: for (var key in attr) if (attr[has](key)) { rlm@29: el[setAttribute](key, attr[key]); rlm@29: } rlm@29: } else { rlm@29: return doc.createElementNS(Paper[proto].svgns, el); rlm@29: } rlm@29: }; rlm@29: R[toString] = function () { rlm@29: return "Your browser supports SVG.\nYou are running Rapha\xebl " + this.version; rlm@29: }; rlm@29: var thePath = function (pathString, SVG) { rlm@29: var el = $("path"); rlm@29: SVG.canvas && SVG.canvas[appendChild](el); rlm@29: var p = new Element(el, SVG); rlm@29: p.type = "path"; rlm@29: setFillAndStroke(p, {fill: "none", stroke: "#000", path: pathString}); rlm@29: return p; rlm@29: }; rlm@29: var addGradientFill = function (o, gradient, SVG) { rlm@29: var type = "linear", rlm@29: fx = .5, fy = .5, rlm@29: s = o.style; rlm@29: gradient = (gradient + E)[rp](radial_gradient, function (all, _fx, _fy) { rlm@29: type = "radial"; rlm@29: if (_fx && _fy) { rlm@29: fx = toFloat(_fx); rlm@29: fy = toFloat(_fy); rlm@29: var dir = ((fy > .5) * 2 - 1); rlm@29: pow(fx - .5, 2) + pow(fy - .5, 2) > .25 && rlm@29: (fy = math.sqrt(.25 - pow(fx - .5, 2)) * dir + .5) && rlm@29: fy != .5 && rlm@29: (fy = fy.toFixed(5) - 1e-5 * dir); rlm@29: } rlm@29: return E; rlm@29: }); rlm@29: gradient = gradient[split](/\s*\-\s*/); rlm@29: if (type == "linear") { rlm@29: var angle = gradient.shift(); rlm@29: angle = -toFloat(angle); rlm@29: if (isNaN(angle)) { rlm@29: return null; rlm@29: } rlm@29: var vector = [0, 0, math.cos(angle * math.PI / 180), math.sin(angle * math.PI / 180)], rlm@29: max = 1 / (mmax(math.abs(vector[2]), math.abs(vector[3])) || 1); rlm@29: vector[2] *= max; rlm@29: vector[3] *= max; rlm@29: if (vector[2] < 0) { rlm@29: vector[0] = -vector[2]; rlm@29: vector[2] = 0; rlm@29: } rlm@29: if (vector[3] < 0) { rlm@29: vector[1] = -vector[3]; rlm@29: vector[3] = 0; rlm@29: } rlm@29: } rlm@29: var dots = parseDots(gradient); rlm@29: if (!dots) { rlm@29: return null; rlm@29: } rlm@29: var el = $(type + "Gradient"); rlm@29: el.id = "r" + (R._id++)[toString](36); rlm@29: $(el, type == "radial" ? {fx: fx, fy: fy} : {x1: vector[0], y1: vector[1], x2: vector[2], y2: vector[3]}); rlm@29: SVG.defs[appendChild](el); rlm@29: for (var i = 0, ii = dots[length]; i < ii; i++) { rlm@29: var stop = $("stop"); rlm@29: $(stop, { rlm@29: offset: dots[i].offset ? dots[i].offset : !i ? "0%" : "100%", rlm@29: "stop-color": dots[i].color || "#fff" rlm@29: }); rlm@29: el[appendChild](stop); rlm@29: }; rlm@29: $(o, { rlm@29: fill: "url(#" + el.id + ")", rlm@29: opacity: 1, rlm@29: "fill-opacity": 1 rlm@29: }); rlm@29: s.fill = E; rlm@29: s.opacity = 1; rlm@29: s.fillOpacity = 1; rlm@29: return 1; rlm@29: }; rlm@29: var updatePosition = function (o) { rlm@29: var bbox = o.getBBox(); rlm@29: $(o.pattern, {patternTransform: R.format("translate({0},{1})", bbox.x, bbox.y)}); rlm@29: }; rlm@29: var setFillAndStroke = function (o, params) { rlm@29: var dasharray = { rlm@29: "": [0], rlm@29: "none": [0], rlm@29: "-": [3, 1], rlm@29: ".": [1, 1], rlm@29: "-.": [3, 1, 1, 1], rlm@29: "-..": [3, 1, 1, 1, 1, 1], rlm@29: ". ": [1, 3], rlm@29: "- ": [4, 3], rlm@29: "--": [8, 3], rlm@29: "- .": [4, 3, 1, 3], rlm@29: "--.": [8, 3, 1, 3], rlm@29: "--..": [8, 3, 1, 3, 1, 3] rlm@29: }, rlm@29: node = o.node, rlm@29: attrs = o.attrs, rlm@29: rot = o.rotate(), rlm@29: addDashes = function (o, value) { rlm@29: value = dasharray[lowerCase.call(value)]; rlm@29: if (value) { rlm@29: var width = o.attrs["stroke-width"] || "1", rlm@29: butt = {round: width, square: width, butt: 0}[o.attrs["stroke-linecap"] || params["stroke-linecap"]] || 0, rlm@29: dashes = []; rlm@29: var i = value[length]; rlm@29: while (i--) { rlm@29: dashes[i] = value[i] * width + ((i % 2) ? 1 : -1) * butt; rlm@29: } rlm@29: $(node, {"stroke-dasharray": dashes[join](",")}); rlm@29: } rlm@29: }; rlm@29: params[has]("rotation") && (rot = params.rotation); rlm@29: var rotxy = (rot + E)[split](separator); rlm@29: if (!(rotxy.length - 1)) { rlm@29: rotxy = null; rlm@29: } else { rlm@29: rotxy[1] = +rotxy[1]; rlm@29: rotxy[2] = +rotxy[2]; rlm@29: } rlm@29: toFloat(rot) && o.rotate(0, true); rlm@29: for (var att in params) if (params[has](att)) { rlm@29: if (!availableAttrs[has](att)) { rlm@29: continue; rlm@29: } rlm@29: var value = params[att]; rlm@29: attrs[att] = value; rlm@29: switch (att) { rlm@29: case "rotation": rlm@29: o.rotate(value, true); rlm@29: break; rlm@29: // Hyperlink rlm@29: case "href": rlm@29: case "title": rlm@29: case "target": rlm@29: var pn = node.parentNode; rlm@29: if (lowerCase.call(pn.tagName) != "a") { rlm@29: var hl = $("a"); rlm@29: pn.insertBefore(hl, node); rlm@29: hl[appendChild](node); rlm@29: pn = hl; rlm@29: } rlm@29: pn.setAttributeNS(o.Paper[proto].xlink, att, value); rlm@29: break; rlm@29: case "cursor": rlm@29: node.style.cursor = value; rlm@29: break; rlm@29: case "clip-rect": rlm@29: var rect = (value + E)[split](separator); rlm@29: if (rect[length] == 4) { rlm@29: o.clip && o.clip.parentNode.parentNode.removeChild(o.clip.parentNode); rlm@29: var el = $("clipPath"), rlm@29: rc = $("rect"); rlm@29: el.id = "r" + (R._id++)[toString](36); rlm@29: $(rc, { rlm@29: x: rect[0], rlm@29: y: rect[1], rlm@29: width: rect[2], rlm@29: height: rect[3] rlm@29: }); rlm@29: el[appendChild](rc); rlm@29: o.paper.defs[appendChild](el); rlm@29: $(node, {"clip-path": "url(#" + el.id + ")"}); rlm@29: o.clip = rc; rlm@29: } rlm@29: if (!value) { rlm@29: var clip = doc.getElementById(node.getAttribute("clip-path")[rp](/(^url\(#|\)$)/g, E)); rlm@29: clip && clip.parentNode.removeChild(clip); rlm@29: $(node, {"clip-path": E}); rlm@29: delete o.clip; rlm@29: } rlm@29: break; rlm@29: case "path": rlm@29: if (value && o.type == "path") { rlm@29: attrs.path = roundPath(pathToAbsolute(value)); rlm@29: $(node, {d: attrs.path}); rlm@29: } rlm@29: break; rlm@29: case "width": rlm@29: node[setAttribute](att, value); rlm@29: if (attrs.fx) { rlm@29: att = "x"; rlm@29: value = attrs.x; rlm@29: } else { rlm@29: break; rlm@29: } rlm@29: case "x": rlm@29: if (attrs.fx) { rlm@29: value = -attrs.x - (attrs.width || 0); rlm@29: } rlm@29: case "rx": rlm@29: if (att == "rx" && o.type == "rect") { rlm@29: break; rlm@29: } rlm@29: case "cx": rlm@29: rotxy && (att == "x" || att == "cx") && (rotxy[1] += value - attrs[att]); rlm@29: node[setAttribute](att, round(value)); rlm@29: o.pattern && updatePosition(o); rlm@29: break; rlm@29: case "height": rlm@29: node[setAttribute](att, value); rlm@29: if (attrs.fy) { rlm@29: att = "y"; rlm@29: value = attrs.y; rlm@29: } else { rlm@29: break; rlm@29: } rlm@29: case "y": rlm@29: if (attrs.fy) { rlm@29: value = -attrs.y - (attrs.height || 0); rlm@29: } rlm@29: case "ry": rlm@29: if (att == "ry" && o.type == "rect") { rlm@29: break; rlm@29: } rlm@29: case "cy": rlm@29: rotxy && (att == "y" || att == "cy") && (rotxy[2] += value - attrs[att]); rlm@29: node[setAttribute](att, round(value)); rlm@29: o.pattern && updatePosition(o); rlm@29: break; rlm@29: case "r": rlm@29: if (o.type == "rect") { rlm@29: $(node, {rx: value, ry: value}); rlm@29: } else { rlm@29: node[setAttribute](att, value); rlm@29: } rlm@29: break; rlm@29: case "src": rlm@29: if (o.type == "image") { rlm@29: node.setAttributeNS(o.paper.xlink, "href", value); rlm@29: } rlm@29: break; rlm@29: case "stroke-width": rlm@29: node.style.strokeWidth = value; rlm@29: // Need following line for Firefox rlm@29: node[setAttribute](att, value); rlm@29: if (attrs["stroke-dasharray"]) { rlm@29: addDashes(o, attrs["stroke-dasharray"]); rlm@29: } rlm@29: break; rlm@29: case "stroke-dasharray": rlm@29: addDashes(o, value); rlm@29: break; rlm@29: case "translation": rlm@29: var xy = (value + E)[split](separator); rlm@29: xy[0] = +xy[0] || 0; rlm@29: xy[1] = +xy[1] || 0; rlm@29: if (rotxy) { rlm@29: rotxy[1] += xy[0]; rlm@29: rotxy[2] += xy[1]; rlm@29: } rlm@29: translate.call(o, xy[0], xy[1]); rlm@29: break; rlm@29: case "scale": rlm@29: var xy = (value + E)[split](separator); rlm@29: o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, +xy[2] || null, +xy[3] || null); rlm@29: break; rlm@29: case "fill": rlm@29: var isURL = (value + E).match(ISURL); rlm@29: if (isURL) { rlm@29: var el = $("pattern"), rlm@29: ig = $("image"); rlm@29: el.id = "r" + (R._id++)[toString](36); rlm@29: $(el, {x: 0, y: 0, patternUnits: "userSpaceOnUse", height: 1, width: 1}); rlm@29: $(ig, {x: 0, y: 0}); rlm@29: ig.setAttributeNS(o.paper.xlink, "href", isURL[1]); rlm@29: el[appendChild](ig); rlm@29: rlm@29: var img = doc.createElement("img"); rlm@29: img.style.cssText = "position:absolute;left:-9999em;top-9999em"; rlm@29: img.onload = function () { rlm@29: $(el, {width: this.offsetWidth, height: this.offsetHeight}); rlm@29: $(ig, {width: this.offsetWidth, height: this.offsetHeight}); rlm@29: doc.body.removeChild(this); rlm@29: o.paper.safari(); rlm@29: }; rlm@29: doc.body[appendChild](img); rlm@29: img.src = isURL[1]; rlm@29: o.paper.defs[appendChild](el); rlm@29: node.style.fill = "url(#" + el.id + ")"; rlm@29: $(node, {fill: "url(#" + el.id + ")"}); rlm@29: o.pattern = el; rlm@29: o.pattern && updatePosition(o); rlm@29: break; rlm@29: } rlm@29: if (!R.getRGB(value).error) { rlm@29: delete params.gradient; rlm@29: delete attrs.gradient; rlm@29: !R.is(attrs.opacity, "undefined") && rlm@29: R.is(params.opacity, "undefined") && rlm@29: $(node, {opacity: attrs.opacity}); rlm@29: !R.is(attrs["fill-opacity"], "undefined") && rlm@29: R.is(params["fill-opacity"], "undefined") && rlm@29: $(node, {"fill-opacity": attrs["fill-opacity"]}); rlm@29: } else if ((({circle: 1, ellipse: 1})[has](o.type) || (value + E).charAt() != "r") && addGradientFill(node, value, o.paper)) { rlm@29: attrs.gradient = value; rlm@29: attrs.fill = "none"; rlm@29: break; rlm@29: } rlm@29: case "stroke": rlm@29: node[setAttribute](att, R.getRGB(value).hex); rlm@29: break; rlm@29: case "gradient": rlm@29: (({circle: 1, ellipse: 1})[has](o.type) || (value + E).charAt() != "r") && addGradientFill(node, value, o.paper); rlm@29: break; rlm@29: case "opacity": rlm@29: case "fill-opacity": rlm@29: if (attrs.gradient) { rlm@29: var gradient = doc.getElementById(node.getAttribute("fill")[rp](/^url\(#|\)$/g, E)); rlm@29: if (gradient) { rlm@29: var stops = gradient.getElementsByTagName("stop"); rlm@29: stops[stops[length] - 1][setAttribute]("stop-opacity", value); rlm@29: } rlm@29: break; rlm@29: } rlm@29: default: rlm@29: att == "font-size" && (value = toInt(value, 10) + "px"); rlm@29: var cssrule = att[rp](/(\-.)/g, function (w) { rlm@29: return upperCase.call(w.substring(1)); rlm@29: }); rlm@29: node.style[cssrule] = value; rlm@29: // Need following line for Firefox rlm@29: node[setAttribute](att, value); rlm@29: break; rlm@29: } rlm@29: } rlm@29: rlm@29: tuneText(o, params); rlm@29: if (rotxy) { rlm@29: o.rotate(rotxy.join(S)); rlm@29: } else { rlm@29: toFloat(rot) && o.rotate(rot, true); rlm@29: } rlm@29: }; rlm@29: var leading = 1.2; rlm@29: var tuneText = function (el, params) { rlm@29: if (el.type != "text" || !(params[has]("text") || params[has]("font") || params[has]("font-size") || params[has]("x") || params[has]("y"))) { rlm@29: return; rlm@29: } rlm@29: var a = el.attrs, rlm@29: node = el.node, rlm@29: fontSize = node.firstChild ? toInt(doc.defaultView.getComputedStyle(node.firstChild, E).getPropertyValue("font-size"), 10) : 10; rlm@29: rlm@29: if (params[has]("text")) { rlm@29: a.text = params.text; rlm@29: while (node.firstChild) { rlm@29: node.removeChild(node.firstChild); rlm@29: } rlm@29: var texts = (params.text + E)[split]("\n"); rlm@29: for (var i = 0, ii = texts[length]; i < ii; i++) if (texts[i]) { rlm@29: var tspan = $("tspan"); rlm@29: i && $(tspan, {dy: fontSize * leading, x: a.x}); rlm@29: tspan[appendChild](doc.createTextNode(texts[i])); rlm@29: node[appendChild](tspan); rlm@29: } rlm@29: } else { rlm@29: var texts = node.getElementsByTagName("tspan"); rlm@29: for (var i = 0, ii = texts[length]; i < ii; i++) { rlm@29: i && $(texts[i], {dy: fontSize * leading, x: a.x}); rlm@29: } rlm@29: } rlm@29: $(node, {y: a.y}); rlm@29: var bb = el.getBBox(), rlm@29: dif = a.y - (bb.y + bb.height / 2); rlm@29: dif && isFinite(dif) && $(node, {y: a.y + dif}); rlm@29: }; rlm@29: var Element = function (node, svg) { rlm@29: var X = 0, rlm@29: Y = 0; rlm@29: this[0] = node; rlm@29: this.id = R._oid++; rlm@29: this.node = node; rlm@29: node.raphael = this; rlm@29: this.paper = svg; rlm@29: this.attrs = this.attrs || {}; rlm@29: this.transformations = []; // rotate, translate, scale rlm@29: this._ = { rlm@29: tx: 0, rlm@29: ty: 0, rlm@29: rt: {deg: 0, cx: 0, cy: 0}, rlm@29: sx: 1, rlm@29: sy: 1 rlm@29: }; rlm@29: !svg.bottom && (svg.bottom = this); rlm@29: this.prev = svg.top; rlm@29: svg.top && (svg.top.next = this); rlm@29: svg.top = this; rlm@29: this.next = null; rlm@29: }; rlm@29: Element[proto].rotate = function (deg, cx, cy) { rlm@29: if (this.removed) { rlm@29: return this; rlm@29: } rlm@29: if (deg == null) { rlm@29: if (this._.rt.cx) { rlm@29: return [this._.rt.deg, this._.rt.cx, this._.rt.cy][join](S); rlm@29: } rlm@29: return this._.rt.deg; rlm@29: } rlm@29: var bbox = this.getBBox(); rlm@29: deg = (deg + E)[split](separator); rlm@29: if (deg[length] - 1) { rlm@29: cx = toFloat(deg[1]); rlm@29: cy = toFloat(deg[2]); rlm@29: } rlm@29: deg = toFloat(deg[0]); rlm@29: if (cx != null) { rlm@29: this._.rt.deg = deg; rlm@29: } else { rlm@29: this._.rt.deg += deg; rlm@29: } rlm@29: (cy == null) && (cx = null); rlm@29: this._.rt.cx = cx; rlm@29: this._.rt.cy = cy; rlm@29: cx = cx == null ? bbox.x + bbox.width / 2 : cx; rlm@29: cy = cy == null ? bbox.y + bbox.height / 2 : cy; rlm@29: if (this._.rt.deg) { rlm@29: this.transformations[0] = R.format("rotate({0} {1} {2})", this._.rt.deg, cx, cy); rlm@29: this.clip && $(this.clip, {transform: R.format("rotate({0} {1} {2})", -this._.rt.deg, cx, cy)}); rlm@29: } else { rlm@29: this.transformations[0] = E; rlm@29: this.clip && $(this.clip, {transform: E}); rlm@29: } rlm@29: $(this.node, {transform: this.transformations[join](S)}); rlm@29: return this; rlm@29: }; rlm@29: Element[proto].hide = function () { rlm@29: !this.removed && (this.node.style.display = "none"); rlm@29: return this; rlm@29: }; rlm@29: Element[proto].show = function () { rlm@29: !this.removed && (this.node.style.display = ""); rlm@29: return this; rlm@29: }; rlm@29: Element[proto].remove = function () { rlm@29: if (this.removed) { rlm@29: return; rlm@29: } rlm@29: tear(this, this.paper); rlm@29: this.node.parentNode.removeChild(this.node); rlm@29: for (var i in this) { rlm@29: delete this[i]; rlm@29: } rlm@29: this.removed = true; rlm@29: }; rlm@29: Element[proto].getBBox = function () { rlm@29: if (this.removed) { rlm@29: return this; rlm@29: } rlm@29: if (this.type == "path") { rlm@29: return pathDimensions(this.attrs.path); rlm@29: } rlm@29: if (this.node.style.display == "none") { rlm@29: this.show(); rlm@29: var hide = true; rlm@29: } rlm@29: var bbox = {}; rlm@29: try { rlm@29: bbox = this.node.getBBox(); rlm@29: } catch(e) { rlm@29: // Firefox 3.0.x plays badly here rlm@29: } finally { rlm@29: bbox = bbox || {}; rlm@29: } rlm@29: if (this.type == "text") { rlm@29: bbox = {x: bbox.x, y: Infinity, width: 0, height: 0}; rlm@29: for (var i = 0, ii = this.node.getNumberOfChars(); i < ii; i++) { rlm@29: var bb = this.node.getExtentOfChar(i); rlm@29: (bb.y < bbox.y) && (bbox.y = bb.y); rlm@29: (bb.y + bb.height - bbox.y > bbox.height) && (bbox.height = bb.y + bb.height - bbox.y); rlm@29: (bb.x + bb.width - bbox.x > bbox.width) && (bbox.width = bb.x + bb.width - bbox.x); rlm@29: } rlm@29: } rlm@29: hide && this.hide(); rlm@29: return bbox; rlm@29: }; rlm@29: Element[proto].attr = function () { rlm@29: if (this.removed) { rlm@29: return this; rlm@29: } rlm@29: if (arguments[length] == 0) { rlm@29: var res = {}; rlm@29: for (var i in this.attrs) if (this.attrs[has](i)) { rlm@29: res[i] = this.attrs[i]; rlm@29: } rlm@29: this._.rt.deg && (res.rotation = this.rotate()); rlm@29: (this._.sx != 1 || this._.sy != 1) && (res.scale = this.scale()); rlm@29: res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient; rlm@29: return res; rlm@29: } rlm@29: if (arguments[length] == 1 && R.is(arguments[0], "string")) { rlm@29: if (arguments[0] == "translation") { rlm@29: return translate.call(this); rlm@29: } rlm@29: if (arguments[0] == "rotation") { rlm@29: return this.rotate(); rlm@29: } rlm@29: if (arguments[0] == "scale") { rlm@29: return this.scale(); rlm@29: } rlm@29: if (arguments[0] == "fill" && this.attrs.fill == "none" && this.attrs.gradient) { rlm@29: return this.attrs.gradient; rlm@29: } rlm@29: return this.attrs[arguments[0]]; rlm@29: } rlm@29: if (arguments[length] == 1 && R.is(arguments[0], "array")) { rlm@29: var values = {}; rlm@29: for (var j in arguments[0]) if (arguments[0][has](j)) { rlm@29: values[arguments[0][j]] = this.attrs[arguments[0][j]]; rlm@29: } rlm@29: return values; rlm@29: } rlm@29: if (arguments[length] == 2) { rlm@29: var params = {}; rlm@29: params[arguments[0]] = arguments[1]; rlm@29: setFillAndStroke(this, params); rlm@29: } else if (arguments[length] == 1 && R.is(arguments[0], "object")) { rlm@29: setFillAndStroke(this, arguments[0]); rlm@29: } rlm@29: return this; rlm@29: }; rlm@29: Element[proto].toFront = function () { rlm@29: if (this.removed) { rlm@29: return this; rlm@29: } rlm@29: this.node.parentNode[appendChild](this.node); rlm@29: var svg = this.paper; rlm@29: svg.top != this && tofront(this, svg); rlm@29: return this; rlm@29: }; rlm@29: Element[proto].toBack = function () { rlm@29: if (this.removed) { rlm@29: return this; rlm@29: } rlm@29: if (this.node.parentNode.firstChild != this.node) { rlm@29: this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild); rlm@29: toback(this, this.paper); rlm@29: var svg = this.paper; rlm@29: } rlm@29: return this; rlm@29: }; rlm@29: Element[proto].insertAfter = function (element) { rlm@29: if (this.removed) { rlm@29: return this; rlm@29: } rlm@29: var node = element.node; rlm@29: if (node.nextSibling) { rlm@29: node.parentNode.insertBefore(this.node, node.nextSibling); rlm@29: } else { rlm@29: node.parentNode[appendChild](this.node); rlm@29: } rlm@29: insertafter(this, element, this.paper); rlm@29: return this; rlm@29: }; rlm@29: Element[proto].insertBefore = function (element) { rlm@29: if (this.removed) { rlm@29: return this; rlm@29: } rlm@29: var node = element.node; rlm@29: node.parentNode.insertBefore(this.node, node); rlm@29: insertbefore(this, element, this.paper); rlm@29: return this; rlm@29: }; rlm@29: var theCircle = function (svg, x, y, r) { rlm@29: x = round(x); rlm@29: y = round(y); rlm@29: var el = $("circle"); rlm@29: svg.canvas && svg.canvas[appendChild](el); rlm@29: var res = new Element(el, svg); rlm@29: res.attrs = {cx: x, cy: y, r: r, fill: "none", stroke: "#000"}; rlm@29: res.type = "circle"; rlm@29: $(el, res.attrs); rlm@29: return res; rlm@29: }; rlm@29: var theRect = function (svg, x, y, w, h, r) { rlm@29: x = round(x); rlm@29: y = round(y); rlm@29: var el = $("rect"); rlm@29: svg.canvas && svg.canvas[appendChild](el); rlm@29: var res = new Element(el, svg); rlm@29: res.attrs = {x: x, y: y, width: w, height: h, r: r || 0, rx: r || 0, ry: r || 0, fill: "none", stroke: "#000"}; rlm@29: res.type = "rect"; rlm@29: $(el, res.attrs); rlm@29: return res; rlm@29: }; rlm@29: var theEllipse = function (svg, x, y, rx, ry) { rlm@29: x = round(x); rlm@29: y = round(y); rlm@29: var el = $("ellipse"); rlm@29: svg.canvas && svg.canvas[appendChild](el); rlm@29: var res = new Element(el, svg); rlm@29: res.attrs = {cx: x, cy: y, rx: rx, ry: ry, fill: "none", stroke: "#000"}; rlm@29: res.type = "ellipse"; rlm@29: $(el, res.attrs); rlm@29: return res; rlm@29: }; rlm@29: var theImage = function (svg, src, x, y, w, h) { rlm@29: var el = $("image"); rlm@29: $(el, {x: x, y: y, width: w, height: h, preserveAspectRatio: "none"}); rlm@29: el.setAttributeNS(svg.xlink, "href", src); rlm@29: svg.canvas && svg.canvas[appendChild](el); rlm@29: var res = new Element(el, svg); rlm@29: res.attrs = {x: x, y: y, width: w, height: h, src: src}; rlm@29: res.type = "image"; rlm@29: return res; rlm@29: }; rlm@29: var theText = function (svg, x, y, text) { rlm@29: var el = $("text"); rlm@29: $(el, {x: x, y: y, "text-anchor": "middle"}); rlm@29: svg.canvas && svg.canvas[appendChild](el); rlm@29: var res = new Element(el, svg); rlm@29: res.attrs = {x: x, y: y, "text-anchor": "middle", text: text, font: availableAttrs.font, stroke: "none", fill: "#000"}; rlm@29: res.type = "text"; rlm@29: setFillAndStroke(res, res.attrs); rlm@29: return res; rlm@29: }; rlm@29: var setSize = function (width, height) { rlm@29: this.width = width || this.width; rlm@29: this.height = height || this.height; rlm@29: this.canvas[setAttribute]("width", this.width); rlm@29: this.canvas[setAttribute]("height", this.height); rlm@29: return this; rlm@29: }; rlm@29: var create = function () { rlm@29: var con = getContainer[apply](null, arguments), rlm@29: container = con && con.container, rlm@29: x = con.x, rlm@29: y = con.y, rlm@29: width = con.width, rlm@29: height = con.height; rlm@29: if (!container) { rlm@29: throw new Error("SVG container not found."); rlm@29: } rlm@29: var cnvs = $("svg"); rlm@29: width = width || 512; rlm@29: height = height || 342; rlm@29: $(cnvs, { rlm@29: xmlns: "http://www.w3.org/2000/svg", rlm@29: version: 1.1, rlm@29: width: width, rlm@29: height: height rlm@29: }); rlm@29: if (container == 1) { rlm@29: cnvs.style.cssText = "position:absolute;left:" + x + "px;top:" + y + "px"; rlm@29: doc.body[appendChild](cnvs); rlm@29: } else { rlm@29: if (container.firstChild) { rlm@29: container.insertBefore(cnvs, container.firstChild); rlm@29: } else { rlm@29: container[appendChild](cnvs); rlm@29: } rlm@29: } rlm@29: container = new Paper; rlm@29: container.width = width; rlm@29: container.height = height; rlm@29: container.canvas = cnvs; rlm@29: plugins.call(container, container, R.fn); rlm@29: container.clear(); rlm@29: return container; rlm@29: }; rlm@29: Paper[proto].clear = function () { rlm@29: var c = this.canvas; rlm@29: while (c.firstChild) { rlm@29: c.removeChild(c.firstChild); rlm@29: } rlm@29: this.bottom = this.top = null; rlm@29: (this.desc = $("desc"))[appendChild](doc.createTextNode("Created with Rapha\xebl")); rlm@29: c[appendChild](this.desc); rlm@29: c[appendChild](this.defs = $("defs")); rlm@29: }; rlm@29: Paper[proto].remove = function () { rlm@29: this.canvas.parentNode && this.canvas.parentNode.removeChild(this.canvas); rlm@29: for (var i in this) { rlm@29: this[i] = removed(i); rlm@29: } rlm@29: }; rlm@29: } rlm@29: rlm@29: // VML rlm@29: if (R.vml) { rlm@29: var path2vml = function (path) { rlm@29: var total = /[ahqstv]/ig, rlm@29: command = pathToAbsolute; rlm@29: (path + E).match(total) && (command = path2curve); rlm@29: total = /[clmz]/g; rlm@29: if (command == pathToAbsolute && !(path + E).match(total)) { rlm@29: var map = {M: "m", L: "l", C: "c", Z: "x", m: "t", l: "r", c: "v", z: "x"}, rlm@29: bites = /([clmz]),?([^clmz]*)/gi, rlm@29: val = /-?[^,\s-]+/g; rlm@29: var res = (path + E)[rp](bites, function (all, command, args) { rlm@29: var vals = []; rlm@29: args[rp](val, function (value) { rlm@29: vals[push](round(value)); rlm@29: }); rlm@29: return map[command] + vals; rlm@29: }); rlm@29: return res; rlm@29: } rlm@29: var pa = command(path), p, res = [], r; rlm@29: for (var i = 0, ii = pa[length]; i < ii; i++) { rlm@29: p = pa[i]; rlm@29: r = lowerCase.call(pa[i][0]); rlm@29: r == "z" && (r = "x"); rlm@29: for (var j = 1, jj = p[length]; j < jj; j++) { rlm@29: r += round(p[j]) + (j != jj - 1 ? "," : E); rlm@29: } rlm@29: res[push](r); rlm@29: } rlm@29: return res[join](S); rlm@29: }; rlm@29: rlm@29: R[toString] = function () { rlm@29: return "Your browser doesn\u2019t support SVG. Falling down to VML.\nYou are running Rapha\xebl " + this.version; rlm@29: }; rlm@29: var thePath = function (pathString, VML) { rlm@29: var g = createNode("group"); rlm@29: g.style.cssText = "position:absolute;left:0;top:0;width:" + VML.width + "px;height:" + VML.height + "px"; rlm@29: g.coordsize = VML.coordsize; rlm@29: g.coordorigin = VML.coordorigin; rlm@29: var el = createNode("shape"), ol = el.style; rlm@29: ol.width = VML.width + "px"; rlm@29: ol.height = VML.height + "px"; rlm@29: el.coordsize = this.coordsize; rlm@29: el.coordorigin = this.coordorigin; rlm@29: g[appendChild](el); rlm@29: var p = new Element(el, g, VML); rlm@29: p.isAbsolute = true; rlm@29: p.type = "path"; rlm@29: p.path = []; rlm@29: p.Path = E; rlm@29: pathString && setFillAndStroke(p, {fill: "none", stroke: "#000", path: pathString}); rlm@29: VML.canvas[appendChild](g); rlm@29: return p; rlm@29: }; rlm@29: var setFillAndStroke = function (o, params) { rlm@29: o.attrs = o.attrs || {}; rlm@29: var node = o.node, rlm@29: a = o.attrs, rlm@29: s = node.style, rlm@29: xy, rlm@29: res = o; rlm@29: for (var par in params) if (params[has](par)) { rlm@29: a[par] = params[par]; rlm@29: } rlm@29: params.href && (node.href = params.href); rlm@29: params.title && (node.title = params.title); rlm@29: params.target && (node.target = params.target); rlm@29: params.cursor && (s.cursor = params.cursor); rlm@29: if (params.path && o.type == "path") { rlm@29: a.path = params.path; rlm@29: node.path = path2vml(a.path); rlm@29: } rlm@29: if (params.rotation != null) { rlm@29: o.rotate(params.rotation, true); rlm@29: } rlm@29: if (params.translation) { rlm@29: xy = (params.translation + E)[split](separator); rlm@29: translate.call(o, xy[0], xy[1]); rlm@29: if (o._.rt.cx != null) { rlm@29: o._.rt.cx +=+ xy[0]; rlm@29: o._.rt.cy +=+ xy[1]; rlm@29: o.setBox(o.attrs, xy[0], xy[1]); rlm@29: } rlm@29: } rlm@29: if (params.scale) { rlm@29: xy = (params.scale + E)[split](separator); rlm@29: o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, +xy[2] || null, +xy[3] || null); rlm@29: } rlm@29: if ("clip-rect" in params) { rlm@29: var rect = (params["clip-rect"] + E)[split](separator); rlm@29: if (rect[length] == 4) { rlm@29: rect[2] = +rect[2] + (+rect[0]); rlm@29: rect[3] = +rect[3] + (+rect[1]); rlm@29: var div = node.clipRect || doc.createElement("div"), rlm@29: dstyle = div.style, rlm@29: group = node.parentNode; rlm@29: dstyle.clip = R.format("rect({1}px {2}px {3}px {0}px)", rect); rlm@29: if (!node.clipRect) { rlm@29: dstyle.position = "absolute"; rlm@29: dstyle.top = 0; rlm@29: dstyle.left = 0; rlm@29: dstyle.width = o.paper.width + "px"; rlm@29: dstyle.height = o.paper.height + "px"; rlm@29: group.parentNode.insertBefore(div, group); rlm@29: div[appendChild](group); rlm@29: node.clipRect = div; rlm@29: } rlm@29: } rlm@29: if (!params["clip-rect"]) { rlm@29: node.clipRect && (node.clipRect.style.clip = E); rlm@29: } rlm@29: } rlm@29: if (o.type == "image" && params.src) { rlm@29: node.src = params.src; rlm@29: } rlm@29: if (o.type == "image" && params.opacity) { rlm@29: node.filterOpacity = " progid:DXImageTransform.Microsoft.Alpha(opacity=" + (params.opacity * 100) + ")"; rlm@29: s.filter = (node.filterMatrix || E) + (node.filterOpacity || E); rlm@29: } rlm@29: params.font && (s.font = params.font); rlm@29: params["font-family"] && (s.fontFamily = '"' + params["font-family"][split](",")[0][rp](/^['"]+|['"]+$/g, E) + '"'); rlm@29: params["font-size"] && (s.fontSize = params["font-size"]); rlm@29: params["font-weight"] && (s.fontWeight = params["font-weight"]); rlm@29: params["font-style"] && (s.fontStyle = params["font-style"]); rlm@29: if (params.opacity != null || rlm@29: params["stroke-width"] != null || rlm@29: params.fill != null || rlm@29: params.stroke != null || rlm@29: params["stroke-width"] != null || rlm@29: params["stroke-opacity"] != null || rlm@29: params["fill-opacity"] != null || rlm@29: params["stroke-dasharray"] != null || rlm@29: params["stroke-miterlimit"] != null || rlm@29: params["stroke-linejoin"] != null || rlm@29: params["stroke-linecap"] != null) { rlm@29: node = o.shape || node; rlm@29: var fill = (node.getElementsByTagName("fill") && node.getElementsByTagName("fill")[0]), rlm@29: newfill = false; rlm@29: !fill && (newfill = fill = createNode("fill")); rlm@29: if ("fill-opacity" in params || "opacity" in params) { rlm@29: var opacity = ((+a["fill-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1); rlm@29: opacity < 0 && (opacity = 0); rlm@29: opacity > 1 && (opacity = 1); rlm@29: fill.opacity = opacity; rlm@29: } rlm@29: params.fill && (fill.on = true); rlm@29: if (fill.on == null || params.fill == "none") { rlm@29: fill.on = false; rlm@29: } rlm@29: if (fill.on && params.fill) { rlm@29: var isURL = params.fill.match(ISURL); rlm@29: if (isURL) { rlm@29: fill.src = isURL[1]; rlm@29: fill.type = "tile"; rlm@29: } else { rlm@29: fill.color = R.getRGB(params.fill).hex; rlm@29: fill.src = E; rlm@29: fill.type = "solid"; rlm@29: if (R.getRGB(params.fill).error && (res.type in {circle: 1, ellipse: 1} || (params.fill + E).charAt() != "r") && addGradientFill(res, params.fill)) { rlm@29: a.fill = "none"; rlm@29: a.gradient = params.fill; rlm@29: } rlm@29: } rlm@29: } rlm@29: newfill && node[appendChild](fill); rlm@29: var stroke = (node.getElementsByTagName("stroke") && node.getElementsByTagName("stroke")[0]), rlm@29: newstroke = false; rlm@29: !stroke && (newstroke = stroke = createNode("stroke")); rlm@29: if ((params.stroke && params.stroke != "none") || rlm@29: params["stroke-width"] || rlm@29: params["stroke-opacity"] != null || rlm@29: params["stroke-dasharray"] || rlm@29: params["stroke-miterlimit"] || rlm@29: params["stroke-linejoin"] || rlm@29: params["stroke-linecap"]) { rlm@29: stroke.on = true; rlm@29: } rlm@29: (params.stroke == "none" || stroke.on == null || params.stroke == 0 || params["stroke-width"] == 0) && (stroke.on = false); rlm@29: stroke.on && params.stroke && (stroke.color = R.getRGB(params.stroke).hex); rlm@29: var opacity = ((+a["stroke-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1), rlm@29: width = (toFloat(params["stroke-width"]) || 1) * .75; rlm@29: opacity < 0 && (opacity = 0); rlm@29: opacity > 1 && (opacity = 1); rlm@29: params["stroke-width"] == null && (width = a["stroke-width"]); rlm@29: params["stroke-width"] && (stroke.weight = width); rlm@29: width && width < 1 && (opacity *= width) && (stroke.weight = 1); rlm@29: stroke.opacity = opacity; rlm@29: rlm@29: params["stroke-linejoin"] && (stroke.joinstyle = params["stroke-linejoin"] || "miter"); rlm@29: stroke.miterlimit = params["stroke-miterlimit"] || 8; rlm@29: params["stroke-linecap"] && (stroke.endcap = params["stroke-linecap"] == "butt" ? "flat" : params["stroke-linecap"] == "square" ? "square" : "round"); rlm@29: if (params["stroke-dasharray"]) { rlm@29: var dasharray = { rlm@29: "-": "shortdash", rlm@29: ".": "shortdot", rlm@29: "-.": "shortdashdot", rlm@29: "-..": "shortdashdotdot", rlm@29: ". ": "dot", rlm@29: "- ": "dash", rlm@29: "--": "longdash", rlm@29: "- .": "dashdot", rlm@29: "--.": "longdashdot", rlm@29: "--..": "longdashdotdot" rlm@29: }; rlm@29: stroke.dashstyle = dasharray[has](params["stroke-dasharray"]) ? dasharray[params["stroke-dasharray"]] : E; rlm@29: } rlm@29: newstroke && node[appendChild](stroke); rlm@29: } rlm@29: if (res.type == "text") { rlm@29: var s = res.paper.span.style; rlm@29: a.font && (s.font = a.font); rlm@29: a["font-family"] && (s.fontFamily = a["font-family"]); rlm@29: a["font-size"] && (s.fontSize = a["font-size"]); rlm@29: a["font-weight"] && (s.fontWeight = a["font-weight"]); rlm@29: a["font-style"] && (s.fontStyle = a["font-style"]); rlm@29: res.node.string && (res.paper.span.innerHTML = (res.node.string + E)[rp](/")); rlm@29: res.W = a.w = res.paper.span.offsetWidth; rlm@29: res.H = a.h = res.paper.span.offsetHeight; rlm@29: res.X = a.x; rlm@29: res.Y = a.y + round(res.H / 2); rlm@29: rlm@29: // text-anchor emulationm rlm@29: switch (a["text-anchor"]) { rlm@29: case "start": rlm@29: res.node.style["v-text-align"] = "left"; rlm@29: res.bbx = round(res.W / 2); rlm@29: break; rlm@29: case "end": rlm@29: res.node.style["v-text-align"] = "right"; rlm@29: res.bbx = -round(res.W / 2); rlm@29: break; rlm@29: default: rlm@29: res.node.style["v-text-align"] = "center"; rlm@29: break; rlm@29: } rlm@29: } rlm@29: }; rlm@29: var addGradientFill = function (o, gradient) { rlm@29: o.attrs = o.attrs || {}; rlm@29: var attrs = o.attrs, rlm@29: fill = o.node.getElementsByTagName("fill"), rlm@29: type = "linear", rlm@29: fxfy = ".5 .5"; rlm@29: o.attrs.gradient = gradient; rlm@29: gradient = (gradient + E)[rp](radial_gradient, function (all, fx, fy) { rlm@29: type = "radial"; rlm@29: if (fx && fy) { rlm@29: fx = toFloat(fx); rlm@29: fy = toFloat(fy); rlm@29: pow(fx - .5, 2) + pow(fy - .5, 2) > .25 && (fy = math.sqrt(.25 - pow(fx - .5, 2)) * ((fy > .5) * 2 - 1) + .5); rlm@29: fxfy = fx + S + fy; rlm@29: } rlm@29: return E; rlm@29: }); rlm@29: gradient = gradient[split](/\s*\-\s*/); rlm@29: if (type == "linear") { rlm@29: var angle = gradient.shift(); rlm@29: angle = -toFloat(angle); rlm@29: if (isNaN(angle)) { rlm@29: return null; rlm@29: } rlm@29: } rlm@29: var dots = parseDots(gradient); rlm@29: if (!dots) { rlm@29: return null; rlm@29: } rlm@29: o = o.shape || o.node; rlm@29: fill = fill[0] || createNode("fill"); rlm@29: if (dots[length]) { rlm@29: fill.on = true; rlm@29: fill.method = "none"; rlm@29: fill.type = (type == "radial") ? "gradientradial" : "gradient"; rlm@29: fill.color = dots[0].color; rlm@29: fill.color2 = dots[dots[length] - 1].color; rlm@29: var clrs = []; rlm@29: for (var i = 0, ii = dots[length]; i < ii; i++) { rlm@29: dots[i].offset && clrs[push](dots[i].offset + S + dots[i].color); rlm@29: } rlm@29: fill.colors && (fill.colors.value = clrs[length] ? clrs[join](",") : "0% " + fill.color); rlm@29: if (type == "radial") { rlm@29: fill.focus = "100%"; rlm@29: fill.focussize = fxfy; rlm@29: fill.focusposition = fxfy; rlm@29: } else { rlm@29: fill.angle = (270 - angle) % 360; rlm@29: } rlm@29: } rlm@29: return 1; rlm@29: }; rlm@29: var Element = function (node, group, vml) { rlm@29: var Rotation = 0, rlm@29: RotX = 0, rlm@29: RotY = 0, rlm@29: Scale = 1; rlm@29: this[0] = node; rlm@29: this.id = R._oid++; rlm@29: this.node = node; rlm@29: node.raphael = this; rlm@29: this.X = 0; rlm@29: this.Y = 0; rlm@29: this.attrs = {}; rlm@29: this.Group = group; rlm@29: this.paper = vml; rlm@29: this._ = { rlm@29: tx: 0, rlm@29: ty: 0, rlm@29: rt: {deg:0}, rlm@29: sx: 1, rlm@29: sy: 1 rlm@29: }; rlm@29: !vml.bottom && (vml.bottom = this); rlm@29: this.prev = vml.top; rlm@29: vml.top && (vml.top.next = this); rlm@29: vml.top = this; rlm@29: this.next = null; rlm@29: }; rlm@29: Element[proto].rotate = function (deg, cx, cy) { rlm@29: if (this.removed) { rlm@29: return this; rlm@29: } rlm@29: if (deg == null) { rlm@29: if (this._.rt.cx) { rlm@29: return [this._.rt.deg, this._.rt.cx, this._.rt.cy][join](S); rlm@29: } rlm@29: return this._.rt.deg; rlm@29: } rlm@29: deg = (deg + E)[split](separator); rlm@29: if (deg[length] - 1) { rlm@29: cx = toFloat(deg[1]); rlm@29: cy = toFloat(deg[2]); rlm@29: } rlm@29: deg = toFloat(deg[0]); rlm@29: if (cx != null) { rlm@29: this._.rt.deg = deg; rlm@29: } else { rlm@29: this._.rt.deg += deg; rlm@29: } rlm@29: cy == null && (cx = null); rlm@29: this._.rt.cx = cx; rlm@29: this._.rt.cy = cy; rlm@29: this.setBox(this.attrs, cx, cy); rlm@29: this.Group.style.rotation = this._.rt.deg; rlm@29: // gradient fix for rotation. TODO rlm@29: // var fill = (this.shape || this.node).getElementsByTagName("fill"); rlm@29: // fill = fill[0] || {}; rlm@29: // var b = ((360 - this._.rt.deg) - 270) % 360; rlm@29: // !R.is(fill.angle, "undefined") && (fill.angle = b); rlm@29: return this; rlm@29: }; rlm@29: Element[proto].setBox = function (params, cx, cy) { rlm@29: if (this.removed) { rlm@29: return this; rlm@29: } rlm@29: var gs = this.Group.style, rlm@29: os = (this.shape && this.shape.style) || this.node.style; rlm@29: params = params || {}; rlm@29: for (var i in params) if (params[has](i)) { rlm@29: this.attrs[i] = params[i]; rlm@29: } rlm@29: cx = cx || this._.rt.cx; rlm@29: cy = cy || this._.rt.cy; rlm@29: var attr = this.attrs, rlm@29: x, rlm@29: y, rlm@29: w, rlm@29: h; rlm@29: switch (this.type) { rlm@29: case "circle": rlm@29: x = attr.cx - attr.r; rlm@29: y = attr.cy - attr.r; rlm@29: w = h = attr.r * 2; rlm@29: break; rlm@29: case "ellipse": rlm@29: x = attr.cx - attr.rx; rlm@29: y = attr.cy - attr.ry; rlm@29: w = attr.rx * 2; rlm@29: h = attr.ry * 2; rlm@29: break; rlm@29: case "rect": rlm@29: case "image": rlm@29: x = +attr.x; rlm@29: y = +attr.y; rlm@29: w = attr.width || 0; rlm@29: h = attr.height || 0; rlm@29: break; rlm@29: case "text": rlm@29: this.textpath.v = ["m", round(attr.x), ", ", round(attr.y - 2), "l", round(attr.x) + 1, ", ", round(attr.y - 2)][join](E); rlm@29: x = attr.x - round(this.W / 2); rlm@29: y = attr.y - this.H / 2; rlm@29: w = this.W; rlm@29: h = this.H; rlm@29: break; rlm@29: case "path": rlm@29: if (!this.attrs.path) { rlm@29: x = 0; rlm@29: y = 0; rlm@29: w = this.paper.width; rlm@29: h = this.paper.height; rlm@29: } else { rlm@29: var dim = pathDimensions(this.attrs.path); rlm@29: x = dim.x; rlm@29: y = dim.y; rlm@29: w = dim.width; rlm@29: h = dim.height; rlm@29: } rlm@29: break; rlm@29: default: rlm@29: x = 0; rlm@29: y = 0; rlm@29: w = this.paper.width; rlm@29: h = this.paper.height; rlm@29: break; rlm@29: } rlm@29: cx = (cx == null) ? x + w / 2 : cx; rlm@29: cy = (cy == null) ? y + h / 2 : cy; rlm@29: var left = cx - this.paper.width / 2, rlm@29: top = cy - this.paper.height / 2; rlm@29: if (this.type == "path" || this.type == "text") { rlm@29: (gs.left != left + "px") && (gs.left = left + "px"); rlm@29: (gs.top != top + "px") && (gs.top = top + "px"); rlm@29: this.X = this.type == "text" ? x : -left; rlm@29: this.Y = this.type == "text" ? y : -top; rlm@29: this.W = w; rlm@29: this.H = h; rlm@29: (os.left != -left + "px") && (os.left = -left + "px"); rlm@29: (os.top != -top + "px") && (os.top = -top + "px"); rlm@29: } else { rlm@29: (gs.left != left + "px") && (gs.left = left + "px"); rlm@29: (gs.top != top + "px") && (gs.top = top + "px"); rlm@29: this.X = x; rlm@29: this.Y = y; rlm@29: this.W = w; rlm@29: this.H = h; rlm@29: (gs.width != this.paper.width + "px") && (gs.width = this.paper.width + "px"); rlm@29: (gs.height != this.paper.height + "px") && (gs.height = this.paper.height + "px"); rlm@29: (os.left != x - left + "px") && (os.left = x - left + "px"); rlm@29: (os.top != y - top + "px") && (os.top = y - top + "px"); rlm@29: (os.width != w + "px") && (os.width = w + "px"); rlm@29: (os.height != h + "px") && (os.height = h + "px"); rlm@29: var arcsize = (+params.r || 0) / mmin(w, h); rlm@29: if (this.type == "rect" && this.arcsize.toFixed(4) != arcsize.toFixed(4) && (arcsize || this.arcsize)) { rlm@29: // We should replace element with the new one rlm@29: var o = createNode("roundrect"), rlm@29: a = {}, rlm@29: i = 0, rlm@29: ii = this.events && this.events[length]; rlm@29: o.arcsize = arcsize; rlm@29: o.raphael = this; rlm@29: this.Group[appendChild](o); rlm@29: this.Group.removeChild(this.node); rlm@29: this[0] = this.node = o; rlm@29: this.arcsize = arcsize; rlm@29: for (var i in attr) { rlm@29: a[i] = attr[i]; rlm@29: } rlm@29: delete a.scale; rlm@29: this.attr(a); rlm@29: if (this.events) for (; i < ii; i++) { rlm@29: this.events[i].unbind = addEvent(this.node, this.events[i].name, this.events[i].f, this); rlm@29: } rlm@29: } rlm@29: } rlm@29: }; rlm@29: Element[proto].hide = function () { rlm@29: !this.removed && (this.Group.style.display = "none"); rlm@29: return this; rlm@29: }; rlm@29: Element[proto].show = function () { rlm@29: !this.removed && (this.Group.style.display = "block"); rlm@29: return this; rlm@29: }; rlm@29: Element[proto].getBBox = function () { rlm@29: if (this.removed) { rlm@29: return this; rlm@29: } rlm@29: if (this.type == "path") { rlm@29: return pathDimensions(this.attrs.path); rlm@29: } rlm@29: return { rlm@29: x: this.X + (this.bbx || 0), rlm@29: y: this.Y, rlm@29: width: this.W, rlm@29: height: this.H rlm@29: }; rlm@29: }; rlm@29: Element[proto].remove = function () { rlm@29: if (this.removed) { rlm@29: return; rlm@29: } rlm@29: tear(this, this.paper); rlm@29: this.node.parentNode.removeChild(this.node); rlm@29: this.Group.parentNode.removeChild(this.Group); rlm@29: this.shape && this.shape.parentNode.removeChild(this.shape); rlm@29: for (var i in this) { rlm@29: delete this[i]; rlm@29: } rlm@29: this.removed = true; rlm@29: }; rlm@29: Element[proto].attr = function () { rlm@29: if (this.removed) { rlm@29: return this; rlm@29: } rlm@29: if (arguments[length] == 0) { rlm@29: var res = {}; rlm@29: for (var i in this.attrs) if (this.attrs[has](i)) { rlm@29: res[i] = this.attrs[i]; rlm@29: } rlm@29: this._.rt.deg && (res.rotation = this.rotate()); rlm@29: (this._.sx != 1 || this._.sy != 1) && (res.scale = this.scale()); rlm@29: res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient; rlm@29: return res; rlm@29: } rlm@29: if (arguments[length] == 1 && R.is(arguments[0], "string")) { rlm@29: if (arguments[0] == "translation") { rlm@29: return translate.call(this); rlm@29: } rlm@29: if (arguments[0] == "rotation") { rlm@29: return this.rotate(); rlm@29: } rlm@29: if (arguments[0] == "scale") { rlm@29: return this.scale(); rlm@29: } rlm@29: if (arguments[0] == "fill" && this.attrs.fill == "none" && this.attrs.gradient) { rlm@29: return this.attrs.gradient; rlm@29: } rlm@29: return this.attrs[arguments[0]]; rlm@29: } rlm@29: if (this.attrs && arguments[length] == 1 && R.is(arguments[0], "array")) { rlm@29: var values = {}; rlm@29: for (var i = 0, ii = arguments[0][length]; i < ii; i++) { rlm@29: values[arguments[0][i]] = this.attrs[arguments[0][i]]; rlm@29: }; rlm@29: return values; rlm@29: } rlm@29: var params; rlm@29: if (arguments[length] == 2) { rlm@29: params = {}; rlm@29: params[arguments[0]] = arguments[1]; rlm@29: } rlm@29: arguments[length] == 1 && R.is(arguments[0], "object") && (params = arguments[0]); rlm@29: if (params) { rlm@29: if (params.text && this.type == "text") { rlm@29: this.node.string = params.text; rlm@29: } rlm@29: setFillAndStroke(this, params); rlm@29: if (params.gradient && (({circle: 1, ellipse: 1})[has](this.type) || (params.gradient + E).charAt() != "r")) { rlm@29: addGradientFill(this, params.gradient); rlm@29: } rlm@29: (this.type != "path" || this._.rt.deg) && this.setBox(this.attrs); rlm@29: } rlm@29: return this; rlm@29: }; rlm@29: Element[proto].toFront = function () { rlm@29: !this.removed && this.Group.parentNode[appendChild](this.Group); rlm@29: this.paper.top != this && tofront(this, this.paper); rlm@29: return this; rlm@29: }; rlm@29: Element[proto].toBack = function () { rlm@29: if (this.removed) { rlm@29: return this; rlm@29: } rlm@29: if (this.Group.parentNode.firstChild != this.Group) { rlm@29: this.Group.parentNode.insertBefore(this.Group, this.Group.parentNode.firstChild); rlm@29: toback(this, this.paper); rlm@29: } rlm@29: return this; rlm@29: }; rlm@29: Element[proto].insertAfter = function (element) { rlm@29: if (this.removed) { rlm@29: return this; rlm@29: } rlm@29: if (element.Group.nextSibling) { rlm@29: element.Group.parentNode.insertBefore(this.Group, element.Group.nextSibling); rlm@29: } else { rlm@29: element.Group.parentNode[appendChild](this.Group); rlm@29: } rlm@29: insertafter(this, element, this.paper); rlm@29: return this; rlm@29: }; rlm@29: Element[proto].insertBefore = function (element) { rlm@29: if (this.removed) { rlm@29: return this; rlm@29: } rlm@29: element.Group.parentNode.insertBefore(this.Group, element.Group); rlm@29: insertbefore(this, element, this.paper); rlm@29: return this; rlm@29: }; rlm@29: rlm@29: var theCircle = function (vml, x, y, r) { rlm@29: var g = createNode("group"), rlm@29: o = createNode("oval"), rlm@29: ol = o.style; rlm@29: g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px"; rlm@29: g.coordsize = vml.coordsize; rlm@29: g.coordorigin = vml.coordorigin; rlm@29: g[appendChild](o); rlm@29: var res = new Element(o, g, vml); rlm@29: res.type = "circle"; rlm@29: setFillAndStroke(res, {stroke: "#000", fill: "none"}); rlm@29: res.attrs.cx = x; rlm@29: res.attrs.cy = y; rlm@29: res.attrs.r = r; rlm@29: res.setBox({x: x - r, y: y - r, width: r * 2, height: r * 2}); rlm@29: vml.canvas[appendChild](g); rlm@29: return res; rlm@29: }, rlm@29: theRect = function (vml, x, y, w, h, r) { rlm@29: var g = createNode("group"), rlm@29: o = createNode("roundrect"), rlm@29: arcsize = (+r || 0) / (mmin(w, h)); rlm@29: g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px"; rlm@29: g.coordsize = vml.coordsize; rlm@29: g.coordorigin = vml.coordorigin; rlm@29: g[appendChild](o); rlm@29: o.arcsize = arcsize; rlm@29: var res = new Element(o, g, vml); rlm@29: res.type = "rect"; rlm@29: setFillAndStroke(res, {stroke: "#000"}); rlm@29: res.arcsize = arcsize; rlm@29: res.setBox({x: x, y: y, width: w, height: h, r: r}); rlm@29: vml.canvas[appendChild](g); rlm@29: return res; rlm@29: }, rlm@29: theEllipse = function (vml, x, y, rx, ry) { rlm@29: var g = createNode("group"), rlm@29: o = createNode("oval"), rlm@29: ol = o.style; rlm@29: g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px"; rlm@29: g.coordsize = vml.coordsize; rlm@29: g.coordorigin = vml.coordorigin; rlm@29: g[appendChild](o); rlm@29: var res = new Element(o, g, vml); rlm@29: res.type = "ellipse"; rlm@29: setFillAndStroke(res, {stroke: "#000"}); rlm@29: res.attrs.cx = x; rlm@29: res.attrs.cy = y; rlm@29: res.attrs.rx = rx; rlm@29: res.attrs.ry = ry; rlm@29: res.setBox({x: x - rx, y: y - ry, width: rx * 2, height: ry * 2}); rlm@29: vml.canvas[appendChild](g); rlm@29: return res; rlm@29: }, rlm@29: theImage = function (vml, src, x, y, w, h) { rlm@29: var g = createNode("group"), rlm@29: o = createNode("image"), rlm@29: ol = o.style; rlm@29: g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px"; rlm@29: g.coordsize = vml.coordsize; rlm@29: g.coordorigin = vml.coordorigin; rlm@29: o.src = src; rlm@29: g[appendChild](o); rlm@29: var res = new Element(o, g, vml); rlm@29: res.type = "image"; rlm@29: res.attrs.src = src; rlm@29: res.attrs.x = x; rlm@29: res.attrs.y = y; rlm@29: res.attrs.w = w; rlm@29: res.attrs.h = h; rlm@29: res.setBox({x: x, y: y, width: w, height: h}); rlm@29: vml.canvas[appendChild](g); rlm@29: return res; rlm@29: }, rlm@29: theText = function (vml, x, y, text) { rlm@29: var g = createNode("group"), rlm@29: el = createNode("shape"), rlm@29: ol = el.style, rlm@29: path = createNode("path"), rlm@29: ps = path.style, rlm@29: o = createNode("textpath"); rlm@29: g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px"; rlm@29: g.coordsize = vml.coordsize; rlm@29: g.coordorigin = vml.coordorigin; rlm@29: path.v = R.format("m{0},{1}l{2},{1}", round(x), round(y), round(x) + 1); rlm@29: path.textpathok = true; rlm@29: ol.width = vml.width; rlm@29: ol.height = vml.height; rlm@29: o.string = text + E; rlm@29: o.on = true; rlm@29: el[appendChild](o); rlm@29: el[appendChild](path); rlm@29: g[appendChild](el); rlm@29: var res = new Element(o, g, vml); rlm@29: res.shape = el; rlm@29: res.textpath = path; rlm@29: res.type = "text"; rlm@29: res.attrs.text = text; rlm@29: res.attrs.x = x; rlm@29: res.attrs.y = y; rlm@29: res.attrs.w = 1; rlm@29: res.attrs.h = 1; rlm@29: setFillAndStroke(res, {font: availableAttrs.font, stroke: "none", fill: "#000"}); rlm@29: res.setBox(); rlm@29: vml.canvas[appendChild](g); rlm@29: return res; rlm@29: }, rlm@29: setSize = function (width, height) { rlm@29: var cs = this.canvas.style; rlm@29: width == +width && (width += "px"); rlm@29: height == +height && (height += "px"); rlm@29: cs.width = width; rlm@29: cs.height = height; rlm@29: cs.clip = "rect(0 " + width + " " + height + " 0)"; rlm@29: return this; rlm@29: }, rlm@29: createNode; rlm@29: doc.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)"); rlm@29: try { rlm@29: !doc.namespaces.rvml && doc.namespaces.add("rvml", "urn:schemas-microsoft-com:vml"); rlm@29: createNode = function (tagName) { rlm@29: return doc.createElement('