@aquera/nile-visualization 2.9.38 → 2.9.40

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.
@@ -31,7 +31,7 @@ let NileKpiChart = class NileKpiChart extends NileElement {
31
31
  this._markerEl = null;
32
32
  /** Full configuration: `{ chart, aq }` (same convention as other Nile charts). */
33
33
  this.config = null;
34
- /** Display variant: default (flat), card (bordered container), gauge (Highcharts solid gauge). */
34
+ /** Display variant: default (flat), card (bordered container), gauge (Highcharts solid gauge), accent (left colour bar), compact (tinted card: label + trend on top, large value, description, sparkline at the bottom). */
35
35
  this.variant = 'default';
36
36
  /** Label displayed above the value. */
37
37
  this.label = '';
@@ -78,7 +78,8 @@ let NileKpiChart = class NileKpiChart extends NileElement {
78
78
  /** Sparkline chart height in pixels. */
79
79
  this.sparklineHeight = 48;
80
80
  /** Sparkline stroke width. */
81
- this.sparklineLineWidth = 2;
81
+ /** Sparkline stroke width in px. Unset: 2 (1.25 for the compact variant). */
82
+ this.sparklineLineWidth = null;
82
83
  /** Sparkline series type: 'area' (filled) or 'line'. */
83
84
  this.sparklineType = 'area';
84
85
  /** Fill area opacity 0–1. Only applies when sparklineType is 'area'. */
@@ -224,12 +225,13 @@ let NileKpiChart = class NileKpiChart extends NileElement {
224
225
  this._showTip(text, tipX, tipY);
225
226
  const isBarLike = this.sparklineType === 'bar' || this.sparklineType === 'column';
226
227
  if (!isBarLike) {
227
- this._showMarker(tipX, tipY, this.sparklineColor || '#1868DB');
228
+ this._showMarker(tipX, tipY, this._sparklineColor());
228
229
  }
229
230
  };
230
231
  this._onSparklineMouseLeave = () => {
231
232
  this._hideTip();
232
233
  };
234
+ this._fitSize = '';
233
235
  this._onGaugeEnter = (e) => {
234
236
  const rect = e.currentTarget.getBoundingClientRect();
235
237
  this._showTip(this.getTooltipContent(), rect.left + rect.width / 2, rect.top + rect.height / 2);
@@ -241,6 +243,19 @@ let NileKpiChart = class NileKpiChart extends NileElement {
241
243
  this._onTipLeave = () => {
242
244
  this._hideTip();
243
245
  };
246
+ /** Mirrors the header slots' content onto the host (`has-header-lead` / `has-header-actions`). */
247
+ this._onHeaderSlotChange = (e) => {
248
+ const slot = e.target;
249
+ const used = slot.assignedNodes({ flatten: true })
250
+ .some(n => n.nodeType === Node.ELEMENT_NODE || !!n.textContent?.trim());
251
+ this.toggleAttribute(`has-${slot.name}`, used);
252
+ this._syncHeaderControls();
253
+ };
254
+ /**
255
+ * The trend and header controls float at the top-right of the header; the title wraps around
256
+ * them (its first lines are shortened by a spacer of this size) and uses the full width below.
257
+ */
258
+ this._controlsObserved = null;
244
259
  }
245
260
  // ── Tooltip ──────────────────────────────────────────────────────────────
246
261
  _createTipEl() {
@@ -692,12 +707,13 @@ let NileKpiChart = class NileKpiChart extends NileElement {
692
707
  this.toggleAttribute('has-value', hasValue);
693
708
  this.toggleAttribute('has-sparkline', this.sparkline.length > 0);
694
709
  this._syncTruncationTips();
710
+ requestAnimationFrame(() => this._fitDescription(true));
695
711
  if (changedProperties.has('config') && this.config) {
696
712
  this.applyConfig(this.config);
697
713
  return;
698
714
  }
699
715
  const sparklineProps = ['sparkline', 'sparklineColor', 'sparklineHeight', 'sparklineLineWidth',
700
- 'sparklineType', 'sparklineFillOpacity', 'sparklineMarkers', 'options'];
716
+ 'sparklineType', 'sparklineFillOpacity', 'sparklineMarkers', 'options', 'trendDirection', 'variant'];
701
717
  const spark = this.sparklineChart;
702
718
  const sparkStale = !!spark && spark.renderTo !== this.sparklineContainer;
703
719
  if (sparkStale || sparklineProps.some(p => changedProperties.has(p))) {
@@ -818,6 +834,8 @@ let NileKpiChart = class NileKpiChart extends NileElement {
818
834
  this._reconcileFit();
819
835
  this.syncSparklineChartSize();
820
836
  this.syncGaugeChartSize();
837
+ this._syncHeaderControls();
838
+ this._fitDescription();
821
839
  this._syncTruncationTips();
822
840
  });
823
841
  this.resizeObserver.observe(this);
@@ -830,8 +848,8 @@ let NileKpiChart = class NileKpiChart extends NileElement {
830
848
  }
831
849
  // ── Chart options ────────────────────────────────────────────────────────
832
850
  buildSparklineOptions() {
833
- const brandColor = this.sparklineColor || '#1868DB';
834
- const lineWidth = this.sparklineLineWidth;
851
+ const brandColor = this._sparklineColor();
852
+ const lineWidth = this.sparklineLineWidth ?? (this.variant === 'compact' ? 1.25 : 2);
835
853
  const seriesType = this.sparklineType;
836
854
  const topAlpha = Math.round(Math.min(1, Math.max(0, this.sparklineFillOpacity)) * 255).toString(16).padStart(2, '0');
837
855
  // Pie variant — a compact pie with no slice labels / connectors.
@@ -874,16 +892,28 @@ let NileKpiChart = class NileKpiChart extends NileElement {
874
892
  const dMax = Math.max(...nums);
875
893
  const span = dMax - dMin;
876
894
  const pad = span > 0 ? span * 0.15 : (Math.abs(dMax) * 0.1 || 1);
877
- yAxisOptions = { visible: false, min: dMin - pad, max: dMax + pad, startOnTick: false, endOnTick: false };
878
- areaThreshold = dMin - pad; // area fills from the line down to the plot bottom
895
+ // Compact bleeds to the card edge, so keep the lowest point ~20px above the bottom: flat or low
896
+ // data then starts well above the edge instead of sitting on it (capped at half the height).
897
+ let padBottom = pad;
898
+ if (this.variant === 'compact' && span > 0) {
899
+ const h = this.sparklineContainer?.clientHeight || 40;
900
+ const f = Math.min(0.5, 20 / h);
901
+ padBottom = ((dMax + pad - dMin) * f) / (1 - f);
902
+ }
903
+ yAxisOptions = { visible: false, min: dMin - padBottom, max: dMax + pad, startOnTick: false, endOnTick: false };
904
+ areaThreshold = dMin - padBottom; // area fills from the line down to the plot bottom
879
905
  }
906
+ // Compact sparklines bleed to the card edge, so the fill keeps a faint tint all the way down instead of fading to nothing.
907
+ const bottomAlpha = this.variant === 'compact'
908
+ ? Math.round(Math.min(1, Math.max(0, this.sparklineFillOpacity)) * 255 * 0.4).toString(16).padStart(2, '0')
909
+ : '00';
880
910
  const fillColor = isAreaLike
881
911
  ? {
882
912
  fillColor: {
883
913
  linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
884
914
  stops: [
885
915
  [0, brandColor + topAlpha],
886
- [1, brandColor + '00'],
916
+ [1, brandColor + bottomAlpha],
887
917
  ],
888
918
  },
889
919
  }
@@ -903,6 +933,8 @@ let NileKpiChart = class NileKpiChart extends NileElement {
903
933
  states: { hover: { enabled: false } },
904
934
  }
905
935
  : {
936
+ // The hover tooltip is the component's own mousemove handler, so Highcharts' tracker path (wider than the line) isn't needed.
937
+ enableMouseTracking: false,
906
938
  marker: { enabled: this.sparklineMarkers, states: { hover: { enabled: false } } },
907
939
  lineWidth,
908
940
  lineColor: brandColor,
@@ -912,10 +944,11 @@ let NileKpiChart = class NileKpiChart extends NileElement {
912
944
  states: { hover: { lineWidth, halo: null } },
913
945
  };
914
946
  const defaults = {
915
- chart: { type: seriesType, height: this.sparklineHeight, margin: [2, 0, 2, 0], backgroundColor: 'transparent', animation: false },
947
+ // Compact sparklines run full-bleed: no bottom margin and no x-axis padding, so the fill reaches every card edge.
948
+ chart: { type: seriesType, height: this.sparklineHeight, margin: this.variant === 'compact' && !isBarLike && !isScatter ? [2, 0, 0, 0] : [2, 0, 2, 0], backgroundColor: 'transparent', animation: false },
916
949
  title: { text: undefined },
917
950
  subtitle: { text: undefined },
918
- xAxis: { visible: false },
951
+ xAxis: this.variant === 'compact' && !isBarLike && !isScatter ? { visible: false, minPadding: 0, maxPadding: 0 } : { visible: false },
919
952
  yAxis: yAxisOptions,
920
953
  legend: { enabled: false },
921
954
  tooltip: { enabled: false },
@@ -1077,6 +1110,47 @@ let NileKpiChart = class NileKpiChart extends NileElement {
1077
1110
  const pct = this.trendValue !== null ? `${Math.abs(this.trendValue).toFixed(1)}%` : '';
1078
1111
  return `${arrow} ${pct}${this.trendLabel ? ' ' + this.trendLabel : ''}`.trim();
1079
1112
  }
1113
+ /**
1114
+ * All-or-nothing description: if the content doesn't fit the card's height with the
1115
+ * description (and forecast) showing, hide them so the sparkline keeps its room and
1116
+ * nothing is half-cut. Re-evaluated only when the card's size changes, so hiding them
1117
+ * (which frees space) can't make it flip back and forth.
1118
+ */
1119
+ _fitDescription(force = false) {
1120
+ const kpi = this.shadowRoot?.querySelector('.kpi');
1121
+ if (!kpi || this.variant === 'gauge')
1122
+ return;
1123
+ const size = `${this.clientWidth}x${this.clientHeight}`;
1124
+ if (!force && size === this._fitSize)
1125
+ return;
1126
+ this._fitSize = size;
1127
+ this.removeAttribute('data-hide-desc');
1128
+ if (kpi.scrollHeight > kpi.clientHeight + 1)
1129
+ this.setAttribute('data-hide-desc', '');
1130
+ }
1131
+ /**
1132
+ * True when `el` is cut off sideways (ellipsis) or, for the title, by the line-clamp. Chrome drops
1133
+ * lines hidden by -webkit-line-clamp without reporting them as overflow, so the clamp is lifted for
1134
+ * one synchronous measurement and the full height compared with the clamped height.
1135
+ */
1136
+ _isLabelTruncated(el, isLabel) {
1137
+ if (el.scrollWidth > el.clientWidth)
1138
+ return true;
1139
+ const text = el.querySelector('.kpi-label-text');
1140
+ if (text && text.scrollWidth > text.clientWidth + 1)
1141
+ return true;
1142
+ if (!isLabel)
1143
+ return el.scrollHeight > el.clientHeight + 1;
1144
+ const clamped = el.clientHeight;
1145
+ const prev = el.style.getPropertyValue('-webkit-line-clamp');
1146
+ el.style.setProperty('-webkit-line-clamp', 'unset');
1147
+ const full = el.scrollHeight;
1148
+ if (prev)
1149
+ el.style.setProperty('-webkit-line-clamp', prev);
1150
+ else
1151
+ el.style.removeProperty('-webkit-line-clamp');
1152
+ return full > clamped + 1;
1153
+ }
1080
1154
  _syncTruncationTips() {
1081
1155
  const root = this.shadowRoot;
1082
1156
  if (!root)
@@ -1087,7 +1161,7 @@ let NileKpiChart = class NileKpiChart extends NileElement {
1087
1161
  return;
1088
1162
  const truncated = tip.dataset['kpiTip'] === 'trend'
1089
1163
  ? getComputedStyle(el).textOverflow === 'ellipsis' && el.scrollWidth > el.clientWidth + 2
1090
- : el.scrollWidth > el.clientWidth;
1164
+ : this._isLabelTruncated(el, tip.dataset['kpiTip'] === 'label');
1091
1165
  const disabled = !this.tooltipEnabled || !truncated;
1092
1166
  if (tip.disabled !== disabled)
1093
1167
  tip.disabled = disabled;
@@ -1115,6 +1189,32 @@ let NileKpiChart = class NileKpiChart extends NileElement {
1115
1189
  color=${this.valueInfoIconColor || 'currentColor'}
1116
1190
  ></nile-glyph></span></nile-lite-tooltip>`;
1117
1191
  }
1192
+ /** Normalise any CSS colour to #rrggbb (the area gradient appends hex alpha to it). */
1193
+ _toHex(color) {
1194
+ if (/^#[0-9a-f]{6}$/i.test(color))
1195
+ return color;
1196
+ const ctx = document.createElement('canvas').getContext('2d');
1197
+ if (!ctx)
1198
+ return null;
1199
+ ctx.fillStyle = '#000000';
1200
+ ctx.fillStyle = color;
1201
+ const out = ctx.fillStyle;
1202
+ return /^#[0-9a-f]{6}$/i.test(out) ? out : null;
1203
+ }
1204
+ /** Explicit `sparklineColor` wins; the compact variant otherwise follows the trend colour. */
1205
+ _sparklineColor() {
1206
+ if (this.sparklineColor)
1207
+ return this.sparklineColor;
1208
+ if (this.variant === 'compact' && this.trendDirection !== 'neutral') {
1209
+ const v = getComputedStyle(this)
1210
+ .getPropertyValue(`--nile-kpi-trend-${this.trendDirection}-color`)
1211
+ .trim();
1212
+ const hex = v ? this._toHex(v) : null;
1213
+ if (hex)
1214
+ return hex;
1215
+ }
1216
+ return '#1868DB';
1217
+ }
1118
1218
  renderTrend() {
1119
1219
  if (this.trendValue === null)
1120
1220
  return undefined;
@@ -1162,6 +1262,41 @@ let NileKpiChart = class NileKpiChart extends NileElement {
1162
1262
  </p>
1163
1263
  `;
1164
1264
  }
1265
+ _syncHeaderControls() {
1266
+ const header = this.shadowRoot?.querySelector('.kpi-header');
1267
+ const controls = header?.querySelector('.kpi-header-controls');
1268
+ if (!header || !controls)
1269
+ return;
1270
+ if (this._controlsObserved !== controls) {
1271
+ this._controlsObserved = controls;
1272
+ this.resizeObserver?.observe(controls);
1273
+ }
1274
+ requestAnimationFrame(() => {
1275
+ const w = controls.offsetWidth;
1276
+ const h = controls.offsetHeight;
1277
+ header.style.setProperty('--kpi-controls-w', `${w}px`);
1278
+ header.style.setProperty('--kpi-controls-h', `${h}px`);
1279
+ });
1280
+ }
1281
+ /**
1282
+ * Header row: [label] [extra, e.g. the compact trend] [header-lead slot] [header-actions slot] —
1283
+ both controls sit at the trailing (right) edge.
1284
+ * When either slot has content the label wraps onto further lines instead of truncating
1285
+ * (see the `has-header-*` rules in the stylesheet).
1286
+ */
1287
+ renderHeaderRow(extra, trendRow) {
1288
+ return html `<div class="kpi-header">
1289
+ ${this.label ? html `<nile-lite-tooltip class="kpi-tip" data-kpi-tip="label" content=${this.label} placement="top" disabled><p
1290
+ class="kpi-label"
1291
+ tabindex="0"
1292
+ ><span class="kpi-label-text">${this.label}</span></p></nile-lite-tooltip>` : nothing}
1293
+ <div class="kpi-header-controls">
1294
+ ${extra ?? nothing}
1295
+ <span class="kpi-header-lead"><slot name="header-lead" @slotchange=${this._onHeaderSlotChange}></slot></span>
1296
+ <span class="kpi-header-actions"><slot name="header-actions" @slotchange=${this._onHeaderSlotChange}></slot></span>
1297
+ </div>
1298
+ </div>${trendRow ? html `<div class="kpi-trend-row">${trendRow}</div>` : nothing}`;
1299
+ }
1165
1300
  render() {
1166
1301
  if (this.loading) {
1167
1302
  return html `<div class="chart-loading">${this.loadingText}</div>`;
@@ -1178,12 +1313,35 @@ let NileKpiChart = class NileKpiChart extends NileElement {
1178
1313
  >
1179
1314
  ${this.prefix ? html `<span class="kpi-prefix">${this.prefix}</span>` : nothing}${displayValue}${this.suffix ? html `<span class="kpi-suffix">${this.suffix}</span>` : nothing}
1180
1315
  </h2>`;
1316
+ if (this.variant === 'compact') {
1317
+ return html `
1318
+ <div class="kpi kpi--compact">
1319
+ ${this.renderHeaderRow(this.renderTrend(), this.renderTrend())}
1320
+
1321
+ <div class="kpi-value-row">
1322
+ <span class="kpi-value-group">
1323
+ ${infoLeft ? this.renderValueInfo() : nothing}
1324
+ ${showTooltip
1325
+ ? html `<nile-lite-tooltip class="kpi-tip" content=${this._valueTooltipText()} placement="top" ?disabled=${!this.tooltipEnabled}>${valueEl}</nile-lite-tooltip>`
1326
+ : valueEl}
1327
+ ${infoLeft ? nothing : this.renderValueInfo()}
1328
+ </span>
1329
+ </div>
1330
+
1331
+ ${this.renderForecast()}
1332
+
1333
+ ${this.description ? html `<nile-lite-tooltip class="kpi-tip" data-kpi-tip="description" content=${this.description} placement="top" disabled><p
1334
+ class="kpi-description"
1335
+ tabindex="0"
1336
+ >${this.description}</p></nile-lite-tooltip>` : nothing}
1337
+
1338
+ ${this.sparkline.length ? html `<div class="kpi-sparkline"></div>` : nothing}
1339
+ </div>
1340
+ `;
1341
+ }
1181
1342
  return html `
1182
1343
  <div class="kpi ${isGauge ? 'kpi--gauge' : ''}">
1183
- ${this.label ? html `<nile-lite-tooltip class="kpi-tip" data-kpi-tip="label" content=${this.label} placement="top" disabled><p
1184
- class="kpi-label"
1185
- tabindex="0"
1186
- >${this.label}</p></nile-lite-tooltip>` : nothing}
1344
+ ${this.renderHeaderRow()}
1187
1345
 
1188
1346
  ${isGauge ? html `
1189
1347
  <div class="kpi-gauge-slot">
@@ -1260,7 +1418,7 @@ __decorate([
1260
1418
  property({ type: Number, attribute: 'trend-value' })
1261
1419
  ], NileKpiChart.prototype, "trendValue", void 0);
1262
1420
  __decorate([
1263
- property({ type: String, attribute: 'trend-direction' })
1421
+ property({ type: String, attribute: 'trend-direction', reflect: true })
1264
1422
  ], NileKpiChart.prototype, "trendDirection", void 0);
1265
1423
  __decorate([
1266
1424
  property({ type: String, attribute: 'trend-label' })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aquera/nile-visualization",
3
- "version": "2.9.38",
3
+ "version": "2.9.40",
4
4
  "description": "A visualization Library for the Nile Design System",
5
5
  "license": "MIT",
6
6
  "author": "Aquera Inc",
@@ -68,12 +68,12 @@
68
68
  "echarts": "^6.1.0"
69
69
  },
70
70
  "peerDependencies": {
71
- "highcharts": "12.5.0",
71
+ "highcharts": "13.1.1",
72
72
  "@aquera/nile-data-grid": ">=0.1.0",
73
73
  "@aquera/nile-elements": ">=0.1.0"
74
74
  },
75
75
  "devDependencies": {
76
- "@aquera/nile-glyph": "^1.0.9",
76
+ "@aquera/nile-glyph": "^1.0.13",
77
77
  "@rollup/plugin-babel": "^6.0.3",
78
78
  "@rollup/plugin-commonjs": "^25.0.3",
79
79
  "@rollup/plugin-node-resolve": "^15.0.1",