import { XYComponentConfigInterface } from '../../core/xy-component/config'; import { Tooltip } from '../tooltip'; import { NumericAccessor, ColorAccessor } from '../../types/accessor'; import { ContinuousScale } from '../../types/scale'; import { WithOptional } from '../../types/misc'; import { CrosshairCircle } from './types'; import { CrosshairSnapMode } from './constants'; export interface CrosshairConfigInterface extends WithOptional, 'x' | 'y'> { /** Optional accessor function for getting the values along the X axis. Default: `undefined` */ x?: NumericAccessor; /** Optional single of multiple accessor functions for getting the values along the Y axis. Default: `undefined` */ y?: NumericAccessor | NumericAccessor[]; /** Optional color array or color accessor function for crosshair circles. Default: `d => d.color` */ color?: ColorAccessor; /** Optional stroke color accessor function for crosshair circles. Default: `undefined` */ strokeColor?: ColorAccessor; /** Optional stroke width for crosshair circles. Default: `undefined` */ strokeWidth?: NumericAccessor; /** Radius of crosshair circles in pixels. Default: `3` */ circleRadius?: number; /** When `true`, the Crosshair also renders a horizontal line. The line is placed at the Y position of the * crosshair circle closest to the mouse pointer (i.e. the snapped data point), or follows the pointer * when there are no circles to snap to (e.g. when `snapToData` is `false`). Default: `false` */ showHorizontalLine?: boolean; /** Separate array of accessors for stacked components (eg StackedBar, Area). Default: `undefined` */ yStacked?: NumericAccessor[]; /** Baseline accessor function for stacked values, useful with stacked areas. Default: `null` */ baseline?: NumericAccessor; /** An instance of the Tooltip component to be used with Crosshair. Default: `undefined` */ tooltip?: Tooltip | undefined; /** Tooltip template accessor. The function is supposed to return either a valid HTML string or an HTMLElement. * When `snapToData` is `false`, `datum` will be `undefined` but `data` and `leftNearestDatumIndex` will be provided. * Default: `d => ''` */ template?: (datum: Datum, x: number | Date, data: Datum[], leftNearestDatumIndex?: number) => string | HTMLElement; /** Hide Crosshair when the corresponding datum element is far from mouse pointer. Default: `true` */ hideWhenFarFromPointer?: boolean; /** Distance in pixels to check in the hideWhenFarFromPointer condition. Default: `100` */ hideWhenFarFromPointerDistance?: number; /** Snap to the nearest data point. * If disabled, the tooltip template will receive only the horizontal position of the crosshair and you'll be responsible * for getting the underlying data records and crosshair circles (see the `getCircles` configuration option). * Default: `true` */ snapToData?: boolean; /** When `snapToData` is enabled, controls how the nearest datum is found: * - `CrosshairSnapMode.XY`: snap to the datum closest to the mouse pointer in both X and Y (measured in pixel space). * This is the right choice for Scatter charts where many points can share similar X values. * - `CrosshairSnapMode.X`: snap to the datum closest along the X axis only. Best for time series / line / area * charts where the crosshair is a vertical line tracking the X position. * * Has no effect when `forceShowAt` is set (no pointer Y is available — it falls back to `CrosshairSnapMode.X`). * Default: `CrosshairSnapMode.X` */ snapMode?: CrosshairSnapMode | `${CrosshairSnapMode}`; /** Custom function for setting up the crosshair circles, usually needed when `snapToData` is set to `false`. * The function receives the horizontal position of the crosshair (in the data space, not in pixels), the data array, * the `yScale` instance to help you calculate the correct vertical position of the circles, and the nearest datum index. * It has to return an array of the `CrosshairCircle` objects: `{ y: number; color: string; opacity?: number }[]`. * Default: `undefined` */ getCircles?: (x: number | Date, data: Datum[], yScale: ContinuousScale, leftNearestDatumIndex?: number) => CrosshairCircle[]; /** Callback function that is called when the crosshair is moved: * - `x` is the horizontal position of the crosshair in the data space; * - `datum` is the nearest datum to the crosshair; * - `datumIndex` is the index of the nearest datum. * - `event` is the event that triggered the crosshair move (mouse or wheel). * * When the mouse goes out of the container and on wheel events, all the arguments are `undefined` except for `event`. * Default: `undefined` */ onCrosshairMove?: (x?: number | Date, datum?: Datum, datumIndex?: number, event?: MouseEvent | WheelEvent) => void; /** Force the crosshair to show at a specific position. Default: `undefined` */ forceShowAt?: number | Date; /** Skip range checks for crosshair visibility. When true, crosshair will show regardless of position within chart bounds. Default: `false` * This is useful for testing, especially when you only triggers mousemove event but does not have real mouse event. */ skipRangeCheck?: boolean; /** Minimum fraction (`0` to `1`) of the container's area that must be visible in the * viewport for the Crosshair (and its Tooltip) to be displayed. This prevents the * Crosshair from showing when the chart is mostly scrolled out of view. Charts that are * wider or taller than the viewport may never reach the default ratio, so lower this * value (or set it to `0` to always show the Crosshair) for large charts. Default: `0.35` */ visibilityThreshold?: number; } export declare const CrosshairDefaultConfig: CrosshairConfigInterface;