04.07.2013 Views

Building Web Applications with SVG - Cdn.oreilly.com

Building Web Applications with SVG - Cdn.oreilly.com

Building Web Applications with SVG - Cdn.oreilly.com

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Here’s how it’s done:<br />

■■ Drawing One advantage of using <strong>SVG</strong>—instead of <strong>com</strong>paratively lightweight graphical<br />

technologies, such as in HTML—for building web applications is that objects in<br />

<strong>SVG</strong> are in the DOM. This means that events can be easily attached to objects and <strong>SVG</strong> event<br />

handling, much like those in the nongraphical parts of HTML. Thus, mouse coordinates (as well<br />

as the targets of events) can easily be interrogated to allow the creation and repositioning of<br />

objects, in the classical sense of a GUI.<br />

■■ Connecting Again, because <strong>SVG</strong> objects are in the DOM, it is easy to build JavaScript referents<br />

to those objects so that arrays of objects and their properties may be maintained along<br />

<strong>with</strong> connections back to their visible instantiations. It is easy to connect and disconnect nodes<br />

of graphs, precisely because they are objects, both in JavaScript and <strong>SVG</strong>.<br />

■<br />

■ Interface The example shown here uses JavaScript to build a menuing system along <strong>with</strong><br />

dialog boxes, and the ability to export and import the user’s drawings. However, much of this<br />

functionality can also be provided through higher-level tools, such as D3, and Pergola (discussed<br />

in later chapters).<br />

20 <strong>Building</strong> <strong>Web</strong> <strong>Applications</strong> <strong>with</strong> <strong>SVG</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!