Feature: Dashboard
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
<section class="dashboard" aria-labelledby="dashboard-title">
|
||||
<div class="dashboard__intro">
|
||||
<p class="dashboard__eyebrow">ISSSTELEON · Análisis de información</p>
|
||||
<h1 id="dashboard-title">Resultados del análisis</h1>
|
||||
<div class="dashboard__metadata">
|
||||
<span class="dashboard__area">{{ result.analysisType }}</span>
|
||||
<span class="dashboard__demo">Datos de demostración</span>
|
||||
</div>
|
||||
<p class="dashboard__note">Los indicadores y las gráficas muestran valores obtenidos del procesamiento de los datos.</p>
|
||||
</div>
|
||||
|
||||
<div class="dashboard__kpis" aria-label="Indicadores de demostración">
|
||||
@for (kpi of result.kpis; track kpi.label) {
|
||||
<article class="kpi">
|
||||
<p class="kpi__value">{{ kpi.value }}</p>
|
||||
<h2 class="kpi__label">{{ kpi.label }}</h2>
|
||||
</article>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="dashboard__charts">
|
||||
<article class="chart-card chart-card--bars" aria-labelledby="bars-title">
|
||||
<h2 id="bars-title">Distribución por categoría</h2>
|
||||
<app-plotly-chart [figure]="bars" aria-label="Gráfica de barras con categorías A a D, datos de demostración" />
|
||||
</article>
|
||||
<article class="chart-card chart-card--donut" aria-labelledby="donut-title">
|
||||
<h2 id="donut-title">Composición</h2>
|
||||
<app-plotly-chart [figure]="donut" aria-label="Gráfica de dona con segmentos A a C, datos de demostración" />
|
||||
</article>
|
||||
<article class="chart-card chart-card--line" aria-labelledby="line-title">
|
||||
<h2 id="line-title">Evolución por periodo</h2>
|
||||
<app-plotly-chart [figure]="line" aria-label="Gráfica de línea con periodos 1 a 6, datos de demostración" />
|
||||
</article>
|
||||
</div>
|
||||
</section>
|
||||
@@ -0,0 +1,40 @@
|
||||
// Datos exclusivos de demostración. No representan resultados clínicos ni un contrato de WebApi.
|
||||
export interface MockAnalysisResult {
|
||||
analysisType: 'CAMA';
|
||||
kpis: ReadonlyArray<{ label: string; value: string }>;
|
||||
charts: {
|
||||
categories: ReadonlyArray<{ label: string; value: number }>;
|
||||
composition: ReadonlyArray<{ label: string; value: number }>;
|
||||
periods: ReadonlyArray<{ label: string; value: number }>;
|
||||
};
|
||||
}
|
||||
|
||||
export const mockAnalysisResult: MockAnalysisResult = {
|
||||
analysisType: 'CAMA',
|
||||
kpis: [
|
||||
{ label: 'Indicador 1', value: '1,248' },
|
||||
{ label: 'Indicador 2', value: '64.2 %' },
|
||||
{ label: 'Indicador 3', value: '327' },
|
||||
],
|
||||
charts: {
|
||||
categories: [
|
||||
{ label: 'Categoría A', value: 12 },
|
||||
{ label: 'Categoría B', value: 19 },
|
||||
{ label: 'Categoría C', value: 9 },
|
||||
{ label: 'Categoría D', value: 15 },
|
||||
],
|
||||
composition: [
|
||||
{ label: 'Segmento A', value: 40 },
|
||||
{ label: 'Segmento B', value: 35 },
|
||||
{ label: 'Segmento C', value: 25 },
|
||||
],
|
||||
periods: [
|
||||
{ label: 'Periodo 1', value: 8 },
|
||||
{ label: 'Periodo 2', value: 11 },
|
||||
{ label: 'Periodo 3', value: 10 },
|
||||
{ label: 'Periodo 4', value: 15 },
|
||||
{ label: 'Periodo 5', value: 13 },
|
||||
{ label: 'Periodo 6', value: 18 },
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
:host { display: block; flex: 1; min-width: 0; }
|
||||
.dashboard { margin: 0 auto; max-width: 1440px; padding: 42px clamp(20px, 4vw, 56px) 72px; width: 100%; }
|
||||
.dashboard__eyebrow { color: var(--color-text-secondary); font-size: 12px; font-weight: 600; letter-spacing: .12em; margin: 0 0 12px; text-transform: uppercase; }
|
||||
h1, h2, p { margin-top: 0; }
|
||||
h1 { color: var(--color-text); font-family: var(--font-heading); font-size: clamp(32px, 3.8vw, 46px); line-height: 1.1; margin-bottom: 16px; }
|
||||
.dashboard__metadata { align-items: center; display: flex; flex-wrap: wrap; gap: 9px; }
|
||||
.dashboard__area, .dashboard__demo { border-radius: 999px; font-size: 13px; font-weight: 700; padding: 6px 12px; }
|
||||
.dashboard__area { background: #eaf0db; color: #465d1e; }
|
||||
.dashboard__demo { background: #eff4f3; color: #326a6c; }
|
||||
.dashboard__note { color: var(--color-text-secondary); font-size: 14px; line-height: 1.5; margin: 14px 0 0; }
|
||||
.dashboard__kpis { display: grid; gap: 18px; grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 32px 0 22px; }
|
||||
.kpi, .chart-card { background: #fff; border: 1px solid var(--color-border); border-radius: 12px; min-width: 0; }
|
||||
.kpi { padding: 22px 24px; }
|
||||
.kpi__value { color: #52691f; font-family: var(--font-heading); font-size: clamp(32px, 3.5vw, 42px); font-weight: 700; line-height: 1; margin: 0 0 8px; overflow-wrap: anywhere; }
|
||||
.kpi__label { color: var(--color-text); font-family: var(--font-body); font-size: 14px; font-weight: 500; margin: 0; }
|
||||
.dashboard__charts { display: grid; gap: 20px; grid-template-columns: minmax(0, 1.8fr) minmax(0, 1fr); }
|
||||
.chart-card { overflow: hidden; padding: 22px 22px 16px; }
|
||||
.chart-card h2 { color: var(--color-text); font-family: var(--font-heading); font-size: 22px; font-weight: 700; line-height: 1.2; margin: 0 0 12px; }
|
||||
.chart-card--line { grid-column: 1 / -1; }
|
||||
@media (max-width: 860px) { .dashboard__charts { grid-template-columns: minmax(0, 1fr); } .chart-card--line { grid-column: auto; } }
|
||||
@media (max-width: 600px) { .dashboard { padding: 30px 16px 48px; } .dashboard__kpis { grid-template-columns: minmax(0, 1fr); gap: 12px; margin-top: 26px; } .kpi { padding: 18px 20px; } .chart-card { padding: 18px 12px 12px; } .chart-card h2 { font-size: 20px; margin-left: 6px; } }
|
||||
@@ -0,0 +1,65 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { mockAnalysisResult } from './dashboard.mock';
|
||||
import { ChartFigure, PlotlyChart } from './plotly-chart';
|
||||
|
||||
const ink = '#081839';
|
||||
const grid = '#e9ede5';
|
||||
const green = '#6f821c';
|
||||
const darkGreen = '#465d1e';
|
||||
const teal = '#5f9ea0';
|
||||
const muted = '#7a7a7a';
|
||||
const font = { family: 'Roboto, sans-serif', color: ink, size: 12 };
|
||||
|
||||
@Component({
|
||||
imports: [PlotlyChart],
|
||||
selector: 'app-dashboard',
|
||||
styleUrl: './dashboard.scss',
|
||||
templateUrl: './dashboard.html',
|
||||
})
|
||||
export class Dashboard {
|
||||
readonly result = mockAnalysisResult;
|
||||
readonly bars: ChartFigure = {
|
||||
data: [{
|
||||
type: 'bar',
|
||||
x: this.result.charts.categories.map((item) => item.label),
|
||||
y: this.result.charts.categories.map((item) => item.value),
|
||||
marker: { color: [green, darkGreen, teal, '#a8c243'] },
|
||||
hovertemplate: '%{x}: %{y}<extra></extra>',
|
||||
}],
|
||||
layout: {
|
||||
paper_bgcolor: 'rgba(0,0,0,0)', plot_bgcolor: 'rgba(0,0,0,0)', font,
|
||||
margin: { l: 36, r: 12, t: 12, b: 48 }, showlegend: false,
|
||||
xaxis: { showgrid: false, linecolor: grid, automargin: true },
|
||||
yaxis: { showgrid: true, gridcolor: grid, zeroline: false, rangemode: 'tozero', automargin: true },
|
||||
},
|
||||
};
|
||||
readonly donut: ChartFigure = {
|
||||
data: [{
|
||||
type: 'pie', hole: 0.62,
|
||||
labels: this.result.charts.composition.map((item) => item.label),
|
||||
values: this.result.charts.composition.map((item) => item.value),
|
||||
marker: { colors: [green, teal, '#b5c69b'] },
|
||||
textinfo: 'none', hovertemplate: '%{label}: %{value}<extra></extra>', sort: false,
|
||||
}],
|
||||
layout: {
|
||||
paper_bgcolor: 'rgba(0,0,0,0)', plot_bgcolor: 'rgba(0,0,0,0)', font,
|
||||
margin: { l: 8, r: 8, t: 8, b: 8 },
|
||||
showlegend: true, legend: { orientation: 'h', x: 0.5, xanchor: 'center', y: -0.06, font: { color: ink, size: 11 } },
|
||||
},
|
||||
};
|
||||
readonly line: ChartFigure = {
|
||||
data: [{
|
||||
type: 'scatter', mode: 'lines+markers',
|
||||
x: this.result.charts.periods.map((item) => item.label),
|
||||
y: this.result.charts.periods.map((item) => item.value),
|
||||
line: { color: darkGreen, width: 3 }, marker: { color: green, size: 8 },
|
||||
hovertemplate: '%{x}: %{y}<extra></extra>',
|
||||
}],
|
||||
layout: {
|
||||
paper_bgcolor: 'rgba(0,0,0,0)', plot_bgcolor: 'rgba(0,0,0,0)', font,
|
||||
margin: { l: 36, r: 16, t: 12, b: 48 }, showlegend: false,
|
||||
xaxis: { showgrid: false, linecolor: grid, automargin: true },
|
||||
yaxis: { showgrid: true, gridcolor: grid, zeroline: false, rangemode: 'tozero', automargin: true },
|
||||
},
|
||||
};
|
||||
}
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
declare module 'plotly.js-basic-dist-min' {
|
||||
interface PlotlyBasic {
|
||||
react(element: HTMLElement, data: ReadonlyArray<Record<string, unknown>>, layout: Record<string, unknown>, config: Record<string, unknown>): Promise<unknown>;
|
||||
purge(element: HTMLElement): void;
|
||||
Plots: { resize(element: HTMLElement): void };
|
||||
}
|
||||
const Plotly: PlotlyBasic;
|
||||
export default Plotly;
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import { isPlatformBrowser } from '@angular/common';
|
||||
import { AfterViewInit, Component, ElementRef, inject, input, OnChanges, OnDestroy, PLATFORM_ID, viewChild } from '@angular/core';
|
||||
|
||||
export interface ChartFigure {
|
||||
data: ReadonlyArray<Record<string, unknown>>;
|
||||
layout: Record<string, unknown>;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-plotly-chart',
|
||||
template: '<div #plot class="plotly-chart__plot"></div>',
|
||||
styles: [':host { display: block; min-width: 0; width: 100%; } .plotly-chart__plot { min-width: 0; width: 100%; height: 290px; }'],
|
||||
})
|
||||
export class PlotlyChart implements AfterViewInit, OnChanges, OnDestroy {
|
||||
readonly figure = input.required<ChartFigure>();
|
||||
private readonly plot = viewChild.required<ElementRef<HTMLDivElement>>('plot');
|
||||
private readonly browser = isPlatformBrowser(inject(PLATFORM_ID));
|
||||
private plotly: (typeof import('plotly.js-basic-dist-min'))['default'] | null = null;
|
||||
private observer: ResizeObserver | null = null;
|
||||
private ready = false;
|
||||
private destroyed = false;
|
||||
|
||||
ngAfterViewInit(): void {
|
||||
if (!this.browser) return;
|
||||
this.ready = true;
|
||||
void this.render();
|
||||
this.observer = new ResizeObserver(() => {
|
||||
if (this.plotly && !this.destroyed) this.plotly.Plots.resize(this.plot().nativeElement);
|
||||
});
|
||||
this.observer.observe(this.plot().nativeElement);
|
||||
}
|
||||
|
||||
ngOnChanges(): void {
|
||||
if (this.ready) void this.render();
|
||||
}
|
||||
|
||||
private async render(): Promise<void> {
|
||||
// The import is evaluated only when a chart is mounted on the Dashboard route.
|
||||
const module = await import('plotly.js-basic-dist-min');
|
||||
if (this.destroyed) return;
|
||||
this.plotly = module.default;
|
||||
await this.plotly.react(this.plot().nativeElement, [...this.figure().data], {
|
||||
...this.figure().layout,
|
||||
autosize: true,
|
||||
}, { responsive: true, displayModeBar: false, displaylogo: false });
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroyed = true;
|
||||
this.observer?.disconnect();
|
||||
if (this.plotly) this.plotly.purge(this.plot().nativeElement);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user