New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: option to convert it back to the SVG path string #11
Comments
Sorry @benkeen, I don't have enough time to spare to prioritise this :') My suggestion would be to write an independent package that does this, and shares the same format as this one. Cheers! |
@benkeen Here's a function to do what you want: function pathData(data){
var params = ['rx','ry','xAxisRotation','largeArc','sweep','x1','y1','x2','y2','x','y'];
var lastCode;
return data.map(function(cmd){
var a = [];
params.forEach(function(param){
if (param in cmd) {
var val = cmd[param]*1; // *1 for true/false values on arc
if (a.length && val>=0) a.push(',');
a.push(val);
}
});
var result = (lastCode===cmd.code?(a[0]<0?'':','):cmd.code) + a.join('');
lastCode=cmd.code;
return result;
}).join('');
} In Action: https://jsfiddle.net/js7zo38o/The function does a bit of work to try to make the resulting path command string as short as possible:
Original Path String:
Parsed and Recreated:
Optimizations that it does not do:
|
As described. That'd be very handy!
The text was updated successfully, but these errors were encountered: