@aquera/nile-visualization 2.9.41 → 2.9.43
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 +7 -0
- package/dist/src/index.d.ts +2 -2
- package/dist/src/internal/echarts/translate-config.js +42 -2
- package/dist/src/internal/types/chart-master-detail-config.type.d.ts +7 -2
- package/dist/src/nile-chart/nile-chart-config.d.ts +7 -2
- package/dist/src/nile-chart/nile-chart-empty.js +10 -0
- package/dist/src/nile-chart/nile-chart.css.js +2 -1
- package/dist/src/nile-chart/nile-chart.js +3 -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/dist/src/nile-master-detail-chart/index.d.ts +1 -1
- package/dist/src/nile-master-detail-chart/nile-master-detail-chart.d.ts +24 -1
- package/dist/src/nile-master-detail-chart/nile-master-detail-chart.js +90 -37
- package/dist/src/nile-master-detail-chart/nile-master-detail-chart.test.d.ts +2 -0
- package/dist/src/nile-master-detail-chart/nile-master-detail-chart.test.js +262 -0
- package/package.json +1 -1
|
@@ -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
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { NileMasterDetailChart } from './nile-master-detail-chart.js';
|
|
2
|
-
export type { MasterDetailPoint, MasterDetailSeriesType } from './nile-master-detail-chart.js';
|
|
2
|
+
export type { MasterDetailPoint, MasterDetailSeries, MasterDetailSeriesType, MasterDetailStacking } from './nile-master-detail-chart.js';
|
|
@@ -8,6 +8,15 @@ export interface MasterDetailPoint {
|
|
|
8
8
|
x: number;
|
|
9
9
|
y: number;
|
|
10
10
|
}
|
|
11
|
+
/** One named series for the multi-series form (`series` property). */
|
|
12
|
+
export interface MasterDetailSeries {
|
|
13
|
+
name: string;
|
|
14
|
+
data: MasterDetailPoint[];
|
|
15
|
+
color?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare const MASTER_DETAIL_STACKING: readonly ["normal", "percent"];
|
|
18
|
+
/** `''` (or any unknown value) means no stacking. */
|
|
19
|
+
export type MasterDetailStacking = (typeof MASTER_DETAIL_STACKING)[number] | '';
|
|
11
20
|
export declare const MASTER_DETAIL_SERIES_TYPES: readonly ["area", "line", "spline", "areaspline", "column", "bar"];
|
|
12
21
|
export type MasterDetailSeriesType = (typeof MASTER_DETAIL_SERIES_TYPES)[number];
|
|
13
22
|
export declare const MASTER_DETAIL_X_AXIS_TYPES: readonly ["datetime", "linear", "logarithmic", "category"];
|
|
@@ -30,6 +39,13 @@ export declare class NileMasterDetailChart extends NileElement {
|
|
|
30
39
|
data: MasterDetailPoint[];
|
|
31
40
|
seriesName: string;
|
|
32
41
|
seriesColor: string;
|
|
42
|
+
/**
|
|
43
|
+
* Several named series. When non-empty it replaces `data` / `seriesName` /
|
|
44
|
+
* `seriesColor`. Series should share x values so stacks line up.
|
|
45
|
+
*/
|
|
46
|
+
series: MasterDetailSeries[];
|
|
47
|
+
/** Stack the series on both panes: `normal`, `percent`, or `''` for none. */
|
|
48
|
+
stacking: MasterDetailStacking;
|
|
33
49
|
detailType: MasterDetailSeriesType;
|
|
34
50
|
masterType: MasterDetailSeriesType;
|
|
35
51
|
masterOnly: boolean;
|
|
@@ -70,7 +86,14 @@ export declare class NileMasterDetailChart extends NileElement {
|
|
|
70
86
|
protected firstUpdated(): void;
|
|
71
87
|
protected updated(changedProperties: PropertyValues): void;
|
|
72
88
|
private setupResizeObserver;
|
|
73
|
-
|
|
89
|
+
/** `series` when given, else one series built from `data` / `seriesName` / `seriesColor`. */
|
|
90
|
+
private get _seriesList();
|
|
91
|
+
private get _isMultiSeries();
|
|
92
|
+
private get _stackingMode();
|
|
93
|
+
/** Sorted, de-duplicated x values across every series. */
|
|
94
|
+
private _allXs;
|
|
95
|
+
private mapPoints;
|
|
96
|
+
private buildSeries;
|
|
74
97
|
private dataExtremes;
|
|
75
98
|
private pointStep;
|
|
76
99
|
private get _isCategoricalMaster();
|