1.3
[raphael] / reference.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
2    "http://www.w3.org/TR/html4/strict.dtd">
3 <html lang="en">
4     <head>
5         <title>Raphaël Reference</title>
6         <meta http-equiv="content-language" content="en">
7         <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
8         <meta name="author" content="Dmitry Baranovskiy">
9         <meta name="description" content="Vector Graphics JavaScript Library">
10         <meta name="keywords" content="JavaScript Library, Raphael, SVG, VML">
11         <meta name="viewport" content="width=450; user-scalable=no">
12         <link rel="shortcut icon" href="/favicon16.png" type="image/x-icon">
13         <link rel="stylesheet" href="raphael.css" type="text/css" charset="utf-8" media="screen,projection">
14         <link rel="stylesheet" type="text/css" media="print" href="print.css">
15         <link rel="shortcut icon" href="/favicon16.png" type="image/x-icon">
16         <link media="only screen and (max-device-width: 480px)" href="iphone.css" type="text/css" rel="stylesheet">
17         <script src="raphael.js" type="text/javascript" charset="utf-8"></script>
18         <script src="museo.js" type="text/javascript" charset="utf-8"></script>
19
20
21     </head>
22     <body class="raphael" id="reference">
23         <div id="header">
24             <a href="http://twitter.com/statuses/user_timeline/17180567.atom" id="rss" name="rss">rss</a>
25             <h1>
26                 Raphaël—JavaScript Library
27             </h1>
28         </div>
29         <div id="content">
30             <div>
31                 <div>
32                     <div id="column-1">
33                         <h2>Main Function</h2>
34                         <h3 id="Raphael">
35                             Raphael
36                         </h3>
37                         <p>
38                             Creates a canvas object on which to draw. You must do this first, as all future calls to drawing methods from this instance will be bound to this canvas.
39                         </p>
40                         <h4>Parameters</h4>
41                         <ol>
42                             <li>container <em>HTMLElement</em> or <em>string</em></li>
43                             <li>width <em>number</em></li>
44                             <li>height <em>number</em></li>
45                         </ol>
46                         <p>or</p>
47                         <ol>
48                             <li>x <em>number</em></li>
49                             <li>y <em>number</em></li>
50                             <li>width <em>number</em></li>
51                             <li>height <em>number</em></li>
52                         </ol>
53                         <p>or</p>
54                         <ol>
55                             <li>all <em>array</em> (first 3 or 4 elements in the array are equal to [containerID, width, height] or [x, y, width, height]. The rest are element descriptions in format {type: type, &lt;attributes>})</li>
56                         </ol>
57                         <h4>Usage</h4>
58                         <pre class="javascript code"><code>// Each of the following examples create a canvas that is 320px wide by 200px high
59 // Canvas is created at the viewport’s 10,50 coordinate
60 var paper = Raphael(10, 50, 320, 200);
61 // Canvas is created at the top left corner of the #notepad element
62 // (or its top right corner in dir="rtl" elements)
63 var paper = Raphael(document.getElementById("notepad"), 320, 200);
64 // Same as above
65 var paper = Raphael("notepad", 320, 200);
66 // Image dump
67 var set = Raphael(["notepad", 320, 200, {
68     type: "rect",
69     x: 10,
70     y: 10,
71     width: 25,
72     height: 25,
73     stroke: "#f00"
74 }, {
75     type: "text",
76     x: 30,
77     y: 40,
78     text: "Dump"
79 }]);</code></pre>
80                         <h3 id="circle">
81                             circle
82                         </h3>
83                         <div class="sample" id="circle-sample"></div>
84                         <p>
85                             Draws a circle.
86                         </p>
87                         <h4>Parameters</h4>
88                         <ol>
89                             <li>x <em>number</em> X coordinate of the centre</li>
90                             <li>y <em>number</em> Y coordinate of the centre</li>
91                             <li>r <em>number</em> radius</li>
92                         </ol>
93                         <h4>Usage</h4>
94                         <pre class="javascript code"><code>var c = paper.circle(50, 50, 40);</code></pre>
95                         <h3 id="rect">
96                             rect
97                         </h3>
98                         <div class="sample" id="rect-sample"></div>
99                         <p>
100                             Draws a rectangle.
101                         </p>
102                         <h4>Parameters</h4>
103                         <ol>
104                             <li>x <em>number</em> X coordinate of top left corner</li>
105                             <li>y <em>number</em> Y coordinate of top left corner</li>
106                             <li>width <em>number</em></li>
107                             <li>height <em>number</em></li>
108                             <li>r <em>number</em> [optional] radius for rounded corners, default is 0</li>
109                         </ol>
110                         <h4>Usage</h4>
111                         <pre class="javascript code"><code>// regular rectangle</code>
112 <code>var c = paper.rect(10, 10, 50, 50);</code>
113 <code>// rectangle with rounded corners</code>
114 <code>var c = paper.rect(40, 40, 50, 50, 10);</code></pre>
115                         <h3 id="ellipse">
116                             ellipse
117                         </h3>
118                         <div class="sample" id="ellipse-sample"></div>
119                         <p>
120                             Draws an ellipse.
121                         </p>
122                         <h4>Parameters</h4>
123                         <ol>
124                             <li>x <em>number</em> X coordinate of the centre</li>
125                             <li>y <em>number</em> X coordinate of the centre</li>
126                             <li>rx <em>number</em> Horisontal radius</li>
127                             <li>ry <em>number</em> Vertical radius</li>
128                         </ol>
129                         <h4>Usage</h4>
130                         <pre class="javascript code"><code>var c = paper.ellipse(50, 50, 40, 20);</code></pre>
131                         <h3 id="image">
132                             image
133                         </h3>
134                         <div class="sample" id="image-sample"></div>
135                         <p>
136                             Embeds an image into the SVG/VML canvas.
137                         </p>
138                         <h4>Parameters</h4>
139                         <ol>
140                             <li>src <em>string</em> URI of the source image</li>
141                             <li>x <em>number</em> X coordinate position</li>
142                             <li>y <em>number</em> Y coordinate position</li>
143                             <li>width <em>number</em> Width of the image</li>
144                             <li>height <em>number</em> Height of the image</li>
145                         </ol>
146                         <h4>Usage</h4>
147                         <pre class="javascript code"><code>var c = paper.image("apple.png", 10, 10, 80, 80);</code></pre>
148                         <h3 id="set">
149                             set
150                         </h3>
151                         <div class="sample" id="set-sample"></div>
152                         <p>
153                             Creates array-like object to keep and operate couple of elements at once. Warning: it doesn’t create any elements for itself in the page.
154                         </p>
155                         <h4>Usage</h4>
156                         <pre class="javascript code"><code>var st = paper.set();</code>
157 <code>st.push(
158     paper.circle(10, 10, 5),
159     paper.circle(30, 10, 5)
160 );</code>
161 <code>st.attr({fill: "red"});</code></pre>
162                         <h3 id="text">
163                             text
164                         </h3>
165                         <div class="sample" id="text-sample"></div>
166                         <p>
167                             Draws a text string. If you need line breaks, put “\n” in the string.
168                         </p>
169                         <h4>Parameters</h4>
170                         <ol>
171                             <li>x <em>number</em> X coordinate position.</li>
172                             <li>y <em>number</em> Y coordinate position.</li>
173                             <li>text <em>string</em> The text string to draw.</li>
174                         </ol>
175                         <h4>Usage</h4>
176                         <pre class="javascript code"><code>var t = paper.text(50, 50, "Raphaël\nkicks\nbutt!");</code></pre>
177                         <h3 id="path">
178                             path
179                         </h3>
180                         <div class="sample" id="path-sample"></div>
181                         <p>
182                             Creates a path element by given path data string.
183                         </p>
184                         <h4>Parameters</h4>
185                         <ol>
186                             <li>pathString <em>string</em> [optional] Path data in <a href="http://www.w3.org/TR/SVG/paths.html#PathData" title="Details of a path's data attribute's format are described in the SVG specification.">SVG path string format</a>.</li>
187                         </ol>
188                         <h4>Usage</h4>
189                         <pre class="javascript code"><code>var c = paper.path("M10 10L90 90");
190 // draw a diagonal line:
191 // move to 10,10, line to 90,90</code></pre>
192                         <h2 id="Element">
193                             Element’s generic methods
194                         </h2>
195                         <p>
196                             Each object created on the canvas shares these same generic methods:
197                         </p>
198                         <h3 id="node">
199                             node
200                         </h3>
201                         <p>
202                             Gives you a reference to the DOM object, so you can assign event handlers or just mess around.
203                         </p>
204                         <h4>Usage</h4>
205                         <pre class="javascript code"><code>// draw a circle at coordinate 10,10 with radius of 10
206 var c = paper.circle(10, 10, 10);
207 c.node.onclick = function () {
208     c.attr("fill", "red");
209 };</code></pre>
210                         <h3 id="paper">
211                             paper
212                         </h3>
213                         <p>
214                             Internal reference to “paper” where object drawn. Mainly for use in plugins and element extensions.
215                         </p>
216                         <h4>Usage</h4>
217                         <pre class="javascript code"><code>Raphael.el.cross = function () {
218     this.attr({fill: "red"});
219     this.paper.path("M10,10L50,50M50,10L10,50")
220         .attr({stroke: "red"});
221 }</code></pre>
222                         <h3 id="remove">
223                             remove
224                         </h3>
225                         <p>
226                             Removes element from the DOM. You can’t use it after this method call.
227                         </p>
228                         <h4>Usage</h4>
229                         <pre class="javascript code"><code>var c = paper.circle(10, 10, 10);
230 c.remove();</code></pre>
231                         <h3 id="hide">
232                             hide
233                         </h3>
234                         <p>
235                             Makes element invisible.
236                         </p>
237                         <h4>Usage</h4>
238                         <pre class="javascript code"><code>var c = paper.circle(10, 10, 10);
239 c.hide();</code></pre>
240                         <h3 id="show">
241                             show
242                         </h3>
243                         <p>
244                             Makes element visible.
245                         </p>
246                         <h4>Usage</h4>
247                         <pre class="javascript code"><code>var c = paper.circle(10, 10, 10);
248 c.show();</code></pre>
249                         <h3 id="rotate">
250                             rotate
251                         </h3>
252                         <p>
253                             Rotates the element by the given degree from its center point.
254                         </p>
255                         <h4>Parameters</h4>
256                         <ol>
257                             <li>degree <em>number</em> Degree of rotation (0 – 360°)</li>
258                             <li>isAbsolute <em>boolean</em> [optional] Specifies is degree is relative to previous position (<code>false</code>) or is it absolute angle (<code>true</code>)</li>
259                         </ol>
260                         <p>or</p>
261                         <ol>
262                             <li>degree <em>number</em> Degree of rotation (0 – 360°)</li>
263                             <li>cx <em>number</em> [optional] X coordinate of the origin of rotation</li>
264                             <li>cY <em>number</em> [optional] Y coordinate of the origin of rotation</li>
265                         </ol>
266                         <h4>Usage</h4>
267                         <pre class="javascript code"><code>var c = paper.circle(10, 10, 10);
268 c.rotate(45);        // rotation is relative
269 c.rotate(45, true);  // rotation is absolute</code></pre>
270                         <h3 id="translate">
271                             translate
272                         </h3>
273                         <p>
274                             Moves the element around the canvas by the given distances.
275                         </p>
276                         <h4>Parameters</h4>
277                         <ol>
278                             <li>dx <em>number</em> Pixels of translation by X axis</li>
279                             <li>dy <em>number</em> Pixels of translation by Y axis</li>
280                         </ol>
281                         <h4>Usage</h4>
282                         <pre class="javascript code"><code>var c = paper.circle(10, 10, 10);
283 // moves the circle 10&nbsp;px to the right and down
284 c.translate(10, 10);</code></pre>
285                         <h3 id="scale">
286                             scale
287                         </h3>
288                         <p>
289                             Resizes the element by the given multiplier.
290                         </p>
291                         <h4>Parameters</h4>
292                         <ol>
293                             <li>Xtimes <em>number</em> Amount to scale horizontally</li>
294                             <li>Ytimes <em>number</em> Amount to scale vertically</li>
295                             <li>centerX <em>number</em> [optional] X of the center of scaling, default is the center of the element</li>
296                             <li>centerY <em>number</em> [optional] Y of the center of scaling, default is the center of the element</li>
297                         </ol>
298                         <h4>Usage</h4>
299                         <pre class="javascript code"><code>var c = paper.circle(10, 10, 10);
300 // makes the circle 1.5 times larger
301 c.scale(1.5, 1.5);
302 // makes the circle half as wide, and 75% as high
303 c.scale(.5, .75);</code></pre>
304                         <h3 id="attr">
305                             attr
306                         </h3>
307                         <p>
308                             Sets the attributes of elements directly.
309                         </p>
310                         <h4>Parameters</h4>
311                         <ol>
312                             <li>attributeName <em>string</em></li>
313                             <li>value <em>string</em></li>
314                         </ol>
315                         <p>or</p>
316                         <ol>
317                             <li>params <em>object</em></li>
318                         </ol>
319                         <p>or</p>
320                         <ol>
321                             <li>attributeName <em>string</em> in this case method returns current value for given attribute name</li>
322                         </ol>
323                         <p>or</p>
324                         <ol>
325                             <li>attributeNames <em>array</em> in this case method returns array of current values for given attribute names</li>
326                         </ol>
327                         <p>or</p>
328                         <p>no parameters, in this case object containing all attributes will be returned</p>
329                         <h4>Possible parameters</h4>
330                         <p>Please refer to the <a href="http://www.w3.org/TR/SVG/" title="The W3C Recommendation for the SVG language describes these properties in detail.">SVG specification</a> for an explanation of these parameters.</p>
331                         <ul>
332                             <li id="attr-clip-rect">clip-rect <em>string</em> comma or space separated values: x, y, width and height</li>
333                             <li id="attr-cx">cx <em>number</em></li>
334                             <li id="attr-cy">cy <em>number</em></li>
335                             <li id="attr-fill">
336                                 fill <em>colour</em> or <em>gradient</em>
337                                 <ul>
338                                     <li>linear gradient: “‹angle›-‹colour›[-‹colour›[:‹offset›]]*-‹colour›”, example: “<samp>90-#fff-#000</samp>” – 90° gradient from white to black or “<samp>0-#fff-#f00:20-#000</samp>” – 0° gradient from white via red (at 20%) to black</li>
339                                     <li>radial gradient: “r[(‹fx›, ‹fy›)]‹colour›[-‹colour›[:‹offset›]]*-‹colour›”, example: “<samp>r#fff-#000</samp>” – gradient from white to black or “<samp>r(0.25, 0.75)#fff-#000</samp>” – gradient from white to black with focus point at 0.25, 0.75</li>
340                                     <li>Focus point coordinates are in 0..1 range</li>
341                                     <li>Radial gradients can only be applied to circles and ellipses</li>
342                                 </ul>
343                             </li>
344                             <li id="attr-fill-opacity">fill-opacity <em>number</em></li>
345                             <li id="attr-font">font <em>string</em></li>
346                             <li id="attr-font-family">font-family <em>string</em></li>
347                             <li id="attr-font-size">font-size <em>number</em></li>
348                             <li id="attr-font-weight">font-weight <em>string</em></li>
349                             <li id="attr-height">height <em>number</em></li>
350                             <li id="attr-opacity">opacity <em>number</em></li>
351                             <li id="attr-path">path <em>pathString</em> <a href="http://www.w3.org/TR/SVG/paths.html#PathData" title="Details of a path’s data attribute’s format are described in the SVG specification.">SVG path string format</a></li>
352                             <li id="attr-r">r <em>number</em></li>
353                             <li id="attr-rotation">rotation <em>number</em></li>
354                             <li id="attr-rx">rx <em>number</em></li>
355                             <li id="attr-ry">ry <em>number</em></li>
356                             <li id="attr-scale">scale <em>string</em> comma or space separated values: xtimes, ytimes, cx, cy. See: <a href="#scale">scale</a></li>
357                             <li id="attr-src">src <em>string</em> (URL)</li>
358                             <li id="attr-stroke">stroke <em>colour</em></li>
359                             <li id="attr-stroke-dasharray">stroke-dasharray <em>string</em> [“”, “<samp>-</samp>”, “<samp>.</samp>”, “<samp>-.</samp>”, “<samp>-..</samp>”, “<samp>. </samp>”, “<samp>- </samp>”, “<samp>--</samp>”, “<samp>-&nbsp;.</samp>”, “<samp>--.</samp>”, “<samp>--..</samp>”]</li>
360                             <li id="attr-stroke-linecap">stroke-linecap <em>string</em> [“<samp>butt</samp>”, “<samp>square</samp>”, “<samp>round</samp>”]</li>
361                             <li id="attr-stroke-linejoin">stroke-linejoin <em>string</em> [“<samp>bevel</samp>”, “<samp>round</samp>”, “<samp>miter</samp>”]</li>
362                             <li id="attr-stroke-miterlimit">stroke-miterlimit <em>number</em></li>
363                             <li id="attr-stroke-opacity">stroke-opacity <em>number</em></li>
364                             <li id="attr-stroke-width">stroke-width <em>number</em></li>
365                             <li id="attr-translation">translation <em>string</em> comma or space separated values: x and y</li>
366                             <li id="attr-width">width <em>number</em></li>
367                             <li id="attr-x">x <em>number</em></li>
368                             <li id="attr-y">y <em>number</em></li>
369                         </ul>
370                         <h4>Usage</h4>
371                         <pre class="javascript code"><code>var c = paper.circle(10, 10, 10);
372 // using strings
373 c.attr("fill", "black");
374 // using params object
375 c.attr({fill: "#000", stroke: "#f00", opacity: 0.5});
376 c.attr({
377     fill: "90-#fff-#000",
378     "stroke-dasharray": "-..",
379     "clip-rect": "10, 10, 100, 100"
380 });</code></pre>
381                         <h3 id="animate">
382                             animate
383                         </h3>
384                         <p>
385                             Changes an attribute from its current value to its specified value in the given amount of milliseconds.
386                         </p>
387                         <h4>Parameters</h4>
388                         <ol>
389                             <li>newAttrs <em>object</em> A parameters object of the animation results. (Not all attributes can be animated.)</li>
390                             <li>ms <em>number</em> The duration of the animation, given in milliseconds.</li>
391                             <li>callback <em>function</em> [optional]</li>
392                         </ol>
393                         <p>or</p>
394                         <ol>
395                             <li>newAttrs <em>object</em> A parameters object of the animation results. (Not all attributes can be animated.)</li>
396                             <li>ms <em>number</em> The duration of the animation, given in milliseconds.</li>
397                             <li>easing <em>string</em> [“<samp>></samp>”, “<samp>&lt;</samp>”, “<samp>&lt;></samp>”, “<samp>backIn</samp>”, “<samp>backOut</samp>”, “<samp>bounce</samp>”, “<samp>elastic</samp>”] or <em>function</em> [optional]</li>
398                             <li>callback <em>function</em> [optional]</li>
399                         </ol>
400                         <h4>Attributes that can be animated</h4>
401                         <p>The <code>newAttrs</code> parameter accepts an object whose properties are the attributes to animate. However, not all attributes listed in the <code>attr</code> method reference can be animated. The following is a list of those properties that can be animated:</p>
402                         <ul>
403                             <li>clip-rect <em>string</em></li>
404                             <li>cx <em>number</em></li>
405                             <li>cy <em>number</em></li>
406                             <li>fill <em>colour</em></li>
407                             <li>fill-opacity <em>number</em></li>
408                             <li>font-size <em>number</em></li>
409                             <li>height <em>number</em></li>
410                             <li>opacity <em>number</em></li>
411                             <li>path <em>pathString</em></li>
412                             <li>r <em>number</em></li>
413                             <li>rotation <em>string</em></li>
414                             <li>rx <em>number</em></li>
415                             <li>ry <em>number</em></li>
416                             <li>scale <em>string</em></li>
417                             <li>stroke <em>colour</em></li>
418                             <li>stroke-opacity <em>number</em></li>
419                             <li>stroke-width <em>number</em></li>
420                             <li>translation <em>string</em></li>
421                             <li>width <em>number</em></li>
422                             <li>x <em>number</em></li>
423                             <li>y <em>number</em></li>
424                         </ul>
425                         <h4>Easing</h4>
426                         <p>
427                             For easing use built in functions or add your own by adding new functions to <code>Raphael.easing_formulas</code> object. Look at the <a href="easing.html">example of easing usage</a>.
428                         </p>
429                         <h4>Usage</h4>
430                         <pre class="javascript code"><code>var c = paper.circle(10, 10, 10);</code>
431 <code>c.animate({cx: 20, r: 20}, 2000);</code>
432 <code>c.animate({cx: 20, r: 20}, 2000, "bounce");</code></pre>
433                         <h3 id="animateWith">
434                             animateWith
435                         </h3>
436                         <p>
437                             The same as <a href="#animate"><code>animate</code></a> method, but synchronise animation with another element.
438                         </p>
439                         <h4>Parameters</h4>
440                         <p>The same as for <a href="#animate"><code>animate</code></a> method, but first argument is an element.</p>
441                         <h4>Usage</h4>
442                         <pre class="javascript code"><code>var c = paper.circle(10, 10, 10),
443     r = paper.rect(10, 10, 10, 10);
444 c.animate({cx: 20, r: 20}, 2000);
445 r.animateWith(c, {x: 20}, 2000);</code></pre>
446                         <h3 id="animateAlong">
447                             animateAlong
448                         </h3>
449                         <div class="sample" id="along-sample"></div>
450                         <p>
451                             Animates element along the given path. As an option it could rotate element along the path.
452                         </p>
453                         <h4>Parameters</h4>
454                         <ol>
455                             <li>path <em>object</em> or <em>string</em> path element or path string along which the element will be animated</li>
456                             <li>ms <em>number</em> The duration of the animation, given in milliseconds.</li>
457                             <li>rotate <em>boolean</em> [optional] if true, element will be rotated along the path</li>
458                             <li>callback <em>function</em> [optional]</li>
459                         </ol>
460                         <h4>Usage</h4>
461                         <pre class="javascript code"><code>var p = r.path("M100,100c0,50 100-50 100,0c0,50 -100-50 -100,0z").attr({stroke: "#ddd"}),
462     e = r.ellipse(104, 100, 4, 4).attr({stroke: "none", fill: "#f00"}),
463     b = r.rect(0, 0, 620, 400).attr({stroke: "none", fill: "#000", opacity: 0}).click(function () {
464         e.attr({rx: 5, ry: 3}).animateAlong(p, 4000, true, function () {
465             e.attr({rx: 4, ry: 4});
466         });
467     });</code></pre>
468                         <h3 id="animateAlongBack">
469                             animateAlongBack
470                         </h3>
471                         <p>
472                             Similar to <a href="animateAlong"><code>animateAlong</code></a>. Animates element along the given path, starting from the end of it.
473                         </p>
474                         <h3 id="onAnimation">
475                             onAnimation
476                         </h3>
477                         <div class="sample" id="onanim-sample"></div>
478                         <p>
479                             Sets or resets the function that will be called on each stage of the animation.
480                         </p>
481                         <h4>Parameters</h4>
482                         <ol>
483                             <li>f <em>function</em> function that will be called on each stage of animation</li>
484                         </ol>
485                         <h4>Usage</h4>
486                         <pre class="javascript code"><code>var p = r.path("M10,50c0,50,80-50,80,0c0,50-80-50-80,0z"),
487     p2 = r.path(),
488     e = r.ellipse(10, 50, 4, 4).attr({stroke: "none", fill: "#f00"}).onAnimation(function () {
489         p2.attr({path: "M50,10L" + e.attr("cx") + "," + e.attr("cy")});
490     }),
491     b = r.rect(0, 0, 620, 400).attr({stroke: "none", fill: "#000", opacity: 0}).click(function () {
492         e.attr({rx: 5, ry: 3}).animateAlong(p, 4000, true, function () {
493             e.attr({rx: 4, ry: 4});
494         });
495     });</code></pre>
496                         <h3 id="getBBox">
497                             getBBox
498                         </h3>
499                         <p>
500                             Returns the dimensions of an element.
501                         </p>
502                         <h4>Usage</h4>
503                         <pre class="javascript code"><code>var c = paper.circle(10, 10, 10);</code>
504 <code>var width = c.getBBox().width;</code></pre>
505                         <h3 id="toFront">
506                             toFront
507                         </h3>
508                         <p>
509                             Moves the element so it is the closest to the viewer’s eyes, on top of other elements.
510                         </p>
511                         <h4>Usage</h4>
512                         <pre class="javascript code"><code>var c = paper.circle(10, 10, 10);</code>
513 <code>c.toFront();</code></pre>
514                         <h3 id="toBack">
515                             toBack
516                         </h3>
517                         <p>
518                             Moves the element so it is the furthest from the viewer’s eyes, behind other elements.
519                         </p>
520                         <h4>Usage</h4>
521                         <pre class="javascript code"><code>var c = paper.circle(10, 10, 10);</code>
522 <code>c.toBack();</code></pre>
523                         <h3 id="insertBefore">
524                             insertBefore
525                         </h3>
526                         <p>
527                             Inserts current object before the given one.
528                         </p>
529                         <h4>Usage</h4>
530                         <pre class="javascript code"><code>var r = paper.rect(10, 10, 10, 10);</code>
531 <code>var c = paper.circle(10, 10, 10);</code>
532 <code>c.insertBefore(r);</code></pre>
533                         <h3 id="insertAfter">
534                             insertAfter
535                         </h3>
536                         <p>
537                             Inserts current object after the given one.
538                         </p>
539                         <h4>Usage</h4>
540                         <pre class="javascript code"><code>var r = paper.rect(10, 10, 10, 10);
541 var c = paper.circle(10, 10, 10);
542 r.insertAfter(c);</code></pre>
543                         <h3 id="clone">
544                             clone
545                         </h3>
546                         <p>
547                             Returns a clone of the current element.
548                         </p>
549                         <h4>Usage</h4>
550                         <pre class="javascript code"><code>var r = paper.rect(10, 10, 10, 10);
551 var c = r.clone();</code></pre>
552                         <h2>Graphic Primitives</h2>
553                         <p>
554                             Methods of “paper” object, created with <code>Raphael</code> function call.
555                         </p>
556                         <h3 id="raphael">
557                             raphael
558                         </h3>
559                         <p>
560                             Internal reference to <code>Raphael</code> object. In case it is not available.
561                         </p>
562                         <h4>Usage</h4>
563                         <pre class="javascript code"><code>Raphael.el.red = function () {
564     var hsb = this.paper.raphael.rgb2hsb(this.attr("fill"));
565     hsb.h = 1;
566     this.attr({fill: this.paper.raphael.hsb2rgb(hsb).hex});
567 }</code></pre>
568                         <h3 id="getTotalLength">
569                             getTotalLength
570                         </h3>
571                         <p>
572                             Path specific method. Returns length of the path in pixels.
573                         </p>
574                         <h4>Usage</h4>
575                         <pre class="javascript code"><code>var p = r.path("M100,100c0,50 100-50 100,0c0,50 -100-50 -100,0z");
576     alert(p.getTotalLength());</code></pre>
577                         <h3 id="getPointAtLength">
578                             getPointAtLength
579                         </h3>
580                         <div class="sample" id="point-sample"></div>
581                         <p>
582                             Path specific method. Returns point description at given length.
583                         </p>
584                         <h4>Parameters</h4>
585                         <ol>
586                             <li>length <em>number</em> length in pixels from the beginining of the path to the point</li>
587                         </ol>
588                         <h4>Usage</h4>
589                         <pre class="javascript code"><code>var p = r.path("M10,50c0,50,80-50,80,0c0,50-80-50-80,0z");
590     var point = p.getPointAtLength(30);
591     r.circle(point.x, point.y, 3);</code></pre>
592                         <p>Returned object format:</p>
593                         <ul>
594                             <li>x – x coordinate of the point</li>
595                             <li>y – y coordinate of the point</li>
596                             <li>alpha – angle of the path at the point</li>
597                         </ul>
598                         <h3 id="getSubpath">
599                             getSubpath
600                         </h3>
601                         <div class="sample" id="subpath-sample"></div>
602                         <p>
603                             Path specific method. Returns the subpath string of a given path.
604                         </p>
605                         <h4>Parameters</h4>
606                         <ol>
607                             <li>from <em>number</em> length in pixels from the beginining of the path to the beginining of the subpath</li>
608                             <li>to <em>number</em> length in pixels from the beginining of the path to the end of the subpath</li>
609                         </ol>
610                         <h4>Usage</h4>
611                         <pre class="javascript code"><code>var p = r.path("M10,50c0,50,80-50,80,0c0,50-80-50-80,0z");
612     var path = p.getSubpath(10, 60);
613     r.path(path).attr({stroke: "#f00"});</code></pre>
614                         <h3 id="setSize">
615                             setSize
616                         </h3>
617                         <p>
618                             If you need to change dimensions of the canvas call this method
619                         </p>
620                         <h4>Parameters</h4>
621                         <ol>
622                             <li>width <em>number</em> new width of the canvas</li>
623                             <li>height <em>number</em> new height of the canvas</li>
624                         </ol>
625                         <h3 id="setWindow">
626                             setWindow
627                         </h3>
628                         <p>
629                             Should be called before main Raphael method. Sets which window should be used for drawing. Default is the current one. You need to use it if you want to draw inside <code>iframe</code>
630                         </p>
631                         <h4>Parameters</h4>
632                         <ol>
633                             <li>window <em>object</em></li>
634                         </ol>
635                         <h3 id="getRGB">
636                             getRGB
637                         </h3>
638                         <p>
639                             Parses passes string and returns an color object. Especially usefull for plug-in developers.
640                         </p>
641                         <h4>Parameters</h4>
642                         <ol>
643                             <li>color <em>string</em> Color in form acceptable by library</li>
644                         </ol>
645                         <h4>Usage</h4>
646                         <pre class="javascript code"><code>var stroke = Raphael.getRGB(circle.attr("stroke")).hex</code></pre>
647                         <h3 id="getColor">
648                             getColor
649                         </h3>
650                         <p>
651                             Returns a colour object for the next colour in spectrum
652                         </p>
653                         <h4>Parameters</h4>
654                         <ol>
655                             <li>value <em>number</em> brightness [optional]</li>
656                         </ol>
657                         <h4>Usage</h4>
658                         <pre class="javascript code"><code>var c = paper.path("M10,10L100,100").attr({stroke: Raphael.getColor()});</code></pre>
659                         <h3 id="getColor-reset">
660                             getColor.reset
661                         </h3>
662                         <p>
663                             Resets getColor function, so it will start from the beginning
664                         </p>
665                         <h3 id="registerFont">
666                             registerFont
667                         </h3>
668                         <p>
669                             Adds given font to the registered set of fonts for Raphaël. Should be used as an internal call from within Cufón’s font file. <a href="http://wiki.github.com/sorccu/cufon/about">More about Cufón and how to convert your font form TTF, OTF, etc to JavaScript file</a>. Returns original parameter, so it could be used with chaining.
670                         </p>
671                         <h4>Parameters</h4>
672                         <ol>
673                             <li>font <em>object</em> the font to register</li>
674                         </ol>
675                         <h4>Usage</h4>
676                         <pre class="javascript code"><code>Cufon.registerFont(Raphael.registerFont({…}))</code></pre>
677                         <h3 id="getFont">
678                             getFont
679                         </h3>
680                         <p>
681                             Finds font object in the registered fonts by given parameters. You could specify only one word from the font name, like “Myriad” for “Myriad Pro”.
682                         </p>
683                         <h4>Parameters</h4>
684                         <ol>
685                             <li>family <em>string</em> font family name or any word from it</li>
686                             <li>weight <em>string</em> weight of the font [optional]</li>
687                             <li>style <em>string</em> style of the font [optional]</li>
688                             <li>stretch <em>string</em> stretch of the font [optional]</li>
689                         </ol>
690                         <h4>Usage</h4>
691                         <pre class="javascript code"><code>paper.print(100, 100, "Test string", paper.getFont("Times", 800), 30);</code></pre>
692                         <h3 id="print">
693                             print
694                         </h3>
695                         <div class="sample" id="print-sample"></div>
696                         <p>
697                             Creates set of shapes to represent given font at given position with given size. Result of the method is set object (see <a href="#set">set</a>) which contains each letter as separate path object.
698                         </p>
699                         <h4>Parameters</h4>
700                         <ol>
701                             <li>x <em>number</em> x position of the text</li>
702                             <li>y <em>number</em> y position of the text</li>
703                             <li>text <em>string</em> text to print</li>
704                             <li>font <em>object</em> font object (see <a href="#getFont">getFont</a>)</li>
705                             <li>font_size <em>number</em> size of the font</li>
706                         </ol>
707                         <h4>Usage</h4>
708                         <pre class="javascript code"><code>var txt = r.print(10, 50, "print", r.getFont("Museo"), 30).attr({fill: "#fff"});
709 // following line will paint first letter in red
710 txt[0].attr({fill: "#f00"});</code></pre>
711                         <h3 id="plugins-canvas">
712                             Adding your own methods to canvas
713                         </h3>
714                         <p>
715                             You can add your own method to the canvas. For example if you want to draw pie chart, you can create your own pie chart function and ship it as a Raphaël plugin. To do this you need to extend Raphael.fn object. Please note that you can create your own namespaces inside fn object. Methods will be run in context of canvas anyway. You should alter fn object before Raphaël instance was created, otherwise it will take no effect.
716                         </p>
717                         <h4>Usage</h4>
718                         <pre class="javascript code"><code>Raphael.fn.arrow = function (x1, y1, x2, y2, size) {
719     return this.path( ... );
720 };
721 // or create namespace
722 Raphael.fn.mystuff = {
723     arrow: function () {…},
724     star: function () {…},
725     // etc…
726 };
727 var paper = Raphael(10, 10, 630, 480);
728 // then use it
729 paper.arrow(10, 10, 30, 30, 5).attr({fill: "#f00"});
730 paper.mystuff.arrow();
731 paper.mystuff.star();
732 </code></pre>
733                         <h3 id="plugins-elements">
734                             Adding your own methods to elements
735                         </h3>
736                         <p>
737                             You can add your own method to elements. This is usefull when you want to hack default functionality or want to wrap some common transformation or attributes in one method. In difference to canvas mathods, you can redefine element method at any time.
738                         </p>
739                         <h4>Usage</h4>
740                         <pre class="javascript code"><code>Raphael.el.red = function () {
741     this.attr({fill: "#f00"});
742 };
743 // then use it
744 paper.circle(100, 100, 20).red();
745 </code></pre>
746                         <h3 id="colour">
747                             Supported colour formats
748                         </h3>
749                         <p>
750                             You could specify colour in this formats:
751                         </p>
752                         <ul>
753                             <li>Colour name (“<samp>red</samp>”, “<samp>green</samp>”, “<samp>cornflowerblue</samp>”, etc)</li>
754                             <li>#••• — shortened HTML colour: (“<samp>#000</samp>”, “<samp>#fc0</samp>”, etc)</li>
755                             <li>#•••••• — full length HTML colour: (“<samp>#000000</samp>”, “<samp>#bd2300</samp>”)</li>
756                             <li>rgb(•••, •••, •••) — red, green and blue channels’ values: (“<samp>rgb(200,&nbsp;100,&nbsp;0)</samp>”)</li>
757                             <li>rgb(•••%, •••%, •••%) — same as above, but in %: (“<samp>rgb(100%,&nbsp;175%,&nbsp;0%)</samp>”)</li>
758                             <li>hsb(•••, •••, •••) — hue, saturation and brightness values: (“<samp>hsb(0.5,&nbsp;0.25,&nbsp;1)</samp>”)</li>
759                             <li>hsb(•••%, •••%, •••%) — same as above, but in %</li>
760                             <li>hsl(•••, •••, •••) — same as hsb</li>
761                             <li>hsl(•••%, •••%, •••%) — same as hsb</li>
762                         </ul>
763                         <h4>Usage</h4>
764                         <pre class="javascript code"><code>paper.circle(100, 100, 20).attr({
765     fill: "hsb(1, 255, 200)",
766     stroke: "red"
767 });</code></pre>
768                         <h3 id="safari">
769                             safari
770                         </h3>
771                         <p>
772                             There is an inconvenient rendering bug is Safari (WebKit): sometimes the rendering should be forced. This method should help with dealing with this bug.
773                         </p>
774                         <h4>Usage</h4>
775                         <pre class="javascript code"><code>paper.safari();</code></pre>
776                         <h3 id="ninja-mode">
777                             “Ninja Mode”
778                         </h3>
779                         <p>
780                             If you want to leave no trace of Raphaël (Well, Raphaël creates only one global variable <code>Raphael</code>, but anyway.) You can use <code>ninja</code> method. Beware, that in this case plugins could stop working, because they are depending on global variable existance.
781                         </p>
782                         <h4>Usage</h4>
783                         <pre class="javascript code"><code>(function (local_raphael) {
784     var paper = local_raphael(10, 10, 320, 200);
785     …
786 })(Raphael.ninja());
787 </code></pre>
788                         <h3 id="events">
789                             Events
790                         </h3>
791                         <p>
792                             You can attach events to elements by using element.node and your favourite library (<samp>$(circle.node).click(…)</samp>) or you can use built-in methods:
793                         </p>
794                         <h4>Usage</h4>
795                         <pre class="javascript code"><code>element.click(function (event) {
796     this.attr({fill: "red"});
797 });
798 element.dblclick(function (event) {
799     this.attr({fill: "red"});
800 });
801 element.mousedown(function (event) {
802     this.attr({fill: "red"});
803 });
804 element.mousemove(function (event) {
805     this.attr({fill: "red"});
806 });
807 element.mouseout(function (event) {
808     this.attr({fill: "red"});
809 });
810 element.mouseover(function (event) {
811     this.attr({fill: "red"});
812 });
813 element.mouseup(function (event) {
814     this.attr({fill: "red"});
815 });
816 element.hover(function (event) {
817     this.attr({fill: "red"});
818 }, function (event) {
819     this.attr({fill: "black"});
820 });</code></pre>
821                         <p>
822                             To unbind events use the same method names with “un” prefix, i.e. <samp>element.unclick(f);</samp>
823                         </p>
824                     </div>
825                     <div id="column-2">
826                         <h2>
827                             <a href="index.html">Home</a>
828                         </h2>
829                         <h2>
830                             Contents
831                         </h2>
832                         <ul id="contents">
833                             <li>
834                                 <a href="#Raphael"><code>Raphael</code></a>
835                             </li>
836                             <li>
837                                 <a href="#circle"><code>circle</code></a>
838                             </li>
839                             <li>
840                                 <a href="#rect"><code>rect</code></a>
841                             </li>
842                             <li>
843                                 <a href="#ellipse"><code>ellipse</code></a>
844                             </li>
845                             <li>
846                                 <a href="#image"><code>image</code></a>
847                             </li>
848                             <li>
849                                 <a href="#set"><code>set</code></a>
850                             </li>
851                             <li>
852                                 <a href="#text"><code>text</code></a>
853                             </li>
854                             <li>
855                                 <a href="#path"><code>path</code></a>
856                             </li>
857                             <li>
858                                 <a href="#node"><code>node</code></a>
859                             </li>
860                             <li>
861                                 <a href="#paper"><code>paper</code></a>
862                             </li>
863                             <li>
864                                 <a href="#remove"><code>remove</code></a>
865                             </li>
866                             <li>
867                                 <a href="#hide"><code>hide</code></a>
868                             </li>
869                             <li>
870                                 <a href="#show"><code>show</code></a>
871                             </li>
872                             <li>
873                                 <a href="#rotate"><code>rotate</code></a>
874                             </li>
875                             <li>
876                                 <a href="#translate"><code>translate</code></a>
877                             </li>
878                             <li>
879                                 <a href="#scale"><code>scale</code></a>
880                             </li>
881                             <li>
882                                 <a href="#attr"><code>attr</code></a>
883                             </li>
884                             <li>
885                                 <a href="#animate"><code>animate</code></a>
886                             </li>
887                             <li>
888                                 <a href="#animateWith"><code>animateWith</code></a>
889                             </li>
890                             <li>
891                                 <a href="#animateAlong"><code>animateAlong</code></a>
892                             </li>
893                             <li>
894                                 <a href="#animateAlongBack"><code>animateAlongBack</code></a>
895                             </li>
896                             <li>
897                                 <a href="#getBBox"><code>getBBox</code></a>
898                             </li>
899                             <li>
900                                 <a href="#toFront"><code>toFront</code></a>
901                             </li>
902                             <li>
903                                 <a href="#toBack"><code>toBack</code></a>
904                             </li>
905                             <li>
906                                 <a href="#insertBefore"><code>insertBefore</code></a>
907                             </li>
908                             <li>
909                                 <a href="#insertAfter"><code>insertAfter</code></a>
910                             </li>
911                             <li>
912                                 <a href="#clone"><code>clone</code></a>
913                             </li>
914                             <li>
915                                 <a href="#raphael"><code>raphael</code></a>
916                             </li>
917                             <li>
918                                 <a href="#getTotalLength"><code>getTotalLength</code></a>
919                             </li>
920                             <li>
921                                 <a href="#getPointAtLength"><code>getPointAtLength</code></a>
922                             </li>
923                             <li>
924                                 <a href="#getSubpath"><code>getSubpath</code></a>
925                             </li>
926                             <li>
927                                 <a href="#setSize"><code>setSize</code></a>
928                             </li>
929                             <li>
930                                 <a href="#setWindow"><code>setWindow</code></a>
931                             </li>
932                             <li>
933                                 <a href="#getRGB"><code>getRGB</code></a>
934                             </li>
935                             <li>
936                                 <a href="#getColor"><code>getColor</code></a>
937                             </li>
938                             <li>
939                                 <a href="#getColor-reset"><code>getColor.reset</code></a>
940                             </li>
941                             <li>
942                                 <a href="#registerFont"><code>registerFont</code></a>
943                             </li>
944                             <li>
945                                 <a href="#getFont"><code>getFont</code></a>
946                             </li>
947                             <li>
948                                 <a href="#print"><code>print</code></a>
949                             </li>
950                             <li>
951                                 <a href="#plugins-canvas">Adding your own methods to canvas</a>
952                             </li>
953                             <li>
954                                 <a href="#plugins-elements">Adding your own methods to elements</a>
955                             </li>
956                             <li>
957                                 <a href="#colour">Supported colour formats</a>
958                             </li>
959                             <li>
960                                 <a href="#safari">safari</a>
961                             </li>
962                             <li>
963                                 <a href="#ninja-mode">“Ninja Mode”</a>
964                             </li>
965                             <li>
966                                 <a href="#events">Events</a>
967                             </li>
968                         </ul>
969                     </div>
970                     <div  id="footer">
971                         <h3 id="copyright">
972                             <a href="http://www.opensource.org/licenses/mit-license.php" title="MIT License" rel="license">Some Rights Reserved</a> by <a href="http://dmitry.baranovskiy.com/">Dmitry Baranovskiy</a>
973                         </h3>
974                         <h3 id="font">
975                             Logo by <a href="http://wasabicube.com/">Wasabicube</a> ·
976                             Work at this project started as 20% time at <a href="http://www.atlassian.com/" title="Atlassian — Software to Track, Test &#38; Collaborate, from Enterprises to Open Source Projects.">Atlassian</a>
977                         </h3>
978                     </div>
979                 </div>
980             </div>
981         </div>
982         <script src="syntax.js" type="text/javascript" charset="utf-8"></script>
983         <script type="text/javascript">
984         var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
985         document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
986         </script>
987         <script type="text/javascript">
988         var pageTracker = _gat._getTracker("UA-616618-3");
989         pageTracker._trackPageview();
990         </script>
991     </body>
992 </html>