diff --git a/src/app/features/indicadores/indicador-figure-panel.ts b/src/app/features/indicadores/indicador-figure-panel.ts index 8699c75..7ab6229 100644 --- a/src/app/features/indicadores/indicador-figure-panel.ts +++ b/src/app/features/indicadores/indicador-figure-panel.ts @@ -15,7 +15,7 @@ import { IndicadoresSnapshots } from './indicadores-snapshots'; import { c2Capability, c2Figure } from './indicadores-c2-adapter'; import { c2BarsHighlight, teaC2Donut } from './indicadores-tea-c2'; import { C1_AGE_BARS, C1_DONUT_ESTRATO, c1DonutCapability, c1DonutFigure } from './indicadores-c1-donut'; -import { stratifiedBars, stratifiedCapabilities, StratifiedCell } from './indicadores-stratified'; +import { etiquetaDimension, MedidaEstrato, stratifiedBars, stratifiedCapabilities, StratifiedCell } from './indicadores-stratified'; import { donutPeriodFigures, periodDatos } from './indicadores-donut-periods'; import { c2GeneralSelection } from './indicadores-c2-general-selection'; import { MatTooltipModule } from '@angular/material/tooltip'; @@ -48,10 +48,16 @@ import { MatTooltipModule } from '@angular/material/tooltip';
Selecciona un periodo para consultar la distribución estratificada.
} } @@ -70,8 +76,8 @@ import { MatTooltipModule } from '@angular/material/tooltip'; @if (hasSuppressedCells) {Hay celdas suprimidas: no se dibuja su magnitud y no representan un cero. Consulta su estado en la tabla de valores.
} @if (hasMissingCells) {Hay datos no disponibles; los espacios sin barra no representan un cero observado.
}| Categoría | Estrato | Conteo | |
|---|---|---|---|
| {{ cell.category }} | {{ cell.stratum }} | {{ cell.status === 'Publicado' ? cell.value : cell.status }} |
| Categoría | Estrato | Conteo | Porcentaje del estrato |
|---|---|---|---|
| {{ cell.category }} | {{ cell.stratum }} | {{ cell.status === 'Publicado' ? cell.value : cell.status }} | {{ cell.percent === null ? '—' : cell.percent + ' %' }} |
No hay categorías publicadas para esta selección.
} @@ -164,6 +170,18 @@ export class IndicadorFigurePanel implements OnChanges { return this.donutPages.find(p => p.period === this.activeDonutPeriod)!.state; } dimension: DimensionEstrato | '' = ''; + readonly etiquetaDimension = etiquetaDimension; + // Counts or each category's share of its stratum; an indicator can ask to open with the share. + private medidaElegida?: MedidaEstrato; + get medida(): MedidaEstrato { return this.medidaElegida ?? this.indicador.medida_estrato ?? 'conteo'; } + changeMedida(medida: MedidaEstrato) { + if (medida === this.medida) return; + this.medidaElegida = medida; + if (this.dimension && this.stratifiedData && this.result().status === 'ready') { + try { this.result.set(this.presentStratified(this.stratifiedData)); } + catch { this.result.set({ status: 'error', message: 'No se pudo representar la distribución.' }); } + } + } cells: StratifiedCell[] = []; get hasSuppressedCells() { return this.cells.some(c => c.status === 'Suprimido'); } get hasMissingCells() { return this.cells.some(c => c.status === 'No disponible'); } @@ -183,7 +201,7 @@ export class IndicadorFigurePanel implements OnChanges { } private presentStratified(data: IndicadorDatos): FigureState { const local = !this.localSelection.period || this.localSelection.period === data.periodos[0] ? this.localSelection : {}; - const adapted = stratifiedBars(data, this.dimension as DimensionEstrato, data.periodos[0], this.tema, local); + const adapted = stratifiedBars(data, this.dimension as DimensionEstrato, data.periodos[0], this.tema, local, this.medida); this.cells = adapted.cells; return { ...this.present(adapted.figure, { dominio: this.dominio, indicador: this.indicador.id, tipoPeriodo: this.applied.tipo, figura: this.figuraId, tema: this.tema, periodos: data.periodos }), diff --git a/src/app/features/indicadores/indicadores-stratified-panel.spec.ts b/src/app/features/indicadores/indicadores-stratified-panel.spec.ts index 39f831c..9ccf517 100644 --- a/src/app/features/indicadores/indicadores-stratified-panel.spec.ts +++ b/src/app/features/indicadores/indicadores-stratified-panel.spec.ts @@ -48,7 +48,9 @@ describe('Barras estratificadas: activación y caché',()=>{ toggle[1].click(); const stratified = request(); stratified.flush(age); fixture.detectChanges(); expect(fixture.componentInstance.dimension).toBe('grupo_edad'); expect(toggle[1].getAttribute('aria-checked')).toBe('true'); - expect(fixture.nativeElement.querySelectorAll('.distribution-dimensions [role="radio"]')).toHaveLength(2); + // The dimensions, apart from the counts or percentage toggle that follows them. + expect(fixture.nativeElement.querySelectorAll('.distribution-dimensions:not(.distribution-medida) [role="radio"]')).toHaveLength(2); + expect(fixture.nativeElement.querySelectorAll('.distribution-medida [role="radio"]')).toHaveLength(2); for(const button of toggle) { expect(button.tagName).toBe('BUTTON'); expect(button.type).toBe('button'); } }); it('deshabilita estratificación en multiperiodo y conserva el mensaje contextual',()=>{ diff --git a/src/app/features/indicadores/indicadores-stratified.spec.ts b/src/app/features/indicadores/indicadores-stratified.spec.ts index 9a1b389..3b6d8ad 100644 --- a/src/app/features/indicadores/indicadores-stratified.spec.ts +++ b/src/app/features/indicadores/indicadores-stratified.spec.ts @@ -1,6 +1,6 @@ import ageJson from './fixtures/cacu_eu7_datos_estrato_grupo_edad.json'; import statusJson from './fixtures/cacu_eu7_datos_estrato_estatus_seguimiento.json'; -import { stratifiedBars, stratifiedCapabilities } from './indicadores-stratified'; +import { etiquetaDimension, stratifiedBars, stratifiedCapabilities } from './indicadores-stratified'; import { DimensionEstrato, Indicador } from './indicadores.models'; const age = { ...ageJson, tipo_periodo: 'semestre' as const }; @@ -61,3 +61,33 @@ describe('Contratos simulados de estratificación de los analistas', () => { expect(()=>stratifiedBars(data,'grupo_edad','2025-S2','claro')).toThrow(); }); }); + +// A CaMa quantity of interest broken down by a stratifier: two strata of different size, one with a suppressed total. +const porEtapa = () => ({ + id: 'cama_birads_cancer_invasor', contrato: 'C2', tipo_periodo: 'semestre', periodos: ['2025-S1'], estrato: 'etapa', + valores_estrato: ['TEMPRANA', 'AVANZADA', 'SIN'], etiquetas_estrato: { TEMPRANA: 'Temprana', AVANZADA: 'Avanzada', SIN: 'Sin dato' }, + grupos: { TOTAL: 'Total' }, grupos_de_categoria: {}, categorias: { B4A: { etiqueta: 'BI-RADS 4A' }, B5: { etiqueta: 'BI-RADS 5' } }, + totales_estrato: [{ periodo: '2025-S1', grupo: 'TOTAL', estrato: 'TEMPRANA', n: 40, suprimido: 0 }, { periodo: '2025-S1', grupo: 'TOTAL', estrato: 'AVANZADA', n: 10, suprimido: 0 }, + { periodo: '2025-S1', grupo: 'TOTAL', estrato: 'SIN', n: null, suprimido: 1 }], + filas: [['TEMPRANA', 'B4A', 10], ['TEMPRANA', 'B5', 30], ['AVANZADA', 'B4A', 1], ['AVANZADA', 'B5', 9], ['SIN', 'B4A', null], ['SIN', 'B5', null]] + .map(([estrato, categoria, n], i) => ({ periodo: '2025-S1', grupo: 'TOTAL', estrato, categoria, n, orden: i % 2, suprimido: n === null ? 1 : 0 })), +}); +describe('Porcentaje en cada estrato', () => { + it('cada categoría es la parte de su estrato, y un estrato con total suprimido no tiene porcentaje', () => { + // Fails if the share is taken over the whole period instead of the stratum, or drawn over an unknown total. + const { figure, cells } = stratifiedBars(porEtapa() as never, 'etapa', '2025-S1', 'claro', {}, 'porcentaje'); + expect(cells.filter(c => c.stratum !== 'Sin dato').map(c => c.percent)).toEqual([25, 75, 10, 90]); + expect(cells.filter(c => c.stratum === 'Sin dato').map(c => c.percent)).toEqual([null, null]); + expect((figure.layout['xaxis'] as { title: { text: string } }).title.text).toBe('Porcentaje del estrato'); + expect(stratifiedBars(porEtapa() as never, 'etapa', '2025-S1', 'claro').figure.data[0]['x']).toEqual([10, 30]); + }); + it('las dimensiones de CaMa toman su etiqueta del catálogo, y CaCu conserva la suya', () => { + // Fails if a new stratifier is offered without its published label, or CaCu's wording changes. + const item = { id: 'x', titulo: 'X', contrato: 'C2', figuras: [], tipos_periodo: ['semestre'] as ['semestre'], + filtros: [{ estrato: 'etapa', etiqueta: 'Etapa (temprana o avanzada)', valores: [{ valor: 'TEMPRANA', etiqueta: 'Temprana' }] }, + { estrato: 'grupo_edad', etiqueta: 'Grupo de edad', valores: [{ valor: '40-49', etiqueta: '40-49' }] }] }; + expect(stratifiedCapabilities(item)).toEqual(['grupo_edad', 'etapa']); + expect(etiquetaDimension(item, 'etapa')).toBe('Por etapa (temprana o avanzada)'); + expect(etiquetaDimension(item, 'grupo_edad')).toBe('Por grupo de edad'); + }); +}); diff --git a/src/app/features/indicadores/indicadores-stratified.ts b/src/app/features/indicadores/indicadores-stratified.ts index a538df2..296dafd 100644 --- a/src/app/features/indicadores/indicadores-stratified.ts +++ b/src/app/features/indicadores/indicadores-stratified.ts @@ -4,14 +4,25 @@ import { c2Color, c2Theme } from './indicadores-c2-palette'; const record = (v: unknown): v is Record