String representation of path in RaphaelJS

26 May

raphaeljs paths

Simple thing but took me a few hours to find a solution. If you are using RaphaelJs and have performed some modifications on the path (like translation etc.) and then you would like to get a string representation of that modified path there is a very simple way to do it:

[path object].attr('path');

As always it’s all in the documentation if you know how to read it…

Quick working example:

var paper = Raphael(10, 50, 320, 200);
var p = paper.path("M10 10L90 90").attr({stroke: 'black'});

/* original path string */				
alert(p.attr('path')); //M10,10L90,90

/* modified path string */
alert(p.attr('path')); //M40,40L120,120

Posted by on May 26, 2011 in RaphaelJS


Tags: ,

2 responses to “String representation of path in RaphaelJS

  1. David Durman

    July 5, 2011 at 9:36 pm

    Unfortunately, this works only for translation. Do you know about any other way how to get
    a path string after rotation? Thanks!

    • Dasha Salo

      July 6, 2011 at 9:07 am

      Looks like rotation doesn’t affect the path itself. I am not sure this is correct behaviour as both ‘transformation’ and ‘translation’ are stored as separate path attributes… Sorry can’t help you with that 😦


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: