package matrix

  1. Overview
  2. Docs

Module Matrix_charts.LayoutSource

Compiled chart layout for coordinate mapping, hit-testing, and interaction.

A layout is produced by Matrix_charts.draw or Layout and captures the computed coordinate mapping, plot region, and resolved scales. It bridges cell coordinates (from mouse/cursor input) and data coordinates (for tooltips, crosshairs, and snapping).

Sourcetype t

The type for compiled layouts.

Sourcetype rect = {
  1. x : int;
  2. y : int;
  3. width : int;
  4. height : int;
}

The type for axis-aligned rectangles in cell coordinates.

Geometry

Sourceval size : t -> int * int

size l is (width, height) of the full chart area.

Sourceval plot_rect : t -> rect

plot_rect l is the data plotting region, excluding axes, labels, and margins.

Sourceval is_inside_plot : t -> px:int -> py:int -> bool

is_inside_plot l ~px ~py is true iff (px, py) falls within the plot region.

Domain and view

Sourceval x_domain : t -> View.window

x_domain l is the full x-axis data domain.

Sourceval y_domain : t -> View.window

y_domain l is the full y-axis data domain.

Sourceval y2_domain : t -> View.window option

y2_domain l is the secondary y-axis domain, or None if no secondary axis is configured.

Sourceval x_view : t -> View.window

x_view l is the currently visible x-axis range (may be a subset of the domain when zoomed).

Sourceval y_view : t -> View.window

y_view l is the currently visible y-axis range.

Sourceval y2_view : t -> View.window option

y2_view l is the currently visible secondary y-axis range.

Sourceval y_axis_title_width : t -> int

y_axis_title_width l is the width reserved for the y-axis title, in cells.

Sourceval y2_axis_width : t -> int

y2_axis_width l is the width reserved for the secondary y-axis, in cells.

Sourceval has_y2 : t -> bool

has_y2 l is true iff a secondary y-axis is active.

Coordinate conversion

Sourceval data_of_px : t -> px:int -> py:int -> (float * float) option

data_of_px l ~px ~py converts cell coordinates to data coordinates. None if (px, py) is outside the plot region.

Sourceval px_of_data : t -> x:float -> y:float -> int * int

px_of_data l ~x ~y converts data coordinates to cell coordinates. Values outside the visible range are clamped to the plot boundary.

Category lookup

Sourceval x_category_of_px : t -> px:int -> string option

x_category_of_px l ~px is the category at cell column px when the x-axis uses a band scale. None for non-band scales or out-of-range positions.

Sourceval y_category_of_px : t -> py:int -> string option

y_category_of_px l ~py is the category at cell row py when the y-axis uses a band scale.

Sourceval px_of_x_category : t -> string -> int option

px_of_x_category l cat is the centre cell column for category cat. None if cat is not in the scale.

Sourceval py_of_y_category : t -> string -> int option

py_of_y_category l cat is the centre cell row for category cat.

View manipulation

Sourcetype axis = [
  1. | `X
  2. | `Y
  3. | `Both
]

The type for axis selectors in zoom/pan operations.

Sourceval clamp_view : t -> View.t -> View.t

clamp_view l view constrains view to the layout's data domain. Respects the clamp setting on each scale; band scales are unchanged.

Sourceval zoom_view_around_px : t -> view:View.t -> axis:axis -> px:int -> py:int -> factor:float -> View.t

zoom_view_around_px l ~view ~axis ~px ~py ~factor zooms view around the data point at cell position (px, py). If the position is outside the plot, zooms around the centre.

Sourceval pan_view_by_px : t -> view:View.t -> dx:int -> dy:int -> View.t

pan_view_by_px l ~view ~dx ~dy pans view by (dx, dy) cells. The delta is converted to data units proportional to the current view range and plot size.

Sourceval plot_center_px : t -> int * int

plot_center_px l is the cell coordinates of the plot centre.

Sourceval zoom_view_around_center : t -> view:View.t -> axis:axis -> factor:float -> View.t

zoom_view_around_center l ~view ~axis ~factor zooms view around the plot centre.

See also zoom_view_around_px.

Hit testing

Sourceval hit_test : ?radius:int -> ?policy:Hit.policy -> t -> px:int -> py:int -> Hit.t option

hit_test l ~px ~py is the nearest data point to cell position (px, py), or None if (px, py) is outside the plot region or no point is within radius. radius defaults to 3. policy defaults to `Nearest_px.