@aquera/nile-visualization 2.9.38 → 2.9.39
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 +5 -0
- package/dist/src/internal/types/aq-config.type.d.ts +2 -0
- package/dist/src/internal/utils/highcharts-compat.d.ts +27 -0
- package/dist/src/internal/utils/highcharts-compat.js +80 -0
- package/dist/src/internal/utils/highcharts-compat.test.d.ts +1 -0
- package/dist/src/internal/utils/highcharts-compat.test.js +116 -0
- package/dist/src/internal/utils/highcharts-provider.js +31 -0
- package/dist/src/nile-chart/nile-chart-config.d.ts +3 -0
- package/dist/src/nile-chart/nile-chart-empty.d.ts +22 -0
- package/dist/src/nile-chart/nile-chart-empty.js +264 -0
- package/dist/src/nile-chart/nile-chart-empty.test.d.ts +1 -0
- package/dist/src/nile-chart/nile-chart-empty.test.js +897 -0
- package/dist/src/nile-chart/nile-chart-skeleton.d.ts +2 -0
- package/dist/src/nile-chart/nile-chart-skeleton.js +9 -0
- package/dist/src/nile-chart/nile-chart-skeleton.test.d.ts +1 -0
- package/dist/src/nile-chart/nile-chart-skeleton.test.js +137 -0
- package/dist/src/nile-chart/nile-chart.css.js +123 -0
- package/dist/src/nile-chart/nile-chart.d.ts +8 -0
- package/dist/src/nile-chart/nile-chart.js +58 -4
- package/package.json +3 -3
|
@@ -0,0 +1,897 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default empty state for <nile-chart>: detection rules (isChartEmpty) and the
|
|
3
|
+
* rendered behaviour (precedence over loading/chart, header kept, ghost chart, slots, a11y).
|
|
4
|
+
*/
|
|
5
|
+
import { expect, fixture, html } from '@open-wc/testing';
|
|
6
|
+
import './nile-chart';
|
|
7
|
+
import { EMPTY_STATE_TITLE, isChartEmpty, toSafeCssLength } from './nile-chart-empty';
|
|
8
|
+
const settle = async (el) => {
|
|
9
|
+
await el.updateComplete;
|
|
10
|
+
await el.updateComplete;
|
|
11
|
+
await new Promise(requestAnimationFrame);
|
|
12
|
+
};
|
|
13
|
+
const make = async (chart, aq = {}) => {
|
|
14
|
+
const el = await fixture(html `<nile-chart></nile-chart>`);
|
|
15
|
+
if (chart)
|
|
16
|
+
el.config = { chart, aq };
|
|
17
|
+
await settle(el);
|
|
18
|
+
return el;
|
|
19
|
+
};
|
|
20
|
+
const root = (el) => el.shadowRoot;
|
|
21
|
+
const emptyState = (el) => root(el).querySelector('.nile-chart-empty');
|
|
22
|
+
const lineData = (data) => ({ type: 'line', data, categories: ['a', 'b', 'c'] });
|
|
23
|
+
describe('NileChart empty state', () => {
|
|
24
|
+
describe('detection (isChartEmpty)', () => {
|
|
25
|
+
it('1. missing or empty top-level data is empty', () => {
|
|
26
|
+
expect(isChartEmpty({ type: 'bar' })).to.be.true;
|
|
27
|
+
expect(isChartEmpty({ type: 'bar', data: [] })).to.be.true;
|
|
28
|
+
expect(isChartEmpty({ type: 'pie', data: [] })).to.be.true;
|
|
29
|
+
expect(isChartEmpty({ type: 'waterfall', data: [] })).to.be.true;
|
|
30
|
+
});
|
|
31
|
+
it('2. series that exist but have no data are empty', () => {
|
|
32
|
+
expect(isChartEmpty({ type: 'line', data: [{ name: 'A', data: [] }] })).to.be.true;
|
|
33
|
+
expect(isChartEmpty({ type: 'line', data: [{ name: 'A', data: [] }, { name: 'B', data: [] }] })).to.be.true;
|
|
34
|
+
});
|
|
35
|
+
it('3. all-null / absent values are empty', () => {
|
|
36
|
+
expect(isChartEmpty({ type: 'line', data: [{ name: 'A', data: [null, null] }] })).to.be.true;
|
|
37
|
+
expect(isChartEmpty({ type: 'line', data: [{ name: 'A', data: [Number.NaN] }] })).to.be.true;
|
|
38
|
+
expect(isChartEmpty({ type: 'scatter', data: [{ name: 'A', data: [[1, null], [2, null]] }] })).to.be.true;
|
|
39
|
+
expect(isChartEmpty({ type: 'line', data: [{ name: 'A', data: [{ y: Number.NaN }, { y: Infinity }] }] })).to.be.true;
|
|
40
|
+
expect(isChartEmpty({ type: 'scatter', data: [{ name: 'A', data: [[1, Number.NaN], [2, -Infinity]] }] })).to.be.true;
|
|
41
|
+
expect(isChartEmpty({ type: 'pie', data: [{ name: 'A', y: Number.NaN }] })).to.be.true;
|
|
42
|
+
expect(isChartEmpty({ type: 'pie', data: [{ name: 'A', y: null }, { name: 'B', y: null }] })).to.be.true;
|
|
43
|
+
});
|
|
44
|
+
it('4. valid zeros are data, not empty', () => {
|
|
45
|
+
expect(isChartEmpty({ type: 'line', data: [{ name: 'A', data: [0, 0, 0] }] })).to.be.false;
|
|
46
|
+
expect(isChartEmpty({ type: 'scatter', data: [{ name: 'A', data: [[0, 0]] }] })).to.be.false;
|
|
47
|
+
expect(isChartEmpty({ type: 'pie', data: [{ name: 'A', y: 0 }] })).to.be.false;
|
|
48
|
+
expect(isChartEmpty({ type: 'line', data: [{ name: 'A', data: [{ y: Number.NaN }, { y: 0 }] }] })).to.be.false;
|
|
49
|
+
});
|
|
50
|
+
it('one series with data keeps the chart', () => {
|
|
51
|
+
expect(isChartEmpty({ type: 'line', data: [{ name: 'A', data: [] }, { name: 'B', data: [3] }] })).to.be.false;
|
|
52
|
+
});
|
|
53
|
+
it('forecast inputs count their actual / projected values', () => {
|
|
54
|
+
expect(isChartEmpty({ type: 'line', data: [{ name: 'A', actual: [], projected: [] }] })).to.be.true;
|
|
55
|
+
expect(isChartEmpty({ type: 'line', data: [{ name: 'A', actual: [1], projected: [] }] })).to.be.false;
|
|
56
|
+
});
|
|
57
|
+
it('data supplied through passthrough options is data', () => {
|
|
58
|
+
expect(isChartEmpty({ type: 'line', data: [], options: { series: [{ data: [1] }] } })).to.be.false;
|
|
59
|
+
});
|
|
60
|
+
it('13a. KPI, grid and specialised shapes are never classified as empty', () => {
|
|
61
|
+
expect(isChartEmpty({ type: 'kpi', data: [] })).to.be.false;
|
|
62
|
+
expect(isChartEmpty({ type: 'grid', data: [], columns: [] })).to.be.false;
|
|
63
|
+
expect(isChartEmpty({ type: 'filter' })).to.be.false;
|
|
64
|
+
expect(isChartEmpty({ type: 'gauge', data: [] })).to.be.false;
|
|
65
|
+
expect(isChartEmpty({ type: 'map', data: [] })).to.be.false;
|
|
66
|
+
expect(isChartEmpty({ type: 'not-a-real-type', data: [] })).to.be.false;
|
|
67
|
+
expect(isChartEmpty(null)).to.be.false;
|
|
68
|
+
});
|
|
69
|
+
it('unfamiliar series / point shapes are treated as data', () => {
|
|
70
|
+
expect(isChartEmpty({ type: 'line', data: [{ name: 'A' }] })).to.be.false;
|
|
71
|
+
expect(isChartEmpty({ type: 'pie', data: [{ name: 'A', custom: 1 }] })).to.be.false;
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
describe('rendering', () => {
|
|
75
|
+
it('shows the empty state for empty top-level data', async () => {
|
|
76
|
+
const el = await make(lineData([]));
|
|
77
|
+
expect(emptyState(el)).to.exist;
|
|
78
|
+
});
|
|
79
|
+
it('shows the empty state for an empty series', async () => {
|
|
80
|
+
const el = await make(lineData([{ name: 'A', data: [] }]));
|
|
81
|
+
expect(emptyState(el)).to.exist;
|
|
82
|
+
});
|
|
83
|
+
it('shows the empty state for all-null data', async () => {
|
|
84
|
+
const el = await make(lineData([{ name: 'A', data: [null, null, null] }]));
|
|
85
|
+
expect(emptyState(el)).to.exist;
|
|
86
|
+
});
|
|
87
|
+
it('4. all-zero data renders the chart, not the empty state', async () => {
|
|
88
|
+
const el = await make(lineData([{ name: 'A', data: [0, 0, 0] }]));
|
|
89
|
+
expect(emptyState(el)).to.be.null;
|
|
90
|
+
expect(root(el).querySelector('nile-line-chart')).to.exist;
|
|
91
|
+
});
|
|
92
|
+
it('5. loading wins over empty', async () => {
|
|
93
|
+
const el = await make(lineData([]));
|
|
94
|
+
expect(emptyState(el)).to.exist;
|
|
95
|
+
el.loading = true;
|
|
96
|
+
await settle(el);
|
|
97
|
+
expect(emptyState(el)).to.be.null;
|
|
98
|
+
expect(root(el).querySelector('.nile-chart-skeleton')).to.exist;
|
|
99
|
+
});
|
|
100
|
+
it('loading → empty: the empty state appears once loading ends', async () => {
|
|
101
|
+
const el = await fixture(html `<nile-chart loading></nile-chart>`);
|
|
102
|
+
el.config = { chart: lineData([]), aq: {} };
|
|
103
|
+
await settle(el);
|
|
104
|
+
expect(emptyState(el)).to.be.null;
|
|
105
|
+
el.loading = false;
|
|
106
|
+
await settle(el);
|
|
107
|
+
expect(emptyState(el)).to.exist;
|
|
108
|
+
});
|
|
109
|
+
it('loading → data: the chart appears once loading ends', async () => {
|
|
110
|
+
const el = await fixture(html `<nile-chart loading></nile-chart>`);
|
|
111
|
+
el.config = { chart: lineData([{ name: 'A', data: [1, 2, 3] }]), aq: {} };
|
|
112
|
+
await settle(el);
|
|
113
|
+
el.loading = false;
|
|
114
|
+
await settle(el);
|
|
115
|
+
expect(emptyState(el)).to.be.null;
|
|
116
|
+
expect(root(el).querySelector('nile-line-chart')).to.exist;
|
|
117
|
+
});
|
|
118
|
+
it('6. valid data renders the chart with no empty state', async () => {
|
|
119
|
+
const el = await make(lineData([{ name: 'A', data: [1, 2, 3] }]));
|
|
120
|
+
expect(emptyState(el)).to.be.null;
|
|
121
|
+
expect(root(el).querySelector('nile-line-chart')).to.exist;
|
|
122
|
+
});
|
|
123
|
+
it('7. empty → populated removes the empty state', async () => {
|
|
124
|
+
const el = await make(lineData([]));
|
|
125
|
+
expect(emptyState(el)).to.exist;
|
|
126
|
+
el.config = { chart: lineData([{ name: 'A', data: [4, 5, 6] }]), aq: {} };
|
|
127
|
+
await settle(el);
|
|
128
|
+
expect(emptyState(el)).to.be.null;
|
|
129
|
+
expect(root(el).querySelector('nile-line-chart')).to.exist;
|
|
130
|
+
});
|
|
131
|
+
it('8. populated → empty swaps the chart for the empty state', async () => {
|
|
132
|
+
const el = await make(lineData([{ name: 'A', data: [4, 5, 6] }]));
|
|
133
|
+
expect(root(el).querySelector('nile-line-chart')).to.exist;
|
|
134
|
+
el.config = { chart: lineData([]), aq: {} };
|
|
135
|
+
await settle(el);
|
|
136
|
+
expect(emptyState(el)).to.exist;
|
|
137
|
+
expect(root(el).querySelector('nile-line-chart')).to.be.null;
|
|
138
|
+
});
|
|
139
|
+
it('9. renders the default title and description, and no glyph', async () => {
|
|
140
|
+
const el = await make(lineData([]));
|
|
141
|
+
expect(root(el).querySelector('.nile-chart-empty nile-glyph')).to.be.null;
|
|
142
|
+
expect(root(el).querySelector('slot[name="empty-glyph"]')).to.be.null;
|
|
143
|
+
expect(root(el).querySelector('.nile-chart-empty__title').textContent.trim()).to.equal(EMPTY_STATE_TITLE);
|
|
144
|
+
expect(root(el).querySelector('.nile-chart-empty__description').textContent.trim()).to.equal('There is nothing to show for this chart yet. Data will appear here once it is available.');
|
|
145
|
+
});
|
|
146
|
+
it('10. a static ghost picture sits behind the message, hidden from assistive tech', async () => {
|
|
147
|
+
const el = await make(lineData([]));
|
|
148
|
+
const ghost = root(el).querySelector('.nile-chart-empty__ghost');
|
|
149
|
+
expect(ghost).to.exist;
|
|
150
|
+
expect(ghost.getAttribute('aria-hidden')).to.equal('true');
|
|
151
|
+
const sk = ghost.querySelector('.nile-chart-skeleton--ghost');
|
|
152
|
+
expect(sk).to.exist;
|
|
153
|
+
expect(sk.hasAttribute('aria-busy')).to.be.false;
|
|
154
|
+
expect(root(el).querySelector('.nile-chart-empty').getAttribute('role')).to.equal('status');
|
|
155
|
+
});
|
|
156
|
+
it('10a. the ghost follows the chart type; line-like charts use solid columns; no axes or legend', async () => {
|
|
157
|
+
const shapeOf = async (chart) => root(await make(chart)).querySelector('.nile-chart-skeleton--ghost').className;
|
|
158
|
+
expect(await shapeOf({ type: 'column', data: [] })).to.contain('--columns');
|
|
159
|
+
expect(await shapeOf(lineData([]))).to.contain('--columns');
|
|
160
|
+
expect(await shapeOf({ type: 'area', data: [] })).to.contain('--columns');
|
|
161
|
+
expect(await shapeOf({ type: 'bar', data: [] })).to.contain('--bars');
|
|
162
|
+
expect(await shapeOf({ type: 'pie', data: [] })).to.contain('--pie');
|
|
163
|
+
expect(await shapeOf({ type: 'scatter', data: [] })).to.contain('--scatter');
|
|
164
|
+
const el = await make({ type: 'column', data: [] });
|
|
165
|
+
const xrow = root(el).querySelector('.nile-chart-skeleton--ghost .nile-chart-skeleton-xaxis-row');
|
|
166
|
+
expect(!xrow || getComputedStyle(xrow).display === 'none').to.be.true;
|
|
167
|
+
});
|
|
168
|
+
it('10b. the ghost does not animate', async () => {
|
|
169
|
+
const el = await make({ type: 'column', data: [], categories: ['a'] });
|
|
170
|
+
const fill = root(el).querySelector('.nile-chart-skeleton--ghost .nile-chart-skeleton-fill');
|
|
171
|
+
expect(getComputedStyle(fill).animationName).to.equal('none');
|
|
172
|
+
});
|
|
173
|
+
it('10c. emptyGhost: false drops the ghost and keeps the message', async () => {
|
|
174
|
+
const el = await make({ ...lineData([]), emptyGhost: false });
|
|
175
|
+
expect(emptyState(el)).to.exist;
|
|
176
|
+
expect(root(el).querySelector('.nile-chart-empty__ghost')).to.be.null;
|
|
177
|
+
expect(root(el).querySelector('.nile-chart-skeleton--ghost')).to.be.null;
|
|
178
|
+
expect(root(el).querySelector('.nile-chart-empty__title').textContent.trim()).to.equal(EMPTY_STATE_TITLE);
|
|
179
|
+
});
|
|
180
|
+
it('10d. a picture in slot="empty-ghost" replaces the ghost picture', async () => {
|
|
181
|
+
const el = await fixture(html `<nile-chart><img slot="empty-ghost" id="pic" alt="" /></nile-chart>`);
|
|
182
|
+
el.config = { chart: lineData([]), aq: {} };
|
|
183
|
+
await settle(el);
|
|
184
|
+
const slot = root(el).querySelector('slot[name="empty-ghost"]');
|
|
185
|
+
expect(slot.assignedElements().map((e) => e.id)).to.deep.equal(['pic']);
|
|
186
|
+
});
|
|
187
|
+
it('10e. the ghost picture is only slot fallback content', async () => {
|
|
188
|
+
const el = await make(lineData([]));
|
|
189
|
+
const slot = root(el).querySelector('slot[name="empty-ghost"]');
|
|
190
|
+
expect(slot.assignedElements()).to.have.length(0);
|
|
191
|
+
expect(slot.querySelector('.nile-chart-skeleton--ghost')).to.exist;
|
|
192
|
+
});
|
|
193
|
+
it('10c. a consumer title in slot="empty-title" replaces the default text', async () => {
|
|
194
|
+
const el = await fixture(html `<nile-chart><span slot="empty-title" id="t">No sign-ins</span></nile-chart>`);
|
|
195
|
+
el.config = { chart: lineData([]), aq: {} };
|
|
196
|
+
await settle(el);
|
|
197
|
+
const slot = root(el).querySelector('slot[name="empty-title"]');
|
|
198
|
+
expect(slot.assignedElements().map((e) => e.id)).to.deep.equal(['t']);
|
|
199
|
+
// the other two parts keep their defaults
|
|
200
|
+
expect(root(el).querySelector('slot[name="empty-description"]').assignedElements()).to.have.length(0);
|
|
201
|
+
});
|
|
202
|
+
it('10d. a consumer description in slot="empty-description" replaces the default text', async () => {
|
|
203
|
+
const el = await fixture(html `<nile-chart><span slot="empty-description" id="d">Nobody has signed in yet.</span></nile-chart>`);
|
|
204
|
+
el.config = { chart: lineData([]), aq: {} };
|
|
205
|
+
await settle(el);
|
|
206
|
+
const slot = root(el).querySelector('slot[name="empty-description"]');
|
|
207
|
+
expect(slot.assignedElements().map((e) => e.id)).to.deep.equal(['d']);
|
|
208
|
+
expect(root(el).querySelector('slot[name="empty-title"]').assignedElements()).to.have.length(0);
|
|
209
|
+
});
|
|
210
|
+
it('10e. the title and description defaults are only slot fallback content', async () => {
|
|
211
|
+
const el = await make(lineData([]));
|
|
212
|
+
expect(root(el).querySelector('slot[name="empty-title"]').textContent.trim()).to.equal(EMPTY_STATE_TITLE);
|
|
213
|
+
expect(root(el).querySelector('slot[name="empty-description"]').textContent.trim()).to.contain('There is nothing to show');
|
|
214
|
+
});
|
|
215
|
+
it('10f. both slots can be replaced together', async () => {
|
|
216
|
+
const el = await fixture(html `<nile-chart>
|
|
217
|
+
<span slot="empty-title" id="t">T</span>
|
|
218
|
+
<span slot="empty-description" id="d">D</span>
|
|
219
|
+
</nile-chart>`);
|
|
220
|
+
el.config = { chart: lineData([]), aq: {} };
|
|
221
|
+
await settle(el);
|
|
222
|
+
for (const [name, id] of [['empty-title', 't'], ['empty-description', 'd']]) {
|
|
223
|
+
const slot = root(el).querySelector(`slot[name="${name}"]`);
|
|
224
|
+
expect(slot.assignedElements().map((e) => e.id), name).to.deep.equal([id]);
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
it('10g. slotted content is not shown when the chart has data', async () => {
|
|
228
|
+
const el = await fixture(html `<nile-chart><span slot="empty-title" id="t">T</span></nile-chart>`);
|
|
229
|
+
el.config = { chart: lineData([{ name: 'A', data: [1, 2, 3] }]), aq: {} };
|
|
230
|
+
await settle(el);
|
|
231
|
+
expect(emptyState(el)).to.be.null;
|
|
232
|
+
expect(root(el).querySelector('slot[name="empty-title"]')).to.be.null;
|
|
233
|
+
});
|
|
234
|
+
it('11. the chart header stays', async () => {
|
|
235
|
+
const el = await make(lineData([]), { chartTitle: 'Sign-ins', chartSubtitle: 'Last 7 days' });
|
|
236
|
+
expect(emptyState(el)).to.exist;
|
|
237
|
+
const header = root(el).querySelector('.nile-chart-header');
|
|
238
|
+
expect(header, 'header should still render').to.exist;
|
|
239
|
+
expect(header.textContent).to.contain('Sign-ins');
|
|
240
|
+
});
|
|
241
|
+
it('12. no chart element, axes or legend are rendered', async () => {
|
|
242
|
+
const el = await make({ type: 'bar', data: [{ name: 'A', data: [] }], categories: [] });
|
|
243
|
+
expect(emptyState(el)).to.exist;
|
|
244
|
+
const inner = root(el).querySelector('.nile-chart-inner');
|
|
245
|
+
expect(inner.querySelector('nile-bar-chart')).to.be.null;
|
|
246
|
+
expect(inner.querySelector('.highcharts-container, .highcharts-axis, .highcharts-legend')).to.be.null;
|
|
247
|
+
expect(inner.querySelector('.nile-chart-empty')).to.exist;
|
|
248
|
+
});
|
|
249
|
+
it('13b. a grid with no rows keeps its own empty state', async () => {
|
|
250
|
+
const el = await make({ type: 'grid', data: [], columns: [{ field: 'name', header: 'Name' }] });
|
|
251
|
+
expect(emptyState(el)).to.be.null;
|
|
252
|
+
expect(root(el).querySelector('nile-data-grid')).to.exist;
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
describe('fit mode (fixed-height cell)', () => {
|
|
256
|
+
const makeFit = async (w, h) => {
|
|
257
|
+
const wrap = await fixture(html `<div style="width:${w}px;height:${h}px"><nile-chart fit></nile-chart></div>`);
|
|
258
|
+
const el = wrap.querySelector('nile-chart');
|
|
259
|
+
el.config = { chart: lineData([]), aq: { chartTitle: 'T' } };
|
|
260
|
+
await settle(el);
|
|
261
|
+
return el;
|
|
262
|
+
};
|
|
263
|
+
const rect = (el, sel) => root(el).querySelector(sel).getBoundingClientRect();
|
|
264
|
+
const lineCount = (el, sel) => {
|
|
265
|
+
const n = root(el).querySelector(sel);
|
|
266
|
+
return Math.round(n.getBoundingClientRect().height / parseFloat(getComputedStyle(n).lineHeight));
|
|
267
|
+
};
|
|
268
|
+
it('keeps the title visible when the cell is shorter than the content', async () => {
|
|
269
|
+
const el = await makeFit(300, 160);
|
|
270
|
+
const inner = rect(el, '.nile-chart-inner');
|
|
271
|
+
expect(root(el).querySelector('.nile-chart-empty__title').getBoundingClientRect().top).to.be.at.least(inner.top);
|
|
272
|
+
});
|
|
273
|
+
it('never squeezes the title: only the description gives way in a short cell', async () => {
|
|
274
|
+
const el = await makeFit(300, 70);
|
|
275
|
+
const title = root(el).querySelector('.nile-chart-empty__title');
|
|
276
|
+
const lineHeight = parseFloat(getComputedStyle(title).lineHeight);
|
|
277
|
+
expect(title.getBoundingClientRect().height).to.be.at.least(lineHeight - 1);
|
|
278
|
+
expect(title.scrollHeight).to.be.at.most(title.clientHeight + 1);
|
|
279
|
+
});
|
|
280
|
+
it('clamps the description to three lines in a roomy fit cell', async () => {
|
|
281
|
+
const el = await makeFit(120, 480);
|
|
282
|
+
await new Promise((r) => setTimeout(r, 150));
|
|
283
|
+
const d = root(el).querySelector('.nile-chart-empty__description');
|
|
284
|
+
expect(getComputedStyle(d).webkitLineClamp).to.equal('3');
|
|
285
|
+
expect(lineCount(el, '.nile-chart-empty__description')).to.equal(3);
|
|
286
|
+
});
|
|
287
|
+
it('never shows a partial description line, at any cell height', async () => {
|
|
288
|
+
// Sweep the cell height through every case: roomy, a line or two fits, none fits.
|
|
289
|
+
for (let h = 60; h <= 300; h += 10) {
|
|
290
|
+
const el = await makeFit(300, h);
|
|
291
|
+
await new Promise((r) => setTimeout(r, 120));
|
|
292
|
+
const tipEl = root(el).querySelector('.nile-chart-empty__tip--description');
|
|
293
|
+
if (tipEl.hidden)
|
|
294
|
+
continue; // dropped entirely: nothing partial to see
|
|
295
|
+
const d = root(el).querySelector('.nile-chart-empty__description');
|
|
296
|
+
const lh = parseFloat(getComputedStyle(d).lineHeight);
|
|
297
|
+
// Its box is a whole number of lines tall, so no line is cut through...
|
|
298
|
+
const lines = d.getBoundingClientRect().height / lh;
|
|
299
|
+
expect(Math.abs(lines - Math.round(lines)), `h=${h}: box is ${lines} lines tall`).to.be.below(0.05);
|
|
300
|
+
// ...and that box sits inside the card body, so none of it is clipped by the card.
|
|
301
|
+
const cell = root(el).querySelector('.nile-chart-inner').getBoundingClientRect();
|
|
302
|
+
expect(d.getBoundingClientRect().bottom, `h=${h}: description pokes out of the cell`).to.be.at.most(cell.bottom + 1);
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
it('hides the description when not even one line fits, and keeps the title', async () => {
|
|
306
|
+
// Short enough that the title alone fills the cell, whether or not design tokens are loaded.
|
|
307
|
+
const el = await makeFit(300, 50);
|
|
308
|
+
await new Promise((r) => setTimeout(r, 150));
|
|
309
|
+
expect(root(el).querySelector('.nile-chart-empty__tip--description').hidden).to.be.true;
|
|
310
|
+
expect(root(el).querySelector('.nile-chart-empty__title')).to.exist;
|
|
311
|
+
});
|
|
312
|
+
it('does not clamp the description outside fit mode', async () => {
|
|
313
|
+
const el = await make(lineData([]));
|
|
314
|
+
const d = root(el).querySelector('.nile-chart-empty__description');
|
|
315
|
+
expect(getComputedStyle(d).webkitLineClamp).to.equal('none');
|
|
316
|
+
});
|
|
317
|
+
it('centres normally when there is room', async () => {
|
|
318
|
+
const el = await makeFit(520, 360);
|
|
319
|
+
const inner = rect(el, '.nile-chart-inner');
|
|
320
|
+
const title = rect(el, '.nile-chart-empty__title');
|
|
321
|
+
const desc = rect(el, '.nile-chart-empty__description');
|
|
322
|
+
const topGap = title.top - inner.top;
|
|
323
|
+
const bottomGap = inner.bottom - desc.bottom;
|
|
324
|
+
expect(Math.abs(topGap - bottomGap)).to.be.below(4);
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
describe('truncation tooltips (nile-lite-tooltip)', () => {
|
|
328
|
+
const LONG_TITLE = 'A very long empty-state title that cannot possibly fit on two lines in a narrow card, however hard it tries to';
|
|
329
|
+
// The tooltip toggles from a ResizeObserver, so give it a tick after the render settles.
|
|
330
|
+
const settleTip = async (el) => { await settle(el); await new Promise((r) => setTimeout(r, 150)); };
|
|
331
|
+
const tip = (el, part) => root(el).querySelector(`.nile-chart-empty__tip--${part}`);
|
|
332
|
+
const lines = (el, sel) => {
|
|
333
|
+
const n = root(el).querySelector(sel);
|
|
334
|
+
return Math.round(n.getBoundingClientRect().height / parseFloat(getComputedStyle(n).lineHeight));
|
|
335
|
+
};
|
|
336
|
+
it('wraps title and description in a lite tooltip that starts disabled', async () => {
|
|
337
|
+
const el = await make(lineData([]));
|
|
338
|
+
await settleTip(el);
|
|
339
|
+
for (const part of ['title', 'description']) {
|
|
340
|
+
expect(tip(el, part), part).to.exist;
|
|
341
|
+
expect(tip(el, part).tagName.toLowerCase()).to.equal('nile-lite-tooltip');
|
|
342
|
+
expect(tip(el, part).disabled, `${part} tooltip off when not truncated`).to.be.true;
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
it('caps both tooltips at the 256px width token so long text wraps', async () => {
|
|
346
|
+
const el = await make(lineData([]));
|
|
347
|
+
await settleTip(el);
|
|
348
|
+
for (const part of ['title', 'description']) {
|
|
349
|
+
expect(tip(el, part).maxWidth, part).to.equal('var(--ng-width-64)');
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
it('clamps a long title to two lines and turns its tooltip on with the full text', async () => {
|
|
353
|
+
const wrap = await fixture(html `<div style="width:200px"><nile-chart><span slot="empty-title">${LONG_TITLE}</span></nile-chart></div>`);
|
|
354
|
+
const el = wrap.querySelector('nile-chart');
|
|
355
|
+
el.config = { chart: lineData([]), aq: {} };
|
|
356
|
+
await settleTip(el);
|
|
357
|
+
expect(lines(el, '.nile-chart-empty__title')).to.equal(2);
|
|
358
|
+
expect(tip(el, 'title').disabled).to.be.false;
|
|
359
|
+
expect(tip(el, 'title').content).to.equal(LONG_TITLE);
|
|
360
|
+
});
|
|
361
|
+
it('keeps the title tooltip off for a short title', async () => {
|
|
362
|
+
const el = await fixture(html `<nile-chart><span slot="empty-title">No sign-ins</span></nile-chart>`);
|
|
363
|
+
el.config = { chart: lineData([]), aq: {} };
|
|
364
|
+
await settleTip(el);
|
|
365
|
+
expect(tip(el, 'title').disabled).to.be.true;
|
|
366
|
+
});
|
|
367
|
+
it('turns the description tooltip on when the clamp cuts it, with the full text', async () => {
|
|
368
|
+
// Narrow and roomy: the default text wraps past the 3-line fit clamp.
|
|
369
|
+
const wrap = await fixture(html `<div style="width:120px;height:480px"><nile-chart fit></nile-chart></div>`);
|
|
370
|
+
const el = wrap.querySelector('nile-chart');
|
|
371
|
+
el.config = { chart: lineData([]), aq: { chartTitle: 'T' } };
|
|
372
|
+
await settleTip(el);
|
|
373
|
+
expect(tip(el, 'description').disabled).to.be.false;
|
|
374
|
+
expect(tip(el, 'description').content).to.contain('There is nothing to show for this chart yet.');
|
|
375
|
+
});
|
|
376
|
+
it('turns the tooltip off again when the space grows back', async () => {
|
|
377
|
+
const wrap = await fixture(html `<div style="width:120px;height:480px"><nile-chart fit></nile-chart></div>`);
|
|
378
|
+
const el = wrap.querySelector('nile-chart');
|
|
379
|
+
el.config = { chart: lineData([]), aq: { chartTitle: 'T' } };
|
|
380
|
+
await settleTip(el);
|
|
381
|
+
expect(tip(el, 'description').disabled).to.be.false;
|
|
382
|
+
wrap.style.width = '700px';
|
|
383
|
+
await settleTip(el);
|
|
384
|
+
expect(tip(el, 'description').disabled).to.be.true;
|
|
385
|
+
});
|
|
386
|
+
it('follows slotted text changes', async () => {
|
|
387
|
+
const wrap = await fixture(html `<div style="width:200px"><nile-chart><span slot="empty-title">Short</span></nile-chart></div>`);
|
|
388
|
+
const el = wrap.querySelector('nile-chart');
|
|
389
|
+
el.config = { chart: lineData([]), aq: {} };
|
|
390
|
+
await settleTip(el);
|
|
391
|
+
expect(tip(el, 'title').disabled).to.be.true;
|
|
392
|
+
el.querySelector('[slot="empty-title"]').textContent = LONG_TITLE;
|
|
393
|
+
await settleTip(el);
|
|
394
|
+
expect(tip(el, 'title').disabled).to.be.false;
|
|
395
|
+
expect(tip(el, 'title').content).to.equal(LONG_TITLE);
|
|
396
|
+
});
|
|
397
|
+
});
|
|
398
|
+
describe('accessibility', () => {
|
|
399
|
+
it('hides the decorative ghost chart and exposes the text as a status region', async () => {
|
|
400
|
+
const el = await make(lineData([]));
|
|
401
|
+
const region = emptyState(el);
|
|
402
|
+
expect(region.getAttribute('role')).to.equal('status');
|
|
403
|
+
expect(root(el).querySelector('.nile-chart-empty__ghost').getAttribute('aria-hidden')).to.equal('true');
|
|
404
|
+
expect(region.textContent).to.contain(EMPTY_STATE_TITLE);
|
|
405
|
+
});
|
|
406
|
+
it('keeps the same node across re-renders so the status is not re-announced', async () => {
|
|
407
|
+
const el = await make(lineData([]));
|
|
408
|
+
const first = emptyState(el);
|
|
409
|
+
el.config = { chart: lineData([{ name: 'A', data: [] }]), aq: {} };
|
|
410
|
+
await settle(el);
|
|
411
|
+
expect(emptyState(el)).to.equal(first);
|
|
412
|
+
});
|
|
413
|
+
});
|
|
414
|
+
describe('size values', () => {
|
|
415
|
+
it('toSafeCssLength keeps real lengths and drops anything that could add CSS', () => {
|
|
416
|
+
expect(toSafeCssLength(240)).to.equal('240px');
|
|
417
|
+
expect(toSafeCssLength('50%')).to.equal('50%');
|
|
418
|
+
expect(toSafeCssLength('calc(100vh - 200px)')).to.equal('calc(100vh - 200px)');
|
|
419
|
+
expect(toSafeCssLength('var(--ng-height-200px)')).to.equal('var(--ng-height-200px)');
|
|
420
|
+
expect(toSafeCssLength('0;position:fixed;inset:0')).to.equal(undefined);
|
|
421
|
+
expect(toSafeCssLength('10px;background:url(https://evil/x)')).to.equal(undefined);
|
|
422
|
+
expect(toSafeCssLength('')).to.equal(undefined);
|
|
423
|
+
expect(toSafeCssLength(NaN)).to.equal(undefined);
|
|
424
|
+
});
|
|
425
|
+
it('a chartMinHeight with extra declarations does not reach the style attribute', async () => {
|
|
426
|
+
const el = await make({ ...lineData([]), chartMinHeight: '0;position:fixed;inset:0;background:url(https://evil/x)' });
|
|
427
|
+
const style = emptyState(el).getAttribute('style') ?? '';
|
|
428
|
+
expect(style).to.not.include('position');
|
|
429
|
+
expect(style).to.not.include('url(');
|
|
430
|
+
});
|
|
431
|
+
it('a valid chartMinHeight is forwarded', async () => {
|
|
432
|
+
const el = await make({ ...lineData([]), chartMinHeight: 180 });
|
|
433
|
+
expect(emptyState(el).style.getPropertyValue('--nile-chart-min-height')).to.equal('180px');
|
|
434
|
+
});
|
|
435
|
+
});
|
|
436
|
+
describe('master-detail, dumbbellLower/Upper, columnDrilldown, flame, euler, vector', () => {
|
|
437
|
+
describe('detection (isChartEmpty)', () => {
|
|
438
|
+
it('master-detail ({ x, y } points): no points, or no usable y, is empty', () => {
|
|
439
|
+
expect(isChartEmpty({ type: 'master-detail' })).to.be.true;
|
|
440
|
+
expect(isChartEmpty({ type: 'master-detail', data: [] })).to.be.true;
|
|
441
|
+
expect(isChartEmpty({ type: 'master-detail', data: [{ x: 1, y: null }, { x: 2, y: null }] })).to.be.true;
|
|
442
|
+
expect(isChartEmpty({ type: 'master-detail', data: [{ x: 1, y: Number.NaN }, { x: 2, y: Infinity }] })).to.be.true;
|
|
443
|
+
});
|
|
444
|
+
it('master-detail: zero is data, and one usable point keeps the chart', () => {
|
|
445
|
+
expect(isChartEmpty({ type: 'master-detail', data: [{ x: 1, y: 0 }] })).to.be.false;
|
|
446
|
+
expect(isChartEmpty({ type: 'master-detail', data: [{ x: 1, y: null }, { x: 2, y: 5 }] })).to.be.false;
|
|
447
|
+
expect(isChartEmpty({ type: 'master-detail', data: [{ x: 1, y: 3 }, { x: 2, y: 4 }] })).to.be.false;
|
|
448
|
+
});
|
|
449
|
+
it('columnDrilldown ({ name, y, drilldown } points): no points, or no usable y, is empty', () => {
|
|
450
|
+
expect(isChartEmpty({ type: 'columnDrilldown' })).to.be.true;
|
|
451
|
+
expect(isChartEmpty({ type: 'columnDrilldown', data: [] })).to.be.true;
|
|
452
|
+
expect(isChartEmpty({ type: 'columnDrilldown', data: [{ name: 'A', y: null, drilldown: 'a' }] })).to.be.true;
|
|
453
|
+
expect(isChartEmpty({ type: 'columnDrilldown', data: [{ name: 'A', y: Number.NaN, drilldown: 'a' }] })).to.be.true;
|
|
454
|
+
});
|
|
455
|
+
it('columnDrilldown: drilldown series alone are not data, zero is', () => {
|
|
456
|
+
const drilldown = { series: [{ id: 'a', data: [['x', 1]] }] };
|
|
457
|
+
expect(isChartEmpty({ type: 'columnDrilldown', data: [], drilldown })).to.be.true;
|
|
458
|
+
expect(isChartEmpty({ type: 'columnDrilldown', data: [{ name: 'A', y: 0, drilldown: 'a' }], drilldown })).to.be.false;
|
|
459
|
+
expect(isChartEmpty({ type: 'columnDrilldown', data: [{ name: 'A', y: 4, drilldown: 'a' }], drilldown })).to.be.false;
|
|
460
|
+
});
|
|
461
|
+
it('dumbbellLower and dumbbellUpper: no points is empty, any point is data', () => {
|
|
462
|
+
for (const type of ['dumbbellLower', 'dumbbellUpper']) {
|
|
463
|
+
expect(isChartEmpty({ type }), type).to.be.true;
|
|
464
|
+
expect(isChartEmpty({ type, data: [] }), type).to.be.true;
|
|
465
|
+
expect(isChartEmpty({ type, data: [{ name: 'A', low: 1, high: 5 }] }), type).to.be.false;
|
|
466
|
+
expect(isChartEmpty({ type, data: [{ name: 'A', low: 0, high: 0 }] }), type).to.be.false;
|
|
467
|
+
}
|
|
468
|
+
});
|
|
469
|
+
it('dumbbellLower and dumbbellUpper decide exactly like dumbbell', () => {
|
|
470
|
+
const inputs = [
|
|
471
|
+
[], [{ name: 'A', low: 1, high: 5 }], [{ name: 'A', low: 0, high: 0 }], [{ name: 'A', low: null, high: null }],
|
|
472
|
+
];
|
|
473
|
+
for (const data of inputs) {
|
|
474
|
+
const expected = isChartEmpty({ type: 'dumbbell', data });
|
|
475
|
+
expect(isChartEmpty({ type: 'dumbbellLower', data })).to.equal(expected);
|
|
476
|
+
expect(isChartEmpty({ type: 'dumbbellUpper', data })).to.equal(expected);
|
|
477
|
+
}
|
|
478
|
+
});
|
|
479
|
+
it('flame (flame / icicle layouts) plots `data`', () => {
|
|
480
|
+
const row = { name: 'f', value: 3, x: 0, low: 0, high: 1 };
|
|
481
|
+
for (const layout of [undefined, 'flame', 'icicle']) {
|
|
482
|
+
expect(isChartEmpty({ type: 'flame', layout }), String(layout)).to.be.true;
|
|
483
|
+
expect(isChartEmpty({ type: 'flame', layout, data: [] }), String(layout)).to.be.true;
|
|
484
|
+
expect(isChartEmpty({ type: 'flame', layout, data: [row] }), String(layout)).to.be.false;
|
|
485
|
+
expect(isChartEmpty({ type: 'flame', layout, data: [{ ...row, value: 0 }] }), String(layout)).to.be.false;
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
it('flame in the sunburst layout plots `sunburstData`, not `data`', () => {
|
|
489
|
+
const flameRow = { name: 'f', value: 3, x: 0, low: 0, high: 1 };
|
|
490
|
+
const sunRow = { id: 'root', parent: '', name: 'Root', value: 5 };
|
|
491
|
+
expect(isChartEmpty({ type: 'flame', layout: 'sunburst', sunburstData: [sunRow] })).to.be.false;
|
|
492
|
+
expect(isChartEmpty({ type: 'flame', layout: 'sunburst', data: [], sunburstData: [sunRow] })).to.be.false;
|
|
493
|
+
expect(isChartEmpty({ type: 'flame', layout: 'sunburst' })).to.be.true;
|
|
494
|
+
expect(isChartEmpty({ type: 'flame', layout: 'sunburst', sunburstData: [] })).to.be.true;
|
|
495
|
+
// `data` rows are ignored by the sunburst layout, so they don't make it non-empty.
|
|
496
|
+
expect(isChartEmpty({ type: 'flame', layout: 'sunburst', data: [flameRow], sunburstData: [] })).to.be.true;
|
|
497
|
+
});
|
|
498
|
+
it('euler ({ sets, value } rows): no rows is empty, any row (including value 0) is data', () => {
|
|
499
|
+
expect(isChartEmpty({ type: 'euler' })).to.be.true;
|
|
500
|
+
expect(isChartEmpty({ type: 'euler', data: [] })).to.be.true;
|
|
501
|
+
expect(isChartEmpty({ type: 'euler', data: [{ sets: ['A'], value: 4 }] })).to.be.false;
|
|
502
|
+
expect(isChartEmpty({ type: 'euler', data: [{ sets: ['A'], value: 0 }] })).to.be.false;
|
|
503
|
+
});
|
|
504
|
+
it('vector ({ x, y, length, direction } rows): no rows is empty, any row (including all zeros) is data', () => {
|
|
505
|
+
expect(isChartEmpty({ type: 'vector' })).to.be.true;
|
|
506
|
+
expect(isChartEmpty({ type: 'vector', data: [] })).to.be.true;
|
|
507
|
+
expect(isChartEmpty({ type: 'vector', data: [{ x: 1, y: 2, length: 3, direction: 90 }] })).to.be.false;
|
|
508
|
+
expect(isChartEmpty({ type: 'vector', data: [{ x: 0, y: 0, length: 0, direction: 0 }] })).to.be.false;
|
|
509
|
+
});
|
|
510
|
+
it('the types still left out (map) are never empty', () => {
|
|
511
|
+
expect(isChartEmpty({ type: 'map', data: [] })).to.be.false;
|
|
512
|
+
});
|
|
513
|
+
});
|
|
514
|
+
describe('rendering', () => {
|
|
515
|
+
// [chart type, element it renders, valid chart config]
|
|
516
|
+
const flameRow = { name: 'f', value: 3, x: 0, low: 0, high: 1 };
|
|
517
|
+
const cases = [
|
|
518
|
+
['master-detail', 'nile-master-detail-chart', { data: [{ x: 1, y: 2 }, { x: 2, y: 3 }] }],
|
|
519
|
+
['dumbbellLower', 'nile-dumbbell-lower-chart', { data: [{ name: 'A', low: 1, high: 5 }] }],
|
|
520
|
+
['dumbbellUpper', 'nile-dumbbell-upper-chart', { data: [{ name: 'A', low: 1, high: 5 }] }],
|
|
521
|
+
['columnDrilldown', 'nile-column-drilldown-chart', { data: [{ name: 'A', y: 4, drilldown: 'a' }], drilldown: { series: [{ id: 'a', data: [['x', 1]] }] } }],
|
|
522
|
+
['flame', 'nile-flame-chart', { data: [flameRow] }],
|
|
523
|
+
['euler', 'nile-euler-chart', { data: [{ sets: ['A'], value: 4 }] }],
|
|
524
|
+
['vector', 'nile-vector-chart', { data: [{ x: 1, y: 2, length: 3, direction: 90 }] }],
|
|
525
|
+
];
|
|
526
|
+
for (const [type, tag, valid] of cases) {
|
|
527
|
+
it(`${type}: empty data shows the shared empty state`, async () => {
|
|
528
|
+
const el = await make({ type, data: [] });
|
|
529
|
+
expect(emptyState(el), type).to.exist;
|
|
530
|
+
expect(root(el).querySelector(tag), type).to.be.null;
|
|
531
|
+
});
|
|
532
|
+
it(`${type}: valid data renders the chart, not the empty state`, async () => {
|
|
533
|
+
const el = await make({ type, ...valid });
|
|
534
|
+
expect(emptyState(el), type).to.be.null;
|
|
535
|
+
expect(root(el).querySelector(tag), type).to.exist;
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
it('master-detail: all-zero data renders the chart', async () => {
|
|
539
|
+
const el = await make({ type: 'master-detail', data: [{ x: 1, y: 0 }, { x: 2, y: 0 }] });
|
|
540
|
+
expect(emptyState(el)).to.be.null;
|
|
541
|
+
});
|
|
542
|
+
it('master-detail: all-null data shows the empty state', async () => {
|
|
543
|
+
const el = await make({ type: 'master-detail', data: [{ x: 1, y: null }, { x: 2, y: null }] });
|
|
544
|
+
expect(emptyState(el)).to.exist;
|
|
545
|
+
});
|
|
546
|
+
it('columnDrilldown: all-zero data renders the chart, all-null shows the empty state', async () => {
|
|
547
|
+
const zero = await make({ type: 'columnDrilldown', data: [{ name: 'A', y: 0, drilldown: 'a' }], drilldown: { series: [] } });
|
|
548
|
+
expect(emptyState(zero)).to.be.null;
|
|
549
|
+
const none = await make({ type: 'columnDrilldown', data: [{ name: 'A', y: null, drilldown: 'a' }], drilldown: { series: [] } });
|
|
550
|
+
expect(emptyState(none)).to.exist;
|
|
551
|
+
});
|
|
552
|
+
it('flame: a sunburst layout with only sunburstData renders the chart', async () => {
|
|
553
|
+
const el = await make({ type: 'flame', layout: 'sunburst', sunburstData: [{ id: 'root', parent: '', name: 'Root', value: 5 }] });
|
|
554
|
+
expect(emptyState(el)).to.be.null;
|
|
555
|
+
expect(root(el).querySelector('nile-flame-chart')).to.exist;
|
|
556
|
+
});
|
|
557
|
+
it('flame: a sunburst layout with no sunburstData shows the empty state', async () => {
|
|
558
|
+
const el = await make({ type: 'flame', layout: 'sunburst', data: [flameRow], sunburstData: [] });
|
|
559
|
+
expect(emptyState(el)).to.exist;
|
|
560
|
+
});
|
|
561
|
+
it('loading still wins over empty for the new types', async () => {
|
|
562
|
+
for (const [type] of cases) {
|
|
563
|
+
const el = await make({ type, data: [], loading: true });
|
|
564
|
+
expect(emptyState(el), type).to.be.null;
|
|
565
|
+
}
|
|
566
|
+
});
|
|
567
|
+
});
|
|
568
|
+
});
|
|
569
|
+
describe('histogram and bellcurve (numeric sample lists)', () => {
|
|
570
|
+
const types = ['histogram', 'bellcurve'];
|
|
571
|
+
const tags = { histogram: 'nile-histogram-chart', bellcurve: 'nile-bellcurve-chart' };
|
|
572
|
+
describe('detection (isChartEmpty)', () => {
|
|
573
|
+
it('missing data and [] are empty', () => {
|
|
574
|
+
for (const type of types) {
|
|
575
|
+
expect(isChartEmpty({ type }), type).to.be.true;
|
|
576
|
+
expect(isChartEmpty({ type, data: [] }), type).to.be.true;
|
|
577
|
+
expect(isChartEmpty({ type, data: null }), type).to.be.true;
|
|
578
|
+
}
|
|
579
|
+
});
|
|
580
|
+
it('a list with no finite numbers is empty', () => {
|
|
581
|
+
for (const type of types) {
|
|
582
|
+
expect(isChartEmpty({ type, data: [Number.NaN] }), type).to.be.true;
|
|
583
|
+
expect(isChartEmpty({ type, data: [Infinity, -Infinity] }), type).to.be.true;
|
|
584
|
+
expect(isChartEmpty({ type, data: [null, undefined, Number.NaN, Infinity] }), type).to.be.true;
|
|
585
|
+
expect(isChartEmpty({ type, data: ['x', {}] }), type).to.be.true;
|
|
586
|
+
}
|
|
587
|
+
});
|
|
588
|
+
it('zero, positive and negative finite values are data', () => {
|
|
589
|
+
for (const type of types) {
|
|
590
|
+
expect(isChartEmpty({ type, data: [0] }), type).to.be.false;
|
|
591
|
+
expect(isChartEmpty({ type, data: [0, 0, 0] }), type).to.be.false;
|
|
592
|
+
expect(isChartEmpty({ type, data: [4.2] }), type).to.be.false;
|
|
593
|
+
expect(isChartEmpty({ type, data: [-3] }), type).to.be.false;
|
|
594
|
+
}
|
|
595
|
+
});
|
|
596
|
+
it('invalid entries mixed with a finite value keep the chart', () => {
|
|
597
|
+
for (const type of types) {
|
|
598
|
+
expect(isChartEmpty({ type, data: [Number.NaN, null, Infinity, 7] }), type).to.be.false;
|
|
599
|
+
expect(isChartEmpty({ type, data: [-Infinity, 0] }), type).to.be.false;
|
|
600
|
+
}
|
|
601
|
+
});
|
|
602
|
+
it('histogram and bellcurve decide identically', () => {
|
|
603
|
+
const inputs = [undefined, [], [Number.NaN], [Infinity], [0], [-1], [Number.NaN, 2], [null]];
|
|
604
|
+
for (const data of inputs) {
|
|
605
|
+
expect(isChartEmpty({ type: 'bellcurve', data })).to.equal(isChartEmpty({ type: 'histogram', data }));
|
|
606
|
+
}
|
|
607
|
+
});
|
|
608
|
+
it('passthrough series still count as data', () => {
|
|
609
|
+
for (const type of types) {
|
|
610
|
+
expect(isChartEmpty({ type, data: [], options: { series: [{ data: [1] }] } }), type).to.be.false;
|
|
611
|
+
}
|
|
612
|
+
});
|
|
613
|
+
});
|
|
614
|
+
describe('rendering', () => {
|
|
615
|
+
for (const type of types) {
|
|
616
|
+
const tag = tags[type];
|
|
617
|
+
it(`${type}: empty data shows the shared empty state, not the chart`, async () => {
|
|
618
|
+
for (const data of [[], [Number.NaN], [Infinity, -Infinity]]) {
|
|
619
|
+
const el = await make({ type, data });
|
|
620
|
+
expect(emptyState(el), type).to.exist;
|
|
621
|
+
expect(root(el).querySelector(tag), type).to.be.null;
|
|
622
|
+
}
|
|
623
|
+
});
|
|
624
|
+
it(`${type}: valid data renders the chart, not the empty state`, async () => {
|
|
625
|
+
for (const data of [[1, 2, 3, 4], [0], [-2, -1], [Number.NaN, 5]]) {
|
|
626
|
+
const el = await make({ type, data });
|
|
627
|
+
expect(emptyState(el), type).to.be.null;
|
|
628
|
+
expect(root(el).querySelector(tag), type).to.exist;
|
|
629
|
+
}
|
|
630
|
+
});
|
|
631
|
+
it(`${type}: loading wins over empty`, async () => {
|
|
632
|
+
const el = await make({ type, data: [], loading: true });
|
|
633
|
+
expect(emptyState(el)).to.be.null;
|
|
634
|
+
});
|
|
635
|
+
}
|
|
636
|
+
});
|
|
637
|
+
});
|
|
638
|
+
describe('organization', () => {
|
|
639
|
+
const node = { id: 'a', name: 'Alice' };
|
|
640
|
+
const link = { from: 'a', to: 'b' };
|
|
641
|
+
describe('detection (isChartEmpty)', () => {
|
|
642
|
+
it('missing or empty nodes is empty, whatever the links', () => {
|
|
643
|
+
expect(isChartEmpty({ type: 'organization' })).to.be.true;
|
|
644
|
+
expect(isChartEmpty({ type: 'organization', nodes: [] })).to.be.true;
|
|
645
|
+
expect(isChartEmpty({ type: 'organization', nodes: [], links: [] })).to.be.true;
|
|
646
|
+
expect(isChartEmpty({ type: 'organization', links: [link] })).to.be.true;
|
|
647
|
+
expect(isChartEmpty({ type: 'organization', nodes: [], links: [link] })).to.be.true;
|
|
648
|
+
});
|
|
649
|
+
it('nodes without links paint nothing in Highcharts, so they are empty', () => {
|
|
650
|
+
expect(isChartEmpty({ type: 'organization', nodes: [node] })).to.be.true;
|
|
651
|
+
expect(isChartEmpty({ type: 'organization', nodes: [node], links: [] })).to.be.true;
|
|
652
|
+
});
|
|
653
|
+
it('nodes with links are data, and links need not match the listed nodes', () => {
|
|
654
|
+
expect(isChartEmpty({ type: 'organization', nodes: [node], links: [link] })).to.be.false;
|
|
655
|
+
expect(isChartEmpty({ type: 'organization', nodes: [{ id: 'x' }], links: [link] })).to.be.false;
|
|
656
|
+
});
|
|
657
|
+
it('minimum structure: nodes need an id, links need from and to', () => {
|
|
658
|
+
expect(isChartEmpty({ type: 'organization', nodes: [{ name: 'no id' }], links: [link] })).to.be.true;
|
|
659
|
+
expect(isChartEmpty({ type: 'organization', nodes: [null, { id: '' }], links: [link] })).to.be.true;
|
|
660
|
+
expect(isChartEmpty({ type: 'organization', nodes: [node], links: [{ from: 'a' }] })).to.be.true;
|
|
661
|
+
expect(isChartEmpty({ type: 'organization', nodes: [node], links: [null, { from: '', to: 'b' }] })).to.be.true;
|
|
662
|
+
expect(isChartEmpty({ type: 'organization', nodes: [{ id: 'a' }, { name: 'x' }], links: [{ from: 'a' }, link] })).to.be.false;
|
|
663
|
+
});
|
|
664
|
+
it('non-array nodes / links are empty', () => {
|
|
665
|
+
expect(isChartEmpty({ type: 'organization', nodes: 'a', links: [link] })).to.be.true;
|
|
666
|
+
expect(isChartEmpty({ type: 'organization', nodes: [node], links: {} })).to.be.true;
|
|
667
|
+
});
|
|
668
|
+
it('passthrough series still count as data', () => {
|
|
669
|
+
expect(isChartEmpty({ type: 'organization', nodes: [], links: [], options: { series: [{ data: [['a', 'b']] }] } })).to.be.false;
|
|
670
|
+
});
|
|
671
|
+
});
|
|
672
|
+
describe('rendering', () => {
|
|
673
|
+
it('empty config shows the shared empty state and no chart', async () => {
|
|
674
|
+
for (const cfg of [{}, { nodes: [], links: [] }, { nodes: [], links: [link] }, { nodes: [node], links: [] }]) {
|
|
675
|
+
const el = await make({ type: 'organization', ...cfg });
|
|
676
|
+
expect(emptyState(el), JSON.stringify(cfg)).to.exist;
|
|
677
|
+
expect(root(el).querySelector('nile-organization-chart'), JSON.stringify(cfg)).to.be.null;
|
|
678
|
+
}
|
|
679
|
+
});
|
|
680
|
+
it('valid nodes and links render the chart, not the empty state', async () => {
|
|
681
|
+
const el = await make({ type: 'organization', nodes: [node, { id: 'b', name: 'Bob' }], links: [link] });
|
|
682
|
+
expect(emptyState(el)).to.be.null;
|
|
683
|
+
expect(root(el).querySelector('nile-organization-chart')).to.exist;
|
|
684
|
+
});
|
|
685
|
+
it('loading wins over empty', async () => {
|
|
686
|
+
const el = await make({ type: 'organization', nodes: [], links: [], loading: true });
|
|
687
|
+
expect(emptyState(el)).to.be.null;
|
|
688
|
+
});
|
|
689
|
+
});
|
|
690
|
+
});
|
|
691
|
+
describe('line-column', () => {
|
|
692
|
+
const cats = ['a', 'b', 'c'];
|
|
693
|
+
const side = (data) => ({ name: 'S', data });
|
|
694
|
+
const lc = (columnSeries, lineSeries, extra = {}) => ({ type: 'line-column', categories: cats, columnSeries, lineSeries, ...extra });
|
|
695
|
+
describe('detection (isChartEmpty)', () => {
|
|
696
|
+
it('no series, empty series and categories alone are empty', () => {
|
|
697
|
+
expect(isChartEmpty({ type: 'line-column' })).to.be.true;
|
|
698
|
+
expect(isChartEmpty({ type: 'line-column', categories: cats })).to.be.true;
|
|
699
|
+
expect(isChartEmpty(lc([], []))).to.be.true;
|
|
700
|
+
expect(isChartEmpty(lc(side([]), side([])))).to.be.true;
|
|
701
|
+
expect(isChartEmpty(lc(side([]), undefined))).to.be.true;
|
|
702
|
+
expect(isChartEmpty(lc(undefined, side([])))).to.be.true;
|
|
703
|
+
});
|
|
704
|
+
it('only invalid values on both sides is empty', () => {
|
|
705
|
+
const bad = [Number.NaN, Infinity, -Infinity, null, undefined, 'x'];
|
|
706
|
+
expect(isChartEmpty(lc(side(bad), side(bad)))).to.be.true;
|
|
707
|
+
expect(isChartEmpty(lc(side(bad), undefined))).to.be.true;
|
|
708
|
+
});
|
|
709
|
+
it('zero and negative values are data, on either side', () => {
|
|
710
|
+
expect(isChartEmpty(lc(side([0]), side([])))).to.be.false;
|
|
711
|
+
expect(isChartEmpty(lc(side([]), side([0])))).to.be.false;
|
|
712
|
+
expect(isChartEmpty(lc(side([-4, -1]), side([])))).to.be.false;
|
|
713
|
+
expect(isChartEmpty(lc(side([]), side([-4, -1])))).to.be.false;
|
|
714
|
+
});
|
|
715
|
+
it('one side is enough, with the other empty or missing', () => {
|
|
716
|
+
expect(isChartEmpty(lc(side([1, 2]), side([])))).to.be.false;
|
|
717
|
+
expect(isChartEmpty(lc(side([1, 2]), undefined))).to.be.false;
|
|
718
|
+
expect(isChartEmpty(lc(side([]), side([1, 2])))).to.be.false;
|
|
719
|
+
expect(isChartEmpty(lc(undefined, side([1, 2])))).to.be.false;
|
|
720
|
+
expect(isChartEmpty(lc(side([1, 2]), side([3, 4])))).to.be.false;
|
|
721
|
+
});
|
|
722
|
+
it('invalid values mixed with one finite value keep the chart', () => {
|
|
723
|
+
expect(isChartEmpty(lc(side([Number.NaN, null, 5]), side([])))).to.be.false;
|
|
724
|
+
expect(isChartEmpty(lc(side([Infinity]), side([null, 2])))).to.be.false;
|
|
725
|
+
});
|
|
726
|
+
it('an array of series parts is also understood', () => {
|
|
727
|
+
expect(isChartEmpty(lc([side([])], [side([])]))).to.be.true;
|
|
728
|
+
expect(isChartEmpty(lc([side([1])], []))).to.be.false;
|
|
729
|
+
});
|
|
730
|
+
it('passthrough series count as data', () => {
|
|
731
|
+
expect(isChartEmpty(lc(side([]), side([]), { options: { series: [{ data: [1] }] } }))).to.be.false;
|
|
732
|
+
expect(isChartEmpty(lc(side([]), side([]), { series: [{ data: [1] }] }))).to.be.false;
|
|
733
|
+
expect(isChartEmpty(lc(side([]), side([]), { options: { series: [] } }))).to.be.true;
|
|
734
|
+
});
|
|
735
|
+
});
|
|
736
|
+
describe('rendering', () => {
|
|
737
|
+
const tag = 'nile-line-column-chart';
|
|
738
|
+
it('empty configs show the shared empty state and no chart', async () => {
|
|
739
|
+
for (const cfg of [lc(), lc(side([]), side([])), lc(side([Number.NaN]), side([null])), lc([], [])]) {
|
|
740
|
+
const el = await make(cfg);
|
|
741
|
+
expect(emptyState(el)).to.exist;
|
|
742
|
+
expect(root(el).querySelector(tag)).to.be.null;
|
|
743
|
+
}
|
|
744
|
+
});
|
|
745
|
+
it('column-only, line-only and combined data render the chart', async () => {
|
|
746
|
+
for (const cfg of [
|
|
747
|
+
lc(side([1, 2, 3]), side([])), lc(side([]), side([1, 2, 3])), lc(side([1, 2, 3]), side([3, 2, 1])), lc(side([0]), side([])),
|
|
748
|
+
]) {
|
|
749
|
+
const el = await make(cfg);
|
|
750
|
+
expect(emptyState(el)).to.be.null;
|
|
751
|
+
expect(root(el).querySelector(tag)).to.exist;
|
|
752
|
+
}
|
|
753
|
+
});
|
|
754
|
+
it('loading wins over empty', async () => {
|
|
755
|
+
const el = await make(lc(side([]), side([]), { loading: true }));
|
|
756
|
+
expect(emptyState(el)).to.be.null;
|
|
757
|
+
});
|
|
758
|
+
});
|
|
759
|
+
});
|
|
760
|
+
describe('fan', () => {
|
|
761
|
+
const pt = (y, category = 'a') => ({ category, y });
|
|
762
|
+
const band = (low, high) => ({ name: 'b', data: [{ category: 'a', low, high }] });
|
|
763
|
+
const fan = (lineData, bands, extra = {}) => ({ type: 'fan', lineData, bands, ...extra });
|
|
764
|
+
describe('detection (isChartEmpty)', () => {
|
|
765
|
+
it('no data, empty lists and bare categories are empty', () => {
|
|
766
|
+
expect(isChartEmpty({ type: 'fan' })).to.be.true;
|
|
767
|
+
expect(isChartEmpty(fan([], []))).to.be.true;
|
|
768
|
+
expect(isChartEmpty(fan([pt(undefined)], []))).to.be.true;
|
|
769
|
+
expect(isChartEmpty(fan([{ category: 'a' }, { category: 'b' }], [{ name: 'b', data: [{ category: 'a' }] }]))).to.be.true;
|
|
770
|
+
expect(isChartEmpty(fan([], [{ name: 'b', data: [] }]))).to.be.true;
|
|
771
|
+
});
|
|
772
|
+
it('line entries with no finite y are empty', () => {
|
|
773
|
+
expect(isChartEmpty(fan([pt(Number.NaN), pt(Infinity), pt(-Infinity), pt(null), pt('7')], []))).to.be.true;
|
|
774
|
+
expect(isChartEmpty(fan([null, 3, 'x'], []))).to.be.true;
|
|
775
|
+
});
|
|
776
|
+
it('zero, positive and negative line values are data', () => {
|
|
777
|
+
expect(isChartEmpty(fan([pt(0)], []))).to.be.false;
|
|
778
|
+
expect(isChartEmpty(fan([pt(4.5)], []))).to.be.false;
|
|
779
|
+
expect(isChartEmpty(fan([pt(-3)], []))).to.be.false;
|
|
780
|
+
expect(isChartEmpty(fan([pt(0)]))).to.be.false;
|
|
781
|
+
});
|
|
782
|
+
it('invalid values mixed with one finite line value keep the chart', () => {
|
|
783
|
+
expect(isChartEmpty(fan([pt(Number.NaN), pt(null), pt(2)], []))).to.be.false;
|
|
784
|
+
});
|
|
785
|
+
it('a band-only fan is data (it paints the shaded area), if low and high are finite', () => {
|
|
786
|
+
expect(isChartEmpty(fan([], [band(1, 2)]))).to.be.false;
|
|
787
|
+
expect(isChartEmpty(fan(undefined, [band(0, 0)]))).to.be.false;
|
|
788
|
+
expect(isChartEmpty(fan([], [band(-3, -1)]))).to.be.false;
|
|
789
|
+
expect(isChartEmpty(fan([], [band(1, Number.NaN)]))).to.be.true;
|
|
790
|
+
expect(isChartEmpty(fan([], [band(null, 2)]))).to.be.true;
|
|
791
|
+
expect(isChartEmpty(fan([], [band(Infinity, 2)]))).to.be.true;
|
|
792
|
+
});
|
|
793
|
+
it('line plus bands is data', () => {
|
|
794
|
+
expect(isChartEmpty(fan([pt(1)], []))).to.be.false;
|
|
795
|
+
expect(isChartEmpty(fan([pt(1)], [band(0, 2)]))).to.be.false;
|
|
796
|
+
expect(isChartEmpty(fan([pt(Number.NaN)], [band(0, 2)]))).to.be.false;
|
|
797
|
+
});
|
|
798
|
+
it('passthrough series count as data', () => {
|
|
799
|
+
expect(isChartEmpty(fan([], [], { options: { series: [{ data: [1] }] } }))).to.be.false;
|
|
800
|
+
expect(isChartEmpty(fan([], [], { series: [{ data: [1] }] }))).to.be.false;
|
|
801
|
+
expect(isChartEmpty(fan([], [], { options: { series: [] } }))).to.be.true;
|
|
802
|
+
});
|
|
803
|
+
});
|
|
804
|
+
describe('rendering', () => {
|
|
805
|
+
const tag = 'nile-fan-chart';
|
|
806
|
+
const line = [pt(1, 'a'), pt(2, 'b')];
|
|
807
|
+
const bands = [{ name: 'b', data: [{ category: 'a', low: 0, high: 2 }, { category: 'b', low: 1, high: 3 }] }];
|
|
808
|
+
it('empty configs show the shared empty state and no chart', async () => {
|
|
809
|
+
for (const cfg of [fan(), fan([], []), fan([pt(Number.NaN)], []), fan([], [band(1, null)])]) {
|
|
810
|
+
const el = await make(cfg);
|
|
811
|
+
expect(emptyState(el)).to.exist;
|
|
812
|
+
expect(root(el).querySelector(tag)).to.be.null;
|
|
813
|
+
}
|
|
814
|
+
});
|
|
815
|
+
it('line-only, line + bands and band-only render the chart', async () => {
|
|
816
|
+
for (const cfg of [fan(line, []), fan(line, bands), fan([], bands), fan([pt(0)], [])]) {
|
|
817
|
+
const el = await make(cfg);
|
|
818
|
+
expect(emptyState(el)).to.be.null;
|
|
819
|
+
expect(root(el).querySelector(tag)).to.exist;
|
|
820
|
+
}
|
|
821
|
+
});
|
|
822
|
+
it('loading wins over empty', async () => {
|
|
823
|
+
const el = await make(fan([], [], { loading: true }));
|
|
824
|
+
expect(emptyState(el)).to.be.null;
|
|
825
|
+
});
|
|
826
|
+
});
|
|
827
|
+
});
|
|
828
|
+
describe('polygon', () => {
|
|
829
|
+
const tri = [[0, 0], [4, 0], [2, 3]];
|
|
830
|
+
const poly = (series, options, extra = {}) => ({ type: 'polygon', series, options, ...extra });
|
|
831
|
+
describe('detection (isChartEmpty)', () => {
|
|
832
|
+
it('no series, [] and series with no data are empty', () => {
|
|
833
|
+
expect(isChartEmpty({ type: 'polygon' })).to.be.true;
|
|
834
|
+
expect(isChartEmpty(poly([]))).to.be.true;
|
|
835
|
+
expect(isChartEmpty(poly([{ name: 'A', data: [] }]))).to.be.true;
|
|
836
|
+
expect(isChartEmpty(poly([{ name: 'A' }]))).to.be.true;
|
|
837
|
+
expect(isChartEmpty(poly([{ name: 'A', data: [] }, { name: 'B', data: [] }]))).to.be.true;
|
|
838
|
+
});
|
|
839
|
+
it('names, colors and options without points are empty', () => {
|
|
840
|
+
expect(isChartEmpty(poly([{ name: 'A', color: '#f00', lineWidth: 2, data: [] }], { title: { text: 'x' } }))).to.be.true;
|
|
841
|
+
});
|
|
842
|
+
it('the generic series shortcut does not apply: a non-empty series array can still be empty', () => {
|
|
843
|
+
expect(isChartEmpty(poly([{ data: [] }]))).to.be.true;
|
|
844
|
+
// ...while it still applies to other types
|
|
845
|
+
expect(isChartEmpty({ type: 'line', data: [], options: { series: [{ data: [1] }] } })).to.be.false;
|
|
846
|
+
});
|
|
847
|
+
it('one valid point, or valid data in one of several series, is data', () => {
|
|
848
|
+
expect(isChartEmpty(poly([{ name: 'A', data: [[1, 2]] }]))).to.be.false;
|
|
849
|
+
expect(isChartEmpty(poly([{ name: 'A', data: [] }, { name: 'B', data: tri }]))).to.be.false;
|
|
850
|
+
});
|
|
851
|
+
it('zero and negative coordinates are data', () => {
|
|
852
|
+
expect(isChartEmpty(poly([{ data: [[0, 0]] }]))).to.be.false;
|
|
853
|
+
expect(isChartEmpty(poly([{ data: [[-3, -1], [-1, -1], [-2, -4]] }]))).to.be.false;
|
|
854
|
+
});
|
|
855
|
+
it('{ x, y } object points are understood', () => {
|
|
856
|
+
expect(isChartEmpty(poly([{ data: [{ x: 0, y: 0 }] }]))).to.be.false;
|
|
857
|
+
expect(isChartEmpty(poly([{ data: [{ x: 1 }, { y: 2 }] }]))).to.be.true;
|
|
858
|
+
});
|
|
859
|
+
it('points that are not finite are empty; mixed with a valid point they are data', () => {
|
|
860
|
+
expect(isChartEmpty(poly([{ data: [[Number.NaN, 1], [1, Infinity], [null, 2], [1], 'x', null] }]))).to.be.true;
|
|
861
|
+
expect(isChartEmpty(poly([{ data: [[Number.NaN, 1], [3, 4]] }]))).to.be.false;
|
|
862
|
+
});
|
|
863
|
+
it('options.series replaces series (arrays do not merge), even when empty', () => {
|
|
864
|
+
expect(isChartEmpty(poly([], { series: [{ type: 'polygon', data: tri }] }))).to.be.false;
|
|
865
|
+
expect(isChartEmpty(poly([{ data: tri }], { series: [] }))).to.be.true;
|
|
866
|
+
expect(isChartEmpty(poly([{ data: tri }], { series: [{ data: [] }] }))).to.be.true;
|
|
867
|
+
expect(isChartEmpty(poly([{ data: tri }], { series: [{ data: tri }] }))).to.be.false;
|
|
868
|
+
expect(isChartEmpty(poly([{ data: tri }], { title: {} }))).to.be.false;
|
|
869
|
+
});
|
|
870
|
+
it('a missing series is empty even if options.series has data (the element needs `series`)', () => {
|
|
871
|
+
expect(isChartEmpty(poly(undefined, { series: [{ data: tri }] }))).to.be.true;
|
|
872
|
+
});
|
|
873
|
+
});
|
|
874
|
+
describe('rendering', () => {
|
|
875
|
+
const tag = 'nile-polygon-chart';
|
|
876
|
+
it('empty configs show the shared empty state and no chart', async () => {
|
|
877
|
+
for (const cfg of [poly(), poly([]), poly([{ name: 'A', data: [] }]), poly([{ data: [[Number.NaN, 1]] }])]) {
|
|
878
|
+
const el = await make(cfg);
|
|
879
|
+
expect(emptyState(el)).to.exist;
|
|
880
|
+
expect(root(el).querySelector(tag)).to.be.null;
|
|
881
|
+
}
|
|
882
|
+
});
|
|
883
|
+
it('valid, zero and negative data render the chart', async () => {
|
|
884
|
+
for (const cfg of [poly([{ name: 'A', data: tri }]), poly([{ data: [[0, 0]] }]), poly([{ data: [[-3, -1], [-1, -1], [-2, -4]] }])]) {
|
|
885
|
+
const el = await make(cfg);
|
|
886
|
+
expect(emptyState(el)).to.be.null;
|
|
887
|
+
expect(root(el).querySelector(tag)).to.exist;
|
|
888
|
+
}
|
|
889
|
+
});
|
|
890
|
+
it('loading wins over empty', async () => {
|
|
891
|
+
const el = await make(poly([], undefined, { loading: true }));
|
|
892
|
+
expect(emptyState(el)).to.be.null;
|
|
893
|
+
});
|
|
894
|
+
});
|
|
895
|
+
});
|
|
896
|
+
});
|
|
897
|
+
//# sourceMappingURL=nile-chart-empty.test.js.map
|