Liking cljdoc? Tell your friends :D

vaelii.browser.svg

The inline-SVG primitives the browser's graphs are drawn with: a node, an edge, an arrowhead, and the arithmetic that lays out layered rows, a relation flank, a column or a ring. faults lists the overlaps and crossings in a finished picture.

No graph library. The browser ships two JavaScript files and this adds none, and no shell-out: a page that renders by starting a process is a page that cannot be served.

Everything here is pure — no KB, no access facade, no belief — so it is tested on hand-built maps. What a node means is the caller's: it supplies the term, the colour class, the link and the tooltip, and this decides only where the box goes and what shape it is.

Coordinates live in one flat user space and may be negative; scene crops the viewBox to the union of what was actually drawn. Every number reaching an attribute is a long: Clojure's / yields a ratio, and 1/2 in an SVG attribute is not a coordinate.

The inline-SVG primitives the browser's graphs are drawn with: a node, an edge, an
arrowhead, and the arithmetic that lays out layered rows, a relation flank, a column or
a ring.  `faults` lists the overlaps and crossings in a finished picture.

**No graph library.**  The browser ships two JavaScript files and this adds none, and
no shell-out: a page that renders by starting a process is a page that cannot be served.

Everything here is **pure** — no KB, no access facade, no belief — so it is tested on
hand-built maps.  What a node *means* is the caller's: it supplies the term, the
colour class, the link and the tooltip, and this decides only where the box goes and
what shape it is.

Coordinates live in one flat user space and may be negative; `scene` crops the
`viewBox` to the union of what was actually drawn.  Every number reaching an attribute
is a **long**: Clojure's `/` yields a ratio, and `1/2` in an SVG attribute is not a
coordinate.
raw docstring

arcclj

(arc nodes cx cy r a)

Place measured nodes on a short arc of radius r centred on angle a around (cx, cy). An arc in one direction puts a neighbour's own neighbours out past it.

The angular step is derived from the widest box exactly as ring's radius is: the arc between two of them is 1.1× the widest, so a cluster of long names spreads and a pair of short ones stays tight.

Place measured `nodes` on a short arc of radius `r` **centred on angle** `a` around
(`cx`, `cy`).  An arc in one direction puts a neighbour's own neighbours out past it.

The angular step is derived from the widest box exactly as `ring`'s radius is: the arc
between two of them is 1.1× the widest, so a cluster of long names spreads and a pair of
short ones stays tight.
sourceraw docstring

arrow-tonesclj

The arrowhead markers, one per stroke colour, keyed by the :tone an edge carries: nil for the muted stroke, :sub for a subsumption edge, :disjoint for a disjoint edge. A marker paints its own fill, so each stroke colour needs its own marker.

The arrowhead markers, one per stroke colour, keyed by the `:tone` an edge carries:
nil for the muted stroke, `:sub` for a subsumption edge, `:disjoint` for a `disjoint`
edge.  A marker paints its own fill, so each stroke colour needs its own marker.
sourceraw docstring

clear-labelsclj

(clear-labels {:keys [nodes edges] :as scene})

Move each edge label of scene, in edge order, to a place 3 px clear of every edge segment, every node and every label placed before it. A label already clear stays at its label-anchor. Otherwise it goes to the first clear place 6, 12, 24 or 48 px right of, left of, above or below the middle of a segment of its edge, tail first. A label with no clear place stays where it was.

Move each edge label of `scene`, in edge order, to a place 3 px clear of every edge
segment, every node and every label placed before it.  A label already clear stays at
its `label-anchor`.  Otherwise it goes to the first clear place 6, 12, 24 or 48 px right
of, left of, above or below the middle of a segment of its edge, tail first.  A label
with no clear place stays where it was.
sourceraw docstring

columnclj

(column nodes x-edge y gap side)

Place measured nodes in a vertical column, stacked gap apart and centred on y. side is -1 for a column to the left of x-edge (its right edge there) and 1 for one to the right, so the two flanks mirror without the caller doing the arithmetic twice.

Place measured `nodes` in a vertical column, stacked `gap` apart and centred on `y`.
`side` is -1 for a column to the *left* of `x-edge` (its right edge there) and 1 for one
to the right, so the two flanks mirror without the caller doing the arithmetic twice.
sourceraw docstring

faultsclj

(faults {:keys [nodes edges frames]})

The faults of the finished picture scene, one string each. A fault is two boxes that overlap, an edge segment through a box it does not end at, a node label wider or taller than its box, or a frame label outside its frame. A card row (measure-card) whose text is larger than the row, or which runs past its card, is a fault too. A box is a node's, an edge label's or a frame label's, and a :mark? node has no label. The vector is empty for a picture with none.

