This is a graph of the sin(2t) function in a radial view.
The curve is animated without interpolating the path.
xxxxxxxxxx
<meta charset="utf-8">
<style>
.frame {
fill: none;
stroke: #000;
}
.axis text {
font: 10px sans-serif;
}
.axis line,
.axis circle {
fill: none;
stroke: #777;
stroke-dasharray: 1,4;
}
.axis :last-of-type circle {
stroke: #333;
stroke-dasharray: none;
}
.line {
fill: none;
stroke: red;
stroke-width: 1.5px;
}
</style>
<body>
<script src="https://d3js.org/d3.v3.min.js"></script>
<script>
//2 PI = 360 deg
var data = d3.range(0, 2*Math.PI, .01).map(function(t) {
return [t, Math.sin(2*t)];
});
var margin = 30;
// radius is the minimal dimension, minus the margin
var width = 960,
height = 500,
radius = Math.min(width, height) / 2 - margin;
var r = d3.scale.linear()
.domain([0, 1])
.range([0, radius]);
//default accessor [[x1,y1]] => radian and angle
var line = d3.svg.line.radial()
.radius(function(d){ console.log('====',d[0],d[1],r(d[1])); return (r(d[1])); }) // will change between -1 and 1
.angle(function(d) { console.log('====',d[0]*(180/Math.PI));return d[0];});
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");
// radius axis
// cheat with CSS
var gr = svg.append("g")
.attr("class", "r axis")
.selectAll("g")
.data(r.ticks(10).slice(0))
.enter().append("g");
gr.append("circle")
.attr("r", function(d,i){console.log("=>",d,i,r(d));return r(d)});
gr.append("text")
.attr("y", function(d) { return -r(d) - 4; })
.attr("transform", "rotate(50)")
.style("text-anchor", "middle")
.text(function(d) { return d; });
var ga = svg.append("g")
.attr("class", "a axis")
.selectAll("g")
.data(d3.range(0, 360, 15))
.enter().append("g")
.attr("transform", function(d) { return "rotate(" + (d-90) + ")"; });
ga.append("line")
.attr("x2", radius);
ga.append("text")
.attr("x", radius + 6)
.attr("dy", ".35em")
.style("text-anchor", function(d) { return d < 270 && d > 90 ? "end" : null; })
.attr("transform", function(d) { return d < 270 && d > 90 ? "rotate(180 " + (radius + 6) + ",0)" : null; })
.text(function(d) { return d + "°"; });
// a bit cheating
var path =
svg.append("path")
.datum(data)
.attr("class", "line")
.attr("d", line);
var totalLength = path.node().getTotalLength();
path
.attr("stroke-dasharray", totalLength + " " + totalLength)
.attr("stroke-dashoffset", totalLength)
.transition()
.duration(2000)
.ease("linear")
.attr("stroke-dashoffset", 0);
</script>
</body>
Modified http://d3js.org/d3.v3.min.js to a secure url
https://d3js.org/d3.v3.min.js