@gravionlabs/helix-ui 22.5.0 → 22.6.0
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 +1 -0
- package/core.css +128 -6
- package/fesm2022/gravionlabs-helix-ui-chart.mjs +2 -25
- package/fesm2022/gravionlabs-helix-ui-chart.mjs.map +1 -1
- package/fesm2022/gravionlabs-helix-ui.mjs +353 -2109
- package/fesm2022/gravionlabs-helix-ui.mjs.map +1 -1
- package/package.json +1 -1
- package/styles.css +128 -6
- package/tokens.css +1 -0
- package/types/gravionlabs-helix-ui.d.ts +90 -1
package/README.md
CHANGED
|
@@ -46,6 +46,7 @@ import { HxChart } from '@gravionlabs/helix-ui/chart';
|
|
|
46
46
|
| `HxRadio` | `input[hx-radio]` | native radio |
|
|
47
47
|
| `HxSelect` | `hx-select` | CDK listbox in an overlay, all three forms APIs |
|
|
48
48
|
| `HxDivider` | `hx-divider` | horizontal/vertical, labelled |
|
|
49
|
+
| `HxKbd` | `hx-kbd` | key caps of a shortcut; `hxTooltipShortcut` on the tooltip |
|
|
49
50
|
| `HxTooltip` | `[hx-tooltip]` | CDK overlay, hover and focus |
|
|
50
51
|
| `HxAvatar`, `HxAvatarGroup` | `hx-avatar`, `hx-avatar-group` | picture, icon or initials; sizes, shapes; the group overlaps its avatars |
|
|
51
52
|
| `HxBadge`, `HxOverlayBadge` | `hx-badge`, `hx-overlay-badge` | count or dot marker, severities and sizes; the overlay variant sits on a corner of the wrapped element |
|
package/core.css
CHANGED
|
@@ -928,15 +928,11 @@
|
|
|
928
928
|
-webkit-mask: var(--hx-check) center/contain no-repeat;
|
|
929
929
|
transform: scale(0);
|
|
930
930
|
transition: transform var(--h-checkbox-transition-duration);
|
|
931
|
-
--hx-check: url(
|
|
932
|
-
"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 14' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m3 7.5 2.8 2.8L11 4.5'/%3E%3C/svg%3E"
|
|
933
|
-
);
|
|
931
|
+
--hx-check: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 14' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m3 7.5 2.8 2.8L11 4.5'/%3E%3C/svg%3E");
|
|
934
932
|
}
|
|
935
933
|
|
|
936
934
|
.hx-checkbox:indeterminate::before {
|
|
937
|
-
--hx-check: url(
|
|
938
|
-
"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 14' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M3 7h8'/%3E%3C/svg%3E"
|
|
939
|
-
);
|
|
935
|
+
--hx-check: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 14' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M3 7h8'/%3E%3C/svg%3E");
|
|
940
936
|
}
|
|
941
937
|
|
|
942
938
|
.hx-checkbox:checked,
|
|
@@ -2040,6 +2036,67 @@
|
|
|
2040
2036
|
resize: none;
|
|
2041
2037
|
}
|
|
2042
2038
|
|
|
2039
|
+
/* kbd */
|
|
2040
|
+
/*
|
|
2041
|
+
* Key caps: `hx-kbd` (one `.hx-kbd-key` per key), coloured by the `--h-kbd-*` tokens. Inside a tooltip bubble the
|
|
2042
|
+
* caps read the `--h-kbd-tooltip-*` tokens, because the bubble is dark in both themes.
|
|
2043
|
+
*/
|
|
2044
|
+
.hx-kbd {
|
|
2045
|
+
--hx-kbd-height: var(--h-kbd-height);
|
|
2046
|
+
--hx-kbd-min-width: var(--h-kbd-min-width);
|
|
2047
|
+
--hx-kbd-padding-x: var(--h-kbd-padding-x);
|
|
2048
|
+
--hx-kbd-font-size: var(--h-kbd-font-size);
|
|
2049
|
+
--hx-kbd-gap: var(--h-kbd-gap);
|
|
2050
|
+
--hx-kbd-background: var(--h-kbd-background);
|
|
2051
|
+
--hx-kbd-color: var(--h-kbd-color);
|
|
2052
|
+
--hx-kbd-border-color: var(--h-kbd-border-color);
|
|
2053
|
+
--hx-kbd-separator-color: var(--h-kbd-separator-color);
|
|
2054
|
+
display: inline-flex;
|
|
2055
|
+
align-items: center;
|
|
2056
|
+
gap: var(--hx-kbd-gap);
|
|
2057
|
+
vertical-align: middle;
|
|
2058
|
+
white-space: nowrap;
|
|
2059
|
+
}
|
|
2060
|
+
|
|
2061
|
+
.hx-kbd-sm {
|
|
2062
|
+
--hx-kbd-height: var(--h-kbd-sm-height);
|
|
2063
|
+
--hx-kbd-min-width: var(--h-kbd-sm-min-width);
|
|
2064
|
+
--hx-kbd-padding-x: var(--h-kbd-sm-padding-x);
|
|
2065
|
+
--hx-kbd-font-size: var(--h-kbd-sm-font-size);
|
|
2066
|
+
--hx-kbd-gap: var(--h-kbd-sm-gap);
|
|
2067
|
+
}
|
|
2068
|
+
|
|
2069
|
+
.hx-kbd-key {
|
|
2070
|
+
display: inline-flex;
|
|
2071
|
+
align-items: center;
|
|
2072
|
+
justify-content: center;
|
|
2073
|
+
box-sizing: border-box;
|
|
2074
|
+
min-width: var(--hx-kbd-min-width);
|
|
2075
|
+
height: var(--hx-kbd-height);
|
|
2076
|
+
padding: 0 var(--hx-kbd-padding-x);
|
|
2077
|
+
border: var(--h-kbd-border-width) solid var(--hx-kbd-border-color);
|
|
2078
|
+
border-radius: var(--h-kbd-border-radius);
|
|
2079
|
+
background: var(--hx-kbd-background);
|
|
2080
|
+
color: var(--hx-kbd-color);
|
|
2081
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
2082
|
+
font-size: var(--hx-kbd-font-size);
|
|
2083
|
+
line-height: 1;
|
|
2084
|
+
}
|
|
2085
|
+
|
|
2086
|
+
.hx-kbd-separator {
|
|
2087
|
+
color: var(--hx-kbd-separator-color);
|
|
2088
|
+
font-size: var(--hx-kbd-font-size);
|
|
2089
|
+
line-height: 1;
|
|
2090
|
+
}
|
|
2091
|
+
|
|
2092
|
+
.hx-tooltip .hx-kbd {
|
|
2093
|
+
--hx-kbd-background: var(--h-kbd-tooltip-background);
|
|
2094
|
+
--hx-kbd-color: var(--h-kbd-tooltip-color);
|
|
2095
|
+
--hx-kbd-border-color: var(--h-kbd-tooltip-border-color);
|
|
2096
|
+
--hx-kbd-separator-color: var(--h-kbd-tooltip-separator-color);
|
|
2097
|
+
margin-inline-start: 0.5rem;
|
|
2098
|
+
}
|
|
2099
|
+
|
|
2043
2100
|
/* listbox */
|
|
2044
2101
|
/*
|
|
2045
2102
|
* Listbox: `<hx-listbox>`. An inline list of options in a bordered box from the `--h-listbox-*` tokens, with an
|
|
@@ -3622,6 +3679,45 @@
|
|
|
3622
3679
|
background: var(--h-tabbar-unread-color);
|
|
3623
3680
|
}
|
|
3624
3681
|
|
|
3682
|
+
/* The close button and the dot of unsaved changes share one slot, so the tab keeps its width. */
|
|
3683
|
+
.hx-tab-bar-slot {
|
|
3684
|
+
display: inline-grid;
|
|
3685
|
+
flex: none;
|
|
3686
|
+
place-items: center;
|
|
3687
|
+
width: var(--h-tabbar-close-size);
|
|
3688
|
+
height: var(--h-tabbar-close-size);
|
|
3689
|
+
}
|
|
3690
|
+
|
|
3691
|
+
.hx-tab-bar-slot > * {
|
|
3692
|
+
grid-area: 1/1;
|
|
3693
|
+
}
|
|
3694
|
+
|
|
3695
|
+
.hx-tab-bar-modified {
|
|
3696
|
+
width: 0.5rem;
|
|
3697
|
+
height: 0.5rem;
|
|
3698
|
+
border-radius: 50%;
|
|
3699
|
+
background: currentcolor;
|
|
3700
|
+
}
|
|
3701
|
+
|
|
3702
|
+
.hx-tab-bar-tab-modified:hover .hx-tab-bar-modified,
|
|
3703
|
+
.hx-tab-bar-tab-modified:focus-visible .hx-tab-bar-modified {
|
|
3704
|
+
visibility: hidden;
|
|
3705
|
+
}
|
|
3706
|
+
|
|
3707
|
+
/* a tab with unsaved changes shows the close button only on hover or focus, also when active */
|
|
3708
|
+
.hx-tab-bar-tab-modified.hx-tab-bar-tab-active .hx-tab-bar-close {
|
|
3709
|
+
visibility: hidden;
|
|
3710
|
+
}
|
|
3711
|
+
|
|
3712
|
+
.hx-tab-bar-tab-modified.hx-tab-bar-tab-active:hover .hx-tab-bar-close,
|
|
3713
|
+
.hx-tab-bar-tab-modified.hx-tab-bar-tab-active:focus-visible .hx-tab-bar-close {
|
|
3714
|
+
visibility: visible;
|
|
3715
|
+
}
|
|
3716
|
+
|
|
3717
|
+
.hx-tab-bar-tab-missing .hx-tab-bar-label {
|
|
3718
|
+
text-decoration: line-through;
|
|
3719
|
+
}
|
|
3720
|
+
|
|
3625
3721
|
.hx-tab-bar-close,
|
|
3626
3722
|
.hx-tab-bar-all {
|
|
3627
3723
|
display: inline-grid;
|
|
@@ -4173,6 +4269,31 @@
|
|
|
4173
4269
|
font-weight: var(--h-toast-detail-font-weight);
|
|
4174
4270
|
}
|
|
4175
4271
|
|
|
4272
|
+
.hx-toast-action {
|
|
4273
|
+
flex: none;
|
|
4274
|
+
padding: 0.25rem 0.5rem;
|
|
4275
|
+
border: 0;
|
|
4276
|
+
border-radius: var(--h-toast-close-button-border-radius);
|
|
4277
|
+
background: transparent;
|
|
4278
|
+
color: inherit;
|
|
4279
|
+
font: inherit;
|
|
4280
|
+
font-weight: 600;
|
|
4281
|
+
text-decoration: underline;
|
|
4282
|
+
cursor: pointer;
|
|
4283
|
+
outline: 0 none;
|
|
4284
|
+
transition: background var(--h-toast-transition-duration);
|
|
4285
|
+
}
|
|
4286
|
+
|
|
4287
|
+
.hx-toast-action:hover {
|
|
4288
|
+
background: var(--hx-toast-hover);
|
|
4289
|
+
}
|
|
4290
|
+
|
|
4291
|
+
.hx-toast-action:focus-visible {
|
|
4292
|
+
outline: var(--h-toast-close-button-focus-ring-width) var(--h-toast-close-button-focus-ring-style) var(--hx-toast-ring);
|
|
4293
|
+
outline-offset: var(--h-toast-close-button-focus-ring-offset);
|
|
4294
|
+
box-shadow: var(--hx-toast-ring-shadow);
|
|
4295
|
+
}
|
|
4296
|
+
|
|
4176
4297
|
.hx-toast-close {
|
|
4177
4298
|
display: inline-flex;
|
|
4178
4299
|
flex: none;
|
|
@@ -4214,6 +4335,7 @@
|
|
|
4214
4335
|
.hx-toast-item {
|
|
4215
4336
|
animation: none;
|
|
4216
4337
|
}
|
|
4338
|
+
.hx-toast-action,
|
|
4217
4339
|
.hx-toast-close {
|
|
4218
4340
|
transition: none;
|
|
4219
4341
|
}
|
|
@@ -308,19 +308,7 @@ var HxChart = class HxChart {
|
|
|
308
308
|
isSignal: true
|
|
309
309
|
}],
|
|
310
310
|
ngImport: i0,
|
|
311
|
-
template:
|
|
312
|
-
<div class="hx-chart-frame" [style.width]="width() ?? null" [style.height]="height() ?? null">
|
|
313
|
-
<canvas
|
|
314
|
-
#canvas
|
|
315
|
-
class="hx-chart-canvas"
|
|
316
|
-
role="img"
|
|
317
|
-
[attr.aria-label]="ariaLabel() || null"
|
|
318
|
-
[attr.aria-labelledby]="ariaLabelledBy() || null"
|
|
319
|
-
(click)="onClick($event)"
|
|
320
|
-
><ng-content select="[hxChartFallback]" /></canvas>
|
|
321
|
-
</div>
|
|
322
|
-
`,
|
|
323
|
-
isInline: true,
|
|
311
|
+
template: "<div class=\"hx-chart-frame\" [style.width]=\"width() ?? null\" [style.height]=\"height() ?? null\">\n <canvas\n #canvas\n class=\"hx-chart-canvas\"\n role=\"img\"\n [attr.aria-label]=\"ariaLabel() || null\"\n [attr.aria-labelledby]=\"ariaLabelledBy() || null\"\n (click)=\"onClick($event)\"\n ><ng-content select=\"[hxChartFallback]\" /></canvas>\n</div>\n",
|
|
324
312
|
changeDetection: i0.ChangeDetectionStrategy.OnPush
|
|
325
313
|
});
|
|
326
314
|
};
|
|
@@ -335,18 +323,7 @@ i0.ɵɵngDeclareClassMetadata({
|
|
|
335
323
|
selector: "hx-chart",
|
|
336
324
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
337
325
|
host: { class: "hx-chart" },
|
|
338
|
-
template:
|
|
339
|
-
<div class="hx-chart-frame" [style.width]="width() ?? null" [style.height]="height() ?? null">
|
|
340
|
-
<canvas
|
|
341
|
-
#canvas
|
|
342
|
-
class="hx-chart-canvas"
|
|
343
|
-
role="img"
|
|
344
|
-
[attr.aria-label]="ariaLabel() || null"
|
|
345
|
-
[attr.aria-labelledby]="ariaLabelledBy() || null"
|
|
346
|
-
(click)="onClick($event)"
|
|
347
|
-
><ng-content select="[hxChartFallback]" /></canvas>
|
|
348
|
-
</div>
|
|
349
|
-
`
|
|
326
|
+
template: "<div class=\"hx-chart-frame\" [style.width]=\"width() ?? null\" [style.height]=\"height() ?? null\">\n <canvas\n #canvas\n class=\"hx-chart-canvas\"\n role=\"img\"\n [attr.aria-label]=\"ariaLabel() || null\"\n [attr.aria-labelledby]=\"ariaLabelledBy() || null\"\n (click)=\"onClick($event)\"\n ><ng-content select=\"[hxChartFallback]\" /></canvas>\n</div>\n"
|
|
350
327
|
}]
|
|
351
328
|
}],
|
|
352
329
|
ctorParameters: () => [],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gravionlabs-helix-ui-chart.mjs","names":[],"sources":["../../../projects/ui/chart/chart.ts"],"sourcesContent":["import { isPlatformBrowser } from '@angular/common';\nimport {\n afterNextRender,\n ChangeDetectionStrategy,\n Component,\n DestroyRef,\n ElementRef,\n effect,\n InjectionToken,\n inject,\n input,\n NgZone,\n numberAttribute,\n output,\n PLATFORM_ID,\n untracked,\n viewChild,\n} from '@angular/core';\n\nexport type HxChartType =\n | 'bar'\n | 'line'\n | 'scatter'\n | 'bubble'\n | 'pie'\n | 'doughnut'\n | 'polarArea'\n | 'radar';\n\n/** What `(dataSelect)` carries: the click and what chart.js found under it. */\nexport interface HxChartSelectEvent {\n originalEvent: Event;\n /** The nearest element under the pointer (chart.js `{ datasetIndex, index, element }`). */\n element: unknown;\n /** The elements of that dataset. */\n dataset: unknown[];\n}\n\n/** The part of chart.js this component uses; the real module is `chart.js/auto`. */\nexport interface HxChartModule {\n default: new (canvas: HTMLCanvasElement, config: unknown) => HxChartInstance;\n}\n\nexport interface HxChartInstance {\n data: unknown;\n options: unknown;\n update(mode?: string): void;\n destroy(): void;\n getElementsAtEventForMode(\n event: Event,\n mode: string,\n options: object,\n useFinalPosition: boolean,\n ): unknown[];\n}\n\n/**\n * Loads chart.js. The default is a dynamic `import('chart.js/auto')`, so chart.js is only fetched by apps that show\n * a chart; provide another function to register a smaller set of chart.js parts or to replace it in tests.\n */\nexport const HX_CHART_LOADER = new InjectionToken<() => Promise<HxChartModule>>('HX_CHART_LOADER', {\n providedIn: 'root',\n factory: () => () => import('chart.js/auto') as unknown as Promise<HxChartModule>,\n});\n\n/** Colours of the datasets that do not set their own, as tokens in the order they are used. */\nconst PALETTE = [\n '--h-primary-color',\n '--h-orange-500',\n '--h-green-500',\n '--h-purple-500',\n '--h-sky-500',\n '--h-red-500',\n '--h-yellow-500',\n '--h-teal-500',\n];\n\ntype Json = Record<string, unknown>;\n\n/** The parts of chart.js data and datasets that are read here; everything else is passed on untouched. */\ninterface ChartDataLike extends Json {\n datasets?: unknown;\n}\ninterface DatasetLike extends Json {\n data?: unknown;\n backgroundColor?: unknown;\n borderColor?: unknown;\n}\n\nconst isObject = (value: unknown): value is Json =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\n/** `defaults` underneath, `overrides` on top; objects merge, everything else is replaced. */\nfunction merge(defaults: Json, overrides: Json): Json {\n const out: Json = { ...defaults };\n for (const [key, value] of Object.entries(overrides)) {\n const base = out[key];\n out[key] = isObject(base) && isObject(value) ? merge(base, value) : value;\n }\n return out;\n}\n\n/**\n * A chart.js chart whose colours, grid and font come from the Helix tokens.\n *\n * ```html\n * <hx-chart type=\"bar\" [data]=\"data\" [options]=\"options\" height=\"20rem\" ariaLabel=\"Sales per month\">\n * <table hxChartFallback>…the same numbers as text…</table>\n * </hx-chart>\n * ```\n *\n * chart.js is an optional peer dependency, loaded with a dynamic import (see `HX_CHART_LOADER`) the first time a\n * chart is shown. Datasets without colours get the Helix palette; text, grid and legend colours come from\n * `--h-text-muted-color` and `--h-content-border-color` of the element. Your `options` win over these defaults.\n * The chart is redrawn when `class` or `style` of `<html>` change (dark mode, the primary colour).\n *\n * The canvas is an `img` named by `ariaLabel` / `ariaLabelledBy`; content marked `hxChartFallback` becomes the\n * canvas fallback content, which assistive technology reads: put the numbers there as text or as a table.\n */\n@Component({\n selector: 'hx-chart',\n changeDetection: ChangeDetectionStrategy.OnPush,\n host: { class: 'hx-chart' },\n template: `\n <div class=\"hx-chart-frame\" [style.width]=\"width() ?? null\" [style.height]=\"height() ?? null\">\n <canvas\n #canvas\n class=\"hx-chart-canvas\"\n role=\"img\"\n [attr.aria-label]=\"ariaLabel() || null\"\n [attr.aria-labelledby]=\"ariaLabelledBy() || null\"\n (click)=\"onClick($event)\"\n ><ng-content select=\"[hxChartFallback]\" /></canvas>\n </div>\n `,\n})\nexport class HxChart {\n readonly #host = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;\n readonly #zone = inject(NgZone);\n readonly #loader = inject(HX_CHART_LOADER);\n readonly #platform = inject(PLATFORM_ID);\n private readonly canvas = viewChild.required<ElementRef<HTMLCanvasElement>>('canvas');\n\n readonly type = input<HxChartType>('bar');\n /** chart.js data: `{ labels, datasets }`. Pass a new object to update the chart. */\n readonly data = input<ChartDataLike>({});\n /** chart.js options, on top of the token defaults. Pass a new object to update the chart. */\n readonly options = input<Json>({});\n /** Extra chart.js plugins for this chart. */\n readonly plugins = input<readonly unknown[]>([]);\n /** CSS width of the frame, e.g. `30rem`; the chart fills its container by default. */\n readonly width = input<string>();\n /** CSS height of the frame; without it chart.js keeps its aspect ratio. */\n readonly height = input<string>();\n /** Resize with the container. */\n readonly responsive = input(true, { transform: (v: unknown) => v !== false && v !== 'false' });\n readonly ariaLabel = input<string>();\n readonly ariaLabelledBy = input<string>();\n /** Delay of a redraw after the theme changed, in ms; the style change is usually followed by more. */\n readonly themeDelay = input(50, { transform: numberAttribute });\n\n /** A data point or dataset was clicked. */\n readonly dataSelect = output<HxChartSelectEvent>();\n\n #chart: HxChartInstance | undefined;\n #chartType: HxChartType | undefined;\n #ready = false;\n #loading = false;\n #observer: MutationObserver | undefined;\n #timer: ReturnType<typeof setTimeout> | undefined;\n\n constructor() {\n afterNextRender(() => {\n this.#ready = true;\n void this.#render();\n this.#watchTheme();\n });\n effect(() => {\n this.type();\n this.data();\n this.options();\n this.plugins();\n this.responsive();\n this.width();\n this.height();\n untracked(() => {\n if (this.#ready) void this.#render();\n });\n });\n inject(DestroyRef).onDestroy(() => {\n clearTimeout(this.#timer);\n this.#observer?.disconnect();\n this.#chart?.destroy();\n this.#chart = undefined;\n this.#ready = false;\n });\n }\n\n /** The chart.js instance, once it exists; `undefined` before chart.js has loaded. */\n get chart(): HxChartInstance | undefined {\n return this.#chart;\n }\n\n /** Redraws the chart, e.g. after the theme changed in a way the component cannot see. */\n refresh(): void {\n if (this.#chart) {\n this.#apply(this.#chart);\n this.#chart.update();\n }\n }\n\n protected onClick(event: MouseEvent): void {\n const chart = this.#chart;\n if (!chart) return;\n const element = chart.getElementsAtEventForMode(event, 'nearest', { intersect: true }, false);\n const dataset = chart.getElementsAtEventForMode(event, 'dataset', { intersect: true }, false);\n if (element?.[0] && dataset)\n this.dataSelect.emit({ originalEvent: event, element: element[0], dataset });\n }\n\n async #render(): Promise<void> {\n if (!isPlatformBrowser(this.#platform)) return;\n const type = this.type();\n if (this.#chart && this.#chartType === type) {\n this.#apply(this.#chart);\n this.#chart.update();\n return;\n }\n if (this.#loading) return;\n this.#loading = true;\n try {\n const module = await this.#loader();\n if (!this.#ready) return; // destroyed while chart.js loaded\n this.#chart?.destroy();\n const Chart = module.default;\n this.#zone.runOutsideAngular(() => {\n this.#chart = new Chart(this.canvas().nativeElement, {\n type: this.type(),\n data: this.#themedData(),\n options: this.#themedOptions(),\n plugins: [...this.plugins()],\n });\n });\n this.#chartType = this.type();\n } catch (error) {\n console.error(\n 'hx-chart: chart.js could not be loaded. Is the peer dependency \"chart.js\" installed?',\n error,\n );\n return;\n } finally {\n this.#loading = false;\n }\n // inputs may have changed while chart.js loaded\n if (this.#chart && this.#chartType !== this.type()) await this.#render();\n }\n\n #apply(chart: HxChartInstance): void {\n chart.data = this.#themedData();\n chart.options = this.#themedOptions();\n }\n\n #token(name: string): string {\n return getComputedStyle(this.#host).getPropertyValue(name).trim();\n }\n\n /** The datasets with palette colours where they set none. The input is not changed. */\n #themedData(): Json {\n const data = this.data();\n const datasets = data.datasets;\n if (!Array.isArray(datasets)) return data;\n const palette = PALETTE.map((name) => this.#token(name)).filter(Boolean);\n if (palette.length === 0) return data;\n const perPoint = ['pie', 'doughnut', 'polarArea'].includes(this.type());\n return {\n ...data,\n datasets: datasets.map((dataset: DatasetLike, i: number) => {\n if (!isObject(dataset)) return dataset;\n const color = palette[i % palette.length];\n const count = Array.isArray(dataset.data) ? dataset.data.length : 0;\n const points = Array.from({ length: count }, (_, n) => palette[n % palette.length]);\n const filled = this.type() === 'line' || this.type() === 'radar';\n return {\n ...dataset,\n backgroundColor:\n dataset.backgroundColor ??\n (perPoint ? points : filled ? `color-mix(in srgb, ${color}, transparent 80%)` : color),\n borderColor:\n dataset.borderColor ?? (perPoint ? this.#token('--h-content-background') : color),\n };\n }),\n };\n }\n\n #themedOptions(): Json {\n const text = this.#token('--h-text-color');\n const muted = this.#token('--h-text-muted-color');\n const grid = this.#token('--h-content-border-color');\n const axis = { ticks: { color: muted }, grid: { color: grid }, border: { color: grid } };\n const radial = {\n ticks: { color: muted, backdropColor: 'transparent' },\n grid: { color: grid },\n angleLines: { color: grid },\n pointLabels: { color: text },\n };\n const type = this.type();\n const scales =\n type === 'radar' || type === 'polarArea'\n ? { r: radial }\n : type === 'pie' || type === 'doughnut'\n ? {}\n : { x: axis, y: axis };\n const defaults: Json = {\n responsive: this.responsive(),\n maintainAspectRatio: !(this.height() || this.width()),\n color: muted,\n borderColor: grid,\n plugins: { legend: { labels: { color: text } } },\n scales,\n };\n return merge(defaults, this.options());\n }\n\n #watchTheme(): void {\n if (typeof MutationObserver === 'undefined') return;\n this.#observer = new MutationObserver(() => {\n clearTimeout(this.#timer);\n this.#timer = setTimeout(() => this.refresh(), this.themeDelay());\n });\n this.#observer.observe(document.documentElement, {\n attributes: true,\n attributeFilter: ['class', 'style', 'data-theme'],\n });\n }\n}\n"],"mappings":";;;AA4DA,MAAa,kBAAkB,IAAI,eAA6C,mBAAmB;CACjG,YAAY;CACZ,qBAAqB,OAAO;AAC7B,CAAA;AAGD,MAAM,UAAU;CACd;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD;AAcD,MAAM,YAAY,UAChB,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAGrE,SAAS,MAAM,UAAgB,WAAe;CAC5C,MAAM,MAAY,EAAE,GAAG,SAAQ;CAC/B,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,SAAS,GAAG;EACpD,MAAM,OAAO,IAAI;EACjB,IAAI,OAAO,SAAS,IAAI,KAAK,SAAS,KAAK,IAAI,MAAM,MAAM,KAAK,IAAI;CACtE;CACA,OAAO;AACT;AAoCA,IAAa,UAAb,MAAa,QAAO;CACT,QAAQ,OAAgC,UAAU,CAAC,CAAC;CACpD,QAAQ,OAAO,MAAM;CACrB,UAAU,OAAO,eAAe;CAChC,YAAY,OAAO,WAAW;CACtB,SAAS,UAAU,SAAwC,UAAS,GAAA,YAAA,CAAA,EAAA,WAAA,SAAA,CAAA,+BAAA,CAAA,CAAA;CAE5E,OAAO,MAAmB,OAAM,GAAA,YAAA,CAAA,EAAA,WAAA,OAAA,CAAA,+BAAA,CAAA,CAAA;CAEhC,OAAO,MAAqB,CAAA,GAAG,GAAA,YAAA,CAAA,EAAA,WAAA,OAAA,CAAA,+BAAA,CAAA,CAAA;CAE/B,UAAU,MAAY,CAAA,GAAG,GAAA,YAAA,CA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,UAAA;GAAA,CAAA;EAAA,CAAA;EAAA,YAAA,CAAA;GAAA,MAAA,GAAA;GAAA,MAAA,CAAA,YAAA;EAAA,CAAA;CAAA;AAAA,CAAA"}
|
|
1
|
+
{"version":3,"file":"gravionlabs-helix-ui-chart.mjs","names":[],"sources":["../../../projects/ui/chart/chart.ts","../../../projects/ui/chart/chart.html"],"sourcesContent":["import { isPlatformBrowser } from '@angular/common';\nimport {\n afterNextRender,\n ChangeDetectionStrategy,\n Component,\n DestroyRef,\n ElementRef,\n effect,\n InjectionToken,\n inject,\n input,\n NgZone,\n numberAttribute,\n output,\n PLATFORM_ID,\n untracked,\n viewChild,\n} from '@angular/core';\n\nexport type HxChartType =\n | 'bar'\n | 'line'\n | 'scatter'\n | 'bubble'\n | 'pie'\n | 'doughnut'\n | 'polarArea'\n | 'radar';\n\n/** What `(dataSelect)` carries: the click and what chart.js found under it. */\nexport interface HxChartSelectEvent {\n originalEvent: Event;\n /** The nearest element under the pointer (chart.js `{ datasetIndex, index, element }`). */\n element: unknown;\n /** The elements of that dataset. */\n dataset: unknown[];\n}\n\n/** The part of chart.js this component uses; the real module is `chart.js/auto`. */\nexport interface HxChartModule {\n default: new (canvas: HTMLCanvasElement, config: unknown) => HxChartInstance;\n}\n\nexport interface HxChartInstance {\n data: unknown;\n options: unknown;\n update(mode?: string): void;\n destroy(): void;\n getElementsAtEventForMode(\n event: Event,\n mode: string,\n options: object,\n useFinalPosition: boolean,\n ): unknown[];\n}\n\n/**\n * Loads chart.js. The default is a dynamic `import('chart.js/auto')`, so chart.js is only fetched by apps that show\n * a chart; provide another function to register a smaller set of chart.js parts or to replace it in tests.\n */\nexport const HX_CHART_LOADER = new InjectionToken<() => Promise<HxChartModule>>('HX_CHART_LOADER', {\n providedIn: 'root',\n factory: () => () => import('chart.js/auto') as unknown as Promise<HxChartModule>,\n});\n\n/** Colours of the datasets that do not set their own, as tokens in the order they are used. */\nconst PALETTE = [\n '--h-primary-color',\n '--h-orange-500',\n '--h-green-500',\n '--h-purple-500',\n '--h-sky-500',\n '--h-red-500',\n '--h-yellow-500',\n '--h-teal-500',\n];\n\ntype Json = Record<string, unknown>;\n\n/** The parts of chart.js data and datasets that are read here; everything else is passed on untouched. */\ninterface ChartDataLike extends Json {\n datasets?: unknown;\n}\ninterface DatasetLike extends Json {\n data?: unknown;\n backgroundColor?: unknown;\n borderColor?: unknown;\n}\n\nconst isObject = (value: unknown): value is Json =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\n/** `defaults` underneath, `overrides` on top; objects merge, everything else is replaced. */\nfunction merge(defaults: Json, overrides: Json): Json {\n const out: Json = { ...defaults };\n for (const [key, value] of Object.entries(overrides)) {\n const base = out[key];\n out[key] = isObject(base) && isObject(value) ? merge(base, value) : value;\n }\n return out;\n}\n\n/**\n * A chart.js chart whose colours, grid and font come from the Helix tokens.\n *\n * ```html\n * <hx-chart type=\"bar\" [data]=\"data\" [options]=\"options\" height=\"20rem\" ariaLabel=\"Sales per month\">\n * <table hxChartFallback>…the same numbers as text…</table>\n * </hx-chart>\n * ```\n *\n * chart.js is an optional peer dependency, loaded with a dynamic import (see `HX_CHART_LOADER`) the first time a\n * chart is shown. Datasets without colours get the Helix palette; text, grid and legend colours come from\n * `--h-text-muted-color` and `--h-content-border-color` of the element. Your `options` win over these defaults.\n * The chart is redrawn when `class` or `style` of `<html>` change (dark mode, the primary colour).\n *\n * The canvas is an `img` named by `ariaLabel` / `ariaLabelledBy`; content marked `hxChartFallback` becomes the\n * canvas fallback content, which assistive technology reads: put the numbers there as text or as a table.\n */\n@Component({\n selector: 'hx-chart',\n changeDetection: ChangeDetectionStrategy.OnPush,\n host: { class: 'hx-chart' },\n templateUrl: './chart.html',\n})\nexport class HxChart {\n readonly #host = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;\n readonly #zone = inject(NgZone);\n readonly #loader = inject(HX_CHART_LOADER);\n readonly #platform = inject(PLATFORM_ID);\n private readonly canvas = viewChild.required<ElementRef<HTMLCanvasElement>>('canvas');\n\n readonly type = input<HxChartType>('bar');\n /** chart.js data: `{ labels, datasets }`. Pass a new object to update the chart. */\n readonly data = input<ChartDataLike>({});\n /** chart.js options, on top of the token defaults. Pass a new object to update the chart. */\n readonly options = input<Json>({});\n /** Extra chart.js plugins for this chart. */\n readonly plugins = input<readonly unknown[]>([]);\n /** CSS width of the frame, e.g. `30rem`; the chart fills its container by default. */\n readonly width = input<string>();\n /** CSS height of the frame; without it chart.js keeps its aspect ratio. */\n readonly height = input<string>();\n /** Resize with the container. */\n readonly responsive = input(true, { transform: (v: unknown) => v !== false && v !== 'false' });\n readonly ariaLabel = input<string>();\n readonly ariaLabelledBy = input<string>();\n /** Delay of a redraw after the theme changed, in ms; the style change is usually followed by more. */\n readonly themeDelay = input(50, { transform: numberAttribute });\n\n /** A data point or dataset was clicked. */\n readonly dataSelect = output<HxChartSelectEvent>();\n\n #chart: HxChartInstance | undefined;\n #chartType: HxChartType | undefined;\n #ready = false;\n #loading = false;\n #observer: MutationObserver | undefined;\n #timer: ReturnType<typeof setTimeout> | undefined;\n\n constructor() {\n afterNextRender(() => {\n this.#ready = true;\n void this.#render();\n this.#watchTheme();\n });\n effect(() => {\n this.type();\n this.data();\n this.options();\n this.plugins();\n this.responsive();\n this.width();\n this.height();\n untracked(() => {\n if (this.#ready) void this.#render();\n });\n });\n inject(DestroyRef).onDestroy(() => {\n clearTimeout(this.#timer);\n this.#observer?.disconnect();\n this.#chart?.destroy();\n this.#chart = undefined;\n this.#ready = false;\n });\n }\n\n /** The chart.js instance, once it exists; `undefined` before chart.js has loaded. */\n get chart(): HxChartInstance | undefined {\n return this.#chart;\n }\n\n /** Redraws the chart, e.g. after the theme changed in a way the component cannot see. */\n refresh(): void {\n if (this.#chart) {\n this.#apply(this.#chart);\n this.#chart.update();\n }\n }\n\n protected onClick(event: MouseEvent): void {\n const chart = this.#chart;\n if (!chart) return;\n const element = chart.getElementsAtEventForMode(event, 'nearest', { intersect: true }, false);\n const dataset = chart.getElementsAtEventForMode(event, 'dataset', { intersect: true }, false);\n if (element?.[0] && dataset)\n this.dataSelect.emit({ originalEvent: event, element: element[0], dataset });\n }\n\n async #render(): Promise<void> {\n if (!isPlatformBrowser(this.#platform)) return;\n const type = this.type();\n if (this.#chart && this.#chartType === type) {\n this.#apply(this.#chart);\n this.#chart.update();\n return;\n }\n if (this.#loading) return;\n this.#loading = true;\n try {\n const module = await this.#loader();\n if (!this.#ready) return; // destroyed while chart.js loaded\n this.#chart?.destroy();\n const Chart = module.default;\n this.#zone.runOutsideAngular(() => {\n this.#chart = new Chart(this.canvas().nativeElement, {\n type: this.type(),\n data: this.#themedData(),\n options: this.#themedOptions(),\n plugins: [...this.plugins()],\n });\n });\n this.#chartType = this.type();\n } catch (error) {\n console.error(\n 'hx-chart: chart.js could not be loaded. Is the peer dependency \"chart.js\" installed?',\n error,\n );\n return;\n } finally {\n this.#loading = false;\n }\n // inputs may have changed while chart.js loaded\n if (this.#chart && this.#chartType !== this.type()) await this.#render();\n }\n\n #apply(chart: HxChartInstance): void {\n chart.data = this.#themedData();\n chart.options = this.#themedOptions();\n }\n\n #token(name: string): string {\n return getComputedStyle(this.#host).getPropertyValue(name).trim();\n }\n\n /** The datasets with palette colours where they set none. The input is not changed. */\n #themedData(): Json {\n const data = this.data();\n const datasets = data.datasets;\n if (!Array.isArray(datasets)) return data;\n const palette = PALETTE.map((name) => this.#token(name)).filter(Boolean);\n if (palette.length === 0) return data;\n const perPoint = ['pie', 'doughnut', 'polarArea'].includes(this.type());\n return {\n ...data,\n datasets: datasets.map((dataset: DatasetLike, i: number) => {\n if (!isObject(dataset)) return dataset;\n const color = palette[i % palette.length];\n const count = Array.isArray(dataset.data) ? dataset.data.length : 0;\n const points = Array.from({ length: count }, (_, n) => palette[n % palette.length]);\n const filled = this.type() === 'line' || this.type() === 'radar';\n return {\n ...dataset,\n backgroundColor:\n dataset.backgroundColor ??\n (perPoint ? points : filled ? `color-mix(in srgb, ${color}, transparent 80%)` : color),\n borderColor:\n dataset.borderColor ?? (perPoint ? this.#token('--h-content-background') : color),\n };\n }),\n };\n }\n\n #themedOptions(): Json {\n const text = this.#token('--h-text-color');\n const muted = this.#token('--h-text-muted-color');\n const grid = this.#token('--h-content-border-color');\n const axis = { ticks: { color: muted }, grid: { color: grid }, border: { color: grid } };\n const radial = {\n ticks: { color: muted, backdropColor: 'transparent' },\n grid: { color: grid },\n angleLines: { color: grid },\n pointLabels: { color: text },\n };\n const type = this.type();\n const scales =\n type === 'radar' || type === 'polarArea'\n ? { r: radial }\n : type === 'pie' || type === 'doughnut'\n ? {}\n : { x: axis, y: axis };\n const defaults: Json = {\n responsive: this.responsive(),\n maintainAspectRatio: !(this.height() || this.width()),\n color: muted,\n borderColor: grid,\n plugins: { legend: { labels: { color: text } } },\n scales,\n };\n return merge(defaults, this.options());\n }\n\n #watchTheme(): void {\n if (typeof MutationObserver === 'undefined') return;\n this.#observer = new MutationObserver(() => {\n clearTimeout(this.#timer);\n this.#timer = setTimeout(() => this.refresh(), this.themeDelay());\n });\n this.#observer.observe(document.documentElement, {\n attributes: true,\n attributeFilter: ['class', 'style', 'data-theme'],\n });\n }\n}\n","<div class=\"hx-chart-frame\" [style.width]=\"width() ?? null\" [style.height]=\"height() ?? null\">\n <canvas\n #canvas\n class=\"hx-chart-canvas\"\n role=\"img\"\n [attr.aria-label]=\"ariaLabel() || null\"\n [attr.aria-labelledby]=\"ariaLabelledBy() || null\"\n (click)=\"onClick($event)\"\n ><ng-content select=\"[hxChartFallback]\" /></canvas>\n</div>\n"],"mappings":";;;AA4DA,MAAa,kBAAkB,IAAI,eAA6C,mBAAmB;CACjG,YAAY;CACZ,qBAAqB,OAAO;AAC7B,CAAA;AAGD,MAAM,UAAU;CACd;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD;AAcD,MAAM,YAAY,UAChB,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAGrE,SAAS,MAAM,UAAgB,WAAe;CAC5C,MA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