@aquera/nile-visualization 2.9.45 → 2.9.46
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/internal/types/chart-heatmap-config.type.d.ts +2 -0
- package/dist/src/internal/utils/highcharts-compat.d.ts +9 -2
- package/dist/src/internal/utils/highcharts-compat.js +10 -3
- package/dist/src/internal/utils/highcharts-compat.test.js +2 -2
- package/dist/src/nile-chart/nile-chart-config.d.ts +2 -0
- package/dist/src/nile-chart/nile-chart.js +2 -2
- package/dist/src/nile-heatmap-chart/heatmap-colors.d.ts +45 -0
- package/dist/src/nile-heatmap-chart/heatmap-colors.js +104 -0
- package/dist/src/nile-heatmap-chart/nile-heatmap-chart.d.ts +23 -0
- package/dist/src/nile-heatmap-chart/nile-heatmap-chart.js +74 -11
- package/dist/src/nile-heatmap-chart/nile-heatmap-chart.test.d.ts +1 -0
- package/dist/src/nile-heatmap-chart/nile-heatmap-chart.test.js +154 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -36,6 +36,13 @@ 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.46 (November 19, 2026)
|
|
40
|
+
- Nile Charts: Charts follow the page's light/dark colour scheme. Chart containers now inherit the page's `color-scheme` instead of always using light, so Highcharts' text, axis, legend and gridline colours go dark under `:root[data-theme="dark"]` (or `color-scheme: dark`) and switch live when the theme changes. Light-only pages look the same as before; a chart's own `palette.colorScheme` still wins (UIF-1429)
|
|
41
|
+
- Nile Heatmap: Default colours are theme-aware. With no `minColor` / `maxColor` set, the scale runs #ffffff → #1e40af in light mode (as before) and #1a2440 → #60a5fa in dark mode; the cell border is #e2e8f0 / #22262f. Re-theme from CSS with `--nile-heatmap-min-color`, `--nile-heatmap-max-color` and `--nile-heatmap-border-color`. Explicit `minColor` / `maxColor` are unchanged (UIF-1429)
|
|
42
|
+
- Nile Heatmap: Cell values are black or white, whichever is more readable on that cell in the current theme (at least 4.5:1 contrast), with no text outline. Apps that set their own data-label `format`, `formatter` or colour keep Highcharts' labels (UIF-1429)
|
|
43
|
+
- Nile Heatmap: The chart is created once on first render (it was created twice, and `nile-chart-ready` fired twice) (UIF-1429)
|
|
44
|
+
- Demo: new heatmap-only page (`demo/heatmap.html`) and a light/dark switch on both demo pages (UIF-1429)
|
|
45
|
+
|
|
39
46
|
#### Version 2.9.45 (November 19, 2026)
|
|
40
47
|
- Nile Chart: `type: 'grid'` charts take a `columnChooser` option (`true`, or `{ title, tooltip, icon, showCount, showReset, resetLabel, indicator, placement }`). It adds a column-settings icon to the chart header, after any `header-actions` content and before the built-in icons, that opens a `nile-floating-panel` of column checkboxes with a visible/total count and a Reset action; a dot on the icon shows while columns are hidden. Toggles fire the grid's `nile-column-visibility-change`, and a new `config.columnVisibility` re-seeds the panel. Needs `nile-floating-panel`, `nile-checkbox` and `nile-glyph` loaded on the page; column locks need `@aquera/nile-data-grid` 0.9.7. New CSS parts `column-chooser-trigger`, `column-chooser-glyph`, `column-chooser-indicator`. `ChartGridConfigType` and `NileChartColumnChooserConfig` are exported. Off unless set (UIF-1428)
|
|
41
48
|
|
|
@@ -9,7 +9,9 @@ export interface ChartHeatmapConfigType {
|
|
|
9
9
|
seriesName?: string;
|
|
10
10
|
colorMin?: number;
|
|
11
11
|
colorMax?: number;
|
|
12
|
+
/** Colour of the lowest value. Default: theme-aware (`--nile-heatmap-min-color`, else #ffffff light / #1a2440 dark). */
|
|
12
13
|
minColor?: string;
|
|
14
|
+
/** Colour of the highest value. Default: theme-aware (`--nile-heatmap-max-color`, else #1e40af light / #60a5fa dark). */
|
|
13
15
|
maxColor?: string;
|
|
14
16
|
colorAxisTitle?: string;
|
|
15
17
|
showDataLabels?: boolean;
|
|
@@ -21,7 +21,14 @@
|
|
|
21
21
|
* roots, where `:root` matches nothing, so the variables are undefined and
|
|
22
22
|
* fills fall back to black (map shading, legends, zoom buttons, timeline
|
|
23
23
|
* labels, …). We widen the selector to `:root, :host` so it also matches
|
|
24
|
-
* inside the chart's shadow root
|
|
25
|
-
*
|
|
24
|
+
* inside the chart's shadow root.
|
|
25
|
+
*
|
|
26
|
+
* The palette values are `light-dark()` pairs, so they resolve against the
|
|
27
|
+
* chart container's `color-scheme`. Highcharts sets that container to
|
|
28
|
+
* `light dark` (the OS preference) by default; we set it to `inherit` instead,
|
|
29
|
+
* so a chart follows the page it sits on: light on a light-only page (no
|
|
30
|
+
* `color-scheme`, the 12.5.0 look), dark under `:root[data-theme="dark"]` /
|
|
31
|
+
* `color-scheme: dark`, and switching live when the page theme changes. An
|
|
32
|
+
* explicit `palette.colorScheme` on the chart still wins.
|
|
26
33
|
*/
|
|
27
34
|
export declare function applyHighchartsCompat(H: unknown): void;
|
|
@@ -21,8 +21,15 @@
|
|
|
21
21
|
* roots, where `:root` matches nothing, so the variables are undefined and
|
|
22
22
|
* fills fall back to black (map shading, legends, zoom buttons, timeline
|
|
23
23
|
* labels, …). We widen the selector to `:root, :host` so it also matches
|
|
24
|
-
* inside the chart's shadow root
|
|
25
|
-
*
|
|
24
|
+
* inside the chart's shadow root.
|
|
25
|
+
*
|
|
26
|
+
* The palette values are `light-dark()` pairs, so they resolve against the
|
|
27
|
+
* chart container's `color-scheme`. Highcharts sets that container to
|
|
28
|
+
* `light dark` (the OS preference) by default; we set it to `inherit` instead,
|
|
29
|
+
* so a chart follows the page it sits on: light on a light-only page (no
|
|
30
|
+
* `color-scheme`, the 12.5.0 look), dark under `:root[data-theme="dark"]` /
|
|
31
|
+
* `color-scheme: dark`, and switching live when the page theme changes. An
|
|
32
|
+
* explicit `palette.colorScheme` on the chart still wins.
|
|
26
33
|
*/
|
|
27
34
|
const PATCHED = Symbol.for('nile.highcharts.matchPointsPatched');
|
|
28
35
|
const ROOT_SELECTOR = ':root {';
|
|
@@ -68,7 +75,7 @@ function scopePaletteToShadowRoot(H) {
|
|
|
68
75
|
style.textContent = css.split(ROOT_SELECTOR).join(SCOPED_SELECTOR);
|
|
69
76
|
}
|
|
70
77
|
if (this.container && !this.options?.palette?.colorScheme) {
|
|
71
|
-
this.container.style.colorScheme = '
|
|
78
|
+
this.container.style.colorScheme = 'inherit';
|
|
72
79
|
}
|
|
73
80
|
});
|
|
74
81
|
}
|
|
@@ -80,14 +80,14 @@ describe('highcharts-compat', () => {
|
|
|
80
80
|
const container = document.createElement('div');
|
|
81
81
|
return { chart: { renderer: { defs: { element: defs } }, container, options: { palette } }, style, container };
|
|
82
82
|
}
|
|
83
|
-
it('widens :root to :root, :host and
|
|
83
|
+
it('widens :root to :root, :host and makes the container inherit the page colour scheme', () => {
|
|
84
84
|
const { H, handlers } = fakeHighcharts();
|
|
85
85
|
applyHighchartsCompat(H);
|
|
86
86
|
const { chart, style, container } = chartWithPalette(':root {\n --a: 1;\n}\n@supports (x) {\n :root {\n --a: 2;\n }\n}');
|
|
87
87
|
handlers.forEach(h => h.call(chart));
|
|
88
88
|
expect(style.textContent).to.not.match(/(^|[^,]\s*):root \{/m);
|
|
89
89
|
expect(style.textContent.match(/:root, :host \{/g)).to.have.length(2);
|
|
90
|
-
expect(container.style.colorScheme).to.equal('
|
|
90
|
+
expect(container.style.colorScheme).to.equal('inherit');
|
|
91
91
|
});
|
|
92
92
|
it('is idempotent across redraws', () => {
|
|
93
93
|
const { H, handlers } = fakeHighcharts();
|
|
@@ -466,7 +466,9 @@ export interface NileHeatmapChartConfig extends NileChartConfigBase {
|
|
|
466
466
|
seriesName?: string;
|
|
467
467
|
colorMin?: number;
|
|
468
468
|
colorMax?: number;
|
|
469
|
+
/** Colour of the lowest value. Default: theme-aware (`--nile-heatmap-min-color`, else #ffffff light / #1a2440 dark). */
|
|
469
470
|
minColor?: string;
|
|
471
|
+
/** Colour of the highest value. Default: theme-aware (`--nile-heatmap-max-color`, else #1e40af light / #60a5fa dark). */
|
|
470
472
|
maxColor?: string;
|
|
471
473
|
colorAxisTitle?: string;
|
|
472
474
|
showDataLabels?: boolean;
|
|
@@ -1963,8 +1963,8 @@ let NileChart = NileChart_1 = class NileChart extends NileElement {
|
|
|
1963
1963
|
.seriesName=${config.seriesName ?? ''}
|
|
1964
1964
|
.colorMin=${config.colorMin ?? null}
|
|
1965
1965
|
.colorMax=${config.colorMax ?? null}
|
|
1966
|
-
.minColor=${config.minColor ?? '
|
|
1967
|
-
.maxColor=${config.maxColor ?? '
|
|
1966
|
+
.minColor=${config.minColor ?? ''}
|
|
1967
|
+
.maxColor=${config.maxColor ?? ''}
|
|
1968
1968
|
.colorAxisTitle=${config.colorAxisTitle ?? ''}
|
|
1969
1969
|
.showDataLabels=${config.showDataLabels ?? true}
|
|
1970
1970
|
.showLegend=${config.legend?.show ?? true}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Theme-aware colours for `<nile-heatmap-chart>`.
|
|
3
|
+
*
|
|
4
|
+
* Highcharts 13 blends colour-axis stops with CSS `color-mix(in srgb, min, max p%)`,
|
|
5
|
+
* so a stop can be any CSS colour, including `var()` and `light-dark()`. The defaults
|
|
6
|
+
* below are `light-dark()` pairs behind a CSS custom property, so a heatmap follows the
|
|
7
|
+
* page's `color-scheme` (see `highcharts-compat`) and apps can re-theme it from CSS:
|
|
8
|
+
*
|
|
9
|
+
* --nile-heatmap-min-color lowest value (light #ffffff, dark #1a2440)
|
|
10
|
+
* --nile-heatmap-max-color highest value (light #1e40af, dark #60a5fa)
|
|
11
|
+
* --nile-heatmap-border-color gaps between cells (light #e2e8f0, dark #22262f)
|
|
12
|
+
*
|
|
13
|
+
* Light values are the previous fixed defaults, so light pages look the same as before.
|
|
14
|
+
*/
|
|
15
|
+
export declare const heatmapDefaultMinColor: () => string;
|
|
16
|
+
export declare const heatmapDefaultMaxColor: () => string;
|
|
17
|
+
export declare const heatmapDefaultBorderColor: () => string;
|
|
18
|
+
export type Rgb = [number, number, number];
|
|
19
|
+
export interface ResolvedStops {
|
|
20
|
+
light: {
|
|
21
|
+
min: Rgb;
|
|
22
|
+
max: Rgb;
|
|
23
|
+
};
|
|
24
|
+
dark: {
|
|
25
|
+
min: Rgb;
|
|
26
|
+
max: Rgb;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/** Parses the computed-style forms browsers return: `rgb()/rgba()` and `color(srgb …)`. */
|
|
30
|
+
export declare function parseComputedColor(value: string): Rgb | null;
|
|
31
|
+
/** WCAG contrast ratio between two colours. */
|
|
32
|
+
export declare function contrastRatio(a: Rgb, b: Rgb): number;
|
|
33
|
+
/** Black or white, whichever contrasts more with `bg` (switch point ≈ luminance 0.179). */
|
|
34
|
+
export declare function readableTextOn(bg: Rgb): '#000000' | '#ffffff';
|
|
35
|
+
/**
|
|
36
|
+
* Label colour for a cell at position `t` (0 = min colour, 1 = max colour) on the scale:
|
|
37
|
+
* a single colour when both schemes agree, otherwise `light-dark(light, dark)`.
|
|
38
|
+
*/
|
|
39
|
+
export declare function heatmapLabelColor(t: number, stops: ResolvedStops): string;
|
|
40
|
+
/**
|
|
41
|
+
* Resolves `min`/`max` (any CSS colour, including `var()` and `light-dark()`) to sRGB in
|
|
42
|
+
* both colour schemes, using a probe element inside `root` so the component's CSS
|
|
43
|
+
* custom properties apply. Returns null if a colour can't be resolved to sRGB.
|
|
44
|
+
*/
|
|
45
|
+
export declare function resolveStops(root: ShadowRoot | HTMLElement, min: string, max: string): ResolvedStops | null;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Theme-aware colours for `<nile-heatmap-chart>`.
|
|
3
|
+
*
|
|
4
|
+
* Highcharts 13 blends colour-axis stops with CSS `color-mix(in srgb, min, max p%)`,
|
|
5
|
+
* so a stop can be any CSS colour, including `var()` and `light-dark()`. The defaults
|
|
6
|
+
* below are `light-dark()` pairs behind a CSS custom property, so a heatmap follows the
|
|
7
|
+
* page's `color-scheme` (see `highcharts-compat`) and apps can re-theme it from CSS:
|
|
8
|
+
*
|
|
9
|
+
* --nile-heatmap-min-color lowest value (light #ffffff, dark #1a2440)
|
|
10
|
+
* --nile-heatmap-max-color highest value (light #1e40af, dark #60a5fa)
|
|
11
|
+
* --nile-heatmap-border-color gaps between cells (light #e2e8f0, dark #22262f)
|
|
12
|
+
*
|
|
13
|
+
* Light values are the previous fixed defaults, so light pages look the same as before.
|
|
14
|
+
*/
|
|
15
|
+
const MIN = { light: '#ffffff', dark: '#1a2440' };
|
|
16
|
+
const MAX = { light: '#1e40af', dark: '#60a5fa' };
|
|
17
|
+
const BORDER = { light: '#e2e8f0', dark: '#22262f' };
|
|
18
|
+
function supportsLightDark() {
|
|
19
|
+
return (typeof CSS !== 'undefined' &&
|
|
20
|
+
typeof CSS.supports === 'function' &&
|
|
21
|
+
CSS.supports('color', 'light-dark(#fff, #000)'));
|
|
22
|
+
}
|
|
23
|
+
/** `var(--name, light-dark(light, dark))`, or the light value where `light-dark()` is unsupported. */
|
|
24
|
+
function themed(name, pair) {
|
|
25
|
+
const fallback = supportsLightDark() ? `light-dark(${pair.light}, ${pair.dark})` : pair.light;
|
|
26
|
+
return `var(${name}, ${fallback})`;
|
|
27
|
+
}
|
|
28
|
+
export const heatmapDefaultMinColor = () => themed('--nile-heatmap-min-color', MIN);
|
|
29
|
+
export const heatmapDefaultMaxColor = () => themed('--nile-heatmap-max-color', MAX);
|
|
30
|
+
export const heatmapDefaultBorderColor = () => themed('--nile-heatmap-border-color', BORDER);
|
|
31
|
+
/** Parses the computed-style forms browsers return: `rgb()/rgba()` and `color(srgb …)`. */
|
|
32
|
+
export function parseComputedColor(value) {
|
|
33
|
+
const v = value.trim();
|
|
34
|
+
let m = v.match(/^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)/i);
|
|
35
|
+
if (m)
|
|
36
|
+
return [Number(m[1]), Number(m[2]), Number(m[3])];
|
|
37
|
+
m = v.match(/^color\(\s*srgb\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)/i);
|
|
38
|
+
if (m)
|
|
39
|
+
return [Number(m[1]) * 255, Number(m[2]) * 255, Number(m[3]) * 255];
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
function luminance([r, g, b]) {
|
|
43
|
+
const lin = (c) => {
|
|
44
|
+
const s = c / 255;
|
|
45
|
+
return s <= 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
|
|
46
|
+
};
|
|
47
|
+
return 0.2126 * lin(r) + 0.7152 * lin(g) + 0.0722 * lin(b);
|
|
48
|
+
}
|
|
49
|
+
/** WCAG contrast ratio between two colours. */
|
|
50
|
+
export function contrastRatio(a, b) {
|
|
51
|
+
const [hi, lo] = [luminance(a), luminance(b)].sort((x, y) => y - x);
|
|
52
|
+
return (hi + 0.05) / (lo + 0.05);
|
|
53
|
+
}
|
|
54
|
+
const mix = (a, b, t) => [0, 1, 2].map((i) => a[i] + (b[i] - a[i]) * t);
|
|
55
|
+
/** Black or white, whichever contrasts more with `bg` (switch point ≈ luminance 0.179). */
|
|
56
|
+
export function readableTextOn(bg) {
|
|
57
|
+
return luminance(bg) < 0.179 ? '#ffffff' : '#000000';
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Label colour for a cell at position `t` (0 = min colour, 1 = max colour) on the scale:
|
|
61
|
+
* a single colour when both schemes agree, otherwise `light-dark(light, dark)`.
|
|
62
|
+
*/
|
|
63
|
+
export function heatmapLabelColor(t, stops) {
|
|
64
|
+
const pos = Math.min(1, Math.max(0, Number.isFinite(t) ? t : 0));
|
|
65
|
+
const light = readableTextOn(mix(stops.light.min, stops.light.max, pos));
|
|
66
|
+
const dark = readableTextOn(mix(stops.dark.min, stops.dark.max, pos));
|
|
67
|
+
if (light === dark || !supportsLightDark())
|
|
68
|
+
return light;
|
|
69
|
+
return `light-dark(${light}, ${dark})`;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Resolves `min`/`max` (any CSS colour, including `var()` and `light-dark()`) to sRGB in
|
|
73
|
+
* both colour schemes, using a probe element inside `root` so the component's CSS
|
|
74
|
+
* custom properties apply. Returns null if a colour can't be resolved to sRGB.
|
|
75
|
+
*/
|
|
76
|
+
export function resolveStops(root, min, max) {
|
|
77
|
+
if (typeof document === 'undefined')
|
|
78
|
+
return null;
|
|
79
|
+
const probe = document.createElement('span');
|
|
80
|
+
probe.style.cssText =
|
|
81
|
+
'position:absolute;width:0;height:0;overflow:hidden;visibility:hidden;pointer-events:none';
|
|
82
|
+
root.appendChild(probe);
|
|
83
|
+
try {
|
|
84
|
+
const read = (color, scheme) => {
|
|
85
|
+
probe.style.colorScheme = scheme;
|
|
86
|
+
probe.style.color = '';
|
|
87
|
+
probe.style.color = color;
|
|
88
|
+
if (!probe.style.color)
|
|
89
|
+
return null; // the browser rejected the colour
|
|
90
|
+
return parseComputedColor(getComputedStyle(probe).color);
|
|
91
|
+
};
|
|
92
|
+
const lMin = read(min, 'light');
|
|
93
|
+
const lMax = read(max, 'light');
|
|
94
|
+
const dMin = read(min, 'dark');
|
|
95
|
+
const dMax = read(max, 'dark');
|
|
96
|
+
if (!lMin || !lMax || !dMin || !dMax)
|
|
97
|
+
return null;
|
|
98
|
+
return { light: { min: lMin, max: lMax }, dark: { min: dMin, max: dMax } };
|
|
99
|
+
}
|
|
100
|
+
finally {
|
|
101
|
+
probe.remove();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=heatmap-colors.js.map
|
|
@@ -9,11 +9,19 @@ export interface HeatmapCell {
|
|
|
9
9
|
y: number;
|
|
10
10
|
value: number;
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Heatmap chart. Colours follow the page's light/dark colour scheme by default.
|
|
14
|
+
*
|
|
15
|
+
* @cssproperty --nile-heatmap-min-color - Colour of the lowest value. Default: #ffffff (light) / #1a2440 (dark).
|
|
16
|
+
* @cssproperty --nile-heatmap-max-color - Colour of the highest value. Default: #1e40af (light) / #60a5fa (dark).
|
|
17
|
+
* @cssproperty --nile-heatmap-border-color - Gaps between cells. Default: #e2e8f0 (light) / #22262f (dark).
|
|
18
|
+
*/
|
|
12
19
|
export declare class NileHeatmapChart extends NileElement {
|
|
13
20
|
static styles: CSSResultGroup;
|
|
14
21
|
private _hc;
|
|
15
22
|
private chart;
|
|
16
23
|
private resizeObserver;
|
|
24
|
+
private _initPending;
|
|
17
25
|
private chartContainer;
|
|
18
26
|
config: SeparatedChartConfigInputType | null;
|
|
19
27
|
chartTitle: string;
|
|
@@ -24,7 +32,15 @@ export declare class NileHeatmapChart extends NileElement {
|
|
|
24
32
|
seriesName: string;
|
|
25
33
|
colorMin: number | null;
|
|
26
34
|
colorMax: number | null;
|
|
35
|
+
/**
|
|
36
|
+
* Colour of the lowest value. Empty (default) = theme-aware: `--nile-heatmap-min-color`,
|
|
37
|
+
* else #ffffff in light mode and #1a2440 in dark mode.
|
|
38
|
+
*/
|
|
27
39
|
minColor: string;
|
|
40
|
+
/**
|
|
41
|
+
* Colour of the highest value. Empty (default) = theme-aware: `--nile-heatmap-max-color`,
|
|
42
|
+
* else #1e40af in light mode and #60a5fa in dark mode.
|
|
43
|
+
*/
|
|
28
44
|
maxColor: string;
|
|
29
45
|
colorAxisTitle: string;
|
|
30
46
|
options: Highcharts.Options;
|
|
@@ -55,6 +71,13 @@ export declare class NileHeatmapChart extends NileElement {
|
|
|
55
71
|
private setupResizeObserver;
|
|
56
72
|
private valueExtent;
|
|
57
73
|
private buildOptions;
|
|
74
|
+
/**
|
|
75
|
+
* Per-cell black/white data-label colour that stays readable in light and dark mode
|
|
76
|
+
* (Highcharts' automatic "contrast" colour can't read the color-mix() cell fills).
|
|
77
|
+
* Skipped when the app sets its own label colour, format or formatter, or when a colour
|
|
78
|
+
* stop can't be resolved — Highcharts' default labels apply then.
|
|
79
|
+
*/
|
|
80
|
+
private readableDataLabels;
|
|
58
81
|
private initChart;
|
|
59
82
|
private destroyChart;
|
|
60
83
|
render(): TemplateResult;
|
|
@@ -7,12 +7,21 @@ 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-heatmap-chart.css.js';
|
|
10
|
+
import { heatmapDefaultBorderColor, heatmapDefaultMaxColor, heatmapDefaultMinColor, heatmapLabelColor, resolveStops, } from './heatmap-colors.js';
|
|
11
|
+
/**
|
|
12
|
+
* Heatmap chart. Colours follow the page's light/dark colour scheme by default.
|
|
13
|
+
*
|
|
14
|
+
* @cssproperty --nile-heatmap-min-color - Colour of the lowest value. Default: #ffffff (light) / #1a2440 (dark).
|
|
15
|
+
* @cssproperty --nile-heatmap-max-color - Colour of the highest value. Default: #1e40af (light) / #60a5fa (dark).
|
|
16
|
+
* @cssproperty --nile-heatmap-border-color - Gaps between cells. Default: #e2e8f0 (light) / #22262f (dark).
|
|
17
|
+
*/
|
|
10
18
|
let NileHeatmapChart = class NileHeatmapChart extends NileElement {
|
|
11
19
|
constructor() {
|
|
12
20
|
super(...arguments);
|
|
13
21
|
this._hc = null;
|
|
14
22
|
this.chart = null;
|
|
15
23
|
this.resizeObserver = null;
|
|
24
|
+
this._initPending = false;
|
|
16
25
|
this.config = null;
|
|
17
26
|
this.chartTitle = '';
|
|
18
27
|
this.chartSubtitle = '';
|
|
@@ -22,8 +31,16 @@ let NileHeatmapChart = class NileHeatmapChart extends NileElement {
|
|
|
22
31
|
this.seriesName = '';
|
|
23
32
|
this.colorMin = null;
|
|
24
33
|
this.colorMax = null;
|
|
25
|
-
|
|
26
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Colour of the lowest value. Empty (default) = theme-aware: `--nile-heatmap-min-color`,
|
|
36
|
+
* else #ffffff in light mode and #1a2440 in dark mode.
|
|
37
|
+
*/
|
|
38
|
+
this.minColor = '';
|
|
39
|
+
/**
|
|
40
|
+
* Colour of the highest value. Empty (default) = theme-aware: `--nile-heatmap-max-color`,
|
|
41
|
+
* else #1e40af in light mode and #60a5fa in dark mode.
|
|
42
|
+
*/
|
|
43
|
+
this.maxColor = '';
|
|
27
44
|
this.colorAxisTitle = '';
|
|
28
45
|
this.options = {};
|
|
29
46
|
this.noResponsive = false;
|
|
@@ -156,6 +173,8 @@ let NileHeatmapChart = class NileHeatmapChart extends NileElement {
|
|
|
156
173
|
const cMin = this.colorMin ?? ext.min;
|
|
157
174
|
const cMax = this.colorMax ?? ext.max;
|
|
158
175
|
const seriesData = this.data.map(c => [c.x, c.y, c.value]);
|
|
176
|
+
const minColor = this.minColor || heatmapDefaultMinColor();
|
|
177
|
+
const maxColor = this.maxColor || heatmapDefaultMaxColor();
|
|
159
178
|
const merged = deepMerge({
|
|
160
179
|
chart: { type: 'heatmap', ...(this.height ? { height: this.height } : {}) },
|
|
161
180
|
title: { text: this.chartTitle || undefined },
|
|
@@ -169,8 +188,8 @@ let NileHeatmapChart = class NileHeatmapChart extends NileElement {
|
|
|
169
188
|
colorAxis: {
|
|
170
189
|
min: cMin,
|
|
171
190
|
max: cMax,
|
|
172
|
-
minColor
|
|
173
|
-
maxColor
|
|
191
|
+
minColor,
|
|
192
|
+
maxColor,
|
|
174
193
|
title: { text: this.colorAxisTitle || undefined },
|
|
175
194
|
},
|
|
176
195
|
legend: (() => { const { show, ...rest } = this.legend ?? {}; return { enabled: show ?? this.showLegend, align: 'right', layout: 'vertical', verticalAlign: 'top', ...rest }; })(),
|
|
@@ -189,9 +208,9 @@ let NileHeatmapChart = class NileHeatmapChart extends NileElement {
|
|
|
189
208
|
},
|
|
190
209
|
plotOptions: {
|
|
191
210
|
heatmap: {
|
|
192
|
-
dataLabels: { enabled: this.showDataLabels },
|
|
211
|
+
dataLabels: { enabled: this.showDataLabels, ...this.readableDataLabels(minColor, maxColor, cMin, cMax) },
|
|
193
212
|
borderWidth: 1,
|
|
194
|
-
borderColor:
|
|
213
|
+
borderColor: heatmapDefaultBorderColor(),
|
|
195
214
|
},
|
|
196
215
|
series: {
|
|
197
216
|
cursor: 'pointer',
|
|
@@ -225,13 +244,57 @@ let NileHeatmapChart = class NileHeatmapChart extends NileElement {
|
|
|
225
244
|
}, this.options);
|
|
226
245
|
return withResponsiveDefaults(merged, 'heatmap', this.noResponsive);
|
|
227
246
|
}
|
|
247
|
+
/**
|
|
248
|
+
* Per-cell black/white data-label colour that stays readable in light and dark mode
|
|
249
|
+
* (Highcharts' automatic "contrast" colour can't read the color-mix() cell fills).
|
|
250
|
+
* Skipped when the app sets its own label colour, format or formatter, or when a colour
|
|
251
|
+
* stop can't be resolved — Highcharts' default labels apply then.
|
|
252
|
+
*/
|
|
253
|
+
readableDataLabels(minColor, maxColor, cMin, cMax) {
|
|
254
|
+
const own = [
|
|
255
|
+
this.options?.plotOptions?.heatmap?.dataLabels,
|
|
256
|
+
this.options?.plotOptions?.series?.dataLabels,
|
|
257
|
+
...(this.options?.series ?? []).map(s => s?.dataLabels),
|
|
258
|
+
].flatMap(d => (Array.isArray(d) ? d : [d]));
|
|
259
|
+
if (own.some(d => d && (d.formatter || d.format || d.color || d.style?.color)))
|
|
260
|
+
return {};
|
|
261
|
+
const stops = resolveStops(this.renderRoot, minColor, maxColor);
|
|
262
|
+
if (!stops)
|
|
263
|
+
return {};
|
|
264
|
+
const hc = () => this._hc;
|
|
265
|
+
return {
|
|
266
|
+
style: { textOutline: 'none' },
|
|
267
|
+
formatter() {
|
|
268
|
+
const point = this.point ?? this;
|
|
269
|
+
const value = point?.value;
|
|
270
|
+
if (value === null || value === undefined)
|
|
271
|
+
return '';
|
|
272
|
+
const axis = point.series?.chart?.colorAxis?.[0];
|
|
273
|
+
const lo = axis?.min ?? cMin;
|
|
274
|
+
const span = (axis?.max ?? cMax) - lo || 1;
|
|
275
|
+
const text = hc()?.format?.('{point.value}', { point }, point.series?.chart) ?? String(value);
|
|
276
|
+
return `<span style="color:${heatmapLabelColor((value - lo) / span, stops)}">${text}</span>`;
|
|
277
|
+
},
|
|
278
|
+
};
|
|
279
|
+
}
|
|
228
280
|
async initChart() {
|
|
229
|
-
|
|
281
|
+
// firstUpdated() and the first updated() both call this while Highcharts is still
|
|
282
|
+
// loading; without the guard two charts were created in the same container (the
|
|
283
|
+
// first destroyed by the second) and nile-chart-ready fired twice.
|
|
284
|
+
if (this.loading || !this.chartContainer || this._initPending)
|
|
230
285
|
return;
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
286
|
+
this._initPending = true;
|
|
287
|
+
try {
|
|
288
|
+
if (!this._hc)
|
|
289
|
+
this._hc = await getHighcharts();
|
|
290
|
+
if (this.chart || this.loading || !this.isConnected || !this.chartContainer)
|
|
291
|
+
return;
|
|
292
|
+
this.chart = this._hc.chart(this.chartContainer, this.buildOptions());
|
|
293
|
+
this.emit('nile-chart-ready', { chart: this.chart });
|
|
294
|
+
}
|
|
295
|
+
finally {
|
|
296
|
+
this._initPending = false;
|
|
297
|
+
}
|
|
235
298
|
}
|
|
236
299
|
destroyChart() {
|
|
237
300
|
if (this.chart) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './nile-heatmap-chart';
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { expect, fixture, html } from '@open-wc/testing';
|
|
2
|
+
import './nile-heatmap-chart';
|
|
3
|
+
import { contrastRatio, heatmapDefaultBorderColor, heatmapDefaultMaxColor, heatmapDefaultMinColor, heatmapLabelColor, parseComputedColor, readableTextOn, } from './heatmap-colors';
|
|
4
|
+
const X = ['Mon', 'Tue', 'Wed'];
|
|
5
|
+
const Y = ['AM', 'PM'];
|
|
6
|
+
const DATA = [
|
|
7
|
+
{ x: 0, y: 0, value: 0 },
|
|
8
|
+
{ x: 1, y: 0, value: 5 },
|
|
9
|
+
{ x: 2, y: 0, value: 10 },
|
|
10
|
+
{ x: 0, y: 1, value: 3 },
|
|
11
|
+
{ x: 1, y: 1, value: 7 },
|
|
12
|
+
{ x: 2, y: 1, value: 9 },
|
|
13
|
+
];
|
|
14
|
+
const hex = (h) => [1, 3, 5].map((i) => parseInt(h.slice(i, i + 2), 16));
|
|
15
|
+
const DEFAULT_STOPS = {
|
|
16
|
+
light: { min: hex('#ffffff'), max: hex('#1e40af') },
|
|
17
|
+
dark: { min: hex('#1a2440'), max: hex('#60a5fa') },
|
|
18
|
+
};
|
|
19
|
+
async function render(props = {}, style = '') {
|
|
20
|
+
let resolveChart;
|
|
21
|
+
const ready = new Promise((r) => (resolveChart = r));
|
|
22
|
+
// Listen in the template so the event can't fire before the test is listening.
|
|
23
|
+
const el = await fixture(html `<nile-heatmap-chart
|
|
24
|
+
style=${style}
|
|
25
|
+
.xCategories=${X}
|
|
26
|
+
.yCategories=${Y}
|
|
27
|
+
.data=${DATA}
|
|
28
|
+
.minColor=${props.minColor ?? ''}
|
|
29
|
+
.maxColor=${props.maxColor ?? ''}
|
|
30
|
+
.options=${props.options ?? {}}
|
|
31
|
+
@nile-chart-ready=${(e) => resolveChart(e.detail.chart)}
|
|
32
|
+
></nile-heatmap-chart>`);
|
|
33
|
+
const chart = await Promise.race([
|
|
34
|
+
ready,
|
|
35
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error('nile-chart-ready never fired')), 10000)),
|
|
36
|
+
]);
|
|
37
|
+
await new Promise(requestAnimationFrame);
|
|
38
|
+
return { el, chart };
|
|
39
|
+
}
|
|
40
|
+
const cells = (el) => [
|
|
41
|
+
...el.shadowRoot.querySelectorAll('.highcharts-heatmap-series .highcharts-point'),
|
|
42
|
+
].filter((c) => getComputedStyle(c).opacity !== '0');
|
|
43
|
+
const fillOf = (c) => parseComputedColor(getComputedStyle(c).fill);
|
|
44
|
+
// Highcharts draws an outlined label twice (outline copy first); read the visible one.
|
|
45
|
+
const visibleText = (t) => t.querySelector(':scope > tspan:not(.highcharts-text-outline)') ?? t;
|
|
46
|
+
const labelColorOf = (t) => parseComputedColor(getComputedStyle(visibleText(t)).fill);
|
|
47
|
+
describe('heatmap-colors', () => {
|
|
48
|
+
it('parses rgb() and color(srgb) computed values', () => {
|
|
49
|
+
expect(parseComputedColor('rgb(1, 2, 3)')).to.deep.equal([1, 2, 3]);
|
|
50
|
+
expect(parseComputedColor('rgba(10, 20, 30, 0.5)')).to.deep.equal([10, 20, 30]);
|
|
51
|
+
const c = parseComputedColor('color(srgb 1 0.5 0)');
|
|
52
|
+
expect(c[0]).to.equal(255);
|
|
53
|
+
expect(c[1]).to.be.closeTo(127.5, 0.01);
|
|
54
|
+
expect(parseComputedColor('oklch(0.5 0.1 200)')).to.equal(null);
|
|
55
|
+
});
|
|
56
|
+
it('defaults are CSS-variable hooks with light/dark fallbacks', () => {
|
|
57
|
+
expect(heatmapDefaultMinColor()).to.match(/^var\(--nile-heatmap-min-color, light-dark\(#ffffff, #1a2440\)\)$/);
|
|
58
|
+
expect(heatmapDefaultMaxColor()).to.match(/^var\(--nile-heatmap-max-color, light-dark\(#1e40af, #60a5fa\)\)$/);
|
|
59
|
+
expect(heatmapDefaultBorderColor()).to.match(/^var\(--nile-heatmap-border-color, light-dark\(#e2e8f0, #22262f\)\)$/);
|
|
60
|
+
});
|
|
61
|
+
it('picks black or white with at least 4.5:1 contrast anywhere on the default scale, in both schemes', () => {
|
|
62
|
+
for (let i = 0; i <= 100; i++) {
|
|
63
|
+
const t = i / 100;
|
|
64
|
+
for (const scheme of ['light', 'dark']) {
|
|
65
|
+
const { min, max } = DEFAULT_STOPS[scheme];
|
|
66
|
+
const cell = [0, 1, 2].map((k) => min[k] + (max[k] - min[k]) * t);
|
|
67
|
+
const text = hex(readableTextOn(cell));
|
|
68
|
+
expect(contrastRatio(text, cell), `${scheme} t=${t}`).to.be.at.least(4.5);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
it('returns one colour when both schemes agree and light-dark() when they differ', () => {
|
|
73
|
+
expect(heatmapLabelColor(0, DEFAULT_STOPS)).to.equal('light-dark(#000000, #ffffff)');
|
|
74
|
+
const same = { light: DEFAULT_STOPS.light, dark: DEFAULT_STOPS.light };
|
|
75
|
+
expect(heatmapLabelColor(1, same)).to.equal('#ffffff');
|
|
76
|
+
expect(heatmapLabelColor(Number.NaN, same)).to.equal('#000000');
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
describe('<nile-heatmap-chart> colours', () => {
|
|
80
|
+
afterEach(() => {
|
|
81
|
+
document.documentElement.style.colorScheme = '';
|
|
82
|
+
});
|
|
83
|
+
it('uses theme-aware colour stops and border by default', async () => {
|
|
84
|
+
const { chart } = await render();
|
|
85
|
+
const axis = chart.colorAxis[0].options;
|
|
86
|
+
expect(axis.minColor).to.equal(heatmapDefaultMinColor());
|
|
87
|
+
expect(axis.maxColor).to.equal(heatmapDefaultMaxColor());
|
|
88
|
+
expect(chart.options.plotOptions.heatmap.borderColor).to.equal(heatmapDefaultBorderColor());
|
|
89
|
+
});
|
|
90
|
+
it('keeps the previous look on a light page: white to #1e40af', async () => {
|
|
91
|
+
const { el } = await render();
|
|
92
|
+
const fills = cells(el).map(fillOf);
|
|
93
|
+
const near = (a, b) => a.every((v, i) => Math.abs(v - b[i]) < 2);
|
|
94
|
+
expect(fills.some((f) => near(f, hex('#ffffff')))).to.equal(true);
|
|
95
|
+
expect(fills.some((f) => near(f, hex('#1e40af')))).to.equal(true);
|
|
96
|
+
});
|
|
97
|
+
it('passes explicit minColor / maxColor through unchanged', async () => {
|
|
98
|
+
const { chart } = await render({ minColor: '#ff0000', maxColor: '#00ff00' });
|
|
99
|
+
expect(chart.colorAxis[0].options.minColor).to.equal('#ff0000');
|
|
100
|
+
expect(chart.colorAxis[0].options.maxColor).to.equal('#00ff00');
|
|
101
|
+
});
|
|
102
|
+
it('can be re-themed from CSS custom properties', async () => {
|
|
103
|
+
const { el } = await render({}, '--nile-heatmap-min-color: rgb(255, 0, 0)');
|
|
104
|
+
const fills = cells(el).map(fillOf);
|
|
105
|
+
expect(fills.some(([r, g, b]) => r > 250 && g < 5 && b < 5)).to.equal(true);
|
|
106
|
+
});
|
|
107
|
+
it('follows a dark page: dark cells and light axis text', async () => {
|
|
108
|
+
document.documentElement.style.colorScheme = 'dark';
|
|
109
|
+
const { el } = await render();
|
|
110
|
+
const container = el.shadowRoot.querySelector('.highcharts-container');
|
|
111
|
+
expect(container.style.colorScheme).to.equal('inherit');
|
|
112
|
+
expect(getComputedStyle(container).colorScheme).to.equal('dark');
|
|
113
|
+
const fills = cells(el).map(fillOf);
|
|
114
|
+
const near = (a, b) => a.every((v, i) => Math.abs(v - b[i]) < 2);
|
|
115
|
+
expect(fills.some((f) => near(f, hex('#1a2440')))).to.equal(true);
|
|
116
|
+
const axisLabel = el.shadowRoot.querySelector('.highcharts-xaxis-labels text, .nile-axis-label');
|
|
117
|
+
const axisColor = parseComputedColor(getComputedStyle(axisLabel).color || getComputedStyle(axisLabel).fill);
|
|
118
|
+
expect(axisColor[0]).to.be.greaterThan(150);
|
|
119
|
+
});
|
|
120
|
+
it('gives every data label at least 4.5:1 contrast with its cell, light and dark, with no outline', async () => {
|
|
121
|
+
for (const scheme of ['light', 'dark']) {
|
|
122
|
+
document.documentElement.style.colorScheme = scheme;
|
|
123
|
+
const { el } = await render();
|
|
124
|
+
const boxes = cells(el).map((c) => ({ r: c.getBoundingClientRect(), fill: fillOf(c) }));
|
|
125
|
+
const labels = [...el.shadowRoot.querySelectorAll('.highcharts-data-label text')];
|
|
126
|
+
expect(labels.length, scheme).to.equal(DATA.length);
|
|
127
|
+
for (const label of labels) {
|
|
128
|
+
expect(label.querySelector('.highcharts-text-outline'), `${scheme} outline`).to.equal(null);
|
|
129
|
+
const b = label.getBoundingClientRect();
|
|
130
|
+
const cell = boxes.find(({ r }) => b.x + b.width / 2 >= r.left &&
|
|
131
|
+
b.x + b.width / 2 <= r.right &&
|
|
132
|
+
b.y + b.height / 2 >= r.top &&
|
|
133
|
+
b.y + b.height / 2 <= r.bottom);
|
|
134
|
+
expect(contrastRatio(labelColorOf(label), cell.fill), `${scheme} "${label.textContent}"`).to.be.at.least(4.5);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
it('leaves data labels to the app when it sets its own format or colour', async () => {
|
|
139
|
+
const { el } = await render({
|
|
140
|
+
options: {
|
|
141
|
+
plotOptions: { heatmap: { dataLabels: { format: '{point.value}%', color: '#ff0000' } } },
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
const labels = [...el.shadowRoot.querySelectorAll('.highcharts-data-label text')];
|
|
145
|
+
const shown = (l) => {
|
|
146
|
+
const outline = l.querySelector('.highcharts-text-outline')?.textContent ?? '';
|
|
147
|
+
return (l.textContent ?? '').replace(outline, '').replace(/\u200b/g, '');
|
|
148
|
+
};
|
|
149
|
+
expect(labels.map(shown)).to.include('5%');
|
|
150
|
+
for (const l of labels)
|
|
151
|
+
expect(labelColorOf(l)).to.deep.equal([255, 0, 0]);
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
//# sourceMappingURL=nile-heatmap-chart.test.js.map
|