21 lines
1.1 KiB
TypeScript
21 lines
1.1 KiB
TypeScript
import { InjectionToken } from '@angular/core';
|
|
import { PlotlyFigure } from '../../features/indicadores/indicadores.models';
|
|
|
|
// Narrow boundary for the official partial bundle, which ships without declarations.
|
|
export interface PlotlyRuntime {
|
|
react(host: HTMLElement, data: PlotlyFigure['data'], layout: PlotlyFigure['layout'], config: Record<string, unknown>): Promise<unknown>;
|
|
purge(host: HTMLElement): void;
|
|
Plots: { resize(host: HTMLElement): Promise<unknown> };
|
|
addFrames(host: HTMLElement, frames: Record<string, unknown>[]): Promise<unknown>;
|
|
deleteFrames(host: HTMLElement, indices: number[]): Promise<unknown>;
|
|
}
|
|
let runtime: Promise<PlotlyRuntime> | undefined;
|
|
export function loadPlotly(): Promise<PlotlyRuntime> {
|
|
return runtime ??= import('plotly.js-cartesian-dist-min')
|
|
.then(module => (module.default ?? module) as unknown as PlotlyRuntime)
|
|
.catch(error => { runtime = undefined; throw error; });
|
|
}
|
|
|
|
export const PLOTLY_LOADER = new InjectionToken<() => Promise<PlotlyRuntime>>('PLOTLY_LOADER', { providedIn: 'root', factory: () => loadPlotly });
|
|
|