feat(indicadores): agregar prototipo de dashboard TEA
Implementa el prototipo del dashboard de indicadores TEA. - Integra catálogo y figuras mediante WebApi. - Incorpora visualizaciones interactivas con Plotly.js. - Agrega controles de indicadores, figuras, periodos y temas. - Implementa estados de carga, errores y diseño responsive. - Incluye explicaciones para los contratos C1, C2 y C3r. - Incorpora pruebas unitarias y de integración de componentes. Prototipo para investigación con datos sintéticos.
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import { inject, Injectable } from '@angular/core';
|
||||
import { HttpClient, HttpParams } from '@angular/common/http';
|
||||
import { map } from 'rxjs';
|
||||
import { FigureSelection, Indicador, PlotlyFigure } from './indicadores.models';
|
||||
|
||||
function record(value: unknown): value is Record<string, unknown> {
|
||||
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
||||
}
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class IndicadoresService {
|
||||
private readonly http = inject(HttpClient);
|
||||
catalogo() {
|
||||
return this.http.get<unknown>('/tea/indicadores').pipe(map(value => {
|
||||
if (!Array.isArray(value) || !value.every(item => record(item)
|
||||
&& typeof item['id'] === 'string' && typeof item['titulo'] === 'string'
|
||||
&& typeof item['contrato'] === 'string' && Array.isArray(item['figuras'])
|
||||
&& item['figuras'].every((figure: unknown) => typeof figure === 'string'))) {
|
||||
throw new Error('Respuesta de catálogo inválida');
|
||||
}
|
||||
return value as Indicador[];
|
||||
}));
|
||||
}
|
||||
figura(selection: FigureSelection) {
|
||||
let params = new HttpParams().set('tema', selection.tema);
|
||||
if (selection.periodos?.length) params = params.set('periodos', selection.periodos.join(','));
|
||||
const url = `/tea/indicadores/${encodeURIComponent(selection.indicador)}/figuras/${encodeURIComponent(selection.figura)}`;
|
||||
return this.http.get<unknown>(url, { params }).pipe(map(value => {
|
||||
if (!record(value) || !Array.isArray(value['data']) || !value['data'].every(record)
|
||||
|| !record(value['layout'])) throw new Error('Respuesta de figura inválida');
|
||||
return value as unknown as PlotlyFigure;
|
||||
}));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user