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