Preface - RaphaelJS: Graphics and Visualization on the Web (2014)

RaphaelJS: Graphics and Visualization on the Web (2014)


I once heard programming described as a way to “express your ideas through a computer.” To me, that morsel of wisdom encapsulates everything that is wonderful and awful about writing code: it gives us the vocabulary to work through our ideas and then lays bare the limits of our ingenuity.

If everyone had the same sorts of ideas, we would only need one programming language. The quotation above comes from a book about Ruby, which many people will fervently argue is the finest language around (often long after you would have preferred to change the subject).

But of course, people have all sorts of wild ideas that cannot be properly served by one language. This book, which is about the JavaScript library called Raphael, is for a specific subset of human ideas: visual ones.

If you’re a person who thinks visually and wants to learn to code, there’s a good chance you’ve been frustrated by efforts to learn classical programming languages like Ruby, Python, PHP, or even JavaScript itself, the programming language that is embedded in every web browser. Most tutorials tend to start you out with printing words to the screen, writing functions to print more words to the screen, and, if you’re lucky, maybe branching into printing numbers to the screen by the end of the first lesson.

In RaphaelJS, we’ll be painting the screen with all manner of shapes and colors, animating them through space and time, and bending them to our will (via the tyranny of our mouse and fingers). Every example and lesson in this book runs in the browser and is 100% web-ready, meaning you can upload it directly to your site to have living, breathing visuals that run in any browser.

While this book is not explicitly an introduction to JavaScript, I’ve done my best to make it accessible to people who are new to the field. None of the code in this book requires advanced mastery of computer science or a deep foundational understanding of JavaScript. It is meant to get both new and experienced coders up and running as fast as possible.

The only tool we need for this book, besides a computer, is the Raphael.js library, which is open-source and freely available at under the MIT License. Bringing a few visual ideas to the table won’t hurt, either. By the end of this manual, you’ll be ready to express them in code.

Conventions Used in This Book

The following typographical conventions are used in this book:


Indicates new terms, URLs, email addresses, filenames, and file extensions.

Constant width

Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords.

Constant width bold

Shows commands or other text that should be typed literally by the user.

Constant width italic

Shows text that should be replaced with user-supplied values or by values determined by context.


This icon signifies a tip, suggestion, or general note.


This icon indicates a warning or caution.