github ↗
docs menu

Module Hugin.View

View values.

A view holds the values a viewer sets on a figure: the values of keys the figure reads through bind, and the zooms of its continuous scales. Views live outside figures, so a rebuilt figure reads the values set on the previous one. A key is identified by its name and its sort, so code that runs again builds equal keys.

Keys

#type 'a key

The type for keys of values of type 'a. A key has a name, a sort (number, choice, interval, or zoom of a kind of scale) and an initial value.

#val number : string -> init:float -> float key

number name ~init is the key name of a number, initially init.

#val choice : string -> init:string -> string key

choice name ~init is the key name of a choice among strings, initially init.

#val interval : string -> init:(float * float) option -> (float * float) option key

interval name ~init is the key name of an interval or none, such as a brushed selection, initially init.

Raises Invalid_argument if init is Some (lo, hi) with lo or hi not finite or lo > hi.

#val zoom : ?at:id -> 'd Scale.t -> ('d * 'd) option key

zoom ~at s is the key of the zoom of the continuous scale named like s, of the kind of s, in the scope that holds the node at (Scopes), the root by default. Its value Some (a, b) sets that scale's domain to [a;b] (Scale.with_domain) in place of its fitted and explicit domains, and its initial value None leaves it. Every continuous scale has such a key without declaring one, and user keys cannot name it. In resolve, after the figure's structure changes, a zoom whose node lies in another scope with a scale of its name and kind applies there; one whose node, name or kind is gone, whose node no scope of its name holds, or whose domain the scale cannot take, is ignored with a warning, and so are the zooms of a scale that several set.

Raises Invalid_argument if s is unnamed or categorical.

Views

#type t

The type for views: keys bound to values.

#val empty : t

empty binds no key, so every key has its initial value.

#val set : 'a key -> 'a -> t -> t

set k v view is view with k bound to v, replacing any value bound to a key of the name of k, whatever its sort.

Raises Invalid_argument if k is an interval key and v is Some (lo, hi) with lo or hi not finite or lo > hi.

#val get : 'a key -> t -> 'a

get k view is the value bound to k in view, or the initial value of k if view binds none or binds the name of k with another sort.

#val equal : t -> t -> bool

equal view view' is true iff view and view' bind the same keys to equal values, floats compared by Float.equal.

#val pp : Stdlib.Format.formatter -> t -> unit

pp ppf view formats the keys of view and their values for debugging.