package matrix

  1. Overview
  2. Docs

Module Matrix_charts.HitSource

Hit-testing results for interactive charts.

Use Layout.hit_test to find the nearest data point or bar to a given cell coordinate, then inspect the returned t for data-level information.

Sourcetype policy = [
  1. | `Nearest_px
  2. | `Nearest_x
  3. | `Nearest_y
]

The type for distance metrics.

  • `Nearest_px: Euclidean distance in cell space.
  • `Nearest_x: horizontal distance only.
  • `Nearest_y: vertical distance only.
Sourcetype kind = [
  1. | `Line
  2. | `Scatter
  3. | `Bars
  4. | `Stacked_bars
  5. | `Heatmap
  6. | `Candles
  7. | `Circle
]

The type of mark that was hit.

Sourcetype payload =
  1. | XY of {
    1. x : float;
    2. y : float;
    }
    (*

    Point data from line, scatter, or circle marks.

    *)
  2. | Bar of {
    1. category : string;
    2. value : float;
    }
    (*

    Bar chart data.

    *)
  3. | Stacked_bar of {
    1. category : string;
    2. segment_index : int;
    3. value : float;
    4. total : float;
    }
    (*

    Stacked bar data with segment detail.

    *)
  4. | Heat of {
    1. x : float;
    2. y : float;
    3. value : float;
    }
    (*

    Heatmap cell data.

    *)
  5. | OHLC of {
    1. time : float;
    2. open_ : float;
    3. high : float;
    4. low : float;
    5. close : float;
    }
    (*

    Candlestick data.

    *)

Mark-specific data payload.

Sourcetype t = {
  1. mark_id : string option;
    (*

    The Mark.id of the hit mark, if set.

    *)
  2. kind : kind;
    (*

    Type of mark that was hit.

    *)
  3. index : int;
    (*

    Index of the data point within the mark's data array.

    *)
  4. px : int;
    (*

    Cell x-coordinate of the snapped hit.

    *)
  5. py : int;
    (*

    Cell y-coordinate of the snapped hit.

    *)
  6. distance_px : float;
    (*

    Distance from query to hit in cell units. 0.0 for hits inside bars.

    *)
  7. payload : payload;
    (*

    Data values at the hit point.

    *)
}

The type for hit-test results.