@aquera/nile-visualization 2.9.39 → 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.
package/README.md CHANGED
@@ -36,6 +36,9 @@ To run a local development server that serves the basic demo located in `demo/in
36
36
 
37
37
  In this section, you can find the updates for each release of `nile-visualization`. It's a good practice to maintain detailed release notes to help users and developers understand what changes have been made from one version to another and how these changes might affect their projects.
38
38
 
39
+ #### Version 2.9.40 (November 17, 2026)
40
+ - Nile KPI Chart: Added the `compact` variant (`variant: 'compact'`) with a full-bleed sparkline and header slots for buttons (UIF-1422)
41
+
39
42
  #### Version 2.9.39 (November 17, 2026)
40
43
  - Nile Chart: Charts with no data now show a "No data" empty state (customise via the `empty-title`, `empty-description` and `empty-ghost` slots; `emptyGhost: false` hides the ghost chart) (UIF-1417)
41
44
  - Nile Chart: Lighter gridlines, adjustable with the new `gridLineStrength` option (0–100 or `'12%'`; `0` hides them) (UIF-1417)
@@ -2254,7 +2254,9 @@ let NileChart = NileChart_1 = class NileChart extends NileElement {
2254
2254
  chartSubtitle: k.chartSubtitle,
2255
2255
  },
2256
2256
  }}
2257
- ></nile-kpi-chart>`;
2257
+ >${this.shouldShowHeader()
2258
+ ? nothing
2259
+ : html `<slot name="header-lead" slot="header-lead"></slot><slot name="header-actions" slot="header-actions"></slot>`}</nile-kpi-chart>`;
2258
2260
  }
2259
2261
  case 'grid': {
2260
2262
  const gridChrome = '--nile-data-grid-radius:0;' +
@@ -53,13 +53,13 @@ export const styles = css `
53
53
  --nile-kpi-card-border-radius: var(--nile-radius-radius-3xl, var(--ng-radius-xl));
54
54
  --nile-kpi-card-shadow: var(--nile-box-shadow-3, var(--ng-shadow-sm));
55
55
  --nile-kpi-card-shadow-hover: var(--nile-kpi-card-shadow, var(--nile-box-shadow-7, var(--ng-shadow-md)));
56
- --nile-kpi-padding-v: var(--nile-spacing-2xl, var(--ng-spacing-2xl));
57
- --nile-kpi-padding-h: var(--nile-spacing-3xl, var(--ng-spacing-3xl));
56
+ --nile-kpi-padding-v: var(--nile-spacing-xl, var(--ng-spacing-xl));
57
+ --nile-kpi-padding-h: var(--nile-spacing-xl, var(--ng-spacing-xl));
58
58
  --nile-kpi-content-gap: var(--nile-spacing-md, var(--ng-spacing-md));
59
59
  --nile-kpi-label-color: var(--nile-colors-neutral-700, var(--ng-colors-text-secondary-700));
60
60
  --nile-kpi-label-font-size: var(--nile-type-scale-3, var(--ng-font-size-text-sm));
61
61
  --nile-kpi-label-font-weight: var(--nile-font-weight-medium, var(--ng-font-weight-medium));
62
- --nile-kpi-value-font-size: clamp(22px, 9cqi, 36px);
62
+ --nile-kpi-value-font-size: clamp(28px, 16cqi, 52px);
63
63
  --nile-kpi-value-color: var(--nile-colors-dark-900, var(--ng-colors-text-primary-900));
64
64
  --nile-kpi-prefix-suffix-font-size: var(--nile-type-scale-6, var(--ng-font-size-text-xl));
65
65
  --nile-kpi-prefix-suffix-color: var(--nile-colors-neutral-700, var(--ng-colors-text-secondary-700));
@@ -136,6 +136,11 @@ export const styles = css `
136
136
  box-shadow: var(--nile-kpi-card-shadow-hover);
137
137
  }
138
138
 
139
+ /* Fit cards are also capped by their height so a short card keeps room for the sparkline. */
140
+ :host([fit]) {
141
+ --nile-kpi-value-font-size: clamp(24px, min(27cqi, 23cqh), 60px);
142
+ }
143
+
139
144
  .kpi {
140
145
  flex: 1 1 auto;
141
146
  display: flex;
@@ -375,10 +380,30 @@ export const styles = css `
375
380
  box-sizing: border-box;
