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:
- 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.
Reactive.do. Code that runs when objects it reads change: “write the distance betweenaandbinto this label” (Reacting to change).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:
- Dragging sets the position of
a. - That starts an update: VisQuill runs everything that depends on
a, right away, before the assignment returns. The segment needs nothing to run, it containsa. The block runs and writes the label, and whatever depends on the label would run next. - 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.
