ag-charts-community
Version:
Advanced Charting / Charts supporting Javascript / Typescript / React / Angular / Vue
335 lines (334 loc) • 16.1 kB
TypeScript
import type { AxisID, Callback, CallbackParam, ChartAnimationPhase, DomainWithMetadata, DynamicContext, NormalisedAxisTickOptions, NormalisedBaseAxisLabelOptions, NormalisedBaseAxisOptions, Point, Scale } from 'ag-charts-core';
import { ChartAxisDirection, ChartUpdateType, CleanupRegistry } from 'ag-charts-core';
import type { AgAxisBoundSeries, AgBaseAxisLabelStyleOptions, AgTimeAxisFormattableLabelUnitFormat, AgTimeInterval, AgTimeIntervalUnit, CssColor, DateFormatterStyle, FormatterParams, TextOrSegments } from 'ag-charts-types';
import type { AxisLayout } from '../../core/eventsHub';
import type { AxisBandDatum, AxisBandMeasurement, AxisContext, AxisFormattableLabel } from '../../module/axisContext';
import type { ChartAxisRegistry, ChartRegistry } from '../../module/moduleContext';
import { ModuleMap } from '../../module/moduleMap';
import { BBox } from '../../scene/bbox';
import { Group, TransformableGroup, TranslatableGroup } from '../../scene/group';
import type { Node } from '../../scene/node';
import { Selection } from '../../scene/selection';
import { type TextBoxingProperties, type TextSizeProperties, TransformableText } from '../../scene/shape/text';
import type { AxisPrimaryTickCount } from '../../util/secondaryAxisTicks';
import { Caption } from '../caption';
import type { AxisGroups, ChartAxis, ChartLayout, FormatDatumParams } from '../chartAxis';
import type { DatumIndexType, ISeries, ISeriesProperties } from '../series/seriesTypes';
import { type AxisLabelFormatterCache } from './axisLabelUtil';
import type { TickInterval } from './axisTick';
import { type AxisGroupDatumTranslation, NiceMode } from './axisUtil';
import type { AnyTimeInterval } from './generateTicksUtils';
export interface LabelNodeDatum extends TextSizeProperties, TextBoxingProperties {
color?: CssColor;
tickId: string;
rotation: number;
text: TextOrSegments;
textBaseline: CanvasTextBaseline;
textUntruncated?: string;
visible: boolean;
x: number;
y: number;
rotationCenterX: number;
rotationCenterY: number;
range: number[];
}
export declare enum AxisGroupZIndexMap {
TickLines = 0,
AxisLine = 1,
TickLabels = 2
}
export type AxisTickFormatParams = {
type: 'number';
fractionDigits: number | undefined;
visibleDomain?: [number, number];
} | {
type: 'date';
unit: AgTimeIntervalUnit;
step: number;
epoch: Date | undefined;
truncateDate?: 'year' | 'month' | 'day';
} | {
type: 'category';
};
interface TickLayout<D, TickLayoutMeta> {
niceDomain: D[];
tickDomain: D[];
ticks: D[];
rawTickCount: number | undefined;
fractionDigits: number;
timeInterval: AnyTimeInterval | undefined;
bbox?: BBox;
layout?: TickLayoutMeta;
}
/**
* A general purpose linear axis with no notion of orientation.
* The axis is always rendered vertically, with horizontal labels positioned to the left
* of the axis line by default. The axis can be {@link rotation | rotated} by an arbitrary angle,
* so that it can be used as a top, right, bottom, left, radial or any other kind
* of linear axis.
* The generic `D` parameter is the type of the domain of the axis' scale.
* The output range of the axis' scale is always numeric (screen coordinates).
*/
export declare abstract class Axis<S extends Scale<D, number, TickInterval<S>> = Scale<any, number, any>, D = any, TickLayoutMeta = any, TOptions extends NormalisedBaseAxisOptions = NormalisedBaseAxisOptions> implements ChartAxis<TOptions> {
protected readonly moduleCtx: DynamicContext<ChartRegistry>;
readonly scale: S;
static readonly defaultTickMinSpacing = 50;
readonly id: AxisID;
/**
* User pass-through option for callback resolution. Declared via `declare`
* (not initialised) so the property is absent on instances that did not
* receive a `context` option — `callbackCache.maybeSetContext` relies on
* the `'context' in axis` check to decide whether to fall back to the
* chartService's context.
*/
context?: unknown;
/**
* `nice` is user-facing only on continuous axis types (`AgContinuousAxisOptions`),
* but every axis subclass reads it (e.g. via `getDomainExtentsNice`). Treated as
* an internal axis-instance field initialised from `options.nice` in the base
* constructor; mini-chart and `CategoryAxis` mutate it directly.
*/
nice: boolean;
options: TOptions;
/**
* Internal axis state derived from `position` (cartesian) or layout direction
* (gradient-legend). Not user-facing — absent from `ag-charts-types`. See I2.
*/
mirrored: boolean;
parallel: boolean;
dataDomain: {
domain: D[];
clipped: boolean;
};
private allowNull;
readonly caption: Caption;
/**
* The length of the grid. The grid is only visible in case of a non-zero value.
* Use {@link setGridLength} to update so the grid-visibility callback fires.
*/
private _gridLength;
get gridLength(): number;
set gridLength(value: number);
/**
* The distance between the grid ticks and the axis ticks.
*/
gridPadding: number;
/**
* Is used to avoid collisions between axis labels and series.
*/
seriesAreaPadding: number;
get type(): string;
abstract get direction(): ChartAxisDirection;
/**
* Backing field for {@link layoutConstraints}. Mutated in-place by the
* `requiredRange` setter on {@link CategoryAxis}. Subclasses (notably
* `CategoryAxis`) may override the getter to project `bandAlignment` onto
* `align` without changing the stored object.
*/
protected _layoutConstraints: ChartAxis['layoutConstraints'];
get layoutConstraints(): ChartAxis['layoutConstraints'];
/**
* Backing field for the `requiredRange` accessor. Subclasses (notably
* `CategoryAxis`) override the setter to react to changes; the base
* implementation just stores the value.
*/
protected _requiredRange?: number;
get requiredRange(): number | undefined;
set requiredRange(value: number | undefined);
boundSeries: ISeries<DatumIndexType, unknown, ISeriesProperties>[];
includeInvisibleDomains: boolean;
interactionEnabled: boolean;
protected readonly axisGroup: Group<unknown>;
protected readonly tickLineGroup: TransformableGroup<AxisGroupDatumTranslation>;
protected readonly tickLabelGroup: TransformableGroup<AxisGroupDatumTranslation>;
protected readonly labelGroup: Group<unknown>;
readonly gridGroup: TranslatableGroup<unknown>;
protected readonly gridFillGroup: Group<unknown>;
protected readonly gridLineGroup: Group<unknown>;
/**
* Three z-index-ordered overlay container groups attached to the chart-level overlay zones
* via {@link attachAxis}. Plugins (currently only the cross-lines plugin) anchor their per-axis
* scene-graph contributions into these groups via {@link AxisContext.attachAxisOverlay}, which
* keeps overlay rendering scoped to the axis's host chart (main chart vs navigator mini-chart)
* without the axis itself knowing what gets drawn.
*/
private readonly overlayLowGroup;
private readonly overlayMidGroup;
private readonly overlayHighGroup;
protected tickLabelGroupSelection: Selection<LabelNodeDatum, TransformableText<LabelNodeDatum>>;
protected readonly formatterCache: AxisLabelFormatterCache;
protected get primaryLabel(): (NormalisedBaseAxisLabelOptions & {
format?: string | Record<string, string> | AgTimeAxisFormattableLabelUnitFormat;
}) | undefined;
protected get primaryTick(): NormalisedAxisTickOptions | undefined;
/**
* Returns the user-supplied label `format` specifier, or `undefined` if the axis's
* label type does not carry one. Only formattable label subtypes (numeric, time,
* formattable angle) declare `format` in `ag-charts-types`; per invariant I2 it is
* not part of the base label type. Subclasses with format-bearing labels override
* this hook; the base default is `undefined`.
*/
protected getLabelFormat(): string | Record<string, string> | undefined;
/**
* Sibling of {@link getLabelFormat} for {@link primaryLabel}, used by axes with a
* parent-level label tier (time-like axes). Default is `undefined`.
*/
protected getPrimaryLabelFormat(): string | Record<string, string> | undefined;
isCategoryLike(): boolean;
defaultTickMinSpacing: number;
readonly translation: {
x: number;
y: number;
};
protected readonly layout: Pick<AxisLayout, 'label'> & Partial<Pick<AxisLayout, 'labelThickness' | 'scrollbar'>>;
protected axisContext: AxisContext | undefined;
private moduleContext?;
protected readonly cleanup: CleanupRegistry;
constructor(moduleCtx: DynamicContext<ChartRegistry>, id: AxisID, scale: S, options: TOptions);
/**
* Replace the axis options reference and re-derive any constructor-time
* fields that depend on options. Called by `Chart.applyAxes` on the
* matching-types update path so reactive `chart.update()` invocations
* pick up changes to fields like `nice` and `layoutConstraints` instead
* of using values frozen at axis construction.
*/
applyOptions(options: TOptions): void;
private syncOptionDerivedState;
resetAnimation(_phase: ChartAnimationPhase): void;
private isHovering;
private onMouseMove;
private endHovering;
destroy(): void;
private setScaleRange;
protected updateScale(): void;
attachAxis(groups: AxisGroups): void;
detachAxis(): void;
attachLabel(axisLabelNode: Node): void;
range: [number, number];
visibleRange: [number, number];
/**
* Checks if a point or an object is in range.
* @param value A point (or object's starting point).
* @param tolerance Expands the range on both ends by this amount.
*/
inRange(value: number, tolerance?: number): boolean;
/**
* Get a point's overflow on the range, expanded to include the non-visible range.
* @param value Point
* @returns Overflow
*/
getRangeOverflow(value: number): number;
protected onGridLengthChange(value: number, prevValue: number): void;
protected onGridVisibilityChange(): void;
/**
* Creates/removes/updates the scene graph nodes that constitute the axis.
*/
update(): void;
protected getLabelStyles(params: {
value: number;
formattedValue: TextOrSegments | undefined;
depth?: number;
}, additionalStyles?: AgBaseAxisLabelStyleOptions, label?: NormalisedBaseAxisLabelOptions): {
border: import("ag-charts-types").BorderOptions;
color: string;
cornerRadius: number;
fill: import("ag-charts-types").AgColorType | undefined;
fillOpacity: number | undefined;
fontFamily: (import("ag-charts-types").FontFamilyFull | undefined) & string;
fontSize: number;
fontStyle: import("ag-charts-types").FontStyle | undefined;
fontWeight: number | "bold" | "normal" | "bolder" | "lighter";
padding: (import("ag-charts-types").Padding | undefined) & ((import("ag-charts-types").Padding | undefined) & NonNullable<import("ag-charts-types").Padding | undefined>);
spacing: number;
};
protected getTickSize(tick?: {
enabled: boolean;
size: number;
}): number;
protected getTickSpacing(tick?: {
enabled: boolean;
}): number;
processData(): void;
getDomainExtentsNice(): [boolean, boolean];
protected animatable: boolean;
setDomains(...domains: DomainWithMetadata<D>[]): void;
protected chartLayout?: ChartLayout;
private unzoomedTickLayoutCache;
calculateDomain(initialPrimaryTickCount?: AxisPrimaryTickCount, scrollbarKey?: string): {
unzoomedTickLayout: TickLayout<D, TickLayoutMeta>;
domain: D[];
};
private tickLayoutCache;
protected tickLayout: TickLayoutMeta | undefined;
calculateLayout(initialPrimaryTickCount?: AxisPrimaryTickCount, chartLayout?: ChartLayout): {
primaryTickCount?: AxisPrimaryTickCount;
bbox?: BBox;
};
private invalidateLayoutCache;
private getScrollbarLayoutCacheKey;
abstract calculateTickLayout(domain: D[], niceMode: NiceMode[], visibleRange: [number, number], primaryTickCount?: AxisPrimaryTickCount): {
niceDomain: D[];
tickDomain: D[];
ticks: D[];
rawTickCount: number | undefined;
fractionDigits: number;
timeInterval: AnyTimeInterval | undefined;
bbox?: BBox;
};
abstract hasDefinedDomain(): boolean;
protected updatePosition(): void;
private getOverlayGroup;
/**
* Generic dispatch that fans an axis-lifecycle phase out to every {@link AxisPluginModuleInstance}
* registered in the module map. Plugins read whatever live state they need from {@link AxisContext}.
*/
protected notifyAxisPlugins(method: 'onAxisUpdate' | 'onAxisLayout' | 'onScaleChange' | 'onGridChange'): void;
protected abstract updateSelections(): void;
protected abstract updateLabels(): void;
abstract tickFormatParams(domain: D[], ticks: D[], fractionDigits: number | undefined, timeInterval: AgTimeInterval | AgTimeIntervalUnit | undefined): AxisTickFormatParams;
abstract datumFormatParams(value: any, params: FormatDatumParams, fractionDigits: number | undefined, timeInterval: AgTimeInterval | AgTimeIntervalUnit | undefined, dateStyle: 'long' | 'component'): FormatterParams<any>;
tickFormatter(domain: D[], ticks: D[], primary: boolean, inputFractionDigits?: number, inputTimeInterval?: AgTimeInterval | AgTimeIntervalUnit, dateStyle?: DateFormatterStyle): (value: any, index: number) => TextOrSegments;
formatDatum(contextProvider: {
context?: unknown;
}, value: any, source: 'tooltip' | 'series-label', seriesId: string, legendItemName: string | undefined, datum: any, key: string): string;
formatDatum<Params extends object>(contextProvider: {
context?: unknown;
} | undefined, value: any, source: 'crosshair' | 'annotation-label', seriesId: undefined, legendItemName: undefined, datum: undefined, key: undefined, domain: undefined, label?: AxisFormattableLabel<Params, FormatterParams<any>>, params?: undefined, allowNull?: boolean): string;
formatDatum<Params extends object>(contextProvider: {
context?: unknown;
} | undefined, value: any, source: 'tooltip' | 'series-label', seriesId: string, legendItemName: string | undefined, datum: any, key: string, domain: any[], label: AxisFormattableLabel<Params>, labelParams: Params): string;
getBBox(): BBox;
hasVisibleSeries(): boolean;
clipTickLines(x: number, y: number, width: number, height: number): void;
clipGrid(x: number, y: number, width: number, height: number): void;
private readonly formatterBoundSeries;
private getFormatterProperty;
protected getTitleFormatterParams(domain: D[]): {
domain: D[];
direction: ChartAxisDirection;
boundSeries: AgAxisBoundSeries[];
defaultValue: string | undefined;
};
protected normaliseDataDomain(d: DomainWithMetadata<D>): {
domain: D[];
clipped: boolean;
};
protected getLayoutTranslation(): {
x: number;
y: number;
};
getLayoutState(): AxisLayout;
private readonly moduleMap;
getModuleMap(): ModuleMap<import("ag-charts-core").ModuleInstance>;
getUpdateTypeOnResize(): ChartUpdateType;
createModuleContext(): DynamicContext<ChartAxisRegistry<AxisContext>>;
createAxisContext(): AxisContext;
pickBand(point: Point): AxisBandDatum | undefined;
measureBand(value: string): AxisBandMeasurement | undefined;
private isVertical;
isReversed(): boolean;
protected cachedCallWithContext<F extends Callback>(fn: F, params: CallbackParam<F>): ReturnType<F> | undefined;
private uncachedCallWithContext;
private createCallWithContext;
}
export {};