Module

Hylograph.Flow.Render.Unfold

Package
purescript-hylograph-flow-render
Repository
afcondon/purescript-hylograph-flow-render

The unfolding engine: one layout for every cut of a flow, so made that the layouts of two cuts that differ by one group can be laid side by side and the reader keeps their place (0.6).

Hylograph.Flow.Grouping.collapse gives the coarser flow for a cut (a set of closed groups). The Sankey engine lays each such flow out afresh: its relaxation places every layer again, an open group is given room for its outline, and a closed group is as broad as what crosses its boundary, which need not be what its parts are abreast. So nothing can be promised of the pair. This engine is told the finest flow once (Whole: the grouping, and the projection with nothing closed) and derives from it three things that no cut changes; every cut's layout is then made of them, and is a function of the cut alone (so closing what was opened gives back, to the number, the layout there was).

1. One order across the flow (Plan.rank). Every node of the finest flow has a rank, and every group's nodes are a run of consecutive ranks, a group inside it a run within that run. It is read once from the Sankey layout of the finest flow (at each level of the grouping, the groups and the loose nodes by the mean of where that layout put them). In every cut, the nodes of a tier stand in the order of their ranks, a closed group at its run; the ribbons on a node's side stand in the order of the ranks of their other ends, whether they run forward or are turned back; and the lane of a long ribbon stands just after the block its source is in, at the level of the innermost group that holds both its ends. Hence Ordered, always: no two nodes of a tier and no two ribbons at a node change order between any two cuts.

2. One breadth for each group (Plan.breadth). A closed group is as broad as the most of its inside that is ever abreast: the heaviest set of its nodes and inner ribbons no two of which lie on one path (a maximum-weight antichain of the finest flow, within the group), or what crosses its boundary one way where that is more. For a chain that is its throughput, and what the Sankey engine gives. For a group that holds a spring beside a dead end, or a loop, it is more than its ribbons, and the bar says so: there is more inside than crosses. An open group is a band of exactly that breadth, in which its parts stand with no gap between them, a group inside it a band within the band. Parts in one tier are never on one path, so they fit; hence Nested, for breadth: the parts of an opened group stand in a slot as broad as its closed bar. (The one case where they do not fit is said under "What is not kept".)

3. One rule for gaps. nodeGap stands between two boxes of a tier that are in different top-level blocks of the grouping (a top-level group, open or closed, or a node no group holds), and nothing stands between two boxes of one block. Two lanes are of one block when their sources are in one top-level block and their targets in one. No gap depends on the cut, and an outline takes no room: its name's strip is in the gap that is there anyway.

