Relationship-based interactive visuals Note

elliot evans
nov 4 2023
This is a seed note, it is the incomplete start of a note. It is missing interactivity, diagrams, content, and editing. With some sunlight and water it will sprout. Please be patient while this note sprouts

The deprecated note below was previously too narrow in what it was discussing, and not very useful. I think this note will be broken into a few other notes:

DEPRECATED NOTE FOLLOWS:

This is an interactive note about a relationship-based API for making visual interactive stuff. By relationship-based I mean that the API is made for building relationships between visual things. By API I mean JavaScript / TypeScript library.

Relationships instead of properties

my square

In a property-based API for visual stuff, you might create a square like this:

    const mySquare = square({ radius: 20, center: [35,35]})

See how we initialized the square with a size (radius) and position (center)? In the API we will be discussing in this note, nothing has a size nor position nor any layout property. So let's make a square without any layout properties:

    const mySquare = square();

square beside square

Things like squares don't have layout properties, they instead have layout relationships with other things.

    const a = square();
    const b = square();
    besideLeftToRight(a, b);

There are multiple ways to express the same relationships; the line below is equivalent to the last line above (note that it is "RightToLeft" instead of "LeftToRight" and a and b are swapped).

NOTE: `aLeftOfB` might be better than `besideRightToLeft`
    besideRightToLeft(square1, square2);

relating and determining

besideLeftToRight and besideRightToLeft place two shapes horizontally next to eachother. Given the position of one of the shapes, we can compute the position of the other; in other words, these particular relationships determine the positions of the shapes they relate. For short, I'll say that these relationships determine position.

Math warning (feel free to ignore): Formally, these relationships are position isomorphisms. Scroll further in this note to see a more formal description of all of this.

Here's a relationship that determines rotation:

    const a = square();
    const b = square();
    rotate(Math.PI/8)(a, b);

To say the same thing again in another situation: rotate(Math.PI/8) determines the rotations of the shapes it relates.

There are more intense relationships that determine all layout properties of the things they relate. The most basic example is:

    const a = square();
    const b = square();
    equal(a, b);

equal completely determines layout of both squares... But it might not be the most interesting relationship. Here's another relationship that completely determines layout:

    const a = square();
    const b = square();
    equalExceptBesideLeftToRight(a, b);

relationships (emphasis on the s)

If you have three things, you can relate them all by specifying only two relationships.

    const a = square();
    const b = square();
    const c = square();
    besideLeftToRight(a, b);
    besideLeftToRight(b, c);

The above is equivalent to the below:

    const a = square();
    const b = square();
    const c = square();
    besideLeftToRight(a, b);
    besideLeftToRightWithSomethingInBetween(b)(a, c);
THIS NEEDS DIAGRAMS NOT CODE!

so how do you actually draw stuff

TODO

TODO

- interactive & editable examples
- diagrams
- push and pull and mixed evaluation models
- beyond visuals: bidirectional relationship programming
- more

Appendix: Formal Description

TODO. Sneak peek: its a Setoid.

Comments new and simple comments system using val.town, please be kind and don't link stuff