@aquera/nile-visualization 2.9.44 → 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 +10 -0
- package/dist/src/index.d.ts +1 -1
- package/dist/src/internal/types/chart-grid-config.type.d.ts +22 -0
- package/dist/src/internal/types/chart-heatmap-config.type.d.ts +2 -0
- package/dist/src/internal/types/index.d.ts +1 -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-column-chooser.d.ts +33 -0
- package/dist/src/nile-chart/nile-chart-column-chooser.js +133 -0
- package/dist/src/nile-chart/nile-chart-column-chooser.test.d.ts +2 -0
- package/dist/src/nile-chart/nile-chart-column-chooser.test.js +244 -0
- package/dist/src/nile-chart/nile-chart-config.d.ts +2 -0
- package/dist/src/nile-chart/nile-chart.css.js +85 -7
- package/dist/src/nile-chart/nile-chart.d.ts +13 -0
- package/dist/src/nile-chart/nile-chart.js +70 -4
- 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
|
@@ -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
|