- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
- <meta property="fb:page_id" content="197406883610725" />
-
- <script src="js/jquery.min.js" type="text/javascript"></script>
- <script src="build/joint.all.min.js" type="text/javascript"></script>
- <script src="http://yandex.st/highlightjs/5.16/highlight.min.js"></script>
- <script src="js/setup.js" type="text/javascript"></script>
-
-
- <link href="css/reset.css" type="text/css" rel="stylesheet" />
- <link href="css/grids.css" type="text/css" rel="stylesheet" />
- <link href="css/styles.css" media="screen, projection" type="text/css" rel="stylesheet" />
- <link rel="stylesheet" href="http://yandex.st/highlightjs/5.16/styles/sunburst.min.css" />
-
- <title>Joint - JavaScript diagramming library.</title>
- </head>
-
- <body>
-
- <div id="header">
- <a href="http://www.jointjs.com"><img class="logo" src="img/logo/logo_standalone.png" alt="JointJS logo"/></a>
- <h1>JavaScript diagramming library</h1>
- <div class="version"><span>0.4</span><img class="tag" src="img/tag.png" alt="JointJS"/></div>
- <ul id="menu">
- <li><a class="current" href="about.html">About</a></li>
- <li><a href="download.html">Download</a></li>
- <li><a href="demos.html">Demos</a></li>
- <li><a href="license.html">License</a></li>
- <li><a href="tutorial.html">Quick tutorial</a></li>
- <li><a href="api.html"><b>API Reference</b></a>
- <li><a href="http://groups.google.com/group/jointjs">Discussion</a></li>
- </ul>
-
- </div>
-
- <div class="main">
- <div id="content">
- <h1 class="subpage-header">Quick tutorial</h1>
- <hr/>
-
- <p>
- This tutorial is probably your first touch with <em>JointJS</em> library. It shows you
- how to create a simple Finite State Machine diagram. At the end of this tutorial
- you can also find a popular "Hello world" program.
- </p>
- <h3>Getting started</h3>
-
- <h4>Scripts:</h4>
- <ul>
- <li><tt>raphael-min.js</tt>: <a href="http://raphaeljs.com">Raphaël</a> library,
- provides cross browser abstract layer for rendering vector objects.</li>
- <li><tt>joint.js</tt>: Joint library core.</li>
- <li><tt>joint.dia.js</tt>: Joint diagramming library core, provides abstraction
- for diagrams elements.
- (necessary for diagram plugins, see below)</li>
- <li><tt>joint.dia.fsa.js</tt>: Finite state machine diagram plugin.</li>
- </ul>
- <p><em>Example: </em>To create a Finite state machine diagram, put these scripts into your document's header:</p>
- <pre>
- <code>
- <script src="raphael-min.js" type="text/javascript"></script>
- <script src="joint.min.js" type="text/javascript"></script>
- <script src="joint.dia.min.js" type="text/javascript"></script>
- <script src="joint.dia.fsa.min.js" type="text/javascript"></script>
- </code>
- </pre>
- Or alternatively you can use the standalone package provided which includes both
- <tt>Joint</tt> and <tt>Joint.dia</tt> libraries, all plugins and Raphaël library, all in one file.
- <pre>
- <code>
- <script src="joint.all-min.js" type="text/javascript"></script>
- </code>
- </pre>
- <p>
- Then you have to create a holder for your diagram.
- </p>
- <pre>
- <code>
- <div id="myfsa"></div>
- </code>
- </pre>
-
- <p>
- Once you have the holder created, you have to initialize diagram paper.
- </p>
- <pre>
- <code>
- Joint.paper("myfsa", 1000, 200); /*(id or HTMLElement, width, height)*/
- </code>
- </pre>
-
- <h4>Creating your first Finite State Machine diagram</h4>
- <p>Each kind of diagram is implemented as a separate plugin.
- FSA plugin contains elements such as <tt>State</tt>, <tt>StartState</tt>, <tt>EndState</tt>
- and definition of the arrow suitable for FSA diagrams <tt>Joint.dia.fsa.arrow</tt>.
- Concrete elements are created using <tt>create</tt> method. This method takes as an argument object containing
- all necessary parameters for the element. (for list of all options, see FSA plugin API)</p>
- <pre>
- <code>
- var s0 = fsa.StartState.create({ position: {x: 50, y: 50} });
- var se = fsa.EndState.create({ position: {x: 450, y: 150} });
- var s1 = fsa.State.create({ position: {x: 120, y: 120}, label: "state 1" });
- var s2 = fsa.State.create({ position: {x: 300, y: 50}, label: "state 2" });
- </code>
- </pre>
-
- <p>
- Joint library provides API for creating your own arrows which reside both connection
- ends. Usually, diagram plugins should provide arrows specific for diagrams they implement.
- Connections can register objects to which they can stick. You can also refine what
- connection end you want to stick to what object. For normal purposes (especially FSA
- diagrams) it is a good practice to create an array which holds all
- the diagram elements. Note the usage of <tt>registerForever()</tt> method. The difference
- between <tt>register()</tt> and <tt>registerForever</tt> is that the latter stores
- a reference to the array object provided as the only argument. That means that
- all elements added later to the array are registered as well.
- </p>
-
- <pre>
- <code>
- var all = [s0, s1, s2, se];
- s0.joint(s1, fsa.arrow).registerForever(all);
- s1.joint(s2, fsa.arrow).registerForever(all);
- s2.joint(se, fsa.arrow).registerForever(all);
- </code>
- </pre>
-
- <p>
- The final diagram is by default interactive. You can drag arrows, break connections and move states:
- </p>
-
- <div style="border: 1px solid gray; background-color: white;" id="myfsa"></div>
- <script type="text/javascript">
- Joint.paper("myfsa", 1000, 200); /*(id or HTMLElement, width, height)*/
- var fsa = Joint.dia.fsa;
-
- var s0 = fsa.StartState.create({ position: {x: 50, y: 50} });
- var se = fsa.EndState.create({ position: {x: 450, y: 150} });
- var s1 = fsa.State.create({ position: {x: 120, y: 120}, label: "state 1" });
- var s2 = fsa.State.create({ position: {x: 300, y: 50}, label: "state 2" });
-
- var all = [s0, s1, s2, se];
- s0.joint(s1, fsa.arrow).registerForever(all);
- s1.joint(s2, fsa.arrow).registerForever(all);
- s2.joint(se, fsa.arrow).registerForever(all);
- </script>
-
- <h4>Hello world!</h4>
- <p>
- <em>Joint</em> library is independent of diagram plugins. It means that
- it can be used on its own for connecting vector objects created by
- Raphaël library. This is useful if you just want a functionality
- of connecting vector objects together. Connections as well as arrows
- and behavior is fully customizable. For more details, see Joint library
- API.
- </p>
- <pre>
- <code>
- <html>
- <head>
- <script type="text/javascript" src="raphael-min.js"></script>
- <script type="text/javascript" src="joint.min.js"></script>
- </head>
- <body>
- <div id="hello_world"></>
- <script type="text/javascript">
- var r = Raphael("hello_world", 1000, 50),
- c1 = r.circle(50, 20, 10),
- c2 = r.circle(250, 25, 10);
- c1.joint(c2);
- </script>
- </body>
- </html>
- </code>
- </pre>
-
- <div style="border: 1px solid gray; background-color: white;" id="hello_world"></div>
- <script type="text/javascript">
- var
- r = Raphael("hello_world", 1000, 50),
- c1 = r.circle(50, 20, 10),
- c2 = r.circle(250, 25, 10);
-
- c1.joint(c2);
- </script>
-
-
-
-
- </div>
- </div>
-
- <div id="foot">
- <div class="gradient-strip"></div>
- <div class="pledgie">
- <a href='http://www.pledgie.com/campaigns/14101'><img alt='Click here to lend your support to: JointJS and make a donation at www.pledgie.com !' src='http://www.pledgie.com/campaigns/14101.png?skin_name=chrome' border='0' /></a>
- </div>
- <div class="diasketch">
- <a href="http://www.diasketch.com">DiaSketch</a><br/><b>Online diagramming solution.</b>
- </div>
- <div class="twitter">
- <a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.jointjs.com" data-count="horizontal" data-via="jointjs">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
- </div>
- <div class="facebook">
- <iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.jointjs.com&layout=standard&show_faces=false&width=450&action=like&colorscheme=dark&height=35" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:35px;" allowTransparency="true"></iframe>
- </div>
- <em class="copyright">Copyright © 2009 - 2011 David Durman</em>
- <p class="notes">
- <span>About the author</span><br/>
- Author is a Software Developer
- based in Amsterdam, the Netherlands.
- He is currently most interested in JavaScript on both
- client and server side.
- </p>
- <p class="notes">
- <span>How to contribute</span><br/>
- For criticism, feature proposals and other useful
- information please use
- the discussion forum. For code contribution: fork
- the joint project on github and use the pull requests.
- </p>
- <p class="notes">
- <span>Bug reporting</span><br/>
- All bug reports are welcome! Please use the
- <a href="https://github.com/DavidDurman/joint/issues">github issue tracker</a>.
- </p>
- </div>
-
- <script type="text/javascript">
- var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
- document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
- </script>
- <script type="text/javascript">
- try {
- var pageTracker = _gat._getTracker("UA-5029684-2");
- pageTracker._trackPageview();
- } catch(err) {}</script>
- </body>
- </html>