UNPKG

6.42 kBTypeScriptView Raw
1import * as Anim from './types/anim.js';
2import * as Data from './types/data.js';
3import * as Config from './types/config.js';
4import * as Styles from './types/styles.js';
5import { EventType, EventMap, EventHandler } from './events.js';
6import { LoaderOptions } from './module/loader.js';
7import { Snapshot } from './module/cchart.js';
8import { AnimControl } from './animcontrol.js';
9import { AnimCompleting } from './animcompleting.js';
10import { Mirrored } from './tsutils.js';
11import { Plugin, PluginApi } from './plugins.js';
12import Presets from './plugins/presets.js';
13import { LazyCanvasOptions, HtmlCanvasApi } from './htmlcanvas.js';
14import { CoordSystemApi } from './plugins/coordsys.js';
15/** Options for the library. */
16export type LibOptions = LoaderOptions;
17/** List of base and additional features:
18 - logging: enables logging of the library to the console
19 (switched off by default).
20 - rendering: enables rendering of the library to the canvas
21 (enabled by default).
22 - tooltip: tooltips on the chart appearing on markers on mouse over.
23 Since the tooltip uses the animation interface, calling animate() while
24 the tooltip is enabled can cause unwanted behaviour.
25 - cssProperties: enables setting the styles through --vizzu-... css properties.
26 - shorthands: enables shorthand properties for chart config and style.
27 - pivotData: enables setting the data in pivot table or data cube format.
28 - pointerEvents: enables pointer events on the chart.
29 */
30export type Feature = 'logging' | 'tooltip' | 'rendering' | 'cssProperties' | 'coordSystem' | 'htmlCanvas' | 'shorthands' | 'pivotData' | 'pointerEvents';
31export interface FeatureOptions {
32 features?: Plugin[];
33}
34export type VizzuOptions = FeatureOptions & LazyCanvasOptions;
35export type FeatureFunction = (feature: Feature | Plugin, enabled?: boolean) => PluginApi;
36export interface Features extends Record<string, PluginApi>, FeatureFunction {
37 coordSystem: CoordSystemApi;
38 htmlCanvas: HtmlCanvasApi;
39}
40/** Class representing a single chart in Vizzu. */
41export default class Vizzu {
42 /** Promise representing the initialization will resolve when
43 initialization is finished. Any API call will potentially cause
44 an error before this promise is resolved. */
45 initializing: Promise<Vizzu>;
46 private _chart?;
47 private _anim;
48 private _plugins;
49 /** Returns the chart preset collection. */
50 static get presets(): Presets;
51 /** Setter method for Library options. */
52 static options(options: LibOptions): void;
53 /** Initializes the library, if not called, first constructor call will do that. */
54 static initialize(): Promise<void>;
55 /** Creates a new chart and connects it to the div or canvas HTML
56 element specified by its ID or DOM object. The new chart is empty by
57 default, but can be set to an initial state in the second optional
58 parameter. */
59 constructor(options: VizzuOptions, initState?: Anim.Target);
60 private _getFeatureList;
61 /** If called as a function:
62 (name, enabled): it enables/disables built-in features and registered plugins.
63 (plugin, enabled?): registers the given plugin.
64 Otherwise gives access to the interfaces of the registered plugins, where
65 every plugin acceccible as a property with the plugin name. */
66 get feature(): Features;
67 private _feature;
68 /** Initiates the animation either to the new chart state passed as the first
69 argument, or through a sequence of keyframe charts passed as the first
70 argument. If there is a currently running animation, all subsequent
71 calls will schedule the corresponding animation after the end of the
72 previous one.
73 The new chart state or keyframe can be a full state specifier object with
74 data, config and style, or a single chart config object.
75 It accepts also a chart snapshot acquired from a previous state using
76 the store() method of this class or a whole previous animation acquired
77 using the store() method of the AnimControl object, which can be queried
78 from the promise returned by the animate() method.
79 The optional second parameter specifies the animation control options
80 and also all the other animation options in case of only a single chart
81 state passed as the first argument.
82 This second option can be a scalar value, setting the overall
83 animation duration. Passing explicit null as second parameter will
84 result in no animation.
85 The method returns a promise, which will resolve when the animation is
86 finished. Since there can be multiple animations in the queue, the result
87 promise provides a nested promise member `activated`,
88 which resolves when the requested animation gets active. */
89 animate(target: Anim.AnimTarget, options?: Anim.ControlOptions): AnimCompleting;
90 private _animate;
91 private _runAnimation;
92 /** Returns controls for the ongoing animation, if any.
93 @deprecated since version 0.4.0 */
94 get animation(): AnimControl;
95 /** Returns the version number of the library. */
96 version(): string;
97 /** Property for read-only access to data metainfo object. */
98 get data(): Mirrored<Data.Metainfo>;
99 /** Property for read-only access to chart parameter object. */
100 get config(): Mirrored<Config.Chart>;
101 /** Property for read-only access to style object without default values. */
102 get style(): Mirrored<Styles.Chart>;
103 /** Property for read-only access to the style object after setting defaults. */
104 getComputedStyle(): Mirrored<Styles.Chart>;
105 /** Installs the provided event handler to the event specified by name. */
106 on<T extends EventType>(eventName: T, handler: EventHandler<EventMap[T]>): void;
107 /** Uninstalls the provided event handler from the event specified by name. */
108 off<T extends EventType>(eventName: T, handler: EventHandler<EventMap[T]>): void;
109 /** Returns a reference to the actual chart state for further reuse.
110 This reference includes the chart config, style parameters and the
111 data filter but does not include the actual data and the animation options. */
112 store(): Snapshot;
113 /** Removes the reference of the chart from every place it attached itself,
114 this method must be called in order to get the chart properly garbage
115 collected. */
116 detach(): void;
117}