ag-charts-types
Version:
Advanced Charting / Charts supporting Javascript / Typescript / React / Angular / Vue
157 lines (156 loc) • 7.68 kB
TypeScript
import type { AgActiveState } from '../api/activeState';
import type { AgAnnotation } from './annotationsOptions';
import type { Listener, SelectionState } from './callbackOptions';
import type { ContextDefault, DatumDefault, DatumKey, Ratio } from './types';
import type { AgAutoScaledAxes } from './zoomOptions';
interface AgChartEvent<T extends string, TContext = ContextDefault> {
type: T;
event: Event;
/** Callback context for this event. */
context?: TContext;
}
export interface AgPreventableEvent {
/** Prevent the AG Charts built-in default event handlers from running. */
preventDefault(): void;
}
export interface AgNodeClickEvent<TEvent extends string, TDatum, TContext = ContextDefault> extends AgChartEvent<TEvent, TContext> {
/** Event type. */
type: TEvent;
/** Series ID, as specified in `series.id` (or generated if not specified) */
seriesId: string;
/** The unique identifier of the picked datum. */
itemId: string | number;
/** The data ID key, if set on chart options. When present, `itemId` is a stable identifier. */
dataIdKey?: DatumKey<TDatum>;
/** Datum from the chart or series data array. */
datum: TDatum;
/** The current selection state of this datum. Set to `undefined` if the selection module is not enabled. */
selectionState?: SelectionState;
/** xKey as specified on series options */
xKey?: DatumKey<TDatum>;
/** yKey as specified on series options */
yKey?: DatumKey<TDatum>;
/** sizeKey as specified on series options */
sizeKey?: DatumKey<TDatum>;
/** labelKey as specified on series options */
labelKey?: DatumKey<TDatum>;
/** colorKey as specified on series options */
colorKey?: DatumKey<TDatum>;
/** angleKey as specified on series options */
angleKey?: DatumKey<TDatum>;
/** calloutLabelKey as specified on series options */
calloutLabelKey?: DatumKey<TDatum>;
/** sectorLabelKey as specified on series options */
sectorLabelKey?: DatumKey<TDatum>;
/** radiusKey as specified on series options */
radiusKey?: DatumKey<TDatum>;
}
export interface AgSeriesVisibilityChange<TContext = ContextDefault> {
/** Event type. */
type: 'seriesVisibilityChange';
/** Callback context for this event. */
context?: TContext;
/** Series id */
seriesId: string;
/** Legend item id - usually yKey value for cartesian series. */
itemId?: string | number;
/** Human-readable description of the y-values. If supplied, matching items with the same value will be toggled together. */
legendItemName?: string;
/** The new visibility status that the series is changing to. */
visible: boolean;
}
export type AgActiveChangeEventSource = 'state-change' | 'user-interaction';
export interface AgActiveChangeEvent<TDatum, TContext> extends AgActiveState, AgPreventableEvent {
/** Event type. */
type: 'activeChange';
/** An indication of what triggered this event. */
source: AgActiveChangeEventSource;
/** Callback context for this event. */
context?: TContext;
/** Datum from the chart or series data array. */
datum?: TDatum;
/** The data ID key, if set on chart options. When present, `activeItem.itemId` is a stable identifier. */
dataIdKey?: DatumKey<TDatum>;
}
export interface AgSelectionItemIds {
/** Series ID, as specified in `series.id` (or generated if not specified). */
seriesId: string;
/** The unique identifier of the datum as specified in `dataIdKey` if set (or generated if not specified). */
itemId: string | number;
}
export interface AgSelectionItem<TDatum> extends AgSelectionItemIds {
/** Datum from the chart or series data array. */
datum: TDatum;
}
export type AgSelectionChangeEventSource = 'user-interaction' | 'api-call';
export interface AgSelectionChangeEvent<TDatum, TContext> extends AgPreventableEvent {
/** Event type. */
type: 'selectionChange';
/** An indication of what triggered this event. */
source: AgSelectionChangeEventSource;
/** Callback context for this event. */
context?: TContext;
/** Items added to the selection in this change. */
added: AgSelectionItem<TDatum>[];
/** Items removed from the selection in this change. */
removed: AgSelectionItem<TDatum>[];
}
export interface AgAnnotationsEvent<TContext = ContextDefault> {
type: 'annotations';
annotations?: AgAnnotation[];
context?: TContext;
}
export type AgZoomEventSource = 'chart-update' | 'data-update' | 'range-check' | 'state-change' | 'sync' | 'user-interaction';
export interface AgZoomEvent<TContext = ContextDefault> {
type: 'zoom';
source: AgZoomEventSource;
rangeX?: AgZoomEventRange;
rangeY?: AgZoomEventRange;
ratioX: AgZoomEventRatio;
ratioY: AgZoomEventRatio;
autoScaledAxes?: AgAutoScaledAxes;
context?: TContext;
}
export interface AgZoomEventRange {
start?: Date | string | number;
end?: Date | string | number;
}
export interface AgZoomEventRatio {
start: Ratio;
end: Ratio;
}
export type AgChartClickEvent<TContext = ContextDefault> = AgChartEvent<'click', TContext>;
export type AgChartDoubleClickEvent<TContext = ContextDefault> = AgChartEvent<'doubleClick', TContext>;
export type AgChartContextMenuEvent<TContext = ContextDefault> = AgChartEvent<'contextMenuEvent', TContext>;
export type AgSeriesAreaContextMenuActionEvent<TContext = ContextDefault> = AgChartEvent<'seriesContextMenuAction', TContext>;
export type AgNodeContextMenuActionEvent<TDatum = DatumDefault, TContext = ContextDefault> = AgNodeClickEvent<'nodeContextMenuAction', TDatum, TContext>;
export interface AgBaseChartListeners<TDatum, TContext = ContextDefault> {
/** The listener to call when a node (marker, column, bar, tile or a pie sector) in any series is clicked.
* Useful for a chart containing multiple series.
*/
seriesNodeClick?: Listener<AgNodeClickEvent<'seriesNodeClick', TDatum, TContext>>;
/** The listener to call when a node (marker, column, bar, tile or a pie sector) in any series is double-clicked.
* Useful for a chart containing multiple series.*/
seriesNodeDoubleClick?: Listener<AgNodeClickEvent<'seriesNodeDoubleClick', TDatum, TContext>>;
/** The listener to call when a series visibility is changed. */
seriesVisibilityChange?: Listener<AgSeriesVisibilityChange<TContext>>;
/** The listener to call when the active state (highlight/tooltip) is changed. */
activeChange?: Listener<AgActiveChangeEvent<TDatum, TContext>>;
/** The listener to call when data selection is changed */
selectionChange?: Listener<AgSelectionChangeEvent<TDatum, TContext>>;
/** The listener to call when the chart is clicked. */
click?: Listener<AgChartClickEvent<TContext>>;
/** The listener to call when the chart is double-clicked. */
doubleClick?: Listener<AgChartDoubleClickEvent<TContext>>;
/** The listener to call when the annotations are changed. */
annotations?: Listener<AgAnnotationsEvent<TContext>>;
/** The listener to call when the zoom is changed. */
zoom?: Listener<AgZoomEvent<TContext>>;
}
export interface AgSeriesListeners<TDatum, TContext = ContextDefault> {
/** The listener to call when a node (marker, column, bar, tile or a pie sector) in the series is clicked. */
seriesNodeClick?: Listener<AgNodeClickEvent<'seriesNodeClick', TDatum, TContext>>;
/** The listener to call when a node (marker, column, bar, tile or a pie sector) in the series is double-clicked. */
seriesNodeDoubleClick?: Listener<AgNodeClickEvent<'seriesNodeDoubleClick', TDatum, TContext>>;
}
export {};