Module

Hylograph.Flow.Render.Measures

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

Measures of a drawn graph, whoever laid it out: the scoreboard of an earlier layout trial, here so that every engine is scored by one rule.

Every measure is a function of a Drawn and nothing else: node boxes, each edge as the straight pieces it is drawn along, and the boxes of the open groups' outlines with their members. drawnOf makes a Drawn of any Layout, each route by Hylograph.Flow.Render.Route.flatten: a straight piece is its two ends, a cubic curve is curveSteps (12) straight pieces. So a ribbon, a dog-leg and a spline are measured by one rule, and no engine's own counts are used. A Drawn can also be made by hand, which is how the measures are held to figures worked out on paper. (The trial read each edge back from its SVG path; the pieces are the same, so its figures stand.)

THE MEASURES, exactly, as the trial stated them.

  • crossings: the number of points at which a piece of one edge's line properly crosses a piece of another edge's: each piece's two ends strictly on opposite sides of the other piece. Touching does not count: two edges that leave one point, an edge that turns exactly on another, and two edges that run along one line (a shared trunk) cross nowhere. Two edges that cross twice count twice. Nor does meeting at a shared end: where the two edges have a node in common and the point of crossing is within skin (1 pixel) of where each of them ends at that node, they meet there, as two edges into one port do when their ends are computed a hair apart; any other crossing of two edges with a node in common counts. (Since 0.3.1; before, such a meeting counted one.) A crossing at a point where a line is cut into pieces counts too (0.7): where one line has a corner on the other (on a corner of it, or within one of its pieces) and the two pieces either side of that corner lie strictly on opposite sides of the other line there, the lines cross once. Until 0.7 that was a touch and scored nothing, which missed the commonest crossing a layered layout has: two neighbours of a tier that change places on the way to the next cross exactly at the middle of their two curves, and the middle is where a curve is cut. A corner that touches and turns back, and two lines that share a stretch, still cross nowhere.
  • edgeLength: the sum of the lengths of every edge's line, pixels.
  • bends: total turning, in right angles: the sum over every interior point of every line of the angle turned there, divided by 90 degrees. An orthogonal route scores one for each corner; a curve scores by how far it swings (an S that reaches 45 degrees and comes back scores one), and a straight line nothing.
  • extent: the box round every node, outline and edge point; area is its width times its height, in pixels squared, and aspect its width over its height.
  • nodeOverlaps: the pairs of node boxes with more than a touch in common (more than skin, 1 pixel, each way).
  • edgesThroughNodes: the pairs of an edge and a node that is neither of its ends, where the edge's line enters the node's box drawn in by skin on every side.
  • outlineTrespasses: the pairs of an edge and an outline where neither end of the edge is a member of the outline's group and the edge's line enters the outline's box drawn in by skin. (An edge with an end inside must cross the outline, and is not counted.)
  • strangersIn: the pairs of an outline and a node that is no member of it and is in its box or partly in it: the general law (Hylograph.Flow.Render.Laws.strangers), counted.
  • unrouted: the edges with no line (fewer than two points). No route of a Layout is such (Route cannot be), so of a layout this is 0 unless a route's points are all one point; it is here for a Drawn made otherwise. An edge an engine left out altogether is the laws' to report (Placed), and unplaced counts them.

Time to lay out is not here: it is measured by whoever runs the layout.