376
381
  }
377
382
 
383
+ /* The value is the hero: on tall cards the sparkline stays a modest strip at the bottom instead of
384
+ taking all the spare height (only fit cards are height-aware; others size to their content). */
385
+ :host([fit]) .kpi-sparkline,
386
+ :host([fit]) .kpi--compact .kpi-sparkline {
387
+ max-height: max(48px, 42cqh);
388
+ margin-top: auto;
389
+ }
390
+
391
+ /* The description never shrinks (and gets half-cut): if it doesn't fit, the fit check hides it whole. */
392
+ .kpi-description,
393
+ .kpi-forecast {
394
+ flex-shrink: 0;
395
+ }
396
+
397
+ /* Set by the component when the card is too short to show the description whole. */
398
+ :host([data-hide-desc][data-hide-desc]) .kpi-description,
399
+ :host([data-hide-desc][data-hide-desc]) .kpi-forecast {
400
+ display: none;
401
+ }
402
+
378
403
  .kpi-sparkline {
379
404
  width: 100%;
380
405
  flex: 1 1 24px;
381
- min-height: 24px;
406
+ min-height: 16px;
382
407
  }
383
408
 
384
409
  /* ── Container queries: scale down for narrow cards ── */
@@ -408,13 +433,7 @@ export const styles = css `
408
433
 
409
434
  .kpi-sparkline {
410
435
  flex-basis: 32px;
411
- min-height: 18px;
412
- }
413
- }
414
-
415
- @container (max-width: 130px) {
416
- .kpi-sparkline {
417
- display: none;
436
+ min-height: 16px;
418
437
  }
419
438
  }
420
439
 
@@ -543,17 +562,6 @@ export const styles = css `
543
562
  }
544
563
  }
545
564
 
546
- @container (max-width: 100px) {
547
- .kpi-sparkline {
548
- display: none;
549
- }
550
- }
551
-
552
- @container (max-width: 379.98px) and (max-height: 90px) {
553
- :host([has-value][has-sparkline]:not([variant='gauge'])) .kpi-sparkline {
554
- display: none;
555
- }
556
- }
557
565
 
558
566
  /* Constrained both ways — only show the value. */
559
567
 
