Package

purescript-hylograph-flow-render

Repository
afcondon/purescript-hylograph-flow-render
License
MIT
Uploaded by
pacchettibotti
Published on
2026-11-25T11:14:33Z

One drawing for every flow.

hylograph-flow is a value for pictures of computation: items that hold values, steps that compute, wires between them, and project, which turns a flow into plain nodes and edges. This package draws that projection: a layout of it, by whichever layout engine you hand it (its own is a layered layout, left to right or, since 0.5, top-down), and an SVG of that layout as a HATS tree. It knows nothing about where a flow came from, and the tree knows nothing about which engine laid it out.

Two small spreadsheets drawn as flows: columns as open boxes, formulas as filled lozenges

Two small spreadsheets as flows. Columns are items (open boxes); each column of formulas is a step (a filled lozenge), coloured and noted by the caller's decoration; a dashed edge turns back to close a cycle.

What it does

  • The layout is pluggable. A layout engine is a value: Engine wire holds a name, a function from a Picture and a projection to a Layout, and the laws the engine promises to keep. Any engine's Layout is drawn by the one tree, held to the one set of general laws, and measured by the one set of measures. The package's own engine is sankey metrics widths; it is designed to take two more, a port of ELK's layered algorithm (ports, right-angled routes) and a rewrite of Graphviz dot (clusters, splines, ranks), neither of which it depends on. A second engine of its own, columns spacing scaling (0.4), is for nodes the caller sizes and ports the caller places.
  • A caller may fix a node, and draw its inside (0.4). Tell the picture a node's size and where its ports are (Picture.fixed), and an engine that promises to keep them (KeepsFixed) does, with each route meeting the port it names. Tell the decoration how to draw the node's inside (Decoration.inside, a HATS tree in the node's own coordinates) and the tree draws that in the node's place instead of a box and a label. A table of rows is such a node: only the caller knows how tall it is, and how far down its side each row stands.
  • A layout says where everything is, as data. Placed nodes with their boxes and the ports the engine placed (which port, which side, how far along it); placed edges with the wires each stands for and its route as a value, not a path string: a Ribbon (the Sankey engine's), a Polyline with its line jumps, or a Spline; outlines for open groups; and the direction the flow runs. The SVG path is derived from the route, and so is everything measured of it.
  • One Sankey layout for two pictures. In the Sankey engine every edge has a width. Plain gives each edge one unit and draws it as a hairline: a DAG. Sankey f reads each edge's width from what its wires carry and draws it as wide as it is. The positions come from the same code either way, the Sankey layout of hylograph-layout.
  • Cycles and strays are placed, not refused. An edge that closes a cycle (an edge from a node to itself among them) runs back under the picture in a channel of its own. A node no edge touches stands on a shelf below.
  • The dress is the caller's. Labels, notes, classes and colours come from a Decoration; what an Overlay knows of an element changes its mark; clicks and the pointer's coming and going are reported by element.
  • A closed group is a step like any other, unless the caller says so. hylograph-flow's collapse makes a closed group one step and, where it provides anything, one summary item. They are drawn as steps and items are; withGroups changes their marks by group, and groupOf says which group a clicked element is, for a page that opens a group where it stands.
  • An open group is an outline. Tell the picture the grouping and which groups are closed (what collapse was told) and every open group that holds a drawn node gets a quiet box round its members with its name above them, a group inside it nested in it. No node that is not a member is inside an outline: that is a general law, of every engine. A click on an outline's name is told as PointedGroup, so a page can shut a group where it stands.
  • Words the layout makes room for. Tell the picture what is written in each node (a title, and a line of detail) and the engine wraps the words to the node's breadth and makes the node tall enough. The layout is pure and measures no text: it estimates widths from a table of character classes (Hylograph.Flow.Render.Text says how, and how wrong it can be: measured once in Helvetica Neue, what was drawn was 0.87 to 1.01 of the estimate; more in a face of other proportions).
  • Laws, split by what they are true of. Hylograph.Flow.Render.Laws holds every layout to the general laws (every node placed once, no two boxes overlapping, every route starting and ending on its two nodes and at the port where one is placed, outlines holding their members and nothing else) and an engine's layout to exactly the laws that engine promises (edges with the flow, layers in line, right-angled routes, widths conserved). An engine that conserves no widths is not asked whether it does. Each fault names its law, so your tests can hold the layout of your own flows, or your own engine, to them.
  • Measures. Hylograph.Flow.Render.Measures: crossings, edge length, bends, area and aspect, node overlaps, edges through nodes that are not their ends, edges through outlines they do not end in. Each is defined exactly in the module's header and works on any engine's layout.

Usage

import Prelude

import Data.Maybe (Maybe(..))
import Data.Set as Set
import Effect (Effect)
import Hylograph.Flow (Drawing(..), Flow(..), GroupId(..), ItemId(..), Node, PortName(..), StepId(..), WireId(..), plain, project)
import Hylograph.Flow.Grouping (Grouping(..), collapse)
import Hylograph.Flow.Render.Engine (Engine, Layout, Picture, plainPicture, run)
import Hylograph.Flow.Render.Layout (layout)
import Hylograph.Flow.Render.Sankey (Widths(..), defaultMetrics, sankey)
import Hylograph.Flow.Render.Columns (columns, defaultSpacing)
import Hylograph.Flow.Render.Engine (FixedNode, PortFlow(..), Side(..))
import Hylograph.Flow.Render.Tree (Decoration, plainDecoration, tree)
import Hylograph.HATS (ElementType(Text), Tree, elem, staticStr)
import Hylograph.HATS.InterpreterTick (rerender)

-- Flour and water are mixed into dough.
bakery :: Flow Unit Unit Unit
bakery = Flow
  { items: [ item "flour", item "water", item "dough" ]
  , steps: [ { id: StepId "mix", name: Just "mix", inputs: [ PortName "dry", PortName "wet" ], outputs: [ PortName "out" ], payload: unit } ]
  , wires: map plain
      [ Reads (ItemId "flour") (StepId "mix") (PortName "dry")
      , Reads (ItemId "water") (StepId "mix") (PortName "wet")
      , Writes (StepId "mix") (PortName "out") (ItemId "dough")
      ]
  }
  where
  item name = { id: ItemId name, name: Just name, count: 1, payload: unit }

-- Where everything goes: items and steps both drawn, every edge a hairline.
placed :: Layout Unit
placed = layout defaultMetrics Plain (project Both bakery)

-- The picture, as a HATS tree: one SVG.
picture :: Tree
picture = tree plainDecoration placed

-- In a browser: put the picture in the element with the id `chart`.
draw :: Effect Unit
draw = void (rerender "#chart" picture)

-- The mixing is a group, and it is open: nothing is closed.
kitchen :: Array Grouping
kitchen = [ Group (GroupId "kitchen") "Kitchen" [ Member (StepId "mix"), Holds (ItemId "flour"), Holds (ItemId "water") ] ]

-- What any engine is told beside the projection: the group, and what is
-- written in each node.
setting :: Picture
setting = plainPicture
  { groups = Just { grouping: kitchen, closed: Set.empty }
  , words = Just \node -> { title: node.label, detail: Just "as weighed this morning" }
  }

-- An engine is a value. This is the Sankey engine with narrower nodes;
-- its metrics and widths are its own, not the picture's.
narrow :: Engine Unit
narrow = sankey (defaultMetrics { nodeBreadth = 88.0 }) Plain

-- The kitchen outlined round its three nodes, each tall enough for a
-- title and a line under it; a click on the outline's name is told to the
-- decoration's `notify` as `PointedGroup (GroupId "kitchen")`.
outlined :: Layout Unit
outlined = run narrow setting (project Both (collapse kitchen Set.empty bakery))

-- The mixing step drawn by the caller: 160 by 60, its two inputs a third
-- and two thirds down its left side, its output half way down its right.
mixer :: Node -> Maybe FixedNode
mixer node = case node.label of
  "mix" -> Just
    { width: 160.0
    , height: 60.0
    , ports:
        [ { name: PortName "dry", flow: Input, side: LeftSide, along: 20.0 }
        , { name: PortName "wet", flow: Input, side: LeftSide, along: 40.0 }
        , { name: PortName "out", flow: Output, side: RightSide, along: 30.0 }
        ]
    }
  _ -> Nothing

-- The columns engine keeps that size and those ports; every edge is a
-- ribbon one pixel to a unit, never less than two pixels.
fixedLayout :: Layout Unit
fixedLayout = run (columns defaultSpacing { pixelsPerUnit: 1.0, least: 2.0, unitsOf: const 1.0 }) (plainPicture { fixed = mixer }) (project Both bakery)

-- What is inside the step is the caller's to draw, in its own coordinates.
drawnInside :: Decoration Unit
drawnInside = plainDecoration
  { inside = \node -> if node.label == "mix" then Just (elem Text [ staticStr "x" "12", staticStr "y" "34", staticStr "textContent" "flour and water, mixed" ] []) else Nothing }

fixedPicture :: Tree
fixedPicture = tree drawnInside fixedLayout

This example is compiled and checked with the tests (test/Test/Render/Example.purs).

layout metrics widths is run (sankey metrics widths) plainPicture: the door 0.2 came in by, still open.

For a Sankey, put a quantity on the wires (Flow item step Number, say) and pass Sankey a function from an edge to its width. An edge carries the wires it stands for, so the width of an edge that is one wire is (NonEmptyArray.head edge.wires).payload.

Writing an engine

An engine is Engine { name, promises, layout }, where layout :: Picture -> Projection wire -> Layout wire. To be drawn, its layout need only be a Layout. To be lawful it must keep the general laws, which Laws.generalFaults picture projection layout lists the breaches of:

  • a PlacedNode for each node of the projection, in order, its box inside the picture and clear of every other; the node's words set (Text.setWords, to the breadth the engine gives the node) where the picture gives words, in a box tall enough for them;
  • a PlacedEdge for each edge, in order, whose route starts on the box of the node it is from and ends on the box of the node it is to; where the engine places a step's ports (PlacedNode.ports) and the edge names one, the route meets it there;
  • a PlacedOutline for each open group that holds a node, holding its members under the strip for its name, nested in its parent's, apart from every other, with no stranger in it.

It then promises what more it keeps, from Promise: FlowsForward, LayersAligned, RoutesOrthogonal, WidthsConserved, and since 0.4 KeepsFixed (the sizes and ports the picture fixes) and WidthsScaled (every route a ribbon as broad as its units at a scale, never less than a least breadth). Laws.check engine picture projection layout is the general laws and exactly those. The test suite's Test.Render.Engines has an engine made by hand, and twelve wrong ones, each breaking one law; Test.Render.Columns has two more, each breaking one of the laws 0.4 added.

The modules

Module What it holds
Hylograph.Flow.Render.Engine What any engine makes: Layout, PlacedNode (with ports :: Array PlacedPort), PlacedEdge (with route), PlacedOutline, Direction, Side, PortFlow, portPoint. What every engine is told: Picture (with fixed :: Node -> Maybe FixedNode), plainPicture, FixedNode, Groups, openPaths. An engine as a value: Engine, Promise, run; Scaling and scaledBreadth for WidthsScaled. Its header gives the reason for each decision.
Hylograph.Flow.Render.Columns The columns engine (0.4): columns :: Spacing -> Scaling wire -> Engine wire, Spacing, defaultSpacing. Nodes sized by the picture, in a column for each layer; ribbons from port to port at one scale. Promises FlowsForward, LayersAligned, KeepsFixed, WidthsScaled; draws no outlines. Its header says why it is an engine of its own and not the Sankey engine taught ports.
Hylograph.Flow.Render.Route Route = Ribbon … | Polyline … | Spline …, and what is read from one: start, end, svgPath, flatten, length, bends.
Hylograph.Flow.Render.Sankey The Sankey engine: sankey :: Metrics -> Widths wire -> Engine wire, and since 0.5 sankeyToward :: Direction -> Metrics -> Widths wire -> Engine wire (top-down), with Metrics, Widths, defaultMetrics, widthOf as its own configuration. Pure, so it runs anywhere, without a DOM. Its header says how a group's members are kept together and what hylograph-layout does not offer for it.
Hylograph.Flow.Render.Unfold The unfolding engine (0.6): unfolding :: Direction -> Metrics -> Widths wire -> Whole wire -> Engine wire, Whole, Plan, plan, unfoldingBy, groupBreadth, rankOf. One layout for every cut of a flow, so that two cuts' layouts can be laid side by side.
Hylograph.Flow.Render.Continuity continuity, Continuity(..), change, Change, Bar, opened (0.6): what two layouts of two cuts keep, measured.
Hylograph.Flow.Render.Reshape reshaped, blend, sameShape (0.6): a layout on the way to being another.
Hylograph.Flow.Render.Transition stages, Stage, frame, watched (0.6; watch went in 0.7): a change of cut watched in stages, on hylograph-transitions.
Hylograph.Flow.Render.Present present, quietKeys, quietly, quietClass (0.6): nothing hidden, the folded drawn quiet, never narrower.
Hylograph.Flow.Render.Signal hued, hueOf, groupsOver (0.6): a group's hue on its bar and its parts.
Hylograph.Flow.Render.Motion prefersReducedMotion (0.6). Foreign; needs a window.
Hylograph.Flow.Render.Layout 0.2's door: layout :: Metrics -> Widths wire -> Projection wire -> Layout wire, and the names 0.2 imported from here, re-exported.
Hylograph.Flow.Render.Text estimateWidth, wrap, setWords, Lettering, heightOf, breadthOf: text set without measuring it.
Hylograph.Flow.Render.Keys pressByKeys (0.5): Enter and Space on a focused button of a drawn flow are a click. The one foreign module; needs a document.
Hylograph.Flow.Render.Tree tree :: Decoration wire -> Layout wire -> Tree, of any engine's layout. Items as open boxes, steps as filled lozenges, placed ports as small squares, open groups as outlines; a node whose inside the decoration draws (inside), as that. plainDecoration, withOverlay, withGroups, groupOf, keyName, groupName, strokeOf.
Hylograph.Flow.Render.Laws check, generalFaults, promiseFaults, Law (with FixedKept and Scaled since 0.4), broken; faultsOf, layoutFaultsOf in words alone; faults, layoutFaults as in 0.2 (the Sankey engine's). strangers: the nodes in an outline that is not theirs (the law is that there are none).
Hylograph.Flow.Render.Measures scoreOf, drawnOf, and each measure by name: crossings, edgeLength, bends, extent, area, aspect, nodeOverlaps, edgesThroughNodes, outlineTrespasses, strangersIn, unplaced.

What is drawn, for a stylesheet or a test to find:

svg.flow[data-direction=left-to-right|top-down]
  g.flow-outlines > g.flow-outline[data-group][data-depth]
                      > rect.flow-outline-box, rect.flow-outline-tab, text.flow-outline-label
  g.flow-edges > path.flow-edge.flow-ribbon|.flow-polyline|.flow-spline
                   .flow-band|.flow-hairline[.flow-backward][.flow-swept][data-edge][data-from][data-to]
  g.flow-nodes > g.flow-node.flow-item|.flow-step[.flow-lettered][data-key]
                   > rect.flow-box, rect.flow-swatch?, text.flow-label,
                     text.flow-label-more*, text.flow-detail*, text.flow-note?,
                     rect.flow-port.flow-port-in|.flow-port-out[data-port]*
                 | g.flow-node.flow-drawn[data-key]
                   > g.flow-inside[transform] > (the caller's),
                     rect.flow-port.flow-port-in|.flow-port-out[data-port]*

Changes in 0.7.0

Legibility: what the unfolding engine draws is measured, and the defects the measures and a first look found are mended. Unpublished; branch flow-legibility.

Measures (Measures): crossings now counts a crossing at a corner of either line (two neighbours of a tier that change places scored 0). New, of a Banded (bandedOf a layout and a colour for each edge): overlaps and overlapsInOneColour, proportions and squat, pictureProportion, againstTheFlow; inkOf; and thresholds, the guesses they are held against, in one place.

The unfolding engine (Unfold):

  • Tied outlines. An open group whose parts stand in separate runs of tiers is a piece for each run, each as broad as what is in it; nothing is kept for it in the tiers between. A layout then has one PlacedOutline for each run (Engine.runsOf, runAt). Order is kept in every pair of cuts of the 60 made flows; rungs move both ways.
  • Seams. Plan.parts, seams: a closed bar's parts where they are abreast, each marked where it only receives or only gives; and a ribbon on such a bar stands in its part where the order allows.
  • Room along the flow. One gap between tiers for every cut, asked of the proportion (Plan.room), and heldTo a length.
  • Ribbons turned back stay in the picture: a turn as wide as the ribbon needs, and margins to hold it. Promised (StaysWithin) and checked (Laws.InkWithin).
  • The hair. A ribbon under thresholds.hair is inked Least: drawn that broad, its breadth still the data's. Laws.notToScale lists them, and the conservation laws fault one that claims it wrongly.
  • gathered: the parallel ribbons from a closed group as one (give the engine a width that adds over an edge's wires).

The tree (Tree.treeWith, Dress): direction marks on ribbons turned back; a ribbon not to scale dashed, with a break mark; seams and walls on a closed bar; group names as headings, closed and open in one place, parts' labels subordinate; a name on each run of a tied outline and a tie between them. tree and treeLabelled draw what they drew.

Colour (Signal): palette (five hues that pass a validator on all pairs for colour-blind readers), shade, coloured.

Transitions: Transition.watch is gone; a page runs watched's spec with hylograph-transitions' own transitionConsumer (0.1.1). The package no longer depends on refs.

Breaking: Transition.watch removed; Route.Ink has a third constructor (Least), Engine.Promise a ninth (StaysWithin), Laws.Law a new one (InkWithin); Unfold.Plan has two more fields; the law Outlined allows several outlines to a group (each member in exactly one); Measures.crossings counts more; the unfolding engine's layouts are not 0.6.0's (the gap between tiers, tied outlines, where ribbons stand on a seamed bar, margins for turns). The Sankey and columns engines' layouts are unchanged. The Sankey engine does not promise StaysWithin and does not keep it: a broad ribbon it turns back can still leave its picture.

Changes in 0.6.0

Not published. Stages 1 and 2 of docs/kb/plans/flow-unfolding.md: one chart that holds the most detail and shows as much as is wanted. Made against a lab page (sverdrup-unfold) that opens and closes the groups of three data sets; everything here is held by this package's own tests on flows made by rule, and by that page's on its own.

What 0.5.0 said was not here is here: a group opened in place, with the rest of the picture keeping its place.

Added:

  • The unfolding engine (Hylograph.Flow.Render.Unfold): unfolding :: Direction -> Metrics -> Widths wire -> Whole wire -> Engine wire, where Whole = { grouping, finest } is the flow whatever the cut: its grouping and its projection with nothing closed. It is run, like any engine, on the projection of any cut (collapse grouping closed flow) with the picture told which groups are closed. Every cut's layout is a function of the cut alone, made of three things no cut changes: one order across the flow in which every group's nodes are neighbours; one breadth for each group, the heaviest set of its nodes and inner ribbons no two of which are on one path (or what crosses its boundary one way, where that is more), which is the breadth of its bar when it is closed and of its band when it is open; and one rule for gaps (nodeGap between top-level blocks, nothing between the parts of one). The placing is a packing, with no relaxation. A node that feeds nothing stands in the last tier. Its header says exactly what is kept and what is not. It promises FlowsForward, LayersAligned and WidthsCarried, sets no words, and is made left to right and stood on end for top-down, as the Sankey engine is.
  • Hylograph.Flow.Render.Continuity: continuity :: Layout wire -> Layout wire -> Continuity, the best rung two layouts of two cuts keep, measured from the two layouts alone: Held (every untouched node keeps its box exactly), Nested (each opened group's parts lie within the span its closed bar had), Ordered (no two nodes of a tier and no two ribbons at a node change order), Rearranged (none of these). change gives everything measured (the nodes that moved, each bar with its breadth and the slot its parts need, what is unaccounted for, each breach of order in words); opened pairs each bar with its parts.
  • Promise.WidthsCarried and Law.Carried: as WidthsConserved and Conservation, but a node is at least as broad as its broader side. A closed group can be broader than its ribbons: a loop inside it, or a spring beside a dead end, is more than crosses its boundary.
  • Hylograph.Flow.Render.Reshape: reshaped (a layout with its boxes moved and its ribbons gone with the sides they stand on) and blend (two layouts of one shape, part of the way from one to the other). What they keep is conservation: a ribbon is as broad as it was and stands where it stood on its node's side.
  • Hylograph.Flow.Render.Transition: stages of a change between two cuts (make room, then unfold; fold, then close up), each two layouts of one shape; frame (the picture part of the way through); watched (the stages as a TransitionSpec of hylograph-transitions' engine) and watch (one run on its Coordinator). No clock of its own.
  • Hylograph.Flow.Render.Present: Present mode. present shortens the nodes of the quiet groups along the flow and never narrows anything; quietly marks them flow-quiet.
  • Hylograph.Flow.Render.Signal: hued and hueOf: a group's hue on its bar and on its parts.
  • Hylograph.Flow.Render.Motion: prefersReducedMotion (the second foreign module).
  • Tree.treeLabelled :: Labels -> Decoration wire -> Layout wire -> Tree (Within, as ever, or Beside least: each label beside its bar, on the paper; none for a bar under least pixels; steps as bars with square corners). tree = treeLabelled Within.
  • Sankey.stoodOnEnd exported (a left-to-right layout stood on end).
  • An outline with no strip for its name (PlacedOutline.header of 0, which only the unfolding engine makes, for a group inside a group) has its name written up its own margin along the flow, or on its top edge after the names over it where it has no such margin. An outline with a strip is drawn as it was.

Not here: a grouping over what wires carry (stage 3), choosers of a cut (stage 4), tier elision (stage 5); a transition for a change that opens some groups and closes others (take it one group at a time); tiers of a quiet group drawn nearer together in Present mode.

Breaking, against 0.5.0:

  • Promise has the constructor WidthsCarried, and Law the constructor Carried, so a case over either without a wildcard needs a branch for it.
  • The package depends on hylograph-transitions (0.1.0, which hylograph-selection already brought) and on refs.
  • Nothing else: Decoration, Picture, Layout and every engine there was are as they were. Every layout the Sankey engine makes is, to the number, what 0.5.0 made, left to right and top-down (240 layouts of the suite's made flows, compared by digest before and after), and 0.5.0's suites pass unchanged.

Changes in 0.5.0

Not published. Made for a page that draws two Sankey diagrams side by side, each running down into a stack of counted symbols (sverdrup-cars, the thinned page); everything here was wanted by that page and is held by this package's own tests.

Added:

  • The Sankey engine top-down: sankeyToward :: Direction -> Metrics -> Widths wire -> Engine wire, and sankey = sankeyToward LeftToRight. Top-down the layers are rows, a node is as broad as the broader of what enters and leaves it, and every edge not turned back runs down the page. The layout is the left-to-right one stood on end (the same placing, order, lanes and channels), and it promises the same three laws, which Laws reads by the layout's direction. Four things are done otherwise top-down, and Sankey's header says each exactly:
    • a node's words make it broader, not taller: they are wrapped to nodeBreadth and the node is as broad as its ribbons or as its widest line needs (Text.breadthOf), so a thin ribbon under a long name has a node as broad as the name and two names cannot collide;
    • every node is as tall as the tallest words of any (restHeight where the picture sets none), so a layer is one row;
    • an outline's strip is before its first row, in the gap between layers, and where the gap has not room the strip and the padding are less in proportion (PlacedOutline.header says what the strip is);
    • the margins are only what is used: none for a picture of forward edges with no outline, which begins at its first row and ends at its last, so a page can stand something directly under it.
  • Top-down, the layers are straightened after room is made. Making room for words and outlines moves boxes one way only, after the Sankey layout has placed each layer against its neighbours; a row of thin ribbons under long names was left spread out over a next row that had not moved, every ribbon slanting the same way. Each layer is now moved once more, whole, by the breadth-weighed mean of how far its edges from earlier layers are from straight (the layers an outline spans move as one). Left to right this is not done, so that no picture made before 0.5 moves.
  • Laws: Conservation reads what a node's words need across the flow by direction (their height left to right, their breadth top-down). No new law and no new promise: a downward Sankey is held to the laws a Sankey is held to.
  • Route.transpose (a route with x for y at every point) and Route.sweptPath (a ribbon as the outline of the area it sweeps across the flow).
  • Decoration.bands :: Bands (Stroked, the default, or Swept). A band was always one path stroked as broad as the ribbon. A stroke is broad across the line, not across the flow: a ribbon 200 pixels broad that shifts 150 across in a run of 90 is too thin in the middle and bulges past both nodes at its ends. Swept draws a band that runs forward as the filled area its span on its source sweeps to its span on its target: flat on both nodes, its breadth across the flow all the way. Its mark has the class flow-swept, a fill and no stroke, so a stylesheet that colours ribbons by stroke must colour these by fill. A band turned back, and a ribbon of 3 pixels or less, are stroked either way.
  • The keyboard: Decoration.button :: Pointed -> Maybe String makes a mark focusable and a button for a screen reader, with the name given; Hylograph.Flow.Render.Keys.pressByKeys (the package's one foreign module) makes Enter and Space on a focused button a click, told as any click is. HATS has behaviours for clicks and the pointer and none for a key, which is why the second half is a listener on a container and not a behaviour on the mark.

What was asked for and is not here: a group opened in place, with the rest of the picture keeping its place. collapse gives the contracted flow and the open one, and an open group is outlined; but each is laid out afresh, and nothing holds what is outside the group where it stood (the open row is wider, and the Sankey relaxation places every layer again). On the flows this was made for the order across the flow was the same open and closed in every case tested; that is an observation of those flows and not a promise of the engine. Keeping places would mean laying out the open flow first and drawing the contracted one in the places it leaves, which no engine here does.

Breaking, against 0.4.0:

  • Decoration has the fields button and bands. Code that builds one from plainDecoration with a record update is unaffected; code that writes one out as a whole record must add button: const Nothing and bands: Stroked.
  • Top-down only: nothing made a top-down Sankey before, so nothing moves. Every left-to-right layout is, to the number, what 0.4.0 made (sankeyToward LeftToRight against sankey on every made flow is in the suite; the left-to-right suites are unchanged and pass).

Changes in 0.4.0

Added, for a node the caller sizes and draws (a table of rows, whose height and whose rows' places only the caller knows):

  • Picture.fixed :: Node -> Maybe FixedNode, where FixedNode = { width, height, ports :: Array PlacedPort }: a node's size and its ports' places, fixed by the caller. plainPicture fixes nothing.
  • Two promises and their laws. KeepsFixed (law FixedKept): every fixed node has the size and exactly the ports it was given; that each route meets its port was already the general law Routed. WidthsScaled scaling (law Scaled): every route is a ribbon as broad as its units at scaling.pixelsPerUnit, and never less than scaling.least (scaledBreadth). Unlike WidthsConserved it says nothing of how tall a node is, which an engine that keeps the caller's sizes cannot promise (a table of 240 rows gives one total). Neither is a general law: the Sankey engine's sizes are its widths, and it is not asked to keep a fix.
  • The columns engine (Hylograph.Flow.Render.Columns): columns spacing scaling. Layers by longest path, with a node nothing enters moved to the layer before the first it feeds; a column for each layer, each node centred in it; nodes pulled down the page towards the ports at the other ends of their edges; one cubic ribbon for each edge, from port to port where the node has the port placed. It promises FlowsForward, LayersAligned, KeepsFixed and WidthsScaled. It draws no outlines: told of open groups, it breaks the general law Outlined, and its tests say so. Spacing.deepest :: Maybe Number says how far under the top of the picture a node may begin, where its column has room: a node that feeds the middle of a node thousands of pixels tall is otherwise pulled level with that middle, under the first screenful. Nothing (the default) raises nothing.
  • Decoration.inside :: Node -> Maybe Tree: a node's inside, drawn by the caller in the node's own coordinates. The tree draws it in a g.flow-inside moved to the node's box, with the node's port squares, and no box, label, words, swatch or note of its own; the node's mark has the class flow-drawn.

Strands: several strands between two nodes (a feed split by a mark) are several edges, each through an item of its own, each meeting a port of its own. One edge drawn as bands was the other way, and was not taken: an edge is one path of wires, so its parts would have had no wires of their own, and the laws and measures would have counted one route where the picture shows several.

Breaking, against 0.3.1:

  • Picture has a field fixed, and Decoration a field inside. Code that builds either from plainPicture or plainDecoration with a record update is unaffected; code that writes one out as a whole record must add fixed: const Nothing or inside: const Nothing.
  • Promise has the constructors KeepsFixed and WidthsScaled, and Law the constructors FixedKept and Scaled, so a case over either without a wildcard needs branches for them.

Changes in 0.3.1

crossings no longer counts two edges meeting at a node they share: a proper crossing of two edges with a node in common, within skin (1 pixel) of where each ends at that node, is a meeting (two edges into one port whose ends were computed a hair apart scored one crossing before). Every other crossing counts as before. Hand-counted cases of edges leaving one node, arriving at one node, bowed in parallel between two nodes, and changing sides after a shared start are in the suite.

Changes in 0.3.0

Added: the layout is pluggable (Engine, Promise, run, Picture, plainPicture); routes as data (Hylograph.Flow.Render.Route); placed ports; the layout's direction; open groups outlined (Groups, PlacedOutline, openPaths, PointedGroup); words set and made room for (Hylograph.Flow.Render.Text); laws split into general and promised (check, Law, generalFaults, promiseFaults, faultsOf, layoutFaultsOf, strangers); Hylograph.Flow.Render.Measures; groupName, strokeOf. layout, faults and layoutFaults have the types they had and place every node where they did.

Breaking, against 0.2.0:

  • A placed edge has a route and no path, start, end, width or stroke. Read them from the route: Route.svgPath e.route, Route.start e.route, Route.end e.route, Tree.strokeOf e.route; a Sankey edge's width is its ribbon's breadth.
  • Layout has the fields direction and outlines, and PlacedNode the fields words and ports. Code that reads a layout is unaffected; code that makes one by hand must supply them (direction: LeftToRight, outlines: [], words: Nothing, ports: []).
  • Pointed has a third constructor, PointedGroup GroupId, so a case over Pointed without a wildcard needs a branch for it. (It is told only where the picture gave groups.)
  • The tree's root has three children where it had two: g.flow-outlines comes first, and is empty unless groups were given. A stylesheet or test that takes the root's first child for the edges must select by class.
  • An edge's d is written differently, and draws the same line. It is derived from the route: one M and then every piece (0.2 began each piece of a long edge with an M of its own), numbers at their shortest (10, where 0.2 wrote 10.0 in forward edges). A test that compared the string to one written down must compare to Route.svgPath.
  • Metrics, Widths, defaultMetrics and widthOf are the Sankey engine's (Hylograph.Flow.Render.Sankey). They are still exported from Hylograph.Flow.Render.Layout, so an import from there compiles; the types PlacedNode, PlacedEdge, Layout, Course, Box, Point are likewise re-exported from where they now live (Hylograph.Flow.Render.Engine).
  • faults holds a layout to one law 0.2 did not state: every route starts and ends on the boxes of its edge's two nodes. The Sankey engine's layouts keep it; a layout made by hand may not.

Installing

spago install hylograph-flow-render

It depends on hylograph-flow (0.2.0 or later), hylograph-layout (0.6.0 or later), hylograph-graph (0.3.1 or later), hylograph-selection (0.6.0 or later) and hylograph-transitions (0.1.0 or later), and on arrays, effect, foldable-traversable, integers, maybe, numbers, ordered-collections, prelude, refs, strings and tuples. It does not depend on any other layout engine: an engine built on another library lives with that library's user.

Running the tests

spago test

The suite runs in Node, with no browser. It holds the Sankey engine to the general laws and to each law it promises on flows made for their shapes (with and without a cycle, with an edge from a node to itself, with nodes no edge touches), plain, by quantity, and with widths varied from edge to edge; on groupings made for theirs (two sibling groups, a group in a group, a group whose members are layers apart, a group of one, a group with members no edge touches, an open group over a closed one), with and without words. It makes a second engine by hand (ports, right angles, no widths) and twelve wrong ones, and checks that each wrong engine breaks exactly the law it was made to break. It holds the columns engine (0.4) to the general laws and its four promises on the same flows, with no node fixed and with every node fixed; to widths and ports worked out by hand; and makes two wrong columns engines, each breaking one of FixedKept and Scaled and nothing else. It holds the Sankey engine top-down (0.5, Test.Render.Down) to the same general laws and promises on every one of those flows and groupings again, and then to what top-down means: that it is the left-to-right layout stood on end where nothing asks for more, its margins, its words, its outline's strip, its layers straightened; and a top-down layout spoiled in one way fails the law that way is against. It holds the measures and the routes to figures worked out by hand (two edges that cross count one crossing; an L has one bend and its two legs' length; a route's SVG path is the string written down). And it reads the HATS tree back, checking one mark for each placed node, one path for each placed edge along its route, one square for each placed port, one outline for each open group, either direction, and the caller's decoration, overlay and gestures on the element they were said of. And it holds the unfolding engine (0.6, Test.Render.Unfold) on sixty flows made by rule from a seed (Test.Render.Generated: layered, with a nested grouping whose groups take their members from any tiers), both directions: every cut of each (1,122) to the general laws and the engine's promises; every pair of cuts that differ by one group (2,667) to order, with no pair Rearranged; the parts of an opened group to a slot as broad as its bar wherever that is promised; every rung continuity gives checked again straight from the boxes; the open layout with two nodes made to change places Rearranged every time; every change watched, eleven pictures through it, each carrying its widths and meeting its nodes; and Present mode narrowing nothing.

Licence

MIT.