THE MEASURES OF LEGIBILITY (0.7). The measures above score a drawing as a graph. These score it as something a general reader has to follow, by four heuristics that are guesses (Andrew's word) and are here to be calibrated; the numbers they are held against are thresholds, in this one place. They need what a Drawn has not: how broad each ribbon is, what colour it is drawn in, and which way the flow runs. That is a Banded (bandedOf makes one of a layout and a colour for each edge; it can be made by hand).

  • overlaps: the pairs of ribbons that cross (their middle lines, by crossings' rule) or overlie one another (their ink has more than thresholds.overlap square pixels in common), each with that area. overlapsInOneColour are those drawn in one colour: the ones a reader cannot follow through. The area is exact where both ribbons are swept bands (flat across the flow: a forward ribbon as the tree's Swept draws it); a ribbon drawn as a stroke (turned back, or a hairline) is taken piece by piece and its corners counted twice, so its areas are a little over.
  • proportions: of each ribbon, its run along the flow, its breadth (the data's, not the ink's), and how far it travels across the flow; squat are those whose run is less than thresholds.proportion times its breadth, or times its travel.
  • pictureProportion: the picture's length along the flow over its breadth across it.
  • againstTheFlow: the ribbons that anywhere run backward along the flow by more than thresholds.against pixels in all, read from their lines and not from what the engine says of them.

#Drawn Source

type Drawn = { edges :: Array DrawnEdge, nodes :: Array Box, outlines :: Array DrawnOutline }

#DrawnEdge Source

type DrawnEdge = { from :: Int, points :: Array Point, to :: Int }

from, to: the places of the edge's two nodes in nodes.

#DrawnOutline Source

type DrawnOutline = { box :: Box, members :: Array Int }

#Score Source

type Score = { area :: Number, aspect :: Number, bends :: Number, crossings :: Int, edgeLength :: Number, edges :: Int, edgesThroughNodes :: Int, height :: Number, nodeOverlaps :: Int, nodes :: Int, outlineTrespasses :: Int, strangers :: Int, unrouted :: Int, width :: Number }

#drawnOf Source

drawnOf :: forall wire. Layout wire -> Drawn

A layout as drawn: its node boxes in the layout's order, its edges as their routes' straight pieces, its outlines.

#scoreOf Source

scoreOf :: forall wire. Layout wire -> Score

Every measure of a layout.

#crossings Source

#edgeLength Source

#extent Source

#nodeOverlaps Source

#edgesThroughNodes Source

#outlineTrespasses Source

#strangersIn Source

strangersIn :: Drawn -> Int

The pairs of an outline and a node that is no member of it and is in its box or partly in it, to a millionth of a pixel: the count of what Hylograph.Flow.Render.Laws.strangers lists.

#unrouted Source

#unplaced Source

unplaced :: forall wire. Projection wire -> Layout wire -> Int

The edges of a projection that a layout of it gave no place.

#skin Source

skin :: Number

How far inside a box an edge must come to be in it, and how much two boxes must share to overlap: 1 pixel.

#Thresholds Source

type Thresholds = { against :: Number, hair :: Number, nameReach :: Number, overlap :: Number, proportion :: Number }

What the measures of legibility are held against, and what the engines and the tree take from them. Guesses, to be calibrated.

  • proportion: a ribbon, and a picture, should be at least this many times as long along the flow as it is broad across it (and a ribbon that many times as long as it travels across).
  • overlap: two ribbons overlie one another when their ink has more than this in common, in square pixels.
  • against: a ribbon runs against the flow when it runs backward by more than this, in pixels.
  • hair: a ribbon less broad than this, in pixels, cannot be seen; the unfolding engine draws it this broad and says it is not to scale.
  • nameReach: an open group's name should be within this of where its closed bar's name was, in pixels.

#Band Source

type Band = { breadth :: Number, colour :: String, edge :: Int, from :: Int, ink :: Number, points :: Array Point, swept :: Boolean, to :: Int }

A ribbon as it is drawn. edge: its index in the layout. from, to: the places of its two nodes among the layout's nodes (-1 where it has none). breadth: the data's. ink: how broad it is drawn. swept: drawn flat across the flow (a band going forward), not as a stroke along its line.

#Banded Source

type Banded = { bands :: Array Band, direction :: Direction, height :: Number, width :: Number }

#bandedOf Source

bandedOf :: forall wire. (PlacedEdge wire -> String) -> Layout wire -> Banded

A layout's ribbons as drawn, each in the colour it is given. A band going forward is taken as swept, as the unfolding pages draw it (Tree.Swept); a route that is no ribbon is a line 1.25 broad (Tree.hairline).

#inkOf Source

inkOf :: Direction -> Band -> Array (Array Point)

The same, by its public name: the corners of a ribbon's ink, piece by piece, for a law that the ink is inside the picture.

#Overlap Source

type Overlap = { area :: Number, colour :: String, crossings :: Int, one :: Int, other :: Int, otherColour :: String }

Two ribbons that cross or overlie one another. one, other: their edges' indices, the lesser first. area: the ink they have in common. crossings: how many times their middle lines cross.

#overlapsInOneColour Source

overlapsInOneColour :: Banded -> Array Overlap

The overlaps a reader cannot follow: both ribbons in one colour.

#Proportion Source

type Proportion = { breadth :: Number, byBreadth :: Number, byTravel :: Number, edge :: Int, run :: Number, travel :: Number }

A ribbon's shape. run: how far its line reaches along the flow. travel: how far it reaches across it. byBreadth, byTravel: the run over each (as great as can be where there is none of it).

#squat Source

squat :: Banded -> Array Proportion

The ribbons too broad, or too steep, for their run: under the threshold on either count.

#pictureProportion Source

pictureProportion :: Banded -> Number

The picture's length along the flow over its breadth across it.

#againstTheFlow Source

againstTheFlow :: Banded -> Array Int

The ribbons that run against the flow, by their edges' indices.