@aquera/nile-visualization 2.9.50 → 2.9.53

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.
@@ -10,6 +10,8 @@ export type KpiNumberSystem = 'indian' | 'international';
10
10
  export type KpiInfoPlacement = 'top-right' | 'center-right' | 'bottom-right' | 'top-left' | 'center-left' | 'bottom-left';
11
11
  /** How compact titles handle an oversized word: `'ellipsis'` cuts it with `…`, `'break'` splits it. */
12
12
  export type KpiTitleOverflow = 'ellipsis' | 'break';
13
+ /** Where the compact variant places its sparkline: `'bottom'` (full-bleed strip) or `'right'` (small chart beside the value). */
14
+ export type KpiSparklinePosition = 'bottom' | 'right';
13
15
  /** `chart` slice for `<nile-kpi-chart>.config` (discriminated by `type: 'kpi'`). */
14
16
  export interface ChartKpiSeparatedPayload {
15
17
  type: 'kpi';
@@ -86,6 +88,8 @@ export interface ChartKpiSeparatedPayload {
86
88
  tooltipEnabled?: boolean;
87
89
  /** How the compact title handles text that doesn't fit; see `KpiTitleOverflow`. */
88
90
  titleOverflow?: KpiTitleOverflow;
91
+ /** Compact variant: sparkline below the value or to its right (default: 'bottom'). */
92
+ sparklinePosition?: KpiSparklinePosition;
89
93
  /** Accent bar colour for the 'accent' variant (default: brand blue). */
90
94
  accentColor?: string;
91
95
  cardBackground?: string;
@@ -147,6 +151,51 @@ export interface KpiConfig {
147
151
  description?: string;
148
152
  sparkline?: number[];
149
153
  }
154
+ /** Every CSS part `nile-kpi-chart` renders; `nile-chart` re-exports them as `kpi-<part>`. */
155
+ export declare const KPI_CHART_PARTS: readonly ["base", "loading", "header", "label-tooltip", "label", "label-text", "header-controls", "header-lead", "header-actions", "trend-row", "trend-tooltip", "trend", "trend-up", "trend-down", "trend-neutral", "trend-arrow", "trend-value", "trend-label", "value-row", "value-group", "value-tooltip", "value", "prefix", "suffix", "value-info-tooltip", "value-info", "value-info-icon", "forecast", "forecast-glyph", "forecast-value", "forecast-prefix", "forecast-suffix", "forecast-label", "description-tooltip", "description", "sparkline", "gauge-slot", "gauge"];
156
+ /**
157
+ * @tag nile-kpi-chart
158
+ * @summary A KPI tile: label, value, trend, optional forecast, description, sparkline or gauge.
159
+ *
160
+ * @csspart base - The tile body (every variant).
161
+ * @csspart loading - The loading message (`loading`).
162
+ * @csspart header - The header row: label plus header controls.
163
+ * @csspart label-tooltip - The tooltip wrapping the label (shown when truncated).
164
+ * @csspart label - The label paragraph.
165
+ * @csspart label-text - The label text inside `label`.
166
+ * @csspart header-controls - The trailing header cluster (compact trend, `header-lead`, `header-actions`).
167
+ * @csspart header-lead - Wrapper of the `header-lead` slot.
168
+ * @csspart header-actions - Wrapper of the `header-actions` slot.
169
+ * @csspart trend-row - The compact variant's trend row under the header.
170
+ * @csspart trend-tooltip - The tooltip wrapping the trend badge.
171
+ * @csspart trend - The trend badge. Also carries `trend-up`, `trend-down` or `trend-neutral`.
172
+ * @csspart trend-up - The trend badge when the trend is up.
173
+ * @csspart trend-down - The trend badge when the trend is down.
174
+ * @csspart trend-neutral - The trend badge when the trend is neutral.
175
+ * @csspart trend-arrow - The arrow icon in the trend badge.
176
+ * @csspart trend-value - The percentage in the trend badge.
177
+ * @csspart trend-label - The trend label text (`trend-label`).
178
+ * @csspart value-row - The row holding the value (and the trend, outside compact).
179
+ * @csspart value-group - The value plus its info icon.
180
+ * @csspart value-tooltip - The tooltip wrapping an abbreviated value.
181
+ * @csspart value - The main value heading.
182
+ * @csspart prefix - The value prefix (`prefix`).
183
+ * @csspart suffix - The value suffix (`suffix`).
184
+ * @csspart value-info-tooltip - The tooltip wrapping the value info icon (`value-info`).
185
+ * @csspart value-info - The value info icon button.
186
+ * @csspart value-info-icon - The `nile-glyph` inside `value-info`.
187
+ * @csspart forecast - The forecast line (`forecast-value`).
188
+ * @csspart forecast-glyph - The forecast icon.
189
+ * @csspart forecast-value - The forecast number.
190
+ * @csspart forecast-prefix - The prefix inside the forecast.
191
+ * @csspart forecast-suffix - The suffix inside the forecast.
192
+ * @csspart forecast-label - The forecast label (`forecast-label`).
193
+ * @csspart description-tooltip - The tooltip wrapping the description.
194
+ * @csspart description - The description paragraph.
195
+ * @csspart sparkline - The sparkline container.
196
+ * @csspart gauge-slot - The gauge area (`variant="gauge"`).
197
+ * @csspart gauge - The gauge chart container.
198
+ */
150
199
  export declare class NileKpiChart extends NileElement {
151
200
  static styles: CSSResultGroup;
152
201
  private _hc;
@@ -272,6 +321,8 @@ export declare class NileKpiChart extends NileElement {
272
321
  tooltipEnabled: boolean;
273
322
  /** How the compact title handles text that doesn't fit; see `KpiTitleOverflow`. */
274
323
  titleOverflow: KpiTitleOverflow;
324
+ /** Compact variant: `'bottom'` runs the sparkline along the card bottom; `'right'` gives a small card with the sparkline beside the value. */
325
+ sparklinePosition: KpiSparklinePosition;
275
326
  cardBackground: string;
276
327
  cardBorderColor: string;
277
328
  cardBorderWidth: string | number;
@@ -356,6 +407,8 @@ export declare class NileKpiChart extends NileElement {
356
407
  * nothing is half-cut. Re-evaluated only when the card's size changes, so hiding them
357
408
  * (which frees space) can't make it flip back and forth.
358
409
  */
410
+ private get _sparkRight();
411
+ private get _sparkBleeds();
359
412
  private _fitDescription;
360
413
  /**
361
414
  * True when `el` shows less than its full text. Chrome hides -webkit-line-clamp lines without reporting overflow, so the clamp is lifted for one measurement.
@@ -16,6 +16,90 @@ function ensureTooltipStyles() {
16
16
  document.head.appendChild(style);
17
17
  _tooltipStylesInjected = true;
18
18
  }
19
+ /** Every CSS part `nile-kpi-chart` renders; `nile-chart` re-exports them as `kpi-<part>`. */
20
+ export const KPI_CHART_PARTS = [
21
+ 'base',
22
+ 'loading',
23
+ 'header',
24
+ 'label-tooltip',
25
+ 'label',
26
+ 'label-text',
27
+ 'header-controls',
28
+ 'header-lead',
29
+ 'header-actions',
30
+ 'trend-row',
31
+ 'trend-tooltip',
32
+ 'trend',
33
+ 'trend-up',
34
+ 'trend-down',
35
+ 'trend-neutral',
36
+ 'trend-arrow',
37
+ 'trend-value',
38
+ 'trend-label',
39
+ 'value-row',
40
+ 'value-group',
41
+ 'value-tooltip',
42
+ 'value',
43
+ 'prefix',
44
+ 'suffix',
45
+ 'value-info-tooltip',
46
+ 'value-info',
47
+ 'value-info-icon',
48
+ 'forecast',
49
+ 'forecast-glyph',
50
+ 'forecast-value',
51
+ 'forecast-prefix',
52
+ 'forecast-suffix',
53
+ 'forecast-label',
54
+ 'description-tooltip',
55
+ 'description',
56
+ 'sparkline',
57
+ 'gauge-slot',
58
+ 'gauge',
59
+ ];
60
+ /**
61
+ * @tag nile-kpi-chart
62
+ * @summary A KPI tile: label, value, trend, optional forecast, description, sparkline or gauge.
63
+ *
64
+ * @csspart base - The tile body (every variant).
65
+ * @csspart loading - The loading message (`loading`).
66
+ * @csspart header - The header row: label plus header controls.
67
+ * @csspart label-tooltip - The tooltip wrapping the label (shown when truncated).
68
+ * @csspart label - The label paragraph.
69
+ * @csspart label-text - The label text inside `label`.
70
+ * @csspart header-controls - The trailing header cluster (compact trend, `header-lead`, `header-actions`).
71
+ * @csspart header-lead - Wrapper of the `header-lead` slot.
72
+ * @csspart header-actions - Wrapper of the `header-actions` slot.
73
+ * @csspart trend-row - The compact variant's trend row under the header.
74
+ * @csspart trend-tooltip - The tooltip wrapping the trend badge.
75
+ * @csspart trend - The trend badge. Also carries `trend-up`, `trend-down` or `trend-neutral`.
76
+ * @csspart trend-up - The trend badge when the trend is up.
77
+ * @csspart trend-down - The trend badge when the trend is down.
78
+ * @csspart trend-neutral - The trend badge when the trend is neutral.
79
+ * @csspart trend-arrow - The arrow icon in the trend badge.
80
+ * @csspart trend-value - The percentage in the trend badge.
81
+ * @csspart trend-label - The trend label text (`trend-label`).
82
+ * @csspart value-row - The row holding the value (and the trend, outside compact).
83
+ * @csspart value-group - The value plus its info icon.
84
+ * @csspart value-tooltip - The tooltip wrapping an abbreviated value.
85
+ * @csspart value - The main value heading.
86
+ * @csspart prefix - The value prefix (`prefix`).
87
+ * @csspart suffix - The value suffix (`suffix`).
88
+ * @csspart value-info-tooltip - The tooltip wrapping the value info icon (`value-info`).
89
+ * @csspart value-info - The value info icon button.
90
+ * @csspart value-info-icon - The `nile-glyph` inside `value-info`.
91
+ * @csspart forecast - The forecast line (`forecast-value`).
92
+ * @csspart forecast-glyph - The forecast icon.
93
+ * @csspart forecast-value - The forecast number.
94
+ * @csspart forecast-prefix - The prefix inside the forecast.
95
+ * @csspart forecast-suffix - The suffix inside the forecast.
96
+ * @csspart forecast-label - The forecast label (`forecast-label`).
97
+ * @csspart description-tooltip - The tooltip wrapping the description.
98
+ * @csspart description - The description paragraph.
99
+ * @csspart sparkline - The sparkline container.
100
+ * @csspart gauge-slot - The gauge area (`variant="gauge"`).
101
+ * @csspart gauge - The gauge chart container.
102
+ */
19
103
  let NileKpiChart = class NileKpiChart extends NileElement {
20
104
  constructor() {
21
105
  super(...arguments);
@@ -140,6 +224,8 @@ let NileKpiChart = class NileKpiChart extends NileElement {
140
224
  this.tooltipEnabled = true;
141
225
  /** How the compact title handles text that doesn't fit; see `KpiTitleOverflow`. */
142
226
  this.titleOverflow = 'ellipsis';
227
+ /** Compact variant: `'bottom'` runs the sparkline along the card bottom; `'right'` gives a small card with the sparkline beside the value. */
228
+ this.sparklinePosition = 'bottom';
143
229
  // ── Card chrome ──
144
230
  this.cardBackground = '';
145
231
  this.cardBorderColor = '';
@@ -608,6 +694,8 @@ let NileKpiChart = class NileKpiChart extends NileElement {
608
694
  this.tooltipEnabled = c.tooltipEnabled;
609
695
  if (c.titleOverflow !== undefined)
610
696
  this.titleOverflow = c.titleOverflow;
697
+ if (c.sparklinePosition !== undefined)
698
+ this.sparklinePosition = c.sparklinePosition;
611
699
  if (c.accentColor !== undefined)
612
700
  this.accentColor = c.accentColor;
613
701
  if (c.cardBackground !== undefined)
@@ -740,7 +828,7 @@ let NileKpiChart = class NileKpiChart extends NileElement {
740
828
  return;
741
829
  }
742
830
  const sparklineProps = ['sparkline', 'sparklineColor', 'sparklineHeight', 'sparklineLineWidth',
743
- 'sparklineType', 'sparklineFillOpacity', 'sparklineMarkers', 'options', 'trendDirection', 'variant'];
831
+ 'sparklineType', 'sparklineFillOpacity', 'sparklineMarkers', 'options', 'trendDirection', 'variant', 'sparklinePosition'];
744
832
  const spark = this.sparklineChart;
745
833
  const sparkStale = !!spark && spark.renderTo !== this.sparklineContainer;
746
834
  if (sparkStale || sparklineProps.some(p => changedProperties.has(p))) {
@@ -924,7 +1012,7 @@ let NileKpiChart = class NileKpiChart extends NileElement {
924
1012
  // Compact bleeds to the card edge, so keep the lowest point ~20px above the bottom: flat or low
925
1013
  // data then starts well above the edge instead of sitting on it (capped at half the height).
926
1014
  let padBottom = pad;
927
- if (this.variant === 'compact' && span > 0) {
1015
+ if (this._sparkBleeds && span > 0) {
928
1016
  const h = this.sparklineContainer?.clientHeight || 40;
929
1017
  const f = Math.min(0.5, 20 / h);
930
1018
  padBottom = ((dMax + pad - dMin) * f) / (1 - f);
@@ -933,7 +1021,7 @@ let NileKpiChart = class NileKpiChart extends NileElement {
933
1021
  areaThreshold = dMin - padBottom; // area fills from the line down to the plot bottom
934
1022
  }
935
1023
  // Compact sparklines bleed to the card edge, so the fill keeps a faint tint all the way down instead of fading to nothing.
936
- const bottomAlpha = this.variant === 'compact'
1024
+ const bottomAlpha = this._sparkBleeds
937
1025
  ? Math.round(Math.min(1, Math.max(0, this.sparklineFillOpacity)) * 255 * 0.4).toString(16).padStart(2, '0')
938
1026
  : '00';
939
1027
  const fillColor = isAreaLike
@@ -974,10 +1062,10 @@ let NileKpiChart = class NileKpiChart extends NileElement {
974
1062
  };
975
1063
  const defaults = {
976
1064
  // Compact sparklines run full-bleed: no bottom margin and no x-axis padding, so the fill reaches every card edge.
977
- chart: { type: seriesType, height: this.sparklineHeight, margin: this.variant === 'compact' && !isBarLike && !isScatter ? [2, 0, 0, 0] : [2, 0, 2, 0], backgroundColor: 'transparent', animation: false },
1065
+ chart: { type: seriesType, height: this.sparklineHeight, margin: this._sparkBleeds && !isBarLike && !isScatter ? [2, 0, 0, 0] : [2, 0, 2, 0], backgroundColor: 'transparent', animation: false },
978
1066
  title: { text: undefined },
979
1067
  subtitle: { text: undefined },
980
- xAxis: this.variant === 'compact' && !isBarLike && !isScatter ? { visible: false, minPadding: 0, maxPadding: 0 } : { visible: false },
1068
+ xAxis: this._sparkBleeds && !isBarLike && !isScatter ? { visible: false, minPadding: 0, maxPadding: 0 } : { visible: false },
981
1069
  yAxis: yAxisOptions,
982
1070
  legend: { enabled: false },
983
1071
  tooltip: { enabled: false },
@@ -1157,6 +1245,12 @@ let NileKpiChart = class NileKpiChart extends NileElement {
1157
1245
  * nothing is half-cut. Re-evaluated only when the card's size changes, so hiding them
1158
1246
  * (which frees space) can't make it flip back and forth.
1159
1247
  */
1248
+ get _sparkRight() {
1249
+ return this.variant === 'compact' && this.sparklinePosition === 'right';
1250
+ }
1251
+ get _sparkBleeds() {
1252
+ return this.variant === 'compact' && !this._sparkRight;
1253
+ }
1160
1254
  _fitDescription(force = false) {
1161
1255
  const kpi = this.shadowRoot?.querySelector('.kpi');
1162
1256
  if (!kpi || this.variant === 'gauge')
@@ -1254,6 +1348,7 @@ let NileKpiChart = class NileKpiChart extends NileElement {
1254
1348
  return nothing;
1255
1349
  const [vertical, side] = (typeof this.valueInfoPlacement === 'string' ? this.valueInfoPlacement : 'top-right').split('-');
1256
1350
  return html `<nile-lite-tooltip
1351
+ part="value-info-tooltip"
1257
1352
  class="kpi-info-tip kpi-info--${vertical === 'bottom' || vertical === 'center' ? vertical : 'top'} kpi-info--${side === 'left' ? 'left' : 'right'}"
1258
1353
  content=${this.valueInfo}
1259
1354
  placement="top"
@@ -1264,6 +1359,7 @@ let NileKpiChart = class NileKpiChart extends NileElement {
1264
1359
  tabindex="0"
1265
1360
  aria-label=${this.valueInfo}
1266
1361
  ><nile-glyph
1362
+ part="value-info-icon"
1267
1363
  name=${this.valueInfoIcon || 'ng-info-circle'}
1268
1364
  method=${this.valueInfoIconMethod || 'stroke'}
1269
1365
  size=${ifDefined(this.valueInfoIconSize === '' || this.valueInfoIconSize == null ? undefined : this.valueInfoIconSize)}
@@ -1302,20 +1398,21 @@ let NileKpiChart = class NileKpiChart extends NileElement {
1302
1398
  const dir = this.trendDirection;
1303
1399
  const formatted = Math.abs(this.trendValue).toFixed(1) + '%';
1304
1400
  const trendAriaLabel = `Trend ${dir === 'up' ? 'up' : dir === 'down' ? 'down' : 'neutral'} ${formatted}${this.trendLabel ? ' ' + this.trendLabel : ''}`.trim();
1305
- return html `<nile-lite-tooltip class="kpi-tip" data-kpi-tip="trend" content=${this._trendTooltipText()} placement="top" disabled><span
1401
+ return html `<nile-lite-tooltip class="kpi-tip" part="trend-tooltip" data-kpi-tip="trend" content=${this._trendTooltipText()} placement="top" disabled><span
1306
1402
  class="kpi-trend kpi-trend--${dir}"
1403
+ part="trend trend-${dir}"
1307
1404
  tabindex="0"
1308
1405
  role="button"
1309
1406
  aria-label=${trendAriaLabel}
1310
1407
  >
1311
- <span class="kpi-trend-arrow">
1408
+ <span class="kpi-trend-arrow" part="trend-arrow">
1312
1409
  ${dir === 'up'
1313
1410
  ? html `<svg viewBox="0 0 12 12"><path d="M6 2.5l4 5H2z"/></svg>`
1314
1411
  : dir === 'down'
1315
1412
  ? html `<svg viewBox="0 0 12 12"><path d="M6 9.5l4-5H2z"/></svg>`
1316
1413
  : html `<svg viewBox="0 0 12 12"><path d="M2 6.5h8" stroke="currentColor" stroke-width="1.5" fill="none"/></svg>`}
1317
1414
  </span>
1318
- <span class="kpi-trend-value">${formatted}</span>${this.trendLabel ? html ` <span class="kpi-trend-label">${this.trendLabel}</span>` : nothing}
1415
+ <span class="kpi-trend-value" part="trend-value">${formatted}</span>${this.trendLabel ? html ` <span class="kpi-trend-label" part="trend-label">${this.trendLabel}</span>` : nothing}
1319
1416
  </span></nile-lite-tooltip>`;
1320
1417
  }
1321
1418
  /**
@@ -1334,12 +1431,12 @@ let NileKpiChart = class NileKpiChart extends NileElement {
1334
1431
  + (this.forecastLabel ? ` ${this.forecastLabel}` : '');
1335
1432
  return html `
1336
1433
  <p class="kpi-forecast" part="forecast" aria-label=${spoken}>
1337
- <span class="kpi-forecast-glyph" aria-hidden="true">
1434
+ <span class="kpi-forecast-glyph" part="forecast-glyph" aria-hidden="true">
1338
1435
  <svg viewBox="0 0 12 12"><path d="M6 0l1.1 3.4L10.5 4.5 7.1 5.6 6 9 4.9 5.6 1.5 4.5 4.9 3.4z"/></svg>
1339
1436
  </span>
1340
- <span class="kpi-forecast-value"
1341
- >${approx}${this.prefix ? html `<span class="kpi-prefix">${this.prefix}</span>` : nothing}${shown}${this.suffix ? html `<span class="kpi-suffix">${this.suffix}</span>` : nothing}</span
1342
- >${this.forecastLabel ? html `<span class="kpi-forecast-label">${this.forecastLabel}</span>` : nothing}
1437
+ <span class="kpi-forecast-value" part="forecast-value"
1438
+ >${approx}${this.prefix ? html `<span class="kpi-prefix" part="forecast-prefix">${this.prefix}</span>` : nothing}${shown}${this.suffix ? html `<span class="kpi-suffix" part="forecast-suffix">${this.suffix}</span>` : nothing}</span
1439
+ >${this.forecastLabel ? html `<span class="kpi-forecast-label" part="forecast-label">${this.forecastLabel}</span>` : nothing}
1343
1440
  </p>
1344
1441
  `;
1345
1442
  }
@@ -1368,21 +1465,22 @@ let NileKpiChart = class NileKpiChart extends NileElement {
1368
1465
  * (see the `has-header-*` rules in the stylesheet).
1369
1466
  */
1370
1467
  renderHeaderRow(extra, trendRow) {
1371
- return html `<div class="kpi-header">
1372
- ${this.label ? html `<nile-lite-tooltip class="kpi-tip" data-kpi-tip="label" content=${this.label} placement="top" disabled><p
1468
+ return html `<div class="kpi-header" part="header">
1469
+ ${this.label ? html `<nile-lite-tooltip class="kpi-tip" part="label-tooltip" data-kpi-tip="label" content=${this.label} placement="top" disabled><p
1373
1470
  class="kpi-label"
1471
+ part="label"
1374
1472
  tabindex="0"
1375
- ><span class="kpi-label-text">${this.label}</span></p></nile-lite-tooltip>` : nothing}
1376
- <div class="kpi-header-controls">
1473
+ ><span class="kpi-label-text" part="label-text">${this.label}</span></p></nile-lite-tooltip>` : nothing}
1474
+ <div class="kpi-header-controls" part="header-controls">
1377
1475
  ${extra ?? nothing}
1378
- <span class="kpi-header-lead"><slot name="header-lead" @slotchange=${this._onHeaderSlotChange}></slot></span>
1379
- <span class="kpi-header-actions"><slot name="header-actions" @slotchange=${this._onHeaderSlotChange}></slot></span>
1476
+ <span class="kpi-header-lead" part="header-lead"><slot name="header-lead" @slotchange=${this._onHeaderSlotChange}></slot></span>
1477
+ <span class="kpi-header-actions" part="header-actions"><slot name="header-actions" @slotchange=${this._onHeaderSlotChange}></slot></span>
1380
1478
  </div>
1381
- </div>${trendRow ? html `<div class="kpi-trend-row">${trendRow}</div>` : nothing}`;
1479
+ </div>${trendRow ? html `<div class="kpi-trend-row" part="trend-row">${trendRow}</div>` : nothing}`;
1382
1480
  }
1383
1481
  render() {
1384
1482
  if (this.loading) {
1385
- return html `<div class="chart-loading">${this.loadingText}</div>`;
1483
+ return html `<div class="chart-loading" part="loading">${this.loadingText}</div>`;
1386
1484
  }
1387
1485
  const isGauge = this.variant === 'gauge';
1388
1486
  const rawNum = this.parseNumericValue(this.value);
@@ -1392,44 +1490,49 @@ let NileKpiChart = class NileKpiChart extends NileElement {
1392
1490
  const infoLeft = typeof this.valueInfoPlacement === 'string' && this.valueInfoPlacement.endsWith('-left');
1393
1491
  const valueEl = html `<h2
1394
1492
  class="kpi-value"
1493
+ part="value"
1395
1494
  tabindex=${showTooltip ? '0' : nothing}
1396
1495
  >
1397
- ${this.prefix ? html `<span class="kpi-prefix">${this.prefix}</span>` : nothing}${displayValue}${this.suffix ? html `<span class="kpi-suffix">${this.suffix}</span>` : nothing}
1496
+ ${this.prefix ? html `<span class="kpi-prefix" part="prefix">${this.prefix}</span>` : nothing}${displayValue}${this.suffix ? html `<span class="kpi-suffix" part="suffix">${this.suffix}</span>` : nothing}
1398
1497
  </h2>`;
1399
1498
  if (this.variant === 'compact') {
1499
+ const sparkRight = this._sparkRight;
1400
1500
  return html `
1401
- <div class="kpi kpi--compact">
1501
+ <div class="kpi kpi--compact" part="base">
1402
1502
  ${this.renderHeaderRow(this.renderTrend(), this.renderTrend())}
1403
1503
 
1404
- <div class="kpi-value-row">
1405
- <span class="kpi-value-group">
1504
+ <div class="kpi-value-row" part="value-row">
1505
+ <span class="kpi-value-group" part="value-group">
1406
1506
  ${infoLeft ? this.renderValueInfo() : nothing}
1407
1507
  ${showTooltip
1408
- ? html `<nile-lite-tooltip class="kpi-tip" content=${this._valueTooltipText()} placement="top" ?disabled=${!this.tooltipEnabled}>${valueEl}</nile-lite-tooltip>`
1508
+ ? html `<nile-lite-tooltip class="kpi-tip" part="value-tooltip" content=${this._valueTooltipText()} placement="top" ?disabled=${!this.tooltipEnabled}>${valueEl}</nile-lite-tooltip>`
1409
1509
  : valueEl}
1410
1510
  ${infoLeft ? nothing : this.renderValueInfo()}
1411
1511
  </span>
1512
+ ${sparkRight && this.sparkline.length ? html `<div class="kpi-sparkline" part="sparkline"></div>` : nothing}
1412
1513
  </div>
1413
1514
 
1414
1515
  ${this.renderForecast()}
1415
1516
 
1416
- ${this.description ? html `<nile-lite-tooltip class="kpi-tip" data-kpi-tip="description" content=${this.description} placement="top" disabled><p
1517
+ ${this.description ? html `<nile-lite-tooltip class="kpi-tip" part="description-tooltip" data-kpi-tip="description" content=${this.description} placement="top" disabled><p
1417
1518
  class="kpi-description"
1519
+ part="description"
1418
1520
  tabindex="0"
1419
1521
  >${this.description}</p></nile-lite-tooltip>` : nothing}
1420
1522
 
1421
- ${this.sparkline.length ? html `<div class="kpi-sparkline"></div>` : nothing}
1523
+ ${!sparkRight && this.sparkline.length ? html `<div class="kpi-sparkline" part="sparkline"></div>` : nothing}
1422
1524
  </div>
1423
1525
  `;
1424
1526
  }
1425
1527
  return html `
1426
- <div class="kpi ${isGauge ? 'kpi--gauge' : ''}">
1528
+ <div class="kpi ${isGauge ? 'kpi--gauge' : ''}" part="base">
1427
1529
  ${this.renderHeaderRow()}
1428
1530
 
1429
1531
  ${isGauge ? html `
1430
- <div class="kpi-gauge-slot">
1532
+ <div class="kpi-gauge-slot" part="gauge-slot">
1431
1533
  <div
1432
1534
  class="kpi-gauge-container"
1535
+ part="gauge"
1433
1536
  tabindex="0"
1434
1537
  role="img"
1435
1538
  aria-label=${this.getTooltipContent()}
@@ -1442,12 +1545,12 @@ let NileKpiChart = class NileKpiChart extends NileElement {
1442
1545
  </div>
1443
1546
  ` : nothing}
1444
1547
 
1445
- <div class="kpi-value-row">
1548
+ <div class="kpi-value-row" part="value-row">
1446
1549
  ${!isGauge ? html `
1447
- <span class="kpi-value-group">
1550
+ <span class="kpi-value-group" part="value-group">
1448
1551
  ${infoLeft ? this.renderValueInfo() : nothing}
1449
1552
  ${showTooltip
1450
- ? html `<nile-lite-tooltip class="kpi-tip" content=${this._valueTooltipText()} placement="top" ?disabled=${!this.tooltipEnabled}>${valueEl}</nile-lite-tooltip>`
1553
+ ? html `<nile-lite-tooltip class="kpi-tip" part="value-tooltip" content=${this._valueTooltipText()} placement="top" ?disabled=${!this.tooltipEnabled}>${valueEl}</nile-lite-tooltip>`
1451
1554
  : valueEl}
1452
1555
  ${infoLeft ? nothing : this.renderValueInfo()}
1453
1556
  </span>
@@ -1459,12 +1562,13 @@ let NileKpiChart = class NileKpiChart extends NileElement {
1459
1562
 
1460
1563
  ${this.renderForecast()}
1461
1564
 
1462
- ${this.description ? html `<nile-lite-tooltip class="kpi-tip" data-kpi-tip="description" content=${this.description} placement="top" disabled><p
1565
+ ${this.description ? html `<nile-lite-tooltip class="kpi-tip" part="description-tooltip" data-kpi-tip="description" content=${this.description} placement="top" disabled><p
1463
1566
  class="kpi-description"
1567
+ part="description"
1464
1568
  tabindex="0"
1465
1569
  >${this.description}</p></nile-lite-tooltip>` : nothing}
1466
1570
 
1467
- ${this.sparkline.length && !isGauge ? html `<div class="kpi-sparkline"></div>` : nothing}
1571
+ ${this.sparkline.length && !isGauge ? html `<div class="kpi-sparkline" part="sparkline"></div>` : nothing}
1468
1572
  </div>
1469
1573
  `;
1470
1574
  }
@@ -1620,6 +1724,9 @@ __decorate([
1620
1724
  __decorate([
1621
1725
  property({ type: String, attribute: 'title-overflow', reflect: true })
1622
1726
  ], NileKpiChart.prototype, "titleOverflow", void 0);
1727
+ __decorate([
1728
+ property({ type: String, attribute: 'sparkline-position', reflect: true })
1729
+ ], NileKpiChart.prototype, "sparklinePosition", void 0);
1623
1730
  __decorate([
1624
1731
  property({ type: String, attribute: 'card-background' })
1625
1732
  ], NileKpiChart.prototype, "cardBackground", void 0);
@@ -1 +1,2 @@
1
1
  import './nile-kpi-chart';
2
+ import '../nile-chart/nile-chart';
@@ -1,6 +1,8 @@
1
1
  /** Tests for <nile-kpi-chart>: sparkline tooltip placement, compact title overflow, sparkline sizing. */
2
2
  import { expect, fixture, html } from '@open-wc/testing';
3
3
  import './nile-kpi-chart';
4
+ import { KPI_CHART_PARTS } from './nile-kpi-chart';
5
+ import '../nile-chart/nile-chart';
4
6
  const LONG = '8 accounts waiting for review across all regions';
5
7
  describe('NileKpiChart sparkline tooltip placement', () => {
6
8
  let el;
@@ -315,6 +317,89 @@ describe('NileKpiChart title overflow', () => {
315
317
  });
316
318
  });
317
319
  });
320
+ describe('NileKpiChart compact sparkline position', () => {
321
+ const mount = async (attrs, spark = [1, 3, 2, 5, 4, 6, 5, 7, 6, 8]) => {
322
+ const el = await fixture(html `<nile-kpi-chart variant="compact" .sparkline=${spark}></nile-kpi-chart>`);
323
+ if (attrs) {
324
+ for (const [k, v] of Object.entries(JSON.parse(attrs)))
325
+ el.setAttribute(k, String(v));
326
+ }
327
+ await el.updateComplete;
328
+ await el.updateComplete;
329
+ return el;
330
+ };
331
+ const compact = (el) => el.shadowRoot.querySelector('.kpi--compact');
332
+ const valueRow = (el) => el.shadowRoot.querySelector('.kpi-value-row');
333
+ const spark = (el) => el.shadowRoot.querySelector('.kpi-sparkline');
334
+ it("1. defaults to 'bottom'", async () => {
335
+ const el = await mount('');
336
+ expect(el.sparklinePosition).to.equal('bottom');
337
+ });
338
+ it("2. reflects the default to the sparkline-position attribute", async () => {
339
+ const el = await mount('');
340
+ expect(el.getAttribute('sparkline-position')).to.equal('bottom');
341
+ });
342
+ it("3. 'bottom': sparkline is a direct child of .kpi--compact, not inside .kpi-value-row", async () => {
343
+ const el = await mount('');
344
+ const s = spark(el);
345
+ expect(s).to.exist;
346
+ expect(s.parentElement).to.equal(compact(el));
347
+ expect(valueRow(el).querySelector('.kpi-sparkline')).to.be.null;
348
+ });
349
+ it("4. 'right': sparkline moves inside .kpi-value-row after the value group", async () => {
350
+ const el = await mount('{"sparkline-position":"right"}');
351
+ const s = spark(el);
352
+ expect(s).to.exist;
353
+ expect(s.parentElement).to.equal(valueRow(el));
354
+ const group = valueRow(el).querySelector('.kpi-value-group');
355
+ expect(group.compareDocumentPosition(s) & Node.DOCUMENT_POSITION_FOLLOWING).to.be.greaterThan(0);
356
+ });
357
+ it("5. 'right' reflects to the sparkline-position attribute", async () => {
358
+ const el = await mount('');
359
+ el.sparklinePosition = 'right';
360
+ await el.updateComplete;
361
+ expect(el.getAttribute('sparkline-position')).to.equal('right');
362
+ expect(spark(el).parentElement).to.equal(valueRow(el));
363
+ });
364
+ it("6. config.chart.sparklinePosition applies and reflects", async () => {
365
+ const el = await mount('');
366
+ el.config = {
367
+ chart: {
368
+ type: 'kpi',
369
+ variant: 'compact',
370
+ value: '285K',
371
+ sparkline: [1, 2, 3, 4, 5],
372
+ sparklinePosition: 'right',
373
+ },
374
+ aq: {},
375
+ };
376
+ await el.updateComplete;
377
+ await el.updateComplete;
378
+ expect(el.sparklinePosition).to.equal('right');
379
+ expect(el.getAttribute('sparkline-position')).to.equal('right');
380
+ expect(spark(el).parentElement).to.equal(valueRow(el));
381
+ });
382
+ it("7. non-compact variants ignore sparkline-position (sparkline stays at the card end)", async () => {
383
+ const el = await fixture(html `<nile-kpi-chart
384
+ variant="default"
385
+ sparkline-position="right"
386
+ .sparkline=${[1, 2, 3, 4, 5]}
387
+ ></nile-kpi-chart>`);
388
+ await el.updateComplete;
389
+ const s = el.shadowRoot.querySelector('.kpi-sparkline');
390
+ expect(s).to.exist;
391
+ expect(s.closest('.kpi-value-row')).to.be.null;
392
+ expect(s.parentElement).to.equal(el.shadowRoot.querySelector('.kpi'));
393
+ });
394
+ it("8. switching back to 'bottom' returns the sparkline to a direct child of .kpi--compact", async () => {
395
+ const el = await mount('{"sparkline-position":"right"}');
396
+ expect(spark(el).parentElement).to.equal(valueRow(el));
397
+ el.sparklinePosition = 'bottom';
398
+ await el.updateComplete;
399
+ expect(spark(el).parentElement).to.equal(compact(el));
400
+ expect(valueRow(el).querySelector('.kpi-sparkline')).to.be.null;
401
+ });
402
+ });
318
403
  describe('NileKpiChart sparkline size under a transform', () => {
319
404
  const setup = async (scale) => {
320
405
  const wrap = await fixture(html ` <div
@@ -370,4 +455,94 @@ describe('NileKpiChart sparkline size under a transform', () => {
370
455
  expect(stub.chartWidth).to.equal(148);
371
456
  });
372
457
  });
458
+ describe('NileKpiChart CSS parts', () => {
459
+ const FULL = {
460
+ label: 'Monthly recurring revenue', value: 1234567, prefix: '$', suffix: '/mo',
461
+ trendValue: 12.5, trendDirection: 'up', trendLabel: 'vs last month',
462
+ forecastValue: 1500000, forecastLabel: 'by Q4', description: 'All regions', valueInfo: 'Net of refunds',
463
+ };
464
+ const partsOf = (el) => [...el.shadowRoot.querySelectorAll('[part]')].flatMap((n) => n.getAttribute('part').split(/\s+/));
465
+ async function render(props) {
466
+ const el = await fixture(html `<nile-kpi-chart style="display:block;width:320px"></nile-kpi-chart>`);
467
+ Object.assign(el, props);
468
+ await el.updateComplete;
469
+ return el;
470
+ }
471
+ it('every listed part renders in some variant, and nothing renders that is not listed', async () => {
472
+ const seen = new Set();
473
+ for (const variant of ['default', 'compact', 'gauge']) {
474
+ for (const dir of ['up', 'down', 'neutral']) {
475
+ const el = await render({ ...FULL, variant, trendDirection: dir, sparkline: variant === 'gauge' ? [] : [1, 3, 2, 5] });
476
+ partsOf(el).forEach((p) => seen.add(p));
477
+ }
478
+ }
479
+ partsOf(await render({ loading: true })).forEach((p) => seen.add(p));
480
+ const listed = new Set(KPI_CHART_PARTS);
481
+ expect([...seen].filter((p) => !listed.has(p)), 'rendered but not in KPI_CHART_PARTS').to.deep.equal([]);
482
+ expect(KPI_CHART_PARTS.filter((p) => !seen.has(p)), 'listed but never rendered').to.deep.equal([]);
483
+ });
484
+ it('the trend badge carries its direction as a second part name', async () => {
485
+ const el = await render({ ...FULL, trendDirection: 'down' });
486
+ const trend = el.shadowRoot.querySelector('[part~="trend"]');
487
+ expect(trend.getAttribute('part')).to.equal('trend trend-down');
488
+ });
489
+ it('parts are stylable from outside with ::part()', async () => {
490
+ const style = document.createElement('style');
491
+ style.textContent = 'nile-kpi-chart.parts-test::part(value) { color: rgb(1, 2, 3); }';
492
+ document.head.appendChild(style);
493
+ const el = await render(FULL);
494
+ el.classList.add('parts-test');
495
+ const value = el.shadowRoot.querySelector('[part~="value"]');
496
+ expect(getComputedStyle(value).color).to.equal('rgb(1, 2, 3)');
497
+ style.remove();
498
+ });
499
+ });
500
+ describe('nile-chart forwards embedded chart parts', () => {
501
+ async function kpiInChart() {
502
+ const chart = await fixture(html `<nile-chart class="fwd-test" style="display:block;width:360px;height:200px"></nile-chart>`);
503
+ chart.config = {
504
+ chart: { type: 'kpi', label: 'MRR', value: 1234, trend: { value: 4, direction: 'up' }, description: 'All regions' },
505
+ };
506
+ await chart.updateComplete;
507
+ await chart.updateComplete;
508
+ const kpi = chart.shadowRoot.querySelector('nile-kpi-chart');
509
+ await kpi.updateComplete;
510
+ return { chart, kpi };
511
+ }
512
+ it('tags the embedded element with `chart` and its type', async () => {
513
+ const { kpi } = await kpiInChart();
514
+ expect(kpi.getAttribute('part')).to.equal('chart kpi-chart');
515
+ });
516
+ it('re-exports every KPI part with a kpi- prefix', async () => {
517
+ const { kpi } = await kpiInChart();
518
+ const map = kpi.getAttribute('exportparts');
519
+ for (const p of KPI_CHART_PARTS)
520
+ expect(map).to.contain(`${p}: kpi-${p}`);
521
+ });
522
+ it('nile-chart::part(kpi-value) and ::part(kpi-chart) style the KPI from the page', async () => {
523
+ const style = document.createElement('style');
524
+ style.textContent = `
525
+ nile-chart.fwd-test::part(kpi-value) { color: rgb(4, 5, 6); }
526
+ nile-chart.fwd-test::part(kpi-chart) { outline: 3px solid rgb(7, 8, 9); }
527
+ nile-chart.fwd-test::part(kpi-header) { padding-top: 11px; }
528
+ `;
529
+ document.head.appendChild(style);
530
+ const { kpi } = await kpiInChart();
531
+ const value = kpi.shadowRoot.querySelector('[part~="value"]');
532
+ const header = kpi.shadowRoot.querySelector('[part~="header"]');
533
+ expect(getComputedStyle(value).color).to.equal('rgb(4, 5, 6)');
534
+ expect(getComputedStyle(kpi).outlineColor).to.equal('rgb(7, 8, 9)');
535
+ expect(getComputedStyle(header).paddingTop).to.equal('11px');
536
+ style.remove();
537
+ });
538
+ it("the KPI's header does not collide with nile-chart's own header part", async () => {
539
+ const style = document.createElement('style');
540
+ style.textContent = 'nile-chart.fwd-test::part(header) { padding-top: 13px; }';
541
+ document.head.appendChild(style);
542
+ const { kpi } = await kpiInChart();
543
+ const header = kpi.shadowRoot.querySelector('[part~="header"]');
544
+ expect(getComputedStyle(header).paddingTop).to.not.equal('13px');
545
+ style.remove();
546
+ });
547
+ });
373
548
  //# sourceMappingURL=nile-kpi-chart.test.js.map