/
api.html
1363 lines (1190 loc) · 74.8 KB
/
api.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
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Algorithm Visualization (JSAV) API documentation</title>
<link rel="stylesheet" href="apidoc.css" >
</head>
<body>
<h1>Documentation for the JavaScript Algorithm Visualization API (JSAV) Version 0.7dev</h1>
<p class="note">
This documentation reflects the current status of the library.
It is a work-in-progress and subject to change!
</p>
<h1>Contents</h1>
<ol id="toc"></ol>
<h2>Loading the Required Files</h2>
<p>
The easiest way to check the required files is to look at
the examples directory and copy one of those files as a template for
your new AV.
</p>
<p>
If done manually, the files required (in this order) are as follows.
Note that <code>[JSAV]</code> refers to the relative position of the
JSAV library directory, which depends on where you are developing from.
</p>
<ul>
<li>jquery.transform: <code>[JSAV]/lib/jquery.transform.light.js</code></li>
<li>Raphael: <code>[JSAV]/lib/raphael.js</code></li>
<li>The library: Either <code>[JSAV]/build/jsav.js</code> or
<code>[JSAV]/build/jsav-min.js</code>.
This must always be included.</li>
</ul>
</p>
<p>
The main jQuery library must always be loaded.
jQuery UI and jquery.transform are only needed when you use the
library to show animations, such as using the data structures or
graphical primitives and modifying them. In other words, using
any other part of the library than the messaging API. Raphael is
only needed when using graphical primitives like circles and
rectangles or when using data structures with edges.
</p>
<p>
In addition, developers must include the supporting .css file:
<code>[JSAV]/css/JSAV.css</code>
</p>
<h2>HTML Template for the Visualization</h2>
<p>
Visualizations generally include two parts:
HTML DOM elements, and JavaScript elements.
The HTML section typical includes something like this:
</p>
<pre>
<div id="container">
<div class="jsavcontrols"></div>
<p class="jsavoutput jsavline"></p>
</div>
</pre>
<dl>
<dt><code>container</code></dt>
<dd>This is the container element for the visualization</dd>
<dt><code>jsavcontrols</code></dt>
<dd>The library will generate slideshow controls inside this
element if your visualization uses the slideshow API</dd>
<dt><code>jsavoutput</code></dt>
<dd>The area where the messages from the
visualization will be displayed to the user.
Type can further be specified using either
class <code>jsavline</code> or <code>jsavscroll</code>.
See the Messages API for more details.</dd>
</dl>
<h2>Creating A Visualization</h2>
<p>Initializing the visualization container is simple:</p>
<pre>var av = new JSAV("container");</pre>
<p>The <code>container</code> here refers to the id attribute of the
container element (see the HTML template above).
Alternatively, a DOM or jQuery element can be
used as well. So, the following are alternative ways to achieve
the same result:</p>
<pre>var av = new JSAV(document.getElementById("container"));
var av = new JSAV(jQuery("#container"));</pre>
<p>Both alternatives accept an optional second parameter <code>options</code>
which should be a JavaScript object. The options that are currently
supported:</p>
<dl>
<dt><code>title</code></dt>
<dd>Title of the AV. This will be shown as the first slide of the
slideshow.</dd><br/>
<dt><code>animationMode</code></dt>
<dd>Use "none" to turn off animation (slideshow) mode.</dd>
</dl>
<p>In addition to the options passed to the function, any options specified
in a global variable <code>JSAV_OPTIONS</code> will be used. Those passed on
initialization always override the global options.</p>
<h2>Slideshow Support</h2>
<p>A slideshow is created by using a series of calls to the
<code>.step()</code> method.
Associated with each step, you use method calls to define or show
the appropriate data structures and UI elements along with any
actions to take place (such as swapping elements in an array or
highlighting an element).</p>
<h3 class="apimethod">.step()</h3>
<p>Marks that a new step in the animation will start. Basically,
everything within one step will be animated simultaneously when
moving backward and forward.</p>
<p>
<b>Returns:</b> A JSAV object. Thus, this method may be chained with,
for example, the <code>umsg</code> method.
</p>
<h3 class="apimethod">.recorded()</h3>
<p>
A call to this method is placed at the end of the series of
<code>.step()</code> method calls to start the slideshow.
</p>
<h3 class="apimethod">.displayInit()</h3>
<p>Marks the current state of the visualization as the state where the
animation will start. That is, what will be displayed initially.</p>
<p>
<b>Returns:</b> A JSAV object. Thus, this method may be chained.</p>
<h3 class="apimethod">.animInfo()</h3>
<p>
This will return an object that has two properties: number of slides
and and number of effects.
It might be better used when called from somewhere like the FireBug
command line than in an actual AV implementation.
It can help a developer to optimize the complexity of the slideshow.
<h3>The <code>counter</code> element</h3>
<p>
A slideshow counter showing the position in slideshow (e.g. 2/120) can
be added by including a DOM element with class <code>jsavcounter</code>
inside the <code>container</code>.
For example, you can add
<code><span class="jsavcounter"></span></code> to some DOM element
to attach the counter.
</p>
<h3>Controlling Animation Outside of JSAV</h3>
<p>Sometimes you might want to control a JSAV animation from JavaScript
and not through the JSAV generated UI. There are two ways to do this:</p>
<ol>
<li>A JSAV instance has functions <code>.begin()</code>, <code>.backward()</code>,
<code>.forward()</code> and <code>.end()</code> that can be called to move in
the animation.</li>
<li>You can trigger events on the <code>container</code> element to have
JSAV move in the animation. The events are: <code>jsav-begin</code>,
<code>jsav-backward</code>, <code>jsav-forward</code>, and
<code>jsav-end</code>. For example, to move a step forward in the animation,
one could write <code>$(".jsavcontainer").trigger("jsav-forward")</code>.
Note, that this example moves <em>all</em> JSAV animations on the page one
step forward.</li>
</ol>
<h2>Messages API</h2>
<p>
The Messages API allows the user to control the contents of the output
message buffer intended for informing the user about the state of the
visualization or for providing directions.</p>
<p>
The output buffer will have been specified in the HTML section of the
document. It is defined as an empty paragraph of class
<code>jsavoutput</code>, with one of the following class options.
</p>
<p>
<code>class="jsavoutput jsavline"</code> indicates a small "line-style"
message buffer where typically each line overwrites the previous one.
</p>
<p>
<code>class="jsavoutput jsavscroll"</code> indicates a visible textbox with a
scrollbar. The textbox is only cleared when explicitly directed by a
<code>.clearumsg()</code> call.
Since this acts as a normal HTML paragraph,
optional standard parameters can be used such as
<code>readonly="readonly"</code> to make
the textbox unwriteable by the user, or to
override the default height and width.
</p>
<h3 class="apimethod">.umsg(msg[, options])</h3>
<p>
Add the given message <code>msg</code> to the message
output. The optional <code>options</code> parameter
can be an object whose properties specify the
behavior. The <code>color</code> property is used (when
present) to change the color of the message.
Use would look something like:
</p>
<pre>
av.umsg("My message here", {"color": "blue"});
</pre>
<p>
When "line-style" message buffer is used, option
<code>"preserve": true</code> can be used to append the new message
after the previous one instead of clearing the buffer.
</p>
<p>
Since the
<code>msg</code> is output as standard HTML, the style of
the message text can also be controlled by using HTML commands.
</p>
<p>
<b>Returns:</b> A JSAV object. Thus, this method may be chained with,
for example, the <code>step</code> method.
</p>
<h3 class="apimethod">.clearumsg()</h3>
<p>Clear the contents of the output message buffer.</p>
<h2>Array Data Structure API</h2>
<p>
JSAV will ultimately provide layout support for a number of standard
data structures. Presently, arrays, trees, and lists are supported.
</p>
<h3 class="apimethod">.ds.array(element[, options]) and
.ds.array(Array[, options])</h3>
<p>
An array can be created using the .ds.array method on a JSAV instance.
It takes one parameter indicating either a DOM/jQuery Element
(ul or ol) or a JavaScript Array.
For example, to initialize and add to the visualization an array with
four elements:</p>
<pre>var arr = av.ds.array([10, 13, 99, 25]);</pre>
<p>
Array indexing begins at zero.
</p>
<p>The returned array instance is controlled through a collection of
methods explained next. Note that changes to the array contents must
go through this API (using the <code>.value</code> method),
since the array contents must be managed by
JSAV rather than by the developer.
</p>
<p>Options that the second, optional, parameter can specify:</p>
<ul>
<li>layout: Defines choices of layout (<code>bar</code> for bars, <code>vertical</code> to show the array vertically, the
default is to show a horizontal array).</li>
<li>indexed: Boolean to determine if array indices are shown or not.</li>
<li>visible: Boolean to determine if initially the array is shown or
not. Default true.</li>
<li>center: Boolean to determine if array should be automatically centered
within its container. Defaults to true.</li>
<li>left/top/right/bottom: Values to determine the absolute position of the array relative to its container.</li>
<li>relativeTo: A JSAV data structure object or DOM element that this structure should be positioned relative to.
If this option is specified, left and top options will change structure's position relative to the relativeTo
element. Note, that the element pointed by relativeTo needs to be visible.</li>
<li>anchor: Defines which position on the element being positioned to align with the target element. Should be in
format <code>horizontal vertical</code>. Possible horizontal values are "left", "center", "right" and vertical values "top", "center", "bottom". Defaults to <code>center center</code>. Only has an effect if relativeTo is
specified.</li>
<li>myAnchor: Similar to anchor, but the position on this element. Defaults to <code>center center</code>. Only
has an effect if relativeTo is specified.</li>
<li>relativeIndex: If relativeTo points to a JSAV array, this option can be used to position this structure relative
to an index in that array. Only has an effect if relativeTo is specified.</li>
</ul>
<h3 class="apimethod">.clone()</h3>
<p>
Create and return a clone of an array.
The clone will remain invisible until the <code>show</code>
method is called on it.
</p>
<h3 class="apimethod">.css(indices, cssPropertyName)</h3>
<p>Returns the value of CSS property <code>cssPropertyName</code> for the first
index matching the <code>indices</code> parameter. Parameter <code>indices</code>
can be a number, array, <code>true</code>, or function like for
the <code>highlight</code> method.</p>
<h3 class="apimethod">.css(indices, css)</h3>
<p>
Apply the given CSS properties to the specified <code>indices</code>.
Parameter <code>indices</code> can be a number, array,
<code>true</code>, or function like for the <code>highlight</code>
method.
When <code>indices</code> is <code>true</code>, then <code>css</code>
is applied to all elements of the array.
The argument <code>css</code> should be an object with property
name-and-value pairs.
For example, to make positions 0 and 4 have green color and lightgray
background:
</p>
<pre>
arr.css([0, 4], {"color": "green", "background-color": "#eee"});
</pre>
<p>
<b>Returns:</b> a JSAV array object. Thus, this method can be chained.
</p>
<h3 class="apimethod">.css(cssPropertyName)</h3>
<p>Returns the value of CSS property <code>cssPropertyName</code> for the array.</p>
<h3 class="apimethod">.css(css)</h3>
<p>
Apply the given CSS properties to the array element.
The argument <code>css</code> should be an object with property
name-and-value pairs. For example, to move the array 20 pixels to the right:
</p>
<pre>
arr.css({"left": "+=20px"});
</pre>
<h3 class="apimethod">.hide()</h3>
<p>
Make the array invisible.
</p>
<h3 class="apimethod">.highlight()</h3>
<p>
Call to <code>highlight</code> without any parameters will highlight
all elements in the array.
Note that this will only apply the color and background-color of CSS class
<code>jsavhighlight</code> to the array elements.
It is up to the author to make sure the loaded CSS files include such
styling.
</p>
<p>
<b>Returns:</b> a JSAV array object. Thus, this method can be chained.
</p>
<h3 class="apimethod">.highlight(number)</h3>
<p>
Highlight the given index number.
</p>
<h3 class="apimethod">.highlight(indexlist)</h3>
<p>
Highlight the indices in the given <code>indexlist</code>.
For example, the following would highlight array positions 1, 2, and 5.
</p>
<pre>arr.highlight([1, 2, 5]);</pre>
<h3 class="apimethod">.highlight(function)</h3>
<p>
Highlights all the indices that the passed function returns true.
For example, to highlight all even indices:</p>
<pre>arr.highlight(function(index) { return index%2==0; });</pre>
<h3 class="apimethod">.highlight(boolean)</h3>
<p>
If the given boolean value is <code>true</code>, all the indices are highlighted.
If <code>false</code>, none are.
For example, to highlight all indices:</p>
<pre>arr.highlight(true);</pre>
<h3 class="apimethod">.show()</h3>
<p>
Make the array visible.
</p>
<h3 class="apimethod">.size()</h3>
<p>
Returns the size of the array.
For the array defined in the array creation example above,
the following would return 4:
</p>
<pre>arr.size();</pre>
<h3 class="apimethod">.swap(index1, index2)</h3>
<p>Swaps the contents (and graphics state) of the two array positions.</p>
<h3 class="apimethod">.unhighlight(indices)</h3>
<p>
Removes the highlight from the given <code>indices</code>.
There are corresponding versions of this function with parameters like
for highlight.
</p>
<p>
<b>Returns:</b> a JSAV array object. Thus, this method can be chained.
</p>
<h3 class="apimethod">.value(index)</h3>
<p>Returns the value of the element at the given index.</p>
<h3 class="apimethod">.value(index, newValue)</h3>
<p>
Sets the value of the element at the given index to the given value.
</p>
<h3 class="apimethod">.toggleLine(index, [options])</h3>
<p>Toggles a marker line above a given array index for bar layout. For other layouts, does nothing. Options that can be passed:</p>
<ul>
<li><code>markStyle</code>: Style of the "ball" as an object of CSS property/value pairs. Default style is first applied, then the given style. Passing <code>null</code> will disable the ball altogether.</li>
<li><code>lineStyle</code>: Style of the line. Works similarly to <code>markStyle</code>.</li>
<li><code>startIndex</code>: Index in the array where the line will start. Default 0.</li>
<li><code>endIndex</code>: Index in the array where the line will end, inclusive. Defaults to last index of the array.</li>
</ul>
<h3 class="apimethod">.isEmpty()</h3>
<p>Returns true if the array is empty.</p>
<h3 class="apimethod">.addClass(index, className, [options])</h3>
<p>Adds the CSS class <code>className</code> to given indices and animates the changes. Like for
the rest of array methods, <code>index</code> can be a number, array of numbers, or a function.</p>
<h3 class="apimethod">.removeClass(index, className, [options])</h3>
<p>Removes the CSS class <code>className</code> to given indices and animates the changes. Like for
the rest of array methods, <code>index</code> can be a number, array of numbers, or a function.</p>
<h3 class="apimethod">.toggleClass(index, className, [options])</h3>
<p>Toggles the CSS class <code>className</code> to given indices and animates the changes. Like for
the rest of array methods, <code>index</code> can be a number, array of numbers, or a function.</p>
<h3 class="apimethod">.hasClass(index, className, [options])</h3>
<p>Return true/false based on if the given index has the CSS class <code>className</code>. Parameter
<code>index</code> should be a number.</p>
<h3 class="apitopic">Events</h3>
<p>There are functions to attach event handlers for the array elements. The events that can be
listened for are: click, dblclick, mousedown, mousemove, mouseup, mouseenter, and mouseleave.
See <a href="http://api.jquery.com/category/events/">jQuery documentation</a> for details on
the events. Every event handler gets as a first parameter the index of the array element that
the event was triggered for. The last parameter is the jQuery event object. Inside the event
handler function, <code>this</code> will refer to the JSAV array object. </p>
<p><b>Returns:</b> a JSAV array object. Thus, this method can be chained.</p>
<p>Example to toggle arrow on click of an element:</p>
<pre>arr.click(function(index) {
this.toggleArrow(index);
});</pre>
<p>Since many of the JSAV array functions take the index as the first parameter, they can be used
as event handlers. For example, to highlight an index on mouseenter and unhighlight on mouseleave,
you can use:</p>
<pre>arr.mouseenter(arr.highlight).mouseleave(arr.unhighlight);</pre>
<p>You can also pass custom arguments to the event handler function. To do this, the first argument
to the event binding function should be an array of parameters that will be passed as parameters to
the event handler function. This is best explained with an example:</p>
<pre>arr.mouseenter([{"color": "red"}], arr.css).mouseleave([{"color": "black"}], arr.css);</pre>
<p>This will use array's <code>css</code> function as the event handler and pass it another parameter
when the event is triggered. On mouse enter, the function call will essentially be:
<code>arr(index, {"color": "red"}, e)</code>. Here, <code>e</code> is again the jQuery event object.</p>
<h3 class="apimethod">.on(eventName, [data,], handler)</h3>
<p>To bind other events than the ones listed above, you can use the <code>on</code> function. It takes
as the first parameter the name of the event. Multiple events can be bound by separating their names with
spaces. Other parameters are the same as for the shortcuts.</p>
<h3 class="apitopic">CSS control</h3>
There are various options and style effects that can be controlled via
CSS.
<h3 class="apimethod">width and height</h3>
<p>By default, array elements are at minimum 45 pixels wide and will automatically expand if the content
is wider than that. Width and height can be controlled with the width/height CSS properties. Example:</p>
<pre>
.jsavarray .jsavindex {
width: 60px;
}
</pre>
<p>Note, that JSAV has specified <code>min-width</code> for array indices to be 45 pixels. If you want to
make the indices smaller than that, you will also need to specify the <code>min-width</code> property. For
example, to make indices 20px wide:<p>
<pre>
.jsavarray .jsavindex {
width: 20px;
min-width: 20px;
}
</pre>
<p>If you change the height of array elements, you should probably also change the line-height of the text inside. Example:</p>
<pre>
.jsavarray .jsavindex {
height: 20px;
min-height: 20px;
line-height: 20px
}
</pre>
<h3 class="apitopic">Extending the Array</h3>
<p class="todo">
Example of extending to provide .opacity(indices, value) function as a
shortcut to set the opacity of indices.
</p>
<h2>Tree Data Structure API</h2>
<p>
Currently, JSAV supports two types of trees: common tree and binary tree. The structures form a "class" hierarchy: Tree ← Binary Tree and TreeNode ← BinaryTreeNode.
</p>
<h3 class="apimethod">.ds.tree([options]) and .ds.bintree([options])</h3>
<p>These functions of a JSAV instance initialize a new tree or binary tree. The returned tree instance is controlled through a collection of methods explained next.</p>
<p>Options that the optional parameter can specify:</p>
<ul>
<li>layout: Defines choices of layout (currently only the default layout is supported).</li>
<li>visible: Boolean to determine if initially the tree is shown or
not. Default true.</li>
<li>center: Boolean to determine if tree should be automatically centered
within its container. Defaults to true.</li>
<li>left/top/right/bottom: Values to determine the absolute position of the tree relative to its container.</li>
<li>nodegap: Number to specify how big the gap between nodes in the tree should be. Defaults to 40.</li>
<li>relativeTo: A JSAV data structure object or DOM element that this structure should be positioned relative to.
If this option is specified, left and top options will change structure's position relative to the relativeTo
element. Note, that the element pointed by relativeTo needs to be visible.</li>
<li>anchor: Defines which position on the element being positioned to align with the target element. Should be in
format <code>horizontal vertical</code>. Possible horizontal values are "left", "center", "right" and vertical values "top", "center", "bottom". Defaults to <code>center center</code>. Only has an effect if relativeTo is
specified.</li>
<li>myAnchor: Similar to anchor, but the position on this element. Defaults to <code>center center</code>. Only
has an effect if relativeTo is specified.</li>
<li>relativeIndex: If relativeTo points to a JSAV array, this option can be used to position this structure relative
to an index in that array. Only has an effect if relativeTo is specified.</li>
</ul>
<h3 class="apimethod">.css(propertyName)</h3>
<p>Returns the value for the given CSS property. This function exists for all trees, nodes, and edges.</p>
<h3 class="apimethod">.css(propertyName, value)</h3>
<p>Animates the value of the given CSS property to value. This function exists for all trees, nodes, and edges.</p>
<h3 class="apimethod">.css({map})</h3>
<p>Animates values of the CSS properties in the map to the given values. This function exists for all trees, nodes, and edges. For example</p>
<pre>
tree.css({color: "green", "font-size": "20px"});
</pre>
<p>would animate the color and font-size properties of the tree.</p>
<h3 class="apimethod">.id([newId])</h3>
<p>Returns the ID of the structure. If optional parameter <var>newId</var> is given, sets the ID of the structure. The given ID should be unique. This function exists for all trees, nodes, and edges.</p>
<h3 class="apimethod">.root([node])</h3>
<p>Returns the root of this tree. If the optional <var>node</var> parameter is given, the root of the tree is set. This function exists for all trees.</p>
<h3 class="apimethod">.newNode(value)</h3>
<p>Creates a new node that can be added to this tree. "Subclasses" override this to create nodes suited for the tree, so this method should be used when creating new nodes. This function exists for all trees.</p>
<h3 class="apimethod">.height()</h3>
<p>Returns the height of the tree. This function exists for all trees</p>
<h3 class="apimethod">.layout()</h3>
<p>This function (re)calculates the layout for the tree. Note, that the library does not do this automatically. That means that after changing the tree, you should call this manually at the end of each animation step. This function exists for all trees.</p>
<h3 class="apimethod">.hide([options])</h3>
<p>Make the tree invisible. This function exists for all trees. It recursively hides all the nodes and edges in the tree as well unless
option <code>recursive</code> is set to <code>false</code>.</p>
<h3 class="apimethod">.show([options])</h3>
<p>Make the tree visible.This function exists for all trees. It recursively shows all the nodes and edges in the tree as well unless
option <code>recursive</code> is set to <code>false</code>.</p>
<h3 class="apimethod">.addClass(className, [options])</h3>
<p>Adds the CSS class <code>className</code> to the tree and animates the changes.</p>
<h3 class="apimethod">.removeClass(className, [options])</h3>
<p>Removes the CSS class <code>className</code> from the tree and animates the changes.</p>
<h3 class="apimethod">.toggleClass(className, [options])</h3>
<p>Toggles the CSS class <code>className</code> to the tree and animates the changes.</p>
<h3 class="apimethod">.hasClass(className, [options])</h3>
<p>Return true/false based on if the tree has the CSS class <code>className</code>.</p>
<h3 class="apitopic">Events</h3>
<p>There are functions to attach event handlers for the nodes and edges in the tree. The events
that can be
listened for are: click, dblclick, mousedown, mousemove, mouseup, mouseenter, and mouseleave.
See <a href="http://api.jquery.com/category/events/">jQuery documentation</a> for details on
the events. Every event handler gets as a parameter the jQuery event object. Inside the event
handler function, <code>this</code> will refer to the JSAV node or edge object. </p>
<p>The function takes another, optional, parameter options that should be an object. It can be
used to specify whether
the event handler is for nodes or edges. By default, it is attached to only nodes.
<p><b>Returns:</b> a JSAV tree object. Thus, this method can be chained.</p>
<p>For example, to highlight an node on mouseenter and unhighlight on mouseleave,
you can use:</p>
<pre>tree.mouseenter(function() { this.highlight(); })
.mouseleave(function() { this.unhighlight(); });</pre>
<p>To attach a handler to edges, you can do:</p>
<pre>tree.mouseenter(yourEventHandler, {edge: true});</pre>
<p>Similarly to arrays, you can also pass custom data to the handler. For example,
<code>bt.click({"color": "blue"}, JSAV.utils._helpers.css);</code> would call the <code>css</code>
function with the given parameter. </p>
<h3 class="apimethod">.on(eventName, [data,], handler, options)</h3>
<p>To bind other events than the ones listed above, you can use the <code>on</code> function. It takes
as the first parameter the name of the event. Multiple events can be bound by separating their names with
spaces. Other parameters are the same as for the shortcuts.</p>
<h2>Tree Node API</h2>
<p>The following functions exist for both tree nodes and binary tree nodes.</p>
<h3 class="apimethod">.value([newValue])</h3>
<p>Returns the value stored in this node. If the optional <var>newValue</var> parameter is given, the value is set to the given value.</p>
<h3 class="apimethod">.parent([newParent])</h3>
<p>Returns the parent node of this node. If the optional <var>newParent</var> parameter is given, the parent node is set.</p>
<h3 class="apimethod">.edgeToParent([newEdge])</h3>
<p>Returns the edge that connects this node to its parent. If the optional <var>newEdge</var> parameter is given, the edge to parent is set.</p>
<h3 class="apimethod">.edgeToChild(pos)</h3>
<p>Returns the edge that connects this node to its child at <var>pos</var>. Returns <code>undefined</code> is no such child exists.</p>
<h3 class="apimethod">.child(pos)</h3>
<p>Returns the <var>pos</var>:th child of this node.</p>
<h3 class="apimethod">.child(pos, node [,options])</h3>
<p>Sets the <var>pos</var>:th child to the given value. The <var>node</var> can be a value or a node of correct type to the node. If value <code>null</code> is given as <code>node</code>, the child at that position is removed. Note, that this also hides the removed node and the edge.</p>
<p>The optional third argument <code>options</code> should be an object. The following option(s) are supported:</p>
<ul>
<li><code>edgeLabel</code>: specify a label shown on the edge connecting the new node to its parent.</li>
</ul>
<h3 class="apimethod">.addChild(node [,options])</h3>
<p>Adds a child node to this node. The <var>node</var> can be a value or a node of correct type to the node.
The <code>options</code> parameter works like above.</p>
<h3 class="apimethod">.remove([options])</h3>
<p>Removes the node from its parent.</p>
<h3 class="apimethod">.hide([options])</h3>
<p>Hides the node and the edge connecting it to the parent node. Also recursively hides all child nodes unless
option <code>recursive</code> is set to <code>false</code>.</p>
<h3 class="apimethod">.show([options])</h3>
<p>Shows the node and the edge connecting it to the parent node. Also recursively shows all child nodes unless
option <code>recursive false</code> is set to <code>false</code>. Note, that if the tree is not visible, showing nodes will not have
any effect until the tree is set visible by calling show.</p>
<h3 class="apimethod">.addClass(className, [options])</h3>
<p>Adds the CSS class <code>className</code> to the node and animates the changes.</p>
<h3 class="apimethod">.removeClass(className, [options])</h3>
<p>Removes the CSS class <code>className</code> from the node and animates the changes.</p>
<h3 class="apimethod">.toggleClass(className, [options])</h3>
<p>Toggles the CSS class <code>className</code> of the node and animates the changes.</p>
<h3 class="apimethod">.hasClass(className, [options])</h3>
<p>Return true/false based on if the node has the CSS class <code>className</code>.</p>
<h2>Binary Tree Node API</h2>
<h3 class="apimethod">.left([node [, options]])</h3>
<p>Returns the left child or undefined if node has no left child. If optional parameter <var>node</var> is given, sets the left child. The parameter can be a value or a binary tree node. If value <code>null</code> is given as <code>node</code>, the left child is removed. Note, that this also hides the removed node and the edge.
The additional <code>options</code> parameter works like for <code>.child(...)</code> above. </p>
<h3 class="apimethod">.right([node [,options]])</h3>
<p>Returns the right child or undefined if node has no right child. If optional parameter <var>node</var> is given, sets the right child. The parameter can be a value or a binary tree node. Passing <code>null</code> as node works similarly to the left function. The additional <code>options</code> parameter works like for <code>.child(...)</code> above.</p>
<h3 class="apimethod">.edgeToLeft()</h3>
<p>Returns the edge that connects this node to its left child. Returns <code>undefined</code> is node has no left child.</p>
<h3 class="apimethod">.edgeToRight()</h3>
<p>Returns the edge that connects this node to its right child. Returns <code>undefined</code> is node has no right child.</p>
<h2>Edge structure API</h2>
<h3 class="apimethod">.start([node])</h3>
<p>Returns the start node of this edge. If the optional <var>node</var> parameter is given, sets the start node of this edge.</p>
<h3 class="apimethod">.end([node])</h3>
<p>Returns the end node of this edge. If the optional <var>node</var> parameter is given, sets the end node of this edge.</p>
<h3 class="apimethod">.label()</h3>
<p>Returns the label attached to this edge.</p>
<h3 class="apimethod">.label(newLabel)</h3>
<p>Sets the value of the label attached to this edge.</p>
<h2>Linked List API</h2>
<h3 class="apimethod">.ds.list([options])</h3>
<p>This function of a JSAV instance initializes an empty linked list. Options that the optional parameter can specify:</p>
<ul>
<li>layout: Defines choices of layout (currently only the default layout is supported).</li>
<li>visible: Boolean to determine if initially the list is shown or not. Default true.</li>
<li>center: Boolean to determine if list should be automatically centered within its container. Defaults to true.</li>
<li>left/top/right/bottom: Values to determine the absolute position of the list relative to its container.</li>
<li>nodegap: Number to specify how big the gap between nodes in the list should be. Defaults to 40.</li>
<li>relativeTo: A JSAV data structure object or DOM element that this structure should be positioned relative to.
If this option is specified, left and top options will change structure's position relative to the relativeTo
element. Note, that the element pointed by relativeTo needs to be visible.</li>
<li>anchor: Defines which position on the element being positioned to align with the target element. Should be in
format <code>horizontal vertical</code>. Possible horizontal values are "left", "center", "right" and vertical values "top", "center", "bottom". Defaults to <code>center center</code>. Only has an effect if relativeTo is
specified.</li>
<li>myAnchor: Similar to anchor, but the position on this element. Defaults to <code>center center</code>. Only
has an effect if relativeTo is specified.</li>
<li>relativeIndex: If relativeTo points to a JSAV array, this option can be used to position this structure relative
to an index in that array. Only has an effect if relativeTo is specified.</li>
</ul>
<p>The returned list instance is controlled through a collection of methods explained next. In addition, the list has the common functions such as <code>.id()</code>, <code>.css(...)</code>, <code>.show()</code>, and <code>.hide()</code>.</p>
<h3 class="apimethod">.first() and last()</h3>
<p>Returns the first or last node in the list. If there are no nodes in the list, returns undefined.</p>
<h3 class="apimethod">.addFirst([value]) and .addFirst([node])</h3>
<p>Adds the given <code>value</code> or <code>node</code> as the first item in the list. Returns the list, so calls can be chained.</p>
<h3 class="apimethod">.addLast([value]) and .addLast([node])</h3>
<p>Adds the given <code>value</code> or <code>node</code> as the last item in the list. Returns the list, so calls can be chained.</p>
<h3 class="apimethod">.add(index, [value or node])</h3>
<p>Adds the given <code>value</code> or <code>node</code> to be the <code>index</code>th item in the list. The first item in the list has index 0. Returns the list, so calls can be chained.</p>
<h3 class="apimethod">.get(index)</h3>
<p>Returns the node at <code>index</code>. First item has index 0. If no such index exists, returns <code>undefined</code>.</p>
<h3 class="apimethod">.removeFirst() and .removeLast()</h3>
<p>Removes the first or last node in the list. Returns the removed node.</p>
<h3 class="apimethod">.remove(index)</h3>
<p>Removes the node at <code>index</code> in the list. First item has index 0. Returns the removed node.</p>
<h3 class="apimethod">.size()</h3>
<p>Returns the size of the list.</p>
<h3 class="apimethod">.layout([options])</h3>
<p>Positions the nodes and edges is the list.</p>
<h3 class="apimethod">.newNode(value [, options])</h3>
<p>Returns a new node that can be added to the list.</p>
<h3 class="apimethod">.addClass(className, [options])</h3>
<p>Adds the CSS class <code>className</code> to the list and animates the changes.</p>
<h3 class="apimethod">.removeClass(className, [options])</h3>
<p>Removes the CSS class <code>className</code> from the list and animates the changes.</p>
<h3 class="apimethod">.toggleClass(className, [options])</h3>
<p>Toggles the CSS class <code>className</code> of the list and animates the changes.</p>
<h3 class="apimethod">.hasClass(className, [options])</h3>
<p>Return true/false based on if the list has the CSS class <code>className</code>.</p>
<h3 class="apitopic">Events</h3>
<p>There are functions to attach event handlers for the nodes and edges in the list. The events
that can be listened for are: click, dblclick, mousedown, mousemove, mouseup, mouseenter, and mouseleave.
See the tree documentation for details.</p>
<h2>Linked List Node API</h2>
<p>A node in a list has the same functions as a tree node: <code>.value([newValue])</code>, <code>.highlight()/unhighlight()</code>, <code>.show()/.hide()</code>, and <code>.css(...)</code>. In addition, it has the following functions.</p>
<h3 class="apimethod">.next()</h3>
<p>Returns the next node in the linked list. If no next, returns null.</p>
<h3 class="apimethod">.next([node [, options]])</h3>
<p>Sets the next node to be the passed <code>node</code>. The optional second argument <code>options</code> should be an object. The following option(s) are supported:</p>
<ul>
<li><code>edgeLabel</code>: specify a label shown on the edge connecting the node to the next.</li>
</ul>
<h3 class="apimethod">.edgeToNext()</h3>
<p>Returns the JSAV Edge object that points to the next item in the list.</p>
<h3 class="apimethod">.addClass(className, [options])</h3>
<p>Adds the CSS class <code>className</code> to the node and animates the changes.</p>
<h3 class="apimethod">.removeClass(className, [options])</h3>
<p>Removes the CSS class <code>className</code> from the node and animates the changes.</p>
<h3 class="apimethod">.toggleClass(className, [options])</h3>
<p>Toggles the CSS class <code>className</code> of the node and animates the changes.</p>
<h3 class="apimethod">.hasClass(className, [options])</h3>
<p>Return true/false based on if the node has the CSS class <code>className</code>.</p>
<h2>Graph API</h2>
<h3 class="apimethod">.ds.graph([options])</h3>
<p>This function of a JSAV instance initializes an empty graph. Options that the optional parameter can specify:</p>
<ul>
<li>layout: Defines choices of layout (currently only the default layout is supported).</li>
<li>visible: Boolean to determine if initially the graph is shown or not. Default true.</li>
<li>center: Boolean to determine if graph should be automatically centered within its container. Defaults to true.</li>
<li>left/top/right/bottom: Values to determine the absolute position of the graph relative to its container.</li>
<li>relativeTo: A JSAV data structure object or DOM element that this structure should be positioned relative to.
If this option is specified, left and top options will change structure's position relative to the relativeTo
element. Note, that the element pointed by relativeTo needs to be visible.</li>
<li>anchor: Defines which position on the element being positioned to align with the target element. Should be in
format <code>horizontal vertical</code>. Possible horizontal values are "left", "center", "right" and vertical values "top", "center", "bottom". Defaults to <code>center center</code>. Only has an effect if relativeTo is
specified.</li>
<li>myAnchor: Similar to anchor, but the position on this element. Defaults to <code>center center</code>. Only
has an effect if relativeTo is specified.</li>
<li>relativeIndex: If relativeTo points to a JSAV array, this option can be used to position this structure relative
to an index in that array. Only has an effect if relativeTo is specified.</li>
<li>width: Width of the graph, in pixels. Defaults to 400.</li>
<li>height: Height of the graph, in pixels. Defaults to 200.</li>
<li>directed: Wether or not this graph is directed.</li>
</ul>
<p>The returned graph instance is modified through a collection of methods explained next. In addition, the graph has the common
functions such as <code>.id()</code>, <code>.css(...)</code>, <code>.show()</code>, and <code>.hide()</code>.</p>
<h3 class="apimethod">.addNode(value, [options])</h3>
<p>Adds a new node with <code>value</code> to the graph. Returns the new node.</p>
<h3 class="apimethod">.removeNode(node, [options])</h3>
<p>Removes the given <code>node</code>.</p>
<h3 class="apimethod">.addEdge(fromNode, toNode, [options])</h3>
<p>Adds edge from <code>fromNode</code> to <code>toNode</code>. Returns the new edge.</p>
<h3 class="apimethod">.removeEdge(fromNode, toNode, [options])</h3>
<p>Removes edge from <code>fromNode</code> to <code>toNode</code>.</p>
<h3 class="apimethod">.hasEdge(fromNode, toNode)</h3>
<p>Returns true if the graph has an edge from <code>fromNode</code> to <code>toNode</code>.</p>
<h3 class="apimethod">.getEdge(fromNode, toNode)</h3>
<p>Returns the Edge object connecting <code>fromNode</code> and <code>toNode</code>, or <code>undefined</code> if no such edge exists.</p>
<h3 class="apimethod">.nodes()</h3>
<p>Returns an iterable array of nodes in the graph. The returned structure can be used as a normal JavaScript array. In addition,
it has methods <code>.next()</code> and <code>.hasNext()</code> for iterating over the values.</p>
<h3 class="apimethod">.edges()</h3>
<p>Returns an iterable array of edges in the graph. The returned structure is similar to the one returned by <code>.nodes()</code>.</p>
<h3 class="apitopic">Events</h3>
<p>There are functions to attach event handlers for the nodes and edges in the graph. The events
that can be listened for are: click, dblclick, mousedown, mousemove, mouseup, mouseenter, and mouseleave.
See the tree documentation for details.</p>
<h2>Graph Node API</h2>
<p>A node in a graph has the same functions as a tree node: <code>.value([newValue])</code>, <code>.highlight()/unhighlight()</code>, <code>.show()/.hide()</code>, and <code>.css(...)</code>. In addition, it has the following functions.</p>
<h3 class="apimethod">.neighbors()</h3>
<p>Returns an iterable array of the nodes that this node is connected to.</p>
<h3 class="apimethod">.edgeTo(node)</h3>
<p>Returns the Edge object connecting this node to the given <code>node</code>. Returns <code>undefined</code> if no such edge exists.</p>
<h3 class="apimethod">.edgeFrom(node)</h3>
<p>Returns the Edge object connecting the given <code>node</code> to this node. Returns <code>undefined</code> if no such edge exists.</p>
<h2>Label API</h2>
<p>UI elements such as arrays can take a label.</p>
<h3 class="apimethod">.label(msg, options)</h3>
<p>
This is a method of the AV object.
It creates a label that is associated with some UI element of the AV
specified by the options.
Parameter <code>msg</code> is the
(initial) value for the label.
Paramter <code>options</code> include the following:
</p>
<ul>
<li> <code>{before: <UI element>}</code> Set the label before element
<code>UI element</code></li>
<li> <code>{after: <UI element>}</code> Set the label after element
<code>UI element</code></li>
<li> <code>{visible: <boolean>}</code> Determine whether the label
is visible on creation. Defaults to true.</li>
<li><code>{left/top/right/bottom: <lengthUnit>}</code> Values to determine the absolute position of the label relative to its container.</li>
</ul>
<h3 class="apimethod">.hide()</h3>
<p>
Make the label invisible.
</p>
<h3 class="apimethod">.show()</h3>
<p>
Make the label visible.
</p>
<h3 class="apimethod">.text(msg)</h3>
<p>
Set the text for the label. If the <code>msg</code> parameter is left
out, this method will return the current text of the label.
</p>
<h3 class="apimethod">.addClass(className, [options])</h3>
<p>Adds the CSS class <code>className</code> to the label and animates the changes.</p>
<h3 class="apimethod">.removeClass(className, [options])</h3>
<p>Removes the CSS class <code>className</code> from the label and animates the changes.</p>
<h3 class="apimethod">.toggleClass(className, [options])</h3>
<p>Toggles the CSS class <code>className</code> of the label and animates the changes.</p>
<h3 class="apimethod">.hasClass(className, [options])</h3>
<p>Return true/false based on if the label has the CSS class <code>className</code>.</p>
<h2>Variable API</h2>
<p>Variables can be used to present undo/redo capable variables.</p>
<h3 class="apimethod">.variable(value, [options])</h3>
<p>
This is a method of the AV object.
It creates a variable that can be associated with some UI element.
Parameter <code>value</code> is the
(initial) value for the variable.
Parameter <code>options</code> include the following:
</p>
<ul>
<li> <code>{before: <UI element>}</code> Add the variable before element
<code>UI element</code></li>
<li> <code>{after: <UI element>}</code> Add the variable after element
<code>UI element</code></li>
<li> <code>{visible: <boolean>}</code> Determine whether the variable
is visible on creation. Defaults to false.</li>
<li> <code>{name: <string>}</code> Name of the variable. Can be used to
fetch the variable value later. </li>
<li> <code>{label: <string>}</code> Label for the variable. Will be shown
before the variable value. For example, label "Count =" would end up the
variable looking like "Count = 3" in the HTML.</li>
<li> <code>{type: <string>}</code> Type of the variable. Can be boolean,
number, or string. By default, the type is decided based on the type of the
initial value.</li>
<li><code>{left/top/right/bottom: <lengthUnit>}</code> Values to determine the absolute position of the label relative to its container.</li>
<li>relativeTo: A JSAV data structure object or DOM element that this structure should be positioned relative to.
If this option is specified, left and top options will change structure's position relative to the relativeTo
element. Note, that the element pointed by relativeTo needs to be visible.</li>
<li>anchor: Defines which position on the element being positioned to align with the target element. Should be in
format <code>horizontal vertical</code>. Possible horizontal values are "left", "center", "right" and vertical values "top", "center", "bottom". Defaults to <code>center center</code>. Only has an effect if relativeTo is
specified.</li>
<li>myAnchor: Similar to anchor, but the position on this element. Defaults to <code>center center</code>. Only
has an effect if relativeTo is specified.</li>
<li>relativeIndex: If relativeTo points to a JSAV array, this option can be used to position this structure relative
to an index in that array. Only has an effect if relativeTo is specified.</li>
</ul>
<h3 class="apimethod">.hide()</h3>
<p>
Make the variable invisible.
</p>
<h3 class="apimethod">.show()</h3>
<p>
Make the variable visible.
</p>
<h3 class="apimethod">.value([val])</h3>
<p>
Set the value of the variable. If the <code>val</code> parameter is left
out, this method will return the current value of the variable. The value is
converted to the type specified when initializing the variable.
</p>
<h3 class="apimethod">.addClass(className, [options])</h3>
<p>Adds the CSS class <code>className</code> to the variable and animates the changes.</p>
<h3 class="apimethod">.removeClass(className, [options])</h3>
<p>Removes the CSS class <code>className</code> from the variable and animates the changes.</p>
<h3 class="apimethod">.toggleClass(className, [options])</h3>
<p>Toggles the CSS class <code>className</code> of the variable and animates the changes.</p>
<h3 class="apimethod">.hasClass(className, [options])</h3>
<p>Return true/false based on if the variable has the CSS class <code>className</code>.</p>
<h2>Pseudocode API</h2>
<p>The pseudocode API in JSAV is intended for showing a static set of codelines that can be show/hidden and
highlighted. There are two ways to initialize a pseudocode object in JSAV:</p>
<h3 class="apimethod">.code(codelines[, options]) or .code([options])</h3>
<p>Both of these are functions of a JSAV object instance. The first version takes either an array or a string
to be used as the lines of code. If a string is passed, it will be split on newline characters (<code>\n</code>)
to get the codelines.</p>
<p>The options that can be specified:</p>
<ul>
<li> <code>{url: <string>}</code> A URL where the code should be fetched. The fetched text will be split on
newline characters (<code>\n</code>). Note, that if the codelines parameter is given, this option is ignored. Also, same-origin
policies in browsers might prevent this from working across domains.</li>
<li> <code>{lineNumbers: <boolean>}</code> Determine whether linenumbers should be shown. Defaults to true.</li>
<li> <code>{visible: <boolean>}</code> Determine whether the pseudocode is visible on creation. Defaults to true.</li>
<li> <code>{before: <UI element>}</code> Add the pseudocode before element <code>UI element</code></li>
<li> <code>{after: <UI element>}</code> Add the pseudocode after element <code>UI element</code></li>
<li> <code>{center: <boolean>}</code> Boolean to determine if array should be automatically centered
within its container. Defaults to true.</li>
<li> <code>{startAfter: <string>}</code> Only the content after the last occurrence of the specified text will be included. Only
applied if the <code>url</code> parameter is also provided.</li>
<li> <code>{endBefore: <string>}</code> Only the content before the first occurrence of the specified text will be included. Only
applied if the <code>url</code> parameter is also provided.</li>
<li>relativeTo: A JSAV data structure object or DOM element that this structure should be positioned relative to.
If this option is specified, left and top options will change structure's position relative to the relativeTo
element. Note, that the element pointed by relativeTo needs to be visible.</li>
<li>anchor: Defines which position on the element being positioned to align with the target element. Should be in
format <code>horizontal vertical</code>. Possible horizontal values are "left", "center", "right" and vertical values "top", "center", "bottom". Defaults to <code>center center</code>. Only has an effect if relativeTo is
specified.</li>
<li>myAnchor: Similar to anchor, but the position on this element. Defaults to <code>center center</code>. Only
has an effect if relativeTo is specified.</li>
<li>relativeIndex: If relativeTo points to a JSAV array, this option can be used to position this structure relative
to an index in that array. Only has an effect if relativeTo is specified.</li>
</ul>
<p>Pseudocode objects have the following functions.</p>
<h3 class="apimethod">.highlight(indices) and .unhighlight(indices)</h3>
<p>Highlight and unhighlight the codelines at given indices. Lines are numbered from 0, so first line could be highlighted with:</p>
<pre>pseudo.highlight(0)</pre>
<p>Similarly to the array (un)highlight, the <var>indices</var> parameter can be either a number, an array of numbers, or a function.</p>
<h3 class="apimethod">.show() and .hide()</h3>
<p>Show/hide the pseudocode object.</p>
<h3 class="apimethod">.show(indices) and .hide(indices)</h3>
<p>Show/hide the codelines at given indices. Again, indices can be a number, an array of numbers, or a function.</p>
<h3 class="apimethod">.css(indices, css)</h3>
<p>Apply the given CSS properties to the codelines at specified <code>indices</code>.
Parameter <code>indices</code> can be a number, array, or function like for
the <code>highlight</code> method.
The argument <code>css</code> should be an object with property name-and-value pairs. For example, to make
lines 0 and 4 have green color and lightgray background:</p>
<pre>pseudo.css([0, 4], {"color": "green", "background-color": "#eee"});</pre>
<h3 class="apimethod">.setCurrentLine(index)</h3>
<p>Sets the line at given <var>index</var> as the current line. Also, if another line was previously set as current, it will be
marked as previous. If a line was also earlier marked as previous, that mark will be removed. This will help in creating a
visual debugger-like code stepping functionality in visualizations.</p>
<h3 class="apimethod">.addClass(indices, className, [options])</h3>
<p>Adds the CSS class <code>className</code> to lines at given indices and animates the changes. Like for
the rest of pseudocode methods, <code>indices</code> can be a number, array of numbers, or a function.</p>
<h3 class="apimethod">.removeClass(indices, className, [options])</h3>
<p>Removes the CSS class <code>className</code> from lines at given indices and animates the changes. Like for
the rest of pseudocode methods, <code>indices</code> can be a number, array of numbers, or a function.</p>
<h3 class="apimethod">.toggleClass(indices, className, [options])</h3>
<p>Toggles the CSS class <code>className</code> of lines at given indices and animates the changes. Like for
the rest of pseudocode methods, <code>indices</code> can be a number, array of numbers, or a function.</p>
<h3 class="apimethod">.hasClass(index, className, [options])</h3>
<p>Return true/false based on if the line at given index has the CSS class <code>className</code>. Parameter
<code>index</code> should be a number.</p>
<h2>Graphical Primitives API</h2>
<p>JSAV supports the following graphical primitives: circle, rectangle, line,
ellipse, polygon, polyline, and path. All these are in the JSAV.g namespace. A
rectangle, for example, can be initialized like follows.</p>