import { Question, Event, ITheme } from "survey-core"; import { DataProvider, GetDataFn } from "./dataProvider"; import { DashboardTheme } from "./theme"; import { SidebarWidget } from "./utils/sidebarWidget"; import { SideBarItemCreators } from "./sideBarItemCreators"; import "./visualizerBase.scss"; export interface IChartAdapter { getChartTypes(): string[]; create(chartNode: HTMLElement): Promise; update(chartNode: HTMLElement): Promise; destroy(node: HTMLElement): void; } export interface ICalculatedDataInfo { dataPath?: string; valueNames: Array; seriesNames?: Array; getLabel?(value: string): string; getSeriesLabel?(series: string): string; } export declare type ICalculationResult = { data: Array>; values: Array; series?: Array; }; export interface IAnswersData { datasets: Array>; values: Array; labels: Array; colors: Array; texts: Array>; seriesLabels: Array; labelsTitle?: string; valuesTitle?: string; } export interface IDataInfo { name: string; dataPath?: string; dataNames: Array; getValues(): Array; getLabels(): Array; getSeriesValues(): Array; getSeriesLabels(): Array; } export type ToolbarItemType = "button" | "dropdown" | "filter" | "license"; type ToolbarItemCreators = { [name: string]: { creator: (toolbar?: HTMLDivElement) => HTMLElement; type: ToolbarItemType; index: number; groupIndex: number; }; }; export declare class PostponeHelper { static postponeFunction: (fn: () => void, timeout?: number) => any; static postpone(fn: () => void, timeout?: number): any; } /** * A base object for all visualizers. Use it to implement a custom visualizer. * * Constructor parameters: * * - `question`: [`Question`](https://surveyjs.io/form-library/documentation/api-reference/question)\ * A survey question to visualize. * - `data`: `Array`\ * Survey results. * - `options`\ * An object with the following properties: * - `dataProvider`: `DataProvider`\ * A data provider for this visualizer. * - `renderContent`: `(contentContainer: HTMLElement, visualizer: VisualizerBase) => void`\ * A function that renders the visualizer's HTML markup. Append the markup to `contentContainer`. * - `survey`: [`SurveyModel`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model)\ * Pass a `SurveyModel` instance if you want to use locales from the survey JSON schema. * - `seriesValues`: `Array`\ * Series values used to group data. * - `seriesLabels`: `Array`\ * Series labels to display. If this property is not set, `seriesValues` are used as labels. * - `type`: `string`\ * *(Optional)* The visualizer's type. * * [View Demo](https://surveyjs.io/dashboard/examples/how-to-plot-survey-data-in-custom-bar-chart/ (linkStyle)) */ export declare class VisualizerBase implements IDataInfo { question: Question; options: { [index: string]: any; }; private _type?; static haveCommercialLicense: boolean; static suppressVisualizerStubRendering: boolean; static get chartAdapterType(): any; static set chartAdapterType(value: any); private _appliedTheme; private _theme; private _showToolbar; private _footerVisualizer; private _dataProvider; private _getDataCore; labelTruncateLength: number; protected haveCommercialLicense: boolean; protected renderResult: HTMLElement; protected toolbarContainer: HTMLElement; protected headerContainer: HTMLElement; protected contentContainer: HTMLElement; protected footerContainer: HTMLElement; protected bannerContainer: HTMLElement; protected wrapperContainer: HTMLElement; protected _supportSelection: boolean; protected _chartAdapter: IChartAdapter; static otherCommentCollapsed: boolean; protected _footerIsCollapsed: boolean; /** * Raised after the visualizer content is rendered. * * Parameters: * * - `sender`: `VisualizerBase`\ * The current `VisualizerBase` instance. * - `options.htmlElement`: `HTMLElement`\ * An `HTMLElement` that contains the rendered content. * @see render * @see refresh * @hidefor Dashboard, VisualizationPanel **/ onAfterRender: Event<(sender: VisualizerBase, options: any) => any, VisualizerBase, any>; protected afterRender(contentContainer: HTMLElement): void; /** * Raised after the locale changes. * * Parameters: * * - `sender`: `VisualizerBase`\ * The current `VisualizerBase` instance. * - `options.locale`: `string`\ * The indentifier of a new locale (for example, `"en"`). * @see locale */ onLocaleChanged: Event<(sender: VisualizerBase, options: { locale: string; }) => any, VisualizerBase, any>; /** * Raised when the visualizer [state](#state) changes. * * The state contains user-defined settings such as selected chart type, layout, sorting, filtering, and other runtime customizations. Handle this event to persist these customizations (for example, in `localStorage`) and restore them later. * * Parameters: * * - `sender`: `VisualizerBase`\ * The current `VisualizerBase` instance. * - `state`: `any`\ * The new state of the visualizer. * * [View Demo](https://surveyjs.io/dashboard/examples/save-dashboard-state-to-local-storage/ (linkStyle)) */ onStateChanged: Event<(sender: VisualizerBase, options: any) => any, VisualizerBase, any>; protected stateChanged(name: string, value: any): void; protected toolbarItemCreators: ToolbarItemCreators; onGetToolbarItemCreators: () => ToolbarItemCreators; protected sideBarItemCreators: SideBarItemCreators; onGetSideBarItemCreators: () => SideBarItemCreators; protected _sidebarWidget: SidebarWidget | undefined; protected getToolbarItemCreators(): ToolbarItemCreators; protected createSidebarPanelButton(_toolbar?: HTMLDivElement): HTMLElement; registerSideBarItem(name: string, creator: (container: HTMLDivElement) => HTMLElement, index?: number, groupIndex?: number): void; unregisterSideBarItem(name: string): ((container: HTMLDivElement) => HTMLElement) | undefined; constructor(question: Question, data: Array<{ [index: string]: any; }> | GetDataFn, options?: { [index: string]: any; }, _type?: string); protected get questionOptions(): any; protected onDataChanged(): void; protected getName(): string; protected get allowChangeType(): any; /** * Returns the identifier of a visualized question. * @hidefor Dashboard, VisualizationPanel */ get name(): string; get dataNames(): Array; get dataPath(): string; /** * Indicates whether the visualizer renders a header. Returns `true` if the question defines a [`correctAnswer`](https://surveyjs.io/form-library/documentation/api-reference/question#correctAnswer). * @see hasFooter * @hidefor Dashboard, VisualizationPanel */ get hasHeader(): boolean; /** * Indicates whether the visualizer renders a footer. Returns `true` if the question supports comments or an "Other" option. * @see hasHeader * @hidefor Dashboard, VisualizationPanel */ get hasFooter(): boolean; protected createVisualizer(question: Question, options?: { [index: string]: any; }, data?: any[]): T; /** * Returns the footer visualizer instance or `undefined` if the footer is not applicable. * @see hasFooter * @hidefor Dashboard, VisualizationPanel */ get footerVisualizer(): VisualizerBase; /** * Indicates whether users can select chart elements to apply cross-filtering. Controlled by the [`allowSelection`](https://surveyjs.io/dashboard/documentation/api-reference/idashboardoptions#allowSelection) option passed to the Dashboard. */ get supportSelection(): boolean; getSeriesValues(): Array; getSeriesLabels(): Array; getValues(): Array; getLabels(): Array; getChartAdapter(): IChartAdapter; /** * Registers a function used to create a toolbar item for this visualizer. * * The following code shows how to add a custom button and drop-down menu to the toolbar: * * ```js * import { VisualizationPanel, DocumentHelper } from "survey-analytics"; * * const vizPanel = new VisualizationPanel( ... ); * * // Add a custom button to the toolbar * vizPanel.visualizers[0].registerToolbarItem("my-toolbar-button", () => { * return DocumentHelper.createButton( * // A button click event handler * () => { * alert("Custom toolbar button is clicked"); * }, * // Button caption * "Button" * ); * }); * * // Add a custom drop-down menu to the toolbar * vizPanel.visualizers[0].registerToolbarItem("my-toolbar-dropdown", () => { * return DocumentHelper.createSelector( * // Menu items * [ * { value: 1, text: "One" }, * { value: 2, text: "Two" }, * { value: 3, text: "Three" } * ], * // A function that specifies initial selection * (option) => false, * // An event handler that is executed when selection is changed * (e) => { * alert(e.target.value); * } * ); * }); * ``` * @param name A custom name for the toolbar item. * @param creator A function that accepts the toolbar and should return an `HTMLElement` with the toolbar item. * @see unregisterToolbarItem * @hidefor Dashboard */ registerToolbarItem(name: string, creator: (toolbar?: HTMLDivElement) => HTMLElement, type: ToolbarItemType, index?: number, groupIndex?: number): void; /** * * Unregisters a function used to create a toolbar item. Allows you to remove a toolbar item. * @param name A toolbar item name. * @returns A function previously used to [register](#registerToolbarItem) the removed toolbar item. * @see registerToolbarItem * @hidefor Dashboard */ unregisterToolbarItem(name: string): (toolbar?: HTMLDivElement) => HTMLElement; /** * Returns the visualizer's title. * @since 2.3.8 * @hidefor Dashboard, VisualizationPanel */ get title(): string; protected getTitle(question: Question): string; /** * Returns the visualizer's type identifier. * @hidefor Dashboard, VisualizationPanel */ get type(): string; get dataType(): string; /** * @deprecated Use the [`surveyData`](https://surveyjs.io/dashboard/documentation/api-reference/visualizationpanel#surveyData) property instead. * @hidden */ protected get data(): any[]; /** * Returns an array of survey result objects used to calculate values for visualization. If a user applies a filter, the array is also filtered. * * To obtain calculated values, call [`getCalculatedValues()`](#getCalculatedValues). */ protected get surveyData(): any[]; protected get dataProvider(): DataProvider; /** * Updates the visualized data. * @param data An array of survey result objects or a data-loading function. */ updateData(data: Array<{ [index: string]: any; }> | GetDataFn): void; onUpdate: () => void; invokeOnUpdate(): void; /** * Deletes the visualizer and removes its DOM elements. * @see clear */ destroy(): void; /** * Clears the toolbar, header, content, and footer containers and removes the license banner and visualizer wrapper from the root. * * Does not remove the visualizer root element from the DOM. Use [`destroy()`](#destroy) to fully dispose of the visualizer. */ clear(): void; protected removeFromParent(element: HTMLElement): void; protected attachBanner(container: HTMLElement, banner: HTMLElement): void; getSortedToolbarItemCreators(): Array; protected createToolbarItems(toolbar: HTMLDivElement): void; protected getCorrectAnswerText(): string; resetContentFilter(): void; protected renderBanner(container: HTMLElement): void; protected destroyToolbar(container: HTMLElement): void; protected renderToolbar(container: HTMLElement): void; protected destroyHeader(container: HTMLElement): void; protected destroyContent(container: HTMLElement): void; protected renderHeader(container: HTMLElement): void; protected renderContentAsync(container: HTMLElement): Promise; protected ensureQuestionIsReady(): Promise; protected renderContent(container: HTMLElement): void; protected destroyFooter(container: HTMLElement): void; get isFooterCollapsed(): boolean; set isFooterCollapsed(newVal: boolean); protected renderFooter(container: HTMLElement): void; /** * Renders the visualizer inside a specified container. * @param targetElement An `HTMLElement` or the `id` of a DOM element. */ render(targetElement: HTMLElement | string, isRoot?: boolean): void; updateToolbar(): void; protected isSupportSoftUpdateContent(): boolean; protected softUpdateContent(): void; protected hardUpdateContent(): void; updateContent(): void; /** * Redraws the visualizer and its content. */ refresh(): void; refreshContent(): void; protected processText(text: string): string; getRandomColor(): string; private _backgroundColor; get backgroundColor(): any; set backgroundColor(value: any); protected getBackgroundColorCore(): any; protected setBackgroundColorCore(color: string): void; protected onThemeChanged(): void; get theme(): DashboardTheme; set theme(theme: DashboardTheme); /** * Applies a theme to the Dashboard. * @param theme An [`ITheme`](https://surveyjs.io/form-library/documentation/api-reference/itheme) object with theme settings. * @param baseTheme An optional [`ITheme`](https://surveyjs.io/form-library/documentation/api-reference/itheme) object used as the base theme. When specified, it is deep-merged with `theme`, and the merged result is applied. * @since 3.0.0 */ applyTheme(theme: ITheme, baseTheme?: ITheme): void; getColors(): string[]; /** * Gets or sets whether the toolbar is visible. * * Default value: `true` */ get showToolbar(): boolean; set showToolbar(newValue: boolean); /** * @deprecated Use the [`getCalculatedValues()`](https://surveyjs.io/dashboard/documentation/api-reference/visualizationpanel#getCalculatedValues) method instead. * @hidden */ getData(): any; private _calculationsCache; protected getCalculatedValuesCore(): ICalculationResult; protected loadingData: boolean; renderLoadingIndicator(contentContainer: HTMLElement): void; convertFromExternalData(externalCalculatedData: any): ICalculationResult; getAnswersData(): Promise; /** * Returns calculated values used for visualization. If a user applies a filter, the array is also filtered. * * To access an array of source survey results, use the [`surveyData`](#surveyData) property. */ getCalculatedValues(): Promise; protected _settingState: boolean; protected _defaultStateValue: any; getDefaultState(): any; /** * Returns an object with properties that describe the current visualizer state. The properties are different for each individual visualizer. * * > This method is overriden in classes descendant from `VisualizerBase`. * @see setState * @see resetState * @see onStateChanged * @hidefor Dashboard, VisualizationPanel */ getState(): any; protected setStateCore(state: any): void; /** * Sets the visualizer state. * * [View Demo](https://surveyjs.io/dashboard/examples/save-dashboard-state-to-local-storage/ (linkStyle)) * * > This method is overriden in classes descendant from `VisualizerBase`. * @see getState * @see resetState * @see onStateChanged * @hidefor Dashboard, VisualizationPanel */ setState(state: any): void; /** * Resets the visualizer state. * * > This method is overriden in classes descendant from `VisualizerBase`. * @see getState * @see setState * @see onStateChanged * @since 2.3.5 * @hidefor Dashboard, VisualizationPanel */ resetState(): void; /** * Gets or sets the current locale. * * If you want to inherit the locale from a visualized survey, assign a [`SurveyModel`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model) instance to the [`survey`](https://surveyjs.io/dashboard/documentation/api-reference/idashboardoptions#survey) option passed to the Dashboard. * * If the survey is [translated into more than one language](https://surveyjs.io/form-library/examples/survey-localization/), the dashboard toolbar displays a language selection drop-down menu. * * [View Demo](https://surveyjs.io/dashboard/examples/localize-survey-data-dashboard-ui/ (linkStyle)) * @see onLocaleChanged */ get locale(): string; set locale(newLocale: string); protected setLocale(newLocale: string): void; } export {};