The d3.lineRadial.angle() method is a radial line accessor method. It sets or returns the angle accessor. If the angle is provided, it must be a number or a function that returns a number representing an angle in radians.
Syntax:
d3.lineRadial.angle( angle );
Parameters:
- angle: This method takes an angle that can be a number or a function returning the angle.
Return Value: This method returns the angle accessor of the Radial line.
Example 1: Setting the angle using this method. For setting radius, we have used lineRadial.radius() method.
HTML
<!DOCTYPE html> < html >
< head >
< meta charset = "utf-8" >
< script src =
</ script >
< script src =
</ script >
</ head >
< body >
< h1 style = "text-align:center; color:green;" >
GeeksforGeeks
</ h1 >
< center >
< svg id = "gfg" width = "200" height = "200" >
< g transform = "translate(100,100)" ></ g >
</ svg >
</ center >
< script >
var lineRadialGenerator = d3.lineRadial();
var data = [
{ angle: 0, radius: 10 },
{ angle: 3.14 * .5, radius: 35 },
{ angle: 3.14 * .75, radius: 55 },
{ angle: 3.14, radius: 60 },
{ angle: 3.14 * 1.25, radius: 65 },
{ angle: 3.14 * 1.5, radius: 70 },
{ angle: 3.14 * 1.75, radius: 75 },
{ angle: 3.14 * 2, radius: 80 },
{ angle: 3.14 * 2.25, radius: 85 },
{ angle: 3.14 * 2.5, radius: 90 },
{ angle: 3.14 * 2.75, radius: 95 },
{ angle: 3.14 * 3, radius: 100 },
{ angle: 3.14 * 3.25, radius: 105 },
{ angle: 3.14 * 3.5, radius: 110 }
];
var lineRadialGenerator = d3.lineRadial()
.angle((d) => d.angle)
.radius((d) => d.radius);
d3.select("#gfg")
.select("g")
.append("path")
.attr("d", lineRadialGenerator(data))
.attr("fill", "none")
.attr("stroke", "green");
</ script >
</ body >
</ html >
|
Output:
Example 2: Getting the function for the angle.
HTML
<!DOCTYPE html> < html >
< head >
< meta charset = "utf-8" >
< script src =
</ script >
< script src =
</ script >
</ head >
< body >
< h1 style = "text-align:center; color:green;" >
GeeksforGeeks
</ h1 >
< center >
< svg id = "gfg" width = "200" height = "200" >
< g transform = "translate(100,100)" ></ g >
</ svg >
</ center >
< script >
var lineRadialGenerator = d3.lineRadial();
var data = [
{ angle: 0, radius: 10 },
{ angle: 3.14 * .5, radius: 35 },
{ angle: 3.14 * .75, radius: 55 },
{ angle: 3.14, radius: 60 },
{ angle: 3.14 * 1.25, radius: 65 },
{ angle: 3.14 * 1.5, radius: 70 },
{ angle: 3.14 * 1.75, radius: 75 },
{ angle: 3.14 * 2, radius: 80 },
{ angle: 3.14 * 2.25, radius: 85 },
{ angle: 3.14 * 2.5, radius: 90 },
{ angle: 3.14 * 2.75, radius: 95 },
{ angle: 3.14 * 3, radius: 100 },
{ angle: 3.14 * 3.25, radius: 105 },
{ angle: 3.14 * 3.5, radius: 110 }
];
var lineRadialGenerator = d3.lineRadial()
.angle((d) => d.angle)
.radius((d) => d.radius);
d3.select("#gfg")
.select("g")
.append("path")
.attr("d", lineRadialGenerator(data))
.attr("fill", "none")
.attr("stroke", "green");
console.log(lineRadialGenerator.angle());
console.log(lineRadialGenerator.angle);
</ script >
</ body >
</ html >
|
Output: