@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
package/README.md
CHANGED
|
@@ -36,6 +36,11 @@ 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.39 (November 17, 2026)
|
|
40
|
+
- Nile Chart: Charts with no data now show a "No data" empty state (customise via the `empty-title`, `empty-description` and `empty-ghost` slots; `emptyGhost: false` hides the ghost chart) (UIF-1417)
|
|
41
|
+
- Nile Chart: Lighter gridlines, adjustable with the new `gridLineStrength` option (0–100 or `'12%'`; `0` hides them) (UIF-1417)
|
|
42
|
+
- Nile Chart: Supports Highcharts 13.1.1; the `highcharts` peer dependency is now pinned to `13.1.1` (NILE-016, UIF-1418)
|
|
43
|
+
|
|
39
44
|
#### Version 2.9.38 (November 16, 2026)
|
|
40
45
|
- Nile Chart: The header info icon now uses `nile-lite-tooltip` (UIF-1416)
|
|
41
46
|
- Nile KPI Chart: The value info icon and the trend, value, label and description tooltips now use `nile-lite-tooltip`, shown only when the text is truncated (UIF-1416)
|
|
@@ -23,6 +23,8 @@ export interface AqConfigType {
|
|
|
23
23
|
noHeader?: boolean;
|
|
24
24
|
/** Remove the `border-bottom` divider under the header, keeping the header itself. */
|
|
25
25
|
noBorder?: boolean;
|
|
26
|
+
/** Gridline strength (0–100, or a percentage string like `'12%'`). Tints the theme's gridline token; 0 hides them. Defaults to 10% (light) / 12% (dark). */
|
|
27
|
+
gridLineStrength?: string | number;
|
|
26
28
|
summary?: string;
|
|
27
29
|
toggleLabel?: string;
|
|
28
30
|
/** AI chat panel configuration. */
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Highcharts 13 compatibility shims, applied once by `highcharts-provider.ts`.
|
|
3
|
+
*
|
|
4
|
+
* Both shims feature-detect the Highcharts 13 code path they work around, so on
|
|
5
|
+
* Highcharts 12.5.0 they are no-ops.
|
|
6
|
+
*
|
|
7
|
+
* 1. Point matching on update (`Series#matchPoints`, new in 13).
|
|
8
|
+
* Every nile-*-chart re-renders with `chart.update(options, true, true)`,
|
|
9
|
+
* which soft-updates series data by matching new points to old ones by `x`.
|
|
10
|
+
* In 13.x the search index only advances for `requireSorting` series, so in
|
|
11
|
+
* unsorted series with repeated x values (heatmap, scatter, bubble, …) every
|
|
12
|
+
* new point matches the FIRST old point with that x: updates overwrite each
|
|
13
|
+
* other and cells are drawn in the wrong place (e.g. a heatmap row goes
|
|
14
|
+
* empty). For those series we skip matching, which makes `setData` replace
|
|
15
|
+
* the points outright — the same as `setData(data, …, updatePoints=false)`.
|
|
16
|
+
*
|
|
17
|
+
* 2. Palette CSS variables inside shadow DOM.
|
|
18
|
+
* In 13.x the default colours are `var(--highcharts-*)`, defined by a
|
|
19
|
+
* `<style class="highcharts-palette">` that Highcharts injects into the
|
|
20
|
+
* chart SVG with a `:root { … }` selector. Nile charts render inside shadow
|
|
21
|
+
* roots, where `:root` matches nothing, so the variables are undefined and
|
|
22
|
+
* fills fall back to black (map shading, legends, zoom buttons, timeline
|
|
23
|
+
* labels, …). We widen the selector to `:root, :host` so it also matches
|
|
24
|
+
* inside the chart's shadow root, and pin the container to the light colour
|
|
25
|
+
* scheme (the 12.5.0 look) unless the chart sets `palette.colorScheme`.
|
|
26
|
+
*/
|
|
27
|
+
export declare function applyHighchartsCompat(H: unknown): void;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Highcharts 13 compatibility shims, applied once by `highcharts-provider.ts`.
|
|
3
|
+
*
|
|
4
|
+
* Both shims feature-detect the Highcharts 13 code path they work around, so on
|
|
5
|
+
* Highcharts 12.5.0 they are no-ops.
|
|
6
|
+
*
|
|
7
|
+
* 1. Point matching on update (`Series#matchPoints`, new in 13).
|
|
8
|
+
* Every nile-*-chart re-renders with `chart.update(options, true, true)`,
|
|
9
|
+
* which soft-updates series data by matching new points to old ones by `x`.
|
|
10
|
+
* In 13.x the search index only advances for `requireSorting` series, so in
|
|
11
|
+
* unsorted series with repeated x values (heatmap, scatter, bubble, …) every
|
|
12
|
+
* new point matches the FIRST old point with that x: updates overwrite each
|
|
13
|
+
* other and cells are drawn in the wrong place (e.g. a heatmap row goes
|
|
14
|
+
* empty). For those series we skip matching, which makes `setData` replace
|
|
15
|
+
* the points outright — the same as `setData(data, …, updatePoints=false)`.
|
|
16
|
+
*
|
|
17
|
+
* 2. Palette CSS variables inside shadow DOM.
|
|
18
|
+
* In 13.x the default colours are `var(--highcharts-*)`, defined by a
|
|
19
|
+
* `<style class="highcharts-palette">` that Highcharts injects into the
|
|
20
|
+
* chart SVG with a `:root { … }` selector. Nile charts render inside shadow
|
|
21
|
+
* roots, where `:root` matches nothing, so the variables are undefined and
|
|
22
|
+
* fills fall back to black (map shading, legends, zoom buttons, timeline
|
|
23
|
+
* labels, …). We widen the selector to `:root, :host` so it also matches
|
|
24
|
+
* inside the chart's shadow root, and pin the container to the light colour
|
|
25
|
+
* scheme (the 12.5.0 look) unless the chart sets `palette.colorScheme`.
|
|
26
|
+
*/
|
|
27
|
+
const PATCHED = Symbol.for('nile.highcharts.matchPointsPatched');
|
|
28
|
+
const ROOT_SELECTOR = ':root {';
|
|
29
|
+
const SCOPED_SELECTOR = ':root, :host {';
|
|
30
|
+
function hasDuplicates(column) {
|
|
31
|
+
if (!column || column.length < 2)
|
|
32
|
+
return false;
|
|
33
|
+
const seen = new Set();
|
|
34
|
+
for (let i = 0; i < column.length; i++) {
|
|
35
|
+
const v = column[i];
|
|
36
|
+
if (seen.has(v))
|
|
37
|
+
return true;
|
|
38
|
+
seen.add(v);
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
function patchPointMatching(H) {
|
|
43
|
+
const proto = H.Series?.prototype;
|
|
44
|
+
const original = proto?.matchPoints;
|
|
45
|
+
if (!proto || typeof original !== 'function' || proto[PATCHED])
|
|
46
|
+
return;
|
|
47
|
+
proto.matchPoints = function (oldXColumn, ...rest) {
|
|
48
|
+
const table = this.dataTable;
|
|
49
|
+
const matchesByX = !this.requireSorting &&
|
|
50
|
+
!this.options?.dataSorting?.enabled &&
|
|
51
|
+
!table?.getColumn?.('id');
|
|
52
|
+
if (matchesByX && (hasDuplicates(oldXColumn) || hasDuplicates(table?.getColumn?.('x')))) {
|
|
53
|
+
return false; // fall back to replacing all points
|
|
54
|
+
}
|
|
55
|
+
return original.call(this, oldXColumn, ...rest);
|
|
56
|
+
};
|
|
57
|
+
proto[PATCHED] = true;
|
|
58
|
+
}
|
|
59
|
+
function scopePaletteToShadowRoot(H) {
|
|
60
|
+
if (!H.Chart || typeof H.addEvent !== 'function')
|
|
61
|
+
return;
|
|
62
|
+
H.addEvent(H.Chart, 'render', function () {
|
|
63
|
+
const style = this.renderer?.defs?.element?.querySelector?.('style.highcharts-palette');
|
|
64
|
+
if (!style)
|
|
65
|
+
return; // Highcharts 12 or styledMode — nothing injected
|
|
66
|
+
const css = style.textContent ?? '';
|
|
67
|
+
if (css.includes(ROOT_SELECTOR)) {
|
|
68
|
+
style.textContent = css.split(ROOT_SELECTOR).join(SCOPED_SELECTOR);
|
|
69
|
+
}
|
|
70
|
+
if (this.container && !this.options?.palette?.colorScheme) {
|
|
71
|
+
this.container.style.colorScheme = 'light';
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
export function applyHighchartsCompat(H) {
|
|
76
|
+
const hc = H;
|
|
77
|
+
patchPointMatching(hc);
|
|
78
|
+
scopePaletteToShadowRoot(hc);
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=highcharts-compat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NILE-016 — Highcharts 13 compatibility shims (see highcharts-compat.ts).
|
|
3
|
+
* Uses fake Highcharts objects so it runs without the peer dependency.
|
|
4
|
+
*/
|
|
5
|
+
import { expect } from '@open-wc/testing';
|
|
6
|
+
import { applyHighchartsCompat } from './highcharts-compat.js';
|
|
7
|
+
function fakeHighcharts(withMatchPoints = true) {
|
|
8
|
+
const calls = [];
|
|
9
|
+
const handlers = [];
|
|
10
|
+
const proto = {};
|
|
11
|
+
if (withMatchPoints) {
|
|
12
|
+
proto.matchPoints = function (...args) { calls.push(args); return true; };
|
|
13
|
+
}
|
|
14
|
+
const H = {
|
|
15
|
+
Series: { prototype: proto },
|
|
16
|
+
Chart: {},
|
|
17
|
+
addEvent: (_target, type, fn) => { if (type === 'render')
|
|
18
|
+
handlers.push(fn); },
|
|
19
|
+
};
|
|
20
|
+
return { H, proto, calls, handlers };
|
|
21
|
+
}
|
|
22
|
+
function fakeSeries(proto, opts) {
|
|
23
|
+
const series = Object.create(proto);
|
|
24
|
+
series.requireSorting = opts.requireSorting ?? false;
|
|
25
|
+
series.options = opts.dataSorting ? { dataSorting: { enabled: true } } : {};
|
|
26
|
+
series.dataTable = { getColumn: (name) => (name === 'x' ? opts.x : name === 'id' ? opts.id : undefined) };
|
|
27
|
+
return series;
|
|
28
|
+
}
|
|
29
|
+
describe('highcharts-compat', () => {
|
|
30
|
+
describe('point matching (Highcharts 13)', () => {
|
|
31
|
+
it('replaces points instead of matching when an unsorted series has repeated x', () => {
|
|
32
|
+
const { H, proto, calls } = fakeHighcharts();
|
|
33
|
+
applyHighchartsCompat(H);
|
|
34
|
+
const s = fakeSeries(proto, { x: [0, 1, 0, 1] });
|
|
35
|
+
expect(s.matchPoints([0, 1, 0, 1])).to.equal(false);
|
|
36
|
+
expect(calls).to.have.length(0);
|
|
37
|
+
});
|
|
38
|
+
it('also catches duplicates that only exist in the old data', () => {
|
|
39
|
+
const { H, proto } = fakeHighcharts();
|
|
40
|
+
applyHighchartsCompat(H);
|
|
41
|
+
const s = fakeSeries(proto, { x: [0, 1, 2] });
|
|
42
|
+
expect(s.matchPoints([5, 5])).to.equal(false);
|
|
43
|
+
});
|
|
44
|
+
it('keeps Highcharts matching for unique x values', () => {
|
|
45
|
+
const { H, proto, calls } = fakeHighcharts();
|
|
46
|
+
applyHighchartsCompat(H);
|
|
47
|
+
const s = fakeSeries(proto, { x: [0, 1, 2] });
|
|
48
|
+
expect(s.matchPoints([0, 1, 2], 'ids')).to.equal(true);
|
|
49
|
+
expect(calls).to.deep.equal([[[0, 1, 2], 'ids']]);
|
|
50
|
+
});
|
|
51
|
+
it('keeps Highcharts matching for sorted series, id-keyed data and data sorting', () => {
|
|
52
|
+
const { H, proto, calls } = fakeHighcharts();
|
|
53
|
+
applyHighchartsCompat(H);
|
|
54
|
+
expect(fakeSeries(proto, { x: [0, 0], requireSorting: true }).matchPoints([0, 0])).to.equal(true);
|
|
55
|
+
expect(fakeSeries(proto, { x: [0, 0], id: ['a', 'b'] }).matchPoints([0, 0])).to.equal(true);
|
|
56
|
+
expect(fakeSeries(proto, { x: [0, 0], dataSorting: true }).matchPoints([0, 0])).to.equal(true);
|
|
57
|
+
expect(calls).to.have.length(3);
|
|
58
|
+
});
|
|
59
|
+
it('patches only once and is a no-op without matchPoints (Highcharts 12)', () => {
|
|
60
|
+
const a = fakeHighcharts();
|
|
61
|
+
applyHighchartsCompat(a.H);
|
|
62
|
+
const patched = a.proto.matchPoints;
|
|
63
|
+
applyHighchartsCompat(a.H);
|
|
64
|
+
expect(a.proto.matchPoints).to.equal(patched);
|
|
65
|
+
const b = fakeHighcharts(false);
|
|
66
|
+
applyHighchartsCompat(b.H);
|
|
67
|
+
expect(b.proto.matchPoints).to.be.undefined;
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
describe('palette variables in shadow DOM (Highcharts 13)', () => {
|
|
71
|
+
function chartWithPalette(css, palette) {
|
|
72
|
+
const defs = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
|
|
73
|
+
let style = null;
|
|
74
|
+
if (css !== null) {
|
|
75
|
+
style = document.createElement('style');
|
|
76
|
+
style.className = 'highcharts-palette';
|
|
77
|
+
style.textContent = css;
|
|
78
|
+
defs.appendChild(style);
|
|
79
|
+
}
|
|
80
|
+
const container = document.createElement('div');
|
|
81
|
+
return { chart: { renderer: { defs: { element: defs } }, container, options: { palette } }, style, container };
|
|
82
|
+
}
|
|
83
|
+
it('widens :root to :root, :host and pins the light colour scheme', () => {
|
|
84
|
+
const { H, handlers } = fakeHighcharts();
|
|
85
|
+
applyHighchartsCompat(H);
|
|
86
|
+
const { chart, style, container } = chartWithPalette(':root {\n --a: 1;\n}\n@supports (x) {\n :root {\n --a: 2;\n }\n}');
|
|
87
|
+
handlers.forEach(h => h.call(chart));
|
|
88
|
+
expect(style.textContent).to.not.match(/(^|[^,]\s*):root \{/m);
|
|
89
|
+
expect(style.textContent.match(/:root, :host \{/g)).to.have.length(2);
|
|
90
|
+
expect(container.style.colorScheme).to.equal('light');
|
|
91
|
+
});
|
|
92
|
+
it('is idempotent across redraws', () => {
|
|
93
|
+
const { H, handlers } = fakeHighcharts();
|
|
94
|
+
applyHighchartsCompat(H);
|
|
95
|
+
const { chart, style } = chartWithPalette(':root {\n}');
|
|
96
|
+
handlers.forEach(h => h.call(chart));
|
|
97
|
+
handlers.forEach(h => h.call(chart));
|
|
98
|
+
expect(style.textContent).to.equal(':root, :host {\n}');
|
|
99
|
+
});
|
|
100
|
+
it('respects an explicit palette.colorScheme', () => {
|
|
101
|
+
const { H, handlers } = fakeHighcharts();
|
|
102
|
+
applyHighchartsCompat(H);
|
|
103
|
+
const { chart, container } = chartWithPalette(':root {\n}', { colorScheme: 'dark' });
|
|
104
|
+
handlers.forEach(h => h.call(chart));
|
|
105
|
+
expect(container.style.colorScheme).to.equal('');
|
|
106
|
+
});
|
|
107
|
+
it('does nothing when no palette style exists (Highcharts 12 / styledMode)', () => {
|
|
108
|
+
const { H, handlers } = fakeHighcharts();
|
|
109
|
+
applyHighchartsCompat(H);
|
|
110
|
+
const { chart, container } = chartWithPalette(null);
|
|
111
|
+
handlers.forEach(h => h.call(chart));
|
|
112
|
+
expect(container.style.colorScheme).to.equal('');
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
//# sourceMappingURL=highcharts-compat.test.js.map
|
|
@@ -6,8 +6,20 @@
|
|
|
6
6
|
* Consumer must load Highcharts via `<script>` before nile-visualization.
|
|
7
7
|
*/
|
|
8
8
|
import { registerNileChartEvents } from './chart-events.js';
|
|
9
|
+
import { applyHighchartsCompat } from './highcharts-compat.js';
|
|
9
10
|
let _Highcharts;
|
|
10
11
|
let _initPromise = null;
|
|
12
|
+
// Gridline strength per theme (the gridline colour below is a token mixed at this strength).
|
|
13
|
+
const GRID_LINE_CSS = `:root { --nile-chart-grid-line-strength: 10%; }
|
|
14
|
+
:root[data-theme="dark"] { --nile-chart-grid-line-strength: 12%; }`;
|
|
15
|
+
function injectGridLineVariables() {
|
|
16
|
+
if (typeof document === 'undefined' || document.getElementById('nile-chart-grid-line'))
|
|
17
|
+
return;
|
|
18
|
+
const style = document.createElement('style');
|
|
19
|
+
style.id = 'nile-chart-grid-line';
|
|
20
|
+
style.textContent = GRID_LINE_CSS;
|
|
21
|
+
document.head.appendChild(style);
|
|
22
|
+
}
|
|
11
23
|
async function init() {
|
|
12
24
|
if (_Highcharts)
|
|
13
25
|
return _Highcharts;
|
|
@@ -187,6 +199,8 @@ async function init() {
|
|
|
187
199
|
'or load it globally via <script> before nile-visualization.');
|
|
188
200
|
}
|
|
189
201
|
_Highcharts.setOptions({
|
|
202
|
+
xAxis: { gridLineColor: '#F2F4F7' },
|
|
203
|
+
yAxis: { gridLineColor: '#F2F4F7' },
|
|
190
204
|
chart: {
|
|
191
205
|
backgroundColor: 'transparent',
|
|
192
206
|
style: {
|
|
@@ -194,7 +208,24 @@ async function init() {
|
|
|
194
208
|
},
|
|
195
209
|
},
|
|
196
210
|
});
|
|
211
|
+
injectGridLineVariables();
|
|
212
|
+
// SVG `stroke` attributes can't take var(), so tint the gridlines through inline CSS instead; it follows the theme live.
|
|
213
|
+
// An axis that sets its own `gridLineColor` keeps it.
|
|
214
|
+
const H = _Highcharts;
|
|
215
|
+
const GRID_TINT = 'color-mix(in srgb, var(--ng-colors-text-quaternary-500, #717680) var(--nile-chart-grid-line-strength, 10%), transparent)';
|
|
216
|
+
const hasOwnColor = (axes) => [].concat(axes ?? []).some((a) => a?.gridLineColor);
|
|
217
|
+
H.addEvent(H.Chart, 'render', function () {
|
|
218
|
+
const { xAxis, yAxis } = this.userOptions ?? {};
|
|
219
|
+
for (const [axisClass, axes] of [['xaxis', xAxis], ['yaxis', yAxis]]) {
|
|
220
|
+
if (hasOwnColor(axes))
|
|
221
|
+
continue;
|
|
222
|
+
this.container?.querySelectorAll(`.highcharts-${axisClass}-grid .highcharts-grid-line`).forEach((line) => {
|
|
223
|
+
line.style.stroke = GRID_TINT;
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
});
|
|
197
227
|
registerNileChartEvents(_Highcharts);
|
|
228
|
+
applyHighchartsCompat(_Highcharts);
|
|
198
229
|
return _Highcharts;
|
|
199
230
|
}
|
|
200
231
|
/**
|
|
@@ -109,6 +109,8 @@ export interface NileChartConfigBase extends HighchartsPassthroughConfig {
|
|
|
109
109
|
noPadding?: boolean;
|
|
110
110
|
/** Remove the `border-bottom` divider under the header (maps to the `no-border` attribute). */
|
|
111
111
|
noBorder?: boolean;
|
|
112
|
+
/** Gridline strength (0–100, or a percentage string like `'12%'`). Tints the theme's gridline token; 0 hides them. Defaults to 10% (light) / 12% (dark). */
|
|
113
|
+
gridLineStrength?: string | number;
|
|
112
114
|
height?: string;
|
|
113
115
|
loading?: boolean;
|
|
114
116
|
options?: HighchartsOptions;
|
|
@@ -128,6 +130,7 @@ export interface NileChartConfigBase extends HighchartsPassthroughConfig {
|
|
|
128
130
|
chartShadow?: string;
|
|
129
131
|
chartPadding?: string | number;
|
|
130
132
|
chartMinHeight?: string | number;
|
|
133
|
+
emptyGhost?: boolean;
|
|
131
134
|
loadingText?: string;
|
|
132
135
|
loadingColor?: string;
|
|
133
136
|
loadingFontSize?: string | number;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type TemplateResult } from 'lit';
|
|
2
|
+
/** Default empty state for `<nile-chart>`: detection (`isChartEmpty`) and markup (`renderChartEmptyState`). */
|
|
3
|
+
export declare const EMPTY_STATE_TITLE = "No data";
|
|
4
|
+
export declare const EMPTY_STATE_DESCRIPTION = "There is nothing to show for this chart yet. Data will appear here once it is available.";
|
|
5
|
+
/** True only for a known chart type with nothing to plot; anything unrecognised is not empty. */
|
|
6
|
+
export declare function isChartEmpty(config: unknown): boolean;
|
|
7
|
+
/** A config size as a safe CSS length, or undefined (dropped) when it isn't one. Numbers become px. */
|
|
8
|
+
export declare function toSafeCssLength(value: unknown): string | undefined;
|
|
9
|
+
export interface ChartEmptyStateOptions {
|
|
10
|
+
/** Draw the ghost chart behind the message. Default true. */
|
|
11
|
+
ghost?: boolean;
|
|
12
|
+
/** Chart type; picks the ghost chart drawn behind the message. */
|
|
13
|
+
type?: string;
|
|
14
|
+
/** CSS height of the configured chart, if any; keeps the card from resizing. */
|
|
15
|
+
height?: string;
|
|
16
|
+
/** Configured `chartMinHeight`, forwarded as the chart's min-height variable. */
|
|
17
|
+
minHeight?: string | number;
|
|
18
|
+
}
|
|
19
|
+
/** Replaces the plotting area with a ghost behind a title and description (slots: `empty-title`, `empty-description`, `empty-ghost`; parts: `empty-badge`, the badge around the title text). */
|
|
20
|
+
export declare function renderChartEmptyState(opts?: ChartEmptyStateOptions): TemplateResult;
|
|
21
|
+
/** Fits the description, then enables a title/description tooltip only while that text is cut short. */
|
|
22
|
+
export declare function syncChartEmptyTruncation(emptyEl: Element): void;
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import { html, nothing } from 'lit';
|
|
2
|
+
import { styleMap } from 'lit/directives/style-map.js';
|
|
3
|
+
import { renderChartGhost } from './nile-chart-skeleton.js';
|
|
4
|
+
/** Default empty state for `<nile-chart>`: detection (`isChartEmpty`) and markup (`renderChartEmptyState`). */
|
|
5
|
+
export const EMPTY_STATE_TITLE = 'No data';
|
|
6
|
+
export const EMPTY_STATE_DESCRIPTION = 'There is nothing to show for this chart yet. Data will appear here once it is available.';
|
|
7
|
+
// Tooltip width cap; longer text wraps. The tooltip mounts on <body>, where :root tokens resolve.
|
|
8
|
+
const TOOLTIP_MAX_WIDTH = 'var(--ng-width-64)';
|
|
9
|
+
// Types whose `data` is `[{ name, data: [...] }]`.
|
|
10
|
+
const SERIES_TYPES = new Set([
|
|
11
|
+
'bar', 'line', 'area', 'column', 'spline', 'scatter', 'bubble', 'radar',
|
|
12
|
+
'trendline', 'anomaly', 'boxplot', 'stacked', 'cluster', 'columnPyramid',
|
|
13
|
+
'columnRange', 'lollipop', 'invertedArea', 'areaSpline', 'areaNegative',
|
|
14
|
+
'areaRange', 'radialBar', 'spiderweb',
|
|
15
|
+
]);
|
|
16
|
+
// Types whose `data` is a flat list of points with a `y` value; empty when no point has a usable `y`.
|
|
17
|
+
const VALUE_POINT_TYPES = new Set([
|
|
18
|
+
'pie', 'donut', 'funnel', 'variablePie',
|
|
19
|
+
'master-detail', // data: { x, y }[]
|
|
20
|
+
'columnDrilldown', // data: { name, y, drilldown }[]
|
|
21
|
+
]);
|
|
22
|
+
// Flat point lists whose point shape varies; only an empty list counts as empty.
|
|
23
|
+
const LIST_ONLY_TYPES = new Set([
|
|
24
|
+
'waterfall', 'heatmap', 'timeline', 'xrange', 'dumbbell',
|
|
25
|
+
'dumbbellLower', 'dumbbellUpper', // same { name, low, high } points as dumbbell
|
|
26
|
+
'euler', // data: { sets, value }[]
|
|
27
|
+
'vector', // data: { x, y, length, direction }[]
|
|
28
|
+
'flame', // data (flame / icicle) or sunburstData (sunburst); isChartEmpty picks by `layout`
|
|
29
|
+
]);
|
|
30
|
+
// Raw numeric samples: `data` is `number[]`; empty when no entry is a finite number (zero counts).
|
|
31
|
+
const NUMERIC_LIST_TYPES = new Set(['histogram', 'bellcurve']);
|
|
32
|
+
// Numeric fields a point can carry; a point object with none of these counts as plottable.
|
|
33
|
+
const MEASURE_KEYS = ['y', 'value', 'z', 'low', 'high', 'q1', 'median', 'q3', 'open', 'close', 'x2'];
|
|
34
|
+
const present = (v) => v !== null && v !== undefined;
|
|
35
|
+
/** A usable value: present, and not NaN or ±Infinity. Zero is a value. */
|
|
36
|
+
const hasValue = (v) => present(v) && !(typeof v === 'number' && !Number.isFinite(v));
|
|
37
|
+
/** True unless the point is absent (null/undefined/NaN, or a tuple/object with no value). Zero is plottable. */
|
|
38
|
+
function isPlottablePoint(point) {
|
|
39
|
+
if (!present(point))
|
|
40
|
+
return false;
|
|
41
|
+
if (typeof point === 'number')
|
|
42
|
+
return hasValue(point);
|
|
43
|
+
if (Array.isArray(point)) {
|
|
44
|
+
if (point.length === 0)
|
|
45
|
+
return false;
|
|
46
|
+
// [x, y] / [x, low, high]: the leading x alone doesn't make a point.
|
|
47
|
+
return point.slice(point.length > 1 ? 1 : 0).some(hasValue);
|
|
48
|
+
}
|
|
49
|
+
if (typeof point === 'object') {
|
|
50
|
+
const obj = point;
|
|
51
|
+
const keys = MEASURE_KEYS.filter((k) => k in obj);
|
|
52
|
+
return keys.length === 0 || keys.some((k) => hasValue(obj[k]));
|
|
53
|
+
}
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
function seriesState(series) {
|
|
57
|
+
if (!series || typeof series !== 'object')
|
|
58
|
+
return 'unknown';
|
|
59
|
+
const s = series;
|
|
60
|
+
// Forecast inputs carry `actual` / `projected` instead of (or beside) `data`.
|
|
61
|
+
const lists = [s.data, s.actual, s.projected].filter(Array.isArray);
|
|
62
|
+
if (lists.length === 0)
|
|
63
|
+
return 'unknown';
|
|
64
|
+
return lists.some((list) => list.some(isPlottablePoint)) ? 'data' : 'empty';
|
|
65
|
+
}
|
|
66
|
+
const hasId = (v) => (typeof v === 'string' && v !== '') || (typeof v === 'number' && Number.isFinite(v));
|
|
67
|
+
/** Organization: needs a node with an `id` and a link with `from` and `to`; unlinked nodes paint nothing. */
|
|
68
|
+
function isOrganizationEmpty(nodes, links) {
|
|
69
|
+
if (!Array.isArray(nodes) || !Array.isArray(links))
|
|
70
|
+
return true;
|
|
71
|
+
const node = nodes.some((n) => !!n && typeof n === 'object' && hasId(n.id));
|
|
72
|
+
const link = links.some((l) => {
|
|
73
|
+
const e = l;
|
|
74
|
+
return !!e && typeof e === 'object' && hasId(e.from) && hasId(e.to);
|
|
75
|
+
});
|
|
76
|
+
return !(node && link);
|
|
77
|
+
}
|
|
78
|
+
/** A line-column side is `{ name, data: number[] }` (an array of such parts is tolerated). */
|
|
79
|
+
function lineColumnSideHasData(side) {
|
|
80
|
+
if (Array.isArray(side))
|
|
81
|
+
return side.some(lineColumnSideHasData);
|
|
82
|
+
if (!side || typeof side !== 'object')
|
|
83
|
+
return false;
|
|
84
|
+
const data = side.data;
|
|
85
|
+
return Array.isArray(data) && data.some((n) => typeof n === 'number' && Number.isFinite(n));
|
|
86
|
+
}
|
|
87
|
+
/** Line-column: either side having a finite number is enough; `categories` alone is not data. */
|
|
88
|
+
function isLineColumnEmpty(columnSeries, lineSeries) {
|
|
89
|
+
return !lineColumnSideHasData(columnSeries) && !lineColumnSideHasData(lineSeries);
|
|
90
|
+
}
|
|
91
|
+
const isFiniteNumber = (n) => typeof n === 'number' && Number.isFinite(n);
|
|
92
|
+
/** Fan: data is a line point with a finite `y` or a band point with finite `low` and `high`. */
|
|
93
|
+
function isFanEmpty(lineData, bands) {
|
|
94
|
+
const line = Array.isArray(lineData) && lineData.some((p) => !!p && typeof p === 'object' && isFiniteNumber(p.y));
|
|
95
|
+
if (line)
|
|
96
|
+
return false;
|
|
97
|
+
const band = Array.isArray(bands) && bands.some((b) => {
|
|
98
|
+
const pts = b?.data;
|
|
99
|
+
return Array.isArray(pts) && pts.some((d) => {
|
|
100
|
+
const pt = d;
|
|
101
|
+
return !!pt && typeof pt === 'object' && isFiniteNumber(pt.low) && isFiniteNumber(pt.high);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
return !band;
|
|
105
|
+
}
|
|
106
|
+
function isPolygonPoint(p) {
|
|
107
|
+
if (Array.isArray(p))
|
|
108
|
+
return isFiniteNumber(p[0]) && isFiniteNumber(p[1]);
|
|
109
|
+
if (!p || typeof p !== 'object')
|
|
110
|
+
return false;
|
|
111
|
+
const { x, y } = p;
|
|
112
|
+
return isFiniteNumber(x) && isFiniteNumber(y);
|
|
113
|
+
}
|
|
114
|
+
/** Polygon: an `options.series` array (even `[]`) overrides `series`; empty without a finite x/y point. */
|
|
115
|
+
function isPolygonEmpty(series, optionsSeries) {
|
|
116
|
+
if (!Array.isArray(series))
|
|
117
|
+
return true;
|
|
118
|
+
const effective = Array.isArray(optionsSeries) ? optionsSeries : series;
|
|
119
|
+
return !effective.some((s) => {
|
|
120
|
+
const data = s?.data;
|
|
121
|
+
return Array.isArray(data) && data.some(isPolygonPoint);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
/** True only for a known chart type with nothing to plot; anything unrecognised is not empty. */
|
|
125
|
+
export function isChartEmpty(config) {
|
|
126
|
+
if (!config || typeof config !== 'object')
|
|
127
|
+
return false;
|
|
128
|
+
const cfg = config;
|
|
129
|
+
const type = cfg.type;
|
|
130
|
+
if (!type)
|
|
131
|
+
return false;
|
|
132
|
+
if (type === 'organization') {
|
|
133
|
+
// Data supplied through the passthrough options is data.
|
|
134
|
+
if ([cfg.series, cfg.options?.series].some((s) => Array.isArray(s) && s.length > 0))
|
|
135
|
+
return false;
|
|
136
|
+
return isOrganizationEmpty(cfg.nodes, cfg.links);
|
|
137
|
+
}
|
|
138
|
+
if (type === 'line-column') {
|
|
139
|
+
// Data supplied through the passthrough options is data.
|
|
140
|
+
if ([cfg.series, cfg.options?.series].some((s) => Array.isArray(s) && s.length > 0))
|
|
141
|
+
return false;
|
|
142
|
+
return isLineColumnEmpty(cfg.columnSeries, cfg.lineSeries);
|
|
143
|
+
}
|
|
144
|
+
// Polygon's `series` is its dataset, so it skips the passthrough shortcut below.
|
|
145
|
+
if (type === 'polygon')
|
|
146
|
+
return isPolygonEmpty(cfg.series, cfg.options?.series);
|
|
147
|
+
if (type === 'fan') {
|
|
148
|
+
// Data supplied through the passthrough options is data.
|
|
149
|
+
if ([cfg.series, cfg.options?.series].some((s) => Array.isArray(s) && s.length > 0))
|
|
150
|
+
return false;
|
|
151
|
+
return isFanEmpty(cfg.lineData, cfg.bands);
|
|
152
|
+
}
|
|
153
|
+
const isKnown = SERIES_TYPES.has(type) || VALUE_POINT_TYPES.has(type) || LIST_ONLY_TYPES.has(type)
|
|
154
|
+
|| NUMERIC_LIST_TYPES.has(type);
|
|
155
|
+
if (!isKnown)
|
|
156
|
+
return false;
|
|
157
|
+
// Data supplied through the passthrough options is data.
|
|
158
|
+
const passthrough = [cfg.series, cfg.options?.series];
|
|
159
|
+
if (passthrough.some((s) => Array.isArray(s) && s.length > 0))
|
|
160
|
+
return false;
|
|
161
|
+
// A flame chart in the sunburst layout plots `sunburstData` and ignores `data`.
|
|
162
|
+
const data = cfg.type === 'flame' && cfg.layout === 'sunburst' ? cfg.sunburstData : cfg.data;
|
|
163
|
+
if (!Array.isArray(data) || data.length === 0)
|
|
164
|
+
return true;
|
|
165
|
+
if (SERIES_TYPES.has(type))
|
|
166
|
+
return data.every((s) => seriesState(s) === 'empty');
|
|
167
|
+
if (VALUE_POINT_TYPES.has(type))
|
|
168
|
+
return data.every((p) => !isPlottablePoint(p));
|
|
169
|
+
if (NUMERIC_LIST_TYPES.has(type))
|
|
170
|
+
return !data.some((n) => typeof n === 'number' && Number.isFinite(n));
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
// Allowlist for config-driven sizes: a length, `0`, `auto`, or a calc()/min()/max()/clamp()/var() expression.
|
|
174
|
+
const CSS_LENGTH = /^(?:-?(?:\d+\.?\d*|\.\d+)(?:px|%|em|rem|vh|vw|vmin|vmax|ch)|0|auto|(?:calc|min|max|clamp|var)\([\w\s.,%+\-*/()]*\))$/;
|
|
175
|
+
/** A config size as a safe CSS length, or undefined (dropped) when it isn't one. Numbers become px. */
|
|
176
|
+
export function toSafeCssLength(value) {
|
|
177
|
+
if (typeof value === 'number')
|
|
178
|
+
return Number.isFinite(value) ? `${value}px` : undefined;
|
|
179
|
+
if (typeof value !== 'string')
|
|
180
|
+
return undefined;
|
|
181
|
+
const v = value.trim();
|
|
182
|
+
return CSS_LENGTH.test(v) ? v : undefined;
|
|
183
|
+
}
|
|
184
|
+
/** Replaces the plotting area with a ghost behind a title and description (slots: `empty-title`, `empty-description`, `empty-ghost`; parts: `empty-badge`, the badge around the title text). */
|
|
185
|
+
export function renderChartEmptyState(opts = {}) {
|
|
186
|
+
// styleMap sets each property on its own, so a stray `;` in a value can't add declarations.
|
|
187
|
+
const height = toSafeCssLength(opts.height);
|
|
188
|
+
const minHeight = toSafeCssLength(opts.minHeight);
|
|
189
|
+
const style = {
|
|
190
|
+
...(height && height !== '100%' ? { height } : {}),
|
|
191
|
+
...(minHeight ? { '--nile-chart-min-height': minHeight } : {}),
|
|
192
|
+
};
|
|
193
|
+
return html `
|
|
194
|
+
<div class="nile-chart-empty" part="empty-state" role="status" style=${styleMap(style)}>
|
|
195
|
+
${opts.ghost === false
|
|
196
|
+
? nothing
|
|
197
|
+
: html `<div class="nile-chart-empty__ghost" part="empty-ghost" aria-hidden="true">
|
|
198
|
+
<slot name="empty-ghost">${renderChartGhost(opts.type)}</slot>
|
|
199
|
+
</div>`}
|
|
200
|
+
<nile-lite-tooltip class="nile-chart-empty__tip nile-chart-empty__tip--title" placement="top" .maxWidth=${TOOLTIP_MAX_WIDTH} disabled>
|
|
201
|
+
<div class="nile-chart-empty__title" part="empty-title">
|
|
202
|
+
<span class="nile-chart-empty__badge" part="empty-badge"><slot name="empty-title">${EMPTY_STATE_TITLE}</slot></span>
|
|
203
|
+
</div>
|
|
204
|
+
</nile-lite-tooltip>
|
|
205
|
+
<nile-lite-tooltip class="nile-chart-empty__tip nile-chart-empty__tip--description" placement="top" .maxWidth=${TOOLTIP_MAX_WIDTH} disabled>
|
|
206
|
+
<div class="nile-chart-empty__description" part="empty-description">
|
|
207
|
+
<slot name="empty-description">${EMPTY_STATE_DESCRIPTION}</slot>
|
|
208
|
+
</div>
|
|
209
|
+
</nile-lite-tooltip>
|
|
210
|
+
</div>
|
|
211
|
+
`;
|
|
212
|
+
}
|
|
213
|
+
/** The text a part currently shows: the slotted text if there is any, else the built-in fallback. */
|
|
214
|
+
function partText(part) {
|
|
215
|
+
const slot = part.querySelector('slot');
|
|
216
|
+
const nodes = slot?.assignedNodes({ flatten: true }) ?? [];
|
|
217
|
+
const raw = nodes.length ? nodes.map((n) => n.textContent ?? '').join('') : slot?.textContent ?? '';
|
|
218
|
+
return raw.replace(/\s+/g, ' ').trim();
|
|
219
|
+
}
|
|
220
|
+
/** In a short cell, show only as many whole description lines as fit (hidden if none). The title never shrinks. */
|
|
221
|
+
function snapDescriptionToWholeLines(emptyEl) {
|
|
222
|
+
const tip = emptyEl.querySelector('.nile-chart-empty__tip--description');
|
|
223
|
+
const desc = emptyEl.querySelector('.nile-chart-empty__description');
|
|
224
|
+
if (!tip || !desc)
|
|
225
|
+
return;
|
|
226
|
+
// Measure from the natural layout.
|
|
227
|
+
desc.style.removeProperty('line-clamp');
|
|
228
|
+
desc.style.removeProperty('-webkit-line-clamp');
|
|
229
|
+
tip.hidden = false;
|
|
230
|
+
// Overflow = how far the description (plus bottom padding) runs past the cell.
|
|
231
|
+
const descRect = desc.getBoundingClientRect();
|
|
232
|
+
const paddingBottom = parseFloat(getComputedStyle(emptyEl).paddingBottom) || 0;
|
|
233
|
+
const overflow = descRect.bottom + paddingBottom - emptyEl.getBoundingClientRect().bottom;
|
|
234
|
+
if (overflow <= 0.5)
|
|
235
|
+
return; // everything fits as is
|
|
236
|
+
const lineHeight = parseFloat(getComputedStyle(desc).lineHeight);
|
|
237
|
+
if (!(lineHeight > 0))
|
|
238
|
+
return;
|
|
239
|
+
const lines = Math.floor((descRect.height - overflow) / lineHeight);
|
|
240
|
+
if (lines < 1)
|
|
241
|
+
tip.hidden = true;
|
|
242
|
+
else {
|
|
243
|
+
desc.style.setProperty('-webkit-line-clamp', String(lines));
|
|
244
|
+
desc.style.setProperty('line-clamp', String(lines));
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
/** Fits the description, then enables a title/description tooltip only while that text is cut short. */
|
|
248
|
+
export function syncChartEmptyTruncation(emptyEl) {
|
|
249
|
+
snapDescriptionToWholeLines(emptyEl);
|
|
250
|
+
for (const part of ['title', 'description']) {
|
|
251
|
+
const tip = emptyEl.querySelector(`.nile-chart-empty__tip--${part}`);
|
|
252
|
+
const text = emptyEl.querySelector(`.nile-chart-empty__${part}`);
|
|
253
|
+
if (!tip || !text)
|
|
254
|
+
continue;
|
|
255
|
+
const full = partText(text);
|
|
256
|
+
// A hidden description has nothing to hover, so its tooltip stays off.
|
|
257
|
+
const show = full !== '' && !tip.hidden && text.scrollHeight > text.clientHeight + 1;
|
|
258
|
+
if (tip.content !== (show ? full : ''))
|
|
259
|
+
tip.content = show ? full : '';
|
|
260
|
+
if (tip.disabled !== !show)
|
|
261
|
+
tip.disabled = !show;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
//# sourceMappingURL=nile-chart-empty.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './nile-chart';
|