The placing is then a packing with no relaxation in it. The tiers are the Sankey layout's of the cut's own flow (its layers, its lanes for long ribbons, its channels for ribbons turned back, its shelf), with one difference from the Sankey engine: a node that feeds nothing stands in the last tier (that layout's Justify), where the Sankey engine stands it just after what feeds it. The ends of a flow are commonly one group (its sinks, its fates), and a group whose parts are in one tier opens Held; left where their feeders put them, the sinks of a real flow are tiers apart and their group spans the picture. Across the flow, the top-level blocks are taken in rank order and each is set as near the start as what stands before it in the tiers it spans allows. An open group spans every tier from its first part's to its last's, and nothing else enters its band in any of them.

So Held, where there is room: when a group whose parts are in one tier opens, the parts take the bar's place exactly and no other box moves; Continuity.continuity says so of the pair, by measuring.

What is not kept

  • The tiers are the cut's. Closing a group whose parts are in several tiers makes it one node in one tier, so what is downstream moves along the flow, and where the group's parts straddled something outside it the closed flow has a cycle and a ribbon is turned back. Then the pair is not Held, and is Nested only if the band kept its place across the flow.
  • A band can be too narrow where a ribbon is turned back. Two parts on one path are never in one tier, unless the path ran through a ribbon that this cut turned back. Then a tier of the group can hold more than the group's breadth, the band is as broad as it needs, and the pair is not Nested. continuity reports it; nothing is drawn wrong.
  • Words make no room. A node is as broad as its ribbons (or its group's breadth) and nothing else: breadth is data. The engine sets no words, so under a picture that gives words it breaks the general law Lettered; give it none, and let the tree write each label beside its node (Tree.treeLabelled (Beside least)).
  • A ribbon turned back does not stand below the others on its node, as the Sankey engine has it: it stands where its other end's rank puts it, since whether a ribbon is turned back is the cut's.
  • A node no edge touches is on the shelf, as ever, unless it is a member of an open group (then it is in its group's band, with no breadth, since nothing passes through it) or a closed group that nothing crosses into or out of (then it is in the first tier, as broad as the group is).
  • An open group that spans tiers keeps its whole band in each of them. So a part of the group over it that stands in one of those tiers stands beside the band, though it may be on one path with what is in the band; the group over it can then need more than its breadth, and opening it is not Nested. The breadth is exact for a group none of whose inner groups, open, spans tiers.

The engine promises FlowsForward, LayersAligned and WidthsCarried (a node is at least as broad as its broader side), not WidthsConserved (exactly as broad), because of 2.

#Whole Source

type Whole wire = { finest :: Projection wire, grouping :: Array Grouping }

The flow whatever the cut: its grouping, and its projection with no group closed (project drawing (collapse grouping Set.empty flow)). Every projection the engine is then run on must be of the same flow under the same grouping and drawing, with some groups closed, and the picture must say which (Picture.groups; a picture that tells of no groups is taken to have none closed, and gets no outlines).

#Plan Source

type Plan = { block :: Map ElementKey Int, blockOfGroup :: Map GroupId Int, breadth :: Map GroupId Number, deepest :: Int, levels :: Map GroupId Int, parts :: Map GroupId (Array Part), rank :: Map ElementKey Int, room :: { given :: Number, tiers :: Int, wanted :: Number }, span :: Map GroupId { hi :: Int, lo :: Int } }

What no cut changes. rank: each node of the finest flow, its place in the one order. span: each group that holds a node, its first and last rank. block: each node's and each group's top-level block, as the first rank of it. breadth: each group's breadth, in pixels. levels: how many levels of group are inside each group. deepest: how many groups deep the grouping goes. parts (0.7): the parts each group opens into (its members and the groups directly inside it), in the one order. room (0.7): the gap between two tiers along the flow: what the proportion asks for (wanted), what the engine gives (given: the same, unless the plan was held to a length, heldTo), and how many tiers the finest flow has.

#plan Source

plan :: forall wire. Metrics -> Widths wire -> Whole wire -> Plan

What no cut changes, read once from the finest flow.

#unfolding Source

unfolding :: forall wire. Direction -> Metrics -> Widths wire -> Whole wire -> Engine wire

The unfolding engine for a flow, the flow running the way it is told. The plan is made once, when the engine is first run.

#unfoldingBy Source

unfoldingBy :: forall wire. Plan -> Direction -> Metrics -> Widths wire -> Whole wire -> Engine wire

The same, by a plan already made (plan, of the same metrics, widths and whole).

#groupBreadth Source

groupBreadth :: Plan -> GroupId -> Maybe Number

How broad a group is, closed or open, in pixels; nothing for a group that holds no node of the finest flow.

#rankOf Source

rankOf :: Plan -> ElementKey -> Int

A node's place in the one order: its own rank, or for a closed group's step or summary the first rank of the group.

#gathered Source

gathered :: forall wire. Projection wire -> Projection wire

A projection with the parallel ribbons from each closed group made one (0.7): the edges that leave one closed group's step (or its summary) for one node become a single edge, in the place of the first of them, that stands for all their wires (wires and via end to end, in order) and names no port.

collapse merges the wires of one item; three members of a closed group that each lose a little to one sink write three items, and the closed group then has three ribbons to the sink, side by side, where a reader expects one: the group lost six, not two three times. Which member wrote what is the open picture's to say.

A width must add. An edge so gathered is as broad as its parts together only if the engine's Widths reads it so: give a width that is a sum over the edge's wires (of what each read carries, say), not one that reads a single wire of it. Run the engine on the gathered projection and check its layout against the same.

Only ribbons from a closed group are gathered. Ribbons into one from a single open node are parallel in the open picture too (several substances between one pair of nodes), and stay apart. A closed group that sends several substances to one node from one member has them gathered as well, which says less than could be said; telling the two apart needs a grouping over what wires carry.

#Part Source

type Part = { breadth :: Number, hi :: Int, lo :: Int, name :: String, only :: Maybe Only }

A part of a group: a member, or a group directly inside it. lo, hi: its ranks. breadth: in pixels, a member's as broad as its broader side in the finest flow, a group's as broad as it is closed. only: what it does alone, in the finest flow, where it only receives or only gives (see Only).

#seams Source

seams :: forall wire. Plan -> Layout wire -> Array Seamed

The seams of each closed group's bar in a layout (0.7): where the parts it opens into divide it. Only for a bar whose parts, side by side, are exactly as broad as it is: then no two of them are ever on one path, the bar is the parts abreast, and where it opens in its own tier each part takes the place its seams mark. A group whose parts follow one another (a chain) is as broad as the broadest of them and has no seams. A part is marked as only receiving or only giving where the group itself does both: that is what says "five end here and four others begin here" of a bar with five on one side and four on the other.

#heldTo Source

heldTo :: Direction -> Metrics -> Number -> Plan -> Plan

A plan held to a length (0.7): the gap between tiers is what the proportion asks for, or as much of it as leaves the finest flow's picture, and its coarsest, no longer along the flow than length, and never less than the metrics' own gap. plan.room then says whether it could be given (given < wanted: it could not).