Files
WebApp/src/app/features/indicadores/indicador-figure-card.ts
T
2026-10-13 19:45:48 -06:00

105 lines
5.2 KiB
TypeScript

import { Component, Input, output, signal } from '@angular/core';
import { MatButtonModule } from '@angular/material/button';
import { MatIconModule } from '@angular/material/icon';
import { MatCardModule } from '@angular/material/card';
import { MatProgressBarModule } from '@angular/material/progress-bar';
import { Dominio, hasNoVisibleValues, Indicador, PlotlyFigure, Tema } from './indicadores.models';
import { figureTitle } from './indicadores.presentation';
import { figureIdentity, identityElementId } from './indicadores-identities';
import { PlotlyChart } from '../../shared/plotly/plotly-chart';
// The panel owns requests; the card receives the original and its presentation copy.
export interface FigureState {
status: 'idle' | 'loading' | 'ready' | 'error' | 'incompatible';
figure?: PlotlyFigure;
presentationFigure?: PlotlyFigure;
message?: string;
}
// Presentation only: contract semantics documented in G3 and G5C.
const CONTRACT_INTERPRETATIONS: Readonly<Record<string, readonly string[]>> = {
C1: [
'El punto representa la proporción observada.',
'En las figuras TEA con intervalos calculados, la línea vertical representa el intervalo de confianza Wilson al 95 %. No se infieren intervalos cuando faltan.',
'Los intervalos amplios pueden deberse a denominadores pequeños.',
'Un porcentaje observado del 100 % no implica certeza poblacional.',
],
C2: [
'Las barras muestran la composición porcentual de cada grupo y periodo.',
'Las categorías corresponden a la distribución de cada grupo y periodo.',
'SIN_DATO, cuando aparece, es una categoría legítima de la representación.',
],
C3r: [
'La caja representa Q1, mediana y Q3; no contiene observaciones individuales.',
'Los límites de dibujo no representan necesariamente extremos observados.',
'Plotly puede mostrar las etiquetas min/max para límites de dibujo derivados de Q1 y Q3. Estos valores no deben interpretarse como los extremos observados de los pacientes.',
],
};
const UNKNOWN_INTERPRETATION = ['No hay una explicación específica disponible para este contrato. Consulta las notas de la figura; no se infiere su significado estadístico.'];
@Component({
selector: 'app-indicador-figure-card',
standalone: true,
imports: [MatButtonModule, MatIconModule, MatCardModule, MatProgressBarModule, PlotlyChart],
templateUrl: './indicador-figure-card.html',
styleUrl: './indicador-figure-card.scss',
})
export class IndicadorFigureCard {
private currentState!: FigureState;
// Keep the mounted host's last presentation only. The template hides it whenever
// it is not the current result; this is neither applied state nor a results cache.
chartFigure?: PlotlyFigure;
@Input({ required: true }) set state(value: FigureState) {
this.currentState = value;
if (value.status === 'ready') this.chartFigure = value.presentationFigure;
}
get state() { return this.currentState; }
@Input() selected?: Indicador;
@Input({ required: true }) figuraId!: string;
@Input({ required: true }) dominio!: Dominio;
@Input({ required: true }) tema!: Tema;
readonly retry = output<void>();
readonly methodologyExpanded = signal(false);
get methodologyId(): string {
return identityElementId(figureIdentity(this.dominio, this.selected?.id ?? '', this.figuraId)) + '-methodology';
}
// Editorial classification of complete local sentences by known family.
// Keep mixed C3r/Wilson sentences and all backend content visible.
private get contract(): string | undefined {
return this.figuraId.startsWith('fig_c1') ? 'C1'
: this.figuraId.startsWith('fig_c2') ? 'C2'
: this.figuraId.startsWith('fig_c3r') ? 'C3r' : this.selected?.contrato;
}
private get complementaryLineCount(): number {
return this.contract === 'C1' ? 1
: this.contract === 'C2' ? (this.dominio === 'tea' ? 2 : 1) : 0;
}
get methodologyDetail(): readonly string[] {
return this.interpretation.slice(0, this.complementaryLineCount);
}
get visibleInterpretation(): readonly string[] {
return this.interpretation.slice(this.complementaryLineCount);
}
readonly hasNoVisibleValues = hasNoVisibleValues;
readonly figureTitle = figureTitle;
get interpretation(): readonly string[] {
const contract = this.contract;
if (contract === 'C2' && this.dominio !== 'tea') return [
'Las barras muestran la composición porcentual de las categorías publicadas para cada periodo.',
'SIN_DATO, cuando aparece, es una categoría legítima de la representación.',
'Los valores nulos o suprimidos no representan porcentajes observados de 0 %.',
];
if (contract === 'C1' && this.dominio !== 'tea') return [
'Los puntos representan porcentajes observados; el eje horizontal muestra el periodo.',
'Estas figuras no entregan intervalos Wilson efectivos; no se interpretan sus barras como intervalos al 95 %.',
'Los puntos suprimidos no representan tasas observadas de 0 %. Consulta las notas del servicio.',
'Un porcentaje observado del 100 % no implica certeza poblacional.',
];
return contract && Object.hasOwn(CONTRACT_INTERPRETATIONS, contract)
? [...CONTRACT_INTERPRETATIONS[contract], 'Los puntos suprimidos no representan tasas observadas de 0 %.'] : UNKNOWN_INTERPRETATION;
}
}