@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
|
@@ -80,17 +80,77 @@ const MENU_OVERRIDE_CSS = `
|
|
|
80
80
|
user-select: none;
|
|
81
81
|
}
|
|
82
82
|
`;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
83
|
+
const COLUMN_CHOOSER_CSS = `
|
|
84
|
+
.nile-chart-column-chooser .nile-chart-column-chooser-title {
|
|
85
|
+
display: inline-flex;
|
|
86
|
+
align-items: baseline;
|
|
87
|
+
gap: var(--nile-spacing-xs, var(--ng-spacing-xs, 4px));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.nile-chart-column-chooser .nile-chart-column-chooser-count {
|
|
91
|
+
font-weight: var(--nile-font-weight-regular, var(--ng-font-weight-regular));
|
|
92
|
+
color: var(--nile-colors-neutral-500, var(--ng-colors-text-quaternary-500));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.nile-chart-column-chooser .nile-chart-column-chooser-list {
|
|
96
|
+
display: flex;
|
|
97
|
+
flex-direction: column;
|
|
98
|
+
gap: var(--nile-spacing-10px, var(--ng-spacing-2-5, 10px));
|
|
99
|
+
width: var(--nile-width-200px, var(--ng-height-200px));
|
|
100
|
+
max-height: 60vh;
|
|
101
|
+
overflow-y: auto;
|
|
102
|
+
/* inset so the checkbox focus ring isn't clipped by the scroll container */
|
|
103
|
+
padding: var(--nile-spacing-xs, var(--ng-spacing-xs, 4px));
|
|
104
|
+
margin: 0 calc(-1 * var(--nile-spacing-xs, var(--ng-spacing-xs, 4px)));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.nile-chart-column-chooser .nile-chart-column-chooser-option {
|
|
108
|
+
align-self: flex-start;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.nile-chart-column-chooser .nile-chart-column-chooser-group {
|
|
112
|
+
font-family: var(--nile-font-family-serif, var(--ng-font-family-body));
|
|
113
|
+
font-size: var(--nile-type-scale-2, var(--ng-font-size-text-xs));
|
|
114
|
+
font-weight: var(--nile-font-weight-medium, var(--ng-font-weight-medium));
|
|
115
|
+
color: var(--nile-colors-neutral-500, var(--ng-colors-text-tertiary-600));
|
|
116
|
+
padding-top: var(--nile-spacing-xs, var(--ng-spacing-xs, 4px));
|
|
117
|
+
user-select: none;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.nile-chart-column-chooser .nile-chart-column-chooser-reset {
|
|
121
|
+
padding: 0;
|
|
122
|
+
border: none;
|
|
123
|
+
background: none;
|
|
124
|
+
cursor: pointer;
|
|
125
|
+
font-family: var(--nile-font-family-serif, var(--ng-font-family-body));
|
|
126
|
+
font-size: var(--nile-type-scale-3, var(--ng-font-size-text-sm));
|
|
127
|
+
font-weight: var(--nile-font-weight-medium, var(--ng-font-weight-semibold));
|
|
128
|
+
color: var(--nile-colors-primary-600, var(--ng-colors-text-brand-tertiary-600));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.nile-chart-column-chooser .nile-chart-column-chooser-reset:focus-visible {
|
|
132
|
+
outline: var(--nile-border-width-2, var(--ng-stroke-width-2)) solid var(--nile-colors-primary-600, var(--ng-colors-fg-brand-primary-600));
|
|
133
|
+
outline-offset: var(--nile-spacing-1px, var(--ng-outline-offset-1));
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
.nile-chart-column-chooser .nile-chart-column-chooser-reset[hidden] {
|
|
137
|
+
display: none;
|
|
138
|
+
}
|
|
139
|
+
`;
|
|
140
|
+
function injectGlobalStyle(id, cssText) {
|
|
141
|
+
if (document.getElementById(id))
|
|
88
142
|
return;
|
|
89
143
|
const style = document.createElement('style');
|
|
90
|
-
style.id =
|
|
91
|
-
style.textContent =
|
|
144
|
+
style.id = id;
|
|
145
|
+
style.textContent = cssText;
|
|
92
146
|
document.head?.appendChild(style);
|
|
93
147
|
}
|
|
148
|
+
export function injectGlobalChartMenuOverrides() {
|
|
149
|
+
if (typeof document === 'undefined')
|
|
150
|
+
return;
|
|
151
|
+
injectGlobalStyle('nile-chart-actions-menu-overrides', MENU_OVERRIDE_CSS);
|
|
152
|
+
injectGlobalStyle('nile-chart-column-chooser-styles', COLUMN_CHOOSER_CSS);
|
|
153
|
+
}
|
|
94
154
|
injectGlobalChartMenuOverrides();
|
|
95
155
|
export const styles = css `
|
|
96
156
|
:host {
|
|
@@ -495,6 +555,24 @@ export const styles = css `
|
|
|
495
555
|
transition: background var(--nile-transition-duration-short, var(--ng-transition-duration-fast)) ease, color var(--nile-transition-duration-short, var(--ng-transition-duration-fast)) ease;
|
|
496
556
|
}
|
|
497
557
|
|
|
558
|
+
.nile-chart-column-chooser-anchor {
|
|
559
|
+
display: inline-flex;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
.nile-chart-column-chooser-trigger {
|
|
563
|
+
position: relative;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
.nile-chart-column-chooser-indicator {
|
|
567
|
+
position: absolute;
|
|
568
|
+
top: var(--nile-spacing-2px, var(--ng-spacing-xxs, 2px));
|
|
569
|
+
right: var(--nile-spacing-2px, var(--ng-spacing-xxs, 2px));
|
|
570
|
+
width: var(--nile-width-6px, var(--ng-height-6px));
|
|
571
|
+
height: var(--nile-height-6px, var(--ng-height-6px));
|
|
572
|
+
border-radius: var(--nile-radius-full, var(--ng-radius-full));
|
|
573
|
+
background: var(--nile-colors-primary-600, var(--ng-colors-fg-brand-primary-600));
|
|
574
|
+
}
|
|
575
|
+
|
|
498
576
|
.nile-chart-menu-trigger:hover {
|
|
499
577
|
background: transparent;
|
|
500
578
|
color: var(--nile-colors-dark-900, var(--ng-colors-text-primary-900));
|
|
@@ -73,6 +73,9 @@ import '../nile-ai-panel/index.js';
|
|
|
73
73
|
* @csspart ai-trigger-glyph - Glyph inside the "Ask AI" button.
|
|
74
74
|
* @csspart ai-panel - The AI chat panel overlay.
|
|
75
75
|
* @csspart ai-panel-content - The nile-ai-panel element inside the overlay.
|
|
76
|
+
* @csspart column-chooser-trigger - The column-chooser button (grid charts with `columnChooser`).
|
|
77
|
+
* @csspart column-chooser-glyph - Glyph inside the column-chooser button.
|
|
78
|
+
* @csspart column-chooser-indicator - Dot on the column-chooser button while any column is hidden.
|
|
76
79
|
* @csspart menu-anchor - The actions-menu dropdown anchor.
|
|
77
80
|
* @csspart menu-trigger - The actions-menu trigger button.
|
|
78
81
|
* @csspart menu-trigger-glyph - Glyph inside the actions-menu trigger.
|
|
@@ -157,6 +160,8 @@ export declare class NileChart extends NileElement {
|
|
|
157
160
|
private hasHeaderSlotContent;
|
|
158
161
|
/** True when elements are projected into `header-actions` (used to show the header row). */
|
|
159
162
|
private hasHeaderActionsSlot;
|
|
163
|
+
private gridColumnVisibility;
|
|
164
|
+
private gridColumnVisibilitySeed;
|
|
160
165
|
private aiPanel;
|
|
161
166
|
private masterDetailChart;
|
|
162
167
|
/** True while the inner master-detail chart is zoomed — drives the header
|
|
@@ -250,6 +255,14 @@ export declare class NileChart extends NileElement {
|
|
|
250
255
|
/** Direct children with `slot=` — header row renders on first paint before slot assignment runs. */
|
|
251
256
|
private lightDomHasSlot;
|
|
252
257
|
private shouldShowHeader;
|
|
258
|
+
private get gridConfig();
|
|
259
|
+
private get columnChooser();
|
|
260
|
+
private get gridElement();
|
|
261
|
+
/** Seeds from `config.columnVisibility` whenever the app passes a new object; user toggles live here in between. */
|
|
262
|
+
private resolveGridColumnVisibility;
|
|
263
|
+
private onGridColumnVisibilityChange;
|
|
264
|
+
private onGridColumnOrderChange;
|
|
265
|
+
private renderColumnChooserTrigger;
|
|
253
266
|
private buildExportingOptions;
|
|
254
267
|
/** Ensures exporting modules are loaded and the chart's exporting/fullscreen instances exist. */
|
|
255
268
|
private ensureExporting;
|
|
@@ -8,6 +8,7 @@ import { styles, injectGlobalChartMenuOverrides } from './nile-chart.css.js';
|
|
|
8
8
|
import { HIGHCHARTS_PASSTHROUGH_KEYS } from '../internal/types/index.js';
|
|
9
9
|
import { nileChartConfig } from './nile-chart-config-builder.js';
|
|
10
10
|
import { renderChartSkeleton } from './nile-chart-skeleton.js';
|
|
11
|
+
import { COLUMN_CHOOSER_PANEL_CLASS, chooserEntries, renderColumnChooser, resolveColumnChooser, } from './nile-chart-column-chooser.js';
|
|
11
12
|
import { isChartEmpty, renderChartEmptyState, syncChartEmptyTruncation } from './nile-chart-empty.js';
|
|
12
13
|
import { convertConfig } from '../internal/utils/chart-adapters.js';
|
|
13
14
|
import { deepMerge } from '../internal/utils/deep-merge.js';
|
|
@@ -144,6 +145,9 @@ function chartTypeLabel(type) {
|
|
|
144
145
|
* @csspart ai-trigger-glyph - Glyph inside the "Ask AI" button.
|
|
145
146
|
* @csspart ai-panel - The AI chat panel overlay.
|
|
146
147
|
* @csspart ai-panel-content - The nile-ai-panel element inside the overlay.
|
|
148
|
+
* @csspart column-chooser-trigger - The column-chooser button (grid charts with `columnChooser`).
|
|
149
|
+
* @csspart column-chooser-glyph - Glyph inside the column-chooser button.
|
|
150
|
+
* @csspart column-chooser-indicator - Dot on the column-chooser button while any column is hidden.
|
|
147
151
|
* @csspart menu-anchor - The actions-menu dropdown anchor.
|
|
148
152
|
* @csspart menu-trigger - The actions-menu trigger button.
|
|
149
153
|
* @csspart menu-trigger-glyph - Glyph inside the actions-menu trigger.
|
|
@@ -229,6 +233,8 @@ let NileChart = NileChart_1 = class NileChart extends NileElement {
|
|
|
229
233
|
this.hasHeaderSlotContent = false;
|
|
230
234
|
/** True when elements are projected into `header-actions` (used to show the header row). */
|
|
231
235
|
this.hasHeaderActionsSlot = false;
|
|
236
|
+
this.gridColumnVisibility = DEFAULT_GRID_COLUMN_VISIBILITY;
|
|
237
|
+
this.gridColumnVisibilitySeed = undefined;
|
|
232
238
|
/** True while the inner master-detail chart is zoomed — drives the header
|
|
233
239
|
* "Reset zoom" button. Reflected from the chart's `nile-master-detail-zoom`. */
|
|
234
240
|
this.masterZoomed = false;
|
|
@@ -286,6 +292,13 @@ let NileChart = NileChart_1 = class NileChart extends NileElement {
|
|
|
286
292
|
this.gridLineStrengthFromConfig = false;
|
|
287
293
|
this._emptyEl = null;
|
|
288
294
|
this._emptyObs = null;
|
|
295
|
+
this.onGridColumnVisibilityChange = (e) => {
|
|
296
|
+
this.gridColumnVisibility = e.detail.columnVisibility;
|
|
297
|
+
this.requestUpdate();
|
|
298
|
+
};
|
|
299
|
+
this.onGridColumnOrderChange = () => {
|
|
300
|
+
this.requestUpdate();
|
|
301
|
+
};
|
|
289
302
|
/** The x-axis label the tooltip belongs to. */
|
|
290
303
|
this._axisLabelActive = null;
|
|
291
304
|
/** Shows the full name for a clipped label; uses mousemove because some browsers never fire mouseover here. */
|
|
@@ -692,7 +705,57 @@ let NileChart = NileChart_1 = class NileChart extends NileElement {
|
|
|
692
705
|
this.lightDomHasSlot('header') ||
|
|
693
706
|
this.lightDomHasSlot('header-actions') ||
|
|
694
707
|
hasBuiltinActions ||
|
|
695
|
-
this.showResetZoom
|
|
708
|
+
this.showResetZoom ||
|
|
709
|
+
!!this.columnChooser);
|
|
710
|
+
}
|
|
711
|
+
get gridConfig() {
|
|
712
|
+
return this.activeConfig?.type === 'grid'
|
|
713
|
+
? this.activeConfig
|
|
714
|
+
: null;
|
|
715
|
+
}
|
|
716
|
+
get columnChooser() {
|
|
717
|
+
return resolveColumnChooser(this.gridConfig?.columnChooser);
|
|
718
|
+
}
|
|
719
|
+
get gridElement() {
|
|
720
|
+
return this.shadowRoot?.querySelector('nile-data-grid.nile-chart-grid') ?? null;
|
|
721
|
+
}
|
|
722
|
+
/** Seeds from `config.columnVisibility` whenever the app passes a new object; user toggles live here in between. */
|
|
723
|
+
resolveGridColumnVisibility(config) {
|
|
724
|
+
const source = config.columnVisibility ?? DEFAULT_GRID_COLUMN_VISIBILITY;
|
|
725
|
+
if (source !== this.gridColumnVisibilitySeed) {
|
|
726
|
+
this.gridColumnVisibilitySeed = source;
|
|
727
|
+
this.gridColumnVisibility = source;
|
|
728
|
+
}
|
|
729
|
+
return this.gridColumnVisibility;
|
|
730
|
+
}
|
|
731
|
+
renderColumnChooserTrigger() {
|
|
732
|
+
const chooser = this.columnChooser;
|
|
733
|
+
const config = this.gridConfig;
|
|
734
|
+
if (!chooser || !config)
|
|
735
|
+
return nothing;
|
|
736
|
+
if (this.loading || config.loading)
|
|
737
|
+
return nothing;
|
|
738
|
+
const grid = this.gridElement;
|
|
739
|
+
const order = grid?.columnOrder?.length ? grid.columnOrder : config.columnOrder ?? [];
|
|
740
|
+
return renderColumnChooser({
|
|
741
|
+
chooser,
|
|
742
|
+
entries: chooserEntries(config.columns, order),
|
|
743
|
+
visibility: this.resolveGridColumnVisibility(config),
|
|
744
|
+
onToggle: (id, visible) => this.gridElement?.toggleColumnVisibility(id, visible),
|
|
745
|
+
onReset: () => this.gridElement?.showAllColumns(),
|
|
746
|
+
onShow: () => {
|
|
747
|
+
const first = document.querySelector(`.${COLUMN_CHOOSER_PANEL_CLASS} nile-checkbox:not([disabled])`);
|
|
748
|
+
first?.focus();
|
|
749
|
+
},
|
|
750
|
+
onHide: () => {
|
|
751
|
+
const panel = document.querySelector(`.${COLUMN_CHOOSER_PANEL_CLASS}`);
|
|
752
|
+
if (panel && panel.contains(document.activeElement)) {
|
|
753
|
+
this.shadowRoot
|
|
754
|
+
?.querySelector('.nile-chart-column-chooser-trigger')
|
|
755
|
+
?.focus();
|
|
756
|
+
}
|
|
757
|
+
},
|
|
758
|
+
});
|
|
696
759
|
}
|
|
697
760
|
buildExportingOptions() {
|
|
698
761
|
return { exporting: { enabled: true, buttons: { contextButton: { enabled: false } } } };
|
|
@@ -991,6 +1054,7 @@ let NileChart = NileChart_1 = class NileChart extends NileElement {
|
|
|
991
1054
|
</div>
|
|
992
1055
|
<div class="nile-chart-header-actions" part="header-actions">
|
|
993
1056
|
<slot name="header-actions" @slotchange=${this.onHeaderActionsSlotChange}></slot>
|
|
1057
|
+
${this.renderColumnChooserTrigger()}
|
|
994
1058
|
${this.showResetZoom
|
|
995
1059
|
? html `<nile-tooltip content="Reset zoom" placement="top" part="reset-zoom-tooltip">
|
|
996
1060
|
<button
|
|
@@ -1899,8 +1963,8 @@ let NileChart = NileChart_1 = class NileChart extends NileElement {
|
|
|
1899
1963
|
.seriesName=${config.seriesName ?? ''}
|
|
1900
1964
|
.colorMin=${config.colorMin ?? null}
|
|
1901
1965
|
.colorMax=${config.colorMax ?? null}
|
|
1902
|
-
.minColor=${config.minColor ?? '
|
|
1903
|
-
.maxColor=${config.maxColor ?? '
|
|
1966
|
+
.minColor=${config.minColor ?? ''}
|
|
1967
|
+
.maxColor=${config.maxColor ?? ''}
|
|
1904
1968
|
.colorAxisTitle=${config.colorAxisTitle ?? ''}
|
|
1905
1969
|
.showDataLabels=${config.showDataLabels ?? true}
|
|
1906
1970
|
.showLegend=${config.legend?.show ?? true}
|
|
@@ -2416,10 +2480,12 @@ let NileChart = NileChart_1 = class NileChart extends NileElement {
|
|
|
2416
2480
|
.columnResizeDirection=${config.columnResizeDirection ?? 'ltr'}
|
|
2417
2481
|
.columnSizing=${config.columnSizing ?? DEFAULT_GRID_COLUMN_SIZING}
|
|
2418
2482
|
.columnPinning=${config.columnPinning ?? DEFAULT_GRID_COLUMN_PINNING}
|
|
2419
|
-
.columnVisibility=${config
|
|
2483
|
+
.columnVisibility=${this.resolveGridColumnVisibility(config)}
|
|
2420
2484
|
.rowSelection=${config.rowSelection ?? DEFAULT_GRID_ROW_SELECTION}
|
|
2421
2485
|
.columnOrder=${config.columnOrder ?? DEFAULT_GRID_COLUMN_ORDER}
|
|
2422
2486
|
style=${gridChrome}
|
|
2487
|
+
@nile-column-visibility-change=${this.onGridColumnVisibilityChange}
|
|
2488
|
+
@nile-column-order-change=${this.onGridColumnOrderChange}
|
|
2423
2489
|
></nile-data-grid>`;
|
|
2424
2490
|
}
|
|
2425
2491
|
case 'filter': {
|
|
@@ -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';
|