How VisQuill thinks

In many drawing libraries you draw a frame, and to change the picture you draw it again. In VisQuill you build the picture once, as objects and relationships between them. After that you only change objects, and VisQuill keeps everything that depends on them up to date.

Objects

Everything you create from the canvas is a reactive object: it knows when it changes and who depends on it.

  • Values: numbers, flags, texts, any JavaScript object, and points and pins (Values and points).
  • Shapes: segments, triangles, rectangles, circles, polygons… A shape is a list of points.
  • Visuals: shapes that are drawn. A visual is a shape, it is just also on the screen (Shapes and visuals).
  • Handles: points the user can drag.

Relationships

There are three ways to say that one object depends on another:

  1. Share a point. A segment built from two handles contains those handles. Moving a handle moves the segment, because it is the segment’s end.
  2. Reactive.do. Code that runs when objects it reads change: “write the distance between a and b into this label” (Reacting to change).
  3. Attach. Ready-made relationships between shapes: “this bar stands on that segment”.

What happens on a change

Take the first figure of Reacting to change: a segment between two handles, and a label showing their distance. This is what happens when the user drags a:

1 pointer moves 2 an update, right away 3 next animation frame handle a segment (shares a) Reactive.do block label SVG on screen
  1. Dragging sets the position of a.
  2. That starts an update: VisQuill runs everything that depends on a, right away, before the assignment returns. The segment needs nothing to run, it contains a. The block runs and writes the label, and whatever depends on the label would run next.
  3. In the next animation frame, VisQuill writes what changed into the SVG, once, however many updates happened since the last frame.

What you don’t write

  • No render loop. Nothing redraws “every frame”; only what changed is written to the SVG.
  • No update calls. You never call something like chart.update() after a change. Changing the object is the update.
  • No bookkeeping of who needs what. The relationships are that bookkeeping.

You still write ordinary code where it belongs: an event listener, a fetch, a timer. It ends with changing a value, and the relationships take it from there.