@aquera/nile-visualization 2.9.41 → 2.9.42
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 +4 -0
- package/dist/src/index.d.ts +1 -1
- package/dist/src/nile-chart/nile-chart.css.js +2 -1
- package/dist/src/nile-kpi-chart/index.d.ts +1 -1
- package/dist/src/nile-kpi-chart/nile-kpi-chart.css.d.ts +1 -1
- package/dist/src/nile-kpi-chart/nile-kpi-chart.css.js +87 -33
- package/dist/src/nile-kpi-chart/nile-kpi-chart.d.ts +10 -5
- package/dist/src/nile-kpi-chart/nile-kpi-chart.js +105 -19
- package/dist/src/nile-kpi-chart/nile-kpi-chart.test.d.ts +1 -0
- package/dist/src/nile-kpi-chart/nile-kpi-chart.test.js +373 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -36,6 +36,10 @@ 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.42 (November 18, 2026)
|
|
40
|
+
- Nile KPI Chart: Compact titles now wrap onto up to 3 lines with or without header controls, and the new `title-overflow` property (`ellipsis` default, or `break`) controls how an oversized word is handled; a tooltip with the full title shows only when it is truncated. Other variants are unchanged. Also fixes the white strip beside the compact sparkline in a scaled wrapper and the sparkline tooltip width and edge clamping (UIF-1424)
|
|
41
|
+
- Nile Charts: Fixed the clipped bottom border of the "No data" empty-state badge (UIF-1424)
|
|
42
|
+
|
|
39
43
|
#### Version 2.9.41 (November 18, 2026)
|
|
40
44
|
- Nile Charts: Opt-in pagination for all axis charts (bar, column, line, area, timeline, …) via `chart.pagination` — chevrons page the category axis when it overflows; `valueSpan` also pages the value axis (UIF-1423)
|
|
41
45
|
- Nile Charts: `chart.zoomType`, `chart.panning` and `chart.panKey` turn on Highcharts zoom and pan; panning moves a paginated chart's page (UIF-1423)
|
package/dist/src/index.d.ts
CHANGED
|
@@ -101,7 +101,7 @@ export type { FlameChartPoint, FlameSunburstPoint, FlameChartLayout, } from './n
|
|
|
101
101
|
export { NileSpiderwebChart } from './nile-spiderweb-chart/index.js';
|
|
102
102
|
export type { SpiderwebChartSeriesData } from './nile-spiderweb-chart/index.js';
|
|
103
103
|
export { NileKpiChart } from './nile-kpi-chart/index.js';
|
|
104
|
-
export type { ChartKpiSeparatedPayload, KpiConfig, NileKpiConfigInputType, TrendDirection, KpiVariant, } from './nile-kpi-chart/index.js';
|
|
104
|
+
export type { ChartKpiSeparatedPayload, KpiConfig, NileKpiConfigInputType, TrendDirection, KpiVariant, KpiTitleOverflow, } from './nile-kpi-chart/index.js';
|
|
105
105
|
export { NileFilterChart } from './nile-filter-chart/index.js';
|
|
106
106
|
export type { FilterChartSeparatedPayload, FilterControl, FilterOption, FilterChartConfig, } from './nile-filter-chart/nile-filter-chart.js';
|
|
107
107
|
export { NileMapChart } from './nile-map-chart/index.js';
|
|
@@ -1125,7 +1125,8 @@ export const styles = css `
|
|
|
1125
1125
|
font-family: var(--nile-font-family-serif, var(--ng-font-family-body));
|
|
1126
1126
|
font-size: var(--nile-type-scale-4, var(--ng-font-size-text-md));
|
|
1127
1127
|
font-weight: var(--nile-font-weight-medium, var(--ng-font-weight-medium));
|
|
1128
|
-
|
|
1128
|
+
/* room for the inline badge's padding and border, which overflow: hidden would clip */
|
|
1129
|
+
line-height: 1.75;
|
|
1129
1130
|
color: var(--nile-colors-dark-900, var(--ng-colors-text-primary-900));
|
|
1130
1131
|
}
|
|
1131
1132
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { NileKpiChart } from './nile-kpi-chart.js';
|
|
2
|
-
export type { ChartKpiSeparatedPayload, KpiConfig, NileKpiConfigInputType, TrendDirection, KpiVariant, } from './nile-kpi-chart.js';
|
|
2
|
+
export type { ChartKpiSeparatedPayload, KpiConfig, NileKpiConfigInputType, TrendDirection, KpiVariant, KpiTitleOverflow, } from './nile-kpi-chart.js';
|
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
* Global tooltip styles — injected once into document.head so the tooltip
|
|
3
3
|
* element on document.body is styled independently of the shadow DOM.
|
|
4
4
|
*/
|
|
5
|
-
export declare const tooltipCss = "\n .nile-kpi-tooltip {\n position: fixed;\n display: none;\n transform: translate(-50%, calc(-100% - 10px));\n background: var(--nile-colors-white-base, var(--ng-colors-bg-primary));\n color: var(--nile-colors-dark-900, var(--ng-colors-text-primary-900));\n font-family: var(--nile-font-family-serif, var(--ng-font-family-body));\n font-size: var(--nile-type-scale-2, var(--ng-font-size-text-xs));\n font-weight: var(--nile-font-weight-medium, var(--ng-font-weight-medium));\n line-height: 1.4;\n padding: var(--nile-spacing-xs, var(--ng-spacing-xs)) var(--nile-spacing-md, var(--ng-spacing-md));\n border-radius: var(--nile-radius-radius-xl, var(--ng-radius-sm));\n border: var(--nile-border-width-1, var(--ng-stroke-width-1)) solid var(--nile-colors-neutral-400, var(--ng-colors-border-secondary));\n pointer-events: none;\n white-space: normal;\n max-width: 260px;\n word-break: break-word;\n z-index: 2;\n box-shadow: var(--nile-box-shadow-3, var(--ng-shadow-sm));\n }\n\n .nile-kpi-tooltip::after {\n content: '';\n position: absolute;\n top: 100%;\n left: 50
|
|
5
|
+
export declare const tooltipCss = "\n .nile-kpi-tooltip {\n position: fixed;\n display: none;\n transform: translate(-50%, calc(-100% - 10px));\n background: var(--nile-colors-white-base, var(--ng-colors-bg-primary));\n color: var(--nile-colors-dark-900, var(--ng-colors-text-primary-900));\n font-family: var(--nile-font-family-serif, var(--ng-font-family-body));\n font-size: var(--nile-type-scale-2, var(--ng-font-size-text-xs));\n font-weight: var(--nile-font-weight-medium, var(--ng-font-weight-medium));\n line-height: 1.4;\n padding: var(--nile-spacing-xs, var(--ng-spacing-xs)) var(--nile-spacing-md, var(--ng-spacing-md));\n border-radius: var(--nile-radius-radius-xl, var(--ng-radius-sm));\n border: var(--nile-border-width-1, var(--ng-stroke-width-1)) solid var(--nile-colors-neutral-400, var(--ng-colors-border-secondary));\n pointer-events: none;\n white-space: normal;\n /* sizes to its text so it can't shrink to a one-character column near the window edge */\n width: max-content;\n /* border-box: max-width caps the total width, padding and border included */\n box-sizing: border-box;\n max-width: min(260px, calc(100vw - 16px));\n word-break: break-word;\n z-index: 2;\n box-shadow: var(--nile-box-shadow-3, var(--ng-shadow-sm));\n }\n\n /* _showTip() sets --nile-kpi-tip-arrow-x so the arrow keeps pointing at the data point */\n .nile-kpi-tooltip::after {\n content: '';\n position: absolute;\n top: 100%;\n left: var(--nile-kpi-tip-arrow-x, 50%);\n transform: translateX(-50%);\n border: var(--nile-border-size-5, 5px) solid transparent;\n border-top-color: var(--nile-colors-neutral-400, var(--ng-colors-border-secondary));\n }\n\n /* No room above the point: sit below it, arrow on top. */\n .nile-kpi-tooltip[data-placement='bottom'] {\n transform: translate(-50%, 10px);\n }\n .nile-kpi-tooltip[data-placement='bottom']::after {\n top: auto;\n bottom: 100%;\n border-top-color: transparent;\n border-bottom-color: var(--nile-colors-neutral-400, var(--ng-colors-border-secondary));\n }\n .nile-kpi-marker {\n position: fixed;\n display: none;\n width: 10px;\n height: 10px;\n border-radius: 50%;\n transform: translate(-50%, -50%);\n pointer-events: none;\n z-index: 1;\n }\n";
|
|
6
6
|
export declare const styles: import("lit").CSSResult;
|
|
@@ -19,21 +19,37 @@ export const tooltipCss = `
|
|
|
19
19
|
border: var(--nile-border-width-1, var(--ng-stroke-width-1)) solid var(--nile-colors-neutral-400, var(--ng-colors-border-secondary));
|
|
20
20
|
pointer-events: none;
|
|
21
21
|
white-space: normal;
|
|
22
|
-
|
|
22
|
+
/* sizes to its text so it can't shrink to a one-character column near the window edge */
|
|
23
|
+
width: max-content;
|
|
24
|
+
/* border-box: max-width caps the total width, padding and border included */
|
|
25
|
+
box-sizing: border-box;
|
|
26
|
+
max-width: min(260px, calc(100vw - 16px));
|
|
23
27
|
word-break: break-word;
|
|
24
28
|
z-index: 2;
|
|
25
29
|
box-shadow: var(--nile-box-shadow-3, var(--ng-shadow-sm));
|
|
26
30
|
}
|
|
27
31
|
|
|
32
|
+
/* _showTip() sets --nile-kpi-tip-arrow-x so the arrow keeps pointing at the data point */
|
|
28
33
|
.nile-kpi-tooltip::after {
|
|
29
34
|
content: '';
|
|
30
35
|
position: absolute;
|
|
31
36
|
top: 100%;
|
|
32
|
-
left: 50
|
|
37
|
+
left: var(--nile-kpi-tip-arrow-x, 50%);
|
|
33
38
|
transform: translateX(-50%);
|
|
34
39
|
border: var(--nile-border-size-5, 5px) solid transparent;
|
|
35
40
|
border-top-color: var(--nile-colors-neutral-400, var(--ng-colors-border-secondary));
|
|
36
41
|
}
|
|
42
|
+
|
|
43
|
+
/* No room above the point: sit below it, arrow on top. */
|
|
44
|
+
.nile-kpi-tooltip[data-placement='bottom'] {
|
|
45
|
+
transform: translate(-50%, 10px);
|
|
46
|
+
}
|
|
47
|
+
.nile-kpi-tooltip[data-placement='bottom']::after {
|
|
48
|
+
top: auto;
|
|
49
|
+
bottom: 100%;
|
|
50
|
+
border-top-color: transparent;
|
|
51
|
+
border-bottom-color: var(--nile-colors-neutral-400, var(--ng-colors-border-secondary));
|
|
52
|
+
}
|
|
37
53
|
.nile-kpi-marker {
|
|
38
54
|
position: fixed;
|
|
39
55
|
display: none;
|
|
@@ -172,6 +188,29 @@ export const styles = css `
|
|
|
172
188
|
flex-shrink: 0;
|
|
173
189
|
}
|
|
174
190
|
|
|
191
|
+
/* The 3-line clamp is on the inner span, not the <p>, so the <p>'s display stays under the card's visibility rules */
|
|
192
|
+
:host([variant='compact']) .kpi-label {
|
|
193
|
+
white-space: normal;
|
|
194
|
+
text-overflow: clip;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
:host([variant='compact']) .kpi-label-text {
|
|
198
|
+
display: -webkit-box;
|
|
199
|
+
-webkit-box-orient: vertical;
|
|
200
|
+
/* _fitDescription lowers --kpi-title-lines when the title would push the value out of the card */
|
|
201
|
+
-webkit-line-clamp: var(--kpi-title-lines, 3);
|
|
202
|
+
line-clamp: var(--kpi-title-lines, 3);
|
|
203
|
+
overflow: hidden;
|
|
204
|
+
text-overflow: ellipsis;
|
|
205
|
+
overflow-wrap: normal;
|
|
206
|
+
word-break: normal;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
:host([variant='compact'][title-overflow='break']) .kpi-label,
|
|
210
|
+
:host([variant='compact'][title-overflow='break']) .kpi-label-text {
|
|
211
|
+
overflow-wrap: anywhere;
|
|
212
|
+
}
|
|
213
|
+
|
|
175
214
|
.kpi-value-row {
|
|
176
215
|
display: flex;
|
|
177
216
|
align-items: center;
|
|
@@ -394,6 +433,11 @@ export const styles = css `
|
|
|
394
433
|
flex-shrink: 0;
|
|
395
434
|
}
|
|
396
435
|
|
|
436
|
+
/* set when the title leaves the compact sparkline less than its minimum height */
|
|
437
|
+
:host([variant='compact'][data-hide-spark]) .kpi-sparkline {
|
|
438
|
+
display: none;
|
|
439
|
+
}
|
|
440
|
+
|
|
397
441
|
/* Set by the component when the card is too short to show the description whole. */
|
|
398
442
|
:host([data-hide-desc][data-hide-desc]) .kpi-description,
|
|
399
443
|
:host([data-hide-desc][data-hide-desc]) .kpi-forecast {
|
|
@@ -647,10 +691,15 @@ export const styles = css `
|
|
|
647
691
|
display: inline-flex;
|
|
648
692
|
}
|
|
649
693
|
|
|
650
|
-
/*
|
|
651
|
-
|
|
652
|
-
:host([has-header-
|
|
653
|
-
|
|
694
|
+
/* the title stays visible beside header controls even where the short-card rules hide it */
|
|
695
|
+
:host([variant='compact'][has-header-lead]) .kpi-label,
|
|
696
|
+
:host([variant='compact'][has-header-actions]) .kpi-label {
|
|
697
|
+
display: block;
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
/* with lead/actions present the title wraps instead of truncating, so it never runs under the controls */
|
|
701
|
+
:host([has-header-lead]:not([variant='compact'])) .kpi-label,
|
|
702
|
+
:host([has-header-actions]:not([variant='compact'])) .kpi-label {
|
|
654
703
|
white-space: normal;
|
|
655
704
|
overflow: visible;
|
|
656
705
|
text-overflow: clip;
|
|
@@ -659,8 +708,8 @@ export const styles = css `
|
|
|
659
708
|
word-break: normal;
|
|
660
709
|
}
|
|
661
710
|
|
|
662
|
-
:host([has-header-lead]) .kpi-label-text,
|
|
663
|
-
:host([has-header-actions]) .kpi-label-text {
|
|
711
|
+
:host([has-header-lead]:not([variant='compact'])) .kpi-label-text,
|
|
712
|
+
:host([has-header-actions]:not([variant='compact'])) .kpi-label-text {
|
|
664
713
|
/* clip (not hidden) so the text stays part of the line-clamp's flow */
|
|
665
714
|
overflow: clip;
|
|
666
715
|
text-overflow: ellipsis;
|
|
@@ -691,8 +740,8 @@ export const styles = css `
|
|
|
691
740
|
|
|
692
741
|
/* A wrapping title is capped by card height so a long one can't push the value and
|
|
693
742
|
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 {
|
|
743
|
+
:host([has-header-lead]:not([variant='compact'])) .kpi-label,
|
|
744
|
+
:host([has-header-actions]:not([variant='compact'])) .kpi-label {
|
|
696
745
|
display: -webkit-box;
|
|
697
746
|
-webkit-box-orient: vertical;
|
|
698
747
|
-webkit-line-clamp: 4;
|
|
@@ -700,35 +749,47 @@ export const styles = css `
|
|
|
700
749
|
}
|
|
701
750
|
|
|
702
751
|
@container (max-height: 230px) {
|
|
703
|
-
:host([has-header-lead]) .kpi-label,
|
|
704
|
-
:host([has-header-actions]) .kpi-label {
|
|
752
|
+
:host([has-header-lead]:not([variant='compact'])) .kpi-label,
|
|
753
|
+
:host([has-header-actions]:not([variant='compact'])) .kpi-label {
|
|
705
754
|
-webkit-line-clamp: 3;
|
|
706
755
|
}
|
|
707
756
|
}
|
|
708
757
|
|
|
709
758
|
/* Very short cards: two lines. Anything taller keeps three, and the sparkline gives way instead. */
|
|
710
759
|
@container (max-height: 125px) {
|
|
711
|
-
:host([has-header-lead]) .kpi-label,
|
|
712
|
-
:host([has-header-actions]) .kpi-label {
|
|
760
|
+
:host([has-header-lead]:not([variant='compact'])) .kpi-label,
|
|
761
|
+
:host([has-header-actions]:not([variant='compact'])) .kpi-label {
|
|
713
762
|
-webkit-line-clamp: 2;
|
|
714
763
|
}
|
|
715
764
|
}
|
|
716
765
|
|
|
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
766
|
.kpi-header-controls {
|
|
720
767
|
display: contents;
|
|
721
768
|
}
|
|
722
769
|
|
|
723
|
-
|
|
724
|
-
:host([has-header-
|
|
770
|
+
/* title and controls sit side by side, so the title's first line starts level with the controls */
|
|
771
|
+
:host([variant='compact'][has-header-lead]) .kpi-header,
|
|
772
|
+
:host([variant='compact'][has-header-actions]) .kpi-header {
|
|
773
|
+
display: flex;
|
|
774
|
+
align-items: flex-start;
|
|
775
|
+
gap: var(--nile-spacing-xs, var(--ng-spacing-xs));
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
:host([variant='compact'][has-header-lead]) .kpi-header .kpi-tip:not([data-kpi-tip='trend']),
|
|
779
|
+
:host([variant='compact'][has-header-actions]) .kpi-header .kpi-tip:not([data-kpi-tip='trend']) {
|
|
780
|
+
display: block;
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
/* the trend, mover and actions float top-right and the title wraps around them via a spacer on its first lines */
|
|
784
|
+
:host([has-header-lead]:not([variant='compact'])) .kpi-header,
|
|
785
|
+
:host([has-header-actions]:not([variant='compact'])) .kpi-header {
|
|
725
786
|
display: block;
|
|
726
787
|
position: relative;
|
|
727
788
|
min-height: var(--kpi-controls-h, 0px);
|
|
728
789
|
}
|
|
729
790
|
|
|
730
|
-
:host([has-header-lead]) .kpi-header-controls,
|
|
731
|
-
:host([has-header-actions]) .kpi-header-controls {
|
|
791
|
+
:host([has-header-lead]:not([variant='compact'])) .kpi-header-controls,
|
|
792
|
+
:host([has-header-actions]:not([variant='compact'])) .kpi-header-controls {
|
|
732
793
|
display: flex;
|
|
733
794
|
position: absolute;
|
|
734
795
|
top: 0;
|
|
@@ -737,23 +798,23 @@ export const styles = css `
|
|
|
737
798
|
gap: var(--nile-spacing-xs, var(--ng-spacing-xs));
|
|
738
799
|
}
|
|
739
800
|
|
|
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']) {
|
|
801
|
+
:host([has-header-lead]:not([variant='compact'])) .kpi-header .kpi-tip:not([data-kpi-tip='trend']),
|
|
802
|
+
:host([has-header-actions]:not([variant='compact'])) .kpi-header .kpi-tip:not([data-kpi-tip='trend']) {
|
|
742
803
|
display: block;
|
|
743
804
|
min-width: 0;
|
|
744
805
|
width: 100%;
|
|
745
806
|
}
|
|
746
807
|
|
|
747
|
-
:host([has-header-lead]) .kpi-header .kpi-label-text::before,
|
|
748
|
-
:host([has-header-actions]) .kpi-header .kpi-label-text::before {
|
|
808
|
+
:host([has-header-lead]:not([variant='compact'])) .kpi-header .kpi-label-text::before,
|
|
809
|
+
:host([has-header-actions]:not([variant='compact'])) .kpi-header .kpi-label-text::before {
|
|
749
810
|
content: '';
|
|
750
811
|
float: right;
|
|
751
812
|
width: calc(var(--kpi-controls-w, 0px) + var(--nile-spacing-xs, var(--ng-spacing-xs)));
|
|
752
813
|
height: var(--kpi-controls-h, 0px);
|
|
753
814
|
}
|
|
754
815
|
|
|
755
|
-
:host([has-header-lead]) .kpi-header .kpi-label-text,
|
|
756
|
-
:host([has-header-actions]) .kpi-header .kpi-label-text {
|
|
816
|
+
:host([has-header-lead]:not([variant='compact'])) .kpi-header .kpi-label-text,
|
|
817
|
+
:host([has-header-actions]:not([variant='compact'])) .kpi-header .kpi-label-text {
|
|
757
818
|
display: block;
|
|
758
819
|
}
|
|
759
820
|
|
|
@@ -932,13 +993,6 @@ export const styles = css `
|
|
|
932
993
|
display: inline-flex;
|
|
933
994
|
}
|
|
934
995
|
|
|
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
996
|
/* 1. The sparkline stays at every size; it only goes when the card is too short for anything else. */
|
|
943
997
|
@container (max-height: 72px) {
|
|
944
998
|
:host([variant='compact']) .kpi-sparkline {
|
|
@@ -8,6 +8,8 @@ export type SparklineType = 'area' | 'line' | 'column' | 'bar' | 'spline' | 'are
|
|
|
8
8
|
export type KpiValueFormat = 'auto' | 'K' | 'M' | 'B' | 'T' | 'none';
|
|
9
9
|
export type KpiNumberSystem = 'indian' | 'international';
|
|
10
10
|
export type KpiInfoPlacement = 'top-right' | 'center-right' | 'bottom-right' | 'top-left' | 'center-left' | 'bottom-left';
|
|
11
|
+
/** How compact titles handle an oversized word: `'ellipsis'` cuts it with `…`, `'break'` splits it. */
|
|
12
|
+
export type KpiTitleOverflow = 'ellipsis' | 'break';
|
|
11
13
|
/** `chart` slice for `<nile-kpi-chart>.config` (discriminated by `type: 'kpi'`). */
|
|
12
14
|
export interface ChartKpiSeparatedPayload {
|
|
13
15
|
type: 'kpi';
|
|
@@ -82,6 +84,8 @@ export interface ChartKpiSeparatedPayload {
|
|
|
82
84
|
loadingText?: string;
|
|
83
85
|
/** Whether the hover tooltip is shown on value / sparkline / gauge (default: true). */
|
|
84
86
|
tooltipEnabled?: boolean;
|
|
87
|
+
/** How the compact title handles text that doesn't fit; see `KpiTitleOverflow`. */
|
|
88
|
+
titleOverflow?: KpiTitleOverflow;
|
|
85
89
|
/** Accent bar colour for the 'accent' variant (default: brand blue). */
|
|
86
90
|
accentColor?: string;
|
|
87
91
|
cardBackground?: string;
|
|
@@ -149,6 +153,8 @@ export declare class NileKpiChart extends NileElement {
|
|
|
149
153
|
private sparklineChart;
|
|
150
154
|
private gaugeChart;
|
|
151
155
|
private resizeObserver;
|
|
156
|
+
/** Pending late re-check of the sparkline size (see initSparkline). */
|
|
157
|
+
private _sparkSettleTimer;
|
|
152
158
|
/** Latched once the fit safety-net has fallen back to inline-size (see _reconcileFit). */
|
|
153
159
|
private _fitInlineFallback;
|
|
154
160
|
/** Tooltip element on document.body — outside shadow DOM, never clipped. */
|
|
@@ -264,6 +270,8 @@ export declare class NileKpiChart extends NileElement {
|
|
|
264
270
|
loadingText: string;
|
|
265
271
|
/** Whether the hover tooltip is shown on value / sparkline / gauge. */
|
|
266
272
|
tooltipEnabled: boolean;
|
|
273
|
+
/** How the compact title handles text that doesn't fit; see `KpiTitleOverflow`. */
|
|
274
|
+
titleOverflow: KpiTitleOverflow;
|
|
267
275
|
cardBackground: string;
|
|
268
276
|
cardBorderColor: string;
|
|
269
277
|
cardBorderWidth: string | number;
|
|
@@ -350,9 +358,7 @@ export declare class NileKpiChart extends NileElement {
|
|
|
350
358
|
*/
|
|
351
359
|
private _fitDescription;
|
|
352
360
|
/**
|
|
353
|
-
* True when `el`
|
|
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.
|
|
361
|
+
* 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.
|
|
356
362
|
*/
|
|
357
363
|
private _isLabelTruncated;
|
|
358
364
|
private _syncTruncationTips;
|
|
@@ -373,8 +379,7 @@ export declare class NileKpiChart extends NileElement {
|
|
|
373
379
|
/** Mirrors the header slots' content onto the host (`has-header-lead` / `has-header-actions`). */
|
|
374
380
|
private _onHeaderSlotChange;
|
|
375
381
|
/**
|
|
376
|
-
*
|
|
377
|
-
* them (its first lines are shortened by a spacer of this size) and uses the full width below.
|
|
382
|
+
* Sizes the spacer the title wraps around beside floating header controls; compact lays them out side by side and skips it.
|
|
378
383
|
*/
|
|
379
384
|
private _controlsObserved;
|
|
380
385
|
private _syncHeaderControls;
|
|
@@ -23,6 +23,8 @@ let NileKpiChart = class NileKpiChart extends NileElement {
|
|
|
23
23
|
this.sparklineChart = null;
|
|
24
24
|
this.gaugeChart = null;
|
|
25
25
|
this.resizeObserver = null;
|
|
26
|
+
/** Pending late re-check of the sparkline size (see initSparkline). */
|
|
27
|
+
this._sparkSettleTimer = null;
|
|
26
28
|
/** Latched once the fit safety-net has fallen back to inline-size (see _reconcileFit). */
|
|
27
29
|
this._fitInlineFallback = false;
|
|
28
30
|
/** Tooltip element on document.body — outside shadow DOM, never clipped. */
|
|
@@ -136,6 +138,8 @@ let NileKpiChart = class NileKpiChart extends NileElement {
|
|
|
136
138
|
this.loadingText = 'Loading...';
|
|
137
139
|
/** Whether the hover tooltip is shown on value / sparkline / gauge. */
|
|
138
140
|
this.tooltipEnabled = true;
|
|
141
|
+
/** How the compact title handles text that doesn't fit; see `KpiTitleOverflow`. */
|
|
142
|
+
this.titleOverflow = 'ellipsis';
|
|
139
143
|
// ── Card chrome ──
|
|
140
144
|
this.cardBackground = '';
|
|
141
145
|
this.cardBorderColor = '';
|
|
@@ -252,8 +256,7 @@ let NileKpiChart = class NileKpiChart extends NileElement {
|
|
|
252
256
|
this._syncHeaderControls();
|
|
253
257
|
};
|
|
254
258
|
/**
|
|
255
|
-
*
|
|
256
|
-
* them (its first lines are shortened by a spacer of this size) and uses the full width below.
|
|
259
|
+
* Sizes the spacer the title wraps around beside floating header controls; compact lays them out side by side and skips it.
|
|
257
260
|
*/
|
|
258
261
|
this._controlsObserved = null;
|
|
259
262
|
}
|
|
@@ -273,10 +276,27 @@ let NileKpiChart = class NileKpiChart extends NileElement {
|
|
|
273
276
|
_showTip(text, x, y) {
|
|
274
277
|
if (!this._tipEl || !this.tooltipEnabled)
|
|
275
278
|
return;
|
|
276
|
-
this._tipEl
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
279
|
+
const tip = this._tipEl;
|
|
280
|
+
tip.textContent = text;
|
|
281
|
+
tip.style.left = `${x}px`;
|
|
282
|
+
tip.style.top = `${y}px`;
|
|
283
|
+
tip.removeAttribute('data-placement');
|
|
284
|
+
tip.style.removeProperty('--nile-kpi-tip-arrow-x');
|
|
285
|
+
tip.style.display = 'block';
|
|
286
|
+
// Centred on the point; shifted back inside the window (the arrow follows) and flipped below when there is no room above.
|
|
287
|
+
const margin = 8;
|
|
288
|
+
const gap = 10;
|
|
289
|
+
const vw = document.documentElement.clientWidth;
|
|
290
|
+
const { width, height } = tip.getBoundingClientRect();
|
|
291
|
+
const half = width / 2;
|
|
292
|
+
const left = width + margin * 2 > vw ? vw / 2 : Math.min(Math.max(x, half + margin), vw - half - margin);
|
|
293
|
+
if (left !== x) {
|
|
294
|
+
tip.style.left = `${left}px`;
|
|
295
|
+
const arrowX = Math.min(Math.max(half + (x - left), 12), width - 12);
|
|
296
|
+
tip.style.setProperty('--nile-kpi-tip-arrow-x', `${arrowX}px`);
|
|
297
|
+
}
|
|
298
|
+
if (y - height - gap < margin)
|
|
299
|
+
tip.setAttribute('data-placement', 'bottom');
|
|
280
300
|
}
|
|
281
301
|
_showMarker(x, y, color) {
|
|
282
302
|
if (!this._markerEl || !this.tooltipEnabled)
|
|
@@ -586,6 +606,8 @@ let NileKpiChart = class NileKpiChart extends NileElement {
|
|
|
586
606
|
this.loadingText = c.loadingText;
|
|
587
607
|
if (c.tooltipEnabled !== undefined)
|
|
588
608
|
this.tooltipEnabled = c.tooltipEnabled;
|
|
609
|
+
if (c.titleOverflow !== undefined)
|
|
610
|
+
this.titleOverflow = c.titleOverflow;
|
|
589
611
|
if (c.accentColor !== undefined)
|
|
590
612
|
this.accentColor = c.accentColor;
|
|
591
613
|
if (c.cardBackground !== undefined)
|
|
@@ -700,7 +722,12 @@ let NileKpiChart = class NileKpiChart extends NileElement {
|
|
|
700
722
|
this.initGauge();
|
|
701
723
|
this.setupResizeObserver();
|
|
702
724
|
requestAnimationFrame(() => this._reconcileFit());
|
|
703
|
-
|
|
725
|
+
// Web fonts change how the title wraps, which changes how much room the rest of the card has.
|
|
726
|
+
void document.fonts?.ready.then(() => {
|
|
727
|
+
if (this.variant === 'compact')
|
|
728
|
+
this._fitDescription(true);
|
|
729
|
+
this._syncTruncationTips();
|
|
730
|
+
});
|
|
704
731
|
}
|
|
705
732
|
updated(changedProperties) {
|
|
706
733
|
const hasValue = this.value !== '' && this.value !== null && this.value !== undefined;
|
|
@@ -803,10 +830,12 @@ let NileKpiChart = class NileKpiChart extends NileElement {
|
|
|
803
830
|
const drawn = chart.container;
|
|
804
831
|
const prevDisplay = drawn.style.display;
|
|
805
832
|
drawn.style.display = 'none';
|
|
806
|
-
|
|
833
|
+
// Layout size, not getBoundingClientRect(): the latter includes transforms, which ResizeObserver can't see change.
|
|
834
|
+
const boxW = this.sparklineContainer.offsetWidth;
|
|
835
|
+
const boxH = this.sparklineContainer.offsetHeight;
|
|
807
836
|
drawn.style.display = prevDisplay;
|
|
808
|
-
const w = Math.max(1,
|
|
809
|
-
const h = Math.max(22,
|
|
837
|
+
const w = Math.max(1, boxW);
|
|
838
|
+
const h = Math.max(22, boxH);
|
|
810
839
|
if (w === chart.chartWidth && h === chart.chartHeight)
|
|
811
840
|
return;
|
|
812
841
|
chart.update({ chart: { width: w, height: h } }, true, false, false);
|
|
@@ -1059,6 +1088,14 @@ let NileKpiChart = class NileKpiChart extends NileElement {
|
|
|
1059
1088
|
this.syncSparklineChartSize();
|
|
1060
1089
|
requestAnimationFrame(() => this.syncSparklineChartSize());
|
|
1061
1090
|
});
|
|
1091
|
+
// Re-check once layout settles: a wrapper that sizes after the chart is built can leave the observer a step behind.
|
|
1092
|
+
const chart = this.sparklineChart;
|
|
1093
|
+
const resync = () => {
|
|
1094
|
+
if (this.sparklineChart === chart && this.isConnected)
|
|
1095
|
+
this.syncSparklineChartSize();
|
|
1096
|
+
};
|
|
1097
|
+
void document.fonts?.ready.then(resync);
|
|
1098
|
+
this._sparkSettleTimer = window.setTimeout(resync, 250);
|
|
1062
1099
|
this.sparklineContainer.addEventListener('mousemove', this._onSparklineMouseMove);
|
|
1063
1100
|
this.sparklineContainer.addEventListener('mouseleave', this._onSparklineMouseLeave);
|
|
1064
1101
|
this.emit('nile-chart-ready', { chart: this.sparklineChart });
|
|
@@ -1080,6 +1117,10 @@ let NileKpiChart = class NileKpiChart extends NileElement {
|
|
|
1080
1117
|
this.emit('nile-chart-ready', { chart: this.gaugeChart });
|
|
1081
1118
|
}
|
|
1082
1119
|
destroySparkline() {
|
|
1120
|
+
if (this._sparkSettleTimer !== null) {
|
|
1121
|
+
clearTimeout(this._sparkSettleTimer);
|
|
1122
|
+
this._sparkSettleTimer = null;
|
|
1123
|
+
}
|
|
1083
1124
|
if (this.sparklineContainer) {
|
|
1084
1125
|
this.sparklineContainer.removeEventListener('mousemove', this._onSparklineMouseMove);
|
|
1085
1126
|
this.sparklineContainer.removeEventListener('mouseleave', this._onSparklineMouseLeave);
|
|
@@ -1125,13 +1166,33 @@ let NileKpiChart = class NileKpiChart extends NileElement {
|
|
|
1125
1166
|
return;
|
|
1126
1167
|
this._fitSize = size;
|
|
1127
1168
|
this.removeAttribute('data-hide-desc');
|
|
1169
|
+
this.removeAttribute('data-hide-spark');
|
|
1170
|
+
this.style.removeProperty('--kpi-title-lines');
|
|
1128
1171
|
if (kpi.scrollHeight > kpi.clientHeight + 1)
|
|
1129
1172
|
this.setAttribute('data-hide-desc', '');
|
|
1173
|
+
// Compact is all-or-nothing: hide the sparkline whole when the title leaves it less than its minimum height.
|
|
1174
|
+
if (this.variant === 'compact') {
|
|
1175
|
+
const spark = this.shadowRoot?.querySelector('.kpi-sparkline');
|
|
1176
|
+
if (spark &&
|
|
1177
|
+
getComputedStyle(spark).display !== 'none' &&
|
|
1178
|
+
spark.getBoundingClientRect().bottom > kpi.getBoundingClientRect().bottom + 4) {
|
|
1179
|
+
this.setAttribute('data-hide-spark', '');
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
// Give title lines back (3 -> 2 -> 1) only while the value still overflows the card.
|
|
1183
|
+
const text = this.variant === 'compact' ? this.shadowRoot?.querySelector('.kpi-label-text') : null;
|
|
1184
|
+
if (text && text.getBoundingClientRect().height > 0) {
|
|
1185
|
+
const lineHeight = parseFloat(getComputedStyle(text).lineHeight) || 0;
|
|
1186
|
+
const showsMoreThan = (n) => text.getBoundingClientRect().height > lineHeight * (n + 0.5);
|
|
1187
|
+
for (let lines = 2; lines >= 1; lines--) {
|
|
1188
|
+
if (!lineHeight || !showsMoreThan(lines) || kpi.scrollHeight <= kpi.clientHeight + 1)
|
|
1189
|
+
break;
|
|
1190
|
+
this.style.setProperty('--kpi-title-lines', String(lines));
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1130
1193
|
}
|
|
1131
1194
|
/**
|
|
1132
|
-
* True when `el`
|
|
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.
|
|
1195
|
+
* 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.
|
|
1135
1196
|
*/
|
|
1136
1197
|
_isLabelTruncated(el, isLabel) {
|
|
1137
1198
|
if (el.scrollWidth > el.clientWidth)
|
|
@@ -1141,14 +1202,34 @@ let NileKpiChart = class NileKpiChart extends NileElement {
|
|
|
1141
1202
|
return true;
|
|
1142
1203
|
if (!isLabel)
|
|
1143
1204
|
return el.scrollHeight > el.clientHeight + 1;
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1205
|
+
if (this.variant !== 'compact') {
|
|
1206
|
+
// Non-compact: the clamp is on the <p> itself.
|
|
1207
|
+
const clamped = el.clientHeight;
|
|
1208
|
+
const prev = el.style.getPropertyValue('-webkit-line-clamp');
|
|
1209
|
+
el.style.setProperty('-webkit-line-clamp', 'unset');
|
|
1210
|
+
const full = el.scrollHeight;
|
|
1211
|
+
if (prev)
|
|
1212
|
+
el.style.setProperty('-webkit-line-clamp', prev);
|
|
1213
|
+
else
|
|
1214
|
+
el.style.removeProperty('-webkit-line-clamp');
|
|
1215
|
+
return full > clamped + 1;
|
|
1216
|
+
}
|
|
1217
|
+
if (!text)
|
|
1218
|
+
return false;
|
|
1219
|
+
const clamped = text.clientHeight;
|
|
1220
|
+
const prev = text.style.getPropertyValue('-webkit-line-clamp');
|
|
1221
|
+
const prevStd = text.style.getPropertyValue('line-clamp');
|
|
1222
|
+
text.style.setProperty('-webkit-line-clamp', 'unset');
|
|
1223
|
+
text.style.setProperty('line-clamp', 'unset');
|
|
1224
|
+
const full = text.scrollHeight;
|
|
1148
1225
|
if (prev)
|
|
1149
|
-
|
|
1226
|
+
text.style.setProperty('-webkit-line-clamp', prev);
|
|
1227
|
+
else
|
|
1228
|
+
text.style.removeProperty('-webkit-line-clamp');
|
|
1229
|
+
if (prevStd)
|
|
1230
|
+
text.style.setProperty('line-clamp', prevStd);
|
|
1150
1231
|
else
|
|
1151
|
-
|
|
1232
|
+
text.style.removeProperty('line-clamp');
|
|
1152
1233
|
return full > clamped + 1;
|
|
1153
1234
|
}
|
|
1154
1235
|
_syncTruncationTips() {
|
|
@@ -1263,6 +1344,8 @@ let NileKpiChart = class NileKpiChart extends NileElement {
|
|
|
1263
1344
|
`;
|
|
1264
1345
|
}
|
|
1265
1346
|
_syncHeaderControls() {
|
|
1347
|
+
if (this.variant === 'compact')
|
|
1348
|
+
return;
|
|
1266
1349
|
const header = this.shadowRoot?.querySelector('.kpi-header');
|
|
1267
1350
|
const controls = header?.querySelector('.kpi-header-controls');
|
|
1268
1351
|
if (!header || !controls)
|
|
@@ -1534,6 +1617,9 @@ __decorate([
|
|
|
1534
1617
|
__decorate([
|
|
1535
1618
|
property({ type: Boolean, attribute: 'tooltip-enabled' })
|
|
1536
1619
|
], NileKpiChart.prototype, "tooltipEnabled", void 0);
|
|
1620
|
+
__decorate([
|
|
1621
|
+
property({ type: String, attribute: 'title-overflow', reflect: true })
|
|
1622
|
+
], NileKpiChart.prototype, "titleOverflow", void 0);
|
|
1537
1623
|
__decorate([
|
|
1538
1624
|
property({ type: String, attribute: 'card-background' })
|
|
1539
1625
|
], NileKpiChart.prototype, "cardBackground", void 0);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './nile-kpi-chart';
|
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
/** Tests for <nile-kpi-chart>: sparkline tooltip placement, compact title overflow, sparkline sizing. */
|
|
2
|
+
import { expect, fixture, html } from '@open-wc/testing';
|
|
3
|
+
import './nile-kpi-chart';
|
|
4
|
+
const LONG = '8 accounts waiting for review across all regions';
|
|
5
|
+
describe('NileKpiChart sparkline tooltip placement', () => {
|
|
6
|
+
let el;
|
|
7
|
+
let host;
|
|
8
|
+
const vw = () => document.documentElement.clientWidth;
|
|
9
|
+
beforeEach(async () => {
|
|
10
|
+
el = await fixture(html `<nile-kpi-chart></nile-kpi-chart>`);
|
|
11
|
+
host = el;
|
|
12
|
+
host._createTipEl();
|
|
13
|
+
});
|
|
14
|
+
afterEach(() => {
|
|
15
|
+
host._hideTip();
|
|
16
|
+
document.querySelectorAll('.nile-kpi-tooltip, .nile-kpi-marker').forEach((n) => n.remove());
|
|
17
|
+
});
|
|
18
|
+
it('sizes to its text at the window edge instead of one character per line', () => {
|
|
19
|
+
host._showTip(LONG, vw(), 300);
|
|
20
|
+
const r = host._tipEl.getBoundingClientRect();
|
|
21
|
+
expect(r.width).to.be.greaterThan(100);
|
|
22
|
+
expect(r.height).to.be.lessThan(120); // two or three lines, not a tall column
|
|
23
|
+
});
|
|
24
|
+
it('stays inside the window at the right edge and keeps the arrow on the point', () => {
|
|
25
|
+
host._showTip(LONG, vw(), 300);
|
|
26
|
+
const r = host._tipEl.getBoundingClientRect();
|
|
27
|
+
expect(r.right).to.be.at.most(vw());
|
|
28
|
+
expect(r.left).to.be.at.least(0);
|
|
29
|
+
const arrowX = parseFloat(host._tipEl.style.getPropertyValue('--nile-kpi-tip-arrow-x'));
|
|
30
|
+
expect(arrowX).to.be.greaterThan(r.width / 2); // arrow moved right of centre, toward the point
|
|
31
|
+
expect(arrowX).to.be.at.most(r.width - 12);
|
|
32
|
+
});
|
|
33
|
+
it('stays inside the window at the left edge', () => {
|
|
34
|
+
host._showTip(LONG, 0, 300);
|
|
35
|
+
const r = host._tipEl.getBoundingClientRect();
|
|
36
|
+
expect(r.left).to.be.at.least(0);
|
|
37
|
+
expect(parseFloat(host._tipEl.style.getPropertyValue('--nile-kpi-tip-arrow-x'))).to.be.lessThan(r.width / 2);
|
|
38
|
+
});
|
|
39
|
+
it('is centred on the point, with a centred arrow, when there is room', () => {
|
|
40
|
+
const x = Math.round(vw() / 2);
|
|
41
|
+
host._showTip('42', x, 300);
|
|
42
|
+
expect(host._tipEl.style.left).to.equal(`${x}px`);
|
|
43
|
+
expect(host._tipEl.style.getPropertyValue('--nile-kpi-tip-arrow-x')).to.equal('');
|
|
44
|
+
expect(host._tipEl.hasAttribute('data-placement')).to.be.false;
|
|
45
|
+
});
|
|
46
|
+
it('flips below the point when there is no room above', () => {
|
|
47
|
+
host._showTip(LONG, Math.round(vw() / 2), 10);
|
|
48
|
+
expect(host._tipEl.getAttribute('data-placement')).to.equal('bottom');
|
|
49
|
+
expect(host._tipEl.getBoundingClientRect().top).to.be.at.least(10);
|
|
50
|
+
});
|
|
51
|
+
it('clears the previous shift and flip on the next call', () => {
|
|
52
|
+
host._showTip(LONG, vw(), 10);
|
|
53
|
+
host._showTip('42', Math.round(vw() / 2), 300);
|
|
54
|
+
expect(host._tipEl.hasAttribute('data-placement')).to.be.false;
|
|
55
|
+
expect(host._tipEl.style.getPropertyValue('--nile-kpi-tip-arrow-x')).to.equal('');
|
|
56
|
+
});
|
|
57
|
+
it('is never wider than the window minus its margins (padding and border count toward the cap)', () => {
|
|
58
|
+
host._showTip(LONG.repeat(4), Math.round(vw() / 2), 300);
|
|
59
|
+
const r = host._tipEl.getBoundingClientRect();
|
|
60
|
+
expect(r.width).to.be.at.most(Math.min(260, vw() - 16) + 0.5);
|
|
61
|
+
expect(r.left).to.be.at.least(0);
|
|
62
|
+
expect(r.right).to.be.at.most(vw());
|
|
63
|
+
});
|
|
64
|
+
it('keeps a z-index of 2', () => {
|
|
65
|
+
host._showTip('42', 100, 300);
|
|
66
|
+
expect(getComputedStyle(host._tipEl).zIndex).to.equal('2');
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
describe('NileKpiChart title overflow', () => {
|
|
70
|
+
// the wrapping matrix covers compact; the other variants are asserted separately below
|
|
71
|
+
const VARIANTS = ['compact'];
|
|
72
|
+
const OTHER_VARIANTS = ['default', 'card'];
|
|
73
|
+
const CONTROLS = {
|
|
74
|
+
none: [],
|
|
75
|
+
lead: ['header-lead'],
|
|
76
|
+
actions: ['header-actions'],
|
|
77
|
+
both: ['header-lead', 'header-actions'],
|
|
78
|
+
};
|
|
79
|
+
const SHORT = 'Revenue';
|
|
80
|
+
const WORD = 'Supercalifragilisticexpialidocious'; // one word far wider than a 170px card
|
|
81
|
+
const WORD_PLUS = 'Supercalifragilisticexpialidocious Overview';
|
|
82
|
+
const LONG = 'one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen'; // > 3 lines everywhere
|
|
83
|
+
const mount = async (label, o = {}) => {
|
|
84
|
+
const wrap = await fixture(html `<div
|
|
85
|
+
style="width:${o.width ?? 170}px;height:${o.height ?? 212}px"
|
|
86
|
+
>
|
|
87
|
+
<nile-kpi-chart fit style="width:100%;height:100%"></nile-kpi-chart>
|
|
88
|
+
</div>`);
|
|
89
|
+
const el = wrap.querySelector('nile-kpi-chart');
|
|
90
|
+
if (o.overflow)
|
|
91
|
+
el.setAttribute('title-overflow', o.overflow);
|
|
92
|
+
for (const slot of o.slots ?? []) {
|
|
93
|
+
const b = document.createElement('button');
|
|
94
|
+
b.slot = slot;
|
|
95
|
+
b.textContent = 'x';
|
|
96
|
+
b.style.cssText = 'width:24px;height:24px;padding:0;border:0';
|
|
97
|
+
el.appendChild(b);
|
|
98
|
+
}
|
|
99
|
+
el.config = {
|
|
100
|
+
chart: {
|
|
101
|
+
type: 'kpi',
|
|
102
|
+
variant: (o.variant ?? 'compact'),
|
|
103
|
+
label,
|
|
104
|
+
value: '285K',
|
|
105
|
+
trendValue: 12.5,
|
|
106
|
+
trendDirection: 'up',
|
|
107
|
+
},
|
|
108
|
+
aq: {},
|
|
109
|
+
};
|
|
110
|
+
await el.updateComplete;
|
|
111
|
+
await el.updateComplete; // config is applied in updated(), which schedules a second update
|
|
112
|
+
await new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r)));
|
|
113
|
+
return el;
|
|
114
|
+
};
|
|
115
|
+
const parts = (el) => {
|
|
116
|
+
const root = el.shadowRoot;
|
|
117
|
+
const label = root.querySelector('.kpi-label');
|
|
118
|
+
const text = root.querySelector('.kpi-label-text');
|
|
119
|
+
const tip = root.querySelector('nile-lite-tooltip[data-kpi-tip="label"]');
|
|
120
|
+
return { label, text, tip, header: root.querySelector('.kpi-header') };
|
|
121
|
+
};
|
|
122
|
+
const lineCount = (el) => {
|
|
123
|
+
const { label, text } = parts(el);
|
|
124
|
+
return Math.round(text.getBoundingClientRect().height / parseFloat(getComputedStyle(label).lineHeight));
|
|
125
|
+
};
|
|
126
|
+
const cutSideways = (el) => {
|
|
127
|
+
const { text } = parts(el);
|
|
128
|
+
return text.scrollWidth > text.clientWidth + 1;
|
|
129
|
+
};
|
|
130
|
+
const tooltipOn = (el) => parts(el).tip.disabled === false;
|
|
131
|
+
for (const variant of VARIANTS) {
|
|
132
|
+
for (const [controls, slots] of Object.entries(CONTROLS)) {
|
|
133
|
+
describe(`${variant} + ${controls}`, () => {
|
|
134
|
+
it('ellipsis: normal words wrap, capped at 3 lines, the rest ends in … with the full title in the tooltip', async () => {
|
|
135
|
+
const el = await mount(LONG, { variant, slots, overflow: 'ellipsis' });
|
|
136
|
+
const { label, text, tip } = parts(el);
|
|
137
|
+
expect(getComputedStyle(label).whiteSpace).to.not.equal('nowrap');
|
|
138
|
+
expect(getComputedStyle(text).webkitLineClamp).to.equal('3');
|
|
139
|
+
expect(getComputedStyle(text).textOverflow).to.equal('ellipsis');
|
|
140
|
+
expect(lineCount(el)).to.equal(3);
|
|
141
|
+
expect(tooltipOn(el)).to.be.true;
|
|
142
|
+
expect(tip.getAttribute('content')).to.equal(LONG);
|
|
143
|
+
});
|
|
144
|
+
it('ellipsis: a word wider than the line is cut with …, not split', async () => {
|
|
145
|
+
const el = await mount(WORD_PLUS, { variant, slots, overflow: 'ellipsis' });
|
|
146
|
+
expect(getComputedStyle(parts(el).text).overflowWrap).to.equal('normal');
|
|
147
|
+
expect(cutSideways(el)).to.be.true;
|
|
148
|
+
expect(tooltipOn(el)).to.be.true;
|
|
149
|
+
expect(parts(el).tip.getAttribute('content')).to.equal(WORD_PLUS);
|
|
150
|
+
});
|
|
151
|
+
it('break: a word wider than the line is split across lines, not cut sideways', async () => {
|
|
152
|
+
const el = await mount(WORD, { variant, slots, overflow: 'break' });
|
|
153
|
+
expect(getComputedStyle(parts(el).text).overflowWrap).to.equal('anywhere');
|
|
154
|
+
expect(cutSideways(el)).to.be.false;
|
|
155
|
+
expect(lineCount(el)).to.be.within(2, 3);
|
|
156
|
+
});
|
|
157
|
+
it('break: text past line 3 is truncated with the full title in the tooltip', async () => {
|
|
158
|
+
const el = await mount(LONG, { variant, slots, overflow: 'break' });
|
|
159
|
+
expect(getComputedStyle(parts(el).text).webkitLineClamp).to.equal('3');
|
|
160
|
+
expect(lineCount(el)).to.equal(3);
|
|
161
|
+
expect(tooltipOn(el)).to.be.true;
|
|
162
|
+
expect(parts(el).tip.getAttribute('content')).to.equal(LONG);
|
|
163
|
+
});
|
|
164
|
+
for (const overflow of ['ellipsis', 'break', null]) {
|
|
165
|
+
it(`no tooltip when the whole title is visible (title-overflow ${overflow ?? 'default'})`, async () => {
|
|
166
|
+
const el = await mount(SHORT, { variant, slots, overflow });
|
|
167
|
+
expect(lineCount(el)).to.equal(1);
|
|
168
|
+
expect(cutSideways(el)).to.be.false;
|
|
169
|
+
expect(tooltipOn(el)).to.be.false;
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
it('the first title line starts level with the top of the header', async () => {
|
|
173
|
+
for (const overflow of ['ellipsis', 'break']) {
|
|
174
|
+
const el = await mount('Transaction Failure Rate Overview', {
|
|
175
|
+
variant,
|
|
176
|
+
slots,
|
|
177
|
+
overflow,
|
|
178
|
+
});
|
|
179
|
+
const { text, header } = parts(el);
|
|
180
|
+
const range = document.createRange();
|
|
181
|
+
range.selectNodeContents(text);
|
|
182
|
+
expect(range.getClientRects()[0].top - header.getBoundingClientRect().top, overflow).to.be.lessThan(4);
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
describe('header controls only change the width, not whether the title wraps', () => {
|
|
189
|
+
for (const variant of VARIANTS) {
|
|
190
|
+
it(`${variant}: wrapping, clamp and overflow-wrap are identical with and without controls`, async () => {
|
|
191
|
+
const snapshot = async (slots, overflow) => {
|
|
192
|
+
const { label, text } = parts(await mount(LONG, { variant, slots, overflow }));
|
|
193
|
+
return [
|
|
194
|
+
getComputedStyle(label).whiteSpace,
|
|
195
|
+
getComputedStyle(text).display,
|
|
196
|
+
getComputedStyle(text).webkitLineClamp,
|
|
197
|
+
getComputedStyle(text).overflowWrap,
|
|
198
|
+
].join('|');
|
|
199
|
+
};
|
|
200
|
+
for (const overflow of ['ellipsis', 'break', null]) {
|
|
201
|
+
const none = await snapshot([], overflow);
|
|
202
|
+
for (const slots of [
|
|
203
|
+
['header-lead'],
|
|
204
|
+
['header-actions'],
|
|
205
|
+
['header-lead', 'header-actions'],
|
|
206
|
+
]) {
|
|
207
|
+
expect(await snapshot(slots, overflow), `${slots.join('+')} / ${overflow ?? 'default'}`).to.equal(none);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
it('a compact card without controls wraps', async () => {
|
|
213
|
+
const el = await mount('Monthly recurring revenue by region and product line');
|
|
214
|
+
expect(parts(el).label.hasAttribute('has-header-actions')).to.be.false;
|
|
215
|
+
expect(el.hasAttribute('has-header-lead')).to.be.false;
|
|
216
|
+
expect(el.hasAttribute('has-header-actions')).to.be.false;
|
|
217
|
+
expect(lineCount(el)).to.be.greaterThan(1);
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
describe('non-compact variants keep a single-line title and floating header controls', () => {
|
|
221
|
+
for (const variant of OTHER_VARIANTS) {
|
|
222
|
+
it(`${variant} without controls: one line cut with …, no 3-line clamp, title-overflow has no effect`, async () => {
|
|
223
|
+
for (const overflow of ['ellipsis', 'break', null]) {
|
|
224
|
+
const el = await mount(LONG, { variant, overflow });
|
|
225
|
+
const { label, text } = parts(el);
|
|
226
|
+
expect(getComputedStyle(label).whiteSpace, String(overflow)).to.equal('nowrap');
|
|
227
|
+
expect(getComputedStyle(label).textOverflow).to.equal('ellipsis');
|
|
228
|
+
expect(getComputedStyle(text).display).to.not.equal('-webkit-box');
|
|
229
|
+
expect(getComputedStyle(text).overflowWrap).to.not.equal('anywhere');
|
|
230
|
+
expect(lineCount(el)).to.equal(1);
|
|
231
|
+
expect(tooltipOn(el)).to.be.true;
|
|
232
|
+
expect(parts(el).tip.getAttribute('content')).to.equal(LONG);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
for (const [controls, slots] of Object.entries(CONTROLS)) {
|
|
236
|
+
if (!slots.length)
|
|
237
|
+
continue;
|
|
238
|
+
it(`${variant} + ${controls}: keeps the title wrapping around floating controls with the 4-line cap`, async () => {
|
|
239
|
+
const el = await mount(LONG, { variant, slots, overflow: 'break' });
|
|
240
|
+
const { label, header } = parts(el);
|
|
241
|
+
expect(getComputedStyle(header).display).to.equal('block');
|
|
242
|
+
expect(getComputedStyle(header).position).to.equal('relative');
|
|
243
|
+
expect(getComputedStyle(label).display).to.equal('-webkit-box');
|
|
244
|
+
expect(getComputedStyle(label).webkitLineClamp).to.be.oneOf(['4', '3', '2']);
|
|
245
|
+
expect(getComputedStyle(parts(el).text).overflowWrap).to.not.equal('anywhere');
|
|
246
|
+
expect(header.style.getPropertyValue('--kpi-controls-w')).to.not.equal('');
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
describe('property and config', () => {
|
|
252
|
+
it("defaults to 'ellipsis' (reflected), which is what a card with no attribute behaves like", async () => {
|
|
253
|
+
const el = await mount(WORD_PLUS);
|
|
254
|
+
expect(el.titleOverflow).to.equal('ellipsis');
|
|
255
|
+
expect(el.getAttribute('title-overflow')).to.equal('ellipsis');
|
|
256
|
+
expect(getComputedStyle(parts(el).text).overflowWrap).to.equal('normal');
|
|
257
|
+
expect(cutSideways(el)).to.be.true;
|
|
258
|
+
});
|
|
259
|
+
it('can be set from config.chart.titleOverflow', async () => {
|
|
260
|
+
const el = await mount(WORD);
|
|
261
|
+
el.config = {
|
|
262
|
+
chart: {
|
|
263
|
+
type: 'kpi',
|
|
264
|
+
variant: 'compact',
|
|
265
|
+
label: WORD,
|
|
266
|
+
value: '285K',
|
|
267
|
+
titleOverflow: 'break',
|
|
268
|
+
},
|
|
269
|
+
aq: {},
|
|
270
|
+
};
|
|
271
|
+
await el.updateComplete;
|
|
272
|
+
await el.updateComplete;
|
|
273
|
+
expect(el.titleOverflow).to.equal('break');
|
|
274
|
+
expect(el.getAttribute('title-overflow')).to.equal('break');
|
|
275
|
+
expect(getComputedStyle(parts(el).text).overflowWrap).to.equal('anywhere');
|
|
276
|
+
});
|
|
277
|
+
it('an unknown value behaves like ellipsis', async () => {
|
|
278
|
+
const el = await mount(WORD_PLUS);
|
|
279
|
+
el.titleOverflow = 'nonsense';
|
|
280
|
+
await el.updateComplete;
|
|
281
|
+
expect(getComputedStyle(parts(el).text).overflowWrap).to.equal('normal');
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
describe('the title does not push the rest of the card out', () => {
|
|
285
|
+
it('keeps the value inside the card at every height while the title has 3 lines', async () => {
|
|
286
|
+
for (const height of [100, 126, 160, 212, 320]) {
|
|
287
|
+
const el = await mount(LONG, { height, slots: ['header-actions'] });
|
|
288
|
+
const value = el.shadowRoot.querySelector('.kpi-value');
|
|
289
|
+
expect(value.getBoundingClientRect().bottom, `height ${height}`).to.be.at.most(el.getBoundingClientRect().bottom + 1);
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
// a stand-in box with the real compact sparkline styles replaces Highcharts, which the test browser can't load
|
|
293
|
+
const withSparkline = async (label, height) => {
|
|
294
|
+
const el = await mount(label, { height });
|
|
295
|
+
const box = document.createElement('div');
|
|
296
|
+
box.className = 'kpi-sparkline';
|
|
297
|
+
el.shadowRoot.querySelector('.kpi--compact').appendChild(box);
|
|
298
|
+
el._fitDescription(true);
|
|
299
|
+
return { el, box };
|
|
300
|
+
};
|
|
301
|
+
it('hides the compact sparkline whole when a 3-line title leaves it less than its minimum height', async () => {
|
|
302
|
+
const { el, box } = await withSparkline(LONG, 100);
|
|
303
|
+
expect(el.hasAttribute('data-hide-spark')).to.be.true;
|
|
304
|
+
expect(getComputedStyle(box).display).to.equal('none');
|
|
305
|
+
});
|
|
306
|
+
it('keeps the sparkline when it fits (short title, or a tall card)', async () => {
|
|
307
|
+
for (const [label, height] of [
|
|
308
|
+
[SHORT, 100],
|
|
309
|
+
[LONG, 260],
|
|
310
|
+
]) {
|
|
311
|
+
const { el, box } = await withSparkline(label, height);
|
|
312
|
+
expect(el.hasAttribute('data-hide-spark'), `${label.slice(0, 7)} @ ${height}`).to.be.false;
|
|
313
|
+
expect(getComputedStyle(box).display).to.not.equal('none');
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
describe('NileKpiChart sparkline size under a transform', () => {
|
|
319
|
+
const setup = async (scale) => {
|
|
320
|
+
const wrap = await fixture(html ` <div
|
|
321
|
+
style="width:148px;transform:scale(${scale});transform-origin:left top"
|
|
322
|
+
>
|
|
323
|
+
<nile-kpi-chart variant="compact" style="display:block;width:100%"></nile-kpi-chart>
|
|
324
|
+
</div>`);
|
|
325
|
+
const el = wrap.querySelector('nile-kpi-chart');
|
|
326
|
+
await el.updateComplete;
|
|
327
|
+
const box = document.createElement('div');
|
|
328
|
+
box.className = 'kpi-sparkline';
|
|
329
|
+
box.style.cssText = 'display:block;width:100%;height:50px';
|
|
330
|
+
el.shadowRoot.appendChild(box);
|
|
331
|
+
const drawn = document.createElement('div');
|
|
332
|
+
box.appendChild(drawn);
|
|
333
|
+
const stub = {
|
|
334
|
+
container: drawn,
|
|
335
|
+
chartWidth: 0,
|
|
336
|
+
chartHeight: 0,
|
|
337
|
+
renderTo: box,
|
|
338
|
+
update(o) {
|
|
339
|
+
this.chartWidth = o.chart.width;
|
|
340
|
+
this.chartHeight = o.chart.height;
|
|
341
|
+
},
|
|
342
|
+
destroy() {
|
|
343
|
+
// stand-in chart: nothing to release
|
|
344
|
+
},
|
|
345
|
+
};
|
|
346
|
+
const host = el;
|
|
347
|
+
host.sparklineChart = stub;
|
|
348
|
+
return { wrap, el, box, host, stub };
|
|
349
|
+
};
|
|
350
|
+
it('uses the layout size while the card is scaled down, not the on-screen size', async () => {
|
|
351
|
+
const { box, host, stub } = await setup(0.973);
|
|
352
|
+
expect(box.offsetWidth).to.equal(148);
|
|
353
|
+
expect(Math.round(box.getBoundingClientRect().width)).to.equal(144); // what getBoundingClientRect() would have given
|
|
354
|
+
host.syncSparklineChartSize();
|
|
355
|
+
expect(stub.chartWidth).to.equal(148); // the layout width, not the scaled on-screen width
|
|
356
|
+
expect(stub.chartHeight).to.equal(50);
|
|
357
|
+
});
|
|
358
|
+
it('matches the box exactly after the scale animation finishes', async () => {
|
|
359
|
+
const { wrap, box, host, stub } = await setup(0.973);
|
|
360
|
+
host.syncSparklineChartSize();
|
|
361
|
+
wrap.style.transform = 'scale(1)'; // layout size does not change, so a ResizeObserver would stay silent
|
|
362
|
+
host.syncSparklineChartSize();
|
|
363
|
+
expect(Math.round(box.getBoundingClientRect().width)).to.equal(148);
|
|
364
|
+
expect(stub.chartWidth).to.equal(box.offsetWidth);
|
|
365
|
+
});
|
|
366
|
+
it('matches the box when there is no transform', async () => {
|
|
367
|
+
const { box, host, stub } = await setup(1);
|
|
368
|
+
host.syncSparklineChartSize();
|
|
369
|
+
expect(stub.chartWidth).to.equal(box.offsetWidth);
|
|
370
|
+
expect(stub.chartWidth).to.equal(148);
|
|
371
|
+
});
|
|
372
|
+
});
|
|
373
|
+
//# sourceMappingURL=nile-kpi-chart.test.js.map
|