Hylograph.Flow.Render.Sankey
- Package
- purescript-hylograph-flow-render
- Repository
- afcondon/purescript-hylograph-flow-render
The Sankey engine: the layout this package has had since 0.1, as one
engine among those the renderer draws (Hylograph.Flow.Render.Engine).
Pure, so it runs in node.
Metrics and Widths are this engine's own configuration: sankey
metrics widths is the engine, and a Picture (words, open groups) is
what it is told as any engine is. It promises FlowsForward,
LayersAligned and WidthsConserved at its own scale; every route it
makes is a Ribbon, inked as a Band by quantity and as a Hairline
in a plain picture. It places no ports: it stacks the edges on a node's
side by where they go, so the edges of one port need not stand
together, and a port would have no one place.
One layout serves both pictures. Every edge has a width, in units; a
node is as tall as the wider of what enters it and what leaves it, and
its edges stack along its sides. A Sankey takes the widths from the
wires' payloads and draws each edge as wide as it is. A plain DAG gives
every edge one unit and draws each as a hairline down the middle of its
place. The positions come from the same code either way: the Sankey
layout in hylograph-layout, with its lanes for edges that span more
than one layer. The flow runs left to right (sankey), or the way the
engine is told (sankeyToward, 0.5).
That layout does the placing (DataViz.Layout.Sankey.Whole): the scale
is fixed (unit pixels to one unit of width, the layers a fixed
distance apart) and the picture is as large as that makes it; a node no
edge touches stands on a shelf under the picture; and an edge that
closes a cycle, an edge from a node to itself among them, leaves its
source below the edges that go forward, runs back under the picture in a
channel of its own, and enters its target likewise. The engine is the
translation and nothing more: from a projection to rows and names, and
from the layout's boxes and routes to placed nodes and centre lines, set
in from the left by a margin with room for an edge to turn.
Words, and open groups
Two things the Sankey layout cannot be asked for, and what is done here about each.
A node tall enough for its words. Told what is written in a node
(words), the layout wraps it to the node's breadth by an estimate of
each line's width (Hylograph.Flow.Render.Text, which says how the
estimate is made and how wrong it can be) and makes the node at least
tall enough for the lines; its edges stand in the middle of its sides.
The breadth is metrics.nodeBreadth, one for the picture, so a caller
with long labels may choose narrower and taller nodes.
An open group, outlined. Told the grouping and which groups are
closed (what collapse was told), the layout gives every open group
that holds a drawn node an outline: a box round its members, with a
strip for its name above them, the outline of a group inside it nested
in it. Nothing that is not a member is inside an outline, and the
outlines of two groups overlap only where one holds the other.
How, in three steps. (1) The Sankey layout runs once, to learn where it
would put everything. From that an order is made: at each level of the
grouping, the groups and the loose nodes by the mean height of what is
in them. (2) It runs again held to that order within every column
(nodeSort), so in each column a group's members stand together, the
members of a group inside it together among them, and the groups in the
same order in every column. A long edge's waypoints go with the
innermost group that holds both its ends. (3) Internal.Bands then
moves boxes down, never up and never past one another, until every
outline has its padding and its strip and no outline has anything else
in any column it spans; the same pass makes the room a taller node
needs. A member of an open group that no edge touches would be on the
shelf, far from its group: it stands in its group's first column
instead.
What hylograph-layout 0.6.0 lacks, exactly, which is why step 3 is
here and not there: a node's height is its value at the scale and
nothing else can be asked (no least height by node); the gap between
two nodes of a column is one number, nodePadding (no gap by pair, so
no room for a frame); and a node is in one column (no node that spans
columns, and no notion of a set of nodes to be kept clear of others
across columns). nodeSort is the one thing it offers, and it is used.
The cost of doing step 3 afterwards is that the Sankey relaxation does
not know of the moves, so edges into a group that was moved down slant
more than they would if the relaxation had made the room itself.
Top-down (0.5)
sankeyToward TopDown is the same layout stood on end: its layers are
rows, a node is as broad as the broader of what enters and what leaves
it, its edges stack along its top and its bottom, and every edge not
turned back runs down the page. It is made by laying the flow out left
to right and exchanging x and y at the last, so the placing, the order,
the lanes and the channels are the left-to-right layout's, and the laws
it promises are the same three, read by the layout's direction. Four
things do not survive being stood on end, and are done otherwise:
- A node's words. Left to right a node is
nodeBreadthalong the flow, its words are wrapped to that, and it is made taller where they need it. Top-down the words are still wrapped tonodeBreadth, which is then the most room a node is given across the flow for its words' sake: a node is as broad as its ribbons, or as its widest line needs where that is more (Text.breadthOf), and its ribbons stand in the middle of it. So a thin ribbon under a long name has a node as broad as the name, and two such nodes cannot have their names collide. - How far a node reaches along the flow. Left to right,
nodeBreadth. Top-down, as tall as the tallest words of any node in the picture (one height, so that the nodes of a layer are one row);restHeightwhere the picture sets no words. - An outline's strip. An outline's name is in a strip at the top of
its box, either way. Left to right that is across the flow, and the
room is made by moving boxes down a column. Top-down it is along the
flow, before the outline's first row, and the room is in the gap
between layers (and above the first): for each outline one in another,
its padding and its strip before, its padding after. Where
layerGaphas not room for what the picture asks, the strip and the padding are both less, in proportion, andPlacedOutline.headersays what the strip is. - The margins. Left to right the picture has half a
layerGapbefore its first layer and after its last, room for an edge that turns back, whether or not one does (as since 0.1, kept so that no picture moves). Top-down it has only what is used: that room where an edge does turn back, an outline's where there is an outline, and otherwise none, so a picture of forward edges begins at its first row and ends at its last, and a page can stand something directly under it.
And one thing is done top-down that is not done left to right: the layers are straightened after room is made. Making room moves boxes one way only, after the Sankey layout has placed each layer against its neighbours; so a row of thin ribbons under long names is spread out, the row they run to is not, and every ribbon between them slants the same way. Top-down each layer is then moved once more, whole, by the mean of how far its edges from earlier layers are from straight, each weighed by its breadth (the layers an outline spans move as one). Left to right it is left as it was, so that no picture made before 0.5 moves; the header's last paragraph above says what that costs.
The shelf of nodes no edge touches, under the picture left to right, is at its right top-down.
#Widths Source
data Widths wireHow wide an edge is. Plain: every edge one unit, drawn as a hairline.
Sankey: the caller reads the width from the edge, which carries what
its wires carry (wires: one for a wire, more where the edge crosses
undrawn elements, and which of them is the quantity is the domain's to
say). A width that is not a positive number is drawn as nothing.
Constructors
#Metrics Source
type Metrics = { hairline :: Number, layerGap :: Number, nodeBreadth :: Number, nodeGap :: Number, restHeight :: Number, unit :: Number }unit: pixels to one unit of width. hairline: the stroke of a plain
edge. nodeBreadth: the breadth a node's words are wrapped to; left to
right it is also the node's extent along the flow. layerGap: between
one layer and the next. nodeGap: between two nodes of a layer.
restHeight: how far across the flow a node reaches that no edge gives
an extent; top-down, also how tall every node is where no words are set.
#sankeyToward Source
sankeyToward :: forall wire. Direction -> Metrics -> Widths wire -> Engine wireThe Sankey engine with the flow running the way it is told (0.5): left
to right, its layers columns, or top-down, its layers rows. The promises
are the same three either way, and Laws reads each by the layout's
direction. See the module's header for what top-down means for a node's
size, its words, and an open group's outline.
#stoodOnEnd Source
stoodOnEnd :: forall wire. Layout wire -> Layout wireA layout made left to right, stood on end: x for y in every box and
every route, so that its columns are rows and it runs top-down. (The
Sankey engine places no ports, so there is none to move to another
side.) An outline's strip, which laidOut put before the outline's
first layer, is then at its top, where PlacedOutline.header says it is.
(Exported since 0.6, for an engine that is made the same way.)
- Modules
- Hylograph.
Flow. Render. Columns - Hylograph.
Flow. Render. Continuity - Hylograph.
Flow. Render. Engine - Hylograph.
Flow. Render. Internal. Bands - Hylograph.
Flow. Render. Keys - Hylograph.
Flow. Render. Laws - Hylograph.
Flow. Render. Layout - Hylograph.
Flow. Render. Measures - Hylograph.
Flow. Render. Motion - Hylograph.
Flow. Render. Present - Hylograph.
Flow. Render. Reshape - Hylograph.
Flow. Render. Route - Hylograph.
Flow. Render. Sankey - Hylograph.
Flow. Render. Signal - Hylograph.
Flow. Render. Text - Hylograph.
Flow. Render. Transition - Hylograph.
Flow. Render. Tree - Hylograph.
Flow. Render. Unfold