@kaufmann-lab/ui 0.1.30 → 0.1.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/fesm2022/kaufmann-lab-ui-auth.mjs +38 -12
- package/fesm2022/kaufmann-lab-ui-auth.mjs.map +1 -1
- package/fesm2022/kaufmann-lab-ui-business.mjs +56 -7
- package/fesm2022/kaufmann-lab-ui-business.mjs.map +1 -1
- package/fesm2022/kaufmann-lab-ui-charts.mjs +1248 -0
- package/fesm2022/kaufmann-lab-ui-charts.mjs.map +1 -0
- package/fesm2022/kaufmann-lab-ui-core.mjs +10409 -4885
- package/fesm2022/kaufmann-lab-ui-core.mjs.map +1 -1
- package/fesm2022/kaufmann-lab-ui-map.mjs +301 -16
- package/fesm2022/kaufmann-lab-ui-map.mjs.map +1 -1
- package/fesm2022/kaufmann-lab-ui-shared.mjs +51 -20
- package/fesm2022/kaufmann-lab-ui-shared.mjs.map +1 -1
- package/fesm2022/kaufmann-lab-ui.mjs +4 -0
- package/fesm2022/kaufmann-lab-ui.mjs.map +1 -1
- package/package.json +5 -1
- package/src/tokens/base.css +102 -2
- package/src/tokens/density.css +27 -0
- package/src/tokens/index.css +5 -1
- package/src/tokens/themes/andes-maq.css +8 -0
- package/src/tokens/themes/divemotor-star.css +8 -0
- package/src/tokens/themes/kaufmann-ar.css +8 -0
- package/src/tokens/tones.css +52 -0
- package/types/kaufmann-lab-ui-auth.d.ts +23 -4
- package/types/kaufmann-lab-ui-business.d.ts +32 -2
- package/types/kaufmann-lab-ui-charts.d.ts +571 -0
- package/types/kaufmann-lab-ui-core.d.ts +2081 -57
- package/types/kaufmann-lab-ui-map.d.ts +113 -5
- package/types/kaufmann-lab-ui-shared.d.ts +25 -5
|
@@ -0,0 +1,1248 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { input, booleanAttribute, ChangeDetectionStrategy, ViewEncapsulation, Component, output, inject, LOCALE_ID, computed, model, ApplicationRef, EnvironmentInjector, DOCUMENT, createComponent, Injectable, numberAttribute, viewChild, signal, ChangeDetectorRef, Injector, DestroyRef, effect, untracked, afterNextRender, ElementRef } from '@angular/core';
|
|
3
|
+
import { formatNumber, NgTemplateOutlet } from '@angular/common';
|
|
4
|
+
import { Button, Icon, Link, Skeleton, DataTable, Modal } from '@kaufmann-lab/ui/core';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Grilla de paneles de gráfico con filas de alto fijo (`--kf-widget-row-height`,
|
|
8
|
+
* 560 px) desde 768 px, para que cada panel llene su celda y no haga falta
|
|
9
|
+
* scroll interno: una columna bajo 768 px, dos entre 768 y 1199 px y `columns`
|
|
10
|
+
* desde 1200 px. Esos anchos son los de la propia grilla (container query), no
|
|
11
|
+
* los del viewport: dentro de una pantalla con barra lateral decide el espacio
|
|
12
|
+
* real. Con `flow` (vacío, carga o error) el alto sigue al contenido y no
|
|
13
|
+
* reserva el de un gráfico con datos.
|
|
14
|
+
*
|
|
15
|
+
* Publica dos propiedades para sus descendientes: `--kf-widget-cap` (tope de
|
|
16
|
+
* filas de un listado Top-N cuando no hay alto fijo que medir; 0 = medir) y
|
|
17
|
+
* `--kf-widget-basis` (base flexible del cuerpo de cada panel: 0 con alto fijo,
|
|
18
|
+
* `auto` en una columna o con `flow`).
|
|
19
|
+
*
|
|
20
|
+
* Usa `ViewEncapsulation.None` porque sus reglas apuntan a los hijos
|
|
21
|
+
* proyectados (el tercer panel de 3 columnas, `.kf-widget-grid__full`), que el
|
|
22
|
+
* encapsulado emulado no alcanza.
|
|
23
|
+
*
|
|
24
|
+
* <kf-widget-grid [columns]="4">
|
|
25
|
+
* <kf-chart-panel title="…">…</kf-chart-panel>
|
|
26
|
+
* </kf-widget-grid>
|
|
27
|
+
*/
|
|
28
|
+
class WidgetGrid {
|
|
29
|
+
/** Columnas desde 1200 px: 4 (Tickets) o 3 (Flota). */
|
|
30
|
+
columns = input(4, /* @ts-ignore */
|
|
31
|
+
...(ngDevMode ? [{ debugName: "columns" }] : /* istanbul ignore next */ []));
|
|
32
|
+
/** Alto de cada fila desde 768 px; cualquier valor CSS. */
|
|
33
|
+
rowHeight = input('var(--kf-widget-row-height)', /* @ts-ignore */
|
|
34
|
+
...(ngDevMode ? [{ debugName: "rowHeight" }] : /* istanbul ignore next */ []));
|
|
35
|
+
/** Alto según el contenido, para estados vacío, de carga o de error. */
|
|
36
|
+
flow = input(false, { ...(ngDevMode ? { debugName: "flow" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
37
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.0", ngImport: i0, type: WidgetGrid, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
38
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "22.1.0", type: WidgetGrid, isStandalone: true, selector: "kf-widget-grid", inputs: { columns: { classPropertyName: "columns", publicName: "columns", isSignal: true, isRequired: false, transformFunction: null }, rowHeight: { classPropertyName: "rowHeight", publicName: "rowHeight", isSignal: true, isRequired: false, transformFunction: null }, flow: { classPropertyName: "flow", publicName: "flow", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "class.kf-widget-grid--3": "columns() === 3", "class.kf-widget-grid--4": "columns() === 4", "class.kf-widget-grid--flow": "flow()", "style.--kf-widget-row": "rowHeight()" }, classAttribute: "kf-widget-grid" }, ngImport: i0, template: '<div class="kf-widget-grid__grid"><ng-content /></div>', isInline: true, styles: [".kf-widget-grid{display:block;width:100%;min-width:0;container-type:inline-size}.kf-widget-grid__grid{--kf-widget-cap: 6;--kf-widget-basis: auto;display:grid;grid-template-columns:minmax(0,1fr);align-items:stretch;gap:var(--kf-space-md);min-width:0}@container (min-width: 768px){.kf-widget-grid__grid{--kf-widget-cap: 0;--kf-widget-basis: 0px;grid-template-columns:repeat(2,minmax(0,1fr));grid-auto-rows:var(--kf-widget-row, var(--kf-widget-row-height))}.kf-widget-grid--3>.kf-widget-grid__grid>:nth-child(3){grid-column:1 / -1}}@container (min-width: 1200px){.kf-widget-grid--4>.kf-widget-grid__grid{grid-template-columns:repeat(4,minmax(0,1fr))}.kf-widget-grid--3>.kf-widget-grid__grid{grid-template-columns:repeat(3,minmax(0,1fr))}.kf-widget-grid--3>.kf-widget-grid__grid>:nth-child(3){grid-column:auto}}.kf-widget-grid--flow>.kf-widget-grid__grid{--kf-widget-cap: 8;--kf-widget-basis: auto;grid-auto-rows:auto}.kf-widget-grid__grid>.kf-widget-grid__full{grid-column:1 / -1}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
|
|
39
|
+
}
|
|
40
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.0", ngImport: i0, type: WidgetGrid, decorators: [{
|
|
41
|
+
type: Component,
|
|
42
|
+
args: [{ selector: 'kf-widget-grid', template: '<div class="kf-widget-grid__grid"><ng-content /></div>', encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, host: {
|
|
43
|
+
class: 'kf-widget-grid',
|
|
44
|
+
'[class.kf-widget-grid--3]': 'columns() === 3',
|
|
45
|
+
'[class.kf-widget-grid--4]': 'columns() === 4',
|
|
46
|
+
'[class.kf-widget-grid--flow]': 'flow()',
|
|
47
|
+
'[style.--kf-widget-row]': 'rowHeight()',
|
|
48
|
+
}, styles: [".kf-widget-grid{display:block;width:100%;min-width:0;container-type:inline-size}.kf-widget-grid__grid{--kf-widget-cap: 6;--kf-widget-basis: auto;display:grid;grid-template-columns:minmax(0,1fr);align-items:stretch;gap:var(--kf-space-md);min-width:0}@container (min-width: 768px){.kf-widget-grid__grid{--kf-widget-cap: 0;--kf-widget-basis: 0px;grid-template-columns:repeat(2,minmax(0,1fr));grid-auto-rows:var(--kf-widget-row, var(--kf-widget-row-height))}.kf-widget-grid--3>.kf-widget-grid__grid>:nth-child(3){grid-column:1 / -1}}@container (min-width: 1200px){.kf-widget-grid--4>.kf-widget-grid__grid{grid-template-columns:repeat(4,minmax(0,1fr))}.kf-widget-grid--3>.kf-widget-grid__grid{grid-template-columns:repeat(3,minmax(0,1fr))}.kf-widget-grid--3>.kf-widget-grid__grid>:nth-child(3){grid-column:auto}}.kf-widget-grid--flow>.kf-widget-grid__grid{--kf-widget-cap: 8;--kf-widget-basis: auto;grid-auto-rows:auto}.kf-widget-grid__grid>.kf-widget-grid__full{grid-column:1 / -1}\n"] }]
|
|
49
|
+
}], propDecorators: { columns: [{ type: i0.Input, args: [{ isSignal: true, alias: "columns", required: false }] }], rowHeight: [{ type: i0.Input, args: [{ isSignal: true, alias: "rowHeight", required: false }] }], flow: [{ type: i0.Input, args: [{ isSignal: true, alias: "flow", required: false }] }] } });
|
|
50
|
+
|
|
51
|
+
let nextPanelId = 0;
|
|
52
|
+
/**
|
|
53
|
+
* Panel de un gráfico: cabecera (título, período, cifra resumen, botón de
|
|
54
|
+
* tabla), cuerpo que llena la celda y pie con «Ver todos (N)». No tiene
|
|
55
|
+
* overflow propio: el cuerpo se recorta con el Top-N de `kf-ranked-bars`.
|
|
56
|
+
*
|
|
57
|
+
* Es una región con nombre (`role="region"` etiquetada por su título): el título
|
|
58
|
+
* es un `h3` por defecto (`headingLevel` 2 si es el primer encabezado de la
|
|
59
|
+
* sección). Vacío, carga y error reemplazan al cuerpo sin cambiar la cabecera;
|
|
60
|
+
* el botón de tabla (`table`) ofrece la alternativa textual del gráfico y el
|
|
61
|
+
* dueño atiende `viewTable` (ver `KfChartTableDialog`).
|
|
62
|
+
*
|
|
63
|
+
* Proyecta `[kfChartLegend]` sobre el cuerpo, el contenido por defecto y
|
|
64
|
+
* `[kfChartFoot]` en el pie. Dentro de `kf-widget-grid` con alto fijo el cuerpo
|
|
65
|
+
* toma el alto de la celda (`--kf-widget-basis`).
|
|
66
|
+
*
|
|
67
|
+
* <kf-chart-panel title="Cumplimiento de SLA" icon="shield-check" [total]="12" [shown]="6"
|
|
68
|
+
* table (viewAll)="verTodos()" (viewTable)="verTabla()">
|
|
69
|
+
* <kf-ranked-bars [items]="filas()" (fitChange)="shown.set($event.shown)" />
|
|
70
|
+
* </kf-chart-panel>
|
|
71
|
+
*/
|
|
72
|
+
class ChartPanel {
|
|
73
|
+
title = input.required(/* @ts-ignore */
|
|
74
|
+
...(ngDevMode ? [{ debugName: "title" }] : /* istanbul ignore next */ []));
|
|
75
|
+
icon = input(/* @ts-ignore */
|
|
76
|
+
...(ngDevMode ? [undefined, { debugName: "icon" }] : /* istanbul ignore next */ []));
|
|
77
|
+
subtitle = input(/* @ts-ignore */
|
|
78
|
+
...(ngDevMode ? [undefined, { debugName: "subtitle" }] : /* istanbul ignore next */ []));
|
|
79
|
+
stat = input(/* @ts-ignore */
|
|
80
|
+
...(ngDevMode ? [undefined, { debugName: "stat" }] : /* istanbul ignore next */ []));
|
|
81
|
+
statSub = input(/* @ts-ignore */
|
|
82
|
+
...(ngDevMode ? [undefined, { debugName: "statSub" }] : /* istanbul ignore next */ []));
|
|
83
|
+
statTone = input('neutral', /* @ts-ignore */
|
|
84
|
+
...(ngDevMode ? [{ debugName: "statTone" }] : /* istanbul ignore next */ []));
|
|
85
|
+
state = input('ready', /* @ts-ignore */
|
|
86
|
+
...(ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []));
|
|
87
|
+
emptyTitle = input('Sin datos', /* @ts-ignore */
|
|
88
|
+
...(ngDevMode ? [{ debugName: "emptyTitle" }] : /* istanbul ignore next */ []));
|
|
89
|
+
emptyText = input(/* @ts-ignore */
|
|
90
|
+
...(ngDevMode ? [undefined, { debugName: "emptyText" }] : /* istanbul ignore next */ []));
|
|
91
|
+
errorTitle = input('No se pudo cargar', /* @ts-ignore */
|
|
92
|
+
...(ngDevMode ? [{ debugName: "errorTitle" }] : /* istanbul ignore next */ []));
|
|
93
|
+
errorText = input(/* @ts-ignore */
|
|
94
|
+
...(ngDevMode ? [undefined, { debugName: "errorText" }] : /* istanbul ignore next */ []));
|
|
95
|
+
/** Texto de lector de pantalla mientras `state` es `loading`. */
|
|
96
|
+
loadingLabel = input('Calculando…', /* @ts-ignore */
|
|
97
|
+
...(ngDevMode ? [{ debugName: "loadingLabel" }] : /* istanbul ignore next */ []));
|
|
98
|
+
retryLabel = input('Reintentar', /* @ts-ignore */
|
|
99
|
+
...(ngDevMode ? [{ debugName: "retryLabel" }] : /* istanbul ignore next */ []));
|
|
100
|
+
/** Pista del pie, p. ej. «Clic en un estado filtra la tabla». */
|
|
101
|
+
hint = input(/* @ts-ignore */
|
|
102
|
+
...(ngDevMode ? [undefined, { debugName: "hint" }] : /* istanbul ignore next */ []));
|
|
103
|
+
/** Filas totales y filas mostradas: el pie ofrece «Ver todos» si shown < total. */
|
|
104
|
+
total = input(/* @ts-ignore */
|
|
105
|
+
...(ngDevMode ? [undefined, { debugName: "total" }] : /* istanbul ignore next */ []));
|
|
106
|
+
shown = input(/* @ts-ignore */
|
|
107
|
+
...(ngDevMode ? [undefined, { debugName: "shown" }] : /* istanbul ignore next */ []));
|
|
108
|
+
/** Texto del enlace del pie; el total se agrega entre paréntesis. */
|
|
109
|
+
viewAllText = input('Ver todos', /* @ts-ignore */
|
|
110
|
+
...(ngDevMode ? [{ debugName: "viewAllText" }] : /* istanbul ignore next */ []));
|
|
111
|
+
/** Palabra final de «y 5 más», el aviso de las filas que el Top-N dejó fuera. */
|
|
112
|
+
moreText = input('más', /* @ts-ignore */
|
|
113
|
+
...(ngDevMode ? [{ debugName: "moreText" }] : /* istanbul ignore next */ []));
|
|
114
|
+
/** Muestra el botón de tabla de la cabecera; el dueño atiende `viewTable`. */
|
|
115
|
+
table = input(false, { ...(ngDevMode ? { debugName: "table" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
116
|
+
/** Nombre accesible del botón de tabla; por defecto se arma con el título. */
|
|
117
|
+
tableLabel = input(/* @ts-ignore */
|
|
118
|
+
...(ngDevMode ? [undefined, { debugName: "tableLabel" }] : /* istanbul ignore next */ []));
|
|
119
|
+
headingLevel = input(3, /* @ts-ignore */
|
|
120
|
+
...(ngDevMode ? [{ debugName: "headingLevel" }] : /* istanbul ignore next */ []));
|
|
121
|
+
viewAll = output();
|
|
122
|
+
viewTable = output();
|
|
123
|
+
retry = output();
|
|
124
|
+
locale = inject(LOCALE_ID);
|
|
125
|
+
titleId = `kf-chart-panel-${nextPanelId++}-title`;
|
|
126
|
+
tableButtonLabel = computed(() => this.tableLabel() ?? `Ver «${this.title()}» como tabla de datos`, /* @ts-ignore */
|
|
127
|
+
...(ngDevMode ? [{ debugName: "tableButtonLabel" }] : /* istanbul ignore next */ []));
|
|
128
|
+
viewAllLabel = computed(() => {
|
|
129
|
+
const total = this.total();
|
|
130
|
+
return total === undefined
|
|
131
|
+
? ''
|
|
132
|
+
: `${this.viewAllText()} (${formatNumber(total, this.locale, '1.0-0')})`;
|
|
133
|
+
}, /* @ts-ignore */
|
|
134
|
+
...(ngDevMode ? [{ debugName: "viewAllLabel" }] : /* istanbul ignore next */ []));
|
|
135
|
+
hasMore = computed(() => {
|
|
136
|
+
const total = this.total();
|
|
137
|
+
const shown = this.shown();
|
|
138
|
+
return total !== undefined && shown !== undefined && shown < total;
|
|
139
|
+
}, /* @ts-ignore */
|
|
140
|
+
...(ngDevMode ? [{ debugName: "hasMore" }] : /* istanbul ignore next */ []));
|
|
141
|
+
/** «y 5 más»: cuántas filas del total quedaron fuera del Top-N. */
|
|
142
|
+
moreLabel = computed(() => {
|
|
143
|
+
const hidden = (this.total() ?? 0) - (this.shown() ?? 0);
|
|
144
|
+
return `y ${formatNumber(hidden, this.locale, '1.0-0')} ${this.moreText()}`;
|
|
145
|
+
}, /* @ts-ignore */
|
|
146
|
+
...(ngDevMode ? [{ debugName: "moreLabel" }] : /* istanbul ignore next */ []));
|
|
147
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.0", ngImport: i0, type: ChartPanel, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
148
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1.0", type: ChartPanel, isStandalone: true, selector: "kf-chart-panel", inputs: { title: { classPropertyName: "title", publicName: "title", isSignal: true, isRequired: true, transformFunction: null }, icon: { classPropertyName: "icon", publicName: "icon", isSignal: true, isRequired: false, transformFunction: null }, subtitle: { classPropertyName: "subtitle", publicName: "subtitle", isSignal: true, isRequired: false, transformFunction: null }, stat: { classPropertyName: "stat", publicName: "stat", isSignal: true, isRequired: false, transformFunction: null }, statSub: { classPropertyName: "statSub", publicName: "statSub", isSignal: true, isRequired: false, transformFunction: null }, statTone: { classPropertyName: "statTone", publicName: "statTone", isSignal: true, isRequired: false, transformFunction: null }, state: { classPropertyName: "state", publicName: "state", isSignal: true, isRequired: false, transformFunction: null }, emptyTitle: { classPropertyName: "emptyTitle", publicName: "emptyTitle", isSignal: true, isRequired: false, transformFunction: null }, emptyText: { classPropertyName: "emptyText", publicName: "emptyText", isSignal: true, isRequired: false, transformFunction: null }, errorTitle: { classPropertyName: "errorTitle", publicName: "errorTitle", isSignal: true, isRequired: false, transformFunction: null }, errorText: { classPropertyName: "errorText", publicName: "errorText", isSignal: true, isRequired: false, transformFunction: null }, loadingLabel: { classPropertyName: "loadingLabel", publicName: "loadingLabel", isSignal: true, isRequired: false, transformFunction: null }, retryLabel: { classPropertyName: "retryLabel", publicName: "retryLabel", isSignal: true, isRequired: false, transformFunction: null }, hint: { classPropertyName: "hint", publicName: "hint", isSignal: true, isRequired: false, transformFunction: null }, total: { classPropertyName: "total", publicName: "total", isSignal: true, isRequired: false, transformFunction: null }, shown: { classPropertyName: "shown", publicName: "shown", isSignal: true, isRequired: false, transformFunction: null }, viewAllText: { classPropertyName: "viewAllText", publicName: "viewAllText", isSignal: true, isRequired: false, transformFunction: null }, moreText: { classPropertyName: "moreText", publicName: "moreText", isSignal: true, isRequired: false, transformFunction: null }, table: { classPropertyName: "table", publicName: "table", isSignal: true, isRequired: false, transformFunction: null }, tableLabel: { classPropertyName: "tableLabel", publicName: "tableLabel", isSignal: true, isRequired: false, transformFunction: null }, headingLevel: { classPropertyName: "headingLevel", publicName: "headingLevel", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { viewAll: "viewAll", viewTable: "viewTable", retry: "retry" }, host: { attributes: { "role": "region" }, properties: { "attr.aria-labelledby": "titleId", "attr.aria-busy": "state() === 'loading' ? 'true' : null" } }, ngImport: i0, template: "<ng-template #titleContent>\n @if (icon(); as iconName) {\n <kf-icon [name]=\"iconName\" size=\"sm\" />\n }\n <span>{{ title() }}</span>\n</ng-template>\n\n<header class=\"kf-chart-panel__head\">\n <div class=\"kf-chart-panel__titles\">\n @if (headingLevel() === 2) {\n <h2 class=\"kf-chart-panel__title\" [id]=\"titleId\">\n <ng-container *ngTemplateOutlet=\"titleContent\" />\n </h2>\n } @else {\n <h3 class=\"kf-chart-panel__title\" [id]=\"titleId\">\n <ng-container *ngTemplateOutlet=\"titleContent\" />\n </h3>\n }\n @if (subtitle()) {\n <p class=\"kf-chart-panel__subtitle\">{{ subtitle() }}</p>\n }\n </div>\n @if (state() === 'ready' && (stat() || table())) {\n <div class=\"kf-chart-panel__aside\">\n @if (stat()) {\n <div\n class=\"kf-chart-panel__stat\"\n [class]=\"'kf-chart-panel__stat kf-chart-panel__stat--' + statTone()\"\n >\n {{ stat() }}\n @if (statSub()) {\n <small>{{ statSub() }}</small>\n }\n </div>\n }\n @if (table()) {\n <kf-button\n class=\"kf-chart-panel__table-button\"\n type=\"button\"\n variant=\"outline\"\n size=\"sm\"\n shape=\"circle\"\n icon=\"list\"\n [ariaLabel]=\"tableButtonLabel()\"\n (click)=\"viewTable.emit()\"\n />\n }\n </div>\n }\n</header>\n\n@switch (state()) {\n @case ('empty') {\n <div class=\"kf-chart-panel__state\" role=\"status\">\n @if (icon(); as iconName) {\n <kf-icon [name]=\"iconName\" size=\"lg\" />\n }\n <strong>{{ emptyTitle() }}</strong>\n @if (emptyText()) {\n <span>{{ emptyText() }}</span>\n }\n </div>\n }\n @case ('loading') {\n <div class=\"kf-chart-panel__skeleton\">\n <span class=\"kf-sr-only\">{{ loadingLabel() }}</span>\n <kf-skeleton variant=\"text\" width=\"90%\" />\n <kf-skeleton variant=\"text\" width=\"70%\" />\n <kf-skeleton variant=\"text\" width=\"80%\" />\n <kf-skeleton variant=\"text\" width=\"55%\" />\n </div>\n }\n @case ('error') {\n <div class=\"kf-chart-panel__state\" role=\"alert\">\n <kf-icon name=\"alert-circle\" size=\"lg\" />\n <strong>{{ errorTitle() }}</strong>\n @if (errorText()) {\n <span>{{ errorText() }}</span>\n }\n <kf-button type=\"button\" variant=\"outline\" size=\"sm\" icon=\"history\" (click)=\"retry.emit()\">\n {{ retryLabel() }}\n </kf-button>\n </div>\n }\n}\n\n<div class=\"kf-chart-panel__body\" [hidden]=\"state() !== 'ready'\">\n <ng-content select=\"[kfChartLegend]\" />\n <ng-content />\n</div>\n\n@if (state() === 'ready') {\n <footer class=\"kf-chart-panel__foot\">\n <span class=\"kf-chart-panel__hint\">{{ hint() }}</span>\n <ng-content select=\"[kfChartFoot]\" />\n @if (hasMore()) {\n <span class=\"kf-chart-panel__more\">\n <span>{{ moreLabel() }}</span>\n <kf-link class=\"kf-chart-panel__link\" (click)=\"viewAll.emit()\">\n {{ viewAllLabel() }}\n </kf-link>\n </span>\n }\n </footer>\n}\n", styles: [".kf-sr-only{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap;border:0}:host{display:flex;flex-direction:column;gap:var(--kf-space-sm);min-width:0;min-height:0;margin:0;padding:var(--kf-space-md);border:1px solid var(--kf-color-border);border-radius:var(--kf-radius-md);background:var(--kf-color-white);box-shadow:var(--kf-shadow-sm)}.kf-chart-panel__head{display:flex;flex-wrap:wrap;align-items:flex-start;gap:var(--kf-space-xs) var(--kf-space-sm)}.kf-chart-panel__titles{flex:1 1 8rem;min-width:0}.kf-chart-panel__title{display:flex;align-items:flex-start;gap:6px;margin:0;font-family:var(--kf-font-title);font-size:var(--kf-font-size-body-sm);font-weight:700;line-height:1.25;color:var(--kf-color-ink)}.kf-chart-panel__title span{min-width:0;overflow-wrap:break-word}.kf-chart-panel__title kf-icon{flex:none;margin-top:1px;color:var(--kf-chart-text-muted)}.kf-chart-panel__subtitle{margin:3px 0 0;font-size:var(--kf-font-size-caption);line-height:1.35;color:var(--kf-chart-text-muted)}.kf-chart-panel__aside{display:flex;flex:0 0 auto;margin-left:auto;align-items:flex-start;gap:var(--kf-space-sm)}.kf-chart-panel__stat{font-family:var(--kf-font-title);font-size:var(--kf-font-size-title-md);font-weight:700;line-height:1;font-variant-numeric:tabular-nums;text-align:right;white-space:nowrap;color:var(--kf-color-ink)}.kf-chart-panel__stat small{display:block;margin-top:3px;font-family:var(--kf-font-body);font-size:var(--kf-font-size-caption);font-weight:400;color:var(--kf-chart-text-muted)}.kf-chart-panel__stat--ok{color:var(--kf-color-success-strong)}.kf-chart-panel__stat--warn{color:var(--kf-color-warning-strong)}.kf-chart-panel__stat--risk{color:var(--kf-color-error-strong)}.kf-chart-panel__table-button{flex:0 0 auto}.kf-chart-panel__body{display:flex;flex:1 1 var(--kf-widget-basis, auto);flex-direction:column;gap:var(--kf-space-sm);min-width:0;min-height:0}.kf-chart-panel__body[hidden]{display:none}.kf-chart-panel__state{display:flex;flex:1 1 auto;flex-direction:column;align-items:center;justify-content:center;gap:var(--kf-space-xs);padding:var(--kf-space-sm);font-size:var(--kf-font-size-label);line-height:1.4;text-align:center;color:var(--kf-chart-text-muted)}.kf-chart-panel__state strong{font-size:var(--kf-font-size-body-sm);color:var(--kf-color-ink)}.kf-chart-panel__skeleton{position:relative;display:flex;flex:1 1 auto;flex-direction:column;gap:var(--kf-space-md)}.kf-chart-panel__foot{display:flex;flex-wrap:wrap;align-items:center;justify-content:space-between;gap:var(--kf-space-xs) var(--kf-space-sm);min-height:28px;font-size:var(--kf-font-size-caption);color:var(--kf-chart-text-muted)}.kf-chart-panel__hint{flex:1 1 8rem;min-width:0}.kf-chart-panel__hint:empty{display:none}.kf-chart-panel__more{display:inline-flex;flex:0 0 auto;align-items:center;gap:var(--kf-space-sm);margin-left:auto;white-space:nowrap}.kf-chart-panel__link{--kf-link-min-height: 24px;font-size:var(--kf-font-size-label);font-weight:600}\n"], dependencies: [{ kind: "component", type: Button, selector: "kf-button", inputs: ["variant", "size", "shape", "disabled", "type", "icon", "block", "loading", "ariaLabel", "ariaExpanded", "ariaPressed", "ariaDisabled", "ariaControls", "ariaHaspopup"] }, { kind: "component", type: Icon, selector: "kf-icon", inputs: ["name", "size", "rotate", "filled"] }, { kind: "component", type: Link, selector: "kf-link", inputs: ["variant", "disabled", "href", "showArrow"] }, { kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "component", type: Skeleton, selector: "kf-skeleton", inputs: ["variant", "width", "height"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
149
|
+
}
|
|
150
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.0", ngImport: i0, type: ChartPanel, decorators: [{
|
|
151
|
+
type: Component,
|
|
152
|
+
args: [{ selector: 'kf-chart-panel', imports: [Button, Icon, Link, NgTemplateOutlet, Skeleton], changeDetection: ChangeDetectionStrategy.OnPush, host: {
|
|
153
|
+
role: 'region',
|
|
154
|
+
'[attr.aria-labelledby]': 'titleId',
|
|
155
|
+
'[attr.aria-busy]': "state() === 'loading' ? 'true' : null",
|
|
156
|
+
}, template: "<ng-template #titleContent>\n @if (icon(); as iconName) {\n <kf-icon [name]=\"iconName\" size=\"sm\" />\n }\n <span>{{ title() }}</span>\n</ng-template>\n\n<header class=\"kf-chart-panel__head\">\n <div class=\"kf-chart-panel__titles\">\n @if (headingLevel() === 2) {\n <h2 class=\"kf-chart-panel__title\" [id]=\"titleId\">\n <ng-container *ngTemplateOutlet=\"titleContent\" />\n </h2>\n } @else {\n <h3 class=\"kf-chart-panel__title\" [id]=\"titleId\">\n <ng-container *ngTemplateOutlet=\"titleContent\" />\n </h3>\n }\n @if (subtitle()) {\n <p class=\"kf-chart-panel__subtitle\">{{ subtitle() }}</p>\n }\n </div>\n @if (state() === 'ready' && (stat() || table())) {\n <div class=\"kf-chart-panel__aside\">\n @if (stat()) {\n <div\n class=\"kf-chart-panel__stat\"\n [class]=\"'kf-chart-panel__stat kf-chart-panel__stat--' + statTone()\"\n >\n {{ stat() }}\n @if (statSub()) {\n <small>{{ statSub() }}</small>\n }\n </div>\n }\n @if (table()) {\n <kf-button\n class=\"kf-chart-panel__table-button\"\n type=\"button\"\n variant=\"outline\"\n size=\"sm\"\n shape=\"circle\"\n icon=\"list\"\n [ariaLabel]=\"tableButtonLabel()\"\n (click)=\"viewTable.emit()\"\n />\n }\n </div>\n }\n</header>\n\n@switch (state()) {\n @case ('empty') {\n <div class=\"kf-chart-panel__state\" role=\"status\">\n @if (icon(); as iconName) {\n <kf-icon [name]=\"iconName\" size=\"lg\" />\n }\n <strong>{{ emptyTitle() }}</strong>\n @if (emptyText()) {\n <span>{{ emptyText() }}</span>\n }\n </div>\n }\n @case ('loading') {\n <div class=\"kf-chart-panel__skeleton\">\n <span class=\"kf-sr-only\">{{ loadingLabel() }}</span>\n <kf-skeleton variant=\"text\" width=\"90%\" />\n <kf-skeleton variant=\"text\" width=\"70%\" />\n <kf-skeleton variant=\"text\" width=\"80%\" />\n <kf-skeleton variant=\"text\" width=\"55%\" />\n </div>\n }\n @case ('error') {\n <div class=\"kf-chart-panel__state\" role=\"alert\">\n <kf-icon name=\"alert-circle\" size=\"lg\" />\n <strong>{{ errorTitle() }}</strong>\n @if (errorText()) {\n <span>{{ errorText() }}</span>\n }\n <kf-button type=\"button\" variant=\"outline\" size=\"sm\" icon=\"history\" (click)=\"retry.emit()\">\n {{ retryLabel() }}\n </kf-button>\n </div>\n }\n}\n\n<div class=\"kf-chart-panel__body\" [hidden]=\"state() !== 'ready'\">\n <ng-content select=\"[kfChartLegend]\" />\n <ng-content />\n</div>\n\n@if (state() === 'ready') {\n <footer class=\"kf-chart-panel__foot\">\n <span class=\"kf-chart-panel__hint\">{{ hint() }}</span>\n <ng-content select=\"[kfChartFoot]\" />\n @if (hasMore()) {\n <span class=\"kf-chart-panel__more\">\n <span>{{ moreLabel() }}</span>\n <kf-link class=\"kf-chart-panel__link\" (click)=\"viewAll.emit()\">\n {{ viewAllLabel() }}\n </kf-link>\n </span>\n }\n </footer>\n}\n", styles: [".kf-sr-only{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap;border:0}:host{display:flex;flex-direction:column;gap:var(--kf-space-sm);min-width:0;min-height:0;margin:0;padding:var(--kf-space-md);border:1px solid var(--kf-color-border);border-radius:var(--kf-radius-md);background:var(--kf-color-white);box-shadow:var(--kf-shadow-sm)}.kf-chart-panel__head{display:flex;flex-wrap:wrap;align-items:flex-start;gap:var(--kf-space-xs) var(--kf-space-sm)}.kf-chart-panel__titles{flex:1 1 8rem;min-width:0}.kf-chart-panel__title{display:flex;align-items:flex-start;gap:6px;margin:0;font-family:var(--kf-font-title);font-size:var(--kf-font-size-body-sm);font-weight:700;line-height:1.25;color:var(--kf-color-ink)}.kf-chart-panel__title span{min-width:0;overflow-wrap:break-word}.kf-chart-panel__title kf-icon{flex:none;margin-top:1px;color:var(--kf-chart-text-muted)}.kf-chart-panel__subtitle{margin:3px 0 0;font-size:var(--kf-font-size-caption);line-height:1.35;color:var(--kf-chart-text-muted)}.kf-chart-panel__aside{display:flex;flex:0 0 auto;margin-left:auto;align-items:flex-start;gap:var(--kf-space-sm)}.kf-chart-panel__stat{font-family:var(--kf-font-title);font-size:var(--kf-font-size-title-md);font-weight:700;line-height:1;font-variant-numeric:tabular-nums;text-align:right;white-space:nowrap;color:var(--kf-color-ink)}.kf-chart-panel__stat small{display:block;margin-top:3px;font-family:var(--kf-font-body);font-size:var(--kf-font-size-caption);font-weight:400;color:var(--kf-chart-text-muted)}.kf-chart-panel__stat--ok{color:var(--kf-color-success-strong)}.kf-chart-panel__stat--warn{color:var(--kf-color-warning-strong)}.kf-chart-panel__stat--risk{color:var(--kf-color-error-strong)}.kf-chart-panel__table-button{flex:0 0 auto}.kf-chart-panel__body{display:flex;flex:1 1 var(--kf-widget-basis, auto);flex-direction:column;gap:var(--kf-space-sm);min-width:0;min-height:0}.kf-chart-panel__body[hidden]{display:none}.kf-chart-panel__state{display:flex;flex:1 1 auto;flex-direction:column;align-items:center;justify-content:center;gap:var(--kf-space-xs);padding:var(--kf-space-sm);font-size:var(--kf-font-size-label);line-height:1.4;text-align:center;color:var(--kf-chart-text-muted)}.kf-chart-panel__state strong{font-size:var(--kf-font-size-body-sm);color:var(--kf-color-ink)}.kf-chart-panel__skeleton{position:relative;display:flex;flex:1 1 auto;flex-direction:column;gap:var(--kf-space-md)}.kf-chart-panel__foot{display:flex;flex-wrap:wrap;align-items:center;justify-content:space-between;gap:var(--kf-space-xs) var(--kf-space-sm);min-height:28px;font-size:var(--kf-font-size-caption);color:var(--kf-chart-text-muted)}.kf-chart-panel__hint{flex:1 1 8rem;min-width:0}.kf-chart-panel__hint:empty{display:none}.kf-chart-panel__more{display:inline-flex;flex:0 0 auto;align-items:center;gap:var(--kf-space-sm);margin-left:auto;white-space:nowrap}.kf-chart-panel__link{--kf-link-min-height: 24px;font-size:var(--kf-font-size-label);font-weight:600}\n"] }]
|
|
157
|
+
}], propDecorators: { title: [{ type: i0.Input, args: [{ isSignal: true, alias: "title", required: true }] }], icon: [{ type: i0.Input, args: [{ isSignal: true, alias: "icon", required: false }] }], subtitle: [{ type: i0.Input, args: [{ isSignal: true, alias: "subtitle", required: false }] }], stat: [{ type: i0.Input, args: [{ isSignal: true, alias: "stat", required: false }] }], statSub: [{ type: i0.Input, args: [{ isSignal: true, alias: "statSub", required: false }] }], statTone: [{ type: i0.Input, args: [{ isSignal: true, alias: "statTone", required: false }] }], state: [{ type: i0.Input, args: [{ isSignal: true, alias: "state", required: false }] }], emptyTitle: [{ type: i0.Input, args: [{ isSignal: true, alias: "emptyTitle", required: false }] }], emptyText: [{ type: i0.Input, args: [{ isSignal: true, alias: "emptyText", required: false }] }], errorTitle: [{ type: i0.Input, args: [{ isSignal: true, alias: "errorTitle", required: false }] }], errorText: [{ type: i0.Input, args: [{ isSignal: true, alias: "errorText", required: false }] }], loadingLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "loadingLabel", required: false }] }], retryLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "retryLabel", required: false }] }], hint: [{ type: i0.Input, args: [{ isSignal: true, alias: "hint", required: false }] }], total: [{ type: i0.Input, args: [{ isSignal: true, alias: "total", required: false }] }], shown: [{ type: i0.Input, args: [{ isSignal: true, alias: "shown", required: false }] }], viewAllText: [{ type: i0.Input, args: [{ isSignal: true, alias: "viewAllText", required: false }] }], moreText: [{ type: i0.Input, args: [{ isSignal: true, alias: "moreText", required: false }] }], table: [{ type: i0.Input, args: [{ isSignal: true, alias: "table", required: false }] }], tableLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "tableLabel", required: false }] }], headingLevel: [{ type: i0.Input, args: [{ isSignal: true, alias: "headingLevel", required: false }] }], viewAll: [{ type: i0.Output, args: ["viewAll"] }], viewTable: [{ type: i0.Output, args: ["viewTable"] }], retry: [{ type: i0.Output, args: ["retry"] }] } });
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Leyenda de un panel: explica la marca de meta, la banda de rango y los
|
|
161
|
+
* colores. Las muestras son decorativas (`aria-hidden`): el significado de
|
|
162
|
+
* cada una lo da su texto.
|
|
163
|
+
*
|
|
164
|
+
* <kf-chart-legend [items]="[{ kind: 'mark', label: 'Meta' }]" />
|
|
165
|
+
*/
|
|
166
|
+
class ChartLegend {
|
|
167
|
+
items = input.required(/* @ts-ignore */
|
|
168
|
+
...(ngDevMode ? [{ debugName: "items" }] : /* istanbul ignore next */ []));
|
|
169
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.0", ngImport: i0, type: ChartLegend, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
170
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1.0", type: ChartLegend, isStandalone: true, selector: "kf-chart-legend", inputs: { items: { classPropertyName: "items", publicName: "items", isSignal: true, isRequired: true, transformFunction: null } }, ngImport: i0, template: "<ul class=\"kf-chart-legend\">\n @for (item of items(); track item.label) {\n <li class=\"kf-chart-legend__item\">\n @switch (item.kind) {\n @case ('mark') {\n <span class=\"kf-chart-legend__mark\" aria-hidden=\"true\"></span>\n }\n @case ('band') {\n <span class=\"kf-chart-legend__band\" aria-hidden=\"true\"></span>\n }\n @default {\n <span\n class=\"kf-chart-legend__swatch\"\n [class]=\"'kf-chart-legend__swatch is-' + (item.tone ?? 'neutral')\"\n aria-hidden=\"true\"\n ></span>\n }\n }\n {{ item.label }}\n </li>\n }\n</ul>\n", styles: [".is-ok{--rb: var(--kf-chart-ok)}.is-warn{--rb: var(--kf-chart-warn)}.is-risk{--rb: var(--kf-chart-risk)}.is-neutral{--rb: var(--kf-chart-neutral)}.is-cat-1{--rb: var(--kf-chart-cat-1)}.is-cat-2{--rb: var(--kf-chart-cat-2)}.is-cat-3{--rb: var(--kf-chart-cat-3)}.is-cat-4{--rb: var(--kf-chart-cat-4)}.is-cat-5{--rb: var(--kf-chart-cat-5)}.is-cat-6{--rb: var(--kf-chart-cat-6)}:host{display:block;flex:0 0 auto}.kf-chart-legend{display:flex;flex-wrap:wrap;gap:3px var(--kf-space-md);margin:0;padding:0;list-style:none;font-size:var(--kf-font-size-caption);line-height:1.3;color:var(--kf-chart-text-muted)}.kf-chart-legend__item{display:inline-flex;align-items:center;gap:5px}.kf-chart-legend__swatch{flex:0 0 auto;width:8px;height:8px;border-radius:2px;background:var(--rb, var(--kf-chart-neutral))}.kf-chart-legend__mark{flex:0 0 auto;width:2px;height:12px;border-radius:1px;background:var(--kf-chart-target)}.kf-chart-legend__band{flex:0 0 auto;width:14px;height:8px;border-radius:2px;background:var(--kf-chart-band)}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
171
|
+
}
|
|
172
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.0", ngImport: i0, type: ChartLegend, decorators: [{
|
|
173
|
+
type: Component,
|
|
174
|
+
args: [{ selector: 'kf-chart-legend', changeDetection: ChangeDetectionStrategy.OnPush, template: "<ul class=\"kf-chart-legend\">\n @for (item of items(); track item.label) {\n <li class=\"kf-chart-legend__item\">\n @switch (item.kind) {\n @case ('mark') {\n <span class=\"kf-chart-legend__mark\" aria-hidden=\"true\"></span>\n }\n @case ('band') {\n <span class=\"kf-chart-legend__band\" aria-hidden=\"true\"></span>\n }\n @default {\n <span\n class=\"kf-chart-legend__swatch\"\n [class]=\"'kf-chart-legend__swatch is-' + (item.tone ?? 'neutral')\"\n aria-hidden=\"true\"\n ></span>\n }\n }\n {{ item.label }}\n </li>\n }\n</ul>\n", styles: [".is-ok{--rb: var(--kf-chart-ok)}.is-warn{--rb: var(--kf-chart-warn)}.is-risk{--rb: var(--kf-chart-risk)}.is-neutral{--rb: var(--kf-chart-neutral)}.is-cat-1{--rb: var(--kf-chart-cat-1)}.is-cat-2{--rb: var(--kf-chart-cat-2)}.is-cat-3{--rb: var(--kf-chart-cat-3)}.is-cat-4{--rb: var(--kf-chart-cat-4)}.is-cat-5{--rb: var(--kf-chart-cat-5)}.is-cat-6{--rb: var(--kf-chart-cat-6)}:host{display:block;flex:0 0 auto}.kf-chart-legend{display:flex;flex-wrap:wrap;gap:3px var(--kf-space-md);margin:0;padding:0;list-style:none;font-size:var(--kf-font-size-caption);line-height:1.3;color:var(--kf-chart-text-muted)}.kf-chart-legend__item{display:inline-flex;align-items:center;gap:5px}.kf-chart-legend__swatch{flex:0 0 auto;width:8px;height:8px;border-radius:2px;background:var(--rb, var(--kf-chart-neutral))}.kf-chart-legend__mark{flex:0 0 auto;width:2px;height:12px;border-radius:1px;background:var(--kf-chart-target)}.kf-chart-legend__band{flex:0 0 auto;width:14px;height:8px;border-radius:2px;background:var(--kf-chart-band)}\n"] }]
|
|
175
|
+
}], propDecorators: { items: [{ type: i0.Input, args: [{ isSignal: true, alias: "items", required: true }] }] } });
|
|
176
|
+
|
|
177
|
+
/** Desde cuántas filas la tabla se pagina en vez de dibujarlas todas. */
|
|
178
|
+
const PAGINATE_FROM = 200;
|
|
179
|
+
const PAGE_SIZE = 100;
|
|
180
|
+
/** Vista del diálogo; solo la monta `KfChartTableDialog`. */
|
|
181
|
+
class ChartTableDialogView {
|
|
182
|
+
def = input.required(/* @ts-ignore */
|
|
183
|
+
...(ngDevMode ? [{ debugName: "def" }] : /* istanbul ignore next */ []));
|
|
184
|
+
open = model(true, /* @ts-ignore */
|
|
185
|
+
...(ngDevMode ? [{ debugName: "open" }] : /* istanbul ignore next */ []));
|
|
186
|
+
locale = inject(LOCALE_ID);
|
|
187
|
+
caption = computed(() => {
|
|
188
|
+
const { subtitle, rows } = this.def();
|
|
189
|
+
const count = `${formatNumber(rows.length, this.locale, '1.0-0')} ${rows.length === 1 ? 'fila' : 'filas'}`;
|
|
190
|
+
return subtitle ? `${subtitle} · ${count}` : count;
|
|
191
|
+
}, /* @ts-ignore */
|
|
192
|
+
...(ngDevMode ? [{ debugName: "caption" }] : /* istanbul ignore next */ []));
|
|
193
|
+
/** La primera columna nombra la fila; las demás son cifras y van a la derecha. */
|
|
194
|
+
columns = computed(() => this.def().head.map((label, index) => ({
|
|
195
|
+
key: `c${index}`,
|
|
196
|
+
label,
|
|
197
|
+
align: index === 0 ? 'start' : 'end',
|
|
198
|
+
})), /* @ts-ignore */
|
|
199
|
+
...(ngDevMode ? [{ debugName: "columns" }] : /* istanbul ignore next */ []));
|
|
200
|
+
records = computed(() => this.def().rows.map((row) => Object.fromEntries(row.map((cell, index) => [`c${index}`, String(cell)]))), /* @ts-ignore */
|
|
201
|
+
...(ngDevMode ? [{ debugName: "records" }] : /* istanbul ignore next */ []));
|
|
202
|
+
pageSize = computed(() => this.def().rows.length > PAGINATE_FROM ? PAGE_SIZE : null, /* @ts-ignore */
|
|
203
|
+
...(ngDevMode ? [{ debugName: "pageSize" }] : /* istanbul ignore next */ []));
|
|
204
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.0", ngImport: i0, type: ChartTableDialogView, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
205
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "22.1.0", type: ChartTableDialogView, isStandalone: true, selector: "kf-chart-table-dialog-view", inputs: { def: { classPropertyName: "def", publicName: "def", isSignal: true, isRequired: true, transformFunction: null }, open: { classPropertyName: "open", publicName: "open", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { open: "openChange" }, ngImport: i0, template: "<kf-modal [(open)]=\"open\" [title]=\"def().title\" size=\"lg\">\n <p class=\"kf-chart-table-dialog__caption\">{{ caption() }}</p>\n <kf-data-table\n [columns]=\"columns()\"\n [rows]=\"records()\"\n [ariaLabel]=\"def().title\"\n [rowFocusable]=\"false\"\n [pageSize]=\"pageSize()\"\n stickyHeader\n maxHeight=\"60vh\"\n >\n <p empty class=\"kf-chart-table-dialog__empty\">Sin filas para mostrar.</p>\n </kf-data-table>\n</kf-modal>\n", styles: [".kf-chart-table-dialog__empty{margin:0;padding:var(--kf-space-md);text-align:center;font-size:var(--kf-font-size-label);color:var(--kf-chart-text-muted)}.kf-chart-table-dialog__caption{margin:0 0 var(--kf-space-sm);font-size:var(--kf-font-size-caption);color:var(--kf-chart-text-muted)}\n"], dependencies: [{ kind: "component", type: DataTable, selector: "kf-data-table", inputs: ["columns", "rows", "loading", "skeletonRows", "rowKey", "flush", "cardable", "defaultView", "showViewToggle", "cardMinWidth", "autoCards", "cardRows", "selectable", "selected", "rowSelectable", "selectLabel", "selectPageLabel", "selectedCountLabel", "stickyHeader", "maxHeight", "cardMenu", "cardMenuLabel", "cardOpenLabel", "render", "cellTemplates", "density", "rowClickable", "rowFocusable", "cellAriaLabel", "ariaLabel", "currentRowKey", "pageSize", "pageSizeOptions", "page", "keepPageOnRowsChange", "itemLabel", "sort", "view"], outputs: ["selectedChange", "cardMenuSelect", "rowClick", "cellClick", "pageChange", "pageSizeChange", "sortChange", "viewChange"] }, { kind: "component", type: Modal, selector: "kf-modal", inputs: ["title", "open", "dismissible", "width", "size", "dividers", "maxHeight", "fullscreenOnMobile", "initialFocus"], outputs: ["openChange"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
206
|
+
}
|
|
207
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.0", ngImport: i0, type: ChartTableDialogView, decorators: [{
|
|
208
|
+
type: Component,
|
|
209
|
+
args: [{ selector: 'kf-chart-table-dialog-view', imports: [DataTable, Modal], changeDetection: ChangeDetectionStrategy.OnPush, template: "<kf-modal [(open)]=\"open\" [title]=\"def().title\" size=\"lg\">\n <p class=\"kf-chart-table-dialog__caption\">{{ caption() }}</p>\n <kf-data-table\n [columns]=\"columns()\"\n [rows]=\"records()\"\n [ariaLabel]=\"def().title\"\n [rowFocusable]=\"false\"\n [pageSize]=\"pageSize()\"\n stickyHeader\n maxHeight=\"60vh\"\n >\n <p empty class=\"kf-chart-table-dialog__empty\">Sin filas para mostrar.</p>\n </kf-data-table>\n</kf-modal>\n", styles: [".kf-chart-table-dialog__empty{margin:0;padding:var(--kf-space-md);text-align:center;font-size:var(--kf-font-size-label);color:var(--kf-chart-text-muted)}.kf-chart-table-dialog__caption{margin:0 0 var(--kf-space-sm);font-size:var(--kf-font-size-caption);color:var(--kf-chart-text-muted)}\n"] }]
|
|
210
|
+
}], propDecorators: { def: [{ type: i0.Input, args: [{ isSignal: true, alias: "def", required: true }] }], open: [{ type: i0.Input, args: [{ isSignal: true, alias: "open", required: false }] }, { type: i0.Output, args: ["openChange"] }] } });
|
|
211
|
+
/**
|
|
212
|
+
* Abre la tabla completa de un gráfico en un `kf-modal`: foco atrapado y Escape
|
|
213
|
+
* los resuelve el `<dialog>` nativo, y al cerrar el foco vuelve al elemento que
|
|
214
|
+
* lo abrió («Ver todos» o el botón de tabla). La promesa se resuelve al cerrar.
|
|
215
|
+
* La tabla es la alternativa textual del gráfico: lleva todas las filas (con más
|
|
216
|
+
* de 200 las pagina de a 100) y la cabecera queda fija al desplazar.
|
|
217
|
+
*
|
|
218
|
+
* readonly dialog = inject(KfChartTableDialog);
|
|
219
|
+
* await this.dialog.open({ title: 'SLA por cliente', head: ['Cliente', 'SLA'], rows });
|
|
220
|
+
*/
|
|
221
|
+
class KfChartTableDialog {
|
|
222
|
+
appRef = inject(ApplicationRef);
|
|
223
|
+
injector = inject(EnvironmentInjector);
|
|
224
|
+
document = inject(DOCUMENT);
|
|
225
|
+
open(def) {
|
|
226
|
+
const opener = this.document.activeElement;
|
|
227
|
+
const view = createComponent(ChartTableDialogView, { environmentInjector: this.injector });
|
|
228
|
+
view.setInput('def', def);
|
|
229
|
+
this.appRef.attachView(view.hostView);
|
|
230
|
+
this.document.body.appendChild(view.location.nativeElement);
|
|
231
|
+
return new Promise((resolve) => {
|
|
232
|
+
const subscription = view.instance.open.subscribe((isOpen) => {
|
|
233
|
+
if (isOpen) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
subscription.unsubscribe();
|
|
237
|
+
view.destroy();
|
|
238
|
+
if (opener?.isConnected) {
|
|
239
|
+
opener.focus();
|
|
240
|
+
}
|
|
241
|
+
resolve();
|
|
242
|
+
});
|
|
243
|
+
view.changeDetectorRef.detectChanges();
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.0", ngImport: i0, type: KfChartTableDialog, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
247
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.1.0", ngImport: i0, type: KfChartTableDialog, providedIn: 'root' });
|
|
248
|
+
}
|
|
249
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.0", ngImport: i0, type: KfChartTableDialog, decorators: [{
|
|
250
|
+
type: Injectable,
|
|
251
|
+
args: [{ providedIn: 'root' }]
|
|
252
|
+
}] });
|
|
253
|
+
|
|
254
|
+
/** Limita un porcentaje a 0–100 para que una barra nunca desborde su pista. */
|
|
255
|
+
function clampPct(value) {
|
|
256
|
+
return Number.isFinite(value) ? Math.max(0, Math.min(100, value)) : 0;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Lista de filas con barra, una por entidad. Con `fit="measure"` mide el alto
|
|
261
|
+
* real de su contenedor y muestra solo las filas que caben (Top-N), de modo que
|
|
262
|
+
* no hay scroll interno: el resto lo informa `fitChange` para que el panel
|
|
263
|
+
* ofrezca «y N más» y «Ver todos (N)». Con `fit="cap"` muestra `maxRows` filas
|
|
264
|
+
* (una columna o alto natural) y con `none`, todas.
|
|
265
|
+
*
|
|
266
|
+
* El estado de alerta (`warn`, `risk`) se dice con ícono y texto para lectores de
|
|
267
|
+
* pantalla, no solo con color; la meta es una marca sólida sobre la pista y el
|
|
268
|
+
* valor siempre está escrito. Con `interactive` cada fila es un `<button>` con
|
|
269
|
+
* `aria-pressed` (filtra) y sin un punto de foco por barra; es un botón nativo
|
|
270
|
+
* porque la fila lleva texto, valor y pista, que `kf-button` no representa.
|
|
271
|
+
*
|
|
272
|
+
* <kf-ranked-bars [items]="filas()" interactive (itemClick)="filtrar($event)"
|
|
273
|
+
* (fitChange)="mostradas.set($event.shown)" />
|
|
274
|
+
*/
|
|
275
|
+
class RankedBars {
|
|
276
|
+
items = input.required(/* @ts-ignore */
|
|
277
|
+
...(ngDevMode ? [{ debugName: "items" }] : /* istanbul ignore next */ []));
|
|
278
|
+
/** Cada fila es un botón con `aria-pressed` que emite `itemClick`. */
|
|
279
|
+
interactive = input(false, { ...(ngDevMode ? { debugName: "interactive" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
280
|
+
density = input('default', /* @ts-ignore */
|
|
281
|
+
...(ngDevMode ? [{ debugName: "density" }] : /* istanbul ignore next */ []));
|
|
282
|
+
/** `measure`: Top-N según el alto real; `cap`: `maxRows` filas; `none`: todas. */
|
|
283
|
+
fit = input('measure', /* @ts-ignore */
|
|
284
|
+
...(ngDevMode ? [{ debugName: "fit" }] : /* istanbul ignore next */ []));
|
|
285
|
+
maxRows = input(6, { ...(ngDevMode ? { debugName: "maxRows" } : /* istanbul ignore next */ {}), transform: numberAttribute });
|
|
286
|
+
layout = input('bar', /* @ts-ignore */
|
|
287
|
+
...(ngDevMode ? [{ debugName: "layout" }] : /* istanbul ignore next */ []));
|
|
288
|
+
/** Rótulo para lectores de la marca de meta (la marca visual es decorativa). */
|
|
289
|
+
targetLabel = input('Meta', /* @ts-ignore */
|
|
290
|
+
...(ngDevMode ? [{ debugName: "targetLabel" }] : /* istanbul ignore next */ []));
|
|
291
|
+
/** Rótulo para lectores de la banda de rango habitual. */
|
|
292
|
+
bandLabel = input('Rango habitual', /* @ts-ignore */
|
|
293
|
+
...(ngDevMode ? [{ debugName: "bandLabel" }] : /* istanbul ignore next */ []));
|
|
294
|
+
itemClick = output();
|
|
295
|
+
fitChange = output();
|
|
296
|
+
list = viewChild('list', /* @ts-ignore */
|
|
297
|
+
...(ngDevMode ? [{ debugName: "list" }] : /* istanbul ignore next */ []));
|
|
298
|
+
limit = signal(null, /* @ts-ignore */
|
|
299
|
+
...(ngDevMode ? [{ debugName: "limit" }] : /* istanbul ignore next */ []));
|
|
300
|
+
visible = computed(() => {
|
|
301
|
+
const limit = this.limit();
|
|
302
|
+
return limit === null ? this.items() : this.items().slice(0, limit);
|
|
303
|
+
}, /* @ts-ignore */
|
|
304
|
+
...(ngDevMode ? [{ debugName: "visible" }] : /* istanbul ignore next */ []));
|
|
305
|
+
cdr = inject(ChangeDetectorRef);
|
|
306
|
+
injector = inject(Injector);
|
|
307
|
+
document = inject(DOCUMENT);
|
|
308
|
+
measuring = false;
|
|
309
|
+
/** Se vuelve verdadero cuando las entradas ya tienen valor. */
|
|
310
|
+
bound = false;
|
|
311
|
+
lastEmitted = null;
|
|
312
|
+
constructor() {
|
|
313
|
+
const destroyRef = inject(DestroyRef);
|
|
314
|
+
let observer = null;
|
|
315
|
+
let destroyed = false;
|
|
316
|
+
destroyRef.onDestroy(() => {
|
|
317
|
+
destroyed = true;
|
|
318
|
+
observer?.disconnect();
|
|
319
|
+
});
|
|
320
|
+
effect(() => {
|
|
321
|
+
this.items();
|
|
322
|
+
this.fit();
|
|
323
|
+
this.maxRows();
|
|
324
|
+
this.layout();
|
|
325
|
+
this.density();
|
|
326
|
+
this.bound = true;
|
|
327
|
+
untracked(() => afterNextRender(() => this.measure(), { injector: this.injector }));
|
|
328
|
+
});
|
|
329
|
+
effect(() => {
|
|
330
|
+
const element = this.list()?.nativeElement;
|
|
331
|
+
observer?.disconnect();
|
|
332
|
+
observer = null;
|
|
333
|
+
if (element && typeof ResizeObserver === 'function') {
|
|
334
|
+
observer = new ResizeObserver(() => this.measure());
|
|
335
|
+
observer.observe(element);
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
// Las fuentes web cambian el alto de las filas al cargar. Si ya estaban listas, la
|
|
339
|
+
// promesa se resuelve antes de que se enlace `items`: sin `bound` leería una entrada
|
|
340
|
+
// requerida todavía sin valor.
|
|
341
|
+
void this.document.fonts?.ready.then(() => {
|
|
342
|
+
if (!destroyed && this.bound) {
|
|
343
|
+
this.measure();
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
isFlagged(item) {
|
|
348
|
+
return item.tone === 'warn' || item.tone === 'risk';
|
|
349
|
+
}
|
|
350
|
+
alertText(item) {
|
|
351
|
+
return item.srLabel ?? (item.tone === 'risk' ? 'Crítico:' : 'Atención:');
|
|
352
|
+
}
|
|
353
|
+
/** Meta y rango como texto: la marca y la banda de la pista son solo visuales. */
|
|
354
|
+
referenceText(item) {
|
|
355
|
+
const parts = [];
|
|
356
|
+
if (item.target !== undefined) {
|
|
357
|
+
parts.push(item.targetText ?? `${this.targetLabel()}: ${this.targetLeft(item)} %`);
|
|
358
|
+
}
|
|
359
|
+
if (item.band) {
|
|
360
|
+
parts.push(item.bandText ??
|
|
361
|
+
`${this.bandLabel()}: ${this.bandLeft(item)} a ${clampPct(item.band[1])} %`);
|
|
362
|
+
}
|
|
363
|
+
return parts.join('. ');
|
|
364
|
+
}
|
|
365
|
+
barWidth(item) {
|
|
366
|
+
return clampPct(item.pct);
|
|
367
|
+
}
|
|
368
|
+
bandLeft(item) {
|
|
369
|
+
return clampPct(item.band?.[0] ?? 0);
|
|
370
|
+
}
|
|
371
|
+
bandWidth(item) {
|
|
372
|
+
return Math.max(1, clampPct(item.band?.[1] ?? 0) - this.bandLeft(item));
|
|
373
|
+
}
|
|
374
|
+
targetLeft(item) {
|
|
375
|
+
return clampPct(item.target ?? 0);
|
|
376
|
+
}
|
|
377
|
+
measure() {
|
|
378
|
+
const list = this.list()?.nativeElement;
|
|
379
|
+
if (!list || this.measuring) {
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
this.measuring = true;
|
|
383
|
+
try {
|
|
384
|
+
const total = this.items().length;
|
|
385
|
+
const next = this.nextLimit(list, total);
|
|
386
|
+
if (next !== this.limit()) {
|
|
387
|
+
this.limit.set(next);
|
|
388
|
+
this.cdr.detectChanges();
|
|
389
|
+
}
|
|
390
|
+
this.emitFit(next === null ? total : Math.min(next, total), total);
|
|
391
|
+
}
|
|
392
|
+
finally {
|
|
393
|
+
this.measuring = false;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
nextLimit(list, total) {
|
|
397
|
+
const mode = this.fit();
|
|
398
|
+
if (mode === 'none' || total === 0) {
|
|
399
|
+
return null;
|
|
400
|
+
}
|
|
401
|
+
if (mode === 'cap') {
|
|
402
|
+
return Math.min(this.maxRows(), total);
|
|
403
|
+
}
|
|
404
|
+
const cap = parseInt(getComputedStyle(list).getPropertyValue('--kf-widget-cap'), 10) || 0;
|
|
405
|
+
if (cap > 0) {
|
|
406
|
+
return Math.min(cap, total);
|
|
407
|
+
}
|
|
408
|
+
// Se vuelcan todas las filas y se cuentan las que caben en el alto real:
|
|
409
|
+
// con desborde cada fila conserva su alto natural, así que la suma es exacta.
|
|
410
|
+
this.limit.set(null);
|
|
411
|
+
this.cdr.detectChanges();
|
|
412
|
+
if (list.scrollHeight <= list.clientHeight + 1) {
|
|
413
|
+
return null;
|
|
414
|
+
}
|
|
415
|
+
let used = 0;
|
|
416
|
+
let fitting = 0;
|
|
417
|
+
for (const row of Array.from(list.children)) {
|
|
418
|
+
used += row.getBoundingClientRect().height;
|
|
419
|
+
if (used > list.clientHeight + 1 && fitting >= 1) {
|
|
420
|
+
break;
|
|
421
|
+
}
|
|
422
|
+
fitting += 1;
|
|
423
|
+
}
|
|
424
|
+
return this.settle(list, Math.max(1, fitting));
|
|
425
|
+
}
|
|
426
|
+
/** Comprueba contra el DOM real que el recorte no desborda: la suma de los
|
|
427
|
+
* altos medidos puede quedar unos píxeles por debajo por redondeo. */
|
|
428
|
+
settle(list, limit) {
|
|
429
|
+
let current = limit;
|
|
430
|
+
while (current > 1) {
|
|
431
|
+
this.limit.set(current);
|
|
432
|
+
this.cdr.detectChanges();
|
|
433
|
+
if (list.scrollHeight <= list.clientHeight + 1) {
|
|
434
|
+
break;
|
|
435
|
+
}
|
|
436
|
+
current -= 1;
|
|
437
|
+
}
|
|
438
|
+
return current;
|
|
439
|
+
}
|
|
440
|
+
emitFit(shown, total) {
|
|
441
|
+
const last = this.lastEmitted;
|
|
442
|
+
if (last?.shown === shown && last.total === total) {
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
this.lastEmitted = { shown, total };
|
|
446
|
+
this.fitChange.emit({ shown, total });
|
|
447
|
+
}
|
|
448
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.0", ngImport: i0, type: RankedBars, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
449
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1.0", type: RankedBars, isStandalone: true, selector: "kf-ranked-bars", inputs: { items: { classPropertyName: "items", publicName: "items", isSignal: true, isRequired: true, transformFunction: null }, interactive: { classPropertyName: "interactive", publicName: "interactive", isSignal: true, isRequired: false, transformFunction: null }, density: { classPropertyName: "density", publicName: "density", isSignal: true, isRequired: false, transformFunction: null }, fit: { classPropertyName: "fit", publicName: "fit", isSignal: true, isRequired: false, transformFunction: null }, maxRows: { classPropertyName: "maxRows", publicName: "maxRows", isSignal: true, isRequired: false, transformFunction: null }, layout: { classPropertyName: "layout", publicName: "layout", isSignal: true, isRequired: false, transformFunction: null }, targetLabel: { classPropertyName: "targetLabel", publicName: "targetLabel", isSignal: true, isRequired: false, transformFunction: null }, bandLabel: { classPropertyName: "bandLabel", publicName: "bandLabel", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { itemClick: "itemClick", fitChange: "fitChange" }, viewQueries: [{ propertyName: "list", first: true, predicate: ["list"], descendants: true, isSignal: true }], ngImport: i0, template: "<ng-template #flag let-item>\n @if (isFlagged(item)) {\n <kf-icon name=\"alert-triangle\" size=\"sm\" />\n <span class=\"kf-sr-only\">{{ alertText(item) }}</span>\n }\n</ng-template>\n\n<ng-template #barBody let-item>\n <span class=\"kf-ranked-bars__top\">\n <span class=\"kf-ranked-bars__label\">\n {{ item.label }}\n @if (item.sub) {\n <small>{{ item.sub }}</small>\n }\n </span>\n <span class=\"kf-ranked-bars__value\">\n <ng-container *ngTemplateOutlet=\"flag; context: { $implicit: item }\" />\n {{ item.display }}\n </span>\n </span>\n @if (referenceText(item); as reference) {\n <span class=\"kf-sr-only\">{{ reference }}</span>\n }\n <span class=\"kf-ranked-bars__track\" aria-hidden=\"true\">\n @if (item.band) {\n <span\n class=\"kf-ranked-bars__band\"\n [style.left.%]=\"bandLeft(item)\"\n [style.width.%]=\"bandWidth(item)\"\n ></span>\n }\n <span class=\"kf-ranked-bars__fill\" [style.width.%]=\"barWidth(item)\"></span>\n @if (item.target !== undefined) {\n <span class=\"kf-ranked-bars__target\" [style.left.%]=\"targetLeft(item)\"></span>\n }\n </span>\n</ng-template>\n\n<ng-template #lineBody let-item>\n <span class=\"kf-ranked-bars__label\">{{ item.label }}</span>\n <span class=\"kf-ranked-bars__value\">\n <ng-container *ngTemplateOutlet=\"flag; context: { $implicit: item }\" />\n {{ item.display }}\n </span>\n</ng-template>\n\n<ng-template #legendBody let-item>\n <span class=\"kf-ranked-bars__swatch\" aria-hidden=\"true\"></span>\n <span class=\"kf-ranked-bars__label\">{{ item.label }}</span>\n <span class=\"kf-ranked-bars__value\">{{ item.display }}</span>\n <span class=\"kf-ranked-bars__pct\">{{ item.detail }}</span>\n</ng-template>\n\n<ul\n #list\n class=\"kf-ranked-bars\"\n [class.kf-ranked-bars--roomy]=\"density() === 'roomy'\"\n [class.kf-ranked-bars--fit]=\"fit() !== 'none'\"\n>\n @for (item of visible(); track item.id) {\n <li class=\"kf-ranked-bars__item\">\n @if (interactive()) {\n <button\n type=\"button\"\n class=\"kf-ranked-bars__row\"\n [class]=\"'kf-ranked-bars__row kf-ranked-bars__row--' + layout() + ' is-' + item.tone\"\n [attr.aria-pressed]=\"item.pressed === true\"\n (click)=\"itemClick.emit(item.id)\"\n >\n @switch (layout()) {\n @case ('line') {\n <ng-container *ngTemplateOutlet=\"lineBody; context: { $implicit: item }\" />\n }\n @case ('legend') {\n <ng-container *ngTemplateOutlet=\"legendBody; context: { $implicit: item }\" />\n }\n @default {\n <ng-container *ngTemplateOutlet=\"barBody; context: { $implicit: item }\" />\n }\n }\n </button>\n } @else {\n <div [class]=\"'kf-ranked-bars__row kf-ranked-bars__row--' + layout() + ' is-' + item.tone\">\n @switch (layout()) {\n @case ('line') {\n <ng-container *ngTemplateOutlet=\"lineBody; context: { $implicit: item }\" />\n }\n @case ('legend') {\n <ng-container *ngTemplateOutlet=\"legendBody; context: { $implicit: item }\" />\n }\n @default {\n <ng-container *ngTemplateOutlet=\"barBody; context: { $implicit: item }\" />\n }\n }\n </div>\n }\n </li>\n }\n</ul>\n", styles: [".is-ok{--rb: var(--kf-chart-ok)}.is-warn{--rb: var(--kf-chart-warn)}.is-risk{--rb: var(--kf-chart-risk)}.is-neutral{--rb: var(--kf-chart-neutral)}.is-cat-1{--rb: var(--kf-chart-cat-1)}.is-cat-2{--rb: var(--kf-chart-cat-2)}.is-cat-3{--rb: var(--kf-chart-cat-3)}.is-cat-4{--rb: var(--kf-chart-cat-4)}.is-cat-5{--rb: var(--kf-chart-cat-5)}.is-cat-6{--rb: var(--kf-chart-cat-6)}.kf-sr-only{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap;border:0}:host{display:flex;flex:1 1 var(--kf-widget-basis, auto);flex-direction:column;min-width:0;min-height:0}.kf-ranked-bars{display:flex;flex:1 1 auto;flex-direction:column;margin:0;padding:0;list-style:none}.kf-ranked-bars--fit{flex-basis:var(--kf-widget-basis, auto);min-height:0}.kf-ranked-bars__item{position:relative;display:flex;flex:1 0 auto;max-height:76px}.kf-ranked-bars__row{display:flex;flex:1 1 auto;flex-direction:column;justify-content:center;gap:var(--kf-space-xs);min-width:0;margin:0;padding:var(--kf-space-xs) 6px;border:0;border-radius:var(--kf-radius-xs);background:transparent;font:inherit;color:inherit;text-align:left}button.kf-ranked-bars__row{width:100%;cursor:pointer}button.kf-ranked-bars__row:hover{background:color-mix(in srgb,var(--kf-color-ink) 5%,transparent)}button.kf-ranked-bars__row:focus-visible{outline:none;box-shadow:var(--kf-shadow-focus)}button.kf-ranked-bars__row[aria-pressed=true]{background:color-mix(in srgb,var(--kf-color-primary) 8%,transparent);box-shadow:inset 0 0 0 1.5px var(--kf-color-primary)}.kf-ranked-bars__top{display:flex;align-items:baseline;justify-content:space-between;gap:var(--kf-space-sm);min-width:0}.kf-ranked-bars__label{min-width:0;font-size:var(--kf-font-size-label);font-weight:500;line-height:1.3;overflow-wrap:break-word;color:var(--kf-color-ink)}.kf-ranked-bars__label small{margin-left:5px;font-size:var(--kf-font-size-caption);font-weight:400;color:var(--kf-chart-text-muted)}.kf-ranked-bars__value{display:inline-flex;flex:0 0 auto;align-items:center;gap:var(--kf-space-xs);font-size:var(--kf-font-size-label);font-weight:600;line-height:1.3;font-variant-numeric:tabular-nums;white-space:nowrap;color:var(--kf-color-ink)}.kf-ranked-bars__row.is-warn .kf-ranked-bars__value{color:var(--kf-color-warning-strong)}.kf-ranked-bars__row.is-risk .kf-ranked-bars__value{font-weight:700;color:var(--kf-color-error-strong)}.kf-ranked-bars__row.is-ok .kf-ranked-bars__value{color:var(--kf-color-success-strong)}.kf-ranked-bars__track{position:relative;display:block;flex:0 0 auto;height:var(--kf-chart-bar);border-radius:var(--kf-radius-pill);background:var(--kf-chart-track)}.kf-ranked-bars__fill{position:absolute;inset:0 auto 0 0;min-width:4px;border-radius:var(--kf-radius-pill);background:var(--rb, var(--kf-chart-neutral))}.kf-ranked-bars__band{position:absolute;top:-3px;bottom:-3px;border-radius:3px;background:var(--kf-chart-band)}.kf-ranked-bars__target{position:absolute;top:-4px;bottom:-4px;width:2px;margin-left:-1px;border-radius:1px;background:var(--kf-chart-target)}.kf-ranked-bars--roomy .kf-ranked-bars__item{max-height:100px}.kf-ranked-bars--roomy .kf-ranked-bars__row{gap:var(--kf-space-sm)}.kf-ranked-bars--roomy .kf-ranked-bars__track{height:14px}.kf-ranked-bars--roomy .kf-ranked-bars__label,.kf-ranked-bars--roomy .kf-ranked-bars__value{font-size:var(--kf-font-size-body-sm)}.kf-ranked-bars__row--line{flex-direction:row;align-items:center;justify-content:space-between;gap:var(--kf-space-sm)}.kf-ranked-bars__row--legend{flex-direction:row;align-items:center;gap:var(--kf-space-sm)}.kf-ranked-bars__row--legend .kf-ranked-bars__label{flex:1 1 auto}.kf-ranked-bars__pct{flex:0 0 3.2em;font-size:var(--kf-font-size-label);font-variant-numeric:tabular-nums;text-align:right;color:var(--kf-chart-text-muted)}.kf-ranked-bars__swatch{flex:0 0 auto;width:10px;height:10px;border-radius:3px;background:var(--rb, var(--kf-chart-neutral))}\n"], dependencies: [{ kind: "component", type: Icon, selector: "kf-icon", inputs: ["name", "size", "rotate", "filled"] }, { kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
450
|
+
}
|
|
451
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.0", ngImport: i0, type: RankedBars, decorators: [{
|
|
452
|
+
type: Component,
|
|
453
|
+
args: [{ selector: 'kf-ranked-bars', imports: [Icon, NgTemplateOutlet], changeDetection: ChangeDetectionStrategy.OnPush, template: "<ng-template #flag let-item>\n @if (isFlagged(item)) {\n <kf-icon name=\"alert-triangle\" size=\"sm\" />\n <span class=\"kf-sr-only\">{{ alertText(item) }}</span>\n }\n</ng-template>\n\n<ng-template #barBody let-item>\n <span class=\"kf-ranked-bars__top\">\n <span class=\"kf-ranked-bars__label\">\n {{ item.label }}\n @if (item.sub) {\n <small>{{ item.sub }}</small>\n }\n </span>\n <span class=\"kf-ranked-bars__value\">\n <ng-container *ngTemplateOutlet=\"flag; context: { $implicit: item }\" />\n {{ item.display }}\n </span>\n </span>\n @if (referenceText(item); as reference) {\n <span class=\"kf-sr-only\">{{ reference }}</span>\n }\n <span class=\"kf-ranked-bars__track\" aria-hidden=\"true\">\n @if (item.band) {\n <span\n class=\"kf-ranked-bars__band\"\n [style.left.%]=\"bandLeft(item)\"\n [style.width.%]=\"bandWidth(item)\"\n ></span>\n }\n <span class=\"kf-ranked-bars__fill\" [style.width.%]=\"barWidth(item)\"></span>\n @if (item.target !== undefined) {\n <span class=\"kf-ranked-bars__target\" [style.left.%]=\"targetLeft(item)\"></span>\n }\n </span>\n</ng-template>\n\n<ng-template #lineBody let-item>\n <span class=\"kf-ranked-bars__label\">{{ item.label }}</span>\n <span class=\"kf-ranked-bars__value\">\n <ng-container *ngTemplateOutlet=\"flag; context: { $implicit: item }\" />\n {{ item.display }}\n </span>\n</ng-template>\n\n<ng-template #legendBody let-item>\n <span class=\"kf-ranked-bars__swatch\" aria-hidden=\"true\"></span>\n <span class=\"kf-ranked-bars__label\">{{ item.label }}</span>\n <span class=\"kf-ranked-bars__value\">{{ item.display }}</span>\n <span class=\"kf-ranked-bars__pct\">{{ item.detail }}</span>\n</ng-template>\n\n<ul\n #list\n class=\"kf-ranked-bars\"\n [class.kf-ranked-bars--roomy]=\"density() === 'roomy'\"\n [class.kf-ranked-bars--fit]=\"fit() !== 'none'\"\n>\n @for (item of visible(); track item.id) {\n <li class=\"kf-ranked-bars__item\">\n @if (interactive()) {\n <button\n type=\"button\"\n class=\"kf-ranked-bars__row\"\n [class]=\"'kf-ranked-bars__row kf-ranked-bars__row--' + layout() + ' is-' + item.tone\"\n [attr.aria-pressed]=\"item.pressed === true\"\n (click)=\"itemClick.emit(item.id)\"\n >\n @switch (layout()) {\n @case ('line') {\n <ng-container *ngTemplateOutlet=\"lineBody; context: { $implicit: item }\" />\n }\n @case ('legend') {\n <ng-container *ngTemplateOutlet=\"legendBody; context: { $implicit: item }\" />\n }\n @default {\n <ng-container *ngTemplateOutlet=\"barBody; context: { $implicit: item }\" />\n }\n }\n </button>\n } @else {\n <div [class]=\"'kf-ranked-bars__row kf-ranked-bars__row--' + layout() + ' is-' + item.tone\">\n @switch (layout()) {\n @case ('line') {\n <ng-container *ngTemplateOutlet=\"lineBody; context: { $implicit: item }\" />\n }\n @case ('legend') {\n <ng-container *ngTemplateOutlet=\"legendBody; context: { $implicit: item }\" />\n }\n @default {\n <ng-container *ngTemplateOutlet=\"barBody; context: { $implicit: item }\" />\n }\n }\n </div>\n }\n </li>\n }\n</ul>\n", styles: [".is-ok{--rb: var(--kf-chart-ok)}.is-warn{--rb: var(--kf-chart-warn)}.is-risk{--rb: var(--kf-chart-risk)}.is-neutral{--rb: var(--kf-chart-neutral)}.is-cat-1{--rb: var(--kf-chart-cat-1)}.is-cat-2{--rb: var(--kf-chart-cat-2)}.is-cat-3{--rb: var(--kf-chart-cat-3)}.is-cat-4{--rb: var(--kf-chart-cat-4)}.is-cat-5{--rb: var(--kf-chart-cat-5)}.is-cat-6{--rb: var(--kf-chart-cat-6)}.kf-sr-only{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap;border:0}:host{display:flex;flex:1 1 var(--kf-widget-basis, auto);flex-direction:column;min-width:0;min-height:0}.kf-ranked-bars{display:flex;flex:1 1 auto;flex-direction:column;margin:0;padding:0;list-style:none}.kf-ranked-bars--fit{flex-basis:var(--kf-widget-basis, auto);min-height:0}.kf-ranked-bars__item{position:relative;display:flex;flex:1 0 auto;max-height:76px}.kf-ranked-bars__row{display:flex;flex:1 1 auto;flex-direction:column;justify-content:center;gap:var(--kf-space-xs);min-width:0;margin:0;padding:var(--kf-space-xs) 6px;border:0;border-radius:var(--kf-radius-xs);background:transparent;font:inherit;color:inherit;text-align:left}button.kf-ranked-bars__row{width:100%;cursor:pointer}button.kf-ranked-bars__row:hover{background:color-mix(in srgb,var(--kf-color-ink) 5%,transparent)}button.kf-ranked-bars__row:focus-visible{outline:none;box-shadow:var(--kf-shadow-focus)}button.kf-ranked-bars__row[aria-pressed=true]{background:color-mix(in srgb,var(--kf-color-primary) 8%,transparent);box-shadow:inset 0 0 0 1.5px var(--kf-color-primary)}.kf-ranked-bars__top{display:flex;align-items:baseline;justify-content:space-between;gap:var(--kf-space-sm);min-width:0}.kf-ranked-bars__label{min-width:0;font-size:var(--kf-font-size-label);font-weight:500;line-height:1.3;overflow-wrap:break-word;color:var(--kf-color-ink)}.kf-ranked-bars__label small{margin-left:5px;font-size:var(--kf-font-size-caption);font-weight:400;color:var(--kf-chart-text-muted)}.kf-ranked-bars__value{display:inline-flex;flex:0 0 auto;align-items:center;gap:var(--kf-space-xs);font-size:var(--kf-font-size-label);font-weight:600;line-height:1.3;font-variant-numeric:tabular-nums;white-space:nowrap;color:var(--kf-color-ink)}.kf-ranked-bars__row.is-warn .kf-ranked-bars__value{color:var(--kf-color-warning-strong)}.kf-ranked-bars__row.is-risk .kf-ranked-bars__value{font-weight:700;color:var(--kf-color-error-strong)}.kf-ranked-bars__row.is-ok .kf-ranked-bars__value{color:var(--kf-color-success-strong)}.kf-ranked-bars__track{position:relative;display:block;flex:0 0 auto;height:var(--kf-chart-bar);border-radius:var(--kf-radius-pill);background:var(--kf-chart-track)}.kf-ranked-bars__fill{position:absolute;inset:0 auto 0 0;min-width:4px;border-radius:var(--kf-radius-pill);background:var(--rb, var(--kf-chart-neutral))}.kf-ranked-bars__band{position:absolute;top:-3px;bottom:-3px;border-radius:3px;background:var(--kf-chart-band)}.kf-ranked-bars__target{position:absolute;top:-4px;bottom:-4px;width:2px;margin-left:-1px;border-radius:1px;background:var(--kf-chart-target)}.kf-ranked-bars--roomy .kf-ranked-bars__item{max-height:100px}.kf-ranked-bars--roomy .kf-ranked-bars__row{gap:var(--kf-space-sm)}.kf-ranked-bars--roomy .kf-ranked-bars__track{height:14px}.kf-ranked-bars--roomy .kf-ranked-bars__label,.kf-ranked-bars--roomy .kf-ranked-bars__value{font-size:var(--kf-font-size-body-sm)}.kf-ranked-bars__row--line{flex-direction:row;align-items:center;justify-content:space-between;gap:var(--kf-space-sm)}.kf-ranked-bars__row--legend{flex-direction:row;align-items:center;gap:var(--kf-space-sm)}.kf-ranked-bars__row--legend .kf-ranked-bars__label{flex:1 1 auto}.kf-ranked-bars__pct{flex:0 0 3.2em;font-size:var(--kf-font-size-label);font-variant-numeric:tabular-nums;text-align:right;color:var(--kf-chart-text-muted)}.kf-ranked-bars__swatch{flex:0 0 auto;width:10px;height:10px;border-radius:3px;background:var(--rb, var(--kf-chart-neutral))}\n"] }]
|
|
454
|
+
}], ctorParameters: () => [], propDecorators: { items: [{ type: i0.Input, args: [{ isSignal: true, alias: "items", required: true }] }], interactive: [{ type: i0.Input, args: [{ isSignal: true, alias: "interactive", required: false }] }], density: [{ type: i0.Input, args: [{ isSignal: true, alias: "density", required: false }] }], fit: [{ type: i0.Input, args: [{ isSignal: true, alias: "fit", required: false }] }], maxRows: [{ type: i0.Input, args: [{ isSignal: true, alias: "maxRows", required: false }] }], layout: [{ type: i0.Input, args: [{ isSignal: true, alias: "layout", required: false }] }], targetLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "targetLabel", required: false }] }], bandLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "bandLabel", required: false }] }], itemClick: [{ type: i0.Output, args: ["itemClick"] }], fitChange: [{ type: i0.Output, args: ["fitChange"] }], list: [{ type: i0.ViewChild, args: ['list', { isSignal: true }] }] } });
|
|
455
|
+
|
|
456
|
+
/** Id del segmento que agrupa la cola cuando hay más segmentos que `maxSegments`. */
|
|
457
|
+
const STACKED_BAR_OTHER_ID = '__other';
|
|
458
|
+
/**
|
|
459
|
+
* Barra apilada de 14 px para una composición (origen de tickets, estado de la
|
|
460
|
+
* flota). Con `interactive` cada segmento es un botón con `aria-pressed`; sin
|
|
461
|
+
* él, la barra es una sola imagen con `ariaLabel`. Sin segmentos con valor
|
|
462
|
+
* dibuja la pista vacía: la altura no cambia con el volumen de datos.
|
|
463
|
+
*
|
|
464
|
+
* Con `maxSegments`, lo que excede se agrupa en un último segmento neutral
|
|
465
|
+
* «Otros» (`otherLabel`), que nunca es interactivo: una composición con decenas
|
|
466
|
+
* de categorías no cabe en una barra de 14 px sin recortar.
|
|
467
|
+
*
|
|
468
|
+
* Los segmentos interactivos son `<button>` nativos: cada uno es una franja de
|
|
469
|
+
* color sin contenido, que `kf-button` no puede representar.
|
|
470
|
+
*
|
|
471
|
+
* <kf-stacked-bar ariaLabel="Origen de los tickets" [segments]="origenes()" />
|
|
472
|
+
*/
|
|
473
|
+
class StackedBar {
|
|
474
|
+
segments = input.required(/* @ts-ignore */
|
|
475
|
+
...(ngDevMode ? [{ debugName: "segments" }] : /* istanbul ignore next */ []));
|
|
476
|
+
interactive = input(false, { ...(ngDevMode ? { debugName: "interactive" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
477
|
+
ariaLabel = input.required(/* @ts-ignore */
|
|
478
|
+
...(ngDevMode ? [{ debugName: "ariaLabel" }] : /* istanbul ignore next */ []));
|
|
479
|
+
/** Tope de segmentos dibujados; el resto se agrupa en «Otros». Sin tope, se dibujan todos. */
|
|
480
|
+
maxSegments = input(null, { ...(ngDevMode ? { debugName: "maxSegments" } : /* istanbul ignore next */ {}), transform: (value) => (value == null ? null : Math.max(2, numberAttribute(value, 2))) });
|
|
481
|
+
otherLabel = input('Otros', /* @ts-ignore */
|
|
482
|
+
...(ngDevMode ? [{ debugName: "otherLabel" }] : /* istanbul ignore next */ []));
|
|
483
|
+
segmentClick = output();
|
|
484
|
+
parts = computed(() => {
|
|
485
|
+
const positive = this.segments().filter((segment) => segment.value > 0);
|
|
486
|
+
const total = positive.reduce((sum, segment) => sum + segment.value, 0);
|
|
487
|
+
const limit = this.maxSegments();
|
|
488
|
+
let shown = positive;
|
|
489
|
+
if (limit !== null && positive.length > limit) {
|
|
490
|
+
const tail = positive.slice(limit - 1);
|
|
491
|
+
shown = [
|
|
492
|
+
...positive.slice(0, limit - 1),
|
|
493
|
+
{
|
|
494
|
+
id: STACKED_BAR_OTHER_ID,
|
|
495
|
+
value: tail.reduce((sum, segment) => sum + segment.value, 0),
|
|
496
|
+
tone: 'neutral',
|
|
497
|
+
label: this.otherLabel(),
|
|
498
|
+
merged: true,
|
|
499
|
+
},
|
|
500
|
+
];
|
|
501
|
+
}
|
|
502
|
+
return shown.map((segment) => ({
|
|
503
|
+
...segment,
|
|
504
|
+
accessibleName: `${segment.label}: ${Math.round((segment.value / total) * 100)}%`,
|
|
505
|
+
}));
|
|
506
|
+
}, /* @ts-ignore */
|
|
507
|
+
...(ngDevMode ? [{ debugName: "parts" }] : /* istanbul ignore next */ []));
|
|
508
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.0", ngImport: i0, type: StackedBar, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
509
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1.0", type: StackedBar, isStandalone: true, selector: "kf-stacked-bar", inputs: { segments: { classPropertyName: "segments", publicName: "segments", isSignal: true, isRequired: true, transformFunction: null }, interactive: { classPropertyName: "interactive", publicName: "interactive", isSignal: true, isRequired: false, transformFunction: null }, ariaLabel: { classPropertyName: "ariaLabel", publicName: "ariaLabel", isSignal: true, isRequired: true, transformFunction: null }, maxSegments: { classPropertyName: "maxSegments", publicName: "maxSegments", isSignal: true, isRequired: false, transformFunction: null }, otherLabel: { classPropertyName: "otherLabel", publicName: "otherLabel", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { segmentClick: "segmentClick" }, ngImport: i0, template: "<div\n class=\"kf-stacked-bar\"\n [attr.role]=\"interactive() ? 'group' : 'img'\"\n [attr.aria-label]=\"ariaLabel()\"\n>\n @for (part of parts(); track part.id) {\n @if (interactive() && !part.merged) {\n <button\n type=\"button\"\n class=\"kf-stacked-bar__segment\"\n [class]=\"'kf-stacked-bar__segment is-' + part.tone\"\n [style.flex-grow]=\"part.value\"\n [attr.aria-pressed]=\"part.pressed === true\"\n [attr.aria-label]=\"part.accessibleName\"\n (click)=\"segmentClick.emit(part.id)\"\n ></button>\n } @else {\n <span\n class=\"kf-stacked-bar__segment\"\n [class]=\"'kf-stacked-bar__segment is-' + part.tone\"\n [style.flex-grow]=\"part.value\"\n [attr.role]=\"interactive() ? 'img' : null\"\n [attr.aria-label]=\"interactive() ? part.accessibleName : null\"\n [attr.aria-hidden]=\"interactive() ? null : 'true'\"\n ></span>\n }\n }\n</div>\n", styles: [".is-ok{--rb: var(--kf-chart-ok)}.is-warn{--rb: var(--kf-chart-warn)}.is-risk{--rb: var(--kf-chart-risk)}.is-neutral{--rb: var(--kf-chart-neutral)}.is-cat-1{--rb: var(--kf-chart-cat-1)}.is-cat-2{--rb: var(--kf-chart-cat-2)}.is-cat-3{--rb: var(--kf-chart-cat-3)}.is-cat-4{--rb: var(--kf-chart-cat-4)}.is-cat-5{--rb: var(--kf-chart-cat-5)}.is-cat-6{--rb: var(--kf-chart-cat-6)}:host{display:block;flex:0 0 auto}.kf-stacked-bar{display:flex;gap:2px;height:14px;border-radius:var(--kf-radius-pill);background:var(--kf-chart-track)}.kf-stacked-bar__segment{flex:1 1 0;min-width:4px;height:100%;margin:0;padding:0;border:0;border-radius:3px;background:var(--rb, var(--kf-chart-neutral))}.kf-stacked-bar__segment:first-child{border-radius:7px 3px 3px 7px}.kf-stacked-bar__segment:last-child{border-radius:3px 7px 7px 3px}.kf-stacked-bar__segment:only-child{border-radius:7px}button.kf-stacked-bar__segment{cursor:pointer}button.kf-stacked-bar__segment:hover{filter:brightness(.92)}button.kf-stacked-bar__segment:focus-visible,button.kf-stacked-bar__segment[aria-pressed=true]{outline:2px solid var(--kf-color-ink);outline-offset:1px}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
510
|
+
}
|
|
511
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.0", ngImport: i0, type: StackedBar, decorators: [{
|
|
512
|
+
type: Component,
|
|
513
|
+
args: [{ selector: 'kf-stacked-bar', changeDetection: ChangeDetectionStrategy.OnPush, template: "<div\n class=\"kf-stacked-bar\"\n [attr.role]=\"interactive() ? 'group' : 'img'\"\n [attr.aria-label]=\"ariaLabel()\"\n>\n @for (part of parts(); track part.id) {\n @if (interactive() && !part.merged) {\n <button\n type=\"button\"\n class=\"kf-stacked-bar__segment\"\n [class]=\"'kf-stacked-bar__segment is-' + part.tone\"\n [style.flex-grow]=\"part.value\"\n [attr.aria-pressed]=\"part.pressed === true\"\n [attr.aria-label]=\"part.accessibleName\"\n (click)=\"segmentClick.emit(part.id)\"\n ></button>\n } @else {\n <span\n class=\"kf-stacked-bar__segment\"\n [class]=\"'kf-stacked-bar__segment is-' + part.tone\"\n [style.flex-grow]=\"part.value\"\n [attr.role]=\"interactive() ? 'img' : null\"\n [attr.aria-label]=\"interactive() ? part.accessibleName : null\"\n [attr.aria-hidden]=\"interactive() ? null : 'true'\"\n ></span>\n }\n }\n</div>\n", styles: [".is-ok{--rb: var(--kf-chart-ok)}.is-warn{--rb: var(--kf-chart-warn)}.is-risk{--rb: var(--kf-chart-risk)}.is-neutral{--rb: var(--kf-chart-neutral)}.is-cat-1{--rb: var(--kf-chart-cat-1)}.is-cat-2{--rb: var(--kf-chart-cat-2)}.is-cat-3{--rb: var(--kf-chart-cat-3)}.is-cat-4{--rb: var(--kf-chart-cat-4)}.is-cat-5{--rb: var(--kf-chart-cat-5)}.is-cat-6{--rb: var(--kf-chart-cat-6)}:host{display:block;flex:0 0 auto}.kf-stacked-bar{display:flex;gap:2px;height:14px;border-radius:var(--kf-radius-pill);background:var(--kf-chart-track)}.kf-stacked-bar__segment{flex:1 1 0;min-width:4px;height:100%;margin:0;padding:0;border:0;border-radius:3px;background:var(--rb, var(--kf-chart-neutral))}.kf-stacked-bar__segment:first-child{border-radius:7px 3px 3px 7px}.kf-stacked-bar__segment:last-child{border-radius:3px 7px 7px 3px}.kf-stacked-bar__segment:only-child{border-radius:7px}button.kf-stacked-bar__segment{cursor:pointer}button.kf-stacked-bar__segment:hover{filter:brightness(.92)}button.kf-stacked-bar__segment:focus-visible,button.kf-stacked-bar__segment[aria-pressed=true]{outline:2px solid var(--kf-color-ink);outline-offset:1px}\n"] }]
|
|
514
|
+
}], propDecorators: { segments: [{ type: i0.Input, args: [{ isSignal: true, alias: "segments", required: true }] }], interactive: [{ type: i0.Input, args: [{ isSignal: true, alias: "interactive", required: false }] }], ariaLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "ariaLabel", required: true }] }], maxSegments: [{ type: i0.Input, args: [{ isSignal: true, alias: "maxSegments", required: false }] }], otherLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "otherLabel", required: false }] }], segmentClick: [{ type: i0.Output, args: ["segmentClick"] }] } });
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* Medidor de un valor entre 0 y 100 con meta opcional (utilización, avance de
|
|
518
|
+
* mantención). Es un `role="meter"` para que el lector de pantalla anuncie el
|
|
519
|
+
* valor en vez de una imagen sin nombre; la pista, la banda y la marca de meta
|
|
520
|
+
* son decorativas y el valor siempre está escrito.
|
|
521
|
+
*
|
|
522
|
+
* <kf-meter label="Utilización" display="72 %" [pct]="72" [target]="85" />
|
|
523
|
+
*/
|
|
524
|
+
class Meter {
|
|
525
|
+
label = input.required(/* @ts-ignore */
|
|
526
|
+
...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
|
|
527
|
+
/** Valor ya formateado, p. ej. «72 %». */
|
|
528
|
+
display = input.required(/* @ts-ignore */
|
|
529
|
+
...(ngDevMode ? [{ debugName: "display" }] : /* istanbul ignore next */ []));
|
|
530
|
+
pct = input.required(/* @ts-ignore */
|
|
531
|
+
...(ngDevMode ? [{ debugName: "pct" }] : /* istanbul ignore next */ []));
|
|
532
|
+
/** Posición de la meta, 0–100. */
|
|
533
|
+
target = input(/* @ts-ignore */
|
|
534
|
+
...(ngDevMode ? [undefined, { debugName: "target" }] : /* istanbul ignore next */ []));
|
|
535
|
+
/** Banda de rango habitual como `[desde, hasta]`, 0–100 (p. ej. P10–P90 de la flota). */
|
|
536
|
+
band = input(/* @ts-ignore */
|
|
537
|
+
...(ngDevMode ? [undefined, { debugName: "band" }] : /* istanbul ignore next */ []));
|
|
538
|
+
/** Sin la fila de etiqueta y valor: el dueño ya los muestra y `label` queda como nombre accesible. */
|
|
539
|
+
hideHeader = input(false, { ...(ngDevMode ? { debugName: "hideHeader" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
540
|
+
tone = input('neutral', /* @ts-ignore */
|
|
541
|
+
...(ngDevMode ? [{ debugName: "tone" }] : /* istanbul ignore next */ []));
|
|
542
|
+
note = input(/* @ts-ignore */
|
|
543
|
+
...(ngDevMode ? [undefined, { debugName: "note" }] : /* istanbul ignore next */ []));
|
|
544
|
+
/** Rótulo para lectores de la meta, que se suma a `aria-valuetext` («72 %, Meta: 85 %»). */
|
|
545
|
+
targetLabel = input('Meta', /* @ts-ignore */
|
|
546
|
+
...(ngDevMode ? [{ debugName: "targetLabel" }] : /* istanbul ignore next */ []));
|
|
547
|
+
/** Rótulo para lectores del rango habitual. */
|
|
548
|
+
bandLabel = input('Rango habitual', /* @ts-ignore */
|
|
549
|
+
...(ngDevMode ? [{ debugName: "bandLabel" }] : /* istanbul ignore next */ []));
|
|
550
|
+
/** Valor más la meta y el rango, que de otro modo solo existirían como marcas visuales. */
|
|
551
|
+
valueText = computed(() => {
|
|
552
|
+
const parts = [this.display()];
|
|
553
|
+
const target = this.targetPct();
|
|
554
|
+
if (target !== undefined) {
|
|
555
|
+
parts.push(`${this.targetLabel()}: ${target} %`);
|
|
556
|
+
}
|
|
557
|
+
const band = this.bandRange();
|
|
558
|
+
if (band) {
|
|
559
|
+
parts.push(`${this.bandLabel()}: ${band.left} a ${Math.min(100, band.left + band.width)} %`);
|
|
560
|
+
}
|
|
561
|
+
return parts.join(', ');
|
|
562
|
+
}, /* @ts-ignore */
|
|
563
|
+
...(ngDevMode ? [{ debugName: "valueText" }] : /* istanbul ignore next */ []));
|
|
564
|
+
fill = computed(() => clampPct(this.pct()), /* @ts-ignore */
|
|
565
|
+
...(ngDevMode ? [{ debugName: "fill" }] : /* istanbul ignore next */ []));
|
|
566
|
+
bandRange = computed(() => {
|
|
567
|
+
const band = this.band();
|
|
568
|
+
if (band === undefined) {
|
|
569
|
+
return undefined;
|
|
570
|
+
}
|
|
571
|
+
const from = clampPct(band[0]);
|
|
572
|
+
return { left: from, width: Math.max(1, clampPct(band[1]) - from) };
|
|
573
|
+
}, /* @ts-ignore */
|
|
574
|
+
...(ngDevMode ? [{ debugName: "bandRange" }] : /* istanbul ignore next */ []));
|
|
575
|
+
targetPct = computed(() => {
|
|
576
|
+
const target = this.target();
|
|
577
|
+
return target === undefined ? undefined : clampPct(target);
|
|
578
|
+
}, /* @ts-ignore */
|
|
579
|
+
...(ngDevMode ? [{ debugName: "targetPct" }] : /* istanbul ignore next */ []));
|
|
580
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.0", ngImport: i0, type: Meter, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
581
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1.0", type: Meter, isStandalone: true, selector: "kf-meter", inputs: { label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: true, transformFunction: null }, display: { classPropertyName: "display", publicName: "display", isSignal: true, isRequired: true, transformFunction: null }, pct: { classPropertyName: "pct", publicName: "pct", isSignal: true, isRequired: true, transformFunction: null }, target: { classPropertyName: "target", publicName: "target", isSignal: true, isRequired: false, transformFunction: null }, band: { classPropertyName: "band", publicName: "band", isSignal: true, isRequired: false, transformFunction: null }, hideHeader: { classPropertyName: "hideHeader", publicName: "hideHeader", isSignal: true, isRequired: false, transformFunction: null }, tone: { classPropertyName: "tone", publicName: "tone", isSignal: true, isRequired: false, transformFunction: null }, note: { classPropertyName: "note", publicName: "note", isSignal: true, isRequired: false, transformFunction: null }, targetLabel: { classPropertyName: "targetLabel", publicName: "targetLabel", isSignal: true, isRequired: false, transformFunction: null }, bandLabel: { classPropertyName: "bandLabel", publicName: "bandLabel", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0, template: "@if (!hideHeader()) {\n <div class=\"kf-meter__top\">\n <span>{{ label() }}</span>\n <b>{{ display() }}</b>\n </div>\n}\n<span\n class=\"kf-meter__track\"\n [class]=\"'kf-meter__track is-' + tone()\"\n role=\"meter\"\n aria-valuemin=\"0\"\n aria-valuemax=\"100\"\n [attr.aria-valuenow]=\"fill()\"\n [attr.aria-valuetext]=\"valueText()\"\n [attr.aria-label]=\"label()\"\n>\n @if (bandRange(); as range) {\n <span\n class=\"kf-meter__band\"\n aria-hidden=\"true\"\n [style.left.%]=\"range.left\"\n [style.width.%]=\"range.width\"\n ></span>\n }\n <span class=\"kf-meter__fill\" [style.width.%]=\"fill()\"></span>\n @if (targetPct() !== undefined) {\n <span class=\"kf-meter__target\" [style.left.%]=\"targetPct()\" aria-hidden=\"true\"></span>\n }\n</span>\n@if (note()) {\n <p class=\"kf-meter__note\">{{ note() }}</p>\n}\n", styles: [".is-ok{--rb: var(--kf-chart-ok)}.is-warn{--rb: var(--kf-chart-warn)}.is-risk{--rb: var(--kf-chart-risk)}.is-neutral{--rb: var(--kf-chart-neutral)}.is-cat-1{--rb: var(--kf-chart-cat-1)}.is-cat-2{--rb: var(--kf-chart-cat-2)}.is-cat-3{--rb: var(--kf-chart-cat-3)}.is-cat-4{--rb: var(--kf-chart-cat-4)}.is-cat-5{--rb: var(--kf-chart-cat-5)}.is-cat-6{--rb: var(--kf-chart-cat-6)}:host{display:flex;flex:0 0 auto;flex-direction:column;gap:5px;padding:0 6px}.kf-meter__top{display:flex;align-items:baseline;justify-content:space-between;gap:var(--kf-space-sm);font-size:var(--kf-font-size-label);font-weight:500;color:var(--kf-color-ink)}.kf-meter__top b{font-weight:700;font-variant-numeric:tabular-nums}.kf-meter__track{position:relative;display:block;flex:0 0 auto;height:var(--kf-chart-bar);border-radius:var(--kf-radius-pill);background:var(--kf-chart-track)}.kf-meter__band{position:absolute;top:-3px;bottom:-3px;border-radius:3px;background:var(--kf-chart-band)}.kf-meter__fill{position:absolute;inset:0 auto 0 0;min-width:4px;border-radius:var(--kf-radius-pill);background:var(--rb, var(--kf-chart-neutral))}.kf-meter__target{position:absolute;top:-4px;bottom:-4px;width:2px;margin-left:-1px;border-radius:1px;background:var(--kf-chart-target)}.kf-meter__note{margin:0;font-size:var(--kf-font-size-caption);line-height:1.35;color:var(--kf-chart-text-muted)}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
582
|
+
}
|
|
583
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.0", ngImport: i0, type: Meter, decorators: [{
|
|
584
|
+
type: Component,
|
|
585
|
+
args: [{ selector: 'kf-meter', changeDetection: ChangeDetectionStrategy.OnPush, template: "@if (!hideHeader()) {\n <div class=\"kf-meter__top\">\n <span>{{ label() }}</span>\n <b>{{ display() }}</b>\n </div>\n}\n<span\n class=\"kf-meter__track\"\n [class]=\"'kf-meter__track is-' + tone()\"\n role=\"meter\"\n aria-valuemin=\"0\"\n aria-valuemax=\"100\"\n [attr.aria-valuenow]=\"fill()\"\n [attr.aria-valuetext]=\"valueText()\"\n [attr.aria-label]=\"label()\"\n>\n @if (bandRange(); as range) {\n <span\n class=\"kf-meter__band\"\n aria-hidden=\"true\"\n [style.left.%]=\"range.left\"\n [style.width.%]=\"range.width\"\n ></span>\n }\n <span class=\"kf-meter__fill\" [style.width.%]=\"fill()\"></span>\n @if (targetPct() !== undefined) {\n <span class=\"kf-meter__target\" [style.left.%]=\"targetPct()\" aria-hidden=\"true\"></span>\n }\n</span>\n@if (note()) {\n <p class=\"kf-meter__note\">{{ note() }}</p>\n}\n", styles: [".is-ok{--rb: var(--kf-chart-ok)}.is-warn{--rb: var(--kf-chart-warn)}.is-risk{--rb: var(--kf-chart-risk)}.is-neutral{--rb: var(--kf-chart-neutral)}.is-cat-1{--rb: var(--kf-chart-cat-1)}.is-cat-2{--rb: var(--kf-chart-cat-2)}.is-cat-3{--rb: var(--kf-chart-cat-3)}.is-cat-4{--rb: var(--kf-chart-cat-4)}.is-cat-5{--rb: var(--kf-chart-cat-5)}.is-cat-6{--rb: var(--kf-chart-cat-6)}:host{display:flex;flex:0 0 auto;flex-direction:column;gap:5px;padding:0 6px}.kf-meter__top{display:flex;align-items:baseline;justify-content:space-between;gap:var(--kf-space-sm);font-size:var(--kf-font-size-label);font-weight:500;color:var(--kf-color-ink)}.kf-meter__top b{font-weight:700;font-variant-numeric:tabular-nums}.kf-meter__track{position:relative;display:block;flex:0 0 auto;height:var(--kf-chart-bar);border-radius:var(--kf-radius-pill);background:var(--kf-chart-track)}.kf-meter__band{position:absolute;top:-3px;bottom:-3px;border-radius:3px;background:var(--kf-chart-band)}.kf-meter__fill{position:absolute;inset:0 auto 0 0;min-width:4px;border-radius:var(--kf-radius-pill);background:var(--rb, var(--kf-chart-neutral))}.kf-meter__target{position:absolute;top:-4px;bottom:-4px;width:2px;margin-left:-1px;border-radius:1px;background:var(--kf-chart-target)}.kf-meter__note{margin:0;font-size:var(--kf-font-size-caption);line-height:1.35;color:var(--kf-chart-text-muted)}\n"] }]
|
|
586
|
+
}], propDecorators: { label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: true }] }], display: [{ type: i0.Input, args: [{ isSignal: true, alias: "display", required: true }] }], pct: [{ type: i0.Input, args: [{ isSignal: true, alias: "pct", required: true }] }], target: [{ type: i0.Input, args: [{ isSignal: true, alias: "target", required: false }] }], band: [{ type: i0.Input, args: [{ isSignal: true, alias: "band", required: false }] }], hideHeader: [{ type: i0.Input, args: [{ isSignal: true, alias: "hideHeader", required: false }] }], tone: [{ type: i0.Input, args: [{ isSignal: true, alias: "tone", required: false }] }], note: [{ type: i0.Input, args: [{ isSignal: true, alias: "note", required: false }] }], targetLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "targetLabel", required: false }] }], bandLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "bandLabel", required: false }] }] } });
|
|
587
|
+
|
|
588
|
+
/** Bajo estos conteos las barras llevan 3 y 2 px de separación; con más, ninguna. */
|
|
589
|
+
const SPACED_UP_TO = 14;
|
|
590
|
+
const TIGHT_UP_TO = 40;
|
|
591
|
+
/**
|
|
592
|
+
* Serie de barras diarias con la meta como línea sólida y el mínimo y el máximo
|
|
593
|
+
* escritos al pie (nunca solo en hover). `values` es la ventana completa, un
|
|
594
|
+
* valor por día y con ceros en los días sin datos. Es una imagen con
|
|
595
|
+
* `ariaLabel`: sin un punto de foco por barra.
|
|
596
|
+
*
|
|
597
|
+
* Las barras se reparten el ancho disponible, nunca pasan de 48 px (una sola
|
|
598
|
+
* no cubre el panel) y un valor positivo mide al menos 2 px para distinguirlo
|
|
599
|
+
* de un cero; la separación baja con la cantidad de barras, así que una
|
|
600
|
+
* ventana larga no desborda.
|
|
601
|
+
*
|
|
602
|
+
* <kf-bar-series ariaLabel="Consumo diario" [values]="consumo()" [target]="14"
|
|
603
|
+
* from="hace 14 días" to="hoy" />
|
|
604
|
+
*/
|
|
605
|
+
class BarSeries {
|
|
606
|
+
values = input.required(/* @ts-ignore */
|
|
607
|
+
...(ngDevMode ? [{ debugName: "values" }] : /* istanbul ignore next */ []));
|
|
608
|
+
target = input(/* @ts-ignore */
|
|
609
|
+
...(ngDevMode ? [undefined, { debugName: "target" }] : /* istanbul ignore next */ []));
|
|
610
|
+
ariaLabel = input.required(/* @ts-ignore */
|
|
611
|
+
...(ngDevMode ? [{ debugName: "ariaLabel" }] : /* istanbul ignore next */ []));
|
|
612
|
+
/** Etiqueta del extremo izquierdo del eje, p. ej. «hace 14 días». */
|
|
613
|
+
from = input.required(/* @ts-ignore */
|
|
614
|
+
...(ngDevMode ? [{ debugName: "from" }] : /* istanbul ignore next */ []));
|
|
615
|
+
/** Etiqueta del extremo derecho del eje, p. ej. «hoy». */
|
|
616
|
+
to = input.required(/* @ts-ignore */
|
|
617
|
+
...(ngDevMode ? [{ debugName: "to" }] : /* istanbul ignore next */ []));
|
|
618
|
+
/** Tono de las barras que superan la meta; el resto es neutral. */
|
|
619
|
+
toneAboveTarget = input('warn', /* @ts-ignore */
|
|
620
|
+
...(ngDevMode ? [{ debugName: "toneAboveTarget" }] : /* istanbul ignore next */ []));
|
|
621
|
+
locale = inject(LOCALE_ID);
|
|
622
|
+
scaleMax = computed(() => {
|
|
623
|
+
const peak = Math.max(0, ...this.values(), this.target() ?? 0);
|
|
624
|
+
return peak > 0 ? peak * 1.08 : 1;
|
|
625
|
+
}, /* @ts-ignore */
|
|
626
|
+
...(ngDevMode ? [{ debugName: "scaleMax" }] : /* istanbul ignore next */ []));
|
|
627
|
+
bars = computed(() => {
|
|
628
|
+
const target = this.target();
|
|
629
|
+
return this.values().map((value, index) => ({
|
|
630
|
+
index,
|
|
631
|
+
height: (Math.max(0, value) / this.scaleMax()) * 100,
|
|
632
|
+
empty: !(value > 0),
|
|
633
|
+
tone: target !== undefined && value > target ? this.toneAboveTarget() : 'neutral',
|
|
634
|
+
}));
|
|
635
|
+
}, /* @ts-ignore */
|
|
636
|
+
...(ngDevMode ? [{ debugName: "bars" }] : /* istanbul ignore next */ []));
|
|
637
|
+
gap = computed(() => {
|
|
638
|
+
const count = this.values().length;
|
|
639
|
+
return count <= SPACED_UP_TO ? 3 : count <= TIGHT_UP_TO ? 2 : 0;
|
|
640
|
+
}, /* @ts-ignore */
|
|
641
|
+
...(ngDevMode ? [{ debugName: "gap" }] : /* istanbul ignore next */ []));
|
|
642
|
+
targetBottom = computed(() => {
|
|
643
|
+
const target = this.target();
|
|
644
|
+
return target === undefined ? undefined : (target / this.scaleMax()) * 100;
|
|
645
|
+
}, /* @ts-ignore */
|
|
646
|
+
...(ngDevMode ? [{ debugName: "targetBottom" }] : /* istanbul ignore next */ []));
|
|
647
|
+
range = computed(() => {
|
|
648
|
+
const values = this.values();
|
|
649
|
+
if (values.length === 0) {
|
|
650
|
+
return '';
|
|
651
|
+
}
|
|
652
|
+
const format = (value) => formatNumber(value, this.locale, '1.1-1');
|
|
653
|
+
return `mín ${format(Math.min(...values))} · máx ${format(Math.max(...values))}`;
|
|
654
|
+
}, /* @ts-ignore */
|
|
655
|
+
...(ngDevMode ? [{ debugName: "range" }] : /* istanbul ignore next */ []));
|
|
656
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.0", ngImport: i0, type: BarSeries, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
657
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1.0", type: BarSeries, isStandalone: true, selector: "kf-bar-series", inputs: { values: { classPropertyName: "values", publicName: "values", isSignal: true, isRequired: true, transformFunction: null }, target: { classPropertyName: "target", publicName: "target", isSignal: true, isRequired: false, transformFunction: null }, ariaLabel: { classPropertyName: "ariaLabel", publicName: "ariaLabel", isSignal: true, isRequired: true, transformFunction: null }, from: { classPropertyName: "from", publicName: "from", isSignal: true, isRequired: true, transformFunction: null }, to: { classPropertyName: "to", publicName: "to", isSignal: true, isRequired: true, transformFunction: null }, toneAboveTarget: { classPropertyName: "toneAboveTarget", publicName: "toneAboveTarget", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0, template: "<div class=\"kf-bar-series\" role=\"img\" [attr.aria-label]=\"ariaLabel()\" [style.gap.px]=\"gap()\">\n @for (bar of bars(); track bar.index) {\n <span\n class=\"kf-bar-series__bar\"\n [class]=\"'kf-bar-series__bar is-' + bar.tone\"\n [class.kf-bar-series__bar--empty]=\"bar.empty\"\n [style.height.%]=\"bar.empty ? null : bar.height\"\n ></span>\n }\n @if (targetBottom() !== undefined) {\n <span class=\"kf-bar-series__target\" [style.bottom.%]=\"targetBottom()\"></span>\n }\n</div>\n<p class=\"kf-bar-series__axis\">\n <span>{{ from() }}</span>\n <span>{{ range() }}</span>\n <span>{{ to() }}</span>\n</p>\n", styles: [".is-ok{--rb: var(--kf-chart-ok)}.is-warn{--rb: var(--kf-chart-warn)}.is-risk{--rb: var(--kf-chart-risk)}.is-neutral{--rb: var(--kf-chart-neutral)}.is-cat-1{--rb: var(--kf-chart-cat-1)}.is-cat-2{--rb: var(--kf-chart-cat-2)}.is-cat-3{--rb: var(--kf-chart-cat-3)}.is-cat-4{--rb: var(--kf-chart-cat-4)}.is-cat-5{--rb: var(--kf-chart-cat-5)}.is-cat-6{--rb: var(--kf-chart-cat-6)}:host{display:flex;flex:0 0 auto;flex-direction:column;gap:var(--kf-space-xs);min-width:0}.kf-bar-series{position:relative;display:flex;align-items:flex-end;justify-content:center;height:56px;border-bottom:1px solid var(--kf-chart-grid)}.kf-bar-series__bar{flex:1 1 0;min-width:0;max-width:48px;min-height:2px;border-radius:3px 3px 0 0;background:var(--rb, var(--kf-chart-neutral))}.kf-bar-series__bar--empty{height:1px;min-height:1px;border-radius:0;background:var(--kf-chart-track)}.kf-bar-series__target{position:absolute;right:0;left:0;height:2px;background:var(--kf-chart-target)}.kf-bar-series__axis{display:flex;justify-content:space-between;gap:var(--kf-space-sm);margin:0;font-size:var(--kf-font-size-caption);font-variant-numeric:tabular-nums;color:var(--kf-chart-text-muted)}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
658
|
+
}
|
|
659
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.0", ngImport: i0, type: BarSeries, decorators: [{
|
|
660
|
+
type: Component,
|
|
661
|
+
args: [{ selector: 'kf-bar-series', changeDetection: ChangeDetectionStrategy.OnPush, template: "<div class=\"kf-bar-series\" role=\"img\" [attr.aria-label]=\"ariaLabel()\" [style.gap.px]=\"gap()\">\n @for (bar of bars(); track bar.index) {\n <span\n class=\"kf-bar-series__bar\"\n [class]=\"'kf-bar-series__bar is-' + bar.tone\"\n [class.kf-bar-series__bar--empty]=\"bar.empty\"\n [style.height.%]=\"bar.empty ? null : bar.height\"\n ></span>\n }\n @if (targetBottom() !== undefined) {\n <span class=\"kf-bar-series__target\" [style.bottom.%]=\"targetBottom()\"></span>\n }\n</div>\n<p class=\"kf-bar-series__axis\">\n <span>{{ from() }}</span>\n <span>{{ range() }}</span>\n <span>{{ to() }}</span>\n</p>\n", styles: [".is-ok{--rb: var(--kf-chart-ok)}.is-warn{--rb: var(--kf-chart-warn)}.is-risk{--rb: var(--kf-chart-risk)}.is-neutral{--rb: var(--kf-chart-neutral)}.is-cat-1{--rb: var(--kf-chart-cat-1)}.is-cat-2{--rb: var(--kf-chart-cat-2)}.is-cat-3{--rb: var(--kf-chart-cat-3)}.is-cat-4{--rb: var(--kf-chart-cat-4)}.is-cat-5{--rb: var(--kf-chart-cat-5)}.is-cat-6{--rb: var(--kf-chart-cat-6)}:host{display:flex;flex:0 0 auto;flex-direction:column;gap:var(--kf-space-xs);min-width:0}.kf-bar-series{position:relative;display:flex;align-items:flex-end;justify-content:center;height:56px;border-bottom:1px solid var(--kf-chart-grid)}.kf-bar-series__bar{flex:1 1 0;min-width:0;max-width:48px;min-height:2px;border-radius:3px 3px 0 0;background:var(--rb, var(--kf-chart-neutral))}.kf-bar-series__bar--empty{height:1px;min-height:1px;border-radius:0;background:var(--kf-chart-track)}.kf-bar-series__target{position:absolute;right:0;left:0;height:2px;background:var(--kf-chart-target)}.kf-bar-series__axis{display:flex;justify-content:space-between;gap:var(--kf-space-sm);margin:0;font-size:var(--kf-font-size-caption);font-variant-numeric:tabular-nums;color:var(--kf-chart-text-muted)}\n"] }]
|
|
662
|
+
}], propDecorators: { values: [{ type: i0.Input, args: [{ isSignal: true, alias: "values", required: true }] }], target: [{ type: i0.Input, args: [{ isSignal: true, alias: "target", required: false }] }], ariaLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "ariaLabel", required: true }] }], from: [{ type: i0.Input, args: [{ isSignal: true, alias: "from", required: true }] }], to: [{ type: i0.Input, args: [{ isSignal: true, alias: "to", required: true }] }], toneAboveTarget: [{ type: i0.Input, args: [{ isSignal: true, alias: "toneAboveTarget", required: false }] }] } });
|
|
663
|
+
|
|
664
|
+
/*
|
|
665
|
+
* Lógica pura de `kf-time-bars`: escala vertical con marcas redondas, corte por
|
|
666
|
+
* pico atípico, rótulos del eje de fechas y geometría de las barras. Sin Angular
|
|
667
|
+
* ni DOM para poder probarla con cualquier volumen de datos.
|
|
668
|
+
*/
|
|
669
|
+
const STEP_BASES = [1, 2, 5];
|
|
670
|
+
/** Cuántos tramos (sin contar el 0) admite el eje antes de subir el paso. */
|
|
671
|
+
const MAX_INTERVALS = 4;
|
|
672
|
+
const MIN_INTERVALS = 2;
|
|
673
|
+
const OUTLIER_FACTOR = 20;
|
|
674
|
+
const MIN_POSITIVE_FOR_OUTLIER = 5;
|
|
675
|
+
/**
|
|
676
|
+
* Marcas enteras con pasos 1-2-5 × 10^k, de 2 a 4 tramos. Un pico de 1 da 0, 1, 2:
|
|
677
|
+
* con valores tan chicos no puede haber marcas decimales («0,5 solicitudes»).
|
|
678
|
+
*/
|
|
679
|
+
function niceScale(peak) {
|
|
680
|
+
const safe = Number.isFinite(peak) && peak > 0 ? Math.ceil(peak) : 0;
|
|
681
|
+
let step = 1;
|
|
682
|
+
for (let exponent = 0; exponent < 15; exponent += 1) {
|
|
683
|
+
const found = STEP_BASES.map((base) => base * 10 ** exponent).find((candidate) => Math.ceil(safe / candidate) <= MAX_INTERVALS);
|
|
684
|
+
if (found !== undefined) {
|
|
685
|
+
step = found;
|
|
686
|
+
break;
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
const intervals = Math.max(MIN_INTERVALS, Math.ceil(safe / step));
|
|
690
|
+
return {
|
|
691
|
+
max: step * intervals,
|
|
692
|
+
step,
|
|
693
|
+
ticks: Array.from({ length: intervals + 1 }, (_, index) => index * step),
|
|
694
|
+
};
|
|
695
|
+
}
|
|
696
|
+
function percentile(sorted, fraction) {
|
|
697
|
+
const rank = Math.max(1, Math.ceil(fraction * sorted.length));
|
|
698
|
+
return sorted[rank - 1];
|
|
699
|
+
}
|
|
700
|
+
/**
|
|
701
|
+
* Escala de la serie. Si el pico supera 20 veces el percentil 90 de los días con
|
|
702
|
+
* datos, un solo día aplastaría al resto: se corta la escala en el percentil 90
|
|
703
|
+
* por 1,5 y el pico queda rotulado con su valor.
|
|
704
|
+
*/
|
|
705
|
+
function seriesScale(totals) {
|
|
706
|
+
const positives = totals.filter((value) => value > 0).sort((a, b) => a - b);
|
|
707
|
+
const peak = positives.length > 0 ? positives[positives.length - 1] : 0;
|
|
708
|
+
if (positives.length >= MIN_POSITIVE_FOR_OUTLIER) {
|
|
709
|
+
const reference = percentile(positives, 0.9);
|
|
710
|
+
if (peak > OUTLIER_FACTOR * reference) {
|
|
711
|
+
return { ...niceScale(reference * 1.5), clipped: true, peak };
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
return { ...niceScale(peak), clipped: false, peak };
|
|
715
|
+
}
|
|
716
|
+
/** Pasos candidatos para rotular cada N días: 2 y semanas, nunca 3 o 5 (no cuadran con el calendario). */
|
|
717
|
+
const LABEL_STEPS = [2, 7, 14, 21, 30];
|
|
718
|
+
/** Con tantas ranuras o más se rotula el inicio de cada mes, no cada N días. */
|
|
719
|
+
const MONTH_MODE_MIN_DAYS = 46;
|
|
720
|
+
function dayOfMonth(date) {
|
|
721
|
+
return Number(date.slice(8, 10));
|
|
722
|
+
}
|
|
723
|
+
/**
|
|
724
|
+
* Índices de los días que llevan rótulo en el eje X. Nunca más de los que
|
|
725
|
+
* caben en `plotWidth` con `minLabelPx` por rótulo y sin repetir un día.
|
|
726
|
+
* Hasta 45 días se rotula cada N días contando desde el último; con más se
|
|
727
|
+
* rotula el día 1 de cada mes y los extremos si hay lugar.
|
|
728
|
+
*/
|
|
729
|
+
function xTickIndices(dates, plotWidth, minLabelPx = 56) {
|
|
730
|
+
const count = dates.length;
|
|
731
|
+
if (count === 0) {
|
|
732
|
+
return [];
|
|
733
|
+
}
|
|
734
|
+
if (count === 1) {
|
|
735
|
+
return [0];
|
|
736
|
+
}
|
|
737
|
+
const capacity = Math.max(1, Math.floor(plotWidth / minLabelPx));
|
|
738
|
+
if (count <= capacity) {
|
|
739
|
+
return Array.from({ length: count }, (_, index) => index);
|
|
740
|
+
}
|
|
741
|
+
const slot = plotWidth / count;
|
|
742
|
+
if (count >= MONTH_MODE_MIN_DAYS) {
|
|
743
|
+
return monthTicks(dates, slot, capacity, minLabelPx);
|
|
744
|
+
}
|
|
745
|
+
const step = LABEL_STEPS.find((candidate) => Math.ceil(count / candidate) <= capacity);
|
|
746
|
+
const chosen = step ?? Math.ceil(count / capacity);
|
|
747
|
+
const indices = [];
|
|
748
|
+
for (let index = count - 1; index >= 0; index -= chosen) {
|
|
749
|
+
indices.unshift(index);
|
|
750
|
+
}
|
|
751
|
+
return indices;
|
|
752
|
+
}
|
|
753
|
+
function monthTicks(dates, slot, capacity, minLabelPx) {
|
|
754
|
+
let indices = dates.flatMap((date, index) => (dayOfMonth(date) === 1 ? [index] : []));
|
|
755
|
+
while (indices.length > Math.max(1, capacity - 1)) {
|
|
756
|
+
indices = indices.filter((_, position) => position % 2 === 0);
|
|
757
|
+
}
|
|
758
|
+
const last = dates.length - 1;
|
|
759
|
+
const room = (from, to) => (to - from) * slot >= minLabelPx;
|
|
760
|
+
if (indices.length === 0 || room(indices[indices.length - 1], last)) {
|
|
761
|
+
indices.push(last);
|
|
762
|
+
}
|
|
763
|
+
if (indices.length === 0 || room(0, indices[0])) {
|
|
764
|
+
indices.unshift(0);
|
|
765
|
+
}
|
|
766
|
+
return [...new Set(indices)];
|
|
767
|
+
}
|
|
768
|
+
const MAX_BAR_WIDTH = 48;
|
|
769
|
+
const MIN_BAR_WIDTH = 2;
|
|
770
|
+
/**
|
|
771
|
+
* Ancho de barra `clamp(2 px, ranura − hueco, 48 px)`, centrada en su ranura. Con
|
|
772
|
+
* un día o siete la barra queda angosta en vez de cubrir el panel de borde a
|
|
773
|
+
* borde; con ranuras de menos de 6 px no hay hueco.
|
|
774
|
+
*/
|
|
775
|
+
function barGeometry(plotWidth, count) {
|
|
776
|
+
const slot = count > 0 ? plotWidth / count : plotWidth;
|
|
777
|
+
const gap = slot < 6 ? 0 : Math.min(4, slot * 0.2);
|
|
778
|
+
const barWidth = Math.min(MAX_BAR_WIDTH, Math.max(MIN_BAR_WIDTH, slot - gap));
|
|
779
|
+
return { slot, barWidth, offset: (slot - barWidth) / 2 };
|
|
780
|
+
}
|
|
781
|
+
const MIN_POSITIVE_HEIGHT = 2;
|
|
782
|
+
/**
|
|
783
|
+
* Altos en px de una barra apilada. Un valor positivo mide al menos 2 px para
|
|
784
|
+
* distinguirlo de un cero; la parte con error conserva su proporción.
|
|
785
|
+
*/
|
|
786
|
+
function barHeights(day, scaleMax, plotHeight) {
|
|
787
|
+
if (!(day.total > 0) || !(scaleMax > 0)) {
|
|
788
|
+
return { total: 0, errors: 0, clipped: false };
|
|
789
|
+
}
|
|
790
|
+
const clipped = day.total > scaleMax;
|
|
791
|
+
const total = Math.min(plotHeight, Math.max(MIN_POSITIVE_HEIGHT, (day.total / scaleMax) * plotHeight));
|
|
792
|
+
const share = Math.min(1, Math.max(0, day.errors / day.total));
|
|
793
|
+
const errors = day.errors > 0 ? Math.min(total, Math.max(MIN_POSITIVE_HEIGHT, share * total)) : 0;
|
|
794
|
+
return { total, errors, clipped };
|
|
795
|
+
}
|
|
796
|
+
/** Días de la serie con al menos una solicitud. */
|
|
797
|
+
function activeDays(days) {
|
|
798
|
+
return days.filter((day) => day.total > 0).length;
|
|
799
|
+
}
|
|
800
|
+
/** Ancho aproximado en px que ocupa el rótulo más ancho del eje Y, para reservar el margen. */
|
|
801
|
+
function yAxisWidth(labels, charPx = 7) {
|
|
802
|
+
return Math.ceil(Math.max(1, ...labels.map((label) => label.length)) * charPx) + 10;
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
const DEFAULT_WIDTH = 600;
|
|
806
|
+
const NARROW_WIDTH = 480;
|
|
807
|
+
const TOP_PAD = 20;
|
|
808
|
+
const AXIS_HEIGHT = 24;
|
|
809
|
+
const MAX_LABELLED_BARS = 8;
|
|
810
|
+
const LABEL_CHAR_PX = 7;
|
|
811
|
+
const COMPACT_FROM = 10_000;
|
|
812
|
+
let nextId = 0;
|
|
813
|
+
/**
|
|
814
|
+
* Serie temporal de barras apiladas (correctas y con error) sobre el eje continuo
|
|
815
|
+
* de toda la ventana: un día sin datos es una ranura de valor 0, no un hueco. La
|
|
816
|
+
* escala vertical se adapta al volumen con marcas enteras y redondas, y un pico
|
|
817
|
+
* atípico se corta y se rotula en vez de aplastar al resto. Las barras tienen
|
|
818
|
+
* ancho mínimo y máximo, así que un solo día no ocupa el panel de borde a borde.
|
|
819
|
+
*
|
|
820
|
+
* Es un grupo enfocable: las flechas, Inicio y Fin leen un día a la vez en una
|
|
821
|
+
* línea `aria-live`, que es también la alternativa textual del gráfico. El error
|
|
822
|
+
* se distingue por trama diagonal y no solo por color.
|
|
823
|
+
*
|
|
824
|
+
* <kf-time-bars ariaLabel="Solicitudes de los últimos 30 días" [days]="dias()" />
|
|
825
|
+
*/
|
|
826
|
+
class TimeBars {
|
|
827
|
+
/** La ventana completa, un elemento por día y en orden cronológico. */
|
|
828
|
+
days = input.required(/* @ts-ignore */
|
|
829
|
+
...(ngDevMode ? [{ debugName: "days" }] : /* istanbul ignore next */ []));
|
|
830
|
+
ariaLabel = input.required(/* @ts-ignore */
|
|
831
|
+
...(ngDevMode ? [{ debugName: "ariaLabel" }] : /* istanbul ignore next */ []));
|
|
832
|
+
/** Sustantivo plural de lo que se cuenta, para la lectura de cada día. */
|
|
833
|
+
valueLabel = input('solicitudes', /* @ts-ignore */
|
|
834
|
+
...(ngDevMode ? [{ debugName: "valueLabel" }] : /* istanbul ignore next */ []));
|
|
835
|
+
okLegend = input('Correctas', /* @ts-ignore */
|
|
836
|
+
...(ngDevMode ? [{ debugName: "okLegend" }] : /* istanbul ignore next */ []));
|
|
837
|
+
errorLegend = input('Con error', /* @ts-ignore */
|
|
838
|
+
...(ngDevMode ? [{ debugName: "errorLegend" }] : /* istanbul ignore next */ []));
|
|
839
|
+
/** Frase del error en la lectura: «4 con error (14 %)». */
|
|
840
|
+
errorPhrase = input('con error', /* @ts-ignore */
|
|
841
|
+
...(ngDevMode ? [{ debugName: "errorPhrase" }] : /* istanbul ignore next */ []));
|
|
842
|
+
/** Locale de números y fechas; por defecto el de la aplicación. */
|
|
843
|
+
locale = input(/* @ts-ignore */
|
|
844
|
+
...(ngDevMode ? [undefined, { debugName: "locale" }] : /* istanbul ignore next */ []));
|
|
845
|
+
appLocale = inject(LOCALE_ID);
|
|
846
|
+
host = inject(ElementRef).nativeElement;
|
|
847
|
+
uid = `kf-time-bars-${nextId++}`;
|
|
848
|
+
width = signal(DEFAULT_WIDTH, /* @ts-ignore */
|
|
849
|
+
...(ngDevMode ? [{ debugName: "width" }] : /* istanbul ignore next */ []));
|
|
850
|
+
active = signal(null, /* @ts-ignore */
|
|
851
|
+
...(ngDevMode ? [{ debugName: "active" }] : /* istanbul ignore next */ []));
|
|
852
|
+
effectiveLocale = computed(() => this.locale() ?? this.appLocale, /* @ts-ignore */
|
|
853
|
+
...(ngDevMode ? [{ debugName: "effectiveLocale" }] : /* istanbul ignore next */ []));
|
|
854
|
+
numbers = computed(() => new Intl.NumberFormat(this.effectiveLocale()), /* @ts-ignore */
|
|
855
|
+
...(ngDevMode ? [{ debugName: "numbers" }] : /* istanbul ignore next */ []));
|
|
856
|
+
compact = computed(() => new Intl.NumberFormat(this.effectiveLocale(), {
|
|
857
|
+
notation: 'compact',
|
|
858
|
+
maximumFractionDigits: 1,
|
|
859
|
+
}), /* @ts-ignore */
|
|
860
|
+
...(ngDevMode ? [{ debugName: "compact" }] : /* istanbul ignore next */ []));
|
|
861
|
+
percentFormat = computed(() => new Intl.NumberFormat(this.effectiveLocale(), { maximumFractionDigits: 1 }), /* @ts-ignore */
|
|
862
|
+
...(ngDevMode ? [{ debugName: "percentFormat" }] : /* istanbul ignore next */ []));
|
|
863
|
+
scale = computed(() => seriesScale(this.days().map((day) => day.total)), /* @ts-ignore */
|
|
864
|
+
...(ngDevMode ? [{ debugName: "scale" }] : /* istanbul ignore next */ []));
|
|
865
|
+
clipped = computed(() => this.scale().clipped, /* @ts-ignore */
|
|
866
|
+
...(ngDevMode ? [{ debugName: "clipped" }] : /* istanbul ignore next */ []));
|
|
867
|
+
scaleMax = computed(() => this.scale().max, /* @ts-ignore */
|
|
868
|
+
...(ngDevMode ? [{ debugName: "scaleMax" }] : /* istanbul ignore next */ []));
|
|
869
|
+
narrow = computed(() => this.width() < NARROW_WIDTH, /* @ts-ignore */
|
|
870
|
+
...(ngDevMode ? [{ debugName: "narrow" }] : /* istanbul ignore next */ []));
|
|
871
|
+
plotHeight = computed(() => (this.narrow() ? 160 : 210), /* @ts-ignore */
|
|
872
|
+
...(ngDevMode ? [{ debugName: "plotHeight" }] : /* istanbul ignore next */ []));
|
|
873
|
+
top = TOP_PAD;
|
|
874
|
+
svgHeight = computed(() => TOP_PAD + this.plotHeight() + AXIS_HEIGHT, /* @ts-ignore */
|
|
875
|
+
...(ngDevMode ? [{ debugName: "svgHeight" }] : /* istanbul ignore next */ []));
|
|
876
|
+
svgWidth = computed(() => this.width(), /* @ts-ignore */
|
|
877
|
+
...(ngDevMode ? [{ debugName: "svgWidth" }] : /* istanbul ignore next */ []));
|
|
878
|
+
formatAxis(value) {
|
|
879
|
+
return value >= COMPACT_FROM ? this.compact().format(value) : this.numbers().format(value);
|
|
880
|
+
}
|
|
881
|
+
yLabels = computed(() => this.scale().ticks.map((tick) => this.formatAxis(tick)), /* @ts-ignore */
|
|
882
|
+
...(ngDevMode ? [{ debugName: "yLabels" }] : /* istanbul ignore next */ []));
|
|
883
|
+
left = computed(() => yAxisWidth(this.yLabels()), /* @ts-ignore */
|
|
884
|
+
...(ngDevMode ? [{ debugName: "left" }] : /* istanbul ignore next */ []));
|
|
885
|
+
plotWidth = computed(() => Math.max(40, this.width() - this.left() - 6), /* @ts-ignore */
|
|
886
|
+
...(ngDevMode ? [{ debugName: "plotWidth" }] : /* istanbul ignore next */ []));
|
|
887
|
+
ticks = computed(() => {
|
|
888
|
+
const scale = this.scale();
|
|
889
|
+
const base = TOP_PAD + this.plotHeight();
|
|
890
|
+
return scale.ticks.map((tick, index) => ({
|
|
891
|
+
y: base - (tick / scale.max) * this.plotHeight(),
|
|
892
|
+
label: this.yLabels()[index],
|
|
893
|
+
}));
|
|
894
|
+
}, /* @ts-ignore */
|
|
895
|
+
...(ngDevMode ? [{ debugName: "ticks" }] : /* istanbul ignore next */ []));
|
|
896
|
+
bars = computed(() => {
|
|
897
|
+
const days = this.days();
|
|
898
|
+
const scale = this.scale();
|
|
899
|
+
const geometry = barGeometry(this.plotWidth(), days.length);
|
|
900
|
+
const baseline = TOP_PAD + this.plotHeight();
|
|
901
|
+
const activeIndices = days.flatMap((day, index) => (day.total > 0 ? [index] : []));
|
|
902
|
+
const fewActive = activeIndices.length <= MAX_LABELLED_BARS;
|
|
903
|
+
// Un rótulo cabe si su ancho no invade al del día activo más cercano.
|
|
904
|
+
const roomFor = (index, text) => {
|
|
905
|
+
const gap = Math.min(...activeIndices.filter((other) => other !== index).map((other) => Math.abs(other - index)));
|
|
906
|
+
return text.length * LABEL_CHAR_PX <= geometry.slot * gap;
|
|
907
|
+
};
|
|
908
|
+
return days.map((day, index) => {
|
|
909
|
+
const heights = barHeights(day, scale.max, this.plotHeight());
|
|
910
|
+
const slotX = this.left() + index * geometry.slot;
|
|
911
|
+
const x = slotX + geometry.offset;
|
|
912
|
+
const okHeight = Math.max(0, heights.total - heights.errors);
|
|
913
|
+
const top = baseline - heights.total;
|
|
914
|
+
const valueText = day.total > 0 ? this.formatAxis(day.total) : null;
|
|
915
|
+
const showValue = valueText !== null && (heights.clipped || (fewActive && roomFor(index, valueText)));
|
|
916
|
+
return {
|
|
917
|
+
index,
|
|
918
|
+
slotX,
|
|
919
|
+
slotWidth: geometry.slot,
|
|
920
|
+
x,
|
|
921
|
+
width: geometry.barWidth,
|
|
922
|
+
baseline,
|
|
923
|
+
okY: baseline - okHeight,
|
|
924
|
+
okHeight,
|
|
925
|
+
errorY: top,
|
|
926
|
+
errorHeight: heights.errors,
|
|
927
|
+
empty: heights.total === 0,
|
|
928
|
+
clipped: heights.clipped,
|
|
929
|
+
separated: geometry.barWidth >= 6,
|
|
930
|
+
valueText: showValue ? valueText : null,
|
|
931
|
+
valueY: Math.max(12, top - 5),
|
|
932
|
+
center: x + geometry.barWidth / 2,
|
|
933
|
+
};
|
|
934
|
+
});
|
|
935
|
+
}, /* @ts-ignore */
|
|
936
|
+
...(ngDevMode ? [{ debugName: "bars" }] : /* istanbul ignore next */ []));
|
|
937
|
+
xLabels = computed(() => {
|
|
938
|
+
const days = this.days();
|
|
939
|
+
const dates = days.map((day) => day.date);
|
|
940
|
+
const indices = xTickIndices(dates, this.plotWidth(), this.narrow() ? 46 : 56);
|
|
941
|
+
const format = this.dateFormat(days.length, dates);
|
|
942
|
+
const geometry = barGeometry(this.plotWidth(), days.length);
|
|
943
|
+
return indices.map((index) => {
|
|
944
|
+
const text = format.format(Date.parse(`${dates[index]}T00:00:00Z`));
|
|
945
|
+
const center = this.left() + index * geometry.slot + geometry.slot / 2;
|
|
946
|
+
const half = (text.length * 6.2) / 2;
|
|
947
|
+
const anchor = center - half < 0 ? 'start' : center + half > this.width() ? 'end' : 'middle';
|
|
948
|
+
return { x: center, text, anchor };
|
|
949
|
+
});
|
|
950
|
+
}, /* @ts-ignore */
|
|
951
|
+
...(ngDevMode ? [{ debugName: "xLabels" }] : /* istanbul ignore next */ []));
|
|
952
|
+
dateFormat(count, dates) {
|
|
953
|
+
const crossesYear = dates.length > 0 && dates[0].slice(0, 4) !== dates[dates.length - 1].slice(0, 4);
|
|
954
|
+
const options = count <= 7
|
|
955
|
+
? { weekday: 'short', day: 'numeric', timeZone: 'UTC' }
|
|
956
|
+
: { day: 'numeric', month: 'short', timeZone: 'UTC' };
|
|
957
|
+
if (crossesYear) {
|
|
958
|
+
options.year = '2-digit';
|
|
959
|
+
}
|
|
960
|
+
return new Intl.DateTimeFormat(this.effectiveLocale(), options);
|
|
961
|
+
}
|
|
962
|
+
longDate = computed(() => new Intl.DateTimeFormat(this.effectiveLocale(), {
|
|
963
|
+
weekday: 'short',
|
|
964
|
+
day: 'numeric',
|
|
965
|
+
month: 'short',
|
|
966
|
+
year: 'numeric',
|
|
967
|
+
timeZone: 'UTC',
|
|
968
|
+
}), /* @ts-ignore */
|
|
969
|
+
...(ngDevMode ? [{ debugName: "longDate" }] : /* istanbul ignore next */ []));
|
|
970
|
+
totals = computed(() => {
|
|
971
|
+
const days = this.days();
|
|
972
|
+
const total = days.reduce((sum, day) => sum + day.total, 0);
|
|
973
|
+
const errors = days.reduce((sum, day) => sum + day.errors, 0);
|
|
974
|
+
return { ok: Math.max(0, total - errors), errors };
|
|
975
|
+
}, /* @ts-ignore */
|
|
976
|
+
...(ngDevMode ? [{ debugName: "totals" }] : /* istanbul ignore next */ []));
|
|
977
|
+
legend = computed(() => {
|
|
978
|
+
const { ok, errors } = this.totals();
|
|
979
|
+
return {
|
|
980
|
+
ok: ok > 0 ? { label: this.okLegend(), value: this.numbers().format(ok) } : null,
|
|
981
|
+
errors: errors > 0 ? { label: this.errorLegend(), value: this.numbers().format(errors) } : null,
|
|
982
|
+
};
|
|
983
|
+
}, /* @ts-ignore */
|
|
984
|
+
...(ngDevMode ? [{ debugName: "legend" }] : /* istanbul ignore next */ []));
|
|
985
|
+
/** Lectura del día activo; vacía mientras no se elige ninguno. */
|
|
986
|
+
readout = computed(() => {
|
|
987
|
+
const index = this.active();
|
|
988
|
+
const day = index === null ? undefined : this.days()[index];
|
|
989
|
+
if (!day) {
|
|
990
|
+
return '';
|
|
991
|
+
}
|
|
992
|
+
const date = this.longDate().format(Date.parse(`${day.date}T00:00:00Z`));
|
|
993
|
+
const noun = this.valueLabel();
|
|
994
|
+
if (day.total === 0) {
|
|
995
|
+
return `${date}: 0 ${noun}`;
|
|
996
|
+
}
|
|
997
|
+
const share = this.percentFormat().format((day.errors / day.total) * 100);
|
|
998
|
+
return `${date}: ${this.numbers().format(day.total)} ${noun}, ${this.numbers().format(day.errors)} ${this.errorPhrase()} (${share} %)`;
|
|
999
|
+
}, /* @ts-ignore */
|
|
1000
|
+
...(ngDevMode ? [{ debugName: "readout" }] : /* istanbul ignore next */ []));
|
|
1001
|
+
activeBar = computed(() => {
|
|
1002
|
+
const index = this.active();
|
|
1003
|
+
return index === null ? null : (this.bars()[index] ?? null);
|
|
1004
|
+
}, /* @ts-ignore */
|
|
1005
|
+
...(ngDevMode ? [{ debugName: "activeBar" }] : /* istanbul ignore next */ []));
|
|
1006
|
+
constructor() {
|
|
1007
|
+
const destroyRef = inject(DestroyRef);
|
|
1008
|
+
const observe = () => {
|
|
1009
|
+
const measured = this.host.getBoundingClientRect().width;
|
|
1010
|
+
if (measured > 0) {
|
|
1011
|
+
this.width.set(Math.floor(measured));
|
|
1012
|
+
}
|
|
1013
|
+
};
|
|
1014
|
+
afterNextRender(() => {
|
|
1015
|
+
observe();
|
|
1016
|
+
if (typeof ResizeObserver !== 'function') {
|
|
1017
|
+
return;
|
|
1018
|
+
}
|
|
1019
|
+
const observer = new ResizeObserver((entries) => {
|
|
1020
|
+
const next = entries[0]?.contentRect.width ?? 0;
|
|
1021
|
+
if (next > 0) {
|
|
1022
|
+
this.width.set(Math.floor(next));
|
|
1023
|
+
}
|
|
1024
|
+
});
|
|
1025
|
+
observer.observe(this.host);
|
|
1026
|
+
destroyRef.onDestroy(() => observer.disconnect());
|
|
1027
|
+
});
|
|
1028
|
+
}
|
|
1029
|
+
onFocus() {
|
|
1030
|
+
if (this.active() === null && this.days().length > 0) {
|
|
1031
|
+
this.active.set(this.days().length - 1);
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
onKeydown(event) {
|
|
1035
|
+
const last = this.days().length - 1;
|
|
1036
|
+
if (last < 0) {
|
|
1037
|
+
return;
|
|
1038
|
+
}
|
|
1039
|
+
const current = this.active() ?? last;
|
|
1040
|
+
const next = {
|
|
1041
|
+
ArrowLeft: Math.max(0, current - 1),
|
|
1042
|
+
ArrowRight: Math.min(last, current + 1),
|
|
1043
|
+
Home: 0,
|
|
1044
|
+
End: last,
|
|
1045
|
+
};
|
|
1046
|
+
if (event.key in next) {
|
|
1047
|
+
event.preventDefault();
|
|
1048
|
+
this.active.set(next[event.key]);
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
onPointer(event) {
|
|
1052
|
+
const svg = event.currentTarget;
|
|
1053
|
+
const rect = svg.getBoundingClientRect();
|
|
1054
|
+
const count = this.days().length;
|
|
1055
|
+
if (count === 0 || rect.width === 0) {
|
|
1056
|
+
return;
|
|
1057
|
+
}
|
|
1058
|
+
const slot = this.plotWidth() / count;
|
|
1059
|
+
const x = event.clientX - rect.left - this.left();
|
|
1060
|
+
this.active.set(Math.min(count - 1, Math.max(0, Math.floor(x / slot))));
|
|
1061
|
+
}
|
|
1062
|
+
onLeave() {
|
|
1063
|
+
if (!this.host.contains(this.host.ownerDocument.activeElement)) {
|
|
1064
|
+
this.active.set(null);
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
onBlur() {
|
|
1068
|
+
this.active.set(null);
|
|
1069
|
+
}
|
|
1070
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.0", ngImport: i0, type: TimeBars, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1071
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1.0", type: TimeBars, isStandalone: true, selector: "kf-time-bars", inputs: { days: { classPropertyName: "days", publicName: "days", isSignal: true, isRequired: true, transformFunction: null }, ariaLabel: { classPropertyName: "ariaLabel", publicName: "ariaLabel", isSignal: true, isRequired: true, transformFunction: null }, valueLabel: { classPropertyName: "valueLabel", publicName: "valueLabel", isSignal: true, isRequired: false, transformFunction: null }, okLegend: { classPropertyName: "okLegend", publicName: "okLegend", isSignal: true, isRequired: false, transformFunction: null }, errorLegend: { classPropertyName: "errorLegend", publicName: "errorLegend", isSignal: true, isRequired: false, transformFunction: null }, errorPhrase: { classPropertyName: "errorPhrase", publicName: "errorPhrase", isSignal: true, isRequired: false, transformFunction: null }, locale: { classPropertyName: "locale", publicName: "locale", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0, template: "<div class=\"kf-time-bars__legend\">\n @if (legend().ok; as item) {\n <span class=\"kf-time-bars__legend-item\">\n <span class=\"kf-time-bars__swatch kf-time-bars__swatch--ok\" aria-hidden=\"true\"></span>\n {{ item.label }} <strong>{{ item.value }}</strong>\n </span>\n }\n @if (legend().errors; as item) {\n <span class=\"kf-time-bars__legend-item\">\n <span class=\"kf-time-bars__swatch kf-time-bars__swatch--error\" aria-hidden=\"true\"></span>\n {{ item.label }} <strong>{{ item.value }}</strong>\n </span>\n }\n @if (clipped()) {\n <span class=\"kf-time-bars__legend-item kf-time-bars__legend-item--note\">\n Escala cortada en {{ formatAxis(scaleMax()) }}: la barra con quiebre supera ese valor\n </span>\n }\n</div>\n\n<div\n class=\"kf-time-bars__chart\"\n role=\"group\"\n tabindex=\"0\"\n aria-roledescription=\"gr\u00E1fico de barras\"\n [attr.aria-label]=\"ariaLabel()\"\n [attr.aria-describedby]=\"uid + '-readout'\"\n (focus)=\"onFocus()\"\n (blur)=\"onBlur()\"\n (keydown)=\"onKeydown($event)\"\n>\n <svg\n class=\"kf-time-bars__svg\"\n aria-hidden=\"true\"\n focusable=\"false\"\n [attr.width]=\"svgWidth()\"\n [attr.height]=\"svgHeight()\"\n [attr.viewBox]=\"'0 0 ' + svgWidth() + ' ' + svgHeight()\"\n (pointermove)=\"onPointer($event)\"\n (pointerdown)=\"onPointer($event)\"\n (pointerleave)=\"onLeave()\"\n >\n <defs>\n <pattern\n [attr.id]=\"uid + '-hatch'\"\n width=\"5\"\n height=\"5\"\n patternUnits=\"userSpaceOnUse\"\n patternTransform=\"rotate(45)\"\n >\n <rect width=\"5\" height=\"5\" class=\"kf-time-bars__hatch-base\" />\n <rect width=\"2\" height=\"5\" class=\"kf-time-bars__hatch-line\" />\n </pattern>\n </defs>\n\n @for (tick of ticks(); track $index) {\n <line\n class=\"kf-time-bars__grid\"\n [class.kf-time-bars__grid--base]=\"$first\"\n [attr.x1]=\"left()\"\n [attr.x2]=\"svgWidth()\"\n [attr.y1]=\"tick.y\"\n [attr.y2]=\"tick.y\"\n />\n <text class=\"kf-time-bars__y\" [attr.x]=\"left() - 6\" [attr.y]=\"tick.y + 4\" text-anchor=\"end\">\n {{ tick.label }}\n </text>\n }\n\n @if (activeBar(); as bar) {\n <rect\n class=\"kf-time-bars__active\"\n [attr.x]=\"bar.slotX\"\n [attr.y]=\"top\"\n [attr.width]=\"bar.slotWidth\"\n [attr.height]=\"plotHeight()\"\n />\n }\n\n @for (bar of bars(); track bar.index) {\n <g class=\"kf-time-bars__slot\">\n @if (bar.empty) {\n <rect\n class=\"kf-time-bars__zero\"\n [attr.x]=\"bar.x\"\n [attr.y]=\"bar.baseline - 1\"\n [attr.width]=\"bar.width\"\n height=\"1\"\n />\n } @else {\n @if (bar.okHeight > 0) {\n <rect\n class=\"kf-time-bars__ok\"\n [attr.x]=\"bar.x\"\n [attr.y]=\"bar.okY\"\n [attr.width]=\"bar.width\"\n [attr.height]=\"bar.okHeight\"\n />\n }\n @if (bar.errorHeight > 0) {\n <rect\n class=\"kf-time-bars__error\"\n [class.kf-time-bars__error--separated]=\"bar.separated && bar.okHeight > 0\"\n [attr.x]=\"bar.x\"\n [attr.y]=\"bar.errorY\"\n [attr.width]=\"bar.width\"\n [attr.height]=\"bar.errorHeight\"\n [attr.fill]=\"'url(#' + uid + '-hatch)'\"\n />\n }\n @if (bar.clipped) {\n <path\n class=\"kf-time-bars__break\"\n [attr.d]=\"'M' + (bar.x - 1) + ' ' + (bar.errorY + 9) + ' l' + (bar.width + 2) + ' -5'\"\n />\n }\n @if (bar.valueText; as valueText) {\n <text\n class=\"kf-time-bars__value\"\n [attr.x]=\"bar.center\"\n [attr.y]=\"bar.valueY\"\n text-anchor=\"middle\"\n >\n {{ valueText }}\n </text>\n }\n }\n </g>\n }\n\n @for (label of xLabels(); track label.x) {\n <text\n class=\"kf-time-bars__x\"\n [attr.x]=\"label.x\"\n [attr.y]=\"svgHeight() - 6\"\n [attr.text-anchor]=\"label.anchor\"\n >\n {{ label.text }}\n </text>\n }\n </svg>\n</div>\n\n<p class=\"kf-time-bars__readout\" aria-live=\"polite\" [id]=\"uid + '-readout'\">\n @if (readout()) {\n {{ readout() }}\n } @else {\n <span class=\"kf-time-bars__hint\" aria-hidden=\"true\">Usar las flechas para leer cada d\u00EDa</span>\n }\n</p>\n", styles: [":host{display:flex;flex-direction:column;gap:var(--kf-space-sm);min-width:0}.kf-time-bars__legend{display:flex;flex-wrap:wrap;align-items:center;gap:var(--kf-space-xs) var(--kf-space-md);font-size:var(--kf-font-size-caption);color:var(--kf-chart-text-muted)}.kf-time-bars__legend-item{display:inline-flex;align-items:center;gap:var(--kf-space-xs)}.kf-time-bars__legend-item strong{font-variant-numeric:tabular-nums;color:var(--kf-color-ink)}.kf-time-bars__swatch{flex:0 0 auto;width:12px;height:12px;border-radius:3px}.kf-time-bars__swatch--ok{background:var(--kf-chart-series)}.kf-time-bars__swatch--error{background:repeating-linear-gradient(45deg,var(--kf-chart-risk) 0 2px,var(--kf-color-white) 2px 4px);box-shadow:inset 0 0 0 1px var(--kf-chart-risk)}.kf-time-bars__chart{min-width:0;border-radius:var(--kf-radius-xs)}.kf-time-bars__chart:focus-visible{outline:none;box-shadow:var(--kf-shadow-focus)}.kf-time-bars__svg{display:block;max-width:100%;overflow:visible;font-variant-numeric:tabular-nums}.kf-time-bars__grid{stroke:var(--kf-chart-grid);stroke-opacity:.55;stroke-width:1;shape-rendering:crispEdges}.kf-time-bars__grid--base{stroke-opacity:1}.kf-time-bars__y,.kf-time-bars__x{font-size:var(--kf-font-size-caption);fill:var(--kf-chart-text-muted)}.kf-time-bars__value{font-size:var(--kf-font-size-caption);font-weight:600;fill:var(--kf-color-ink)}.kf-time-bars__ok{fill:var(--kf-chart-series)}.kf-time-bars__zero{fill:var(--kf-chart-track)}.kf-time-bars__error{stroke:var(--kf-chart-risk);stroke-width:0}.kf-time-bars__error--separated{stroke:var(--kf-color-white);stroke-width:1px;paint-order:stroke}.kf-time-bars__hatch-base{fill:var(--kf-chart-risk)}.kf-time-bars__hatch-line{fill:var(--kf-color-white);fill-opacity:.55}.kf-time-bars__break{fill:none;stroke:var(--kf-color-white);stroke-width:2px}.kf-time-bars__active{fill:var(--kf-chart-track);fill-opacity:.45}.kf-time-bars__readout{min-height:1.4em;margin:0;font-size:var(--kf-font-size-label);font-weight:500;line-height:1.4;font-variant-numeric:tabular-nums;color:var(--kf-color-ink)}.kf-time-bars__hint{font-weight:400;color:var(--kf-chart-text-muted)}@media(hover:none){.kf-time-bars__hint{display:none}}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
1072
|
+
}
|
|
1073
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.0", ngImport: i0, type: TimeBars, decorators: [{
|
|
1074
|
+
type: Component,
|
|
1075
|
+
args: [{ selector: 'kf-time-bars', changeDetection: ChangeDetectionStrategy.OnPush, template: "<div class=\"kf-time-bars__legend\">\n @if (legend().ok; as item) {\n <span class=\"kf-time-bars__legend-item\">\n <span class=\"kf-time-bars__swatch kf-time-bars__swatch--ok\" aria-hidden=\"true\"></span>\n {{ item.label }} <strong>{{ item.value }}</strong>\n </span>\n }\n @if (legend().errors; as item) {\n <span class=\"kf-time-bars__legend-item\">\n <span class=\"kf-time-bars__swatch kf-time-bars__swatch--error\" aria-hidden=\"true\"></span>\n {{ item.label }} <strong>{{ item.value }}</strong>\n </span>\n }\n @if (clipped()) {\n <span class=\"kf-time-bars__legend-item kf-time-bars__legend-item--note\">\n Escala cortada en {{ formatAxis(scaleMax()) }}: la barra con quiebre supera ese valor\n </span>\n }\n</div>\n\n<div\n class=\"kf-time-bars__chart\"\n role=\"group\"\n tabindex=\"0\"\n aria-roledescription=\"gr\u00E1fico de barras\"\n [attr.aria-label]=\"ariaLabel()\"\n [attr.aria-describedby]=\"uid + '-readout'\"\n (focus)=\"onFocus()\"\n (blur)=\"onBlur()\"\n (keydown)=\"onKeydown($event)\"\n>\n <svg\n class=\"kf-time-bars__svg\"\n aria-hidden=\"true\"\n focusable=\"false\"\n [attr.width]=\"svgWidth()\"\n [attr.height]=\"svgHeight()\"\n [attr.viewBox]=\"'0 0 ' + svgWidth() + ' ' + svgHeight()\"\n (pointermove)=\"onPointer($event)\"\n (pointerdown)=\"onPointer($event)\"\n (pointerleave)=\"onLeave()\"\n >\n <defs>\n <pattern\n [attr.id]=\"uid + '-hatch'\"\n width=\"5\"\n height=\"5\"\n patternUnits=\"userSpaceOnUse\"\n patternTransform=\"rotate(45)\"\n >\n <rect width=\"5\" height=\"5\" class=\"kf-time-bars__hatch-base\" />\n <rect width=\"2\" height=\"5\" class=\"kf-time-bars__hatch-line\" />\n </pattern>\n </defs>\n\n @for (tick of ticks(); track $index) {\n <line\n class=\"kf-time-bars__grid\"\n [class.kf-time-bars__grid--base]=\"$first\"\n [attr.x1]=\"left()\"\n [attr.x2]=\"svgWidth()\"\n [attr.y1]=\"tick.y\"\n [attr.y2]=\"tick.y\"\n />\n <text class=\"kf-time-bars__y\" [attr.x]=\"left() - 6\" [attr.y]=\"tick.y + 4\" text-anchor=\"end\">\n {{ tick.label }}\n </text>\n }\n\n @if (activeBar(); as bar) {\n <rect\n class=\"kf-time-bars__active\"\n [attr.x]=\"bar.slotX\"\n [attr.y]=\"top\"\n [attr.width]=\"bar.slotWidth\"\n [attr.height]=\"plotHeight()\"\n />\n }\n\n @for (bar of bars(); track bar.index) {\n <g class=\"kf-time-bars__slot\">\n @if (bar.empty) {\n <rect\n class=\"kf-time-bars__zero\"\n [attr.x]=\"bar.x\"\n [attr.y]=\"bar.baseline - 1\"\n [attr.width]=\"bar.width\"\n height=\"1\"\n />\n } @else {\n @if (bar.okHeight > 0) {\n <rect\n class=\"kf-time-bars__ok\"\n [attr.x]=\"bar.x\"\n [attr.y]=\"bar.okY\"\n [attr.width]=\"bar.width\"\n [attr.height]=\"bar.okHeight\"\n />\n }\n @if (bar.errorHeight > 0) {\n <rect\n class=\"kf-time-bars__error\"\n [class.kf-time-bars__error--separated]=\"bar.separated && bar.okHeight > 0\"\n [attr.x]=\"bar.x\"\n [attr.y]=\"bar.errorY\"\n [attr.width]=\"bar.width\"\n [attr.height]=\"bar.errorHeight\"\n [attr.fill]=\"'url(#' + uid + '-hatch)'\"\n />\n }\n @if (bar.clipped) {\n <path\n class=\"kf-time-bars__break\"\n [attr.d]=\"'M' + (bar.x - 1) + ' ' + (bar.errorY + 9) + ' l' + (bar.width + 2) + ' -5'\"\n />\n }\n @if (bar.valueText; as valueText) {\n <text\n class=\"kf-time-bars__value\"\n [attr.x]=\"bar.center\"\n [attr.y]=\"bar.valueY\"\n text-anchor=\"middle\"\n >\n {{ valueText }}\n </text>\n }\n }\n </g>\n }\n\n @for (label of xLabels(); track label.x) {\n <text\n class=\"kf-time-bars__x\"\n [attr.x]=\"label.x\"\n [attr.y]=\"svgHeight() - 6\"\n [attr.text-anchor]=\"label.anchor\"\n >\n {{ label.text }}\n </text>\n }\n </svg>\n</div>\n\n<p class=\"kf-time-bars__readout\" aria-live=\"polite\" [id]=\"uid + '-readout'\">\n @if (readout()) {\n {{ readout() }}\n } @else {\n <span class=\"kf-time-bars__hint\" aria-hidden=\"true\">Usar las flechas para leer cada d\u00EDa</span>\n }\n</p>\n", styles: [":host{display:flex;flex-direction:column;gap:var(--kf-space-sm);min-width:0}.kf-time-bars__legend{display:flex;flex-wrap:wrap;align-items:center;gap:var(--kf-space-xs) var(--kf-space-md);font-size:var(--kf-font-size-caption);color:var(--kf-chart-text-muted)}.kf-time-bars__legend-item{display:inline-flex;align-items:center;gap:var(--kf-space-xs)}.kf-time-bars__legend-item strong{font-variant-numeric:tabular-nums;color:var(--kf-color-ink)}.kf-time-bars__swatch{flex:0 0 auto;width:12px;height:12px;border-radius:3px}.kf-time-bars__swatch--ok{background:var(--kf-chart-series)}.kf-time-bars__swatch--error{background:repeating-linear-gradient(45deg,var(--kf-chart-risk) 0 2px,var(--kf-color-white) 2px 4px);box-shadow:inset 0 0 0 1px var(--kf-chart-risk)}.kf-time-bars__chart{min-width:0;border-radius:var(--kf-radius-xs)}.kf-time-bars__chart:focus-visible{outline:none;box-shadow:var(--kf-shadow-focus)}.kf-time-bars__svg{display:block;max-width:100%;overflow:visible;font-variant-numeric:tabular-nums}.kf-time-bars__grid{stroke:var(--kf-chart-grid);stroke-opacity:.55;stroke-width:1;shape-rendering:crispEdges}.kf-time-bars__grid--base{stroke-opacity:1}.kf-time-bars__y,.kf-time-bars__x{font-size:var(--kf-font-size-caption);fill:var(--kf-chart-text-muted)}.kf-time-bars__value{font-size:var(--kf-font-size-caption);font-weight:600;fill:var(--kf-color-ink)}.kf-time-bars__ok{fill:var(--kf-chart-series)}.kf-time-bars__zero{fill:var(--kf-chart-track)}.kf-time-bars__error{stroke:var(--kf-chart-risk);stroke-width:0}.kf-time-bars__error--separated{stroke:var(--kf-color-white);stroke-width:1px;paint-order:stroke}.kf-time-bars__hatch-base{fill:var(--kf-chart-risk)}.kf-time-bars__hatch-line{fill:var(--kf-color-white);fill-opacity:.55}.kf-time-bars__break{fill:none;stroke:var(--kf-color-white);stroke-width:2px}.kf-time-bars__active{fill:var(--kf-chart-track);fill-opacity:.45}.kf-time-bars__readout{min-height:1.4em;margin:0;font-size:var(--kf-font-size-label);font-weight:500;line-height:1.4;font-variant-numeric:tabular-nums;color:var(--kf-color-ink)}.kf-time-bars__hint{font-weight:400;color:var(--kf-chart-text-muted)}@media(hover:none){.kf-time-bars__hint{display:none}}\n"] }]
|
|
1076
|
+
}], ctorParameters: () => [], propDecorators: { days: [{ type: i0.Input, args: [{ isSignal: true, alias: "days", required: true }] }], ariaLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "ariaLabel", required: true }] }], valueLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "valueLabel", required: false }] }], okLegend: [{ type: i0.Input, args: [{ isSignal: true, alias: "okLegend", required: false }] }], errorLegend: [{ type: i0.Input, args: [{ isSignal: true, alias: "errorLegend", required: false }] }], errorPhrase: [{ type: i0.Input, args: [{ isSignal: true, alias: "errorPhrase", required: false }] }], locale: [{ type: i0.Input, args: [{ isSignal: true, alias: "locale", required: false }] }] } });
|
|
1077
|
+
|
|
1078
|
+
/**
|
|
1079
|
+
* Variación contra el período anterior: flecha ▲▼■ más el valor, nunca solo
|
|
1080
|
+
* color (la forma de la flecha y el texto dicen el sentido). `unit="pp"` resta
|
|
1081
|
+
* puntos porcentuales; `unit="%"` es el cambio relativo. `goodWhen` decide si
|
|
1082
|
+
* subir es bueno o malo (p. ej. bajar el tiempo de espera es bueno). Para
|
|
1083
|
+
* lectores de pantalla se lee una sola frase («Sube +2,0 pp vs. período
|
|
1084
|
+
* anterior»).
|
|
1085
|
+
*
|
|
1086
|
+
* Se proyecta dentro del valor de un `kf-stat-tile` (`hasProjectedValue`); el
|
|
1087
|
+
* tile no tiene un input `delta`.
|
|
1088
|
+
*
|
|
1089
|
+
* <kf-stat-delta [current]="82" [previous]="79" unit="pp" />
|
|
1090
|
+
*/
|
|
1091
|
+
class StatDelta {
|
|
1092
|
+
current = input.required(/* @ts-ignore */
|
|
1093
|
+
...(ngDevMode ? [{ debugName: "current" }] : /* istanbul ignore next */ []));
|
|
1094
|
+
previous = input.required(/* @ts-ignore */
|
|
1095
|
+
...(ngDevMode ? [{ debugName: "previous" }] : /* istanbul ignore next */ []));
|
|
1096
|
+
unit = input('pp', /* @ts-ignore */
|
|
1097
|
+
...(ngDevMode ? [{ debugName: "unit" }] : /* istanbul ignore next */ []));
|
|
1098
|
+
goodWhen = input('up', /* @ts-ignore */
|
|
1099
|
+
...(ngDevMode ? [{ debugName: "goodWhen" }] : /* istanbul ignore next */ []));
|
|
1100
|
+
/** Texto de comparación, visible y leído tras el valor. */
|
|
1101
|
+
comparisonLabel = input('vs. período anterior', /* @ts-ignore */
|
|
1102
|
+
...(ngDevMode ? [{ debugName: "comparisonLabel" }] : /* istanbul ignore next */ []));
|
|
1103
|
+
locale = inject(LOCALE_ID);
|
|
1104
|
+
delta = computed(() => {
|
|
1105
|
+
const diff = this.current() - this.previous();
|
|
1106
|
+
if (this.unit() === '%') {
|
|
1107
|
+
return this.previous() === 0 ? 0 : (diff / Math.abs(this.previous())) * 100;
|
|
1108
|
+
}
|
|
1109
|
+
return diff;
|
|
1110
|
+
}, /* @ts-ignore */
|
|
1111
|
+
...(ngDevMode ? [{ debugName: "delta" }] : /* istanbul ignore next */ []));
|
|
1112
|
+
direction = computed(() => {
|
|
1113
|
+
const delta = Math.round(this.delta() * 10) / 10;
|
|
1114
|
+
return delta > 0 ? 'up' : delta < 0 ? 'down' : 'flat';
|
|
1115
|
+
}, /* @ts-ignore */
|
|
1116
|
+
...(ngDevMode ? [{ debugName: "direction" }] : /* istanbul ignore next */ []));
|
|
1117
|
+
verdict = computed(() => {
|
|
1118
|
+
const direction = this.direction();
|
|
1119
|
+
if (direction === 'flat') {
|
|
1120
|
+
return 'neutral';
|
|
1121
|
+
}
|
|
1122
|
+
return direction === this.goodWhen() ? 'good' : 'bad';
|
|
1123
|
+
}, /* @ts-ignore */
|
|
1124
|
+
...(ngDevMode ? [{ debugName: "verdict" }] : /* istanbul ignore next */ []));
|
|
1125
|
+
arrow = computed(() => {
|
|
1126
|
+
const direction = this.direction();
|
|
1127
|
+
return direction === 'up' ? '▲' : direction === 'down' ? '▼' : '■';
|
|
1128
|
+
}, /* @ts-ignore */
|
|
1129
|
+
...(ngDevMode ? [{ debugName: "arrow" }] : /* istanbul ignore next */ []));
|
|
1130
|
+
text = computed(() => {
|
|
1131
|
+
const value = Math.round(this.delta() * 10) / 10;
|
|
1132
|
+
const sign = value > 0 ? '+' : '';
|
|
1133
|
+
const unit = this.unit() === 'pp' ? ' pp' : ' %';
|
|
1134
|
+
return `${sign}${formatNumber(value, this.locale, '1.1-1')}${unit}`;
|
|
1135
|
+
}, /* @ts-ignore */
|
|
1136
|
+
...(ngDevMode ? [{ debugName: "text" }] : /* istanbul ignore next */ []));
|
|
1137
|
+
srText = computed(() => {
|
|
1138
|
+
const direction = this.direction();
|
|
1139
|
+
const word = direction === 'up' ? 'Sube' : direction === 'down' ? 'Baja' : 'Sin cambio';
|
|
1140
|
+
return direction === 'flat'
|
|
1141
|
+
? `${word} ${this.comparisonLabel()}`
|
|
1142
|
+
: `${word} ${this.text()} ${this.comparisonLabel()}`;
|
|
1143
|
+
}, /* @ts-ignore */
|
|
1144
|
+
...(ngDevMode ? [{ debugName: "srText" }] : /* istanbul ignore next */ []));
|
|
1145
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.0", ngImport: i0, type: StatDelta, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1146
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "22.1.0", type: StatDelta, isStandalone: true, selector: "kf-stat-delta", inputs: { current: { classPropertyName: "current", publicName: "current", isSignal: true, isRequired: true, transformFunction: null }, previous: { classPropertyName: "previous", publicName: "previous", isSignal: true, isRequired: true, transformFunction: null }, unit: { classPropertyName: "unit", publicName: "unit", isSignal: true, isRequired: false, transformFunction: null }, goodWhen: { classPropertyName: "goodWhen", publicName: "goodWhen", isSignal: true, isRequired: false, transformFunction: null }, comparisonLabel: { classPropertyName: "comparisonLabel", publicName: "comparisonLabel", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0, template: "<span class=\"kf-stat-delta\" [class]=\"'kf-stat-delta kf-stat-delta--' + verdict()\">\n <span class=\"kf-stat-delta__arrow\" aria-hidden=\"true\">{{ arrow() }}</span>\n <span aria-hidden=\"true\">{{ text() }}</span>\n <small aria-hidden=\"true\">{{ comparisonLabel() }}</small>\n <span class=\"kf-sr-only\">{{ srText() }}</span>\n</span>\n", styles: [".kf-sr-only{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap;border:0}:host{display:inline-flex}.kf-stat-delta{position:relative;display:inline-flex;flex-wrap:wrap;align-items:center;gap:var(--kf-space-xs);font-size:var(--kf-font-size-caption);font-weight:600;font-variant-numeric:tabular-nums;color:var(--kf-chart-text-muted)}.kf-stat-delta--good{color:var(--kf-color-success-strong)}.kf-stat-delta--bad{color:var(--kf-color-error-strong)}.kf-stat-delta small{font-size:var(--kf-font-size-caption);font-weight:400;color:var(--kf-chart-text-muted)}.kf-stat-delta__arrow{font-size:.7em}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
1147
|
+
}
|
|
1148
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.0", ngImport: i0, type: StatDelta, decorators: [{
|
|
1149
|
+
type: Component,
|
|
1150
|
+
args: [{ selector: 'kf-stat-delta', changeDetection: ChangeDetectionStrategy.OnPush, template: "<span class=\"kf-stat-delta\" [class]=\"'kf-stat-delta kf-stat-delta--' + verdict()\">\n <span class=\"kf-stat-delta__arrow\" aria-hidden=\"true\">{{ arrow() }}</span>\n <span aria-hidden=\"true\">{{ text() }}</span>\n <small aria-hidden=\"true\">{{ comparisonLabel() }}</small>\n <span class=\"kf-sr-only\">{{ srText() }}</span>\n</span>\n", styles: [".kf-sr-only{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap;border:0}:host{display:inline-flex}.kf-stat-delta{position:relative;display:inline-flex;flex-wrap:wrap;align-items:center;gap:var(--kf-space-xs);font-size:var(--kf-font-size-caption);font-weight:600;font-variant-numeric:tabular-nums;color:var(--kf-chart-text-muted)}.kf-stat-delta--good{color:var(--kf-color-success-strong)}.kf-stat-delta--bad{color:var(--kf-color-error-strong)}.kf-stat-delta small{font-size:var(--kf-font-size-caption);font-weight:400;color:var(--kf-chart-text-muted)}.kf-stat-delta__arrow{font-size:.7em}\n"] }]
|
|
1151
|
+
}], propDecorators: { current: [{ type: i0.Input, args: [{ isSignal: true, alias: "current", required: true }] }], previous: [{ type: i0.Input, args: [{ isSignal: true, alias: "previous", required: true }] }], unit: [{ type: i0.Input, args: [{ isSignal: true, alias: "unit", required: false }] }], goodWhen: [{ type: i0.Input, args: [{ isSignal: true, alias: "goodWhen", required: false }] }], comparisonLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "comparisonLabel", required: false }] }] } });
|
|
1152
|
+
|
|
1153
|
+
/** Medidas del viewBox de `kf-sparkline`: 84 × 28 con 3 de margen. */
|
|
1154
|
+
const SPARKLINE_WIDTH = 84;
|
|
1155
|
+
const SPARKLINE_HEIGHT = 28;
|
|
1156
|
+
const PAD = 3;
|
|
1157
|
+
const round = (value) => Math.round(value * 10) / 10;
|
|
1158
|
+
/**
|
|
1159
|
+
* Geometría pura de la línea: una serie con valores de 0 a `max` en un
|
|
1160
|
+
* viewBox de 84 × 28. Un valor sobre `max` se dibuja al tope; con un solo
|
|
1161
|
+
* punto no hay trazo y el punto queda al centro. Devuelve `null` si la serie
|
|
1162
|
+
* no tiene ningún valor positivo (no hay nada que dibujar).
|
|
1163
|
+
*/
|
|
1164
|
+
function sparklineShape(values, max) {
|
|
1165
|
+
const finite = values.map((value) => (Number.isFinite(value) ? Math.max(0, value) : 0));
|
|
1166
|
+
if (finite.length === 0 || !(max > 0) || !finite.some((value) => value > 0)) {
|
|
1167
|
+
return null;
|
|
1168
|
+
}
|
|
1169
|
+
const inner = SPARKLINE_WIDTH - 2 * PAD;
|
|
1170
|
+
const count = finite.length;
|
|
1171
|
+
const points = finite.map((value, index) => ({
|
|
1172
|
+
x: round(count === 1 ? SPARKLINE_WIDTH / 2 : PAD + (index / (count - 1)) * inner),
|
|
1173
|
+
y: round(SPARKLINE_HEIGHT - PAD - (Math.min(value, max) / max) * (SPARKLINE_HEIGHT - 2 * PAD)),
|
|
1174
|
+
}));
|
|
1175
|
+
return {
|
|
1176
|
+
path: count === 1
|
|
1177
|
+
? ''
|
|
1178
|
+
: points.map((point, index) => `${index === 0 ? 'M' : 'L'}${point.x} ${point.y}`).join(' '),
|
|
1179
|
+
end: points[count - 1],
|
|
1180
|
+
baseline: SPARKLINE_HEIGHT - PAD,
|
|
1181
|
+
baseFrom: PAD,
|
|
1182
|
+
baseTo: SPARKLINE_WIDTH - PAD,
|
|
1183
|
+
};
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
/**
|
|
1187
|
+
* Línea de tendencia de 84 × 28 px para una celda de tabla o una tarjeta: base,
|
|
1188
|
+
* trazo y punto final destacado. La escala es el máximo de la propia serie; para
|
|
1189
|
+
* comparar varias filas se les pasa el mismo `scale` (el máximo común), así una
|
|
1190
|
+
* serie chica no parece grande. Sin ningún valor positivo no dibuja una línea
|
|
1191
|
+
* plana: muestra `emptyText` en su lugar, con el mismo ancho.
|
|
1192
|
+
*
|
|
1193
|
+
* Es una imagen con `ariaLabel`; el valor de cada punto no es enfocable, por lo
|
|
1194
|
+
* que la cifra resumen va escrita junto a ella.
|
|
1195
|
+
*
|
|
1196
|
+
* <kf-sparkline [values]="uso30d" [scale]="maximoComun"
|
|
1197
|
+
* [ariaLabel]="'Uso de los últimos 30 días de ' + cliente" emptyText="Sin uso" />
|
|
1198
|
+
*/
|
|
1199
|
+
class Sparkline {
|
|
1200
|
+
values = input.required(/* @ts-ignore */
|
|
1201
|
+
...(ngDevMode ? [{ debugName: "values" }] : /* istanbul ignore next */ []));
|
|
1202
|
+
ariaLabel = input.required(/* @ts-ignore */
|
|
1203
|
+
...(ngDevMode ? [{ debugName: "ariaLabel" }] : /* istanbul ignore next */ []));
|
|
1204
|
+
/** Máximo del eje; por defecto el de la propia serie. */
|
|
1205
|
+
scale = input(/* @ts-ignore */
|
|
1206
|
+
...(ngDevMode ? [undefined, { debugName: "scale" }] : /* istanbul ignore next */ []));
|
|
1207
|
+
/** Texto cuando la serie no tiene ningún valor positivo. */
|
|
1208
|
+
emptyText = input('Sin datos', /* @ts-ignore */
|
|
1209
|
+
...(ngDevMode ? [{ debugName: "emptyText" }] : /* istanbul ignore next */ []));
|
|
1210
|
+
width = SPARKLINE_WIDTH;
|
|
1211
|
+
height = SPARKLINE_HEIGHT;
|
|
1212
|
+
shape = computed(() => {
|
|
1213
|
+
const values = this.values();
|
|
1214
|
+
const own = Math.max(0, ...values.map((value) => (Number.isFinite(value) ? value : 0)));
|
|
1215
|
+
const scale = this.scale();
|
|
1216
|
+
return sparklineShape(values, scale !== undefined && scale > 0 ? scale : own);
|
|
1217
|
+
}, /* @ts-ignore */
|
|
1218
|
+
...(ngDevMode ? [{ debugName: "shape" }] : /* istanbul ignore next */ []));
|
|
1219
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.0", ngImport: i0, type: Sparkline, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1220
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1.0", type: Sparkline, isStandalone: true, selector: "kf-sparkline", inputs: { values: { classPropertyName: "values", publicName: "values", isSignal: true, isRequired: true, transformFunction: null }, ariaLabel: { classPropertyName: "ariaLabel", publicName: "ariaLabel", isSignal: true, isRequired: true, transformFunction: null }, scale: { classPropertyName: "scale", publicName: "scale", isSignal: true, isRequired: false, transformFunction: null }, emptyText: { classPropertyName: "emptyText", publicName: "emptyText", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0, template: "@if (shape(); as line) {\n <svg\n class=\"kf-sparkline__svg\"\n role=\"img\"\n [attr.aria-label]=\"ariaLabel()\"\n [attr.width]=\"width\"\n [attr.height]=\"height\"\n [attr.viewBox]=\"'0 0 ' + width + ' ' + height\"\n >\n <line\n class=\"kf-sparkline__base\"\n [attr.x1]=\"line.baseFrom\"\n [attr.x2]=\"line.baseTo\"\n [attr.y1]=\"line.baseline\"\n [attr.y2]=\"line.baseline\"\n />\n @if (line.path) {\n <path class=\"kf-sparkline__line\" [attr.d]=\"line.path\" />\n }\n <circle class=\"kf-sparkline__dot\" [attr.cx]=\"line.end.x\" [attr.cy]=\"line.end.y\" r=\"2.5\" />\n </svg>\n} @else {\n <span class=\"kf-sparkline__empty\" role=\"img\" [attr.aria-label]=\"ariaLabel() + ': ' + emptyText()\">\n {{ emptyText() }}\n </span>\n}\n", styles: [":host{display:inline-block;flex:none;vertical-align:middle}.kf-sparkline__svg{display:block}.kf-sparkline__base{stroke:var(--kf-chart-grid);stroke-width:1;opacity:.6}.kf-sparkline__line{fill:none;stroke:var(--kf-chart-series);stroke-width:1.75;stroke-linejoin:round;stroke-linecap:round}.kf-sparkline__dot{fill:var(--kf-chart-series)}.kf-sparkline__empty{display:block;width:84px;font-size:var(--kf-font-size-caption);font-style:italic;color:var(--kf-chart-text-muted)}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
1221
|
+
}
|
|
1222
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.0", ngImport: i0, type: Sparkline, decorators: [{
|
|
1223
|
+
type: Component,
|
|
1224
|
+
args: [{ selector: 'kf-sparkline', changeDetection: ChangeDetectionStrategy.OnPush, template: "@if (shape(); as line) {\n <svg\n class=\"kf-sparkline__svg\"\n role=\"img\"\n [attr.aria-label]=\"ariaLabel()\"\n [attr.width]=\"width\"\n [attr.height]=\"height\"\n [attr.viewBox]=\"'0 0 ' + width + ' ' + height\"\n >\n <line\n class=\"kf-sparkline__base\"\n [attr.x1]=\"line.baseFrom\"\n [attr.x2]=\"line.baseTo\"\n [attr.y1]=\"line.baseline\"\n [attr.y2]=\"line.baseline\"\n />\n @if (line.path) {\n <path class=\"kf-sparkline__line\" [attr.d]=\"line.path\" />\n }\n <circle class=\"kf-sparkline__dot\" [attr.cx]=\"line.end.x\" [attr.cy]=\"line.end.y\" r=\"2.5\" />\n </svg>\n} @else {\n <span class=\"kf-sparkline__empty\" role=\"img\" [attr.aria-label]=\"ariaLabel() + ': ' + emptyText()\">\n {{ emptyText() }}\n </span>\n}\n", styles: [":host{display:inline-block;flex:none;vertical-align:middle}.kf-sparkline__svg{display:block}.kf-sparkline__base{stroke:var(--kf-chart-grid);stroke-width:1;opacity:.6}.kf-sparkline__line{fill:none;stroke:var(--kf-chart-series);stroke-width:1.75;stroke-linejoin:round;stroke-linecap:round}.kf-sparkline__dot{fill:var(--kf-chart-series)}.kf-sparkline__empty{display:block;width:84px;font-size:var(--kf-font-size-caption);font-style:italic;color:var(--kf-chart-text-muted)}\n"] }]
|
|
1225
|
+
}], propDecorators: { values: [{ type: i0.Input, args: [{ isSignal: true, alias: "values", required: true }] }], ariaLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "ariaLabel", required: true }] }], scale: [{ type: i0.Input, args: [{ isSignal: true, alias: "scale", required: false }] }], emptyText: [{ type: i0.Input, args: [{ isSignal: true, alias: "emptyText", required: false }] }] } });
|
|
1226
|
+
|
|
1227
|
+
/*
|
|
1228
|
+
* Public API Surface of ui/charts — entry point secundario, `@kaufmann-lab/ui/charts`.
|
|
1229
|
+
*
|
|
1230
|
+
* Sistema de gráficos del ecosistema: paneles, barras ordenadas, barra apilada,
|
|
1231
|
+
* medidor, series de barras, serie temporal, línea de tendencia y variación.
|
|
1232
|
+
* SVG y HTML propios, sin dependencia externa; los colores salen de los tokens
|
|
1233
|
+
* `--kf-chart-*` (`tokens/base.css`), que siguen al tema.
|
|
1234
|
+
*
|
|
1235
|
+
* Es un entry point propio por organización (regla 2 de `ENTRY-POINTS.md`): son
|
|
1236
|
+
* piezas de UNA misma preocupación, los gráficos, con tokens y reglas comunes
|
|
1237
|
+
* (Top-N medido, eje completo de la ventana, valor siempre escrito). Importa
|
|
1238
|
+
* piezas base de `'@kaufmann-lab/ui/core'` (nunca desde la raíz
|
|
1239
|
+
* `'@kaufmann-lab/ui'`) y no se reexporta desde la raíz: se importa de forma
|
|
1240
|
+
* explícita desde `'@kaufmann-lab/ui/charts'`.
|
|
1241
|
+
*/
|
|
1242
|
+
|
|
1243
|
+
/**
|
|
1244
|
+
* Generated bundle index. Do not edit.
|
|
1245
|
+
*/
|
|
1246
|
+
|
|
1247
|
+
export { BarSeries, ChartLegend, ChartPanel, ChartTableDialogView, KfChartTableDialog, Meter, RankedBars, STACKED_BAR_OTHER_ID, Sparkline, StackedBar, StatDelta, TimeBars, WidgetGrid };
|
|
1248
|
+
//# sourceMappingURL=kaufmann-lab-ui-charts.mjs.map
|