feat(indicadores): dashboard interactivo multidominio y seguimiento CaCu

This commit is contained in:
Angel Capetillo Zavala
2026-10-22 17:10:35 -06:00
parent 9cc67c0ef2
commit 1fe88dfb45
62 changed files with 4380 additions and 187 deletions
+17 -1
View File
@@ -1,6 +1,11 @@
import { PlotlyFigure } from '../../features/indicadores/indicadores.models';
import { PlotlyRuntime } from './plotly-runtime';
interface EventHost extends HTMLElement {
on?: (name: string, listener: (event: unknown) => void) => void;
removeListener?: (name: string, listener: (event: unknown) => void) => void;
}
// One serialized queue owns the host. A completed stale operation cannot expose
// its graph or overwrite a newer react operation. Resize uses the same queue.
export class PlotlyController {
@@ -12,8 +17,13 @@ export class PlotlyController {
private resizePending = false;
private plotly?: PlotlyRuntime;
private frameCount = 0;
private listenerAttached = false;
private readonly handleClick = (event: unknown) => {
if (!this.destroyed && !this.busy && this.rendered === this.version) this.click?.(event);
};
constructor(private host: HTMLElement, private load: () => Promise<PlotlyRuntime>,
private state: (state: 'loading' | 'ready' | 'error') => void) {}
private state: (state: 'loading' | 'ready' | 'error') => void,
private click?: (event: unknown) => void) {}
setFigure(figure: PlotlyFigure) {
if (this.destroyed) return;
@@ -30,6 +40,8 @@ export class PlotlyController {
}
destroy() {
this.destroyed = true;
if (this.listenerAttached) (this.host as EventHost).removeListener?.('plotly_click', this.handleClick);
this.listenerAttached = false;
this.host.style.visibility = 'hidden';
this.plotly?.purge(this.host);
}
@@ -52,6 +64,10 @@ export class PlotlyController {
showSendToCloud: false,
modeBarButtonsToRemove: ['sendChartToCloud'],
});
if (!this.destroyed && !this.listenerAttached && this.click && (this.host as EventHost).on) {
(this.host as EventHost).on!('plotly_click', this.handleClick);
this.listenerAttached = true;
}
if (this.destroyed) break;
if (version !== this.version) continue;
if (figure.frames?.length) {