// SVG
if (R.svg) {
+ var round = function (num) {
+ return isNaN(num) ? num : +num + ((+num).toFixed() == +num) * .5;
+ };
+ var roundPath = function (path) {
+ for (var i = 0, ii = path.length; i < ii; i++) {
+ if (path[i][0].toLowerCase() != "a") {
+ for (var j = 0, jj = path[i].length; j < jj; j++) {
+ var x = path[i][j];
+ path[i][j] = round(x);
+ }
+ } else {
+ path[i][6] = round(path[i][6]);
+ path[i][7] = round(path[i][7]);
+ }
+ }
+ return path;
+ };
R.toString = function () {
return "Your browser supports SVG.\nYou are running Rapha\u00ebl " + this.version;
};
}
var p = new Element(el, SVG);
p.type = "path";
- p.attrs.path = R.parsePathString(pathString);
+ p.attrs.path = roundPath(pathToAbsolute(pathString));
pathString && p.node.setAttribute("d", p.attrs.path);
setFillAndStroke(p, {fill: "none", stroke: "#000"});
return p;
break;
case "path":
if (o.type == "path") {
- attrs.path = R.parsePathString(value);
+ attrs.path = roundPath(pathToAbsolute(value));
node.setAttribute("d", attrs.path);
}
case "width":
}
break;
}
+ case "font-size":
+ value = parseInt(value, 10) + "px";
default :
var cssrule = att.replace(/(\-.)/g, function (w) {
return w.substring(1).toUpperCase();
return this;
};
var theCircle = function (svg, x, y, r) {
+ x = round(x);
+ y = round(y);
var el = doc.createElementNS(svg.svgns, "circle");
el.setAttribute("cx", x);
el.setAttribute("cy", y);
return res;
};
var theRect = function (svg, x, y, w, h, r) {
+ x = round(x);
+ y = round(y);
var el = doc.createElementNS(svg.svgns, "rect");
el.setAttribute("x", x);
el.setAttribute("y", y);
return res;
};
var theEllipse = function (svg, x, y, rx, ry) {
+ x = round(x);
+ y = round(y);
var el = doc.createElementNS(svg.svgns, "ellipse");
el.setAttribute("cx", x);
el.setAttribute("cy", y);
params.title && (node.title = params.title);
params.target && (node.target = params.target);
if (params.path && o.type == "path") {
- o.node.path = path2vml(params.path);
+ o.attrs.path = R.parsePathString(params.path);
+ o.node.path = path2vml(o.attrs.path);
}
if (params.rotation != null) {
o.rotate(params.rotation, true);
paper.text = function (x, y, text) {
return theText(this, x, y, text);
};
- paper.drawGrid = function (x, y, w, h, wv, hv, color) {
- color = color || "#000";
- var path = ["M", x, y, "L", x + w, y, x + w, y + h, x, y + h, x, y],
- rowHeight = h / hv,
- columnWidth = w / wv;
- for (var i = 1; i < hv; i++) {
- path = path.concat(["M", x, y + i * rowHeight, "L", x + w, y + i * rowHeight]);
- }
- for (var i = 1; i < wv; i++) {
- path = path.concat(["M", x + i * columnWidth, y, "L", x + i * columnWidth, y + h]);
- }
- return this.path({stroke: color, "stroke-width": 1}, path.join(","));
- };
paper.set = function (itemsArray) {
return new Set(itemsArray);
};
clearTimeout(this.animation_in_progress);
if (typeof easing == "function" || !easing) {
callback = easing || null;
- easing = "linear";
}
var from = {},
to = {},
}
var start = +new Date,
prev = 0,
+ upto255 = function (color) {
+ return +color > 255 ? 255 : +color;
+ },
that = this;
(function tick() {
var time = new Date - start,
set = {},
now;
if (time < ms) {
- pos = R.easing(easing, time / ms);
+ var pos = R.easing(easing, time / ms);
for (var attr in from) {
switch (availableAnimAttrs[attr]) {
case "number":
break;
case "colour":
now = "rgb(" + [
- Math.round(from[attr].r + pos * ms * diff[attr].r),
- Math.round(from[attr].g + pos * ms * diff[attr].g),
- Math.round(from[attr].b + pos * ms * diff[attr].b)
+ upto255(Math.round(from[attr].r + pos * ms * diff[attr].r)),
+ upto255(Math.round(from[attr].g + pos * ms * diff[attr].g)),
+ upto255(Math.round(from[attr].b + pos * ms * diff[attr].b))
].join(",") + ")";
break;
case "path":
}
break;
}
- if (attr == "font-size") {
- set[attr] = now + "px";
- } else {
- set[attr] = now;
- }
+ set[attr] = now;
}
that.attr(set);
that.animation_in_progress = setTimeout(tick);
var Set = function (items) {
this.items = [];
this.length = 0;
+ arguments.length > 1 && (items = Array.prototype.splice.call(arguments, 0, arguments.length));
if (items) {
for (var i = 0, ii = items.length; i < ii; i++) {
if (items[i] && (items[i].constructor == Element || items[i].constructor == Set)) {