The faults of the finished picture `scene`, one string each.  A fault is two boxes that
overlap, an edge segment through a box it does not end at, a node label wider or taller
than its box, or a frame label outside its frame.  A card row (`measure-card`) whose text
is larger than the row, or which runs past its card, is a fault too.  A box is a node's,
an edge label's or a frame label's, and a `:mark?` node has no label.  The vector is
empty for a picture with none.
sourceraw docstring

flankclj

(flank centre items {:keys [gap reach lane-pad]})

Place the relation flank beside the placed centre: each of items ({:node measured :label s :side -1|1}) in a column on its side, centred on the centre's height, gap apart. Between a column and the centre is a lane as wide as that side's widest label plus lane-pad each side, then reach px of open space. An item's route runs from its node's inner side straight across the lane, with the label over it, then to a port on the centre's side; ports are spread over the side in the columns' order. Returns the items in order, each with its placed :node, its :points from the node to the centre and its :label-at.

Place the relation flank beside the placed `centre`: each of `items` (`{:node measured
:label s :side -1|1}`) in a column on its side, centred on the centre's height, `gap`
apart.  Between a column and the centre is a lane as wide as that side's widest label
plus `lane-pad` each side, then `reach` px of open space.  An item's route runs from its
node's inner side straight across the lane, with the label over it, then to a port on
the centre's side; ports are spread over the side in the columns' order.  Returns the
items in order, each with its placed `:node`, its `:points` from the node to the centre
and its `:label-at`.
sourceraw docstring

flank-heightclj

(flank-height items gap)

How tall the taller of the two flank columns of items (see flank) stands.

How tall the taller of the two flank columns of `items` (see `flank`) stands.
sourceraw docstring

framedclj

(framed {:keys [nodes edges] :as scene} lines class)

scene ({:nodes :edges}) inside one frame of CSS class, 12 px clear of everything the scene draws, with lines as the frame's label at its top. The frame is centred on the scene and as wide as the wider of the scene and the label.

`scene` (`{:nodes :edges}`) inside one frame of CSS `class`, 12 px clear of everything
the scene draws, with `lines` as the frame's label at its top.  The frame is centred on
the scene and as wide as the wider of the scene and the label.
sourceraw docstring

label-capclj

How many characters one line of a term's node label holds. Thirty-two holds every name the shipped ontology has, CxNormalPhysicalConditions (26) among them, so a name is drawn whole; a longer label wraps (wrap-text), and the node's title holds the whole term.

How many characters one line of a term's node label holds.  Thirty-two holds every
name the shipped ontology has, `CxNormalPhysicalConditions` (26) among them, so a name
is drawn whole; a longer label wraps (`wrap-text`), and the node's `title` holds the
whole term.
sourceraw docstring

label-linesclj

How many lines a node label wraps over. Text past the last line is cut, and the last line ends in an ellipsis.

How many lines a node label wraps over.  Text past the last line is cut, and the last
line ends in an ellipsis.
sourceraw docstring

layeredclj

(layered
  nodes
  edges
  {:keys [level gap cap width line-gap bands groups group-gap]
   :or {cap Long/MAX_VALUE width Long/MAX_VALUE line-gap 0 bands {} groups {}}})

