Recall that Vamonos visualizations can be either in edit mode or display mode, and that the behavior of widgets changes between these modes. In the next few parts part of the user’s guide, we’ll discuss the behavior of the major widgets included with Vamonos.

To use a widget, you must do two things:

  1. Include a “container” <div> in the HTML, where the widget will “draw itself.”

  2. In the page’s Javascript, construct a widget object and pass it to the visualizer in the list of widgets.

Nearly all visualizations in Vamonos will include a controls widget, so we will begin our discussion with it.

Overview

The Controls widget is how the user will navigate the sequence of snapshots that comprise the visualization.

Example:

This simple example runs an algorithm that generates 50 “dummy” snapshots (plus a “before” and “after” snapshot).

The Controls widget can then be used to navigate the snapshots. Since there are no widgets that actually display data from the snapshots, this experience is rather boring.

HTML:

<div id="controls"></div>

Javascript:

new Vamonos.Visualizer({
    widgets: [
        new Vamonos.Widget.Hardcoded({ breakpoints: [1] }),
        new Vamonos.Widget.Controls({ container: "controls" })
    ],
    algorithm: function (_) {
        for (var i = 0; i < 50; i++) {
            _(1);
        }
    }
});

Result:

Usage:

The first button (whose text is either run or stop) toggles the visualization between edit and display modes.

The next two buttons step to the previous/next snapshots. The last button toggles between a “play” and a “pause” button. When “playing”, the visualization is advanced to the next frame once per second.

The slider allows for fast movement through the sequence of snapshots.

Looking ahead, many widgets are able to highlight data that changes between snapshots. These widgets are able to highlight selectively, depending on whether the snapshot was changed via the slider, “next” button, or “previous” button. The default behavior is that widgets highlight their changes only when the “next” button is pushed.

Constructor Arguments

You can create a Controls widget with the Vamonos.Widget.Controls constructor. It accepts the following arguments:

Alternatively, you can simply pass a string to the Controls constructor specifying its container. All other options will be set to their defaults.

Example:

Here is an example which sets several options for the Controls widget. Take notice of the following things:

HTML:

 <div id="array"></div>
 <div id="controls"></div>

Javascript:

new Vamonos.Visualizer({
    widgets: [
        new Vamonos.Widget.Hardcoded({ breakpoints: [1] }),

        new Vamonos.Widget.Array({
            container:    "array",
            varName:      "A",
            showIndices:  ["i"],
            defaultInput: [0,0,0,0,0,0,0,0]
        }),

        new Vamonos.Widget.Controls({
            container:        "controls",
            runStopButton:    false,
            showWhileSliding: false
        })
    ],
    autoStart: true,

    algorithm: function (_) {
        with (this) {
            for (i = 0; i < A.length; i++) {
                _(1);
                A[i] = i+1;
            }
        }
    }
});

Result:

Buttons Only / Slider Only

You can control whether or not the slider and buttons display with the slider and buttons arguments to the Controls constructor (they default to true).

new Vamonos.Widget.Controls({ 
    slider: false,
    container: "container" 
})
new Vamonos.Widget.Controls({ 
    buttons: false,
    container: "container" 
})
Next page: The pseudocode widget