svg path abs2rel

by joepenzo

HTML

<script src="http://cdn.jsdelivr.net/snap.svg/0.3.0/snap.svg.js"></script>
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
	 width="400px" height="500px" viewBox="80 -200 400 500" enable-background="new 80 -200 400 500" xml:space="preserve">
<path d="M480,288c0,6.627-5.373,12-12,12L92,280c-6.627,0-12-5.373-12-12v-456c0-6.627,5.373-12,12-12h376c6.627,0,12,5.373,12,12
	V288z"/>
</svg>

JavaScript

var dv, txt0, txt1, svgee,
    path = Snap.select('path'),
    pathRel = Snap.path.toRelative(path);
document.querySelector('path').setAttribute('d', pathRel);
dv = document.createElement('div');
dv.style.fontSize = '0.5em';
txt0 = 'Output: ' + document.querySelector('path').getAttribute('d');
txt1 = document.createTextNode(txt0);
dv.appendChild(txt1);
svgee = document.querySelector('svg');
document.body.insertBefore(dv, svgee);