A change to a canvas: what a person did, or what the app does.
Every change goes the same way, whoever makes it: the canvas applies it
to its graph (Hakushi.Graph.apply/2), checks its rules
(Hakushi.Rules), asks the app (on_change), and only then shows it,
to the person and to everyone else on the canvas. A change the server
refuses goes back in the browser, with the reason.
op is one of:
:add-nodesis a list ofHakushi.Nodes,edgesa list ofHakushi.Edges between them or others: a node dropped on the canvas, a paste, a duplicate, an undone delete.:connect-edgesis a list ofHakushi.Edges, drawn by a person from a handle to a handle.:move-nodesis a list of maps with:id,:xand:y,:widthand:heightfor a node that was resized, and:parentfor a node dropped into a group (an id) or out of one (nil). The nodes in a moved node move with it:Hakushi.Graph.apply/2lists them.:reconnect-edgesis a list of maps with:idand the new ends (:source,:source_handle,:target,:target_handle): an edge's end dragged to another handle.:update-nodesis a list of maps with:idand the keys that change (:data,:type,:locked),edgesa list of maps with:idand the keys that change (:label,:path,:marker,:animated,:data).:delete-nodesandedgesare lists of ids. Deleting a node deletes the nodes in it and the edges of all of them: the change thatHakushi.Graph.apply/2gives back lists them.
by is the user of the canvas that made it (a map with an :id), or
nil for the app's own.
Summary
Functions
Adds nodes, and edges.
Connects two nodes: an edge, or a list of them.
Deletes nodes (with their edges) and edges, by id.
The ids of the nodes a change touches, and of its edges, as two lists.
Moves nodes: [{id, x, y}] or maps with :id, :x and :y.
Moves the ends of edges: maps with the edge's :id and its new
:source, :source_handle, :target or :target_handle.
Changes nodes and edges: maps with an :id and the keys that change.
Types
@type op() :: :add | :connect | :move | :reconnect | :update | :delete
@type t() :: %Hakushi.Change{ by: map() | nil, edges: [Hakushi.Edge.t() | map() | Hakushi.Edge.id()], nodes: [Hakushi.Node.t() | map() | Hakushi.Node.id()], op: op() }
Functions
@spec add([Hakushi.Node.t() | map()], [Hakushi.Edge.t() | map()]) :: t()
Adds nodes, and edges.
@spec connect(Hakushi.Edge.t() | map() | [Hakushi.Edge.t() | map()]) :: t()
Connects two nodes: an edge, or a list of them.
Deletes nodes (with their edges) and edges, by id.
@spec ids(t()) :: {[Hakushi.Node.id()], [Hakushi.Edge.id()]}
The ids of the nodes a change touches, and of its edges, as two lists.
@spec move([{Hakushi.Node.id(), number(), number()} | map()]) :: t()
Moves nodes: [{id, x, y}] or maps with :id, :x and :y.
Moves the ends of edges: maps with the edge's :id and its new
:source, :source_handle, :target or :target_handle.
Changes nodes and edges: maps with an :id and the keys that change.
Hakushi.Change.update(nodes: [%{id: "users", data: %{name: "people"}}])