拉斐尔圈内的文字

时间:2016-04-06 08:50:32

标签: javascript css raphael

我试图用Raphael复制下面的图片:

enter image description here

到目前为止,我只是设法让圈子运转起来。如何获得微弱的灰色轮廓(显示余数)和圆圈内的文本。

var score = 883
var amount = score/1000 * 100;

var archtype = Raphael("canvas", 200, 100);
archtype.customAttributes.arc = function (xloc, yloc, value, total, R) {
    var alpha = 360 / total * value,
        a = (90 - alpha) * Math.PI / 180,
        x = xloc + R * Math.cos(a),
        y = yloc - R * Math.sin(a),
        path;
    if (total == value) {
        path = [
            ["M", xloc, yloc - R],
            ["A", R, R, 0, 1, 1, xloc - 0.01, yloc - R]
        ];
    } else {
        path = [
            ["M", xloc, yloc - R],
            ["A", R, R, 0, +(alpha > 180), 1, x, y]
        ];
    }
    return {
        path: path
    };
};

var my_arc = archtype.path().attr({
    "stroke": "#00BB7B",
    "stroke-width": 7,
    arc: [50, 50, 0, 100, 30]
});

my_arc.animate({
    arc: [50, 50, amount, 100, 30]
}, 1500, "bounce");

Jsfiddle:http://jsfiddle.net/1eh7dmgu/

1 个答案:

答案 0 :(得分:1)

1)平衡你可以显示它只是把它放在绿色弧闭合的灰色弧下:

var remainder = archtype.path().attr({
    "stroke": "#eeeeee",
    "stroke-width": 7,
    arc: [50, 50, 100, 100, 30]
});

2)动画文本计数器也可以使用手动属性:

archtype.customAttributes.counter = function (counter) {
    return { text: counter, counter: counter }
}

[http://jsfiddle.net/mwvLc0kb/]