@aquera/nile-visualization 2.9.42 → 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 CHANGED
@@ -36,6 +36,9 @@ To run a local development server that serves the basic demo located in `demo/in
36
36
 
37
37
  In this section, you can find the updates for each release of `nile-visualization`. It's a good practice to maintain detailed release notes to help users and developers understand what changes have been made from one version to another and how these changes might affect their projects.
38
38
 
39
+ #### Version 2.9.43 (November 18, 2026)
40
+ - Nile Chart: The master-detail chart now takes several series and can stack them. Set `series` (`{ name, data, color? }[]`, replaces `data` when non-empty) and `stacking` (`normal` or `percent`) on `type: 'master-detail'` or `<nile-master-detail-chart>`; both panes stack, the detail pane shows a legend and a shared tooltip for 2+ series, and dragging the master selection now zooms every series instead of only the first. Single-series charts are unchanged (UIF-1425)
41
+
39
42
  #### Version 2.9.42 (November 18, 2026)
40
43
  - Nile KPI Chart: Compact titles now wrap onto up to 3 lines with or without header controls, and the new `title-overflow` property (`ellipsis` default, or `break`) controls how an oversized word is handled; a tooltip with the full title shows only when it is truncated. Other variants are unchanged. Also fixes the white strip beside the compact sparkline in a scaled wrapper and the sparkline tooltip width and edge clamping (UIF-1424)
41
44
  - Nile Charts: Fixed the clipped bottom border of the "No data" empty-state badge (UIF-1424)
@@ -40,7 +40,7 @@ export type { BoxplotBox, BoxplotSeriesData } from './nile-boxplot-chart/index.j
40
40
  export { NileTimelineChart } from './nile-timeline-chart/index.js';
41
41
  export type { TimelineEvent } from './nile-timeline-chart/index.js';
42
42
  export { NileMasterDetailChart } from './nile-master-detail-chart/index.js';
43
- export type { MasterDetailPoint, MasterDetailSeriesType } from './nile-master-detail-chart/index.js';
43
+ export type { MasterDetailPoint, MasterDetailSeries, MasterDetailSeriesType, MasterDetailStacking } from './nile-master-detail-chart/index.js';
44
44
  export { NileDumbbellChart } from './nile-dumbbell-chart/index.js';
45
45
  export type { DumbbellPoint } from './nile-dumbbell-chart/index.js';
46
46
  export { NileDumbbellLowerChart } from './nile-dumbbell-lower-chart/index.js';
@@ -325,8 +325,48 @@ const WAVE2_TRANSLATORS = {
325
325
  return o;
326
326
  },
327
327
  'master-detail': (c) => {
328
- const o = cartesian(c, 'line');
329
- return { ...o, dataZoom: [{ type: 'slider', height: 22, bottom: 4 }, { type: 'inside' }], grid: { ...o.grid, bottom: 58 } };
328
+ const zoom = { dataZoom: [{ type: 'slider', height: 22, bottom: 4 }, { type: 'inside' }] };
329
+ if (!(Array.isArray(c.series) && c.series.length)) {
330
+ const o = cartesian(c, 'line');
331
+ return { ...o, ...zoom, grid: { ...o.grid, bottom: 58 } };
332
+ }
333
+ // Multi-series form: { name, data: { x, y }[], color? }[] on a time/value x-axis,
334
+ // stacked when `stacking` is set. ECharts has no percent stacking, so percent
335
+ // mode normalises each x to the share of its column total first.
336
+ const stacking = c.stacking === 'normal' || c.stacking === 'percent' ? c.stacking : undefined;
337
+ const area = !['line', 'spline', 'column', 'bar'].includes(c.detailType ?? 'area');
338
+ const bar = c.detailType === 'column' || c.detailType === 'bar';
339
+ const totals = new Map();
340
+ if (stacking === 'percent') {
341
+ for (const s of c.series)
342
+ for (const p of s.data ?? [])
343
+ totals.set(p.x, (totals.get(p.x) ?? 0) + (Number(p.y) || 0));
344
+ }
345
+ const value = (p) => {
346
+ if (stacking !== 'percent')
347
+ return p.y;
348
+ const total = totals.get(p.x) ?? 0;
349
+ return total === 0 ? 0 : ((Number(p.y) || 0) / total) * 100;
350
+ };
351
+ const series = c.series.map((s) => ({
352
+ name: s.name,
353
+ type: bar ? 'bar' : 'line',
354
+ smooth: c.detailType === 'spline' || c.detailType === 'areaspline' || undefined,
355
+ showSymbol: false,
356
+ ...(area && !bar ? { areaStyle: {} } : {}),
357
+ ...(stacking ? { stack: 'total' } : {}),
358
+ ...(s.color ? { itemStyle: { color: s.color }, lineStyle: { color: s.color } } : {}),
359
+ data: (s.data ?? []).map((p) => [p.x, value(p)]),
360
+ }));
361
+ const b = base(c, series.length);
362
+ return {
363
+ ...b,
364
+ ...zoom,
365
+ grid: { ...b.grid, bottom: 58 },
366
+ xAxis: { type: (c.xAxisType ?? 'datetime') === 'datetime' ? 'time' : 'value' },
367
+ yAxis: { type: 'value', name: c.yAxisTitle, ...(stacking === 'percent' ? { max: 100 } : {}) },
368
+ series,
369
+ };
330
370
  },
331
371
  'line-column': (c) => {
332
372
  // ONE value axis (dual axis is banned) — series carry their own form
@@ -1,8 +1,13 @@
1
1
  import type { Options } from 'highcharts';
2
- import type { MasterDetailPoint, MasterDetailSeriesType, MasterDetailXAxisType } from '../../nile-master-detail-chart/nile-master-detail-chart.js';
2
+ import type { MasterDetailPoint, MasterDetailSeries, MasterDetailSeriesType, MasterDetailStacking, MasterDetailXAxisType } from '../../nile-master-detail-chart/nile-master-detail-chart.js';
3
3
  export interface ChartMasterDetailConfigType {
4
4
  type: 'master-detail';
5
- data: MasterDetailPoint[];
5
+ /** Single-series shorthand. Optional when `series` is given. */
6
+ data?: MasterDetailPoint[];
7
+ /** Several named series; when non-empty it replaces `data` / `seriesName` / `seriesColor`. */
8
+ series?: MasterDetailSeries[];
9
+ /** Stack the series on both panes. */
10
+ stacking?: MasterDetailStacking;
6
11
  seriesName?: string;
7
12
  seriesColor?: string;
8
13
  detailType?: MasterDetailSeriesType;
@@ -28,7 +28,7 @@ import type { HistogramSamples } from '../nile-histogram-chart/nile-histogram-ch
28
28
  import type { BellcurveSamples } from '../nile-bellcurve-chart/nile-bellcurve-chart.js';
29
29
  import type { BoxplotSeriesData } from '../nile-boxplot-chart/nile-boxplot-chart.js';
30
30
  import type { TimelineEvent } from '../nile-timeline-chart/nile-timeline-chart.js';
31
- import type { MasterDetailPoint } from '../nile-master-detail-chart/nile-master-detail-chart.js';
31
+ import type { MasterDetailPoint, MasterDetailSeries, MasterDetailStacking } from '../nile-master-detail-chart/nile-master-detail-chart.js';
32
32
  import type { DumbbellPoint } from '../nile-dumbbell-chart/nile-dumbbell-chart.js';
33
33
  import type { FanLinePoint, FanUncertaintyBand } from '../nile-fan-chart/nile-fan-chart.js';
34
34
  import type { FunnelDataPoint } from '../nile-funnel-chart/nile-funnel-chart.js';
@@ -410,7 +410,12 @@ export interface NileTimelineChartConfig extends NileChartConfigBase {
410
410
  }
411
411
  export interface NileMasterDetailChartConfig extends NileChartConfigBase {
412
412
  type: 'master-detail';
413
- data: MasterDetailPoint[];
413
+ /** Single-series shorthand. Optional when `series` is given. */
414
+ data?: MasterDetailPoint[];
415
+ /** Several named series; when non-empty it replaces `data` / `seriesName` / `seriesColor`. */
416
+ series?: MasterDetailSeries[];
417
+ /** Stack the series on both panes: `normal` or `percent`. */
418
+ stacking?: MasterDetailStacking;
414
419
  seriesName?: string;
415
420
  seriesColor?: string;
416
421
  detailType?: string;
@@ -150,6 +150,16 @@ export function isChartEmpty(config) {
150
150
  return false;
151
151
  return isFanEmpty(cfg.lineData, cfg.bands);
152
152
  }
153
+ if (type === 'master-detail' && Array.isArray(cfg.series) && cfg.series.length > 0) {
154
+ // Multi-series form: `series` is the dataset ({ name, data: { x, y }[] }[]), so
155
+ // it is empty only when no series has a plottable point.
156
+ const hasPoint = cfg.series.some((s) => Array.isArray(s?.data) && (s.data).some(isPlottablePoint));
157
+ if (hasPoint)
158
+ return false;
159
+ const optSeries = cfg.options?.series;
160
+ if (!(Array.isArray(optSeries) && optSeries.length > 0))
161
+ return true;
162
+ }
153
163
  const isKnown = SERIES_TYPES.has(type) || VALUE_POINT_TYPES.has(type) || LIST_ONLY_TYPES.has(type)
154
164
  || NUMERIC_LIST_TYPES.has(type);
155
165
  if (!isKnown)
@@ -1568,7 +1568,9 @@ let NileChart = NileChart_1 = class NileChart extends NileElement {
1568
1568
  ></nile-timeline-chart>`;
