// Helper tool to piece together Raphael's paths into strings again
Array.prototype.flatten || (Array.prototype.flatten = function() {
return this.reduce(function(a, b) {
return a.concat('function' === typeof b.flatten ? b.flatten() : b);
}, []);
});
// Bake the transforms into all path nodes and remove the transform attributes
var paths = [].slice.call(document.querySelectorAll('path'), 0);
paths.forEach(function bake(p) {
var before = p.getAttribute('d'), after = applyTransforms(p);
console.log('before/after path #'+arguments[1]+':\n', before, '\n', after);
p.setAttribute('d', after);
});
paths.forEach(function removeTransforms(p) {
do {
p.removeAttribute('transform');
p = p.parentNode;
} while (!/^svg$/i.test(p.nodeName)); // walk to the SVG root, to catch <g>s
});
// done!
// Uses Raphael.path2curve and Raphael.pathToRelative
//
// Calculates a new <path d> attribute relative to a given root (<svg>) element,
// folding in all the transforms into the path data itself so it can move there,
// and get rid of its transform attribute.
function applyTransforms(path, root) {
function point(x, y) { var p = svg.createSVGPoint(); p.x=x; p.y=y; return p; }
// add a copy of the path at the same level of the hierarchy to see transforms
path = path.parentElement.appendChild(path.cloneNode(false));
// turn all arc commands into splines so we can transform them even with skews
path.setAttribute('d', path2curve(path));
debugger
var svg = path.ownerSVGElement
, normal = (root||svg).getScreenCTM().inverse() // compensation for root
, matrix = normal.multiply(path.getCTM()) // transform, relative to svg root
, _ = ''
, coords = [_, 1, 2] // main and optional handle 1 and 2 coordinates
, segs = path.pathSegList
, len = segs.numberOfItems
, x = { 0: 0, '': 0, 1: 0, 2: 0 }
, y = { 0: 0, '': 0, 1: 0, 2: 0 }
, i = -1
, seg, cmd
;
// simplify the logic by normalizing to...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.