Files
WebApp/src/app/plot.ts
T
alberto 56d1ef2e8a WebApp shared: Plotly partial bundle, card actions, print report, export module
Plotly partial bundle (bar, scatter, box, pie, sankey, contour) replacing the cartesian dist; card-actions (published Measure definitions, settings, Volver); Descargar reporte with a print stylesheet; export module: xlsx with frozen header, autofilter, Parámetros sheet and 5,000-row cap, pdfmake documents with header/footer, allRows following next links, file names without patient identifiers; lazy-loaded export libraries.

Checks on milkpc (node:22): npm ci, ng build (initial 567 kB / 134 kB transfer), ng test 7 files passed.
2026-11-30 13:36:35 -06:00

59 lines
1.6 KiB
TypeScript

import { Component, effect, ElementRef, input, OnDestroy, viewChild } from '@angular/core';
import type * as Plotly from 'plotly.js';
import plotly from './plotly-bundle';
export type Figure = { data: Partial<Plotly.Data>[]; layout?: Partial<Plotly.Layout> };
/** The series colours today's charts use, in order. */
export const PALETTE = [
'#A8C243',
'#42C29C',
'#C24269',
'#9C42C2',
'#4269C2',
'#C29C42',
'#7A7A7A',
];
const LAYOUT: Partial<Plotly.Layout> = {
font: { family: 'Roboto, Arial, sans-serif', size: 14, color: '#17324d' },
colorway: PALETTE,
margin: { t: 24, r: 16, b: 48, l: 56 },
paper_bgcolor: 'rgba(0,0,0,0)',
plot_bgcolor: 'rgba(0,0,0,0)',
legend: { orientation: 'h', y: -0.2 },
};
const CONFIG: Partial<Plotly.Config> = {
responsive: true,
displaylogo: false,
modeBarButtonsToRemove: ['lasso2d', 'select2d'],
};
/** One Plotly chart: the figure, drawn with the platform's layout and config. */
@Component({
selector: 'app-plot',
template: '<div #host class="plot" [style.height.px]="height()"></div>',
styles: ':host { display: block; } .plot { width: 100%; }',
})
export class Plot implements OnDestroy {
readonly figure = input.required<Figure>();
readonly height = input(320);
private readonly host = viewChild.required<ElementRef<HTMLDivElement>>('host');
constructor() {
effect(() => {
const { data, layout } = this.figure();
void plotly.react(
this.host().nativeElement,
data as Plotly.Data[],
{ ...LAYOUT, ...layout },
CONFIG,
);
});
}
ngOnDestroy(): void {
plotly.purge(this.host().nativeElement);
}
}