ag-charts-community
Version:
Advanced Charting / Charts supporting Javascript / Typescript / React / Angular / Vue
123 lines (122 loc) • 5.72 kB
TypeScript
import type { AxisID, BoxBounds, CartesianAxisDirection, DeepReadonly, DefinedZoomState, DynamicContext, MementoOriginator, Scale, ZoomMinMax, ZoomState } from 'ag-charts-core';
import type { AgZoomEventSource, AgZoomRange } from 'ag-charts-types';
import type { ZoomEventSourceDetail, ZoomMemento } from '../../core/eventsHub';
import type { ChartRegistry } from '../../module/moduleContext';
import type { BBox } from '../../scene/bbox';
import { BaseManager } from '../../util/baseManager';
import { PanToBBoxScalingModeEnum } from '../../util/panToBBox';
import type { ISeries } from '../series/seriesTypes';
type CoreZoomEntry = ZoomMinMax & {
direction: CartesianAxisDirection;
};
export type CoreZoomState = Record<AxisID, CoreZoomEntry>;
export type CoreZoomStateSafeRetrieval = {
readonly [K in AxisID]: CoreZoomEntry | undefined;
};
export type SimpleAxis = {
id: AxisID;
direction: CartesianAxisDirection;
};
export type CartesianAxisLike = SimpleAxis & {
type: string;
visibleRange: [number, number];
scale: Scale<any, any>;
range: [number, number];
boundSeries: ISeries<any, any, any>[];
options?: {
min?: number;
max?: number;
};
getZoom(): ZoomMinMax;
setZoom(zoom: ZoomMinMax): void;
};
export type UpdateZoomSourcing = {
source: AgZoomEventSource;
sourceDetail: ZoomEventSourceDetail;
};
export type UpdateZoomChanges = Record<AxisID, ZoomMinMax | undefined>;
export type UpdateZoomParams = UpdateZoomSourcing & {
isReset: boolean;
changes: UpdateZoomChanges;
};
export type UpdateZoomWithFunction = (start: Date | number, end: Date | number, windowStart: Date | number, windowEnd: Date | number, source: AgZoomEventSource) => [Date | number | undefined, Date | number | undefined];
declare function refreshCoreState(nextAxes: Array<CartesianAxisLike> | Array<SimpleAxis>, state: CoreZoomStateSafeRetrieval): CoreZoomState;
export declare function userInteraction<D extends ZoomEventSourceDetail>(sourceDetail: D): {
source: "user-interaction";
sourceDetail: D;
};
/**
* Manages the current zoom state for a chart. Tracks the requested zoom from distinct dependents
* and handles conflicting zoom requests.
*/
export declare class ZoomManager extends BaseManager implements MementoOriginator<ZoomMemento> {
private readonly ctx;
mementoOriginatorKey: "zoom";
private get state();
private set state(value);
private readonly axes;
private readonly allAxes;
private didLayoutAxes;
private pendingZoomEventSource?;
private lastRestoredRequiredRange?;
private lastRestoredRequiredRangeDirection?;
private lastRequiredRange?;
private restoreRequiredRangeIterations;
private independentAxes;
private navigatorModule;
private zoomModule;
private readonly debug;
panToBBoxScalingMode: PanToBBoxScalingModeEnum;
private pendingMemento;
constructor(ctx: DynamicContext<ChartRegistry>);
toCoreZoomState(axisZoom: DeepReadonly<ZoomState>): CoreZoomState;
createMemento(): ZoomMemento;
guardMemento(blob: unknown, messages: string[]): blob is ZoomMemento | undefined;
restoreMemento(version: string, mementoVersion: string, memento: ZoomMemento | undefined): void;
private writeInitialZoom;
private findAxis;
getAxes(): CartesianAxisLike[];
setAxes(nextAxes: Parameters<typeof refreshCoreState>[0]): void;
setIndependentAxes(independent?: boolean): void;
setNavigatorEnabled(enabled?: boolean): void;
setZoomModuleEnabled(enabled?: boolean): void;
isNavigatorEnabled(): boolean;
isZoomEnabled(): boolean;
updateZoom({ source, sourceDetail }: UpdateZoomSourcing, newZoom?: ZoomState): boolean;
private computeChangedAxesIds;
updateChanges(params: UpdateZoomParams): boolean;
resetZoom({ source, sourceDetail }: UpdateZoomSourcing): void;
resetAxisZoom({ source, sourceDetail }: UpdateZoomSourcing, axisId: AxisID): void;
panToBBox(seriesRect: BBox, target: BoxBounds): boolean;
fireZoomPanStartEvent(callerId: 'navigator' | 'zoom'): void;
updateWith({ source, sourceDetail }: UpdateZoomSourcing, direction: CartesianAxisDirection, fn: UpdateZoomWithFunction): void;
isValidUpdateWith(direction: CartesianAxisDirection, fn: UpdateZoomWithFunction, source: AgZoomEventSource): boolean;
/**
* Snapshot of the per-axis zoom map built from axis-local state. Used by per-axis iteration
* consumers (panner, scroller, toolbar independent-axes branch). New code should prefer reading
* `chartState.zoom` (per-direction) or `axis.getZoom()` (per-axis).
*/
getAxisZooms(): CoreZoomStateSafeRetrieval;
getAxisZoom(axisId: AxisID): ZoomMinMax;
getPrimaryAxisId(direction: CartesianAxisDirection): AxisID | undefined;
private getBoundSeries;
constrainZoomToItemCount(zoom: DefinedZoomState, minVisibleItems: number, shouldAutoscale: boolean): DefinedZoomState;
isVisibleItemsCountAtLeast(zoom: DefinedZoomState, minVisibleItems: number, opts: {
autoScaleYAxis: boolean;
includeYVisibleRange: boolean;
}): boolean;
private getMementoRanges;
private restoreRequiredRange;
private constrainZoomToRequiredWidth;
private dispatch;
private getRange;
private getRangeDirection;
private getRangeAxis;
rangeToRatio(axisId: AxisID, range: AgZoomRange): ZoomMinMax | undefined;
rangeToRatioDirection(direction: CartesianAxisDirection, range: AgZoomRange): ZoomMinMax | undefined;
private rangeToRatioAxis;
getPrimaryAxis(direction: CartesianAxisDirection): CartesianAxisLike | undefined;
private getDomainPixelExtents;
private isValidUpdateWithResult;
}
export {};