我非常尴尬地意识到,段属性是一个自定义属性,创建并用于我发现更新扇形饼的路径的示例,因此它的大小。它看起来像这样:
var r = Raphael("holder");
r.customAttributes.segment = function (x, y, r, a1, a2) {
var flag = (a2 - a1) > 180,
clr = (a2 - a1)/360;
a1 = (a1 % 360) * Math.PI/180;
a2 = (a2 % 360) * Math.PI/180;
return {
path: [["M", x, y], ["l", r * Math.cos(a1), r * Math.sin(a1)], ["A", r, r, 0, +flag, 1, x + r * Math.cos(a2), y + r * Math.sin(a2)], ["z"]],
fill: "hsb(" + clr + ", .75, .8)"
};
};
这里的,这可能是什么样的背景下:我有三个值[10,20,15]认为总数达到45假定为250的宽度和高度,我可以一圆填充使用这样的段自定义属性片圆(假设我有持有人的ID我的网页上一个div):
var r = Raphael("holder");
r.customAttributes.segment = function (x, y, r, a1, a2) {
var flag = (a2 - a1) > 180,
clr = (a2 - a1)/360;
a1 = (a1 % 360) * Math.PI/180;
a2 = (a2 % 360) * Math.PI/180;
return {
path: [["M", x, y], ["l", r * Math.cos(a1), r * Math.sin(a1)], ["A", r, r, 0, +flag, 1, x + r * Math.cos(a2), y + r * Math.sin(a2)], ["z"]],
fill: "hsb(" + clr + ", .75, .8)"
};
};
points = [10, 20, 15];
total = 45;
start = 0;
paths = [];
for(i=0; i<=2; i++) {
size = 360/total * points[i];
var slice = r.path();
slice.attr({segment: [250, 250, 200, start, start + size], stroke: "#000", title: "Slice "+i});
paths.push(slice);
start += size;
}
然后我可以动画切片在我的路径数组每当我想,通过动画片段属性:
newPoints = [5, 20, 20];
start = 0;
for(i=0; i<=2; i++) {
size = 360/total * newPoints[i];
paths[i].animate({segment: [250, 250, 200, start, start + size]}, 800);
paths[i].angle = start - size/2;
start += size;
}
其中一些我明白,其中一些我不知道。但上面的代码将工作(我检查)。
看起来像你知道的。你为什么不接受你的答案? – 2010-10-07 02:19:47
良好的通话。谢谢彼得。 – madmanlear 2010-10-08 15:17:41