@@ -574,29 +582,414 @@ export const styles = css `
574
582
  }
575
583
 
576
584
  @container (max-height: 150px) {
577
- :host([has-sparkline]:not([variant='gauge'])) .kpi-description {
585
+ :host([has-sparkline]:not([variant='gauge']):not([variant='compact'])) .kpi-description {
578
586
  display: none;
579
587
  }
580
588
  }
581
589
 
582
590
  @container (max-width: 319.98px) and (max-height: 165px) {
583
- :host([has-sparkline]:not([variant='gauge'])) .kpi-description {
591
+ :host([has-sparkline]:not([variant='gauge']):not([variant='compact'])) .kpi-description {
584
592
  display: none;
585
593
  }
586
594
  }
587
595
 
588
596
  @container (max-width: 319.98px) and (max-height: 110px) {
589
- :host([has-value]) .kpi-label {
597
+ :host([has-value]:not([variant='compact'])) .kpi-label {
590
598
  display: none;
591
599
  }
592
600
  }
593
601
 
594
602
  @container (max-height: 110px) {
595
- :host([has-value][has-sparkline]:not([variant='gauge'])) .kpi-label {
603
+ :host([has-value][has-sparkline]:not([variant='gauge']):not([variant='compact'])) .kpi-label {
596
604
  display: none;
597
605
  }
598
606
  }
599
607
 
608
+ /* ── Header row (all variants): [header-lead] title [trend] [header-actions] ── */
609
+
610
+ .kpi-header {
611
+ display: flex;
612
+ align-items: flex-start;
613
+ gap: var(--nile-spacing-xs, var(--ng-spacing-xs));
614
+ min-width: 0;
615
+ width: 100%;
616
+ flex: 0 0 auto;
617
+ }
618
+
619
+ .kpi-header .kpi-tip {
620
+ display: block;
621
+ min-width: 0;
622
+ flex: 1 1 0;
623
+ }
624
+
625
+ .kpi-header .kpi-label {
626
+ width: auto;
627
+ }
628
+
629
+ /* The title never collapses to a sliver, however many controls share the row. */
630
+ .kpi-header .kpi-tip:not([data-kpi-tip='trend']) {
631
+ min-width: 3.5em;
632
+ }
633
+
634
+ .kpi-header-lead,
635
+ .kpi-header-actions {
636
+ display: none;
637
+ align-items: center;
638
+ flex: 0 0 auto;
639
+ gap: var(--nile-spacing-xs, var(--ng-spacing-xs));
640
+ /* Pin the controls to the top, centred on the title's first line. */
641
+ align-self: flex-start;
642
+ min-height: calc(var(--nile-kpi-label-font-size) * 1.4);
643
+ }
644
+
645
+ :host([has-header-lead]) .kpi-header-lead,
646
+ :host([has-header-actions]) .kpi-header-actions {
647
+ display: inline-flex;
648
+ }
649
+
650
+ /* With lead/actions present the title wraps instead of truncating, so it
651
+ never runs underneath the controls. */
652
+ :host([has-header-lead]) .kpi-label,
653
+ :host([has-header-actions]) .kpi-label {
654
+ white-space: normal;
655
+ overflow: visible;
656
+ text-overflow: clip;
657
+ /* Never split a word: one that is too wide for the line is cut with an ellipsis instead. */
658
+ overflow-wrap: normal;
659
+ word-break: normal;
660
+ }
661
+
662
+ :host([has-header-lead]) .kpi-label-text,
663
+ :host([has-header-actions]) .kpi-label-text {
664
+ /* clip (not hidden) so the text stays part of the line-clamp's flow */
665
+ overflow: clip;
666
+ text-overflow: ellipsis;
667
+ overflow-wrap: normal;
668
+ }
669
+
670
+ /* The title scales with the card's width and (for fit cards) height, so words
671
+ fit on a line instead of breaking mid-word and short cards keep room for the
672
+ value and sparkline. Never larger than the variant's own size. */
673
+ .kpi-header {
674
+ --kpi-label-fs: clamp(11px, min(7.5cqi, 9cqh), var(--nile-kpi-label-font-size));
675
+ }
676
+
677
+ .kpi-header .kpi-label {
678
+ font-size: var(--kpi-label-fs);
679
+ }
680
+
681
+ @container (max-width: 190px) {
682
+ .kpi-header {
683
+ gap: var(--nile-spacing-xs, var(--ng-spacing-xs));
684
+ }
685
+
686
+ .kpi-header-lead,
687
+ .kpi-header-actions {
688
+ gap: 2px;
689
+ }
690
+ }
691
+
692
+ /* A wrapping title is capped by card height so a long one can't push the value and
693
+ sparkline out of the card; the rest is cut with an ellipsis (full text is in the tooltip). */
694
+ :host([has-header-lead]) .kpi-label,
695
+ :host([has-header-actions]) .kpi-label {
696
+ display: -webkit-box;
697
+ -webkit-box-orient: vertical;
698
+ -webkit-line-clamp: 4;
699
+ overflow: hidden;
700
+ }
701
+
702
+ @container (max-height: 230px) {
703
+ :host([has-header-lead]) .kpi-label,
704
+ :host([has-header-actions]) .kpi-label {
705
+ -webkit-line-clamp: 3;
706
+ }
707
+ }
708
+
709
+ /* Very short cards: two lines. Anything taller keeps three, and the sparkline gives way instead. */
710
+ @container (max-height: 125px) {
711
+ :host([has-header-lead]) .kpi-label,
712
+ :host([has-header-actions]) .kpi-label {
713
+ -webkit-line-clamp: 2;
714
+ }
715
+ }
716
+
717
+ /* With header controls the trend + mover + actions float at the top-right and the title
718
+ wraps AROUND them: first lines are shortened by a spacer, later lines use the full width. */
719
+ .kpi-header-controls {
720
+ display: contents;
721
+ }
722
+
723
+ :host([has-header-lead]) .kpi-header,
724
+ :host([has-header-actions]) .kpi-header {
725
+ display: block;
726
+ position: relative;
727
+ min-height: var(--kpi-controls-h, 0px);
728
+ }
729
+
730
+ :host([has-header-lead]) .kpi-header-controls,
731
+ :host([has-header-actions]) .kpi-header-controls {
732
+ display: flex;
733
+ position: absolute;
734
+ top: 0;
735
+ right: 0;
736
+ align-items: flex-start;
737
+ gap: var(--nile-spacing-xs, var(--ng-spacing-xs));
738
+ }
739
+
740
+ :host([has-header-lead]) .kpi-header .kpi-tip:not([data-kpi-tip='trend']),
741
+ :host([has-header-actions]) .kpi-header .kpi-tip:not([data-kpi-tip='trend']) {
742
+ display: block;
743
+ min-width: 0;
744
+ width: 100%;
745
+ }
746
+
747
+ :host([has-header-lead]) .kpi-header .kpi-label-text::before,
748
+ :host([has-header-actions]) .kpi-header .kpi-label-text::before {
749
+ content: '';
750
+ float: right;
751
+ width: calc(var(--kpi-controls-w, 0px) + var(--nile-spacing-xs, var(--ng-spacing-xs)));
752
+ height: var(--kpi-controls-h, 0px);
753
+ }
754
+
755
+ :host([has-header-lead]) .kpi-header .kpi-label-text,
756
+ :host([has-header-actions]) .kpi-header .kpi-label-text {
757
+ display: block;
758
+ }
759
+
760
+ :host([has-header-lead]) .kpi-header .kpi-tip[data-kpi-tip='trend'],
761
+ :host([has-header-actions]) .kpi-header .kpi-tip[data-kpi-tip='trend'] {
762
+ min-height: calc(var(--nile-kpi-label-font-size) * 1.4);
763
+ display: inline-flex;
764
+ align-items: center;
765
+ }
766
+
767
+ /* Compact: the trend sits between the title and the actions. */
768
+ .kpi--compact .kpi-header {
769
+ align-items: baseline;
770
+ justify-content: space-between;
771
+ }
772
+
773
+ .kpi-header .kpi-tip[data-kpi-tip='trend'] {
774
+ flex: 0 1 auto;
775
+ min-width: 0;
776
+ overflow: hidden;
777
+ }
778
+
779
+ /* Narrow compact card with header controls: no room for title + trend + controls on one
780
+ line, so the trend moves to its own row under the header. The controls themselves never
781
+ wrap — they stay in the absolutely-positioned group at the top-right. */
782
+ .kpi-trend-row {
783
+ display: none;
784
+ }
785
+
786
+ @container (max-width: 210px) {
787
+ :host([variant='compact'][has-header-lead]) .kpi-header-controls .kpi-tip[data-kpi-tip='trend'],
788
+ :host([variant='compact'][has-header-actions]) .kpi-header-controls .kpi-tip[data-kpi-tip='trend'] {
789
+ display: none;
790
+ }
791
+
792
+ :host([variant='compact'][has-header-lead]) .kpi-trend-row,
793
+ :host([variant='compact'][has-header-actions]) .kpi-trend-row {
794
+ display: block;
795
+ min-width: 0;
796
+ margin-top: var(--nile-spacing-xs, var(--ng-spacing-xs));
797
+ }
798
+ }
799
+
800
+ /* ── Compact variant ──
801
+ Tinted card: label (left) + trend (right) on one header row, a large
802
+ value under it, a muted description, and the sparkline along the bottom.
803
+ Same config as the other variants — only padding, type and placement differ. */
804
+
805
+ :host([variant='compact']) {
806
+ /* 12px on all four sides. */
807
+ --nile-kpi-padding-v: 12px;
808
+ --nile-kpi-padding-h: 12px;
809
+ --nile-kpi-card-border-radius: var(--nile-radius-radius-3xl, var(--ng-radius-xl));
810
+ --nile-kpi-label-font-size: var(--nile-type-scale-3, var(--ng-font-size-text-sm));
811
+ /* Title and value are regular weight; the value stays the dark colour, the title and description the muted grey. */
812
+ --nile-kpi-label-font-weight: var(--nile-font-weight-regular, 400);
813
+ --nile-kpi-label-color: var(--nile-colors-neutral-700, var(--ng-colors-text-secondary-700));
814
+ --nile-kpi-value-font-size: clamp(32px, 18cqi, 56px);
815
+ --nile-kpi-description-color: var(--nile-colors-neutral-700, var(--ng-colors-text-secondary-700));
816
+ --nile-kpi-description-font-size: var(--nile-type-scale-2, var(--ng-font-size-text-xs));
817
+ min-height: 160px;
818
+ }
819
+
820
+ /* Fit-to-container (e.g. a resizable box) must be able to shrink below the default.
821
+ The value font is also capped by the card height so a wide-but-short card
822
+ doesn't grow a value that crowds out the description and sparkline. */
823
+ :host([variant='compact'][fit]) {
824
+ min-height: 0;
825
+ --nile-kpi-value-font-size: clamp(24px, min(18cqi, 24cqh), 56px);
826
+ }
827
+
828
+ :host([variant='compact']:not([embed-in-nile-chart])) {
829
+ background: var(--nile-kpi-card-bg);
830
+ border: var(--nile-kpi-card-border-width) solid var(--nile-kpi-card-border-color);
831
+ border-radius: var(--nile-kpi-card-border-radius);
832
+ box-shadow: var(--nile-kpi-card-shadow);
833
+ transition: box-shadow var(--nile-transition-duration-default, var(--ng-transition-duration-default)) ease;
834
+ }
835
+
836
+ :host([variant='compact']:not([embed-in-nile-chart]):hover) {
837
+ box-shadow: var(--nile-kpi-card-shadow-hover);
838
+ }
839
+
840
+ /* With a sparkline the border moves outside the box (as a ring), so the full-bleed fill
841
+ reaches the card edge instead of stopping at an inner 1px border. */
842
+ :host([variant='compact'][has-sparkline]:not([embed-in-nile-chart])) {
843
+ border-width: 0;
844
+ box-shadow: 0 0 0 var(--nile-kpi-card-border-width) var(--nile-kpi-card-border-color), var(--nile-kpi-card-shadow);
845
+ }
846
+
847
+ :host([variant='compact'][has-sparkline]:not([embed-in-nile-chart]):hover) {
848
+ box-shadow: 0 0 0 var(--nile-kpi-card-border-width) var(--nile-kpi-card-border-color), var(--nile-kpi-card-shadow-hover);
849
+ }
850
+
851
+ .kpi--compact {
852
+ gap: var(--nile-spacing-xs, var(--ng-spacing-xs));
853
+ }
854
+
855
+ .kpi--compact .kpi-label {
856
+ width: auto;
857
+ }
858
+
859
+ /* Trend becomes a plain top-right figure (no arrow, no vs-label). */
860
+ .kpi--compact .kpi-trend {
861
+ /* On a very narrow card the trend shrinks and ends in an ellipsis rather than spilling out. */
862
+ display: block;
863
+ flex: 0 1 auto;
864
+ min-width: 0;
865
+ max-width: 100%;
866
+ overflow: hidden;
867
+ text-overflow: ellipsis;
868
+ white-space: nowrap;
869
+ padding: 0;
870
+ font-size: var(--nile-type-scale-3, var(--ng-font-size-text-sm));
871
+ font-weight: var(--nile-font-weight-medium, var(--ng-font-weight-medium));
872
+ }
873
+
874
+ .kpi--compact .kpi-trend-arrow,
875
+ .kpi--compact .kpi-trend-label {
876
+ display: none;
877
+ }
878
+
879
+ .kpi--compact .kpi-trend-value::before {
880
+ content: '+';
881
+ }
882
+
883
+ .kpi--compact .kpi-trend--down .kpi-trend-value::before {
884
+ content: '-';
885
+ }
886
+
887
+ .kpi--compact .kpi-trend--neutral .kpi-trend-value::before {
888
+ content: '';
889
+ }
890
+
891
+ .kpi--compact .kpi-value {
892
+ font-weight: var(--nile-font-weight-regular, 400);
893
+ line-height: 1.1;
894
+ letter-spacing: -0.02em;
895
+ }
896
+
897
+ .kpi--compact .kpi-description {
898
+ font-size: var(--nile-kpi-description-font-size);
899
+ }
900
+
901
+ .kpi--compact .kpi-sparkline {
902
+ flex: 1 1 20px;
903
+ min-height: 20px;
904
+ margin-top: var(--nile-spacing-xs, var(--ng-spacing-xs));
905
+ /* Full-bleed: cancel the card's side padding so the sparkline runs edge to edge. */
906
+ width: auto;
907
+ margin-left: calc(-1 * var(--nile-kpi-padding-h));
908
+ margin-right: calc(-1 * var(--nile-kpi-padding-h));
909
+ margin-bottom: calc(-1 * var(--nile-kpi-padding-v));
910
+ }
911
+
912
+ /* Compact keeps its own column layout at every size (the generic short-wide
913
+ row layout above would split it up) ... */
914
+ :host([variant='compact']) .kpi--compact {
915
+ flex-direction: column;
916
+ align-items: stretch;
917
+ justify-content: flex-start;
918
+ }
919
+
920
+ /* ... and its parts are all-or-nothing: shown whole, or hidden — never
921
+ squashed or clipped. The generic short-card rules above that would otherwise
922
+ half-hide them are scoped to non-compact variants. Height tiers only apply when
923
+ the card is sized by its container (fit / size-container). */
924
+ :host([variant='compact']) .kpi-label,
925
+ :host([variant='compact']) .kpi-description,
926
+ :host([variant='compact']) .kpi-forecast,
927
+ :host([variant='compact']) .kpi-sparkline {
928
+ display: block;
929
+ }
930
+
931
+ :host([variant='compact']) .kpi-forecast {
932
+ display: inline-flex;
933
+ }
934
+
935
+ /* Compact titles that wrap beside header controls keep their line cap (the block
936
+ rule above would otherwise cancel -webkit-box). */
937
+ :host([variant='compact'][has-header-lead]) .kpi-label,
938
+ :host([variant='compact'][has-header-actions]) .kpi-label {
939
+ display: -webkit-box;
940
+ }
941
+
942
+ /* 1. The sparkline stays at every size; it only goes when the card is too short for anything else. */
943
+ @container (max-height: 72px) {
944
+ :host([variant='compact']) .kpi-sparkline {
945
+ display: none;
946
+ }
947
+ }
948
+
949
+ /* 2. Then the description and forecast. */
950
+ @container (max-height: 128px) {
951
+ :host([variant='compact']) .kpi-description,
952
+ :host([variant='compact']) .kpi-forecast {
953
+ display: none;
954
+ }
955
+ }
956
+
957
+ /* The wrapped trend row (narrow card with header controls) costs ~20px, so
958
+ tiers 1 and 2 kick in that much earlier. */
959
+ @container (max-width: 210px) and (max-height: 150px) {
960
+ :host([variant='compact'][has-header-lead]) .kpi-description,
961
+ :host([variant='compact'][has-header-lead]) .kpi-forecast,
962
+ :host([variant='compact'][has-header-actions]) .kpi-description,
963
+ :host([variant='compact'][has-header-actions]) .kpi-forecast {
964
+ display: none;
965
+ }
966
+ }
967
+
968
+ /* 3. Tighten the padding so header + value still fit. */
969
+ @container (max-height: 108px) {
970
+ :host([variant='compact']) {
971
+ --nile-kpi-padding-v: 12px;
972
+ --nile-kpi-padding-h: 12px;
973
+ }
974
+ }
975
+
976
+ /* 4. Smallest: value only. */
977
+ @container (max-height: 90px) {
978
+ /* Title and trend go; any header-lead / header-actions controls stay. */
979
+ :host([variant='compact']) .kpi-header .kpi-tip {
980
+ display: none;
981
+ }
982
+
983
+ :host([variant='compact']) {
984
+ --nile-kpi-padding-v: 12px;
985
+ --nile-kpi-value-font-size: clamp(22px, 10cqi, 32px);
986
+ }
987
+
988
+ :host([variant='compact']) .kpi--compact {
989
+ justify-content: center;
990
+ }
991
+ }
992
+
600
993
  /* ── Gauge variant ── */
601
994
 
602
995
  .kpi--gauge {
@@ -3,7 +3,7 @@ import type Highcharts from 'highcharts';
3
3
  import NileElement from '../internal/base/nile-element.js';
4
4
  import type { AqConfigType } from '../internal/types/aq-config.type.js';
5
5
  export type TrendDirection = 'up' | 'down' | 'neutral';
6
- export type KpiVariant = 'default' | 'card' | 'gauge' | 'accent';
6
+ export type KpiVariant = 'default' | 'card' | 'gauge' | 'accent' | 'compact';
7
7
  export type SparklineType = 'area' | 'line' | 'column' | 'bar' | 'spline' | 'areaspline' | 'pie' | 'scatter';
8
8
  export type KpiValueFormat = 'auto' | 'K' | 'M' | 'B' | 'T' | 'none';
9
9
  export type KpiNumberSystem = 'indian' | 'international';
@@ -160,7 +160,7 @@ export declare class NileKpiChart extends NileElement {
160
160
  private gaugeSlot;
161
161
  /** Full configuration: `{ chart, aq }` (same convention as other Nile charts). */
162
162
  config: NileKpiConfigInputType | null;
163
- /** Display variant: default (flat), card (bordered container), gauge (Highcharts solid gauge). */
163
+ /** 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). */
164
164
  variant: KpiVariant;
165
165
  /** Label displayed above the value. */
166
166
  label: string;
@@ -206,7 +206,8 @@ export declare class NileKpiChart extends NileElement {
206
206
  /** Sparkline chart height in pixels. */
207
207
  sparklineHeight: number;
208
208
  /** Sparkline stroke width. */
209
- sparklineLineWidth: number;
209
+ /** Sparkline stroke width in px. Unset: 2 (1.25 for the compact variant). */
210
+ sparklineLineWidth: number | null;
210
211
  /** Sparkline series type: 'area' (filled) or 'line'. */
211
212
  sparklineType: SparklineType;
212
213
  /** Fill area opacity 0–1. Only applies when sparklineType is 'area'. */
@@ -340,17 +341,50 @@ export declare class NileKpiChart extends NileElement {
340
341
  private destroyCharts;
341
342
  private _valueTooltipText;
342
343
  private _trendTooltipText;
344
+ private _fitSize;
345
+ /**
346
+ * All-or-nothing description: if the content doesn't fit the card's height with the
347
+ * description (and forecast) showing, hide them so the sparkline keeps its room and
348
+ * nothing is half-cut. Re-evaluated only when the card's size changes, so hiding them
349
+ * (which frees space) can't make it flip back and forth.
350
+ */
351
+ private _fitDescription;
352
+ /**
353
+ * True when `el` is cut off sideways (ellipsis) or, for the title, by the line-clamp. Chrome drops
354
+ * lines hidden by -webkit-line-clamp without reporting them as overflow, so the clamp is lifted for
355
+ * one synchronous measurement and the full height compared with the clamped height.
356
+ */
357
+ private _isLabelTruncated;
343
358
  private _syncTruncationTips;
344
359
  private _onGaugeEnter;
345
360
  private _onTrendKeydown;
346
361
  private _onTipLeave;
347
362
  private renderValueInfo;
363
+ /** Normalise any CSS colour to #rrggbb (the area gradient appends hex alpha to it). */
364
+ private _toHex;
365
+ /** Explicit `sparklineColor` wins; the compact variant otherwise follows the trend colour. */
366
+ private _sparklineColor;
348
367
  private renderTrend;
349
368
  /**
350
369
  * The projected-value line. Rendered only when `forecastValue` is set, so a
351
370
  * tile with no projection keeps exactly the layout it had.
352
371
  */
353
372
  private renderForecast;
373
+ /** Mirrors the header slots' content onto the host (`has-header-lead` / `has-header-actions`). */
374
+ private _onHeaderSlotChange;
375
+ /**
376
+ * The trend and header controls float at the top-right of the header; the title wraps around
377
+ * them (its first lines are shortened by a spacer of this size) and uses the full width below.
378
+ */
379
+ private _controlsObserved;
380
+ private _syncHeaderControls;
381
+ /**
382
+ * Header row: [label] [extra, e.g. the compact trend] [header-lead slot] [header-actions slot] —
383
+ both controls sit at the trailing (right) edge.
384
+ * When either slot has content the label wraps onto further lines instead of truncating
385
+ * (see the `has-header-*` rules in the stylesheet).
386
+ */
387
+ private renderHeaderRow;
354
388
  render(): TemplateResult;
355
389
  }
356
390
  declare global {
@@ -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.39",
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",