package matrix

  1. Overview
  2. Docs

Module Matrix_charts.ViewSource

Viewport windowing for zoom and pan.

A view constrains which portion of the data domain is visible. Store a t in your application model and pass it to Matrix_charts.draw. Use empty to show the full data extent.

All window operations produce valid windows: min is always < max, with a minimum span enforced to prevent degenerate ranges.

Sourcetype window = {
  1. min : float;
  2. max : float;
}

The type for 1D ranges. Invariant: min < max.

Sourcetype t = {
  1. x : window option;
  2. y : window option;
  3. y2 : window option;
}

The type for viewport state. None on any axis means "show full domain".

Sourceval empty : t

No constraints on any axis.

Sourceval set_x : window option -> t -> t

set_x w v is v with x-axis window w.

Sourceval set_y : window option -> t -> t

set_y w v is v with y-axis window w.

Sourceval set_y2 : window option -> t -> t

set_y2 w v is v with secondary y-axis window w.

Sourceval window : min:float -> max:float -> window

window ~min ~max is a window over [min, max]. If min > max the values are swapped. A minimum span is enforced.

Sourceval zoom : window -> factor:float -> window

zoom w ~factor zooms around the centre of w. factor > 1 zooms in (smaller range), factor < 1 zooms out. Non-positive factors are treated as 1.0.

Sourceval zoom_around : window -> center:float -> factor:float -> window

zoom_around w ~center ~factor zooms around center, preserving its relative position within the window.

Sourceval pan : window -> delta:float -> window

pan w ~delta shifts w by delta data units.

Sourceval clamp : domain:window -> window -> window

clamp ~domain w restricts w to fit within domain. If w is wider than domain, returns domain. Otherwise slides w to the nearest position that fits.