Assume I create some arbitrary path using the curve part of d3-shape, by providing it a small set of x,y points, like so:
var my_curve = d3.line()
.x(function(d) { return d.x; })
.y(function(d) { return d.y; })
.curve(d3.curveCatmullRom.alpha(0.5));
var curve_dat = [{x:10,y:10},{x:110,y:120},{x:160,y:20},{x:400,y:60},{x:200,y:360},{x:40,y:300}];
var svg_main = d3.select("div#svg_cont")
.append('svg')
.attr('width', 600)
.attr('height', 400);
var path_1 = svg_main.append('path')
.datum(curve_dat)
.attr('fill', 'none')
.attr('stroke', 'red')
.attr('stroke-width', 3)
.attr('d', my_curve);
svg_main.selectAll('circle')
.data(curve_dat)
.enter()
.append('circle')
.attr('fill', 'none')
.attr('stroke', 'black')
.attr('stroke-width', 3)
.attr('cx', d => d.x)
.attr('cy', d => d.y)
.attr('r', 5);
which produces:
(where the black circles are the locations of the generating points.)
Now, I want to choose two points along the path, and get the section/subset of the original path from them:
pt1 = path_1.node().getPointAtLength(300);
svg_main.append('circle')
.attr('fill', 'none')
.attr('stroke', 'green')
.attr('stroke-width', 3)
.attr('cx', pt1.x)
.attr('cy', pt1.y)
.attr('r', 5);
pt1 = path_1.node().getPointAtLength(450);
svg_main.append('circle')
.attr('fill', 'none')
.attr('stroke', 'green')
.attr('stroke-width', 3)
.attr('cx', pt1.x)
.attr('cy', pt1.y)
.attr('r', 5);
(where the green circles are the bounds of the section I want to get)
So even though I have the x,y for each of those points, I can't just draw the curve generated by those two, because it'll be different than the original red curve between them.
Is there a smart way to do this? From a bit of searching it seems like there used to be a method called SVGPathElement.createSVGPathSegClosePath(), but it's deprecated and they don't even provide documentation on it.
Is there another way?


