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