import { Color, PointStyle, BorderRadius, CoreInteractionOptions } from 'chart.js'; import { AnnotationEvents, PartialEventContext } from './events'; import { LabelOptions, BoxLabelOptions, LabelTypeOptions } from './label'; export type DrawTime = 'afterDraw' | 'afterDatasetsDraw' | 'beforeDraw' | 'beforeDatasetsDraw'; export interface AnnotationTypeRegistry { box: BoxAnnotationOptions ellipse: EllipseAnnotationOptions label: LabelAnnotationOptions line: LineAnnotationOptions point: PointAnnotationOptions polygon: PolygonAnnotationOptions } export type AnnotationType = keyof AnnotationTypeRegistry; export type AnnotationOptions = { [key in TYPE]: { type: key } & AnnotationTypeRegistry[key] }[TYPE] export type Scriptable = T | ((ctx: TContext, options: AnnotationOptions) => T); export type ScaleValue = number | string; interface ShadowOptions { backgroundShadowColor?: Scriptable, borderShadowColor?: Scriptable, shadowBlur?: Scriptable, shadowOffsetX?: Scriptable, shadowOffsetY?: Scriptable } export interface CoreAnnotationOptions extends AnnotationEvents, ShadowOptions{ adjustScaleRange?: Scriptable, borderColor?: Scriptable, borderDash?: Scriptable, borderDashOffset?: Scriptable, borderWidth?: Scriptable, display?: Scriptable, drawTime?: Scriptable, id?: string, xMax?: Scriptable, xMin?: Scriptable, xScaleID?: Scriptable, yMax?: Scriptable, yMin?: Scriptable, yScaleID?: Scriptable, z?: Scriptable } interface AnnotationPointCoordinates { xValue?: Scriptable, yValue?: Scriptable, } export interface ArrowHeadOptions extends ShadowOptions { backgroundColor?: Scriptable, borderColor?: Scriptable, borderDash?: Scriptable, borderDashOffset?: Scriptable, borderWidth?: Scriptable, display?: Scriptable, fill?: Scriptable, length?: Scriptable, width?: Scriptable, } export interface ArrowHeadsOptions extends ArrowHeadOptions{ end?: ArrowHeadOptions, start?: ArrowHeadOptions, } export interface LineAnnotationOptions extends CoreAnnotationOptions { arrowHeads?: ArrowHeadsOptions, endValue?: Scriptable, label?: LabelOptions, scaleID?: Scriptable, value?: Scriptable } export interface BoxAnnotationOptions extends CoreAnnotationOptions { backgroundColor?: Scriptable, /** * Border line cap style. See MDN. * @default 'butt' */ borderCapStyle?: Scriptable, /** * Border line dash. See MDN. * @default [] */ borderDash?: Scriptable, /** * Border line dash offset. See MDN. * @default 0.0 */ borderDashOffset?: Scriptable, /** * Border line join style. See MDN. * @default 'miter' */ borderJoinStyle?: Scriptable, borderRadius?: Scriptable, label?: BoxLabelOptions, rotation?: Scriptable } export interface EllipseAnnotationOptions extends CoreAnnotationOptions { backgroundColor?: Scriptable, label?: BoxLabelOptions, rotation?: Scriptable } export interface PointAnnotationOptions extends CoreAnnotationOptions, AnnotationPointCoordinates { backgroundColor: Scriptable, pointStyle?: Scriptable, radius?: Scriptable, rotation?: Scriptable, xAdjust?: Scriptable, yAdjust?: Scriptable, } export interface LabelAnnotationOptions extends CoreAnnotationOptions, LabelTypeOptions, AnnotationPointCoordinates { rotation?: Scriptable } interface PolygonAnnotationOptions extends CoreAnnotationOptions, AnnotationPointCoordinates { backgroundColor: Scriptable, borderCapStyle?: Scriptable, borderJoinStyle?: Scriptable, point?: PointAnnotationOptions, radius?: Scriptable, rotation?: Scriptable, sides?: Scriptable, xAdjust?: Scriptable, yAdjust?: Scriptable, } export interface AnnotationPluginOptions extends AnnotationEvents { animations?: Record, annotations: AnnotationOptions[] | Record, clip?: boolean, common?: BoxAnnotationOptions | EllipseAnnotationOptions | LabelAnnotationOptions | LineAnnotationOptions | PointAnnotationOptions | PolygonAnnotationOptions, interaction?: CoreInteractionOptions }