Module

Hylograph.Flow.Render.Route

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

The line an edge is drawn along, as data.

In 0.2 a placed edge held an SVG path string. A string can be drawn and nothing else: to measure an edge an earlier layout trial had to parse the string back, and a second layout engine had to print its routes as strings only for them to be read again. Here the route is a value, the string is derived from it (svgPath), and so are the points it is measured along (flatten).

THE THREE ROUTES. Route is closed, and has exactly the routes of the three engines this renderer is built to take. None is there for an engine nobody has.

  • Ribbon, the Sankey layout's: a centre line of straight and cubic pieces, and a breadth, the room the edge takes on the side of each node it touches (its two attachment spans are the centre line's two ends, half the breadth either way across the flow). The Sankey layout's ribbons are as broad at one end as at the other, so the width profile is one number; an engine that tapers one would need a profile here, and none of the three does. ink says how the ribbon is drawn: a Band as broad as it is, or a Hairline down its middle. It is an ADT and not a second number because a stroke beside a breadth is two numbers that can disagree, and in a band they are one.
  • Polyline, layered-layout's: straight legs from point to point, and its line jumps (where it hops over an edge it crosses). That the bends are right angles is not in the type: that engine's routes through nested groups are joined at the group's boundary and may slant by a pixel or two there, so right angles are a promise an engine makes and a law checks (RoutesOrthogonal), not a constructor.
  • Spline, Graphviz dot's (Stemma): cubic Bézier pieces end to end.

NO ROUTE WITHOUT A LINE. Each constructor has a first point and at least one more (a NonEmptyArray of pieces, or a to), so an edge that is placed has somewhere to be drawn; an engine that cannot route an edge leaves the edge out, and the law that every edge is placed says so. The trial's unrouted measure counted polylines of fewer than two points; there is no such value now.

MEASURING. flatten is the one rule by which every route becomes straight pieces: a straight piece is its two ends, a cubic piece is curveSteps (12) straight pieces, and a cubic whose four points lie on one line is one. It is the trial's rule (it read the same pieces back from the path string), kept so that its figures stand. A polyline's jumps are ink, not geometry: they are drawn and not measured.

#Point Source

type Point = { x :: Number, y :: Number }

#Curve Source

type Curve = { arriving :: Point, leaving :: Point, to :: Point }

A cubic Bézier piece from where the line has got to: it leaves towards leaving, arrives from arriving, and ends at to.

#Piece Source

data Piece

One piece of a ribbon's centre line, from where the last piece ended.

Constructors

Instances

#Ink Source

data Ink

How a ribbon is drawn: as broad as it is, or as a line of this stroke down its middle.

Constructors

Instances

#Route Source

data Route

Constructors

Instances

#start Source

start :: Route -> Point

Where a route leaves its source.

#end Source

end :: Route -> Point

Where a route enters its target.

#flatten Source

flatten :: Route -> Array Point

A route as the points of its straight pieces, first to last; see the module's header for the rule. A point is not given twice running.

#flattenPieces Source

flattenPieces :: Point -> Array Piece -> Array Point

A line of pieces from a point, as points.

#curveSteps Source

curveSteps :: Int

Straight pieces to a cubic piece.

#length Source

length :: Route -> Number

A route's length along its straight pieces, pixels.

#turning Source

turning :: Array Point -> Number

How far a line of points turns, in radians: the sum over every interior point of the angle turned there.

#bends Source

bends :: Route -> Number

A route's total turning in right angles: one for each corner of an orthogonal route; for a curve, by how far it swings.

#numbers Source

numbers :: Route -> Array Number

Every number a route is made of, for a law that each is finite.

#svgPath Source

svgPath :: Route -> String

A route as the d of an SVG path: absolute M, L and C, and for a polyline's jumps A. A jump is drawn as a half circle of hopRadius where it lies on a leg with that much of the leg clear on either side of it (of the leg's ends and of the jump before); a jump with less room is passed straight through.

#hopRadius Source

hopRadius :: Number

The radius of the hop a polyline makes over an edge it crosses.

#distance Source

#cross Source

cross :: Point -> Point -> Point -> Number

Twice the signed area of the triangle a, b, c.