-
Notifications
You must be signed in to change notification settings - Fork 635
/
Copy pathreference.html
626 lines (589 loc) · 30 KB
/
reference.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>arbor.js</title>
<meta name="generator" content="TextMate http://macromates.com/">
<meta name="author" content="Christian Swinehart">
<!-- Date: 2011-01-11 -->
<link rel="stylesheet" href="_/docs.css" type="text/css" charset="utf-8">
</head>
<body>
<div id="nav">
<p>reference</p>
</div>
<div id="docs">
<div id="reference">
<h1>ParticleSystem</h1>
<div class="lead-in">
<p>The particle system stores your nodes
and edges and handles updating their coordinates as the simulation progresses.</p>
<a href="#" class="more">creation & use…</a>
<h2><a href="#">×</a> creation</h2>
<p>Parameters for the physics simulation can be set at creation-time
by calling the constructor with the arguments:</p>
<p class="code">
arbor.ParticleSystem(repulsion, stiffness, friction, gravity, fps, dt, precision)
</p>
<p>The parameters and their defaults are:</p>
<ul>
<li><em>repulsion </em><b>1,000</b> the force repelling nodes from each other</li>
<li><em>stiffness </em><b>600</b> the rigidity of the edges </li>
<li><em>friction </em><b>0.5</b> the amount of damping in the system </li>
<li><em>gravity </em><b>false</b> an additional force attracting nodes to the origin </li>
<li><em>fps </em><b>55</b> frames per second </li>
<li><em>dt </em><b>0.02</b> timestep to use for stepping the simulation </li>
<li><em>precision </em><b>0.6</b> accuracy vs. speed in force calculations<br>
<em> </em><b> </b> (zero is fast but jittery, one is smooth but cpu-intensive)</li>
</ul>
<p>The defaults will be used for any omitted arguments. Parameters can also be passed
in an object literal. For reference, the following calls are all equivalent:</p>
<p class="code">
arbor.ParticleSystem()<br>
arbor.ParticleSystem(600)<br>
arbor.ParticleSystem(600, 1000, .5, 55, .02, false)<br>
arbor.ParticleSystem({friction:.5, stiffness:600, repulsion:1000})
</p>
<p>Once a particle system has been created, the parameters can be tweaked by passing
an object to the <code>.parameters</code> method:</p>
<p class="code">
var sys = arbor.ParticleSystem()<br>
sys.parameters({gravity:true, dt:0.005})
</p>
<h2>rendering</h2>
<p>The particle system doesn’t do any drawing on its own; you need to provide those
routines in a separate object that will be triggered by the system when it’s time
to redraw the screen. To set this up, create an object with two methods (<code>.init</code>
and <code>.redraw</code>), then set the particle system’s <code>renderer</code>
attribute to your new object:</p>
<p class="code">
var myRenderer = {<br>
init: function(system){ console.log("starting",system) },<br>
redraw:function(){ console.log("redraw") }<br>
}<br>
var sys = arbor.ParticleSystem()<br>
sys.renderer = myRenderer
</p>
<p>The <code>.init</code> method will be called once before the first pass through the
draw loop. Then the <code>.redraw</code> method will be called each time the screen
needs to be re-plotted. Take a look at the <a href="https://github.com/samizdatco/arbor/sample-project">sample project</a> for a
slightly more elaborated example of how this works.
</p>
</div>
<h2>nodes</h2>
<dl>
<dt>addNode<em>(name, data)</em></dt>
<dd>
<p><code class="arg">name</code> is a string identifier that will be used in talking to the particle
system about this node.</p>
<p><code class="arg">data</code> is an object with keys and values set by the user. you can use it to
store additional information about the node for later use in e.g., drawing.</p>
<div class="desc">Creates a new node in the particle system and returns the resulting <code>Node</code> object.</div>
<hr>
</dd>
<dt>getNode<em>(name)</em></dt>
<dd>
<p><code class="arg">name</code> is an identifier for a node already in the system</p>
<div class="desc">Returns the corresponding <code>Node</code> object or
<code>undefined</code> if none is found. If called with a node as an
argument, it will return that same node (for idempotence).</div>
<hr>
</dd>
<dt>pruneNode<em>(node)</em> </dt>
<dd>
<p><code class="arg">node</code> is either an identifier string or a Node object</p>
<div class="desc">Removes the corresponding <code>Node</code> from the
particle system (as well as any <code>Edge</code>s in which it is a participant).</div>
<hr>
</dd>
</dl>
<h2>edges</h2>
<dl>
<dt>addEdge<em>(source, target, data)</em></dt>
<dd>
<p><code class="arg">source</code> and <code class="arg">target</code> are either identifier strings or a Node objects.</p>
<p><code class="arg">data</code> is a user data object with additional information about the edge.</p>
<div class="desc">Creates a new edge connecting the source and target nodes
then returns the resulting <code>Edge</code> object.
</div>
<hr>
</dd>
<dt>getEdges<em>(source, target)</em> </dt>
<dd>
<p><code class="arg">source</code> and <code class="arg">target</code> are either identifier strings or a Node objects.</p>
<div class="desc">Returns an array containing all <code>Edge</code> objects connecting the specified nodes.
If no connections exist, returns <code style="letter-spacing:2px;">[]</code>.
</div>
<hr>
</dd>
<dt>getEdgesFrom<em>(node)</em></dt>
<dd>
<p><code class="arg">node</code> is a string identifier or Node object</p>
<div class="desc">Returns an array containing all <code>Edge</code> objects in which the
node is the source.
If no connections exist, returns <code style="letter-spacing:2px;">[]</code>.
</div>
<hr>
</dd>
<dt>getEdgesTo<em>(node)</em> </dt>
<dd>
<p><code class="arg">node</code> is a string identifier or Node object</p>
<div class="desc">Returns an array containing all <code>Edge</code> objects in which the
node is the target.
If no connections exist, returns <code style="letter-spacing:2px;">[]</code>.
</div>
<hr>
</dd>
<dt>pruneEdge<em>(edge)</em> </dt>
<dd>
<p><code class="arg">edge</code> is an Edge object.</p>
<div class="desc">Removes the corresponding <code>Edge</code> from the particle system.
</div>
<hr>
</dd>
</dl>
<h2>iteration</h2>
<dl>
<dt>eachNode<em>(callback)</em></dt>
<dd>
<p><code class="arg">callback</code> is a function with the signature ƒ(<code>node</code>, <code>pt</code>) where
<code class="arg">node</code> is a Node object and <code class="arg">pt</code> is a Point object with its current
location.</p>
<div class="desc">The callback function will be invoked once for each <code>Node</code> in the system.</div>
<div class="desc">Note that while the <code>node.p</code> attribute is always in the coordinate system of
the particle system, the <code>pt</code> argument is transformed into pixel coordinates
(provided you have called <code>.screenSize</code> to specify the screen bounding box).</div>
<hr>
</dd>
<dt>eachEdge<em>(callback)</em></dt>
<dd>
<p><code class="arg">callback</code> is a function with the signature ƒ(<code>edge</code>, <code>pt1</code>, <code>pt2</code>) where
<code class="arg">edge</code> is an Edge object and <code class="arg">pt1</code> and <code class="arg">pt2</code> are Point objects
with the current endpoint locations.</p>
<div class="desc">The callback function will be invoked once for each <code>Edge</code> in the system.</div>
<div class="desc">Similar to the behavior of <code>.eachNode</code>, the <code>edge.source.p</code> and
<code>edge.target.p</code> attributes are always in the coordinate system of
the particle system, while <code>pt1</code> and <code>pt2</code> will be transformed into pixel coordinates
(provided you have called <code>.screenSize</code> to specify the screen bounding box).</div>
<hr>
</dd>
</dl>
<h2>modification</h2>
<dl>
<dt>graft<em>(branch)</em></dt>
<dd>
<p><code class="arg">branch</code> is an object of the form <code>{nodes:{}, objects:{}}</code>.</p>
<p>the <code class="arg">nodes</code> attribute contains a mapping of node names to data objects. For example,</p>
<p class="code">{ nodes:{foo:{color:"red", mass:2},<br>
bar:{color:"green"}} }</p>
<p style="text-indent:-10px">the <code class="arg">edges</code> attribute contains nested objects to map source identifier to target, then
target to edge data object. e.g,</p>
<p class="code">{ edges:{bar:{foo:{similarity:0},<br>
baz:{similarity:.666}} }</p>
<div class="desc">Adds nodes and edges to the current set in the particle system. The
leaf object values in the <code>branch</code> argument will be accessible through the
<code>.data</code> attribute of the resulting <code>Node</code>s and <code>Edge</code>s.
</div>
<hr>
</dd>
<dt>merge<em>(branch)</em></dt>
<dd>
<p><code class="arg">branch</code> is an object of the form <code>{nodes:{}, objects:{}}</code>
(see <code>.graft</code> for details).</p>
<div class="desc">Adds nodes and edges to the current set in the particle system and removes
any that are not present in the new branch. Conserved nodes will maintain their position
and state.
</div>
<hr>
</dd>
<dt>prune<em>(callback)</em></dt>
<dd>
<p><code class="arg">callback</code> is a function with the signature ƒ(<code>node</code>, <code>from</code>, <code>to</code>) where
<code class="arg">node</code> is a Node object and <code class="arg">from</code> and <code class="arg">to</code> are arrays
of edges for which node is the source and target respectively.</p>
<div class="desc">The callback function will be invoked once for each <code>Node</code>
in the system and should return <code>true</code> if the node should be pruned or do
nothing if the node should remain unaltered. Note that pruning a node will also remove all edges in
which it participates</div>
<hr>
</dd>
</dl>
<h2>system settings</h2>
<dl>
<dt>parameters<em>( ) or (params)</em></dt>
<dd>
<p>if present, <code class="arg">params</code> is an object containing new settings values
for the particle system. Valid keys are the same as for the <code>ParticleSystem</code>
constructor function:
<code>repulsion</code>, <code>stiffness</code>, <code>friction</code>, <code>gravity</code>, <code>fps</code>, and <code>dt</code>.
</p>
<div class="desc">If called with no arguments, returns an object with the current system
parameters as keys and values. If an argument is supplied, any values specified will
be used as the new parameters (omitted values will remain unchanged).
</div>
<hr>
</dd>
<dt>fps<em>( ) or (fps)</em></dt>
<dd>
<p>if present, the <code class="arg">fps</code> argument is a positive integer.
</p>
<div class="desc">If called with no arguments, returns the frame rate achieved over
the last few seconds of drawing. Otherwise the argument will set the new target
frame rate. This affects the frequency with which the particle system iterates
its simulation as well as the frequency with which the <code>ParticleSystem</code> calls the
<code>.redraw</code> method of the object pointed to by its
<code>.renderer</code> attribute.
</div>
<hr>
</dd>
<dt>bounds<em>( )</em></dt>
<dd>
<div class="desc">Returns a bounding box containing all nodes using system
coordinates. The return value is of the form:
</div>
<p class="code">{ topleft:{x:, y:}, bottomright:{x:, y:} }</p>
<hr>
</dd>
<dt>energy<em>( )</em></dt>
<dd>
<div class="desc">Returns some basic stats on the state of activity in the
system. The values are in terms of velocity within the system’s coordinate
frame. This can be a useful measure of when the layout has stabilized.
The return value is of the form:
</div>
<p class="code">{sum:, max:, mean:, n:}</p>
<hr>
</dd>
<dt>start<em>( )</em></dt>
<dd>
<div class="desc">Manually start the system running. By default the system
will run and pause on its own based on the level of energy in the particles.
You should only need to manually start after having previously called the <code>.stop</code> method.
</div>
<hr>
</dd>
<dt>stop<em>( )</em></dt>
<dd>
<div class="desc">Pauses the particle simulation until <code>.start</code> is called.
Since the system begins running as soon as it is supplied with nodes and edges, you
may wish to call <code>.stop</code> shortly after creating the system object if it
will not be displayed until later in the page lifetime (e.g., until a user action takes place).
</div>
<hr>
</dd>
</dl>
<h2>coordinate helpers</h2>
<dl>
<dt>screenSize<em>(width, height)</em></dt>
<dd>
<p><code class="arg">width</code> and <code class="arg">height</code> are positive integers defining the
dimensions of the screen area you will be drawing in.</p>
<div class="desc">Calling this method enables automatic coordinate transformations
from the particle system’s coordinate system to your display’s. This can be seen
in the points supplied by the <code>.eachNode</code> and <code>.eachEdge</code>
iterators as well as the <code>to</code>/<code>fromScreen</code> and <code>nearest</code>
methods in this section.
</div>
<div class="desc">You will nearly always want to call this once when setting up your
<code>ParticleSystem</code> and <code>renderer</code> as well as whenever the dimensions
of the display area change.
</div>
<hr>
</dd>
<dt>screenPadding<em>(top, right, bottom, left)</em></dt>
<dd>
<p>All arguments are integers defining the number of pixels that should be left
blank along each edge of the display area. Either 1, 2, or 4 arguments are
expected and are interpreted similarly to the CSS <code>padding:</code> property.</p>
<div class="desc">When the system transforms points
between coordinate systems it will factor the padding into the locations it
provides to <code>.eachNode</code> and company.
</div>
<hr>
</dd>
<dt>screenStep<em>(stepsize)</em></dt>
<dd>
<p><code class="arg">stepsize</code> is a number between 0 and 1 defining the
amount the bounding box should move from one frame to the next.</p>
<div class="desc">As the nodes move and the bounding box changes, the system
applies a variable amount of smoothing to the ‘camera’ movements. As stepsize
approaches 1 the amount of smoothing decreases as the bounds updates become more
instantaneous.
</div>
<hr>
</dd>
<dt>screen<em>() or (opts)</em></dt>
<dd>
<p>If present, <code class="arg">opts</code> is an object of the form:</p>
<p class="code">{ size:{width:400, height:300},<br>
padding:[1,2,3,4],<br>
step:.1 }</p>
<div class="desc">This is a shorthand method combining the functions of the prior three.
If called without an argument, returns the current screen size/padding/scaling. If an
argument is supplied, updates the settings accordingly.
</div>
<hr>
</dd>
<dt>toScreen<em>(systemPoint)</em> </dt>
<dd>
<p><code class="arg">systemPoint</code> is a <code>Point</code> object whose x and y
values are set using the system’s internal coordinate scheme.</p>
<div class="desc">Converts the x and y to screen coordinates on the basis of the current
screen size and padding, returning the result as a new <code>Point object</code>. If the
size hasn’t been set or the system hasn’t started yet, <code>undefined</code> will be returned
instead.
</div>
<hr>
</dd>
<dt>fromScreen<em>(screenPoint)</em> </dt>
<dd>
<p><code class="arg">screenPoint</code> is a <code>Point</code> object whose x and y
values are using the screen’s pixel coordinates.</p>
<div class="desc">Converts the x and y to system coordinates on the basis of the current
screen size and padding, returning the result as a new <code>Point object</code>. If the
size hasn’t been set or the system hasn’t started yet, <code>undefined</code> will be returned
instead.
</div>
<hr>
</dd>
<dt>nearest<em>(screenPoint)</em></dt>
<dd>
<p><code class="arg">screenPoint</code> is a <code>Point</code> object whose x and y
values are using the screen’s pixel coordinates.</p>
<div class="desc">Returns a reference to the node nearest the argument’s screen position
in an object of the form:
</div>
<p class="code">{node:, point:, distance:}</p>
<div class="desc"><code>node</code> and <code>point</code> will either be the eponymous
objects or <code>null</code> depending on whether any such node exists. <code>distance</code>
is measured in pixels.
</div>
<hr>
</dd>
</dl>
<h2>tweening</h2>
<dl>
<dt>tweenNode<em>(node, duration, opts)</em></dt>
<dd>
<p><code class="arg">node</code> is a <code>Node</code> object or an identifier string
for the node whose values you wish to tween.</p>
<p><code class="arg">duration</code> is the time (in seconds) the transition should last.</p>
<p><code class="arg">opts</code> is a mapping of names and target values.</p>
<div class="desc">
This method allows you to initiate gradual transitions of values in the <code>.data</code>
object of a given <code>Node</code>. For instance consider a node whose <code>.data</code>
object looks like:
</div>
<p class="code">{color:"#00ff00", radius:1}</p>
<div class="desc">
The following call will make this node quadruple in size and change color to light blue
over the course of 3 seconds:
</div>
<p class="code">sys.tweenNode(myNode, 3, {color:"cyan", radius:4})</p>
<div class="desc">
The system can handle tweening numerical values or colors which are expressed as either
named <b>CSS</b> colors or hex strings beginning with a “<code>#</code>”.
</div>
<div class="desc">
There is also a pair of ‘magic’ keys that can be included in the <code class="arg">opts</code>
argument to modify the tween behavior. <code>delay</code> specifies the time
in seconds before the tween should begin. <code>ease</code> can be set to
one of the names seen in the <code>src/easing.js</code> file to control the dynamics
of the transition.
</div>
<div class="desc">
<div class="bang">!</div>
Note that the tween methods are disabled unless you include the <code>arbor-tween.js</code>
file in your page.
</div>
<hr>
</dd>
<dt>tweenEdge<em>(edge, duration, opts)</em></dt>
<dd>
<p><code class="arg">edge</code> is the <code>Edge</code> whose values you wish
to tween.</p>
<p><code class="arg">duration</code> is the time (in seconds) the transition should last.</p>
<p><code class="arg">opts</code> is a mapping of names and target values.</p>
<div class="desc">
Identical in behavior to <code>.tweenNode</code> except that it operates on the <code>.data</code>
attribute of an <code>Edge</code> instead of a <code>Node</code>.
</div>
<div class="desc">
<div class="bang">!</div>
Note that the tween methods are disabled unless you include the <code>arbor-tween.js</code>
file in your page.
</div>
<hr>
</dd>
</dl>
<div class="sect">datastructures</div>
<h1>Node</h1>
<div class="lead-in">
<p>Node objects encapsulate the current physics state of a point in the particle
system as well as giving you a place to attach associated non-physics metadata.</p>
<a href="#" class="more">creation & use…</a>
<h2><a href="#">×</a> creation</h2>
<p>New nodes are created through the particle system’s <code>.addNode</code> method. For
example:</p>
<p class="code">
sys = arbor.ParticleSystem()<br>
node = sys.addNode("mynode", {mass:2, myColor:"goldenrod"})
</p>
<p>This will create a new <code>Node</code> object with a <code>.data</code> field
containing <code>{myColor:"goldenrod"}</code>. Note that the mass value was stripped
out of the data object and used for the node’s mass in the simulation. </p>
<p style="margin-top:1em;">The ‘magic’
variables you can use in this way (and their defaults):
</p>
<ul>
<li><em style="width:30px;">mass </em><b>1.0</b> the node’s resistance to movement and repulsive power</li>
<li><em style="width:30px;">fixed </em><b>false</b> if true, the node will be unaffected by other particles</li>
<li><em style="width:30px;">x </em><b>auto</b> the starting x position (in system coordinates)</li>
<li><em style="width:30px;">y </em><b>auto</b> the starting y position (in system coordinates)</li>
</ul>
<h2>using nodes</h2>
<p>With each tick of the simulation the values in <code>.p</code> will be updated based on
the repulsion and spring forces in the system. To alter the node’s properties (in response
to, say, a mouse click), simply reset its values and the system will use the new values
in its next tick:</p>
<p class="code">
console.log( node.p.x, node.p.y )<br>
>> 1.2, 0.4<br>
<br>
node.p = arbor.Point(1, 1)<br>
console.log( node.p.x, node.p.y )<br>
>> 1, 1<br>
<br>
node.p.y = 13<br>
console.log( node.p.x, node.p.y )<br>
>> 1, 13<br>
</p>
<p style="margin-top:1em;">Each node contains an attribute called <code>.data</code> whose contents
and use are entirely up to you. Typically it is used for storing metadata about
the node so your rendering code can know how to draw it, what its label text
should be, which url to go to on click, etc.</p>
<!-- <hr> -->
</div>
<h2>system values</h2>
<dl class="datastructure">
<dt>name</dt><dd>String (read only)</dd><br>
<dt>mass</dt><dd>Number</dd><br>
<dt>fixed</dt><dd>Boolean</dd><br>
<dt>p</dt><dd>Point</dd>
</dl>
<h2>user values</h2>
<dl class="datastructure">
<dt>data</dt><dd><code>{ … }</code></dd>
</dl>
<h1>Edge</h1>
<div class="lead-in">
<p>Edge objects hold references to the source and target nodes they connect and have
a preferred ‘resting’ length. They will apply forces on their endpoint nodes in an
attempt to attain this optimal distance.</p>
<a href="#" class="more">creation & use…</a>
<h2><a href="#">×</a> creation</h2>
<p>New edges are created through the particle system’s <code>.addEdge</code> method. For
example:</p>
<p class="code">
sys = arbor.ParticleSystem()<br>
node1 = sys.addNode("one node")<br>
node2 = sys.addNode("another")<br>
edge = sys.addEdge(node1, node2, {length:.75, pointSize:3})
</p>
<p>This creates a pair of <code>Node</code> objects then creates an <code>Edge</code> from
the first to the second. The <code>length</code> key is a special variable that will be
used for setting the edge’s resting length. Any other keys in the object passed to
<code>.addEdge</code> will be placed in the resulting <code>Edge</code>’s <code>.data</code>
attribute.</p>
<p style="margin-top:1em;">Note that <code>.addEdge</code> can be called with either actual
<code>Node</code> objects or simply their <code>.name</code>s as arguments. If a name is
used but a node with that identifier does not yet exist, the system will automatically create
one before creating the edge. For instance, the above code could be simplified to:
</p>
<p class="code">
sys = arbor.ParticleSystem()<br>
edge = sys.addEdge("one node", "another", {length:.75, pointSize:3})
</p>
</div>
<h2>system values</h2>
<dl class="datastructure">
<dt>source</dt><dd>Node</dd><br>
<dt>target</dt><dd>Node</dd><br>
<dt>length</dt><dd>Number</dd>
</dl>
<h2>user values</h2>
<dl class="datastructure">
<dt>data</dt><dd><code>{ … }</code></dd>
</dl>
<h1>Point</h1>
<div class="lead-in">
<p>Point objects are simple containers for x/y coordinates bundled together
with handy methods for doing vector calculations. Create points by calling
<code>arbor.Point(x, y)</code>.</p>
</div>
<h2>coordinate data</h2>
<dl class="datastructure">
<dt>x</dt><dd>Number</dd><br>
<dt>y</dt><dd>Number</dd>
</dl>
<h2>vector math</h2>
<dl>
<dt>add<em>(pt) → Point</em></dt>
<dd>Returns a new Point with the sum of the two points.</dd>
<dt>subtract<em>(pt) → Point</em></dt>
<dd>Returns a new Point with the difference of the two points.</dd>
<dt>multiply<em>(n) → Point</em></dt>
<dd>Returns a linearly scaled copy of the original point.</dd>
<dt>divide<em>(n) → Point</em></dt>
<dd>Returns a linearly scaled copy of the original point.</dd>
<dt>magnitude<em>( ) → Number</em></dt>
<dd>Returns the point’s distance from the origin.</dd>
<dt>normal<em>( ) → Point</em></dt>
<dd>Returns the point’s vector normal.</dd>
<dt>normalize<em>( ) → Point</em></dt>
<dd>Returns a scaled copy of the point with a magnitude of one.</dd>
</dl>
<h2>sanity checking</h2>
<dl>
<dt>exploded<em>( ) → Boolean</em></dt>
<dd>Returns <code>true</code> if x or y is NaN.</dd>
</dl>
</div>
</div>
<script type="text/javascript" src="../demos/_/jquery-1.6.1.min.js" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
var Nav = function(elt){
var dom = $(elt)
var that = {
init:function(){
$('.more').one('click',that.more)
$('#docs dl:not(.datastructure) dt').click(that.reveal)
$('#docs dl:not(.datastructure) em').click(that.reveal)
return that
},
more:function(e){
$(this).removeAttr('href').addClass('less').html(' ').siblings().fadeIn()
$(this).next('h2').find('a').one('click', that.less)
return false
},
less:function(e){
var more = $(this).closest('h2').prev('a')
$(this).closest('h2').prev('a')
.nextAll().fadeOut(function(){
$(more).text('creation & use').removeClass('less').attr('href','#')
})
$(this).closest('h2').prev('a').one('click',that.more)
return false
},
reveal:function(e){
$(e.target).next('dd').fadeToggle('fast')
return false
}
}
return that.init()
}
nav = Nav("#nav")
</script>
</body>
</html>