Module Vz.Scale

module Scale: sig .. end
Scales.

Scale represent functions mapping domains to ranges. They help to map dimensions of data to dimensions of visual representations. Scales can also be represented as images.



Scales


type 'a set = [ `Discrete of 'a list | `Intervals of 'a list ] 
The type for representing sets of values.
type ('a, 'b) t = ('a, 'b) Vz.scale 
The type for scales from values of type 'a to 'b.
val clamp : ('a, 'b) Vz.scale -> bool
clamp s is true if the map of s first clamps values to the scale domain before mapping them (ensures the map returns only values in the range).
val nice : ('a, 'b) Vz.scale -> bool
nice s is true if the bounds of s are niced.
val dom : ('a, 'b) Vz.scale -> 'a set
dom s is the (possibly niced) domain of s.
val dom_raw : ('a, 'b) Vz.scale -> 'a set
dom s is the unniced domain of s.
val range : ('a, 'b) Vz.scale -> 'b set
range s is the range of s.
val map : ('a, 'b) Vz.scale -> 'a -> 'b
map s is the mapping function of s.

Warning. On ordinal scales the mapping function raises Invalid_argument on undefined argument. Use Vz.Scale.partial_map to ensure that it never raises.

val partial_map : ('a, 'b) Vz.scale -> 'a -> 'b option
partial_map s is like map s except on ordinal scales it returns None on undefined argument.
val fold_ticks : ?bounds:bool ->
int -> ('a -> int -> float -> 'a) -> 'a -> (float, 'b) Vz.scale -> 'a
fold_ticks bounds n f acc scale folds f over approximatevely n uniformly spaced values taken in scale's domain using Vz.Nice.step to determine the step value. See Vz.Nice.step_fold. If bounds is true ensures that the bounds of the domain are folded over.

Linear scales



The type for linear scales. Linear scales maps
val linear : ?clamp:bool ->
?nice:bool -> float * float -> float * float -> (float, float) Vz.scale
linear clamp nice (x0, x1) (y0, y1) is the map that linearly transforms x0 on y0 and x1 on y1. If the map is undefined (x0 = x1 and y0 <> y1) the map always returns y0.

Ordinal scales

Ordinal scales maps a discrete orderable domain to a range.

val ordinal : ?cmp:('a -> 'a -> int) -> 'a list -> 'b list -> ('a, 'b) Vz.scale
ordinal cmp dom range maps the value domi to the value rangei mod max with max = List.length range - 1. cmp is the order on the domain, defaults to Pervasives.compare.

Generating discrete ranges


val range_pts : ?rpad:float -> min:float -> max:float -> int -> float list
val range_bands : ?rpad:float -> ?pad:float -> min:float -> max:float -> int -> float list