I have this code :
el.replace(/[0-9]*\.[0-9]*/g, function(x){ return (+x).toFixed(2) }) };
It works great on an individual svg path to trim its decimal places. Now I want to be able to trim all the paths from a paper(svg).To do that I am trying to make a snap svg plugin here:
Snap.plugin(function(Snap, Element, Paper, glob){
Paper.prototype.trimPthDec = function(){
this.paper.selectAll('path').forEach( function(el) { el.trim() } ) ;
function trim(){
el.replace(/[0-9]*\.[0-9]*/g, function(x){ return (+x).toFixed(2) }) };
//return paper;
});
But it doesn't seem to work when I call it like:
// And use it like this to update the paper with new paths?!:
trimPthDec(); // I get this error: Uncaught ReferenceError: trimPthDec is not defined
Could anybody tell me why it is not working please?
Few bits wrong with the plugin and the code...mainly its run on the paper, so you need to reference that paper correctly in the code, and call the function as a prototype, rather than a standalone func (so paper.func() rather than func() )
jsfiddle