1569
1569
  case 'master-detail':
1570
1570
  return html `<nile-master-detail-chart
1571
- .data=${config.data}
1571
+ .data=${config.data ?? []}
1572
+ .series=${config.series ?? []}
1573
+ .stacking=${config.stacking ?? ''}
1572
1574
  .height=${this.hasAttribute('fit') ? null : (config.height ?? '100%')}
1573
1575
  .seriesName=${config.seriesName ?? ''}
1574
1576
  .seriesColor=${config.seriesColor ?? ''}
@@ -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
- private mapData;
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();
@@ -7,6 +7,7 @@ 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
+ export const MASTER_DETAIL_STACKING = ['normal', 'percent'];
10
11
  export const MASTER_DETAIL_SERIES_TYPES = [
11
12
  'area',
12
13
  'line',
@@ -31,6 +32,13 @@ let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
31
32
  this.data = [];
32
33
  this.seriesName = '';
33
34
  this.seriesColor = '';
35
+ /**
36
+ * Several named series. When non-empty it replaces `data` / `seriesName` /
37
+ * `seriesColor`. Series should share x values so stacks line up.
38
+ */
39
+ this.series = [];
40
+ /** Stack the series on both panes: `normal`, `percent`, or `''` for none. */
41
+ this.stacking = '';
34
42
  this.detailType = 'area';
35
43
  this.masterType = 'area';
36
44
  this.masterOnly = false;
@@ -143,6 +151,8 @@ let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
143
151
  }
144
152
  const props = [
145
153
  'data',
154
+ 'series',
155
+ 'stacking',
146
156
  'options',
147
157
  'masterOptions',
148
158
  'height',
@@ -168,7 +178,7 @@ let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
168
178
  'masterHeight', 'loadingText', 'loadingColor', 'loadingFontSize', 'loadingFontFamily', 'loadingBg'];
169
179
  if (cssVarProps.some(p => changedProperties.has(p)))
170
180
  this._syncCssVars();
171
- const objectProps = new Set(['data', 'options', 'masterOptions', 'legend']);
181
+ const objectProps = new Set(['data', 'series', 'options', 'masterOptions', 'legend']);
172
182
  const reallyChanged = (p) => {
173
183
  if (!changedProperties.has(p))
174
184
  return false;
@@ -217,14 +227,44 @@ let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
217
227
  });
218
228
  this.resizeObserver.observe(target);
219
229
  }
220
- mapData() {
221
- return this.data.map(d => ({ x: d.x, y: d.y }));
230
+ /** `series` when given, else one series built from `data` / `seriesName` / `seriesColor`. */
231
+ get _seriesList() {
232
+ if (Array.isArray(this.series) && this.series.length)
233
+ return this.series;
234
+ return [{ name: this.seriesName || 'Series', data: this.data ?? [], color: this.seriesColor || undefined }];
235
+ }
236
+ get _isMultiSeries() {
237
+ return this._seriesList.length > 1;
238
+ }
239
+ get _stackingMode() {
240
+ return MASTER_DETAIL_STACKING.includes(this.stacking)
241
+ ? this.stacking
242
+ : undefined;
243
+ }
244
+ /** Sorted, de-duplicated x values across every series. */
245
+ _allXs() {
246
+ const xs = new Set();
247
+ for (const s of this._seriesList)
248
+ for (const p of s.data ?? [])
249
+ xs.add(p.x);
250
+ return [...xs].sort((a, b) => a - b);
251
+ }
252
+ mapPoints(points, min = -Infinity, max = Infinity) {
253
+ return (points ?? []).filter(p => p.x >= min && p.x <= max).map(p => ({ x: p.x, y: p.y }));
254
+ }
255
+ buildSeries(type, min, max) {
256
+ return this._seriesList.map(s => ({
257
+ type,
258
+ name: s.name,
259
+ data: this.mapPoints(s.data, min, max),
260
+ color: s.color || undefined,
261
+ }));
222
262
  }
223
263
  dataExtremes() {
224
- const xs = this.data.map(p => p.x);
264
+ const xs = this._allXs();
225
265
  return {
226
- dataMin: xs.length ? Math.min(...xs) : 0,
227
- dataMax: xs.length ? Math.max(...xs) : 0,
266
+ dataMin: xs.length ? xs[0] : 0,
267
+ dataMax: xs.length ? xs[xs.length - 1] : 0,
228
268
  };
229
269
  }
230
270
  pointStep(xs) {
@@ -243,17 +283,17 @@ let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
243
283
  _zoomWindow(min, max) {
244
284
  if (!this._isCategoricalMaster || min !== max)
245
285
  return { min, max };
246
- const eps = this.pointStep(this.data.map(p => p.x).sort((a, b) => a - b)) * 1e-4;
286
+ const eps = this.pointStep(this._allXs()) * 1e-4;
247
287
  return { min: min - eps, max: max + eps };
248
288
  }
249
289
  _masterMinRange() {
250
- const step = this.pointStep(this.data.map(p => p.x).sort((a, b) => a - b));
290
+ const step = this.pointStep(this._allXs());
251
291
  if (!step)
252
292
  return undefined;
253
293
  return this._isCategoricalMaster ? step * 1e-5 : step;
254
294
  }
255
295
  snapSelection(min, max) {
256
- const xs = this.data.map(p => p.x).sort((a, b) => a - b);
296
+ const xs = this._allXs();
257
297
  if (xs.length === 0)
258
298
  return { min, max };
259
299
  const step = this.pointStep(xs);
@@ -275,10 +315,22 @@ let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
275
315
  }
276
316
  buildDetailOptions() {
277
317
  const { min, max } = this.defaultSelection();
278
- const detailData = this.mapData().filter(p => {
279
- const x = p.x;
280
- return x >= min && x <= max;
281
- });
318
+ const multi = this._isMultiSeries;
319
+ const stacking = this._stackingMode;
320
+ // Single series keeps its original tooltip. Several series get one shared
321
+ // tooltip headed by the x value, a line per series, and the share in percent mode.
322
+ const tooltip = multi
323
+ ? {
324
+ shared: true,
325
+ pointFormat: stacking === 'percent'
326
+ ? '<span style="color:{point.color}">●</span> {series.name}: <b>{point.y}</b> ({point.percentage:.0f}%)<br/>'
327
+ : '<span style="color:{point.color}">●</span> {series.name}: <b>{point.y}</b><br/>',
328
+ }
329
+ : {
330
+ headerFormat: '<b>{series.name}</b><br>',
331
+ pointFormat: '{point.x} : {point.y}',
332
+ shared: true,
333
+ };
282
334
  const merged = deepMerge({
283
335
  chart: { type: this.detailType, reflow: true },
284
336
  title: { text: this.detailTitle || undefined },
@@ -292,25 +344,15 @@ let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
292
344
  min: this.yAxisMin ?? undefined,
293
345
  max: this.yAxisMax ?? undefined,
294
346
  },
295
- tooltip: {
296
- headerFormat: '<b>{series.name}</b><br>',
297
- pointFormat: '{point.x} : {point.y}',
298
- shared: true,
299
- },
300
- legend: { enabled: false },
347
+ tooltip,
348
+ legend: { enabled: multi },
301
349
  plotOptions: {
302
350
  series: {
351
+ stacking,
303
352
  marker: { enabled: false, states: { hover: { enabled: true, radius: 3 } } },
304
353
  },
305
354
  },
306
- series: [
307
- {
308
- type: this.detailType,
309
- name: this.seriesName || 'Series',
310
- data: detailData,
311
- color: this.seriesColor || undefined,
312
- },
313
- ],
355
+ series: this.buildSeries(this.detailType, min, max),
314
356
  credits: { enabled: false },
315
357
  }, this.options);
316
358
  // Only the detail pane takes the built-in rules. The master is a fixed short
@@ -363,6 +405,11 @@ let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
363
405
  },
364
406
  },
365
407
  title: { text: this.masterTitle || undefined },
408
+ // With several series the legend lives on the detail pane, so the master
409
+ // must use the same colours or the overview contradicts it. Inherit the
410
+ // detail palette (`options.colors`, which nile-chart fills from its theme)
411
+ // unless `masterOptions.colors` sets one. Single-series output is unchanged.
412
+ ...(this._isMultiSeries && Array.isArray(this.options?.colors) ? { colors: this.options.colors } : {}),
366
413
  // A capped master (see the `min(…, 40%)` height in the stylesheet) can get
367
414
  // short enough that the 30px label band above leaves almost no plot. Below
368
415
  // that point drop the date labels and give the space back to the overview
@@ -399,19 +446,13 @@ let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
399
446
  credits: { enabled: false },
400
447
  plotOptions: {
401
448
  series: {
449
+ stacking: this._stackingMode,
402
450
  lineWidth: 1,
403
451
  marker: { enabled: false, states: { hover: { enabled: mo, radius: 3 } } },
404
452
  enableMouseTracking: mo,
405
453
  },
406
454
  },
407
- series: [
408
- {
409
- type: this.masterType,
410
- name: this.seriesName || 'Series',
411
- data: this.mapData(),
412
- color: this.seriesColor || undefined,
413
- },
414
- ],
455
+ series: this.buildSeries(this.masterType),
415
456
  }, this.masterOptions);
416
457
  // The master keeps its own height-aware rule rather than the shared cartesian
417
458
  // set, but it honors the same opt-out: `no-responsive` means no built-in
@@ -446,8 +487,14 @@ let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
446
487
  return;
447
488
  }
448
489
  if (this.detailChart) {
449
- const detailData = this.data.filter(p => p.x >= min && p.x <= max).map(p => ({ x: p.x, y: p.y }));
450
- this.detailChart.series[0].setData(detailData, true);
490
+ // Refilter every series we own (by index) and redraw once, so a stack
491
+ // stays consistent while zooming. Extra series supplied only through
492
+ // `options.series` are left as they are.
493
+ const chart = this.detailChart;
494
+ this._seriesList.forEach((s, i) => {
495
+ chart.series[i]?.setData(this.mapPoints(s.data, min, max), false);
496
+ });
497
+ chart.redraw();
451
498
  }
452
499
  const { dataMin, dataMax } = this.dataExtremes();
453
500
  const xAxis = this.masterChart.xAxis[0];
@@ -553,6 +600,12 @@ __decorate([
553
600
  __decorate([
554
601
  property({ type: String, attribute: 'series-color' })
555
602
  ], NileMasterDetailChart.prototype, "seriesColor", void 0);
603
+ __decorate([
604
+ property({ type: Array })
605
+ ], NileMasterDetailChart.prototype, "series", void 0);
606
+ __decorate([
607
+ property({ type: String })
608
+ ], NileMasterDetailChart.prototype, "stacking", void 0);
556
609
  __decorate([
557
610
  property({ type: String, attribute: 'detail-type' })
558
611
  ], NileMasterDetailChart.prototype, "detailType", void 0);
@@ -0,0 +1,2 @@
1
+ import './nile-master-detail-chart';
2
+ import '../nile-chart/nile-chart';
@@ -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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aquera/nile-visualization",
3
- "version": "2.9.42",
3
+ "version": "2.9.43",
4
4
  "description": "A visualization Library for the Nile Design System",
5
5
  "license": "MIT",
6
6
  "author": "Aquera Inc",