我發現是什麼導致圓形變形。
我用stroke-width
來設置圓的「胖」/「帽」,它越大,變形越大。
至少,這些是我的觀察結果,它在技術上可能會被別的東西所注意。
不管怎麼說,爲了得到正確的甜甜圈,我結束了這種方法:
/**
* Donut circle drawing
*
* @param integer start Percentage to start with
* @param float diameter
* @param float fat How fat should the circle bar be
* @return object
*/
var fatDonutArc = function (start, diameter, fat)
{
var center = diameter/2;
var outerRadius = center;
var innerRadius = center - fat; // subtract fat
var alpha = 360/100 * start;
var a = (90 - alpha) * Math.PI/-180; // -180 starts to draw from 12 o'clock
// calculate outer ring point coordinates
var outerX = center + outerRadius * Math.cos(a);
var outerY = center + outerRadius * Math.sin(a);
// calculate inner ring point coordinates
var innerX = center + innerRadius * Math.cos(a);
var innerY = center + innerRadius * Math.sin(a);
// path cache
var path;
if (start !== 100)
{
path = [
// move to start point of inner ring
[
"M",
center,
center - innerRadius
],
// draw a line to outer ring
[
"L",
center,
center - outerRadius
],
// arc to outer ring end
[
"A",
outerRadius,
outerRadius,
0,
+(alpha > 180),
1,
outerX,
outerY
],
// move to inner ring end
[
"L",
innerX,
innerY
],
// arc to inner ring start
[
"A",
innerRadius,
innerRadius,
0,
+(alpha > 180),
0,
center,
center - innerRadius
]
];
}
else
{
path = [
// move to outer ring start
[
"M",
center,
center - outerRadius
],
// arc around the clock
[
"A",
outerRadius,
outerRadius,
0,
+(alpha > 180),
1,
outerX - .1, // subtract, otherwise the path becomes "reset"
outerY
],
// connect
[
"z"
],
// move to inner circle start
[
"M",
innerX,
innerY
],
// arc around the clock
[
"A",
innerRadius,
innerRadius,
0,
+(alpha > 180),
0,
innerX + .1, // subtract, otherwise the path becomes "reset"
innerY
],
// and connect
[
"z"
]
];
}
return {
path : path
};
};
這就是混搭:raphael.js - converting pie graph to donut graph + http://raphaeljs.com/polar-clock.html
這裏我設置了一個例子,看看吧在行動:http://jsbin.com/erusos/1
仍然有一個未回答的問題:在Chrome中,它是CSS渲染器,它不是完整的圓形,或者它是SVG?
享受!