PathData is a group of JavaScript objects that can be used to manipulate <path> data. PathData is really rough right now, but you may find it useful in its present form.
In order to use PathData in your SVG file, you will need to insert a <script> element inside of your <svg> element. As an example, if pathData.js is in the same directory as your SVG document, then you would include PathData with the following text:
<script xlink:href="pathData.js" />
PathSegments are objects that represent all of the commands used in a path element. All PathSegments have a command property. This is the letter abbreviation used to represent this command in a path element. The remaining properties depend on the command itself. If you view the SVG specification, you will see names used to define the parameters of each segment command. Each PathSegment will have properties following those same names. The only exceptions occur when the spec uses hypens in the name. I remove the hypen and then capitalize the letter following the hypen.
For example, a curveto PathSegment would have the following properties:
pathSegment.x1; pathSegment.y1; pathSegment.x2; pathSegment.y2; pathSegment.x; pathSegment.y;
However, an arc would have following properties:
pathSegment.rx; pathSegment.ry; pathSegment.xAxisRotation; pathSegment.largeArcFlag; pathSegment.sweepFlag; pathSegment.x; pathSegment.y;
To convert a path node's d attribute to a series of PathSegment Objects, you will need to pass the path node to the loadDataFrom() method:
pd = new PathData(); path_node = SVGDoc.getElementById("some_path_id_here"); pd.loadDataFrom(path_node);
You can add PathSegments to a PathData object by passing two parameters to the appendSegment() method. The first parameter is the Path Segment Command (for example, "M" or "L", etc.). The second parameter is an anonymous array of all of the data to be passed to the command. For instance, a bezier curvto command is denoted by the letter "C" and it expects six number parameters. The following example will append a bezier curve to a PathData object:
pd.appendSegment("C", [0,100, 100,100, 100,0]);
You can find all PathSegments of a given type using the getSegmentsByCommandName() method. The following example will return an array of all lineto PathSegments:
segment_array = pd.getSegmentsByCommandName("L");
You may now manipulate any of the properites of each PathSegment in the array.
Once you have completed your alterations to the PathData object and its PathSegments, you can update the PathData's associated path node (the same node used in the loadDataFrom() method) by using the applySegments() method:
pd.applySegments();
Apply gravity to all M and L PathSegment: gravity.svg
Whirl PathSegments: whirl.svg
Jumble a Burst and watch it oscillate back into shape: splat.svg
Use custom tags to design you path data. Click on the path image or "View Source" to see the custom tags (Adobe SVG Viewer 3.0 only): custom_tags.svg