@aquera/nile-visualization 2.9.42 → 2.9.44
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 +1 -1
- 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/internal/utils/lite-tooltip.d.ts +5 -0
- package/dist/src/internal/utils/lite-tooltip.js +18 -0
- package/dist/src/nile-chart/nile-chart-config.d.ts +7 -2
- package/dist/src/nile-chart/nile-chart-empty.js +13 -3
- package/dist/src/nile-chart/nile-chart.css.js +12 -0
- package/dist/src/nile-chart/nile-chart.d.ts +29 -5
- package/dist/src/nile-chart/nile-chart.js +193 -69
- package/dist/src/nile-kpi-chart/nile-kpi-chart.js +10 -6
- 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 +92 -38
- 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
|
@@ -7,6 +7,8 @@ import { applySeparatedChartConfig } from '../internal/utils/separated-chart-con
|
|
|
7
7
|
import { deepMerge } from '../internal/utils/deep-merge.js';
|
|
8
8
|
import { withResponsiveDefaults } from '../internal/utils/responsive-defaults.js';
|
|
9
9
|
import { styles } from './nile-master-detail-chart.css.js';
|
|
10
|
+
import { LITE_TOOLTIP_MAX_WIDTH, limitLiteTooltipHeight } from '../internal/utils/lite-tooltip.js';
|
|
11
|
+
export const MASTER_DETAIL_STACKING = ['normal', 'percent'];
|
|
10
12
|
export const MASTER_DETAIL_SERIES_TYPES = [
|
|
11
13
|
'area',
|
|
12
14
|
'line',
|
|
@@ -31,6 +33,13 @@ let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
|
|
|
31
33
|
this.data = [];
|
|
32
34
|
this.seriesName = '';
|
|
33
35
|
this.seriesColor = '';
|
|
36
|
+
/**
|
|
37
|
+
* Several named series. When non-empty it replaces `data` / `seriesName` /
|
|
38
|
+
* `seriesColor`. Series should share x values so stacks line up.
|
|
39
|
+
*/
|
|
40
|
+
this.series = [];
|
|
41
|
+
/** Stack the series on both panes: `normal`, `percent`, or `''` for none. */
|
|
42
|
+
this.stacking = '';
|
|
34
43
|
this.detailType = 'area';
|
|
35
44
|
this.masterType = 'area';
|
|
36
45
|
this.masterOnly = false;
|
|
@@ -143,6 +152,8 @@ let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
|
|
|
143
152
|
}
|
|
144
153
|
const props = [
|
|
145
154
|
'data',
|
|
155
|
+
'series',
|
|
156
|
+
'stacking',
|
|
146
157
|
'options',
|
|
147
158
|
'masterOptions',
|
|
148
159
|
'height',
|
|
@@ -168,7 +179,7 @@ let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
|
|
|
168
179
|
'masterHeight', 'loadingText', 'loadingColor', 'loadingFontSize', 'loadingFontFamily', 'loadingBg'];
|
|
169
180
|
if (cssVarProps.some(p => changedProperties.has(p)))
|
|
170
181
|
this._syncCssVars();
|
|
171
|
-
const objectProps = new Set(['data', 'options', 'masterOptions', 'legend']);
|
|
182
|
+
const objectProps = new Set(['data', 'series', 'options', 'masterOptions', 'legend']);
|
|
172
183
|
const reallyChanged = (p) => {
|
|
173
184
|
if (!changedProperties.has(p))
|
|
174
185
|
return false;
|
|
@@ -217,14 +228,44 @@ let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
|
|
|
217
228
|
});
|
|
218
229
|
this.resizeObserver.observe(target);
|
|
219
230
|
}
|
|
220
|
-
|
|
221
|
-
|
|
231
|
+
/** `series` when given, else one series built from `data` / `seriesName` / `seriesColor`. */
|
|
232
|
+
get _seriesList() {
|
|
233
|
+
if (Array.isArray(this.series) && this.series.length)
|
|
234
|
+
return this.series;
|
|
235
|
+
return [{ name: this.seriesName || 'Series', data: this.data ?? [], color: this.seriesColor || undefined }];
|
|
236
|
+
}
|
|
237
|
+
get _isMultiSeries() {
|
|
238
|
+
return this._seriesList.length > 1;
|
|
239
|
+
}
|
|
240
|
+
get _stackingMode() {
|
|
241
|
+
return MASTER_DETAIL_STACKING.includes(this.stacking)
|
|
242
|
+
? this.stacking
|
|
243
|
+
: undefined;
|
|
244
|
+
}
|
|
245
|
+
/** Sorted, de-duplicated x values across every series. */
|
|
246
|
+
_allXs() {
|
|
247
|
+
const xs = new Set();
|
|
248
|
+
for (const s of this._seriesList)
|
|
249
|
+
for (const p of s.data ?? [])
|
|
250
|
+
xs.add(p.x);
|
|
251
|
+
return [...xs].sort((a, b) => a - b);
|
|
252
|
+
}
|
|
253
|
+
mapPoints(points, min = -Infinity, max = Infinity) {
|
|
254
|
+
return (points ?? []).filter(p => p.x >= min && p.x <= max).map(p => ({ x: p.x, y: p.y }));
|
|
255
|
+
}
|
|
256
|
+
buildSeries(type, min, max) {
|
|
257
|
+
return this._seriesList.map(s => ({
|
|
258
|
+
type,
|
|
259
|
+
name: s.name,
|
|
260
|
+
data: this.mapPoints(s.data, min, max),
|
|
261
|
+
color: s.color || undefined,
|
|
262
|
+
}));
|
|
222
263
|
}
|
|
223
264
|
dataExtremes() {
|
|
224
|
-
const xs = this.
|
|
265
|
+
const xs = this._allXs();
|
|
225
266
|
return {
|
|
226
|
-
dataMin: xs.length ?
|
|
227
|
-
dataMax: xs.length ?
|
|
267
|
+
dataMin: xs.length ? xs[0] : 0,
|
|
268
|
+
dataMax: xs.length ? xs[xs.length - 1] : 0,
|
|
228
269
|
};
|
|
229
270
|
}
|
|
230
271
|
pointStep(xs) {
|
|
@@ -243,17 +284,17 @@ let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
|
|
|
243
284
|
_zoomWindow(min, max) {
|
|
244
285
|
if (!this._isCategoricalMaster || min !== max)
|
|
245
286
|
return { min, max };
|
|
246
|
-
const eps = this.pointStep(this.
|
|
287
|
+
const eps = this.pointStep(this._allXs()) * 1e-4;
|
|
247
288
|
return { min: min - eps, max: max + eps };
|
|
248
289
|
}
|
|
249
290
|
_masterMinRange() {
|
|
250
|
-
const step = this.pointStep(this.
|
|
291
|
+
const step = this.pointStep(this._allXs());
|
|
251
292
|
if (!step)
|
|
252
293
|
return undefined;
|
|
253
294
|
return this._isCategoricalMaster ? step * 1e-5 : step;
|
|
254
295
|
}
|
|
255
296
|
snapSelection(min, max) {
|
|
256
|
-
const xs = this.
|
|
297
|
+
const xs = this._allXs();
|
|
257
298
|
if (xs.length === 0)
|
|
258
299
|
return { min, max };
|
|
259
300
|
const step = this.pointStep(xs);
|
|
@@ -275,10 +316,22 @@ let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
|
|
|
275
316
|
}
|
|
276
317
|
buildDetailOptions() {
|
|
277
318
|
const { min, max } = this.defaultSelection();
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
319
|
+
const multi = this._isMultiSeries;
|
|
320
|
+
const stacking = this._stackingMode;
|
|
321
|
+
// Single series keeps its original tooltip. Several series get one shared
|
|
322
|
+
// tooltip headed by the x value, a line per series, and the share in percent mode.
|
|
323
|
+
const tooltip = multi
|
|
324
|
+
? {
|
|
325
|
+
shared: true,
|
|
326
|
+
pointFormat: stacking === 'percent'
|
|
327
|
+
? '<span style="color:{point.color}">●</span> {series.name}: <b>{point.y}</b> ({point.percentage:.0f}%)<br/>'
|
|
328
|
+
: '<span style="color:{point.color}">●</span> {series.name}: <b>{point.y}</b><br/>',
|
|
329
|
+
}
|
|
330
|
+
: {
|
|
331
|
+
headerFormat: '<b>{series.name}</b><br>',
|
|
332
|
+
pointFormat: '{point.x} : {point.y}',
|
|
333
|
+
shared: true,
|
|
334
|
+
};
|
|
282
335
|
const merged = deepMerge({
|
|
283
336
|
chart: { type: this.detailType, reflow: true },
|
|
284
337
|
title: { text: this.detailTitle || undefined },
|
|
@@ -292,25 +345,15 @@ let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
|
|
|
292
345
|
min: this.yAxisMin ?? undefined,
|
|
293
346
|
max: this.yAxisMax ?? undefined,
|
|
294
347
|
},
|
|
295
|
-
tooltip
|
|
296
|
-
|
|
297
|
-
pointFormat: '{point.x} : {point.y}',
|
|
298
|
-
shared: true,
|
|
299
|
-
},
|
|
300
|
-
legend: { enabled: false },
|
|
348
|
+
tooltip,
|
|
349
|
+
legend: { enabled: multi },
|
|
301
350
|
plotOptions: {
|
|
302
351
|
series: {
|
|
352
|
+
stacking,
|
|
303
353
|
marker: { enabled: false, states: { hover: { enabled: true, radius: 3 } } },
|
|
304
354
|
},
|
|
305
355
|
},
|
|
306
|
-
series:
|
|
307
|
-
{
|
|
308
|
-
type: this.detailType,
|
|
309
|
-
name: this.seriesName || 'Series',
|
|
310
|
-
data: detailData,
|
|
311
|
-
color: this.seriesColor || undefined,
|
|
312
|
-
},
|
|
313
|
-
],
|
|
356
|
+
series: this.buildSeries(this.detailType, min, max),
|
|
314
357
|
credits: { enabled: false },
|
|
315
358
|
}, this.options);
|
|
316
359
|
// Only the detail pane takes the built-in rules. The master is a fixed short
|
|
@@ -363,6 +406,11 @@ let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
|
|
|
363
406
|
},
|
|
364
407
|
},
|
|
365
408
|
title: { text: this.masterTitle || undefined },
|
|
409
|
+
// With several series the legend lives on the detail pane, so the master
|
|
410
|
+
// must use the same colours or the overview contradicts it. Inherit the
|
|
411
|
+
// detail palette (`options.colors`, which nile-chart fills from its theme)
|
|
412
|
+
// unless `masterOptions.colors` sets one. Single-series output is unchanged.
|
|
413
|
+
...(this._isMultiSeries && Array.isArray(this.options?.colors) ? { colors: this.options.colors } : {}),
|
|
366
414
|
// A capped master (see the `min(…, 40%)` height in the stylesheet) can get
|
|
367
415
|
// short enough that the 30px label band above leaves almost no plot. Below
|
|
368
416
|
// that point drop the date labels and give the space back to the overview
|
|
@@ -399,19 +447,13 @@ let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
|
|
|
399
447
|
credits: { enabled: false },
|
|
400
448
|
plotOptions: {
|
|
401
449
|
series: {
|
|
450
|
+
stacking: this._stackingMode,
|
|
402
451
|
lineWidth: 1,
|
|
403
452
|
marker: { enabled: false, states: { hover: { enabled: mo, radius: 3 } } },
|
|
404
453
|
enableMouseTracking: mo,
|
|
405
454
|
},
|
|
406
455
|
},
|
|
407
|
-
series:
|
|
408
|
-
{
|
|
409
|
-
type: this.masterType,
|
|
410
|
-
name: this.seriesName || 'Series',
|
|
411
|
-
data: this.mapData(),
|
|
412
|
-
color: this.seriesColor || undefined,
|
|
413
|
-
},
|
|
414
|
-
],
|
|
456
|
+
series: this.buildSeries(this.masterType),
|
|
415
457
|
}, this.masterOptions);
|
|
416
458
|
// The master keeps its own height-aware rule rather than the shared cartesian
|
|
417
459
|
// set, but it honors the same opt-out: `no-responsive` means no built-in
|
|
@@ -446,8 +488,14 @@ let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
|
|
|
446
488
|
return;
|
|
447
489
|
}
|
|
448
490
|
if (this.detailChart) {
|
|
449
|
-
|
|
450
|
-
|
|
491
|
+
// Refilter every series we own (by index) and redraw once, so a stack
|
|
492
|
+
// stays consistent while zooming. Extra series supplied only through
|
|
493
|
+
// `options.series` are left as they are.
|
|
494
|
+
const chart = this.detailChart;
|
|
495
|
+
this._seriesList.forEach((s, i) => {
|
|
496
|
+
chart.series[i]?.setData(this.mapPoints(s.data, min, max), false);
|
|
497
|
+
});
|
|
498
|
+
chart.redraw();
|
|
451
499
|
}
|
|
452
500
|
const { dataMin, dataMax } = this.dataExtremes();
|
|
453
501
|
const xAxis = this.masterChart.xAxis[0];
|
|
@@ -508,7 +556,7 @@ let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
|
|
|
508
556
|
? null
|
|
509
557
|
: html `<div class="detail-container ${masterHidden ? 'detail-container--grow' : ''}" part="detail-container"></div>
|
|
510
558
|
${this.masterCollapsible
|
|
511
|
-
? html `<nile-lite-tooltip content=${this.masterCollapsed ? 'Show master' : 'Hide master'} placement="top">
|
|
559
|
+
? html `<nile-lite-tooltip .maxWidth=${LITE_TOOLTIP_MAX_WIDTH} @nile-show=${limitLiteTooltipHeight} content=${this.masterCollapsed ? 'Show master' : 'Hide master'} placement="top">
|
|
512
560
|
<button
|
|
513
561
|
type="button"
|
|
514
562
|
class="master-toggle"
|
|
@@ -553,6 +601,12 @@ __decorate([
|
|
|
553
601
|
__decorate([
|
|
554
602
|
property({ type: String, attribute: 'series-color' })
|
|
555
603
|
], NileMasterDetailChart.prototype, "seriesColor", void 0);
|
|
604
|
+
__decorate([
|
|
605
|
+
property({ type: Array })
|
|
606
|
+
], NileMasterDetailChart.prototype, "series", void 0);
|
|
607
|
+
__decorate([
|
|
608
|
+
property({ type: String })
|
|
609
|
+
], NileMasterDetailChart.prototype, "stacking", void 0);
|
|
556
610
|
__decorate([
|
|
557
611
|
property({ type: String, attribute: 'detail-type' })
|
|
558
612
|
], NileMasterDetailChart.prototype, "detailType", void 0);
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for <nile-master-detail-chart> multi-series + stacking
|
|
3
|
+
* (spec: kb/specs/nile-master-detail-chart-stacking.md — Acceptance criteria).
|
|
4
|
+
*
|
|
5
|
+
* Highcharts itself cannot run in this test browser (the dynamic `import('highcharts')`
|
|
6
|
+
* resolves to a module whose `setOptions` is missing — see the stand-in used by the
|
|
7
|
+
* kpi suite for the same reason). So instead of a live chart we inject a minimal fake
|
|
8
|
+
* Highcharts through the component's private `_hc` field *before* the first render:
|
|
9
|
+
* `initCharts()` then builds its real `buildDetailOptions()` / `buildMasterOptions()`
|
|
10
|
+
* into the fake, and `applySelection` / `resetZoom` run their real code against it.
|
|
11
|
+
* The fake captures each chart's `options`, `series` (with a working `setData`) and a
|
|
12
|
+
* single `xAxis`, which is everything the assertions below read.
|
|
13
|
+
*/
|
|
14
|
+
import { expect, fixture, html } from '@open-wc/testing';
|
|
15
|
+
import './nile-master-detail-chart';
|
|
16
|
+
import '../nile-chart/nile-chart';
|
|
17
|
+
const host = (el) => el;
|
|
18
|
+
const SERIES = [
|
|
19
|
+
{ name: 'Alpha', data: [{ x: 1, y: 10 }, { x: 2, y: 20 }, { x: 3, y: 30 }], color: '#ff0000' },
|
|
20
|
+
{ name: 'Beta', data: [{ x: 1, y: 5 }, { x: 2, y: 15 }, { x: 3, y: 25 }], color: '#00ff00' },
|
|
21
|
+
// Gamma reaches x=4 so the union-of-x assertions have something only it contributes.
|
|
22
|
+
{ name: 'Gamma', data: [{ x: 1, y: 1 }, { x: 2, y: 2 }, { x: 3, y: 3 }, { x: 4, y: 4 }], color: '#0000ff' },
|
|
23
|
+
];
|
|
24
|
+
const SINGLE = [{ x: 1, y: 10 }, { x: 2, y: 20 }, { x: 3, y: 30 }, { x: 4, y: 40 }];
|
|
25
|
+
// --- minimal fake Highcharts -------------------------------------------------
|
|
26
|
+
const toPoints = (data = []) => data.map((d) => ({ x: d.x, y: d.y }));
|
|
27
|
+
function makeSeries(s) {
|
|
28
|
+
const inst = {
|
|
29
|
+
name: s.name,
|
|
30
|
+
options: { ...s },
|
|
31
|
+
points: toPoints(s.data),
|
|
32
|
+
get xData() {
|
|
33
|
+
return inst.points.map((p) => p.x);
|
|
34
|
+
},
|
|
35
|
+
setData(data) {
|
|
36
|
+
inst.points = toPoints(data);
|
|
37
|
+
inst.options = { ...inst.options, data };
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
return inst;
|
|
41
|
+
}
|
|
42
|
+
function makeAxis() {
|
|
43
|
+
const bands = new Map();
|
|
44
|
+
return {
|
|
45
|
+
min: undefined,
|
|
46
|
+
max: undefined,
|
|
47
|
+
setExtremes(min, max) {
|
|
48
|
+
this.min = min;
|
|
49
|
+
this.max = max;
|
|
50
|
+
},
|
|
51
|
+
getExtremes() {
|
|
52
|
+
return { min: this.min, max: this.max, dataMin: this.min, dataMax: this.max };
|
|
53
|
+
},
|
|
54
|
+
addPlotBand(b) {
|
|
55
|
+
bands.set(b.id, b);
|
|
56
|
+
},
|
|
57
|
+
removePlotBand(id) {
|
|
58
|
+
bands.delete(id);
|
|
59
|
+
},
|
|
60
|
+
_bands: bands,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
const mergeSeriesOpts = (a = {}, b = {}) => ({
|
|
64
|
+
...a,
|
|
65
|
+
...b,
|
|
66
|
+
series: { ...(a.series || {}), ...(b.series || {}) },
|
|
67
|
+
});
|
|
68
|
+
function makeChart(options) {
|
|
69
|
+
const chart = {
|
|
70
|
+
options,
|
|
71
|
+
series: (options.series || []).map(makeSeries),
|
|
72
|
+
xAxis: [makeAxis()],
|
|
73
|
+
get legend() {
|
|
74
|
+
return { options: chart.options.legend || {} };
|
|
75
|
+
},
|
|
76
|
+
update(next) {
|
|
77
|
+
chart.options = {
|
|
78
|
+
...chart.options,
|
|
79
|
+
...next,
|
|
80
|
+
plotOptions: mergeSeriesOpts(chart.options.plotOptions, next.plotOptions),
|
|
81
|
+
legend: { ...(chart.options.legend || {}), ...(next.legend || {}) },
|
|
82
|
+
};
|
|
83
|
+
if (next.series)
|
|
84
|
+
chart.series = next.series.map(makeSeries);
|
|
85
|
+
},
|
|
86
|
+
reflow() { },
|
|
87
|
+
redraw() { },
|
|
88
|
+
destroy() { },
|
|
89
|
+
};
|
|
90
|
+
return chart;
|
|
91
|
+
}
|
|
92
|
+
const makeFakeHC = () => ({ chart: (_c, options) => makeChart(options), setOptions() { } });
|
|
93
|
+
// --- mount helper (injects the fake before first render) ---------------------
|
|
94
|
+
const mounted = [];
|
|
95
|
+
async function mount(props) {
|
|
96
|
+
const el = document.createElement('nile-master-detail-chart');
|
|
97
|
+
el.style.cssText = 'display:block;width:600px;height:400px';
|
|
98
|
+
Object.assign(el, props);
|
|
99
|
+
host(el)._hc = makeFakeHC(); // skip the (failing) getHighcharts() import
|
|
100
|
+
document.body.appendChild(el);
|
|
101
|
+
mounted.push(el);
|
|
102
|
+
await el.updateComplete;
|
|
103
|
+
await el.updateComplete; // updated() re-applies built options after firstUpdated()
|
|
104
|
+
return el;
|
|
105
|
+
}
|
|
106
|
+
afterEach(() => {
|
|
107
|
+
while (mounted.length)
|
|
108
|
+
mounted.pop().remove();
|
|
109
|
+
});
|
|
110
|
+
const detailSeries = (el) => host(el).detailChart.series;
|
|
111
|
+
const detailOpts = (el) => host(el).detailChart.options;
|
|
112
|
+
const masterOpts = (el) => host(el).masterChart.options;
|
|
113
|
+
const stackingOf = (opts) => opts?.plotOptions?.series?.stacking ?? null;
|
|
114
|
+
const pointCount = (s) => s.points.length;
|
|
115
|
+
describe('NileMasterDetailChart — property defaults', () => {
|
|
116
|
+
it('1. is defined', () => {
|
|
117
|
+
expect(customElements.get('nile-master-detail-chart')).to.exist;
|
|
118
|
+
});
|
|
119
|
+
it('2. renders', async () => {
|
|
120
|
+
const el = await fixture(html `<nile-master-detail-chart></nile-master-detail-chart>`);
|
|
121
|
+
expect(el).to.exist;
|
|
122
|
+
expect(el.shadowRoot).to.not.be.null;
|
|
123
|
+
});
|
|
124
|
+
it('3. series defaults to an empty array', async () => {
|
|
125
|
+
const el = await fixture(html `<nile-master-detail-chart></nile-master-detail-chart>`);
|
|
126
|
+
expect(el.series).to.deep.equal([]);
|
|
127
|
+
});
|
|
128
|
+
it('4. stacking defaults to empty string', async () => {
|
|
129
|
+
const el = await fixture(html `<nile-master-detail-chart></nile-master-detail-chart>`);
|
|
130
|
+
expect(el.stacking).to.equal('');
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
describe('NileMasterDetailChart — multi-series', () => {
|
|
134
|
+
it('5. renders one detail series per entry with the given names and colours', async () => {
|
|
135
|
+
const el = await mount({ series: SERIES });
|
|
136
|
+
const series = detailSeries(el);
|
|
137
|
+
expect(series.length).to.equal(3);
|
|
138
|
+
expect(series.map((s) => s.name)).to.deep.equal(['Alpha', 'Beta', 'Gamma']);
|
|
139
|
+
expect(series.map((s) => s.options.color)).to.deep.equal(['#ff0000', '#00ff00', '#0000ff']);
|
|
140
|
+
});
|
|
141
|
+
it('6. renders one master series per entry', async () => {
|
|
142
|
+
const el = await mount({ series: SERIES });
|
|
143
|
+
expect(host(el).masterChart.series.length).to.equal(3);
|
|
144
|
+
});
|
|
145
|
+
it('7. series (non-empty) wins over data / seriesName / seriesColor', async () => {
|
|
146
|
+
const el = await mount({ series: SERIES, data: SINGLE, seriesName: 'Ignored', seriesColor: '#111111' });
|
|
147
|
+
expect(detailSeries(el).length).to.equal(3);
|
|
148
|
+
expect(detailSeries(el)[0].name).to.equal('Alpha');
|
|
149
|
+
});
|
|
150
|
+
it('24. master inherits the detail palette (options.colors) with 2+ series', async () => {
|
|
151
|
+
const colors = ['#111111', '#222222', '#333333'];
|
|
152
|
+
const el = await mount({ series: SERIES, options: { colors } });
|
|
153
|
+
expect(masterOpts(el).colors).to.deep.equal(colors);
|
|
154
|
+
});
|
|
155
|
+
it('25. masterOptions.colors still wins over the inherited palette', async () => {
|
|
156
|
+
const el = await mount({ series: SERIES, options: { colors: ['#111111'] }, masterOptions: { colors: ['#999999'] } });
|
|
157
|
+
expect(masterOpts(el).colors).to.deep.equal(['#999999']);
|
|
158
|
+
});
|
|
159
|
+
it('26. single-series master does not inherit options.colors (unchanged)', async () => {
|
|
160
|
+
const el = await mount({ data: SINGLE, options: { colors: ['#111111'] } });
|
|
161
|
+
expect(masterOpts(el).colors).to.equal(undefined);
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
describe('NileMasterDetailChart — stacking', () => {
|
|
165
|
+
it("8. stacking 'normal' sets stacking on both panes", async () => {
|
|
166
|
+
const el = await mount({ series: SERIES, stacking: 'normal' });
|
|
167
|
+
expect(stackingOf(detailOpts(el))).to.equal('normal');
|
|
168
|
+
expect(stackingOf(masterOpts(el))).to.equal('normal');
|
|
169
|
+
});
|
|
170
|
+
it("9. stacking 'percent' sets percent stacking on both panes", async () => {
|
|
171
|
+
const el = await mount({ series: SERIES, stacking: 'percent' });
|
|
172
|
+
expect(stackingOf(detailOpts(el))).to.equal('percent');
|
|
173
|
+
expect(stackingOf(masterOpts(el))).to.equal('percent');
|
|
174
|
+
});
|
|
175
|
+
it('10. no stacking when stacking is unset', async () => {
|
|
176
|
+
const el = await mount({ series: SERIES });
|
|
177
|
+
expect(stackingOf(detailOpts(el))).to.be.null;
|
|
178
|
+
expect(stackingOf(masterOpts(el))).to.be.null;
|
|
179
|
+
});
|
|
180
|
+
it('11. an unknown stacking value means no stacking', async () => {
|
|
181
|
+
const el = await mount({ series: SERIES, stacking: 'bogus' });
|
|
182
|
+
expect(stackingOf(detailOpts(el))).to.be.null;
|
|
183
|
+
});
|
|
184
|
+
it('17. options can override the detail stacking', async () => {
|
|
185
|
+
const el = await mount({
|
|
186
|
+
series: SERIES,
|
|
187
|
+
stacking: 'normal',
|
|
188
|
+
options: { plotOptions: { series: { stacking: undefined } } },
|
|
189
|
+
});
|
|
190
|
+
expect(stackingOf(detailOpts(el))).to.be.null;
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
describe('NileMasterDetailChart — legend', () => {
|
|
194
|
+
it('12. legend is enabled on the detail pane with 2+ series', async () => {
|
|
195
|
+
const el = await mount({ series: SERIES });
|
|
196
|
+
expect(detailOpts(el).legend.enabled).to.be.true;
|
|
197
|
+
});
|
|
198
|
+
it('13. legend is disabled on the detail pane with a single series', async () => {
|
|
199
|
+
const el = await mount({ series: [SERIES[0]] });
|
|
200
|
+
expect(detailOpts(el).legend.enabled).to.not.be.true;
|
|
201
|
+
});
|
|
202
|
+
it('18. options can override the detail legend', async () => {
|
|
203
|
+
const el = await mount({ series: SERIES, options: { legend: { enabled: false } } });
|
|
204
|
+
expect(detailOpts(el).legend.enabled).to.not.be.true;
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
describe('NileMasterDetailChart — extremes, selection, reset', () => {
|
|
208
|
+
it('14. data extremes span the union of all series x values', async () => {
|
|
209
|
+
const el = await mount({ series: SERIES });
|
|
210
|
+
const { dataMin, dataMax } = host(el).dataExtremes();
|
|
211
|
+
expect(dataMin).to.equal(1);
|
|
212
|
+
expect(dataMax).to.equal(4); // only Gamma reaches x=4
|
|
213
|
+
});
|
|
214
|
+
it('15. applySelection refilters every detail series to the range', async () => {
|
|
215
|
+
const el = await mount({ series: SERIES });
|
|
216
|
+
host(el).applySelection(2, 3);
|
|
217
|
+
// Alpha/Beta have x in {1,2,3} → 2 points in [2,3]; Gamma {1,2,3,4} → also 2.
|
|
218
|
+
expect(detailSeries(el).map(pointCount)).to.deep.equal([2, 2, 2]);
|
|
219
|
+
});
|
|
220
|
+
it('16. resetZoom restores every detail series to its full data', async () => {
|
|
221
|
+
const el = await mount({ series: SERIES });
|
|
222
|
+
host(el).applySelection(2, 2);
|
|
223
|
+
el.resetZoom();
|
|
224
|
+
await el.updateComplete;
|
|
225
|
+
expect(detailSeries(el).map(pointCount)).to.deep.equal([3, 3, 4]);
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
describe('NileMasterDetailChart — single-series regression (data, unchanged)', () => {
|
|
229
|
+
it('19. renders exactly one detail series from data', async () => {
|
|
230
|
+
const el = await mount({ data: SINGLE, seriesName: 'Solo' });
|
|
231
|
+
expect(detailSeries(el).length).to.equal(1);
|
|
232
|
+
expect(detailSeries(el)[0].name).to.equal('Solo');
|
|
233
|
+
});
|
|
234
|
+
it('20. keeps the legend disabled for a single data series', async () => {
|
|
235
|
+
const el = await mount({ data: SINGLE });
|
|
236
|
+
expect(detailOpts(el).legend.enabled).to.not.be.true;
|
|
237
|
+
});
|
|
238
|
+
it('21. applySelection filters the single series', async () => {
|
|
239
|
+
const el = await mount({ data: SINGLE });
|
|
240
|
+
host(el).applySelection(2, 3);
|
|
241
|
+
expect(pointCount(detailSeries(el)[0])).to.equal(2);
|
|
242
|
+
});
|
|
243
|
+
it('22. data extremes come from the single series x values', async () => {
|
|
244
|
+
const el = await mount({ data: SINGLE });
|
|
245
|
+
const { dataMin, dataMax } = host(el).dataExtremes();
|
|
246
|
+
expect(dataMin).to.equal(1);
|
|
247
|
+
expect(dataMax).to.equal(4);
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
describe('NileChart → master-detail passthrough', () => {
|
|
251
|
+
it('23. passes series and stacking down to the inner nile-master-detail-chart', async () => {
|
|
252
|
+
const el = await fixture(html `<nile-chart style="display:block;width:600px;height:400px"></nile-chart>`);
|
|
253
|
+
el.config = { chart: { type: 'master-detail', series: SERIES, stacking: 'normal' } };
|
|
254
|
+
await el.updateComplete;
|
|
255
|
+
await el.updateComplete;
|
|
256
|
+
const inner = el.shadowRoot.querySelector('nile-master-detail-chart');
|
|
257
|
+
expect(inner, 'inner master-detail chart should render').to.exist;
|
|
258
|
+
expect(inner.series).to.deep.equal(SERIES);
|
|
259
|
+
expect(inner.stacking).to.equal('normal');
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
//# sourceMappingURL=nile-master-detail-chart.test.js.map
|