Gathering detailed insights and metrics for d3-interpolate-path
Gathering detailed insights and metrics for d3-interpolate-path
Gathering detailed insights and metrics for d3-interpolate-path
Gathering detailed insights and metrics for d3-interpolate-path
@types/d3-interpolate-path
TypeScript definitions for d3-interpolate-path
ngx-d3-wrapper
A D3 service for Angular applications
@d-m-p/ngx-d3
A D3 service for Angular applications
d3-transition-stroke
Interpolate a path using `stroke-dasharray`. Based on https://bl.ocks.org/mbostock/5649592
Interpolates path `d` attribute smoothly when A and B have different number of points.
npm install d3-interpolate-path
Typescript
Module System
Node Version
NPM Version
99.7
Supply Chain
100
Quality
75.9
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
41,556,075
Last Day
59,750
Last Week
342,194
Last Month
1,470,456
Last Year
14,867,174
BSD-3-Clause License
334 Stars
111 Commits
18 Forks
8 Watchers
6 Branches
5 Contributors
Updated on Apr 13, 2025
Minified
Minified + Gzipped
Latest Version
2.3.0
Package Id
d3-interpolate-path@2.3.0
Unpacked Size
56.74 kB
Size
15.82 kB
File Count
5
NPM Version
8.11.0
Node Version
16.15.1
Cumulative downloads
Total Downloads
d3-interpolate-path is a zero-dependency that adds an interpolator optimized for SVG <path> elements. It can also work directly with object representations of path commands that can be later interpreted for use with canvas or WebGL.
Note this package no longer has a dependency on d3 or d3-interpolate, but in web usage adds itself to the d3 namespace like other d3 plugins do.
Blog: Improving D3 Path Animation
Demo: https://pbeshai.github.io/d3-interpolate-path/
1var line = d3.line() 2 .curve(d3.curveLinear) 3 .x(function (d) { return x(d.x); }) 4 .y(function (d) { return y(d.y); }); 5 6d3.select('path.my-path') 7 .transition() 8 .duration(2000) 9 .attrTween('d', function (d) { 10 var previous = d3.select(this).attr('d'); 11 var current = line(d); 12 return d3.interpolatePath(previous, current); 13 });
If you're using it in a module environment, you can import it as follows:
1import { interpolatePath } from 'd3-interpolate-path';
Otherwise, you can use it via a <script>
tag as follows:
1<script src="https://unpkg.com/d3-interpolate-path/build/d3-interpolate-path.min.js"></script>
Get rollup watching for changes and rebuilding
1npm run watch
Run a web server in the docs directory
1cd docs 2php -S localhost:8000
Go to http://localhost:8000
If you use NPM, npm install d3-interpolate-path
. Otherwise, download the latest release.
# interpolatePath(a, b, excludeSegment)
Returns an interpolator between two path attribute d
strings a and b. The interpolator extends a and b to have the same number of points before applying linear interpolation on the values. It uses De Castlejau's algorithm for handling bezier curves.
1var pathInterpolator = interpolatePath('M0,0 L10,10', 'M10,10 L20,20 L30,30') 2pathInterpolator(0) // 'M0,0 L10,10 L10,10' 3pathInterpolator(0.5) // 'M5,5 L15,15 L20,20' 4pathInterpolator(1) // 'M10,10 L20,20 L30,30'
You can optionally provide a function excludeSegment that takes two adjacent path commands and returns true if that segment should be excluded when splitting the line. A command object has form { type, x, y }
(with possibly more attributes depending on type). An example object:
1// equivalent to M0,150 in a path `d` string 2{ 3 type: 'M', 4 x: 0, 5 y: 150 6}
This is most useful when working with d3-area. Excluding the final segment (i.e. the vertical line at the end) from being split ensures a nice transition. If you know that highest x
value in the path, you can exclude the final segment by passing an excludeSegment function similar to:
1function excludeSegment(a, b) { 2 return a.x === b.x && a.x === 300; // here 300 is the max X 3}
# interpolatePathCommands(aCommands, bCommands, excludeSegment)
Returns an interpolator between two paths defined as arrays of command objects a and b. The interpolator extends a and b to have the same number of points if they differ. This can be useful if you want to work with paths in other formats besides SVG (e.g. canvas or WebGL).
Command objects take the following form:
1| { type: 'M', x: number, y: number }, 2| { type: 'L', x, y } 3| { type: 'H', x } 4| { type: 'V', y } 5| { type: 'C', x1, y1, x2, y2, x, y } 6| { type: 'S', x2, y2, x, y } 7| { type: 'Q', x1, y1, x, y } 8| { type: 'T', x, y } 9| { type: 'A', rx, ry, xAxisRotation, largeArcFlag, sweepFlag, x, y } 10| { type: 'Z' }
Example usage:
1const a = [ 2 { type: 'M', x: 0, y: 0 }, 3 { type: 'L', x: 10, y: 10 }, 4]; 5const b = [ 6 { type: 'M', x: 10, y: 10 }, 7 { type: 'L', x: 20, y: 20 }, 8 { type: 'L', x: 200, y: 200 }, 9]; 10 11const interpolator = interpolatePathCommands(a, b); 12 13> interpolator(0); 14[ 15 { type: 'M', x: 0, y: 0 }, 16 { type: 'L', x: 5, y: 5 }, 17 { type: 'L', x: 10, y: 10 }, 18] 19 20> interpolator(0.5); 21[ 22 { type: 'M', x: 5, y: 5 }, 23 { type: 'L', x: 12.5, y: 12.5 }, 24 { type: 'L', x: 105, y: 105 }, 25]
# pathCommandsFromString(pathDString)
Converts a path d
string into an array of path command objects to work with interpolatePathCommands.
Example usage:
1const a = 'M0,0L10,10'; 2 3> pathCommandsFromString(a) 4[ 5 { type: 'M', x: 0, y: 0 }, 6 { type: 'L', x: 10, y: 10 }, 7]
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 3/18 approved changesets -- score normalized to 1
Reason
9 existing vulnerabilities detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
Project has not signed or included provenance with any releases.
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-04-28
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreLast Day
2.8%
59,750
Compared to previous day
Last Week
-6.2%
342,194
Compared to previous week
Last Month
7.4%
1,470,456
Compared to previous month
Last Year
36.4%
14,867,174
Compared to previous year