UNPKG

vizzu

Version:

Vizzu is a free, open-source Javascript/C++ library utilizing a generic dataviz engine that generates many types of charts and seamlessly animates between them. It can be used to create static charts but more importantly it is designed for building animat

139 lines (138 loc) 4.93 kB
import Vizzu from './vizzu.js'; import * as Anim from './types/anim.js'; import { Events, EventType, EventHandler, EventMap } from './events.js'; import { AnimCompleting } from './animcompleting.js'; import { Point } from './geom.js'; import { CRenderer } from './module/crenderer.js'; import { Canvas } from './module/canvas.js'; /** Available hooks for plugins in Vizzu. */ export declare enum Hooks { /** Called once on startup for start the rendering loop. */ start = "start", /** Called when updating the chart due to time change. */ update = "update", /** Called on rendering. */ render = "render", /** Called when the animate() parameters gets set in the library to prepare the animation. */ prepareAnimation = "prepareAnimation", /** Called when the animate() method called, and the lib shedules the call to the animation queue. */ registerAnimation = "registerAnimation", /** Called when all animate() parameter set and animation can be started. */ runAnimation = "runAnimation" } /** Plugin metainfo. */ export interface PluginMeta { /** Name of the plugin. If not set, the class name will be used with a lowercase first char. */ name?: string; /** Version of the plugin. Not used for now. */ version?: string; /** List of plugins this plugin depends on. Dependent plugins should be registered beforehand. */ depends?: string[]; } export interface StartContext { update: (force: boolean) => void; } export interface UpdateContext { timeInMSecs: number | null; } export declare enum RenderControlMode { forced = "forced", allowed = "allowed", disabled = "disabled" } export interface RenderContext { renderer: (CRenderer & Canvas) | null; control: RenderControlMode; changed: boolean; size: Point; } export interface PrepareAnimationContext { target: Anim.AnimTarget; options?: Anim.ControlOptions; } export interface RegisterAnimationContext { target: Anim.AnimTarget; options?: Anim.ControlOptions; promise: AnimCompleting; } export interface RunAnimationContext { callback: (ok: boolean) => void; } export interface HookContexts { [Hooks.start]: StartContext; [Hooks.update]: UpdateContext; [Hooks.render]: RenderContext; [Hooks.prepareAnimation]: PrepareAnimationContext; [Hooks.registerAnimation]: RegisterAnimationContext; [Hooks.runAnimation]: RunAnimationContext; } type Next = () => void; /** Plugin hook implementation. Plugin hooks gets called by Vizzu in priority order. Each hook should call the next hook in the chain, or the default implementation won't run. */ type PluginHook<T> = { (ctx: T, next: Next): void; priority?: number; }; /** Set of plugin hook implementations. */ export type PluginHooks<T extends Hooks = Hooks> = { [key in T]?: PluginHook<HookContexts[key]>; }; export type PluginListeners = { [event in EventType]?: EventHandler<EventMap[event]>; }; export interface PluginApi { [apiMethod: string]: unknown; } /** Vizzu plugin interface. */ export interface Plugin { /** Metainfo about the plugin. */ meta?: PluginMeta; /** Hooks the plugin implemenst. They work only if the plugin is enabled. */ hooks?: PluginHooks; /** Event listeners the plugin implements. They work only if the plugin is enabled. */ listeners?: PluginListeners; /** Any parameter or method the Plugin exposes for the user. */ api?: PluginApi; /** Register called when the plugin added to vizzu, receiving the Vizzu instance. */ register?: (ctx: Vizzu) => void; /** Unregister is called when detach() called on the Vizzu instance. */ unregister?: (ctx: Vizzu) => void; /** Method called by Vizzu indicating for the plugin that it got switched on/off. If switched off, its event listeners gets removed and its hooks won't be called. */ enable?: (enabled: boolean) => void; } interface HookExecutor<T extends Hooks> { default: (last?: (ctx: HookContexts[T]) => void) => void; } export declare class PluginRegistry { private _parent; private _plugins; private _events?; constructor(parent: Vizzu, plugins?: Plugin[]); init(events: Events): void; enable(name: string, enabled: boolean): void; getRegisteredName(instance: Plugin): string | undefined; register(instance: Plugin, enabled?: boolean): string; destruct(): void; unregister(name: string): void; api(name: string): PluginApi; hook<T extends Hooks>(type: T, ctx: HookContexts[T]): HookExecutor<T>; private _setEnabled; private _enableEvents; private _disableEvents; private _validate; private _validateName; private _discoverName; private _firstToLower; private _validateDepends; private _getByName; private _exec; private _getHooks; private _executeHooks; } export {};