The function d3.svg.line.radialcreates a series of cubic Bezier curves (not arcs) between several points in the array based on the input polar coordinates (radius and angle) for each point.
(The example you are referring to seems to have drawn a circle, but only because it splits the circle to many very spaced points - try using 5 points instead of 50, and you will see that the shape of the curve isn’t a real circle.)
d3.svg.arc , , innerRadius, externalRadius, startAngle endAngle.
, "12 " ( ). , .
, , . , , , , i, , startAngle endAngle .
, . , , :
http://jsfiddle.net/MX7JC/688/
: , .
. : http://jsfiddle.net/4VnHn/5/
, , , "" , . , 45 ( ) , .
. : http://jsfiddle.net/4VnHn/6/
, , switch : http://jsfiddle.net/MX7JC/689/
, , , 45 - , , , , .
, SVG. , . , , interpolate.
, , x, y. . , - , :
function arcInterpolator(r) {
return function(points) {
var allCommands = [];
var startAngle;
points.forEach(function(point, i) {
var angle = Math.atan2(point[0], point[1]);
var command;
if (i) command = ["A",
r,
r,
0,
+(Math.abs(angle - startAngle) > Math.PI),
+(angle < startAngle),
point[0],
point[1]
];
else command = point;
startAngle = angle;
allCommands.push( command.join(" ") );
});
return allCommands.join(" ");
};
}
: http://jsfiddle.net/4VnHn/8/
, , , . , , , , 360 (, , , , ):
var curveFunction = d3.svg.line.radial()
.interpolate( arcInterpolator(r-45) )
.tension(0)
.radius(r-45)
.angle(function(d, i) {
return Math.min(
i? d.endAngle : d.startAngle,
Math.PI*2
);
});
: http://jsfiddle.net/MX7JC/690/
, :
- ;
- , .
( donut , - "textcurve-Agg-Intl" ); <textPath> ;xlink:href # id