DataViz.Layout.Abacus
- Package
- purescript-hylograph-layout
- Repository
- afcondon/purescript-hylograph-layout
The abacus diagram. A flow (nodes, and links that carry a quantity of some kind) drawn with counted units where a Sankey has ribbons of a width: each node is a small grid of equal units, ten to a line unless told otherwise; one unit is worth a declared amount; a unit's kind (its colour, when drawn) is the kind of what flows. The links are wires that say only that two nodes are joined. It is Neurath's rule for Isotype (more of a thing is shown by more signs, never by a bigger sign) on a Sankey's graph.
▪▪▪▪▪▪▪▪▪▪ ▪▪▪▪▪▪▪▪▪▪
▪▪▪▪▪▪▪▪▪▪ ────── ▪▪▪▪▪▪▪▫▫▫ ────── ▪▪▪▪▪▪▪
▪▪▪▪▪ ╲
a source ╲──────── ▫▫▫
The columns, the order down a column and the links that close a cycle
are the Sankey's (computeLayoutWithConfig on the same rows with
config.sankey, or computeLayoutWithLanes when wires have lanes): the
abacus keeps them and replaces the sizes, since a node here is as large
as its units.
The laws (the test suite holds the layout to each):
- A node's total is the larger of what comes in and what goes out.
- A node's kinds, and what arises (
Composition;IncomingAndArisingunless told otherwise). What comes in, by kind, is in the node at its own amount,Carried. If more goes out than comes in, the rest (outgoing - incoming) arises in the node: a kind hasrest * (outgoing of that kind / outgoing)of it,Arising. So the quantities sum to the total, a node that nothing comes into is allArising, and a node where no more goes out than comes in is allCarried. - How many units. With
n = total / worth: a total of nothing is oneEmpty;0 < n < 1is onePart, of the node's largest share; otherwise the node hasround nunits, allWhole(a half rounds up). - Which kinds get them. Those
round nunits are shared out by largest remainder: a share (a kind, carried or arising) of quantityq, worthw = q / worthunits, getsfloor worfloor w + 1of them, the extra ones going to the kinds with the largest fractionsw - floor w(of two equal fractions, to the larger kind). So the kinds' units sum to the node's, and no kind is more than one unit from its share. A kind worth less than one unit may get none. - Places. A unit lies inside its node's box, which is exactly the box around the node's units; no two units of a node overlap; no two nodes overlap.
- Wires. One for each ordered pair of different nodes that links of a
quantity join, from the right side of its source to the left side of
its target. It turns back exactly when the Sankey set those links
aside as back-edges, so an input with no cycle has none that do. A
link from a node to itself is no wire: its node
returnsToItself. - A wire's line keeps clear (
wireSegments). Every wire first runs level to the right side of its source's column. The line of a wire to the next column (Onward), of a wire with lanes (Laned: one that passes over one or more columns, whenlanesare on, as they are unless told otherwise) and of a wire that turns back (TurningBack: down the space after its source's column, along a channel of its own below every node, up the space before its target's column) goes through no node's box and through no node's room for a name (labelRoom,nodeMinWidth). Not promised: two wires may cross, or run together, in the space between columns; withWithoutLanesa wire over a column goes straight through it; and a caller'snodeLayercan put a forward wire's target in its source's column or before it, where nothing is promised either. - The extent holds every wire's line.
let links = kindedBy _.s rows -- a kind for each row
let worth = niceWorthFor 40 links -- the largest node at most 40 units
let laid = computeLayout links (defaultAbacusConfig worth)
laid.nodes <#> \node -> node.units <#> \unit -> … -- a square at (unit.x, unit.y)
laid.wires <#> wirePath -- a thin stroke
#computeLayout Source
computeLayout :: forall kind. Ord kind => Array (AbacusLink kind) -> AbacusConfig -> AbacusLayout kindThe abacus of links. See the module's own account for what it keeps
of the Sankey's layout and for its laws.
#throughput Source
throughput :: forall kind. Ord kind => Composition -> Array (AbacusLink kind) -> Array (Throughput kind)What passes through each node, in the order the links first name the nodes. A link from a node to itself counts once as coming in and once as going out, as it does in the Sankey.
#niceWorthFor Source
niceWorthFor :: forall kind. Ord kind => Int -> Array (AbacusLink kind) -> UnitWorthniceWorth for the largest node of links: at that worth no node has
more than most units.
#wireSegments Source
wireSegments :: forall kind. AbacusWire kind -> Array WireSegmentA wire's line, piece by piece. Every wire starts level, to the right
side of its source's column. Onward: then one S across to its
target's side. Laned: then an S across each space between columns
and level through each lane, and a last S into its target's side.
TurningBack: on to down, down to the channel at under, along it
to up, up, and level into its target's side, each of the four turns
rounded by turn.
#wirePath Source
wirePath :: forall kind. AbacusWire kind -> StringA wire's line as an SVG path, to be stroked thin.
Re-exports from DataViz.Layout.Abacus.Types
#WireCourse Source
data WireCourseHow a wire runs. Every wire leaves the right side of its source at
from and enters the left side of its target at to, and first runs
level to the right side of its source's column.
Onward: from leaves, the right side of its source's column, across
to its target, which is in the next column (or, with WithoutLanes,
in any later one). Laned: its target is two or more columns on; from
leaves it goes through a lane in each column it passes, in order,
crossing from one column to the next in the space between them.
TurningBack: it closes a cycle (the Sankey set it aside as a
back-edge); it goes down at down, in the space after its source's
column, back along a channel at under, below every node, and up at
up, in the space before its target's column. turn: how far its
four turns are rounded.
Constructors
Onward { leaves :: Number }Laned { leaves :: Number, through :: Array LaneSlot }TurningBack { down :: Number, turn :: Number, under :: Number, up :: Number }
Instances
#UnitMark Source
data UnitMark kindWhat a unit says. Whole: one unit's worth of a kind, carried into the
node or arising in it. Part: an amount of that kind which is more
than nothing and less than one unit; drawn smaller. Empty: nothing;
drawn open.
Constructors
Instances
#Throughput Source
type Throughput kind = { byKind :: Array (KindQuantity kind), name :: String, total :: Number }What passes through a node: total is the larger of what comes in and
what goes out, and byKind is the total by kind and origin as the
Composition shares it out, the largest first (of equal quantities,
kinds in the order the links first name them, and carried before
arising). The quantities of byKind sum to total.
#Lanes Source
data LanesWhether a wire that passes over one or more columns is given a lane: a
place kept for it in each column it passes, between the nodes there, so
that it runs through no node and no name. gap is the room a lane takes
in a column, top to bottom; the wire runs along its middle.
Constructors
WithoutLanesWithLanes { gap :: Number }
Instances
#KindQuantity Source
type KindQuantity kind = { kind :: kind, origin :: Origin, quantity :: Number }#Composition Source
data CompositionWhich kinds a node's units are, and which of them were carried in and which arose in the node, where what comes in and what goes out differ. The node's total is the larger of the two whichever is chosen.
IncomingAndArising(the default): what comes in, by kind, at its own amounts,Carried; if more goes out than comes in, the rest is what arises in the node: it is shared among the kinds of what goes out, in their proportions, and isArising. So a node that nothing comes into (a source) is allArising.IncomingScaled: the kinds of what comes in, each scaled bytotal / incomingso that they sum to the total, allCarried; a node that nothing comes into has the kinds of what goes out,Arising.LargerSide: the kinds of whichever side is larger (what comes in, when they are equal):Carried, butArisingwhere nothing comes in.
Constructors
Instances
#AbacusWire Source
type AbacusWire kind = { course :: WireCourse, from :: Point, kind :: kind, links :: Array Int, source :: String, target :: String, to :: Point }A wire says only that two nodes are joined, and which way: there is one
for each pair of different nodes that links of a quantity join in one
direction, however many such links there are. links: their places in
the input. kind: the kind of the largest of them. from, to: its
two ends.
#AbacusUnit Source
type AbacusUnit kind = { mark :: UnitMark kind, size :: Number, x :: Number, y :: Number }A unit's place: its top left corner and its side. A Part and an
Empty have the same place as a Whole; drawing them smaller or open
is the caller's.
#AbacusNode Source
type AbacusNode kind = { layer :: Int, name :: String, returnsToItself :: Boolean, total :: Number, units :: Array (AbacusUnit kind), x0 :: Number, x1 :: Number, y0 :: Number, y1 :: Number }A node. Its box (x0, y0, x1, y1) is exactly the box around its
units. layer: its column, as the Sankey numbers them. total: see
Throughput. returnsToItself: some link of a quantity runs from this
node to itself; it is drawn as a mark on the node and has no wire.
#AbacusLink Source
type AbacusLink kind = { kind :: kind, s :: String, t :: String, v :: Number }A link: a Sankey's row (s, t, v) and the kind of what flows along
it. A quantity below zero counts as none.
#AbacusLayout Source
type AbacusLayout kind = { extent :: Extent, nodes :: Array (AbacusNode kind), wires :: Array (AbacusWire kind), worth :: UnitWorth }nodes: in the order of the Sankey's own nodes for the same rows, so
that what is given by a node's place there (a colour, say) is the same
in both pictures. wires: in the order the links first join each pair. worth: what a
unit is worth, to be said beside the picture. extent: the box around
everything, label room, lanes and the wires that turn back included;
such a wire may run to the left of origin or to the right of the last
column.
#AbacusConfig Source
type AbacusConfig = { backWireDip :: Number, backWireGap :: Number, composition :: Composition, labelRoom :: LabelRoom, lanes :: Lanes, layerGap :: Number, nodeGap :: Number, nodeMinWidth :: String -> Number, origin :: Point, sankey :: SankeyConfig, tally :: Tally, unitGap :: Number, unitSize :: Number, unitsPerLine :: Int, worth :: UnitWorth }worth: what one unit is worth. unitsPerLine: how many units to a
line before the next line starts. unitSize: a unit's side. unitGap:
between one unit and the next, across and down. tally: grouping.
composition: see Composition. lanes: see Lanes.
nodeGap: between one node and the next below it (beyond the label
room). layerGap: between the widest node of one column and the left of
the next column. labelRoom: see LabelRoom. nodeMinWidth: a node's
least width in its column, by name (room for its label); the units keep
to the left of it. backWireDip: from the bottom of the lowest node
(its label room counted) to the channel of the first wire that turns
back, and the most a wire's turns are rounded by. backWireGap: from
one such channel to the next.
origin: the top left corner of the picture.
sankey: the Sankey layout that says which column a node is in, the
order of the nodes (and of the lanes) down a column, and which links
turn back. Its
alignment, nodeLayer and nodeSort mean here what they mean there.
Its sizes (extent, nodeWidth, nodePadding) reach the abacus only
through the order that the Sankey's relaxation settles on.
#turnsBack Source
turnsBack :: forall kind. AbacusWire kind -> Boolean#ofOneKind Source
ofOneKind :: Array LinkCSVRow -> Array (AbacusLink Unit)A Sankey's rows where nothing tells one flow from another.
#kindedBy Source
kindedBy :: forall kind. (LinkCSVRow -> kind) -> Array LinkCSVRow -> Array (AbacusLink kind)A Sankey's rows, each given a kind.
#defaultAbacusConfig Source
defaultAbacusConfig :: UnitWorth -> AbacusConfigTen units to a line, each 4 square and 1 apart, in no groups; kinds by what comes in and what arises; lanes, each 6 deep; columns 20 apart, nodes 12 apart with no room kept for labels; the Sankey's own defaults for a chart 960 by 600.
- Modules
- DataViz.
Layout. Abacus - DataViz.
Layout. Abacus. Types - DataViz.
Layout. Adjacency - DataViz.
Layout. Adjacency. Layout - DataViz.
Layout. Adjacency. Types - DataViz.
Layout. BlockCutTree - DataViz.
Layout. Chord - DataViz.
Layout. Chord. Layout - DataViz.
Layout. Chord. Types - DataViz.
Layout. Hierarchy. Cluster - DataViz.
Layout. Hierarchy. Core - DataViz.
Layout. Hierarchy. EdgeBundle - DataViz.
Layout. Hierarchy. EdgeBundle. Bilink - DataViz.
Layout. Hierarchy. EdgeBundle. BundleCurve - DataViz.
Layout. Hierarchy. EdgeBundle. Hierarchy - DataViz.
Layout. Hierarchy. EdgeBundle. RadialCluster - DataViz.
Layout. Hierarchy. EdgeBundle. Types - DataViz.
Layout. Hierarchy. Link - DataViz.
Layout. Hierarchy. Pack - DataViz.
Layout. Hierarchy. Partition - DataViz.
Layout. Hierarchy. Placed - DataViz.
Layout. Hierarchy. Tree - DataViz.
Layout. Hierarchy. TreeStyle - DataViz.
Layout. Hierarchy. Treemap - DataViz.
Layout. Hierarchy. Types - DataViz.
Layout. Pattern - DataViz.
Layout. Pattern. Adapters - DataViz.
Layout. Pattern. Types - DataViz.
Layout. Sankey. BackEdge - DataViz.
Layout. Sankey. CSV - DataViz.
Layout. Sankey. Compute - DataViz.
Layout. Sankey. ComputeWithSteps - DataViz.
Layout. Sankey. Lanes - DataViz.
Layout. Sankey. Path - DataViz.
Layout. Sankey. Types - DataViz.
Layout. Sankey. Whole - DataViz.
Layout. StateMachine - DataViz.
Layout. StateMachine. Layout - DataViz.
Layout. StateMachine. Path - DataViz.
Layout. StateMachine. Tree - DataViz.
Layout. StateMachine. Types - DataViz.
Layout. TidyDag