jcberentsen/elm-wiring-diagrams/2.0.0

NOTE: the latest version is 5.4.7

WiringDiagram

Wiring diagrams

Inspiration

https://arxiv.org/pdf/2101.12046.pdf

Diagram type

type Diagram a
= Diagram
{ label : Maybe a
, wrap : Bool
, inner : List (Diagram a)
, direction : Direction
, inPorts : Ports
, outPorts : Ports
}

Represent an abstract wire-diagram.

Think of boxes connected with ports, that can be inside other boxes (which connect outside) (TODO illustration)

Initialize an empty Diagram. The idea is a box with no label. The box is abstract and will be given geometry using the Layout module

Use modifiers like setInPorts to configure further

#Custom use

initLabeled : Maybe a -> Diagram a

Initialize an empty Diagram with a label of a chosen type

All diagrams you intend to combine needs to have the same label type

diagram : { a | label : Maybe b, inner : List (Diagram b) } -> Diagram b

Wrap a diagram, exposing the free in and out ports

Diagram helpers

source : a -> Int -> Diagram a

Make a source with label a and a number of outPorts

sink : a -> Int -> Diagram a

Make a sink with label a and a number of inPorts

relation : a -> Int -> Int -> Diagram a

Make a relation with label a and a number of inPorts and outPorts

inSequence : List (Diagram a) -> Diagram a

Connect diagrams in a chain

inParallel : List (Diagram a) -> Diagram a

Put diagrams in paralell. No connections will be made. (We probably need to relabel ports here...)

-> { a | direction : Direction }
-> { a | direction : Direction }

Say which direction the children should lay out

= D1
| D2

Direction of composition of diagrams

D1 is horizontal (sequenced, chained) D2 is vertical (in paralell)

include : List (Diagram a) -> Diagram a -> Diagram a

Include a list of diagrams inside another diagram. The included list will replace any previous innards.

Wrap a diagram, exposing the free in and out ports

Input and output Ports

setOutPorts : List Int -> { a | outPorts : Ports } -> { a | outPorts : Ports }

Assign output ports to a Diagram

setInPorts : List Int -> { a | inPorts : Ports } -> { a | inPorts : Ports }

Assign input ports to a Diagram

outPorts : Diagram a -> Ports

Extract the output ports of a Diagram

inPorts : Diagram a -> Ports

Extract the input ports of a Diagram

Misc

map :
( { label : Maybe a
, wrap : Bool
, inner : List (Diagram a)
, direction : Direction
, inPorts : Ports
, outPorts : Ports
}
-> { label : Maybe b
, wrap : Bool
, inner : List (Diagram b)
, direction : Direction
, inPorts : Ports
, outPorts : Ports
}
)
-> Diagram a
-> Diagram b

Map a function over a diagram innards You should avoid using this

type alias Ports =
List Int

Ports are a list of numbers identifying each port

offsetPorts : Int -> Diagram a -> Diagram a

Bump the port numbers of a diagram.

This is used to avoid duplicate ports when combining diagrams in paralell (relabel ports here...)