Place a layered drawing. Each of nodes is measured and has a :term, an integer :layer (a smaller layer is higher on the page) and a content key :order. Each of edges has :from and :to terms and whatever else the caller puts on it. Opts: :level (one-line rows' centre distance), :gap, :cap and :width past which a layer wraps onto lines :line-gap apart, and :bands {layer least-height}. :groups is {group {:rank n :lines [s …]}}; a node's :group keeps it in a block :group-gap from its neighbours, framed with the lines as its label. Returns {:nodes :edges :frames}, each edge with its :points.

Place a layered drawing.  Each of `nodes` is measured and has a `:term`, an integer
`:layer` (a smaller layer is higher on the page) and a content key `:order`.  Each of
`edges` has `:from` and `:to` terms and whatever else the caller puts on it.  Opts:
`:level` (one-line rows' centre distance), `:gap`, `:cap` and `:width` past which a layer
wraps onto lines `:line-gap` apart, and `:bands` {layer least-height}.  `:groups` is
{group {:rank n :lines [s …]}}; a node's `:group` keeps it in a block `:group-gap` from
its neighbours, framed with the lines as its label.  Returns `{:nodes :edges :frames}`,
each edge with its `:points`.
sourceraw docstring

measureclj

(measure node)

Give a node its label lines and its box — :lines, :w, :h — leaving where it goes to the layout fns below. Idempotent, so a caller may measure once and place twice.

The text is :display when the caller supplied one, else the term itself, wrapped at the node's :cap (default label-cap) characters a line over at most label-lines lines. A vector :display is one line per string, each cut at the cap. :term stays the identity the layout places by. The width and the height are even, so a box's edge is an integer wherever its centre is.

Give a node its label lines and its box — `:lines`, `:w`, `:h` — leaving *where* it
goes to the layout fns below.  Idempotent, so a caller may measure once and place twice.

The text is `:display` when the caller supplied one, else the term itself, wrapped at
the node's `:cap` (default `label-cap`) characters a line over at most `label-lines`
lines.  A vector `:display` is one line per string, each cut at the cap.  `:term` stays
the identity the layout places by.  The width and the height are even, so a box's edge
is an integer wherever its centre is.
sourceraw docstring

measure-cardclj

(measure-card card)

Give a card its box and each of its rows a box inside it. A card is a node whose header is its :display (else :term), wrapped as measure wraps a label. A row's :text wraps at label-cap over label-lines, and each of its :notes at note-cap over note-lines. :more is a note under the rows. Every row is as wide as the card's widest line, and the card adds card-pad each side. A row gets :lines, :notes, :w, :h and :dy, its top under the card's top. The card gets :lines, :w, :h and, with a :more, :more-lines and :more-at, that line's baseline under its top.

Give a card its box and each of its rows a box inside it.  A card is a node whose header
is its `:display` (else `:term`), wrapped as `measure` wraps a label.  A row's `:text`
wraps at `label-cap` over `label-lines`, and each of its `:notes` at `note-cap` over
`note-lines`.  `:more` is a note under the rows.  Every row is as wide as the card's
widest line, and the card adds `card-pad` each side.  A row gets `:lines`, `:notes`,
`:w`, `:h` and `:dy`, its top under the card's top.  The card gets `:lines`, `:w`, `:h`
and, with a `:more`, `:more-lines` and `:more-at`, that line's baseline under its top.
sourceraw docstring

node-hclj

The height of a one-line node. Each further line of a wrapped label adds line-h.

The height of a one-line node.  Each further line of a wrapped label adds `line-h`.
sourceraw docstring

note-capclj

How many characters one line of a card row's note holds: a row's label-cap characters of label text, in the smaller face the note is set in.

How many characters one line of a card row's note holds: a row's `label-cap` characters
of label text, in the smaller face the note is set in.
sourceraw docstring

note-linesclj

How many lines one card row's note wraps over before wrap-text cuts it. A note names up to three things, a context, a source and a reading, so it takes more lines than a label.

How many lines one card row's note wraps over before `wrap-text` cuts it.  A note names
up to three things, a context, a source and a reading, so it takes more lines than a
label.
sourceraw docstring

packclj

(pack parts width gap)

Place parts, each {:nodes :edges} laid out on its own with every edge's :points, left to right in rows at most width wide, gap apart, each part's top on its row's top. Answers one {:nodes :edges}.

Place `parts`, each `{:nodes :edges}` laid out on its own with every edge's `:points`,
left to right in rows at most `width` wide, `gap` apart, each part's top on its row's top.
Answers one `{:nodes :edges}`.
sourceraw docstring

ringclj

(ring nodes cx cy min-r start)

Place measured nodes evenly around a circle centred at (cx, cy), starting at start radians and going clockwise.

The radius is computed: the larger of min-r and the radius that spaces the arc between neighbours at 1.15× the widest box. Eight long names spread onto a wider ring instead of overlapping, and two short ones stay at min-r.

Place measured `nodes` evenly around a circle centred at (`cx`, `cy`), starting at
`start` radians and going clockwise.

The radius is computed: the larger of `min-r` and the radius that spaces the arc
between neighbours at 1.15× the widest box.  Eight long names spread onto a wider ring
instead of overlapping, and two short ones stay at `min-r`.
sourceraw docstring

ring-graphclj

(ring-graph nodes edges max-w)

Place one connected network: the measured nodes evenly on an ellipse round the origin in longest-label-path order, and each of edges (:from, :to, :label) straight, its label where label-clear puts it. The ellipse starts where neighbouring boxes stand the widest label and 40 px apart across, and the tallest label and 40 px apart down. Its radii grow by a quarter, at most eleven times, the across one only up to max-w px wide and the down one to max-w px tall, and a size putting two boxes within 6 px is skipped. Answers {:nodes :edges}, each edge with :points and :label-at, or nil when no size gives every label a place.

Place one connected network: the measured `nodes` evenly on an ellipse round the origin
in `longest-label-path` order, and each of `edges` (`:from`, `:to`, `:label`) straight,
its label where `label-clear` puts it.  The ellipse starts where neighbouring boxes stand
the widest label and 40 px apart across, and the tallest label and 40 px apart down.  Its
radii grow by a quarter, at most eleven times, the across one only up to `max-w` px wide
and the down one to `max-w` px tall, and a size putting two boxes within 6 px is skipped.
Answers `{:nodes :edges}`, each edge with `:points` and `:label-at`, or nil when no size
gives every label a place.
sourceraw docstring

rowclj

(row nodes cx y gap)

Place measured nodes left to right in a row centred on cx at height y, gap apart.

Place measured `nodes` left to right in a row centred on `cx` at height `y`, `gap`
apart.
sourceraw docstring

sceneclj

(scene {:keys [nodes edges frames aria-label]})

The whole picture as one <svg>, or nil when there is nothing to draw — a caller renders the nil and gets no empty frame.

aria-label is what a screen reader is told the image shows; it is role="img" because the prose above it, not the picture, is the accessible answer. The viewBox is the crop. An intrinsic pixel width/height (one user unit to one CSS px) draws the graph at its natural size, so a wide one scrolls inside .kb-graph-fig rather than shrinking on a narrow column.

The whole picture as one `<svg>`, or **nil** when there is nothing to draw — a caller
renders the nil and gets no empty frame.

`aria-label` is what a screen reader is told the image shows; it is `role="img"`
because the prose above it, not the picture, is the accessible answer.  The `viewBox`
is the crop.  An intrinsic pixel `width`/`height` (one user unit to one CSS px) draws
the graph at its natural size, so a wide one scrolls inside `.kb-graph-fig` rather than
shrinking on a narrow column.
sourceraw docstring

sentence-capclj

How many characters one line of a sentence's node label holds, for a node whose :cap is this: a proof's node is a sentence. A node at the cap is 380 px wide (char-w × 40 and the padding).

How many characters one line of a sentence's node label holds, for a node whose `:cap`
is this: a proof's node is a sentence.  A node at the cap is 380 px wide (`char-w` × 40
and the padding).
sourceraw docstring

timelineclj

(timeline bands {:keys [unit name-gap band-gap lane-gap]})

Place a timeline. Each of bands, {:lanes [lane …] :spans [span …]}, sits under the one before it, band-gap apart, its lanes lane-gap apart. A lane {:node :from :to :mark} sets the measured node name-gap px left of x = 0, and its mark node as a bar from rank :from to rank :to, or a tick where the two are equal. Rank r is at r × the band's unit: unit, widened to the widest span label and 16 px. Under the lanes runs an axis marking each rank, and under the axis each span {:from :to :label} joins its two ranks. Answers {:nodes :edges}.

Place a timeline.  Each of `bands`, `{:lanes [lane …] :spans [span …]}`, sits under the
one before it, `band-gap` apart, its lanes `lane-gap` apart.  A lane `{:node :from :to
:mark}` sets the measured `node` `name-gap` px left of x = 0, and its mark node as a bar
from rank `:from` to rank `:to`, or a tick where the two are equal.  Rank r is at r × the
band's unit: `unit`, widened to the widest span label and 16 px.  Under the lanes runs an
axis marking each rank, and under the axis each span `{:from :to :label}` joins its two
ranks.  Answers `{:nodes :edges}`.
sourceraw docstring

trimclj

(trim a b)

The visible segment between two placed nodes: the line between their centres, clipped at each one's box, so an arrowhead lands on the boundary of the node it points at rather than under its label. Nil when the two centres coincide — there is no direction to draw.

The visible segment between two **placed** nodes: the line between their centres,
clipped at each one's box, so an arrowhead lands on the boundary of the node it points
at rather than under its label.  Nil when the two centres coincide — there is no
direction to draw.
sourceraw docstring

wrap-textclj

(wrap-text s cap lines)

s as at most lines lines of at most cap characters each: broken at spaces, and inside a word only where the word alone is longer than cap. Text past the last line is cut, and the last line then ends in an ellipsis.

`s` as at most `lines` lines of at most `cap` characters each: broken at spaces, and
inside a word only where the word alone is longer than `cap`.  Text past the last line
is cut, and the last line then ends in an ellipsis.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close