fn
is used for adding your own methods to the canvas.
Any methods you add to fn
will work on the canvas. This is in contrast to methods that would work on for example an element ( for which you would use el
).
Since extending the fn
object will act on the canvas, you must add your custom methods before creating your Raphael instance (this is not true if you are extending the el
of an element).
For example, from the documentation:
// Extend Raphael fn object by adding methods to it:
Raphael.fn.arrow = function (x1, y1, x2, y2, size) {
return this.path( ... );
};
// or add namespaces to it:
Raphael.fn.mystuff = {
arrow: function () {…},
star: function () {…},
// etc…
};
// Now when you create a Raphael instance, your custom
// methods are available.
var paper = Raphael(10, 10, 630, 480);
// Using custom methods:
paper.arrow(10, 10, 30, 30, 5).attr({fill: "#f00"});
// Using name spaced custom methods
paper.mystuff.arrow();
paper.mystuff.star();