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