ngwr 16.7.1 → 16.8.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/charts/donut-chart/styles/_index.scss +9 -3
- package/charts/meter-group/styles/_index.scss +8 -1
- package/charts/sparkline/styles/_index.scss +6 -3
- package/command-palette/styles/_index.scss +10 -0
- package/fesm2022/ngwr-charts-calendar-heatmap.mjs +3 -1
- package/fesm2022/ngwr-charts-calendar-heatmap.mjs.map +1 -1
- package/fesm2022/ngwr-charts-core.mjs +17 -0
- package/fesm2022/ngwr-charts-core.mjs.map +1 -1
- package/fesm2022/ngwr-charts-donut-chart-testing.mjs +27 -0
- package/fesm2022/ngwr-charts-donut-chart-testing.mjs.map +1 -1
- package/fesm2022/ngwr-charts-donut-chart.mjs +54 -6
- package/fesm2022/ngwr-charts-donut-chart.mjs.map +1 -1
- package/fesm2022/ngwr-charts-meter-group-testing.mjs +27 -0
- package/fesm2022/ngwr-charts-meter-group-testing.mjs.map +1 -1
- package/fesm2022/ngwr-charts-meter-group.mjs +54 -6
- package/fesm2022/ngwr-charts-meter-group.mjs.map +1 -1
- package/fesm2022/ngwr-charts-sparkline-testing.mjs +27 -0
- package/fesm2022/ngwr-charts-sparkline-testing.mjs.map +1 -1
- package/fesm2022/ngwr-charts-sparkline.mjs +45 -4
- package/fesm2022/ngwr-charts-sparkline.mjs.map +1 -1
- package/fesm2022/ngwr-checkbox.mjs +38 -3
- package/fesm2022/ngwr-checkbox.mjs.map +1 -1
- package/fesm2022/ngwr-color-picker-testing.mjs.map +1 -1
- package/fesm2022/ngwr-color-picker.mjs +4 -3
- package/fesm2022/ngwr-color-picker.mjs.map +1 -1
- package/fesm2022/ngwr-command-palette.mjs +39 -19
- package/fesm2022/ngwr-command-palette.mjs.map +1 -1
- package/fesm2022/ngwr-context-menu.mjs +7 -2
- package/fesm2022/ngwr-context-menu.mjs.map +1 -1
- package/fesm2022/ngwr-dialog.mjs +10 -7
- package/fesm2022/ngwr-dialog.mjs.map +1 -1
- package/fesm2022/ngwr-drawer.mjs +14 -8
- package/fesm2022/ngwr-drawer.mjs.map +1 -1
- package/fesm2022/ngwr-file-upload.mjs +2 -2
- package/fesm2022/ngwr-file-upload.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-ar.mjs +9 -2
- package/fesm2022/ngwr-i18n-ar.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-cs.mjs +9 -2
- package/fesm2022/ngwr-i18n-cs.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-de.mjs +9 -2
- package/fesm2022/ngwr-i18n-de.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-en.mjs +9 -2
- package/fesm2022/ngwr-i18n-en.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-es.mjs +9 -2
- package/fesm2022/ngwr-i18n-es.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-fr.mjs +9 -2
- package/fesm2022/ngwr-i18n-fr.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-he.mjs +9 -2
- package/fesm2022/ngwr-i18n-he.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-hi.mjs +9 -2
- package/fesm2022/ngwr-i18n-hi.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-id.mjs +9 -2
- package/fesm2022/ngwr-i18n-id.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-it.mjs +9 -2
- package/fesm2022/ngwr-i18n-it.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-ja.mjs +9 -2
- package/fesm2022/ngwr-i18n-ja.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-kk.mjs +9 -2
- package/fesm2022/ngwr-i18n-kk.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-ko.mjs +9 -2
- package/fesm2022/ngwr-i18n-ko.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-nl.mjs +9 -2
- package/fesm2022/ngwr-i18n-nl.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-pl.mjs +9 -2
- package/fesm2022/ngwr-i18n-pl.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-pt.mjs +9 -2
- package/fesm2022/ngwr-i18n-pt.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-ru.mjs +9 -2
- package/fesm2022/ngwr-i18n-ru.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-sv.mjs +9 -2
- package/fesm2022/ngwr-i18n-sv.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-tr.mjs +9 -2
- package/fesm2022/ngwr-i18n-tr.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-uk.mjs +9 -2
- package/fesm2022/ngwr-i18n-uk.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-vi.mjs +9 -2
- package/fesm2022/ngwr-i18n-vi.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-zh-tw.mjs +9 -2
- package/fesm2022/ngwr-i18n-zh-tw.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-zh.mjs +9 -2
- package/fesm2022/ngwr-i18n-zh.mjs.map +1 -1
- package/fesm2022/ngwr-input-number.mjs +33 -10
- package/fesm2022/ngwr-input-number.mjs.map +1 -1
- package/fesm2022/ngwr-input-otp.mjs +24 -10
- package/fesm2022/ngwr-input-otp.mjs.map +1 -1
- package/fesm2022/ngwr-input.mjs +2 -2
- package/fesm2022/ngwr-input.mjs.map +1 -1
- package/fesm2022/ngwr-lightbox.mjs +5 -3
- package/fesm2022/ngwr-lightbox.mjs.map +1 -1
- package/fesm2022/ngwr-overlay.mjs +51 -2
- package/fesm2022/ngwr-overlay.mjs.map +1 -1
- package/fesm2022/ngwr-popconfirm.mjs +2 -2
- package/fesm2022/ngwr-popconfirm.mjs.map +1 -1
- package/fesm2022/ngwr-slider.mjs +22 -17
- package/fesm2022/ngwr-slider.mjs.map +1 -1
- package/fesm2022/ngwr-switch.mjs +33 -3
- package/fesm2022/ngwr-switch.mjs.map +1 -1
- package/fesm2022/ngwr-tour.mjs +8 -3
- package/fesm2022/ngwr-tour.mjs.map +1 -1
- package/fesm2022/ngwr-version.mjs +1 -1
- package/fesm2022/ngwr-version.mjs.map +1 -1
- package/i18n/ar.json +9 -2
- package/i18n/cs.json +9 -2
- package/i18n/de.json +9 -2
- package/i18n/en.json +9 -2
- package/i18n/es.json +9 -2
- package/i18n/fr.json +9 -2
- package/i18n/he.json +9 -2
- package/i18n/hi.json +9 -2
- package/i18n/id.json +9 -2
- package/i18n/it.json +9 -2
- package/i18n/ja.json +9 -2
- package/i18n/kk.json +9 -2
- package/i18n/ko.json +9 -2
- package/i18n/nl.json +9 -2
- package/i18n/pl.json +9 -2
- package/i18n/pt.json +9 -2
- package/i18n/ru.json +9 -2
- package/i18n/sv.json +9 -2
- package/i18n/tr.json +9 -2
- package/i18n/uk.json +9 -2
- package/i18n/vi.json +9 -2
- package/i18n/zh-TW.json +9 -2
- package/i18n/zh.json +9 -2
- package/llms-full.txt +4 -4
- package/package.json +1 -1
- package/schematics/use/rule.js +1 -0
- package/schematics/use/symbol-map.json +1 -0
- package/tour/styles/_index.scss +11 -7
- package/types/ngwr-charts-donut-chart-testing.d.ts +32 -3
- package/types/ngwr-charts-donut-chart.d.ts +45 -6
- package/types/ngwr-charts-meter-group-testing.d.ts +29 -1
- package/types/ngwr-charts-meter-group.d.ts +43 -4
- package/types/ngwr-charts-sparkline-testing.d.ts +32 -2
- package/types/ngwr-charts-sparkline.d.ts +42 -3
- package/types/ngwr-checkbox.d.ts +14 -0
- package/types/ngwr-color-picker-testing.d.ts +1 -1
- package/types/ngwr-command-palette.d.ts +2 -1
- package/types/ngwr-dialog.d.ts +11 -6
- package/types/ngwr-drawer.d.ts +12 -4
- package/types/ngwr-file-upload.d.ts +1 -1
- package/types/ngwr-input-number.d.ts +14 -2
- package/types/ngwr-input-otp.d.ts +2 -0
- package/types/ngwr-lightbox.d.ts +1 -0
- package/types/ngwr-overlay.d.ts +20 -1
- package/types/ngwr-slider.d.ts +3 -1
- package/types/ngwr-switch.d.ts +13 -0
- package/types/ngwr-version.d.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ngwr-charts-core.mjs","names":[],"sources":["../../../projects/lib/charts/core/axis.ts","../../../projects/lib/charts/core/chart-state.ts","../../../projects/lib/charts/core/chart-state.html","../../../projects/lib/charts/core/chart-table.ts","../../../projects/lib/charts/core/chart-table.html","../../../projects/lib/charts/core/interaction.ts","../../../projects/lib/charts/core/labels.ts","../../../projects/lib/charts/core/palette.ts","../../../projects/lib/charts/core/markers.ts","../../../projects/lib/charts/core/numbers.ts","../../../projects/lib/charts/core/round.ts"],"sourcesContent":["/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { wrRound } from 'ngwr/utils';\n\nimport type { WrChartAxis, WrChartAxisOptions } from './types';\n\n/** How many gaps an axis aims for by default. Five labels, four gaps. */\nconst TICK_COUNT = 4;\n\n/** The axis drawn when there is no data to fit: 0 to 1 in quarters, the line chart's empty frame. */\nconst EMPTY: WrChartAxis = { min: 0, max: 1, step: 0.25, ticks: [1, 0.75, 0.5, 0.25, 0] };\n\n/** The rungs of the {@link niceStep} ladder within one decade, from the top: 1, 0.5, 0.25 and 0.2 of it. */\nconst LADDER = [1, 0.5, 0.25, 0.2] as const;\n\n/**\n * How many fraction digits a tick on an axis stepping by `step` is rounded to: two past\n * the step's own leading digit, and never fewer than six or more than fifteen.\n *\n * It was a fixed six, which cannot write a tick finer than a millionth: an axis stepping\n * by 2.5e-7 — a micro-priced asset — came back as five ticks of `0.000013` and\n * `0.000012`, one stepping by 5e-10 as five zeros, and one stepping by 2.5e-6 put two of\n * its gridlines at the wrong height. Every tick is a whole multiple of the step, whose\n * last digit is at most one place past its leading one (2.5, and 0.25 on the\n * centred axis' ladder, two), so two past the leading digit writes every tick exactly.\n * The floor of six keeps every axis that was already exact bit for bit what it was,\n * and keeps a step no rung divides — a third, centred — at the six it always had.\n */\nfunction tickDigits(step: number): number {\n return Math.min(15, Math.max(6, Math.ceil(-Math.log10(step)) + 2));\n}\n\n/**\n * The `symmetric` axis for data with no span: the value in the MIDDLE, as a tick of\n * its own, with one step either side.\n *\n * Snapped outward, a flat range keeps its value inside the frame but not at its\n * centre: a lone 120 lands on an axis from 100 to 150, two fifths of the way up. The\n * step here is the largest rung of the same ladder that is at most a quarter of the\n * value and divides it exactly, so all three ticks are round: 100 / 120 / 140,\n * 4 / 5 / 6, 1234 / 1234.5 / 1235. Zero has no magnitude to take a quarter of, and\n * reads −1 / 0 / 1; a value no rung divides within twelve decades takes a quarter\n * of itself.\n */\nfunction centredAxis(value: number): WrChartAxis {\n const magnitude = Math.abs(value);\n let step = magnitude === 0 ? 1 : magnitude / 4;\n if (magnitude > 0) {\n const top = Math.ceil(Math.log10(magnitude / 4));\n search: for (let exponent = top; exponent > top - 12; exponent--) {\n for (const rung of LADDER) {\n const candidate = rung * 10 ** exponent;\n if (candidate > magnitude / 4) continue;\n const ratio = value / candidate;\n if (Math.abs(ratio - Math.round(ratio)) < 1e-9) {\n step = candidate;\n break search;\n }\n }\n }\n }\n const digits = tickDigits(step);\n return {\n min: value - step,\n max: value + step,\n step,\n ticks: [wrRound(value + step, digits), value, wrRound(value - step, digits)],\n };\n}\n\n/**\n * The smallest 1 / 2 / 2.5 / 5 × 10ⁿ at or above `raw` — the conventional\n * nice-number ladder every plotting library uses to pick an axis step.\n *\n * `2.5` earns its place on the small end: without it a span that wants a step\n * of 2.1 jumps to 5 and the axis loses half its labels.\n */\nexport function niceStep(raw: number): number {\n if (!Number.isFinite(raw) || raw <= 0) return 1;\n const magnitude = 10 ** Math.floor(Math.log10(raw));\n const normalised = raw / magnitude;\n const nice = normalised <= 1 ? 1 : normalised <= 2 ? 2 : normalised <= 2.5 ? 2.5 : normalised <= 5 ? 5 : 10;\n return nice * magnitude;\n}\n\n/**\n * A value axis for data running from `min` to `max`, SNAPPED to a readable step —\n * and the snapping is the point.\n *\n * The line chart's axis used to be \"the data's max plus 10%, divided into four\",\n * which lands on a round number almost never: seven integers between 3 and 35 gave\n * an axis reading 38.2 / 28.7 / 19.1 / 9.6 / 0. A chart's axis is the one part of it\n * a reader is supposed to do arithmetic against.\n *\n * So the step is rounded UP to the nearest 1, 2, 2.5 or 5 times a power of ten —\n * the conventional nice-number ladder — and the bounds are then snapped outward to\n * whole multiples of it. The same 3..35 reads 0 / 10 / 20 / 30 / 40. Snapping\n * outward replaces the old 10% padding, and where the peak still lands exactly on\n * the top it is lifted a step, since a line that ends on the frame reads as clipped.\n * `symmetric` does the same at the bottom.\n *\n * A flat range has no span to divide, so it is given its own magnitude as one (or 1,\n * at zero). With `symmetric` it is centred instead: the value is the middle of three\n * ticks, a round step on either side, whatever `tickCount` asks for. Non-finite\n * bounds, the `Math.min()` / `Math.max()` of no data, give the empty frame from 0 to\n * 1. Bounds handed in the wrong order are swapped.\n *\n * The line chart's own rule, which floors its axis at zero and never lifts it to\n * zero from below, is `wrChartAxis(Math.min(0, min), max)`: an all-negative series\n * keeps an axis that ends just above its peak. `includeZero` is the other reading,\n * zero inside the range on either side, which an area needs for its baseline.\n *\n * @internal\n */\nexport function wrChartAxis(min: number, max: number, options: WrChartAxisOptions = {}): WrChartAxis {\n if (!Number.isFinite(min) || !Number.isFinite(max)) return EMPTY;\n const dataLo = Math.min(min, max);\n const dataHi = Math.max(min, max);\n const lo = options.includeZero ? Math.min(0, dataLo) : dataLo;\n const hi = options.includeZero ? Math.max(0, dataHi) : dataHi;\n // A scale with no baseline has no reason to put a lone value anywhere but the middle.\n if (options.symmetric && lo === hi) return centredAxis(lo);\n\n const count = options.tickCount !== undefined && options.tickCount >= 1 ? Math.round(options.tickCount) : TICK_COUNT;\n // A flat series has no span to divide, so give it one rather than a zero step.\n const span = hi - lo || Math.abs(hi) || 1;\n const step = niceStep(span / count);\n // A quotient a hair off a whole number (0.3 / 0.025 is 11.999999999999998) is that number.\n const snap = (value: number): number => {\n const q = value / step;\n return Math.abs(q - Math.round(q)) <= 1e-9 * Math.max(1, Math.abs(q)) ? Math.round(q) : q;\n };\n const near = (a: number, b: number): boolean => Math.abs(a - b) <= step * 1e-9;\n let bottomStep = Math.floor(snap(lo));\n let topStep = Math.ceil(snap(hi));\n // The data's peak sitting exactly on the frame reads as clipped, so lift the\n // ceiling by one step when the snap did not already do it. Measured against the\n // DATA, so a zero that only `includeZero` put at the top is not lifted: nothing\n // sits on it. `symmetric` holds the bottom to the same rule.\n if (near(topStep * step, dataHi)) topStep += 1;\n if (options.symmetric && near(bottomStep * step, dataLo)) bottomStep -= 1;\n const bottom = bottomStep * step;\n const top = topStep * step;\n\n // Floating-point: 0.1 + 0.2 walks past an exact bound, so count in integers and\n // multiply, and stop on the count rather than on `value >= min`.\n const digits = tickDigits(step);\n const gaps = Math.round((top - bottom) / step);\n const ticks: number[] = [];\n for (let i = 0; i <= gaps; i++) ticks.push(wrRound(top - i * step, digits));\n return { min: bottom, max: top, step, ticks };\n}\n","/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { Component, type Signal, ViewEncapsulation, computed, input } from '@angular/core';\n\nimport { useI18nText } from 'ngwr/i18n';\n\n/**\n * What a chart shows in place of its marks.\n *\n * @internal\n */\nexport type WrChartStateKind = 'empty' | 'loading' | 'error';\n\n/**\n * The state a chart is in, with the message it shows for it.\n *\n * @internal\n */\nexport interface WrChartStateView {\n readonly kind: WrChartStateKind;\n readonly label: string;\n}\n\n/**\n * The inputs a chart hands {@link useChartState}.\n *\n * @internal\n */\nexport interface WrChartStateOptions {\n /** The chart's `loading` input. */\n readonly loading: Signal<boolean>;\n /** The chart's `error` input. */\n readonly error: Signal<boolean>;\n /** Whether the chart has nothing to draw. */\n readonly empty: Signal<boolean>;\n /** The chart's `emptyLabel`, `loadingLabel` and `errorLabel` inputs: `null` takes the catalog's. */\n readonly emptyLabel: Signal<string | null>;\n readonly loadingLabel: Signal<string | null>;\n readonly errorLabel: Signal<string | null>;\n}\n\n/**\n * The state a chart shows instead of its marks, or `null` while it draws them: loading\n * first, then a failed load, then no data. Each message is the chart's own `*Label`\n * input, then the catalog's `chart.loading` / `chart.error` / `chart.empty`, then\n * English. Call in an injection context.\n *\n * One rule for every chart, so a dashboard whose requests are in flight reads the same\n * in every tile, and a chart with no data is a framed \"No data\" rather than a blank box\n * of whatever height its markup collapses to.\n *\n * @internal\n */\nexport function useChartState(options: WrChartStateOptions): Signal<WrChartStateView | null> {\n const loading = useI18nText(options.loadingLabel, 'chart.loading', 'Loading…');\n const error = useI18nText(options.errorLabel, 'chart.error', 'Could not load');\n const empty = useI18nText(options.emptyLabel, 'chart.empty', 'No data');\n return computed<WrChartStateView | null>(() => {\n if (options.loading()) return { kind: 'loading', label: loading() };\n if (options.error()) return { kind: 'error', label: error() };\n if (options.empty()) return { kind: 'empty', label: empty() };\n return null;\n });\n}\n\n/**\n * The message a chart shows in place of its marks, centred over the frame it keeps.\n *\n * A live region: `role=\"status\"`, so a screen reader hears \"Loading…\" when a chart\n * starts a request and \"No data\" when it comes back with none, without the chart taking\n * focus. A failed load is `role=\"alert\"`, which interrupts, since it is the one of the\n * three a reader has to act on. The chart renders it inside the box its marks are drawn\n * in, which it positions; the grid and the axis under it stay.\n *\n * @example\n * ```html\n * @if (state(); as shown) {\n * <wr-chart-state [kind]=\"shown.kind\" [label]=\"shown.label\" />\n * }\n * ```\n *\n * @internal\n */\n@Component({\n selector: 'wr-chart-state',\n templateUrl: './chart-state.html',\n encapsulation: ViewEncapsulation.None,\n host: {\n class: 'wr-chart-state',\n '[class.wr-chart-state--empty]': \"kind() === 'empty'\",\n '[class.wr-chart-state--loading]': \"kind() === 'loading'\",\n '[class.wr-chart-state--error]': \"kind() === 'error'\",\n '[attr.role]': \"kind() === 'error' ? 'alert' : 'status'\",\n },\n})\nexport class WrChartState {\n /** Which of the three states this is. */\n readonly kind = input.required<WrChartStateKind>();\n\n /** The message, already translated. */\n readonly label = input.required<string>();\n}\n","<span class=\"wr-chart-state__plate\">\n @if (kind() === 'loading') {\n <!-- Decoration: the word beside it carries the state. -->\n <span class=\"wr-chart-state__spinner\" aria-hidden=\"true\"></span>\n }\n <span class=\"wr-chart-state__label\">{{ label() }}</span>\n</span>\n","/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { Component, ViewEncapsulation, computed, input } from '@angular/core';\n\nimport type { WrChartTableData } from './types';\n\n/**\n * The figures a chart draws, as a table that only assistive technology reaches.\n *\n * A chart's drawing is one named `role=\"img\"`, and `img` makes everything inside it\n * presentational: the name is announced and the numbers are nowhere a screen reader\n * can walk. This renders them as a real `<table>` — a caption, column headers, row\n * headers, and a `<tbody>` per group headed by a `<th scope=\"rowgroup\">` down its rows\n * — so a reader can move cell by cell and hear each value with its row and column.\n *\n * **Beside the image, never inside it.** Inside, `img` would hide it with the rest of\n * the drawing. A chart renders `<wr-chart-table>` as a sibling of the element that\n * carries `role=\"img\"`, and only while its `dataTable` input asks for it. **The chart's\n * host has to be positioned** (`position: relative`): the table is out of flow, and\n * against a static host it resolves to an ancestor outside the chart and keeps its place\n * in an unpositioned scroller's content, which grew one page by 1600px of blank scroll.\n *\n * **Hidden by clipping, not by `display` or `hidden`**, which would take it out of the\n * accessibility tree as well: the host is clipped to nothing and taken out of flow, so\n * it costs the chart no layout and still reads in full. The table inside keeps its own\n * layout, because a `<table>` will not shrink to a clip box of its own — it grows to\n * fit its cells whatever its width says. Nothing in it is focusable, so no tab stop\n * lands on something that cannot be seen.\n *\n * No ids: the headers are tied to their cells by `scope`, which needs none, and an id\n * minted on the server would not match the client's.\n *\n * @example\n * ```html\n * <div class=\"wr-line-chart__plot\" role=\"img\" [attr.aria-label]=\"label()\">…</div>\n * @if (dataTable()) {\n * <wr-chart-table [data]=\"table()\" />\n * }\n * ```\n *\n * @internal\n */\n@Component({\n selector: 'wr-chart-table',\n templateUrl: './chart-table.html',\n encapsulation: ViewEncapsulation.None,\n host: { class: 'wr-chart-table' },\n})\nexport class WrChartTable {\n /** The caption, the column headings and the rows, every string already written. */\n readonly data = input.required<WrChartTableData>();\n\n /** Whether any group is headed, which gives every row a leading group column. */\n protected readonly hasGroupHeaders = computed(() => this.data().groups.some(group => !!group.header));\n}\n","@let d = data();\n@let grouped = hasGroupHeaders();\n<!-- Every section is written out, `<thead>` and each `<tbody>` included: the HTML\n parser inserts a `<tbody>` the template left out, and hydration would then meet\n a tree it did not render. -->\n<table class=\"wr-chart-table__table\">\n <caption>\n {{\n d.caption\n }}\n </caption>\n <thead>\n <tr>\n <!-- Over the group headers' column, then the row headers' one. -->\n @if (grouped && !d.corner) {\n <td colspan=\"2\"></td>\n } @else {\n @if (grouped) {\n <td></td>\n }\n @if (d.corner) {\n <th scope=\"col\">{{ d.corner }}</th>\n } @else {\n <td></td>\n }\n }\n @for (column of d.columns; track $index) {\n <th scope=\"col\">{{ column }}</th>\n }\n </tr>\n </thead>\n @for (group of d.groups; track $index) {\n @if (group.rows.length > 0) {\n <tbody>\n @for (row of group.rows; track $index; let first = $first, count = $count) {\n <tr>\n <!-- The group's header in a column of its own, down every row of the group:\n the shape the HTML table algorithm and every checker read as heading the\n cells beside it. A full-width row above the group heads nothing by axe's\n reading. -->\n @if (grouped && first) {\n @if (group.header) {\n <th scope=\"rowgroup\" [attr.rowspan]=\"count\">{{ group.header }}</th>\n } @else {\n <td [attr.rowspan]=\"count\"></td>\n }\n }\n <th scope=\"row\">{{ row.header }}</th>\n @for (cell of row.cells; track $index) {\n <td>{{ cell }}</td>\n }\n </tr>\n }\n </tbody>\n }\n }\n</table>\n","/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { DestroyRef, ElementRef, type Signal, afterNextRender, afterRenderEffect, inject, signal } from '@angular/core';\n\nconst UNMEASURED: WrChartSize = { width: 0, height: 0 };\n\n/** What each observed element reports to, on the one observer every chart shares. */\nconst listeners = new WeakMap<Element, (size: WrChartSize) => void>();\n\n/** The marks {@link wrChartDim} lit last, per host, so the next call clears them without a scan. */\nconst litMarks = new WeakMap<Element, Element[]>();\n\nlet observer: ResizeObserver | null = null;\n\n/** The constructor `observer` was built with: a page has one, a test suite swaps it. */\nlet observerType: typeof ResizeObserver | null = null;\n\n/**\n * The box a chart measures, in px. Both are 0 until it is laid out.\n *\n * @internal\n */\nexport interface WrChartSize {\n readonly width: number;\n readonly height: number;\n}\n\n/**\n * Reports `element`'s content box to `listener` whenever it changes, through ONE\n * `ResizeObserver` for every chart on the page. Returns the function that stops it.\n *\n * Seven charts each made an observer of their own, so a dashboard of forty tiles ran\n * forty. An observer is built to watch many targets and delivers them in one callback\n * per frame. One listener per element: observing an element again replaces its listener.\n * Where there is no `ResizeObserver` (a server, an old test environment) nothing is\n * observed and the returned function does nothing.\n *\n * @internal\n */\nexport function wrChartObserveSize(element: Element, listener: (size: WrChartSize) => void): () => void {\n if (typeof ResizeObserver === 'undefined') return () => undefined;\n if (!observer || observerType !== ResizeObserver) {\n observerType = ResizeObserver;\n observer = new ResizeObserver(entries => {\n for (const entry of entries) {\n const { width, height } = entry.contentRect;\n listeners.get(entry.target)?.({ width, height });\n }\n });\n }\n const shared = observer;\n listeners.set(element, listener);\n shared.observe(element);\n return () => {\n listeners.delete(element);\n shared.unobserve(element);\n };\n}\n\n/**\n * The size of the element `target` holds, as a signal that follows it: `0 × 0` until the\n * element is rendered and laid out, and again once it is gone. On the shared observer of\n * {@link wrChartObserveSize}. Call in an injection context.\n *\n * @internal\n */\nexport function useChartSize(target: Signal<ElementRef<Element> | Element | undefined>): Signal<WrChartSize> {\n const size = signal<WrChartSize>(UNMEASURED);\n let stop: (() => void) | null = null;\n let observed: Element | null = null;\n\n afterRenderEffect(() => {\n const held = target();\n const element = held instanceof ElementRef ? held.nativeElement : (held ?? null);\n if (element === observed) return;\n stop?.();\n observed = element;\n stop = null;\n if (!element) {\n size.set(UNMEASURED);\n return;\n }\n stop = wrChartObserveSize(element, next => {\n const current = size();\n if (current.width !== next.width || current.height !== next.height) size.set(next);\n });\n });\n inject(DestroyRef).onDestroy(() => stop?.());\n return size.asReadonly();\n}\n\n/**\n * What {@link useChartHover} tells a chart.\n *\n * @internal\n */\nexport interface WrChartHoverHandlers {\n /** The pointer is over the section whose `data-wr-index` is `index`. Not repeated while it stays there. */\n enter(index: number): void;\n /** The pointer left the sections: for the chart's box, or for a part of it that is no section. */\n leave(event: MouseEvent): void;\n}\n\n/**\n * Dims every mark of `host` but the ones of series `key`, or none for `null`: the chart\n * takes `wr-chart--dim` and the series' own marks `wr-chart-mark--on`, and the shared\n * stylesheet fades the rest to `--wr-chart-dim`. A mark is anything carrying\n * `data-wr-series`, a legend row included.\n *\n * Classes set by hand rather than bound: a binding on every mark is re-evaluated for\n * every mark on each hover change, and this touches the marks of two series.\n *\n * @internal\n */\nexport function wrChartDim(host: Element, key: string | null): void {\n for (const mark of litMarks.get(host) ?? []) mark.classList.remove('wr-chart-mark--on');\n host.classList.toggle('wr-chart--dim', key !== null);\n if (key === null) {\n litMarks.delete(host);\n return;\n }\n const marks = [...host.querySelectorAll(`[data-wr-series=\"${CSS.escape(key)}\"]`)];\n for (const mark of marks) mark.classList.add('wr-chart-mark--on');\n litMarks.set(host, marks);\n}\n\n/**\n * A chart's hover, from ONE pair of listeners on its host however many sections it draws.\n *\n * A section is any element carrying `data-wr-index`: the listener finds the nearest one\n * above whatever the pointer is on and reports its index, once per section entered. A\n * listener pair on every bar was two per bar, and each one a change detection pass over\n * the whole chart for every bar the pointer crossed; these are native listeners, so a\n * move runs no pass at all unless the chart's own handler writes a signal.\n *\n * A gap the chart marks with `data-wr-hold` keeps the section and the dim as they are, so\n * crossing from one bar to the next does not close and reopen the tooltip; a section in\n * such an area takes `wr-chart-section--on`, so a band the chart paints on it stays too.\n *\n * It also drives the shared hover-dim: the nearest element carrying `data-wr-series`\n * names the series under the pointer, and {@link wrChartDim} fades the rest. Legend rows\n * carry the attribute too, so hovering a row dims the chart the same way.\n *\n * Registered after the first render, in the browser only. Call in an injection context.\n *\n * @internal\n */\nexport function useChartHover(handlers: WrChartHoverHandlers): void {\n const host = inject(ElementRef).nativeElement as HTMLElement;\n const destroyRef = inject(DestroyRef);\n let index: number | null = null;\n let series: string | null = null;\n\n const dim = (key: string | null): void => {\n if (key === series) return;\n series = key;\n wrChartDim(host, key);\n };\n\n let current: Element | null = null;\n const band = (section: Element | null): void => {\n current?.classList.remove('wr-chart-section--on');\n current = section?.closest('[data-wr-hold]') ? section : null;\n current?.classList.add('wr-chart-section--on');\n };\n\n const inHost = (el: Element | null | undefined): el is Element => !!el && host.contains(el);\n\n const over = (event: MouseEvent): void => {\n const target = event.target instanceof Element ? event.target : null;\n const section = target?.closest('[data-wr-index]');\n const series = target?.closest('[data-wr-series]');\n // In the room a chart holds open between its marks (`data-wr-hold`, the gaps between\n // its bars), the pointer is still on the drawing: what it last pointed at stays,\n // rather than closing and reopening a few pixels on.\n const held = !inHost(series) && inHost(target?.closest('[data-wr-hold]'));\n if (!held) dim(inHost(series) ? series.getAttribute('data-wr-series') : null);\n if (held && !inHost(section)) return;\n\n const next = inHost(section) ? Number(section.getAttribute('data-wr-index')) : null;\n if (next === index) return;\n index = next;\n if (next === null || !Number.isFinite(next)) {\n band(null);\n handlers.leave(event);\n } else {\n band(section ?? null);\n handlers.enter(next);\n }\n };\n\n const leave = (event: MouseEvent): void => {\n dim(null);\n if (index === null) return;\n index = null;\n band(null);\n handlers.leave(event);\n };\n\n afterNextRender(() => {\n host.addEventListener('mouseover', over);\n host.addEventListener('mouseleave', leave);\n destroyRef.onDestroy(() => {\n host.removeEventListener('mouseover', over);\n host.removeEventListener('mouseleave', leave);\n });\n });\n}\n","/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\n/**\n * The `limit` longest of `labels`, each once, longest first: the strings worth measuring.\n *\n * A chart sizes a gutter or keeps room past a bar from a hidden copy of the text that goes\n * there. Copying every label made ten thousand hidden spans for ten thousand bars, to learn\n * the width of one. The widest label is almost always among the longest few by character\n * count - a proportional font can put `1,111` under `999`, which is why this returns a few\n * and not one - so a chart renders these and reads the widest.\n *\n * @internal\n */\nexport function wrChartLongest(labels: readonly string[], limit = 3): string[] {\n const longest: string[] = [];\n for (const label of new Set(labels)) {\n if (longest.length === limit && label.length <= longest[longest.length - 1].length) continue;\n let at = longest.findIndex(kept => kept.length < label.length);\n if (at < 0) at = longest.length;\n longest.splice(at, 0, label);\n if (longest.length > limit) longest.pop();\n }\n return longest;\n}\n\n/**\n * How many categories each printed label stands for, so no two labels along an axis run\n * into each other: 1 while every label fits its own band, 2 to print every second one,\n * and so on.\n *\n * `extent` is the axis' length and `count` how many bands share it; `labelSize` is the\n * longest label along the axis, and `gap` the least room between two labels. All in the\n * same unit, px in practice. With nothing measured yet - a server render, a chart not\n * laid out - the answer is 1: every label, as the markup had before it was measured.\n *\n * @internal\n */\nexport function wrChartLabelStep(count: number, extent: number, labelSize: number, gap = 8): number {\n if (!(count > 1) || !(extent > 0) || !(labelSize > 0)) return 1;\n const band = extent / count;\n return Math.max(1, Math.min(count, Math.ceil((labelSize + gap) / band)));\n}\n","/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\n/**\n * Default series colours, in order: what a series, a slice or a segment with no\n * `color` of its own takes. Each is a token of the chart theme (`--wr-chart-1` to\n * `--wr-chart-8`, declared by `ngwr/charts/core`'s stylesheet), so an app retints\n * every chart by setting the tokens and a chart's markup never names a hex.\n *\n * The palette is not the status intents: a second series is not a success and a\n * fourth is not a danger. The first is the brand colour and the last the neutral\n * role; neighbours alternate between a deep and a mid tone, so two series next to\n * each other differ in lightness as well as in hue. The stylesheet carries the\n * measured contrast of each.\n *\n * A chart that draws lines still pairs each with a dash (`WR_CHART_DASHES`), and\n * one that draws points with a shape (`WR_CHART_MARKERS`): colour is never the\n * only thing that tells two series apart.\n *\n * @internal\n */\nexport const WR_CHART_PALETTE: readonly string[] = [\n 'var(--wr-chart-1)',\n 'var(--wr-chart-2)',\n 'var(--wr-chart-3)',\n 'var(--wr-chart-4)',\n 'var(--wr-chart-5)',\n 'var(--wr-chart-6)',\n 'var(--wr-chart-7)',\n 'var(--wr-chart-8)',\n];\n\n/**\n * The palette colour for the series at `index`, wrapping past the end.\n *\n * @internal\n */\nexport function wrChartColor(index: number): string {\n return WR_CHART_PALETTE[wrap(index, WR_CHART_PALETTE.length)];\n}\n\n/**\n * The series colours every chart took before the chart theme: four status intents and\n * the neutral role. Kept for the charts that have not moved onto `--wr-chart-*` yet,\n * so each keeps its look until it does; a chart on the theme reads\n * {@link WR_CHART_PALETTE}.\n *\n * `warning` measures 1.71:1 on a white surface, under the 3:1 a graphic needs, which\n * is one of the reasons the theme's palette replaced it.\n *\n * @internal\n */\nexport const WR_CHART_LEGACY_PALETTE: readonly string[] = [\n 'var(--wr-color-primary)',\n 'var(--wr-color-success)',\n 'var(--wr-color-warning)',\n 'var(--wr-color-danger)',\n 'var(--wr-color-on-surface-muted)',\n];\n\n/**\n * The {@link WR_CHART_LEGACY_PALETTE} colour for the series at `index`, wrapping past\n * the end.\n *\n * @internal\n */\nexport function wrChartLegacyColor(index: number): string {\n return WR_CHART_LEGACY_PALETTE[wrap(index, WR_CHART_LEGACY_PALETTE.length)];\n}\n\n/**\n * A dash pattern per series, so lines are told apart by SHAPE and not only by hue.\n *\n * A reader with red-green colour blindness can see two strokes of similar lightness\n * as one grey, and a legend that pairs a coloured dot with a name does not rescue it:\n * matching the dot to the line is exactly the step that needs hue. Distinguishing\n * series by dash is the standard remedy and the only one that survives greyscale,\n * printing and a monochrome display.\n *\n * The FIRST entry is solid on purpose. A single-series chart is the common case\n * and there is nothing to tell apart in it; the patterns only appear once a second\n * series does. Each value is an SVG `stroke-dasharray`, `''` meaning none.\n *\n * @internal\n */\nexport const WR_CHART_DASHES: readonly string[] = ['', '7 4', '2 3', '10 4 2 4', '1 4', '6 3 2 3'];\n\n/**\n * The dash pattern for the series at `index`, wrapping past the end.\n *\n * @internal\n */\nexport function wrChartDash(index: number): string {\n return WR_CHART_DASHES[wrap(index, WR_CHART_DASHES.length)];\n}\n\n/** `index` folded into `[0, length)`, negatives included, so a bad index still picks an entry. */\nexport function wrap(index: number, length: number): number {\n const i = Number.isFinite(index) ? Math.trunc(index) : 0;\n return ((i % length) + length) % length;\n}\n","/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { wrap } from './palette';\nimport type { WrChartMarkerExtent, WrChartMarkerShape } from './types';\n\n/** Half the side of a square with the area of a circle of radius 1: √π / 2. */\nconst SQUARE = Math.sqrt(Math.PI) / 2;\n\n/** Half the diagonal of that square, standing on a corner. */\nconst DIAMOND = SQUARE * Math.SQRT2;\n\n/** The side of an equilateral triangle with the area of a circle of radius 1: √(4π / √3). */\nconst TRIANGLE_SIDE = Math.sqrt((4 * Math.PI) / Math.sqrt(3));\n\n/** The distance from that triangle's centroid to a corner (two thirds of its height). */\nconst TRIANGLE_APEX = (TRIANGLE_SIDE * Math.sqrt(3)) / 3;\n\n/**\n * A plus with arms 0.35 of their length thick, half-length `L` and half-thickness\n * `0.35 L`, has an area of `8·0.35·L² − 4·0.35²·L²`; this is the `L` that makes it π.\n */\nconst CROSS_ARM = Math.sqrt(Math.PI / (8 * 0.35 - 4 * 0.35 ** 2));\nconst CROSS_THICKNESS = CROSS_ARM * 0.35;\n\n/**\n * How far each shape reaches from its centre at `r = 1`, read off the corners\n * {@link wrChartMarkerPath} draws: up, down, to either side, and to the farthest\n * corner.\n */\nconst EXTENTS: Readonly<Record<WrChartMarkerShape, WrChartMarkerExtent>> = {\n circle: { top: 1, bottom: 1, side: 1, radius: 1 },\n square: { top: SQUARE, bottom: SQUARE, side: SQUARE, radius: SQUARE * Math.SQRT2 },\n diamond: { top: DIAMOND, bottom: DIAMOND, side: DIAMOND, radius: DIAMOND },\n triangle: { top: TRIANGLE_APEX, bottom: TRIANGLE_APEX / 2, side: TRIANGLE_SIDE / 2, radius: TRIANGLE_APEX },\n 'triangle-down': { top: TRIANGLE_APEX / 2, bottom: TRIANGLE_APEX, side: TRIANGLE_SIDE / 2, radius: TRIANGLE_APEX },\n cross: { top: CROSS_ARM, bottom: CROSS_ARM, side: CROSS_ARM, radius: Math.hypot(CROSS_ARM, CROSS_THICKNESS) },\n};\n\n/** A coordinate to three decimals, without trailing zeros, so a path stays short. */\nconst n = (value: number): string => String(Math.round(value * 1000) / 1000 || 0);\n\n/** `M x y L … Z` through the given corners. */\nconst polygon = (points: readonly (readonly [number, number])[]): string =>\n `M ${points.map(([x, y]) => `${n(x)} ${n(y)}`).join(' L ')} Z`;\n\n/**\n * A marker shape per series, so points are told apart by SHAPE and not only by\n * hue — the dash list's job, for a chart that draws points rather than lines.\n *\n * The circle comes first for the reason the solid dash does: a single-series chart\n * has nothing to tell apart. The order then alternates corners and points, so two\n * neighbouring series never differ by a rotation alone (a square beside a diamond\n * is the pair a small marker blurs into one).\n *\n * @internal\n */\nexport const WR_CHART_MARKERS: readonly WrChartMarkerShape[] = [\n 'circle',\n 'square',\n 'triangle',\n 'diamond',\n 'cross',\n 'triangle-down',\n];\n\n/**\n * The marker shape for the series at `index`, wrapping past the end.\n *\n * @internal\n */\nexport function wrChartMarker(index: number): WrChartMarkerShape {\n return WR_CHART_MARKERS[wrap(index, WR_CHART_MARKERS.length)];\n}\n\n/**\n * The SVG path `d` of a marker centred on the origin, as large as a circle of\n * radius `r` — every shape has that circle's area, so a triangle reaches past it\n * and a square stays inside it, and the eye weighs them the same.\n *\n * Drawn about the origin so a chart can place it with a `transform`, or inside a\n * nested `<svg x y overflow=\"visible\">`, and size it in pixels whatever the plot's\n * own scale. A non-finite or negative `r` draws nothing rather than a path of\n * `NaN`.\n *\n * @internal\n */\nexport function wrChartMarkerPath(shape: WrChartMarkerShape, r: number): string {\n if (!Number.isFinite(r) || r <= 0) return '';\n switch (shape) {\n case 'square': {\n const h = r * SQUARE;\n return polygon([\n [-h, -h],\n [h, -h],\n [h, h],\n [-h, h],\n ]);\n }\n case 'diamond': {\n const d = r * DIAMOND;\n return polygon([\n [0, -d],\n [d, 0],\n [0, d],\n [-d, 0],\n ]);\n }\n case 'triangle':\n case 'triangle-down': {\n // Centred on the centroid, not on the box, so a triangle sits on the same\n // point a circle would.\n const flip = shape === 'triangle' ? 1 : -1;\n const apex = r * TRIANGLE_APEX;\n const half = (r * TRIANGLE_SIDE) / 2;\n return polygon([\n [0, -apex * flip],\n [half, (apex / 2) * flip],\n [-half, (apex / 2) * flip],\n ]);\n }\n case 'cross': {\n const a = r * CROSS_ARM;\n const t = r * CROSS_THICKNESS;\n return polygon([\n [-t, -a],\n [t, -a],\n [t, -t],\n [a, -t],\n [a, t],\n [t, t],\n [t, a],\n [-t, a],\n [-t, t],\n [-a, t],\n [-a, -t],\n [-t, -t],\n ]);\n }\n case 'circle':\n default:\n // Two arcs, since one arc from a point back to itself draws nothing.\n return `M ${n(-r)} 0 A ${n(r)} ${n(r)} 0 1 0 ${n(r)} 0 A ${n(r)} ${n(r)} 0 1 0 ${n(-r)} 0 Z`;\n }\n}\n\n/**\n * How far the marker {@link wrChartMarkerPath} draws at `r` reaches from its centre,\n * in px, before any stroke: up, down, to either side, and to its farthest corner.\n *\n * Every shape has the circle's AREA, so `r` is not how far a marker reaches: a\n * triangle's point stands 1.56 r above its centroid, a diamond's tips 1.25 r out\n * and a cross's corners 1.24 r, while a square's sides sit 0.89 r in. A box, a hit\n * area or a margin sized by `r` alone cuts the tips off. A non-finite or negative\n * `r` reaches nowhere, as it draws nothing.\n *\n * @internal\n */\nexport function wrChartMarkerExtent(shape: WrChartMarkerShape, r: number): WrChartMarkerExtent {\n const size = Number.isFinite(r) && r > 0 ? r : 0;\n const unit = EXTENTS[shape] ?? EXTENTS.circle;\n return { top: unit.top * size, bottom: unit.bottom * size, side: unit.side * size, radius: unit.radius * size };\n}\n","/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { LOCALE_ID, type Signal, inject } from '@angular/core';\n\nimport { wrClamp } from 'ngwr/utils';\n\nimport type { WrChartNumbers } from './types';\n\n/**\n * The fewest fraction digits that write `value` exactly, up to six: the precision of a\n * step no power of ten divides, such as the third a flat range is centred with.\n */\nfunction fractionDigits(value: number): number {\n for (let d = 0; d <= 6; d++) if (Math.abs(value * 10 ** d - Math.round(value * 10 ** d)) < 1e-9) return d;\n return 6;\n}\n\n/** The power of ten of `value`'s leading digit: 2 for 750, -2 for 0.025. */\nfunction magnitude(value: number): number {\n const abs = Math.abs(value);\n let m = Math.floor(Math.log10(abs));\n // `log10` is a float: guard the exact powers of ten from landing one off.\n if (10 ** (m + 1) <= abs) m++;\n if (10 ** m > abs) m--;\n return m;\n}\n\n/**\n * The power of ten of `step`'s LAST significant digit: 1 for 250, -1 for 2.5. Every tick\n * is a whole multiple of the step, so no tick has a digit below it, and a tick written to\n * that digit is written exactly.\n */\nfunction lastDigit(step: number): number {\n for (let e = magnitude(step); e > -21; e--) {\n const scaled = step / 10 ** e;\n if (Math.abs(scaled - Math.round(scaled)) < 1e-6) return e;\n }\n return -21;\n}\n\n/** Every formatter the charts have asked for, by locale and options. */\nconst FORMATTERS = new Map<string, Intl.NumberFormat>();\n\n/**\n * The `Intl.NumberFormat` for `locale` and `options`, built once for the page and shared\n * by every chart on it.\n *\n * Building one costs about a tenth of a millisecond, and the charts built them freely:\n * three per chart instance, and one per tick on every pass over an axis, so a table of a\n * hundred sparklines paid for three hundred identical formatters. A formatter holds no\n * state, so one per distinct key serves them all. The key is the locale and the options\n * in the order given; the charts ask with a handful of shapes, so the map stays small.\n *\n * @internal\n */\nexport function wrChartNumberFormat(locale: string, options?: Intl.NumberFormatOptions): Intl.NumberFormat {\n const key = options ? `${locale}|${JSON.stringify(options)}` : locale;\n let format = FORMATTERS.get(key);\n if (!format) {\n format = new Intl.NumberFormat(locale, options);\n FORMATTERS.set(key, format);\n }\n return format;\n}\n\n/**\n * The number writers of one chart: its axis ticks, the labels it prints in tight\n * spaces, and the figures of its tooltip and its accessible names — every one\n * through the chart's `valueFormat` when it has one, else through `Intl` in\n * `locale`.\n *\n * Seven charts kept their own copy of the `Intl` half until 15.1, each with the\n * same two formatters and the same `formatValue`, and the line chart a second,\n * axis-wide copy for its ticks. The rules are theirs, unchanged:\n *\n * - `value` is never compact, and is `Intl`'s default otherwise: up to three\n * fraction digits, and below one three SIGNIFICANT digits, since three fraction\n * digits write a reading of 0.0004 as `0`. It is not the exact figure: 1.08345\n * is `1.083`, and an axis stepping by 0.00025 is finer than it. A chart that has\n * to write a figure to a known precision asks `exact`.\n * - `label` is compact from a thousand up, where a bar is too narrow for\n * `1,234,567`, and below a thousand it is `value`: compact rounding would print\n * 12.5 as `13`, and there is nothing to abbreviate.\n * - `ticks` is decided for the AXIS. Compact, through `Intl` (`1.2K`, `3.4M`,\n * `4 Mio.`, `5 тыс.`), with each tick to exactly the significant digits the step\n * needs — a fixed count printed 1250 beside 1000 as `1.3k` and `1k` on an axis\n * stepping by 250. And when abbreviating would make the labels LONGER (a fine\n * step on large numbers, where `-1.025K` is wider than `-1,025`) the whole axis\n * is written in full instead, so no axis mixes `-1K` with `-1,025`. Written in\n * full, a tick has as many fraction digits as the step's last digit needs, however\n * fine: they stopped at six, so an axis stepping by 2.5e-7 printed `0.000013` twice.\n * - `exact` writes a figure to a precision the chart decides — the step of its axis,\n * a price's tick size — never compact, through `valueFormat` when there is one.\n *\n * `valueFormat` takes whatever extra arguments the chart passes it, so a chart can\n * tell its formatter which axis a number is for while a `(value) => string`\n * written for another chart still fits. Call in an injection context: `locale`\n * defaults to `LOCALE_ID`.\n *\n * @internal\n */\nexport function useChartNumbers<A extends readonly unknown[] = []>(\n valueFormat: Signal<((value: number, ...args: A) => string) | null | undefined>,\n locale: string = inject(LOCALE_ID)\n): WrChartNumbers<A> {\n const numbers = wrChartNumberFormat(locale);\n /** Below one, by significant digits, which keep 0.0004 from rounding to `0`. */\n const smallNumbers = wrChartNumberFormat(locale, { maximumSignificantDigits: 3 });\n const compactNumbers = wrChartNumberFormat(locale, { notation: 'compact' });\n\n const value = (v: number, ...args: A): string => {\n const custom = valueFormat();\n if (custom) return custom(v, ...args);\n return (v !== 0 && Math.abs(v) < 1 ? smallNumbers : numbers).format(v);\n };\n\n const label = (v: number, ...args: A): string => {\n if (valueFormat() || Math.abs(v) < 1000) return value(v, ...args);\n return compactNumbers.format(v);\n };\n\n const ticks = (values: readonly number[], step: number, ...args: A): string[] => {\n const custom = valueFormat();\n if (custom) return values.map(v => custom(v, ...args));\n if (values.length === 0) return [];\n\n const last = lastDigit(step);\n // A CEILING rather than a fixed count, so trailing zeros are dropped: a 0.25 step\n // wants two digits on 0.25 and none on 1, and `1.00` beside `0.25` reads as\n // spurious precision. Down to the step's last digit, however fine — the six digits\n // `fractionDigits` stops at printed a 2.5e-7 step as `0.000013` twice, and called\n // a step below 1e-9 whole. A step with no last digit (a third) keeps those six.\n const digits = last <= -21 ? fractionDigits(step) : wrClamp(-last, 0, 20);\n const full = wrChartNumberFormat(locale, { maximumFractionDigits: digits });\n const plain = values.map(v => full.format(v));\n const compact = values.map(v =>\n v === 0\n ? full.format(0)\n : wrChartNumberFormat(locale, {\n notation: 'compact',\n maximumSignificantDigits: wrClamp(magnitude(v) - last + 1, 1, 21),\n }).format(v)\n );\n const longest = (labels: readonly string[]): number => Math.max(...labels.map(text => text.length));\n return longest(compact) <= longest(plain) ? compact : plain;\n };\n\n const exact = (v: number, fractionDigits: number, ...args: A): string => {\n const custom = valueFormat();\n if (custom) return custom(v, ...args);\n const digits = Number.isFinite(fractionDigits) ? wrClamp(Math.round(fractionDigits), 0, 20) : 3;\n return wrChartNumberFormat(locale, { maximumFractionDigits: digits }).format(v);\n };\n\n return { value, label, ticks, exact };\n}\n","/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\n/**\n * `value` rounded to `digits` decimals for an inline style or an SVG attribute, with\n * `-0` folded to `0`: a share of an axis, a percentage, a coordinate.\n *\n * Eleven charts each kept a copy of this under another name (`short`, `percent`,\n * `fixed`), at three precisions. A written geometry value wants few digits - every one\n * past the fourth is bytes in the DOM and a different string for the same pixel - and\n * never `-0`, which `Math.round` produces for a small negative and which prints as `-0`.\n *\n * Not `wrRound` from `ngwr/utils`, which nudges by `Number.EPSILON` to round a decimal\n * tie the way a person expects and keeps the sign of a zero.\n *\n * @internal\n */\nexport function wrChartRound(value: number, digits = 4): number {\n const factor = 10 ** digits;\n return Math.round(value * factor) / factor || 0;\n}\n"],"mappings":";;;;;;;;;;AAYA,MAAM,aAAa;AAGnB,MAAM,QAAqB;CAAE,KAAK;CAAG,KAAK;CAAG,MAAM;CAAM,OAAO;EAAC;EAAG;EAAM;EAAK;EAAM;CAAC;AAAC;AAGvF,MAAM,SAAS;CAAC;CAAG;CAAK;CAAM;AAAG;AAejC,SAAS,WAAW,MAAY;CAC9B,OAAO,KAAK,IAAI,IAAI,KAAK,IAAI,GAAG,KAAK,KAAK,CAAC,KAAK,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC;AACnE;AAcA,SAAS,YAAY,OAAa;CAChC,MAAM,YAAY,KAAK,IAAI,KAAK;CAChC,IAAI,OAAO,cAAc,IAAI,IAAI,YAAY;CAC7C,IAAI,YAAY,GAAG;EACjB,MAAM,MAAM,KAAK,KAAK,KAAK,MAAM,YAAY,CAAC,CAAC;EAC/C,QAAQ,KAAK,IAAI,WAAW,KAAK,WAAW,MAAM,IAAI,YACpD,KAAK,MAAM,QAAQ,QAAQ;GACzB,MAAM,YAAY,OAAO,MAAM;GAC/B,IAAI,YAAY,YAAY,GAAG;GAC/B,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AAA,CAAC,CAAC,OAAO,CAAC,CAAC;EAElB,MAAM,WAAW,WAAsC,KAAK,IAAI,GAAG,OAAO,KAAI,SAAQ,KAAK,MAAM,CAAC;EAClG,OAAO,QAAQ,OAAO,KAAK,QAAQ,KAAK,IAAI,UAAU;CACxD;CAEA,MAAM,SAAS,GAAW,gBAAwB,GAAG,SAAmB;EACtE,MAAM,SAAS,YAAW;EAC1B,IAAI,QAAQ,OAAO,OAAO,GAAG,GAAG,IAAI;EAEpC,OAAO,oBAAoB,QAAQ,EAAE,uBADtB,OAAO,SAAS,cAAc,IAAI,QAAQ,KAAK,MAAM,cAAc,GAAG,GAAG,EAAE,IAAI,EAC5B,CAAE,CAAC,CAAC,OAAO,CAAC;CAChF;CAEA,OAAO;EAAE;EAAO;EAAO;EAAO;CAAK;AACrC;;;;;;;AC3IA,SAAgB,aAAa,OAAe,SAAS,GAAC;CACpD,MAAM,SAAS,MAAM;CACrB,OAAO,KAAK,MAAM,QAAQ,MAAM,IAAI,UAAU;AAChD"}
|
|
1
|
+
{"version":3,"file":"ngwr-charts-core.mjs","names":[],"sources":["../../../projects/lib/charts/core/axis.ts","../../../projects/lib/charts/core/chart-state.ts","../../../projects/lib/charts/core/chart-state.html","../../../projects/lib/charts/core/chart-table.ts","../../../projects/lib/charts/core/chart-table.html","../../../projects/lib/charts/core/interaction.ts","../../../projects/lib/charts/core/labels.ts","../../../projects/lib/charts/core/palette.ts","../../../projects/lib/charts/core/markers.ts","../../../projects/lib/charts/core/numbers.ts","../../../projects/lib/charts/core/round.ts"],"sourcesContent":["/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { wrRound } from 'ngwr/utils';\n\nimport type { WrChartAxis, WrChartAxisOptions } from './types';\n\n/** How many gaps an axis aims for by default. Five labels, four gaps. */\nconst TICK_COUNT = 4;\n\n/** The axis drawn when there is no data to fit: 0 to 1 in quarters, the line chart's empty frame. */\nconst EMPTY: WrChartAxis = { min: 0, max: 1, step: 0.25, ticks: [1, 0.75, 0.5, 0.25, 0] };\n\n/** The rungs of the {@link niceStep} ladder within one decade, from the top: 1, 0.5, 0.25 and 0.2 of it. */\nconst LADDER = [1, 0.5, 0.25, 0.2] as const;\n\n/**\n * How many fraction digits a tick on an axis stepping by `step` is rounded to: two past\n * the step's own leading digit, and never fewer than six or more than fifteen.\n *\n * It was a fixed six, which cannot write a tick finer than a millionth: an axis stepping\n * by 2.5e-7 — a micro-priced asset — came back as five ticks of `0.000013` and\n * `0.000012`, one stepping by 5e-10 as five zeros, and one stepping by 2.5e-6 put two of\n * its gridlines at the wrong height. Every tick is a whole multiple of the step, whose\n * last digit is at most one place past its leading one (2.5, and 0.25 on the\n * centred axis' ladder, two), so two past the leading digit writes every tick exactly.\n * The floor of six keeps every axis that was already exact bit for bit what it was,\n * and keeps a step no rung divides — a third, centred — at the six it always had.\n */\nfunction tickDigits(step: number): number {\n return Math.min(15, Math.max(6, Math.ceil(-Math.log10(step)) + 2));\n}\n\n/**\n * The `symmetric` axis for data with no span: the value in the MIDDLE, as a tick of\n * its own, with one step either side.\n *\n * Snapped outward, a flat range keeps its value inside the frame but not at its\n * centre: a lone 120 lands on an axis from 100 to 150, two fifths of the way up. The\n * step here is the largest rung of the same ladder that is at most a quarter of the\n * value and divides it exactly, so all three ticks are round: 100 / 120 / 140,\n * 4 / 5 / 6, 1234 / 1234.5 / 1235. Zero has no magnitude to take a quarter of, and\n * reads −1 / 0 / 1; a value no rung divides within twelve decades takes a quarter\n * of itself.\n */\nfunction centredAxis(value: number): WrChartAxis {\n const magnitude = Math.abs(value);\n let step = magnitude === 0 ? 1 : magnitude / 4;\n if (magnitude > 0) {\n const top = Math.ceil(Math.log10(magnitude / 4));\n search: for (let exponent = top; exponent > top - 12; exponent--) {\n for (const rung of LADDER) {\n const candidate = rung * 10 ** exponent;\n if (candidate > magnitude / 4) continue;\n const ratio = value / candidate;\n if (Math.abs(ratio - Math.round(ratio)) < 1e-9) {\n step = candidate;\n break search;\n }\n }\n }\n }\n const digits = tickDigits(step);\n return {\n min: value - step,\n max: value + step,\n step,\n ticks: [wrRound(value + step, digits), value, wrRound(value - step, digits)],\n };\n}\n\n/**\n * The smallest 1 / 2 / 2.5 / 5 × 10ⁿ at or above `raw` — the conventional\n * nice-number ladder every plotting library uses to pick an axis step.\n *\n * `2.5` earns its place on the small end: without it a span that wants a step\n * of 2.1 jumps to 5 and the axis loses half its labels.\n */\nexport function niceStep(raw: number): number {\n if (!Number.isFinite(raw) || raw <= 0) return 1;\n const magnitude = 10 ** Math.floor(Math.log10(raw));\n const normalised = raw / magnitude;\n const nice = normalised <= 1 ? 1 : normalised <= 2 ? 2 : normalised <= 2.5 ? 2.5 : normalised <= 5 ? 5 : 10;\n return nice * magnitude;\n}\n\n/**\n * A value axis for data running from `min` to `max`, SNAPPED to a readable step —\n * and the snapping is the point.\n *\n * The line chart's axis used to be \"the data's max plus 10%, divided into four\",\n * which lands on a round number almost never: seven integers between 3 and 35 gave\n * an axis reading 38.2 / 28.7 / 19.1 / 9.6 / 0. A chart's axis is the one part of it\n * a reader is supposed to do arithmetic against.\n *\n * So the step is rounded UP to the nearest 1, 2, 2.5 or 5 times a power of ten —\n * the conventional nice-number ladder — and the bounds are then snapped outward to\n * whole multiples of it. The same 3..35 reads 0 / 10 / 20 / 30 / 40. Snapping\n * outward replaces the old 10% padding, and where the peak still lands exactly on\n * the top it is lifted a step, since a line that ends on the frame reads as clipped.\n * `symmetric` does the same at the bottom.\n *\n * A flat range has no span to divide, so it is given its own magnitude as one (or 1,\n * at zero). With `symmetric` it is centred instead: the value is the middle of three\n * ticks, a round step on either side, whatever `tickCount` asks for. Non-finite\n * bounds, the `Math.min()` / `Math.max()` of no data, give the empty frame from 0 to\n * 1. Bounds handed in the wrong order are swapped.\n *\n * The line chart's own rule, which floors its axis at zero and never lifts it to\n * zero from below, is `wrChartAxis(Math.min(0, min), max)`: an all-negative series\n * keeps an axis that ends just above its peak. `includeZero` is the other reading,\n * zero inside the range on either side, which an area needs for its baseline.\n *\n * @internal\n */\nexport function wrChartAxis(min: number, max: number, options: WrChartAxisOptions = {}): WrChartAxis {\n if (!Number.isFinite(min) || !Number.isFinite(max)) return EMPTY;\n const dataLo = Math.min(min, max);\n const dataHi = Math.max(min, max);\n const lo = options.includeZero ? Math.min(0, dataLo) : dataLo;\n const hi = options.includeZero ? Math.max(0, dataHi) : dataHi;\n // A scale with no baseline has no reason to put a lone value anywhere but the middle.\n if (options.symmetric && lo === hi) return centredAxis(lo);\n\n const count = options.tickCount !== undefined && options.tickCount >= 1 ? Math.round(options.tickCount) : TICK_COUNT;\n // A flat series has no span to divide, so give it one rather than a zero step.\n const span = hi - lo || Math.abs(hi) || 1;\n const step = niceStep(span / count);\n // A quotient a hair off a whole number (0.3 / 0.025 is 11.999999999999998) is that number.\n const snap = (value: number): number => {\n const q = value / step;\n return Math.abs(q - Math.round(q)) <= 1e-9 * Math.max(1, Math.abs(q)) ? Math.round(q) : q;\n };\n const near = (a: number, b: number): boolean => Math.abs(a - b) <= step * 1e-9;\n let bottomStep = Math.floor(snap(lo));\n let topStep = Math.ceil(snap(hi));\n // The data's peak sitting exactly on the frame reads as clipped, so lift the\n // ceiling by one step when the snap did not already do it. Measured against the\n // DATA, so a zero that only `includeZero` put at the top is not lifted: nothing\n // sits on it. `symmetric` holds the bottom to the same rule.\n if (near(topStep * step, dataHi)) topStep += 1;\n if (options.symmetric && near(bottomStep * step, dataLo)) bottomStep -= 1;\n const bottom = bottomStep * step;\n const top = topStep * step;\n\n // Floating-point: 0.1 + 0.2 walks past an exact bound, so count in integers and\n // multiply, and stop on the count rather than on `value >= min`.\n const digits = tickDigits(step);\n const gaps = Math.round((top - bottom) / step);\n const ticks: number[] = [];\n for (let i = 0; i <= gaps; i++) ticks.push(wrRound(top - i * step, digits));\n return { min: bottom, max: top, step, ticks };\n}\n","/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { Component, type Signal, ViewEncapsulation, computed, input } from '@angular/core';\n\nimport { useI18nText } from 'ngwr/i18n';\n\n/**\n * What a chart shows in place of its marks.\n *\n * @internal\n */\nexport type WrChartStateKind = 'empty' | 'loading' | 'error';\n\n/**\n * The state a chart is in, with the message it shows for it.\n *\n * @internal\n */\nexport interface WrChartStateView {\n readonly kind: WrChartStateKind;\n readonly label: string;\n}\n\n/**\n * The inputs a chart hands {@link useChartState}.\n *\n * @internal\n */\nexport interface WrChartStateOptions {\n /** The chart's `loading` input. */\n readonly loading: Signal<boolean>;\n /** The chart's `error` input. */\n readonly error: Signal<boolean>;\n /** Whether the chart has nothing to draw. */\n readonly empty: Signal<boolean>;\n /** The chart's `emptyLabel`, `loadingLabel` and `errorLabel` inputs: `null` takes the catalog's. */\n readonly emptyLabel: Signal<string | null>;\n readonly loadingLabel: Signal<string | null>;\n readonly errorLabel: Signal<string | null>;\n}\n\n/**\n * The state a chart shows instead of its marks, or `null` while it draws them: loading\n * first, then a failed load, then no data. Each message is the chart's own `*Label`\n * input, then the catalog's `chart.loading` / `chart.error` / `chart.empty`, then\n * English. Call in an injection context.\n *\n * One rule for every chart, so a dashboard whose requests are in flight reads the same\n * in every tile, and a chart with no data is a framed \"No data\" rather than a blank box\n * of whatever height its markup collapses to.\n *\n * @internal\n */\nexport function useChartState(options: WrChartStateOptions): Signal<WrChartStateView | null> {\n const loading = useI18nText(options.loadingLabel, 'chart.loading', 'Loading…');\n const error = useI18nText(options.errorLabel, 'chart.error', 'Could not load');\n const empty = useI18nText(options.emptyLabel, 'chart.empty', 'No data');\n return computed<WrChartStateView | null>(() => {\n if (options.loading()) return { kind: 'loading', label: loading() };\n if (options.error()) return { kind: 'error', label: error() };\n if (options.empty()) return { kind: 'empty', label: empty() };\n return null;\n });\n}\n\n/**\n * The message a chart shows in place of its marks, centred over the frame it keeps.\n *\n * A live region: `role=\"status\"`, so a screen reader hears \"Loading…\" when a chart\n * starts a request and \"No data\" when it comes back with none, without the chart taking\n * focus. A failed load is `role=\"alert\"`, which interrupts, since it is the one of the\n * three a reader has to act on. The chart renders it inside the box its marks are drawn\n * in, which it positions; the grid and the axis under it stay.\n *\n * @example\n * ```html\n * @if (state(); as shown) {\n * <wr-chart-state [kind]=\"shown.kind\" [label]=\"shown.label\" />\n * }\n * ```\n *\n * @internal\n */\n@Component({\n selector: 'wr-chart-state',\n templateUrl: './chart-state.html',\n encapsulation: ViewEncapsulation.None,\n host: {\n class: 'wr-chart-state',\n '[class.wr-chart-state--empty]': \"kind() === 'empty'\",\n '[class.wr-chart-state--loading]': \"kind() === 'loading'\",\n '[class.wr-chart-state--error]': \"kind() === 'error'\",\n '[attr.role]': \"kind() === 'error' ? 'alert' : 'status'\",\n },\n})\nexport class WrChartState {\n /** Which of the three states this is. */\n readonly kind = input.required<WrChartStateKind>();\n\n /** The message, already translated. */\n readonly label = input.required<string>();\n}\n","<span class=\"wr-chart-state__plate\">\n @if (kind() === 'loading') {\n <!-- Decoration: the word beside it carries the state. -->\n <span class=\"wr-chart-state__spinner\" aria-hidden=\"true\"></span>\n }\n <span class=\"wr-chart-state__label\">{{ label() }}</span>\n</span>\n","/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { Component, ViewEncapsulation, computed, input } from '@angular/core';\n\nimport type { WrChartTableData } from './types';\n\n/**\n * The figures a chart draws, as a table that only assistive technology reaches.\n *\n * A chart's drawing is one named `role=\"img\"`, and `img` makes everything inside it\n * presentational: the name is announced and the numbers are nowhere a screen reader\n * can walk. This renders them as a real `<table>` — a caption, column headers, row\n * headers, and a `<tbody>` per group headed by a `<th scope=\"rowgroup\">` down its rows\n * — so a reader can move cell by cell and hear each value with its row and column.\n *\n * **Beside the image, never inside it.** Inside, `img` would hide it with the rest of\n * the drawing. A chart renders `<wr-chart-table>` as a sibling of the element that\n * carries `role=\"img\"`, and only while its `dataTable` input asks for it. **The chart's\n * host has to be positioned** (`position: relative`): the table is out of flow, and\n * against a static host it resolves to an ancestor outside the chart and keeps its place\n * in an unpositioned scroller's content, which grew one page by 1600px of blank scroll.\n *\n * **Hidden by clipping, not by `display` or `hidden`**, which would take it out of the\n * accessibility tree as well: the host is clipped to nothing and taken out of flow, so\n * it costs the chart no layout and still reads in full. The table inside keeps its own\n * layout, because a `<table>` will not shrink to a clip box of its own — it grows to\n * fit its cells whatever its width says. Nothing in it is focusable, so no tab stop\n * lands on something that cannot be seen.\n *\n * No ids: the headers are tied to their cells by `scope`, which needs none, and an id\n * minted on the server would not match the client's.\n *\n * @example\n * ```html\n * <div class=\"wr-line-chart__plot\" role=\"img\" [attr.aria-label]=\"label()\">…</div>\n * @if (dataTable()) {\n * <wr-chart-table [data]=\"table()\" />\n * }\n * ```\n *\n * @internal\n */\n@Component({\n selector: 'wr-chart-table',\n templateUrl: './chart-table.html',\n encapsulation: ViewEncapsulation.None,\n host: { class: 'wr-chart-table' },\n})\nexport class WrChartTable {\n /** The caption, the column headings and the rows, every string already written. */\n readonly data = input.required<WrChartTableData>();\n\n /** Whether any group is headed, which gives every row a leading group column. */\n protected readonly hasGroupHeaders = computed(() => this.data().groups.some(group => !!group.header));\n}\n","@let d = data();\n@let grouped = hasGroupHeaders();\n<!-- Every section is written out, `<thead>` and each `<tbody>` included: the HTML\n parser inserts a `<tbody>` the template left out, and hydration would then meet\n a tree it did not render. -->\n<table class=\"wr-chart-table__table\">\n <caption>\n {{\n d.caption\n }}\n </caption>\n <thead>\n <tr>\n <!-- Over the group headers' column, then the row headers' one. -->\n @if (grouped && !d.corner) {\n <td colspan=\"2\"></td>\n } @else {\n @if (grouped) {\n <td></td>\n }\n @if (d.corner) {\n <th scope=\"col\">{{ d.corner }}</th>\n } @else {\n <td></td>\n }\n }\n @for (column of d.columns; track $index) {\n <th scope=\"col\">{{ column }}</th>\n }\n </tr>\n </thead>\n @for (group of d.groups; track $index) {\n @if (group.rows.length > 0) {\n <tbody>\n @for (row of group.rows; track $index; let first = $first, count = $count) {\n <tr>\n <!-- The group's header in a column of its own, down every row of the group:\n the shape the HTML table algorithm and every checker read as heading the\n cells beside it. A full-width row above the group heads nothing by axe's\n reading. -->\n @if (grouped && first) {\n @if (group.header) {\n <th scope=\"rowgroup\" [attr.rowspan]=\"count\">{{ group.header }}</th>\n } @else {\n <td [attr.rowspan]=\"count\"></td>\n }\n }\n <th scope=\"row\">{{ row.header }}</th>\n @for (cell of row.cells; track $index) {\n <td>{{ cell }}</td>\n }\n </tr>\n }\n </tbody>\n }\n }\n</table>\n","/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { DestroyRef, ElementRef, type Signal, afterNextRender, afterRenderEffect, inject, signal } from '@angular/core';\n\nconst UNMEASURED: WrChartSize = { width: 0, height: 0 };\n\n/** What each observed element reports to, on the one observer every chart shares. */\nconst listeners = new WeakMap<Element, (size: WrChartSize) => void>();\n\n/** The marks {@link wrChartDim} lit last, per host, so the next call clears them without a scan. */\nconst litMarks = new WeakMap<Element, Element[]>();\n\nlet observer: ResizeObserver | null = null;\n\n/** The constructor `observer` was built with: a page has one, a test suite swaps it. */\nlet observerType: typeof ResizeObserver | null = null;\n\n/**\n * The box a chart measures, in px. Both are 0 until it is laid out.\n *\n * @internal\n */\nexport interface WrChartSize {\n readonly width: number;\n readonly height: number;\n}\n\n/**\n * Reports `element`'s content box to `listener` whenever it changes, through ONE\n * `ResizeObserver` for every chart on the page. Returns the function that stops it.\n *\n * Seven charts each made an observer of their own, so a dashboard of forty tiles ran\n * forty. An observer is built to watch many targets and delivers them in one callback\n * per frame. One listener per element: observing an element again replaces its listener.\n * Where there is no `ResizeObserver` (a server, an old test environment) nothing is\n * observed and the returned function does nothing.\n *\n * @internal\n */\nexport function wrChartObserveSize(element: Element, listener: (size: WrChartSize) => void): () => void {\n if (typeof ResizeObserver === 'undefined') return () => undefined;\n if (!observer || observerType !== ResizeObserver) {\n observerType = ResizeObserver;\n observer = new ResizeObserver(entries => {\n for (const entry of entries) {\n const { width, height } = entry.contentRect;\n listeners.get(entry.target)?.({ width, height });\n }\n });\n }\n const shared = observer;\n listeners.set(element, listener);\n shared.observe(element);\n return () => {\n listeners.delete(element);\n shared.unobserve(element);\n };\n}\n\n/**\n * The size of the element `target` holds, as a signal that follows it: `0 × 0` until the\n * element is rendered and laid out, and again once it is gone. On the shared observer of\n * {@link wrChartObserveSize}. Call in an injection context.\n *\n * @internal\n */\nexport function useChartSize(target: Signal<ElementRef<Element> | Element | undefined>): Signal<WrChartSize> {\n const size = signal<WrChartSize>(UNMEASURED);\n let stop: (() => void) | null = null;\n let observed: Element | null = null;\n\n afterRenderEffect(() => {\n const held = target();\n const element = held instanceof ElementRef ? held.nativeElement : (held ?? null);\n if (element === observed) return;\n stop?.();\n observed = element;\n stop = null;\n if (!element) {\n size.set(UNMEASURED);\n return;\n }\n stop = wrChartObserveSize(element, next => {\n const current = size();\n if (current.width !== next.width || current.height !== next.height) size.set(next);\n });\n });\n inject(DestroyRef).onDestroy(() => stop?.());\n return size.asReadonly();\n}\n\n/**\n * What {@link useChartHover} tells a chart.\n *\n * @internal\n */\nexport interface WrChartHoverHandlers {\n /** The pointer is over the section whose `data-wr-index` is `index`. Not repeated while it stays there. */\n enter(index: number): void;\n /** The pointer left the sections: for the chart's box, or for a part of it that is no section. */\n leave(event: MouseEvent): void;\n}\n\n/**\n * Dims every mark of `host` but the ones of series `key`, or none for `null`: the chart\n * takes `wr-chart--dim` and the series' own marks `wr-chart-mark--on`, and the shared\n * stylesheet fades the rest to `--wr-chart-dim`. A mark is anything carrying\n * `data-wr-series`, a legend row included.\n *\n * Classes set by hand rather than bound: a binding on every mark is re-evaluated for\n * every mark on each hover change, and this touches the marks of two series.\n *\n * @internal\n */\nexport function wrChartDim(host: Element, key: string | null): void {\n for (const mark of litMarks.get(host) ?? []) mark.classList.remove('wr-chart-mark--on');\n host.classList.toggle('wr-chart--dim', key !== null);\n if (key === null) {\n litMarks.delete(host);\n return;\n }\n const marks = [...host.querySelectorAll(`[data-wr-series=\"${CSS.escape(key)}\"]`)];\n for (const mark of marks) mark.classList.add('wr-chart-mark--on');\n litMarks.set(host, marks);\n}\n\n/**\n * A chart's hover, from ONE pair of listeners on its host however many sections it draws.\n *\n * A section is any element carrying `data-wr-index`: the listener finds the nearest one\n * above whatever the pointer is on and reports its index, once per section entered. A\n * listener pair on every bar was two per bar, and each one a change detection pass over\n * the whole chart for every bar the pointer crossed; these are native listeners, so a\n * move runs no pass at all unless the chart's own handler writes a signal.\n *\n * A gap the chart marks with `data-wr-hold` keeps the section and the dim as they are, so\n * crossing from one bar to the next does not close and reopen the tooltip; a section in\n * such an area takes `wr-chart-section--on`, so a band the chart paints on it stays too.\n *\n * It also drives the shared hover-dim: the nearest element carrying `data-wr-series`\n * names the series under the pointer, and {@link wrChartDim} fades the rest. Legend rows\n * carry the attribute too, so hovering a row dims the chart the same way.\n *\n * Registered after the first render, in the browser only. Call in an injection context.\n *\n * @internal\n */\nexport function useChartHover(handlers: WrChartHoverHandlers): void {\n const host = inject(ElementRef).nativeElement as HTMLElement;\n const destroyRef = inject(DestroyRef);\n let index: number | null = null;\n let series: string | null = null;\n\n // Marks drawn while a series is dimmed (a legend row hides it and shows it again with\n // the pointer still on the row) are new elements that `wrChartDim` never saw: they\n // would stay faded until the pointer moved. Only watched while a series is dimmed.\n let relight: MutationObserver | null = null;\n const watch = (on: boolean): void => {\n if (!on) {\n relight?.disconnect();\n relight = null;\n } else if (!relight && typeof MutationObserver !== 'undefined') {\n relight = new MutationObserver(() => {\n if (series !== null) wrChartDim(host, series);\n });\n relight.observe(host, { childList: true, subtree: true });\n }\n };\n\n const dim = (key: string | null): void => {\n if (key === series) return;\n series = key;\n wrChartDim(host, key);\n watch(key !== null);\n };\n\n let current: Element | null = null;\n const band = (section: Element | null): void => {\n current?.classList.remove('wr-chart-section--on');\n current = section?.closest('[data-wr-hold]') ? section : null;\n current?.classList.add('wr-chart-section--on');\n };\n\n const inHost = (el: Element | null | undefined): el is Element => !!el && host.contains(el);\n\n const over = (event: MouseEvent): void => {\n const target = event.target instanceof Element ? event.target : null;\n const section = target?.closest('[data-wr-index]');\n const series = target?.closest('[data-wr-series]');\n // In the room a chart holds open between its marks (`data-wr-hold`, the gaps between\n // its bars), the pointer is still on the drawing: what it last pointed at stays,\n // rather than closing and reopening a few pixels on.\n const held = !inHost(series) && inHost(target?.closest('[data-wr-hold]'));\n if (!held) dim(inHost(series) ? series.getAttribute('data-wr-series') : null);\n if (held && !inHost(section)) return;\n\n const next = inHost(section) ? Number(section.getAttribute('data-wr-index')) : null;\n if (next === index) return;\n index = next;\n if (next === null || !Number.isFinite(next)) {\n band(null);\n handlers.leave(event);\n } else {\n band(section ?? null);\n handlers.enter(next);\n }\n };\n\n const leave = (event: MouseEvent): void => {\n dim(null);\n if (index === null) return;\n index = null;\n band(null);\n handlers.leave(event);\n };\n\n afterNextRender(() => {\n host.addEventListener('mouseover', over);\n host.addEventListener('mouseleave', leave);\n destroyRef.onDestroy(() => {\n watch(false);\n host.removeEventListener('mouseover', over);\n host.removeEventListener('mouseleave', leave);\n });\n });\n}\n","/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\n/**\n * The `limit` longest of `labels`, each once, longest first: the strings worth measuring.\n *\n * A chart sizes a gutter or keeps room past a bar from a hidden copy of the text that goes\n * there. Copying every label made ten thousand hidden spans for ten thousand bars, to learn\n * the width of one. The widest label is almost always among the longest few by character\n * count - a proportional font can put `1,111` under `999`, which is why this returns a few\n * and not one - so a chart renders these and reads the widest.\n *\n * @internal\n */\nexport function wrChartLongest(labels: readonly string[], limit = 3): string[] {\n const longest: string[] = [];\n for (const label of new Set(labels)) {\n if (longest.length === limit && label.length <= longest[longest.length - 1].length) continue;\n let at = longest.findIndex(kept => kept.length < label.length);\n if (at < 0) at = longest.length;\n longest.splice(at, 0, label);\n if (longest.length > limit) longest.pop();\n }\n return longest;\n}\n\n/**\n * How many categories each printed label stands for, so no two labels along an axis run\n * into each other: 1 while every label fits its own band, 2 to print every second one,\n * and so on.\n *\n * `extent` is the axis' length and `count` how many bands share it; `labelSize` is the\n * longest label along the axis, and `gap` the least room between two labels. All in the\n * same unit, px in practice. With nothing measured yet - a server render, a chart not\n * laid out - the answer is 1: every label, as the markup had before it was measured.\n *\n * @internal\n */\nexport function wrChartLabelStep(count: number, extent: number, labelSize: number, gap = 8): number {\n if (!(count > 1) || !(extent > 0) || !(labelSize > 0)) return 1;\n const band = extent / count;\n return Math.max(1, Math.min(count, Math.ceil((labelSize + gap) / band)));\n}\n","/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\n/**\n * Default series colours, in order: what a series, a slice or a segment with no\n * `color` of its own takes. Each is a token of the chart theme (`--wr-chart-1` to\n * `--wr-chart-8`, declared by `ngwr/charts/core`'s stylesheet), so an app retints\n * every chart by setting the tokens and a chart's markup never names a hex.\n *\n * The palette is not the status intents: a second series is not a success and a\n * fourth is not a danger. The first is the brand colour and the last the neutral\n * role; neighbours alternate between a deep and a mid tone, so two series next to\n * each other differ in lightness as well as in hue. The stylesheet carries the\n * measured contrast of each.\n *\n * A chart that draws lines still pairs each with a dash (`WR_CHART_DASHES`), and\n * one that draws points with a shape (`WR_CHART_MARKERS`): colour is never the\n * only thing that tells two series apart.\n *\n * @internal\n */\nexport const WR_CHART_PALETTE: readonly string[] = [\n 'var(--wr-chart-1)',\n 'var(--wr-chart-2)',\n 'var(--wr-chart-3)',\n 'var(--wr-chart-4)',\n 'var(--wr-chart-5)',\n 'var(--wr-chart-6)',\n 'var(--wr-chart-7)',\n 'var(--wr-chart-8)',\n];\n\n/**\n * The palette colour for the series at `index`, wrapping past the end.\n *\n * @internal\n */\nexport function wrChartColor(index: number): string {\n return WR_CHART_PALETTE[wrap(index, WR_CHART_PALETTE.length)];\n}\n\n/**\n * The series colours every chart took before the chart theme: four status intents and\n * the neutral role. Kept for the charts that have not moved onto `--wr-chart-*` yet,\n * so each keeps its look until it does; a chart on the theme reads\n * {@link WR_CHART_PALETTE}.\n *\n * `warning` measures 1.71:1 on a white surface, under the 3:1 a graphic needs, which\n * is one of the reasons the theme's palette replaced it.\n *\n * @internal\n */\nexport const WR_CHART_LEGACY_PALETTE: readonly string[] = [\n 'var(--wr-color-primary)',\n 'var(--wr-color-success)',\n 'var(--wr-color-warning)',\n 'var(--wr-color-danger)',\n 'var(--wr-color-on-surface-muted)',\n];\n\n/**\n * The {@link WR_CHART_LEGACY_PALETTE} colour for the series at `index`, wrapping past\n * the end.\n *\n * @internal\n */\nexport function wrChartLegacyColor(index: number): string {\n return WR_CHART_LEGACY_PALETTE[wrap(index, WR_CHART_LEGACY_PALETTE.length)];\n}\n\n/**\n * A dash pattern per series, so lines are told apart by SHAPE and not only by hue.\n *\n * A reader with red-green colour blindness can see two strokes of similar lightness\n * as one grey, and a legend that pairs a coloured dot with a name does not rescue it:\n * matching the dot to the line is exactly the step that needs hue. Distinguishing\n * series by dash is the standard remedy and the only one that survives greyscale,\n * printing and a monochrome display.\n *\n * The FIRST entry is solid on purpose. A single-series chart is the common case\n * and there is nothing to tell apart in it; the patterns only appear once a second\n * series does. Each value is an SVG `stroke-dasharray`, `''` meaning none.\n *\n * @internal\n */\nexport const WR_CHART_DASHES: readonly string[] = ['', '7 4', '2 3', '10 4 2 4', '1 4', '6 3 2 3'];\n\n/**\n * The dash pattern for the series at `index`, wrapping past the end.\n *\n * @internal\n */\nexport function wrChartDash(index: number): string {\n return WR_CHART_DASHES[wrap(index, WR_CHART_DASHES.length)];\n}\n\n/** `index` folded into `[0, length)`, negatives included, so a bad index still picks an entry. */\nexport function wrap(index: number, length: number): number {\n const i = Number.isFinite(index) ? Math.trunc(index) : 0;\n return ((i % length) + length) % length;\n}\n","/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { wrap } from './palette';\nimport type { WrChartMarkerExtent, WrChartMarkerShape } from './types';\n\n/** Half the side of a square with the area of a circle of radius 1: √π / 2. */\nconst SQUARE = Math.sqrt(Math.PI) / 2;\n\n/** Half the diagonal of that square, standing on a corner. */\nconst DIAMOND = SQUARE * Math.SQRT2;\n\n/** The side of an equilateral triangle with the area of a circle of radius 1: √(4π / √3). */\nconst TRIANGLE_SIDE = Math.sqrt((4 * Math.PI) / Math.sqrt(3));\n\n/** The distance from that triangle's centroid to a corner (two thirds of its height). */\nconst TRIANGLE_APEX = (TRIANGLE_SIDE * Math.sqrt(3)) / 3;\n\n/**\n * A plus with arms 0.35 of their length thick, half-length `L` and half-thickness\n * `0.35 L`, has an area of `8·0.35·L² − 4·0.35²·L²`; this is the `L` that makes it π.\n */\nconst CROSS_ARM = Math.sqrt(Math.PI / (8 * 0.35 - 4 * 0.35 ** 2));\nconst CROSS_THICKNESS = CROSS_ARM * 0.35;\n\n/**\n * How far each shape reaches from its centre at `r = 1`, read off the corners\n * {@link wrChartMarkerPath} draws: up, down, to either side, and to the farthest\n * corner.\n */\nconst EXTENTS: Readonly<Record<WrChartMarkerShape, WrChartMarkerExtent>> = {\n circle: { top: 1, bottom: 1, side: 1, radius: 1 },\n square: { top: SQUARE, bottom: SQUARE, side: SQUARE, radius: SQUARE * Math.SQRT2 },\n diamond: { top: DIAMOND, bottom: DIAMOND, side: DIAMOND, radius: DIAMOND },\n triangle: { top: TRIANGLE_APEX, bottom: TRIANGLE_APEX / 2, side: TRIANGLE_SIDE / 2, radius: TRIANGLE_APEX },\n 'triangle-down': { top: TRIANGLE_APEX / 2, bottom: TRIANGLE_APEX, side: TRIANGLE_SIDE / 2, radius: TRIANGLE_APEX },\n cross: { top: CROSS_ARM, bottom: CROSS_ARM, side: CROSS_ARM, radius: Math.hypot(CROSS_ARM, CROSS_THICKNESS) },\n};\n\n/** A coordinate to three decimals, without trailing zeros, so a path stays short. */\nconst n = (value: number): string => String(Math.round(value * 1000) / 1000 || 0);\n\n/** `M x y L … Z` through the given corners. */\nconst polygon = (points: readonly (readonly [number, number])[]): string =>\n `M ${points.map(([x, y]) => `${n(x)} ${n(y)}`).join(' L ')} Z`;\n\n/**\n * A marker shape per series, so points are told apart by SHAPE and not only by\n * hue — the dash list's job, for a chart that draws points rather than lines.\n *\n * The circle comes first for the reason the solid dash does: a single-series chart\n * has nothing to tell apart. The order then alternates corners and points, so two\n * neighbouring series never differ by a rotation alone (a square beside a diamond\n * is the pair a small marker blurs into one).\n *\n * @internal\n */\nexport const WR_CHART_MARKERS: readonly WrChartMarkerShape[] = [\n 'circle',\n 'square',\n 'triangle',\n 'diamond',\n 'cross',\n 'triangle-down',\n];\n\n/**\n * The marker shape for the series at `index`, wrapping past the end.\n *\n * @internal\n */\nexport function wrChartMarker(index: number): WrChartMarkerShape {\n return WR_CHART_MARKERS[wrap(index, WR_CHART_MARKERS.length)];\n}\n\n/**\n * The SVG path `d` of a marker centred on the origin, as large as a circle of\n * radius `r` — every shape has that circle's area, so a triangle reaches past it\n * and a square stays inside it, and the eye weighs them the same.\n *\n * Drawn about the origin so a chart can place it with a `transform`, or inside a\n * nested `<svg x y overflow=\"visible\">`, and size it in pixels whatever the plot's\n * own scale. A non-finite or negative `r` draws nothing rather than a path of\n * `NaN`.\n *\n * @internal\n */\nexport function wrChartMarkerPath(shape: WrChartMarkerShape, r: number): string {\n if (!Number.isFinite(r) || r <= 0) return '';\n switch (shape) {\n case 'square': {\n const h = r * SQUARE;\n return polygon([\n [-h, -h],\n [h, -h],\n [h, h],\n [-h, h],\n ]);\n }\n case 'diamond': {\n const d = r * DIAMOND;\n return polygon([\n [0, -d],\n [d, 0],\n [0, d],\n [-d, 0],\n ]);\n }\n case 'triangle':\n case 'triangle-down': {\n // Centred on the centroid, not on the box, so a triangle sits on the same\n // point a circle would.\n const flip = shape === 'triangle' ? 1 : -1;\n const apex = r * TRIANGLE_APEX;\n const half = (r * TRIANGLE_SIDE) / 2;\n return polygon([\n [0, -apex * flip],\n [half, (apex / 2) * flip],\n [-half, (apex / 2) * flip],\n ]);\n }\n case 'cross': {\n const a = r * CROSS_ARM;\n const t = r * CROSS_THICKNESS;\n return polygon([\n [-t, -a],\n [t, -a],\n [t, -t],\n [a, -t],\n [a, t],\n [t, t],\n [t, a],\n [-t, a],\n [-t, t],\n [-a, t],\n [-a, -t],\n [-t, -t],\n ]);\n }\n case 'circle':\n default:\n // Two arcs, since one arc from a point back to itself draws nothing.\n return `M ${n(-r)} 0 A ${n(r)} ${n(r)} 0 1 0 ${n(r)} 0 A ${n(r)} ${n(r)} 0 1 0 ${n(-r)} 0 Z`;\n }\n}\n\n/**\n * How far the marker {@link wrChartMarkerPath} draws at `r` reaches from its centre,\n * in px, before any stroke: up, down, to either side, and to its farthest corner.\n *\n * Every shape has the circle's AREA, so `r` is not how far a marker reaches: a\n * triangle's point stands 1.56 r above its centroid, a diamond's tips 1.25 r out\n * and a cross's corners 1.24 r, while a square's sides sit 0.89 r in. A box, a hit\n * area or a margin sized by `r` alone cuts the tips off. A non-finite or negative\n * `r` reaches nowhere, as it draws nothing.\n *\n * @internal\n */\nexport function wrChartMarkerExtent(shape: WrChartMarkerShape, r: number): WrChartMarkerExtent {\n const size = Number.isFinite(r) && r > 0 ? r : 0;\n const unit = EXTENTS[shape] ?? EXTENTS.circle;\n return { top: unit.top * size, bottom: unit.bottom * size, side: unit.side * size, radius: unit.radius * size };\n}\n","/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { LOCALE_ID, type Signal, inject } from '@angular/core';\n\nimport { wrClamp } from 'ngwr/utils';\n\nimport type { WrChartNumbers } from './types';\n\n/**\n * The fewest fraction digits that write `value` exactly, up to six: the precision of a\n * step no power of ten divides, such as the third a flat range is centred with.\n */\nfunction fractionDigits(value: number): number {\n for (let d = 0; d <= 6; d++) if (Math.abs(value * 10 ** d - Math.round(value * 10 ** d)) < 1e-9) return d;\n return 6;\n}\n\n/** The power of ten of `value`'s leading digit: 2 for 750, -2 for 0.025. */\nfunction magnitude(value: number): number {\n const abs = Math.abs(value);\n let m = Math.floor(Math.log10(abs));\n // `log10` is a float: guard the exact powers of ten from landing one off.\n if (10 ** (m + 1) <= abs) m++;\n if (10 ** m > abs) m--;\n return m;\n}\n\n/**\n * The power of ten of `step`'s LAST significant digit: 1 for 250, -1 for 2.5. Every tick\n * is a whole multiple of the step, so no tick has a digit below it, and a tick written to\n * that digit is written exactly.\n */\nfunction lastDigit(step: number): number {\n for (let e = magnitude(step); e > -21; e--) {\n const scaled = step / 10 ** e;\n if (Math.abs(scaled - Math.round(scaled)) < 1e-6) return e;\n }\n return -21;\n}\n\n/** Every formatter the charts have asked for, by locale and options. */\nconst FORMATTERS = new Map<string, Intl.NumberFormat>();\n\n/**\n * The `Intl.NumberFormat` for `locale` and `options`, built once for the page and shared\n * by every chart on it.\n *\n * Building one costs about a tenth of a millisecond, and the charts built them freely:\n * three per chart instance, and one per tick on every pass over an axis, so a table of a\n * hundred sparklines paid for three hundred identical formatters. A formatter holds no\n * state, so one per distinct key serves them all. The key is the locale and the options\n * in the order given; the charts ask with a handful of shapes, so the map stays small.\n *\n * @internal\n */\nexport function wrChartNumberFormat(locale: string, options?: Intl.NumberFormatOptions): Intl.NumberFormat {\n const key = options ? `${locale}|${JSON.stringify(options)}` : locale;\n let format = FORMATTERS.get(key);\n if (!format) {\n format = new Intl.NumberFormat(locale, options);\n FORMATTERS.set(key, format);\n }\n return format;\n}\n\n/**\n * The number writers of one chart: its axis ticks, the labels it prints in tight\n * spaces, and the figures of its tooltip and its accessible names — every one\n * through the chart's `valueFormat` when it has one, else through `Intl` in\n * `locale`.\n *\n * Seven charts kept their own copy of the `Intl` half until 15.1, each with the\n * same two formatters and the same `formatValue`, and the line chart a second,\n * axis-wide copy for its ticks. The rules are theirs, unchanged:\n *\n * - `value` is never compact, and is `Intl`'s default otherwise: up to three\n * fraction digits, and below one three SIGNIFICANT digits, since three fraction\n * digits write a reading of 0.0004 as `0`. It is not the exact figure: 1.08345\n * is `1.083`, and an axis stepping by 0.00025 is finer than it. A chart that has\n * to write a figure to a known precision asks `exact`.\n * - `label` is compact from a thousand up, where a bar is too narrow for\n * `1,234,567`, and below a thousand it is `value`: compact rounding would print\n * 12.5 as `13`, and there is nothing to abbreviate.\n * - `ticks` is decided for the AXIS. Compact, through `Intl` (`1.2K`, `3.4M`,\n * `4 Mio.`, `5 тыс.`), with each tick to exactly the significant digits the step\n * needs — a fixed count printed 1250 beside 1000 as `1.3k` and `1k` on an axis\n * stepping by 250. And when abbreviating would make the labels LONGER (a fine\n * step on large numbers, where `-1.025K` is wider than `-1,025`) the whole axis\n * is written in full instead, so no axis mixes `-1K` with `-1,025`. Written in\n * full, a tick has as many fraction digits as the step's last digit needs, however\n * fine: they stopped at six, so an axis stepping by 2.5e-7 printed `0.000013` twice.\n * - `exact` writes a figure to a precision the chart decides — the step of its axis,\n * a price's tick size — never compact, through `valueFormat` when there is one.\n *\n * `valueFormat` takes whatever extra arguments the chart passes it, so a chart can\n * tell its formatter which axis a number is for while a `(value) => string`\n * written for another chart still fits. Call in an injection context: `locale`\n * defaults to `LOCALE_ID`.\n *\n * @internal\n */\nexport function useChartNumbers<A extends readonly unknown[] = []>(\n valueFormat: Signal<((value: number, ...args: A) => string) | null | undefined>,\n locale: string = inject(LOCALE_ID)\n): WrChartNumbers<A> {\n const numbers = wrChartNumberFormat(locale);\n /** Below one, by significant digits, which keep 0.0004 from rounding to `0`. */\n const smallNumbers = wrChartNumberFormat(locale, { maximumSignificantDigits: 3 });\n const compactNumbers = wrChartNumberFormat(locale, { notation: 'compact' });\n\n const value = (v: number, ...args: A): string => {\n const custom = valueFormat();\n if (custom) return custom(v, ...args);\n return (v !== 0 && Math.abs(v) < 1 ? smallNumbers : numbers).format(v);\n };\n\n const label = (v: number, ...args: A): string => {\n if (valueFormat() || Math.abs(v) < 1000) return value(v, ...args);\n return compactNumbers.format(v);\n };\n\n const ticks = (values: readonly number[], step: number, ...args: A): string[] => {\n const custom = valueFormat();\n if (custom) return values.map(v => custom(v, ...args));\n if (values.length === 0) return [];\n\n const last = lastDigit(step);\n // A CEILING rather than a fixed count, so trailing zeros are dropped: a 0.25 step\n // wants two digits on 0.25 and none on 1, and `1.00` beside `0.25` reads as\n // spurious precision. Down to the step's last digit, however fine — the six digits\n // `fractionDigits` stops at printed a 2.5e-7 step as `0.000013` twice, and called\n // a step below 1e-9 whole. A step with no last digit (a third) keeps those six.\n const digits = last <= -21 ? fractionDigits(step) : wrClamp(-last, 0, 20);\n const full = wrChartNumberFormat(locale, { maximumFractionDigits: digits });\n const plain = values.map(v => full.format(v));\n const compact = values.map(v =>\n v === 0\n ? full.format(0)\n : wrChartNumberFormat(locale, {\n notation: 'compact',\n maximumSignificantDigits: wrClamp(magnitude(v) - last + 1, 1, 21),\n }).format(v)\n );\n const longest = (labels: readonly string[]): number => Math.max(...labels.map(text => text.length));\n return longest(compact) <= longest(plain) ? compact : plain;\n };\n\n const exact = (v: number, fractionDigits: number, ...args: A): string => {\n const custom = valueFormat();\n if (custom) return custom(v, ...args);\n const digits = Number.isFinite(fractionDigits) ? wrClamp(Math.round(fractionDigits), 0, 20) : 3;\n return wrChartNumberFormat(locale, { maximumFractionDigits: digits }).format(v);\n };\n\n return { value, label, ticks, exact };\n}\n","/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\n/**\n * `value` rounded to `digits` decimals for an inline style or an SVG attribute, with\n * `-0` folded to `0`: a share of an axis, a percentage, a coordinate.\n *\n * Eleven charts each kept a copy of this under another name (`short`, `percent`,\n * `fixed`), at three precisions. A written geometry value wants few digits - every one\n * past the fourth is bytes in the DOM and a different string for the same pixel - and\n * never `-0`, which `Math.round` produces for a small negative and which prints as `-0`.\n *\n * Not `wrRound` from `ngwr/utils`, which nudges by `Number.EPSILON` to round a decimal\n * tie the way a person expects and keeps the sign of a zero.\n *\n * @internal\n */\nexport function wrChartRound(value: number, digits = 4): number {\n const factor = 10 ** digits;\n return Math.round(value * factor) / factor || 0;\n}\n"],"mappings":";;;;;;;;;;AAYA,MAAM,aAAa;AAGnB,MAAM,QAAqB;CAAE,KAAK;CAAG,KAAK;CAAG,MAAM;CAAM,OAAO;EAAC;EAAG;EAAM;EAAK;EAAM;CAAC;AAAC;AAGvF,MAAM,SAAS;CAAC;CAAG;CAAK;CAAM;AAAG;AAejC,SAAS,WAAW,MAAY;CAC9B,OAAO,KAAK,IAAI,IAAI,KAAK,IAAI,GAAG,KAAK,KAAK,CAAC,KAAK,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC;AACnE;AAcA,SAAS,YAAY,OAAa;CAChC,MAAM,YAAY,KAAK,IAAI,KAAK;CAChC,IAAI,OAAO,cAAc,IAAI,IAAI,YAAY;CAC7C,IAAI,YAAY,GAAG;EACjB,MAAM,MAAM,KAAK,KAAK,KAAK,MAAM,YAAY,CAAC,CAAC;EAC/C,QAAQ,KAAK,IAAI,WAAW,KAAK,WAAW,MAAM,IAAI,YACpD,KAAK,MAAM,QAAQ,QAAQ;GACzB,MAAM,YAAY,OAAO,MAAM;GAC/B,IAAI,YAAY,YAAY,GAAG;GAC/B,MAAM,QAAQ,QAAQ;GACtB,IAAI,KAAK,IAAI,QAAQ,KAAK,MAAM,KAAK,CAAC,IAAI,MAAM;IAC9C,OAAO;IACP,MAAM;GACR;EACF;CAEJ;CACA,MAAM,SAAS,WAAW,IAAI;CAC9B,OAAO;EACL,KAAK,QAAQ;EACb,KAAK,QAAQ;EACb;EACA,OAAO;GAAC,QAAQ,QAAQ,MAAM,MAAM;GAAG;GAAO,QAAQ,QAAQ,MAAM,MAAM;EAAC;CAC5E;AACH;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AAI,OAAO,GAAG,GAAG,EAAE;EACjE,CAAA,CAAC,CAAC,OAAO,CAAC,CAAC;EAElB,MAAM,WAAW,WAAsC,KAAK,IAAI,GAAG,OAAO,KAAI,SAAQ,KAAK,MAAM,CAAC;EAClG,OAAO,QAAQ,OAAO,KAAK,QAAQ,KAAK,IAAI,UAAU;CACxD;CAEA,MAAM,SAAS,GAAW,gBAAwB,GAAG,SAAmB;EACtE,MAAM,SAAS,YAAW;EAC1B,IAAI,QAAQ,OAAO,OAAO,GAAG,GAAG,IAAI;EAEpC,OAAO,oBAAoB,QAAQ,EAAE,uBADtB,OAAO,SAAS,cAAc,IAAI,QAAQ,KAAK,MAAM,cAAc,GAAG,GAAG,EAAE,IAAI,EAC5B,CAAE,CAAC,CAAC,OAAO,CAAC;CAChF;CAEA,OAAO;EAAE;EAAO;EAAO;EAAO;CAAK;AACrC;;;;;;;AC3IA,SAAgB,aAAa,OAAe,SAAS,GAAC;CACpD,MAAM,SAAS,MAAM;CACrB,OAAO,KAAK,MAAM,QAAQ,MAAM,IAAI,UAAU;AAChD"}
|
|
@@ -6,6 +6,17 @@ import { WrChartLegendHarness } from "ngwr/charts/chart-legend/testing";
|
|
|
6
6
|
* Use of this source code is governed by an MIT-style license that can be
|
|
7
7
|
* found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE
|
|
8
8
|
*/
|
|
9
|
+
var TableRowHarness = class extends ComponentHarness {
|
|
10
|
+
static hostSelector = ".wr-chart-table tbody tr";
|
|
11
|
+
async read() {
|
|
12
|
+
const header = await this.locatorFor("th[scope=\"row\"]")();
|
|
13
|
+
const cells = await this.locatorForAll("td")();
|
|
14
|
+
return {
|
|
15
|
+
header: await header.text(),
|
|
16
|
+
cells: await Promise.all(cells.map((cell) => cell.text()))
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
};
|
|
9
20
|
var WrDonutChartHarness = class WrDonutChartHarness extends ComponentHarness {
|
|
10
21
|
static hostSelector = "wr-donut-chart";
|
|
11
22
|
static with(options = {}) {
|
|
@@ -39,6 +50,19 @@ var WrDonutChartHarness = class WrDonutChartHarness extends ComponentHarness {
|
|
|
39
50
|
value: await values[index]?.text() ?? ""
|
|
40
51
|
})));
|
|
41
52
|
}
|
|
53
|
+
async hasDataTable() {
|
|
54
|
+
return await this.locatorForOptional(".wr-chart-table")() !== null;
|
|
55
|
+
}
|
|
56
|
+
async getTableColumns() {
|
|
57
|
+
await this.assertDataTable("getTableColumns");
|
|
58
|
+
const headings = await this.locatorForAll(".wr-chart-table thead th[scope=\"col\"]")();
|
|
59
|
+
return Promise.all(headings.map((heading) => heading.text()));
|
|
60
|
+
}
|
|
61
|
+
async getTableRows() {
|
|
62
|
+
await this.assertDataTable("getTableRows");
|
|
63
|
+
const rows = await this.locatorForAll(TableRowHarness)();
|
|
64
|
+
return Promise.all(rows.map((row) => row.read()));
|
|
65
|
+
}
|
|
42
66
|
async getCenterValue() {
|
|
43
67
|
const center = await this.locatorForOptional(".wr-donut-chart__center-value")();
|
|
44
68
|
return center ? center.text() : null;
|
|
@@ -53,6 +77,9 @@ var WrDonutChartHarness = class WrDonutChartHarness extends ComponentHarness {
|
|
|
53
77
|
if (!match) throw new Error(`WrDonutChartHarness.getSize(): no inline width on .wr-donut-chart__surface (style: "${style ?? ""}"). The component writes one unconditionally, so its absence is the bug rather than a zero.`);
|
|
54
78
|
return Number.parseFloat(match[1]);
|
|
55
79
|
}
|
|
80
|
+
async assertDataTable(method) {
|
|
81
|
+
if (!await this.hasDataTable()) throw new Error(`WrDonutChartHarness.${method}(): the chart renders no data table: \`dataTable\` is off, or there is nothing to tabulate. Ask hasDataTable() first.`);
|
|
82
|
+
}
|
|
56
83
|
};
|
|
57
84
|
export { WrDonutChartHarness };
|
|
58
85
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ngwr-charts-donut-chart-testing.mjs","names":[],"sources":["../../../projects/lib/charts/donut-chart/testing/wr-donut-chart-harness.ts"],"sourcesContent":["/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { ComponentHarness, HarnessPredicate } from '@angular/cdk/testing';\n\nimport { WrChartLegendHarness } from 'ngwr/charts/chart-legend/testing';\n\nimport type { WrDonutChartHarnessFilters, WrDonutChartLegendEntry } from './types';\n\n/**\n * Test harness for `<wr-donut-chart>`.\n *\n * **The ring itself is unreadable, and that is by design.** The slices are SVG\n * paths inside a `role=\"img\"` drawing: a screen reader is given that drawing's\n * `aria-label` and nothing else, and a spec cannot get a label or a value off a\n * path's `d`. {@link getLegend} is where the numbers are — which is also the\n * argument for keeping `showLegend` on, since with it off the only other text is\n * whatever {@link getCenterValue} and {@link getCenterLabel} were given.\n *\n * The name is read off the `<svg>` rather than off the surface that wraps it, and\n * the two are not interchangeable: `img` makes its whole subtree presentational, so\n * a name on the wrapper would take the centre text down with it.\n *\n * {@link getSliceCount} is therefore the one thing the ring answers: how many\n * wedges were drawn. Compare it with the legend's length to catch a slice that was\n * filtered out of one and not the other — apart from a slice hidden through\n * `hiddenSegments`, which keeps its legend row and draws no wedge by design;\n * {@link getLegendHarness} says which rows those are.\n *\n * @example\n * ```ts\n * const chart = await loader.getHarness(WrDonutChartHarness);\n *\n * expect(await chart.getSliceCount()).toBe(3);\n * expect(await chart.getLegend()).toEqual([\n * { label: 'Direct', value: '48' },\n * { label: 'Search', value: '32' },\n * { label: 'Social', value: '20' },\n * ]);\n * ```\n *\n * @see https://ngwr.dev/guides/testing\n */\nexport class WrDonutChartHarness extends ComponentHarness {\n static hostSelector = 'wr-donut-chart';\n\n /** Build a predicate that narrows the query — pass to `getHarness` / `getAllHarnesses`. */\n static with(options: WrDonutChartHarnessFilters = {}): HarnessPredicate<WrDonutChartHarness> {\n return new HarnessPredicate(WrDonutChartHarness, options)\n .addOption('ariaLabel', options.ariaLabel, (harness, label) =>\n HarnessPredicate.stringMatches(harness.getAccessibleName(), label)\n )\n .addOption('sliceLabel', options.sliceLabel, async (harness, label) => {\n for (const entry of await harness.getLegend()) {\n if (await HarnessPredicate.stringMatches(entry.label, label)) return true;\n }\n return false;\n });\n }\n\n /** The name the ring announces — the whole chart's, since the slices announce nothing. */\n async getAccessibleName(): Promise<string | null> {\n return (await this.locatorFor('.wr-donut-chart__surface svg')()).getAttribute('aria-label');\n }\n\n /**\n * How many wedges were drawn. A hidden slice draws none, and nor does a chart that is\n * empty, loading or failed. The invisible hover target a sliver gets over the ring\n * (`.wr-donut-chart__hit`) and the track an empty ring keeps (`.wr-donut-chart__track`)\n * are not wedges and are not counted.\n */\n async getSliceCount(): Promise<number> {\n return (await this.locatorForAll('.wr-donut-chart__slice')()).length;\n }\n\n /**\n * Whether the chart is a pie (`pie`), read off its `wr-donut-chart--pie` modifier.\n * Not whether the slices reach the centre — a `thickness` of 0 does that too, and keeps\n * the centre text — since a path's `d` is not read, for the reason given in the class\n * note. A pie renders no centre text: {@link getCenterValue} and {@link getCenterLabel}\n * answer `null` for it whatever was bound.\n */\n async isPie(): Promise<boolean> {\n return (await this.host()).hasClass('wr-donut-chart--pie');\n }\n\n /**\n * Whether the legend is rendered: `showLegend` is not off, `legendPosition` is not\n * `none`, and there are two segments or more - or one, with `showLegend` set.\n */\n async hasLegend(): Promise<boolean> {\n return (await this.locatorForOptional('.wr-donut-chart__legend')()) !== null;\n }\n\n /**\n * The legend as a {@link WrChartLegendHarness}: each row's key and its hidden state\n * and, with `toggleableLegend`, the toggles that show and hide a slice. Not the same\n * thing as {@link getLegend}, which reads the rows' text and stays as it was.\n *\n * Throws when the chart draws no legend (`showLegend` off, `legendPosition=\"none\"`, no\n * segments, or a single one under `showLegend=\"auto\"`) rather than answering with an\n * empty one: {@link hasLegend} is the question for that.\n */\n async getLegendHarness(): Promise<WrChartLegendHarness> {\n const legend = await this.locatorForOptional(WrChartLegendHarness)();\n if (!legend) {\n throw new Error(\n 'WrDonutChartHarness.getLegendHarness(): the chart draws no legend — `showLegend` is off or there are no ' +\n 'segments. Ask hasLegend() first.'\n );\n }\n return legend;\n }\n\n /** The legend rows in order — the only textual form the data has. Hidden slices included. */\n async getLegend(): Promise<WrDonutChartLegendEntry[]> {\n const labels = await this.locatorForAll('.wr-donut-chart__legend-label')();\n const values = await this.locatorForAll('.wr-donut-chart__legend-value')();\n\n return Promise.all(\n labels.map(async (label, index) => ({\n label: await label.text(),\n value: (await values[index]?.text()) ?? '',\n }))\n );\n }\n\n /** The big number in the middle, or `null` when the chart has none — a pie never has. */\n async getCenterValue(): Promise<string | null> {\n const center = await this.locatorForOptional('.wr-donut-chart__center-value')();\n return center ? center.text() : null;\n }\n\n /** The caption under the centre value, or `null` — a pie never has one. */\n async getCenterLabel(): Promise<string | null> {\n const center = await this.locatorForOptional('.wr-donut-chart__center-label')();\n return center ? center.text() : null;\n }\n\n /**\n * The chart's outer size in pixels, read off the `style` ATTRIBUTE.\n *\n * NOT `getCssValue()`, which is `getComputedStyle()` — the same rule this\n * file's class note already states and this method alone broke. A computed\n * read answers from the LAID-OUT box, so it agrees with the inline value in\n * jsdom (which lays nothing out and echoes the declaration) and disagrees in a\n * browser, where sub-pixel rounding turns a declared 240 into 239.5. A harness\n * that answers differently in the two places it runs is worse than one that\n * refuses.\n */\n async getSize(): Promise<number> {\n const style = await (await this.locatorFor('.wr-donut-chart__surface')()).getAttribute('style');\n const match = /width:\\s*([\\d.]+)px/.exec(style ?? '');\n if (!match) {\n throw new Error(\n `WrDonutChartHarness.getSize(): no inline width on .wr-donut-chart__surface (style: \"${style ?? ''}\"). ` +\n 'The component writes one unconditionally, so its absence is the bug rather than a zero.'\n );\n }\n return Number.parseFloat(match[1]);\n }\n}\n"],"mappings":";;;;;;;;AA+CA,IAAa,sBAAb,MAAa,4BAA4B,iBAAgB;CACvD,OAAO,eAAe;CAGtB,OAAO,KAAK,UAAsC,CAAA,GAAE;EAClD,OAAO,IAAI,iBAAiB,qBAAqB,OAAO,CAAC,CACtD,UAAU,aAAa,QAAQ,YAAY,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,CAAA;EAC7E,OAAO,SAAS,OAAO,KAAI,IAAK;CAClC;CAaA,MAAM,UAAO;EACX,MAAM,QAAQ,OAAO,MAAM,KAAK,WAAW,0BAA0B,CAAC,CAAA,EAAA,CAAI,aAAa,OAAO;EAC9F,MAAM,QAAQ,sBAAsB,KAAK,SAAS,EAAE;EACpD,IAAI,CAAC,OACH,MAAM,IAAI,MACR,uFAAuF,SAAS,GAAE,4FACP;EAG/F,OAAO,OAAO,WAAW,MAAM,EAAE;CACnC"}
|
|
1
|
+
{"version":3,"file":"ngwr-charts-donut-chart-testing.mjs","names":[],"sources":["../../../projects/lib/charts/donut-chart/testing/wr-donut-chart-harness.ts"],"sourcesContent":["/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { ComponentHarness, HarnessPredicate } from '@angular/cdk/testing';\n\nimport { WrChartLegendHarness } from 'ngwr/charts/chart-legend/testing';\n\nimport type { WrDonutChartHarnessFilters, WrDonutChartLegendEntry, WrDonutChartTableRow } from './types';\n\n/**\n * One body row of the chart's data table, so its header and cells are read off the row\n * they sit in rather than matched up by position across the whole table.\n */\nclass TableRowHarness extends ComponentHarness {\n static hostSelector = '.wr-chart-table tbody tr';\n\n async read(): Promise<WrDonutChartTableRow> {\n const header = await this.locatorFor('th[scope=\"row\"]')();\n const cells = await this.locatorForAll('td')();\n return { header: await header.text(), cells: await Promise.all(cells.map(cell => cell.text())) };\n }\n}\n\n/**\n * Test harness for `<wr-donut-chart>`.\n *\n * **The ring itself is unreadable, and that is by design.** The slices are SVG\n * paths inside a `role=\"img\"` drawing: a screen reader is given that drawing's\n * `aria-label` and nothing else, and a spec cannot get a label or a value off a\n * path's `d`. {@link getLegend} is where the numbers are — which is also the\n * argument for keeping `showLegend` on, since with it off the only other text is\n * whatever {@link getCenterValue} and {@link getCenterLabel} were given, unless\n * `dataTable` is on: {@link getTableRows} then reads every slice shown, with its share.\n *\n * The name is read off the `<svg>` rather than off the surface that wraps it, and\n * the two are not interchangeable: `img` makes its whole subtree presentational, so\n * a name on the wrapper would take the centre text down with it.\n *\n * {@link getSliceCount} is therefore the one thing the ring answers: how many\n * wedges were drawn. Compare it with the legend's length to catch a slice that was\n * filtered out of one and not the other — apart from a slice hidden through\n * `hiddenSegments`, which keeps its legend row and draws no wedge by design;\n * {@link getLegendHarness} says which rows those are.\n *\n * @example\n * ```ts\n * const chart = await loader.getHarness(WrDonutChartHarness);\n *\n * expect(await chart.getSliceCount()).toBe(3);\n * expect(await chart.getLegend()).toEqual([\n * { label: 'Direct', value: '48' },\n * { label: 'Search', value: '32' },\n * { label: 'Social', value: '20' },\n * ]);\n * ```\n *\n * @see https://ngwr.dev/guides/testing\n */\nexport class WrDonutChartHarness extends ComponentHarness {\n static hostSelector = 'wr-donut-chart';\n\n /** Build a predicate that narrows the query — pass to `getHarness` / `getAllHarnesses`. */\n static with(options: WrDonutChartHarnessFilters = {}): HarnessPredicate<WrDonutChartHarness> {\n return new HarnessPredicate(WrDonutChartHarness, options)\n .addOption('ariaLabel', options.ariaLabel, (harness, label) =>\n HarnessPredicate.stringMatches(harness.getAccessibleName(), label)\n )\n .addOption('sliceLabel', options.sliceLabel, async (harness, label) => {\n for (const entry of await harness.getLegend()) {\n if (await HarnessPredicate.stringMatches(entry.label, label)) return true;\n }\n return false;\n });\n }\n\n /** The name the ring announces — the whole chart's, since the slices announce nothing. */\n async getAccessibleName(): Promise<string | null> {\n return (await this.locatorFor('.wr-donut-chart__surface svg')()).getAttribute('aria-label');\n }\n\n /**\n * How many wedges were drawn. A hidden slice draws none, and nor does a chart that is\n * empty, loading or failed. The invisible hover target a sliver gets over the ring\n * (`.wr-donut-chart__hit`) and the track an empty ring keeps (`.wr-donut-chart__track`)\n * are not wedges and are not counted.\n */\n async getSliceCount(): Promise<number> {\n return (await this.locatorForAll('.wr-donut-chart__slice')()).length;\n }\n\n /**\n * Whether the chart is a pie (`pie`), read off its `wr-donut-chart--pie` modifier.\n * Not whether the slices reach the centre — a `thickness` of 0 does that too, and keeps\n * the centre text — since a path's `d` is not read, for the reason given in the class\n * note. A pie renders no centre text: {@link getCenterValue} and {@link getCenterLabel}\n * answer `null` for it whatever was bound.\n */\n async isPie(): Promise<boolean> {\n return (await this.host()).hasClass('wr-donut-chart--pie');\n }\n\n /**\n * Whether the legend is rendered: `showLegend` is not off, `legendPosition` is not\n * `none`, and there are two segments or more - or one, with `showLegend` set.\n */\n async hasLegend(): Promise<boolean> {\n return (await this.locatorForOptional('.wr-donut-chart__legend')()) !== null;\n }\n\n /**\n * The legend as a {@link WrChartLegendHarness}: each row's key and its hidden state\n * and, with `toggleableLegend`, the toggles that show and hide a slice. Not the same\n * thing as {@link getLegend}, which reads the rows' text and stays as it was.\n *\n * Throws when the chart draws no legend (`showLegend` off, `legendPosition=\"none\"`, no\n * segments, or a single one under `showLegend=\"auto\"`) rather than answering with an\n * empty one: {@link hasLegend} is the question for that.\n */\n async getLegendHarness(): Promise<WrChartLegendHarness> {\n const legend = await this.locatorForOptional(WrChartLegendHarness)();\n if (!legend) {\n throw new Error(\n 'WrDonutChartHarness.getLegendHarness(): the chart draws no legend — `showLegend` is off or there are no ' +\n 'segments. Ask hasLegend() first.'\n );\n }\n return legend;\n }\n\n /** The legend rows in order — the only textual form the data has. Hidden slices included. */\n async getLegend(): Promise<WrDonutChartLegendEntry[]> {\n const labels = await this.locatorForAll('.wr-donut-chart__legend-label')();\n const values = await this.locatorForAll('.wr-donut-chart__legend-value')();\n\n return Promise.all(\n labels.map(async (label, index) => ({\n label: await label.text(),\n value: (await values[index]?.text()) ?? '',\n }))\n );\n }\n\n /** Whether the hidden data table is rendered (`dataTable`, while the chart draws its slices). */\n async hasDataTable(): Promise<boolean> {\n return (await this.locatorForOptional('.wr-chart-table')()) !== null;\n }\n\n /**\n * The data table's column headings: the value's name and the share's.\n *\n * Throws when the chart renders no table (`dataTable` off, or a state in the slices'\n * place) rather than answering with no columns.\n */\n async getTableColumns(): Promise<string[]> {\n await this.assertDataTable('getTableColumns');\n const headings = await this.locatorForAll('.wr-chart-table thead th[scope=\"col\"]')();\n return Promise.all(headings.map(heading => heading.text()));\n }\n\n /**\n * The data table's rows, one per slice shown, in the data's own order: its label, its\n * value and its share of the ring, as a screen reader walks them. A slice hidden\n * through `hiddenSegments` has no row, and one that draws nothing an empty share.\n *\n * Throws when the chart renders no table, for the reason {@link getTableColumns} gives.\n */\n async getTableRows(): Promise<WrDonutChartTableRow[]> {\n await this.assertDataTable('getTableRows');\n const rows = await this.locatorForAll(TableRowHarness)();\n return Promise.all(rows.map(row => row.read()));\n }\n\n /** The big number in the middle, or `null` when the chart has none — a pie never has. */\n async getCenterValue(): Promise<string | null> {\n const center = await this.locatorForOptional('.wr-donut-chart__center-value')();\n return center ? center.text() : null;\n }\n\n /** The caption under the centre value, or `null` — a pie never has one. */\n async getCenterLabel(): Promise<string | null> {\n const center = await this.locatorForOptional('.wr-donut-chart__center-label')();\n return center ? center.text() : null;\n }\n\n /**\n * The chart's outer size in pixels, read off the `style` ATTRIBUTE.\n *\n * NOT `getCssValue()`, which is `getComputedStyle()` — the same rule this\n * file's class note already states and this method alone broke. A computed\n * read answers from the LAID-OUT box, so it agrees with the inline value in\n * jsdom (which lays nothing out and echoes the declaration) and disagrees in a\n * browser, where sub-pixel rounding turns a declared 240 into 239.5. A harness\n * that answers differently in the two places it runs is worse than one that\n * refuses.\n */\n async getSize(): Promise<number> {\n const style = await (await this.locatorFor('.wr-donut-chart__surface')()).getAttribute('style');\n const match = /width:\\s*([\\d.]+)px/.exec(style ?? '');\n if (!match) {\n throw new Error(\n `WrDonutChartHarness.getSize(): no inline width on .wr-donut-chart__surface (style: \"${style ?? ''}\"). ` +\n 'The component writes one unconditionally, so its absence is the bug rather than a zero.'\n );\n }\n return Number.parseFloat(match[1]);\n }\n\n private async assertDataTable(method: string): Promise<void> {\n if (!(await this.hasDataTable())) {\n throw new Error(\n `WrDonutChartHarness.${method}(): the chart ren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AAS,EAAE;EACpD,IAAI,CAAC,OACH,MAAM,IAAI,MACR,uFAAuF,SAAS,GAAE,4FACP;EAG/F,OAAO,OAAO,WAAW,MAAM,EAAE;CACnC;CAEQ,MAAM,gBAAgB,QAAc;EAC1C,IAAI,CAAE,MAAM,KAAK,aAAY,GAC3B,MAAM,IAAI,MACR,uBAAuB,OAAM,sHACwB;CAG3D"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as i0 from "@angular/core";
|
|
2
|
-
import { Component, ViewEncapsulation, computed, input, model, viewChild } from "@angular/core";
|
|
2
|
+
import { Component, LOCALE_ID, ViewEncapsulation, computed, inject, input, model, viewChild } from "@angular/core";
|
|
3
3
|
import { coerceBooleanProperty, coerceNumberProperty } from "@angular/cdk/coercion";
|
|
4
4
|
import { NgTemplateOutlet } from "@angular/common";
|
|
5
5
|
import { wrCheckStyles } from "ngwr/utils";
|
|
6
|
-
import { useI18nText } from "ngwr/i18n";
|
|
6
|
+
import { useI18nText, wrReadI18nText } from "ngwr/i18n";
|
|
7
7
|
import { WR_CHART_LEGEND_BLOCK, WrChartLegend } from "ngwr/charts/chart-legend";
|
|
8
|
-
import { WrChartState, useChartHover, useChartNumbers, useChartState, wrChartColor } from "ngwr/charts/core";
|
|
8
|
+
import { WrChartState, WrChartTable, useChartHover, useChartNumbers, useChartState, wrChartColor, wrChartNumberFormat } from "ngwr/charts/core";
|
|
9
9
|
import { useChartTooltip, wrCoerceChartTooltip } from "ngwr/popover";
|
|
10
10
|
/**
|
|
11
11
|
* @license
|
|
@@ -76,7 +76,22 @@ var WrDonutChart = class WrDonutChart {
|
|
|
76
76
|
transform: wrCoerceChartTooltip
|
|
77
77
|
});
|
|
78
78
|
valueFormat = input(null, ...ngDevMode ? [{ debugName: "valueFormat" }] : /* istanbul ignore next */ []);
|
|
79
|
+
dataTable = input(false, {
|
|
80
|
+
...ngDevMode ? { debugName: "dataTable" } : /* istanbul ignore next */ {},
|
|
81
|
+
transform: coerceBooleanProperty
|
|
82
|
+
});
|
|
83
|
+
valueName = wrReadI18nText("donutChart.value", "Value");
|
|
84
|
+
shareName = wrReadI18nText("donutChart.share", "Share");
|
|
79
85
|
numbers = useChartNumbers(this.valueFormat);
|
|
86
|
+
locale = inject(LOCALE_ID);
|
|
87
|
+
shares = wrChartNumberFormat(this.locale, {
|
|
88
|
+
style: "percent",
|
|
89
|
+
maximumFractionDigits: 1
|
|
90
|
+
});
|
|
91
|
+
smallShares = wrChartNumberFormat(this.locale, {
|
|
92
|
+
style: "percent",
|
|
93
|
+
maximumSignificantDigits: 2
|
|
94
|
+
});
|
|
80
95
|
hidden = computed(() => new Set(this.hiddenSegments()), ...ngDevMode ? [{ debugName: "hidden" }] : /* istanbul ignore next */ []);
|
|
81
96
|
svg = viewChild("svg", ...ngDevMode ? [{ debugName: "svg" }] : /* istanbul ignore next */ []);
|
|
82
97
|
outerR = 50;
|
|
@@ -209,6 +224,17 @@ var WrDonutChart = class WrDonutChart {
|
|
|
209
224
|
loadingLabel: this.loadingLabel,
|
|
210
225
|
errorLabel: this.errorLabel
|
|
211
226
|
});
|
|
227
|
+
tableData = computed(() => ({
|
|
228
|
+
caption: this.resolvedAriaLabel(),
|
|
229
|
+
columns: [this.valueName(), this.shareName()],
|
|
230
|
+
groups: [{ rows: this.slices().filter((slice) => !slice.hidden).map((slice) => {
|
|
231
|
+
const share = slice.percent / 100;
|
|
232
|
+
return {
|
|
233
|
+
header: slice.label,
|
|
234
|
+
cells: [slice.text, share > 0 ? (share < .01 ? this.smallShares : this.shares).format(share) : ""]
|
|
235
|
+
};
|
|
236
|
+
}) }]
|
|
237
|
+
}), ...ngDevMode ? [{ debugName: "tableData" }] : /* istanbul ignore next */ []);
|
|
212
238
|
track = computed(() => this.state() || this.slices().every((slice) => !slice.path) ? this.arcPath(0, Math.PI * 2) : null, ...ngDevMode ? [{ debugName: "track" }] : /* istanbul ignore next */ []);
|
|
213
239
|
tip = useChartTooltip(this.tooltip, (index) => {
|
|
214
240
|
const slice = this.slices()[index];
|
|
@@ -412,6 +438,13 @@ var WrDonutChart = class WrDonutChart {
|
|
|
412
438
|
isSignal: true,
|
|
413
439
|
isRequired: false,
|
|
414
440
|
transformFunction: null
|
|
441
|
+
},
|
|
442
|
+
dataTable: {
|
|
443
|
+
classPropertyName: "dataTable",
|
|
444
|
+
publicName: "dataTable",
|
|
445
|
+
isSignal: true,
|
|
446
|
+
isRequired: false,
|
|
447
|
+
transformFunction: null
|
|
415
448
|
}
|
|
416
449
|
},
|
|
417
450
|
outputs: { hiddenSegments: "hiddenSegmentsChange" },
|
|
@@ -431,7 +464,7 @@ var WrDonutChart = class WrDonutChart {
|
|
|
431
464
|
isSignal: true
|
|
432
465
|
}],
|
|
433
466
|
ngImport: i0,
|
|
434
|
-
template: "@let shown = state();\n\n<!-- The legend, drawn before the drawing or after it so it is in the DOM where it is on\n screen: a toggleable legend's rows are tab stops, and their order follows it. The key\n is `aria-hidden`: the row's text is its name, and the dot carries no word of its own. -->\n<ng-template #legend>\n <ul\n wr-chart-legend\n class=\"wr-donut-chart__legend\"\n [items]=\"legendItems()\"\n [position]=\"legendPosition()\"\n [toggleable]=\"toggleableLegend()\"\n [(hiddenSeries)]=\"hiddenSegments\"\n ></ul>\n</ng-template>\n\n@if (legendShown() && legendFirst()) {\n <ng-container [ngTemplateOutlet]=\"legend\" />\n}\n\n<div class=\"wr-donut-chart__surface\" [style.width.px]=\"size()\">\n <!-- The name sits on the DRAWING, not on this wrapper. `img` is a\n children-presentational role, so with it out here WebKit dropped the whole\n subtree — including the centre value and label, which are real text and are\n the headline datum the legend does not carry. -->\n <svg #svg viewBox=\"0 0 100 100\" role=\"img\" [attr.aria-label]=\"resolvedAriaLabel()\">\n @if (track(); as ring) {\n <!-- The frame the chart keeps with no slice to draw: the ring itself, as a track. -->\n <path class=\"wr-donut-chart__track\" [attr.d]=\"ring\" />\n }\n <!-- Every slice is stroked in the SURFACE colour (`--wr-donut-chart-slice-gap-color`,\n from the stylesheet), so adjacent arcs are separated by a visible gap rather than\n by the boundary between two fills. Without it the only thing dividing two slices\n is the colour change itself, and for a reader who cannot separate hue two\n neighbours merge into one arc and the chart reads as having fewer slices than it\n has. A gap is a shape, and it survives greyscale, printing and a monochrome\n display. The stroke does not scale with the drawing, so the gap is the same\n pixels at any `size`; its width is the stylesheet's. -->\n @if (!shown) {\n @for (slice of slices(); track $index) {\n <!-- A hidden slice draws nothing at all; the index stays the slice's own, which is\n what the tooltip looks it up by. `data-wr-index` is what the chart's one hover\n listener reads, and `data-wr-series` the slice's legend row, which the hover\n dims by. -->\n @if (!slice.hidden) {\n <path\n class=\"wr-donut-chart__slice\"\n [attr.d]=\"slice.path\"\n [attr.fill]=\"slice.color\"\n [style.--wr-donut-chart-slice-color]=\"slice.color\"\n [attr.data-wr-index]=\"$index\"\n [attr.data-wr-series]=\"$index\"\n stroke-linejoin=\"round\"\n vector-effect=\"non-scaling-stroke\"\n />\n }\n }\n <!-- A sliver's wider hover target in a pie, filled with nothing: see `hits`, which is\n empty for the ring and with the tooltip off. Last, so it wins the pointer over the\n slices it reaches into; `fill`, so the unpainted stroke is not hit-tested and the\n edges stay where `hits` put them. It carries its slice's index and legend row, so\n the hover reads it as the slice. -->\n @for (hit of hits(); track hit.index) {\n <path\n class=\"wr-donut-chart__hit\"\n [attr.d]=\"hit.path\"\n [attr.data-wr-index]=\"hit.index\"\n [attr.data-wr-series]=\"hit.index\"\n fill=\"none\"\n pointer-events=\"fill\"\n />\n }\n }\n </svg>\n <!-- Never with `pie`: a pie has no hole to print in. -->\n @if (showCenter()) {\n <div class=\"wr-donut-chart__center\">\n @if (centerValue()) {\n <div class=\"wr-donut-chart__center-value\">{{ centerValue() }}</div>\n }\n @if (centerLabel()) {\n <div class=\"wr-donut-chart__center-label\">{{ centerLabel() }}</div>\n }\n </div>\n }\n @if (shown) {\n <!-- Empty, loading or failed: the message, over the track the chart keeps. -->\n <wr-chart-state [kind]=\"shown.kind\" [label]=\"shown.label\" />\n }\n</div>\n\n@if (legendShown() && !legendFirst()) {\n <ng-container [ngTemplateOutlet]=\"legend\" />\n}\n",
|
|
467
|
+
template: "@let shown = state();\n\n<!-- The legend, drawn before the drawing or after it so it is in the DOM where it is on\n screen: a toggleable legend's rows are tab stops, and their order follows it. The key\n is `aria-hidden`: the row's text is its name, and the dot carries no word of its own. -->\n<ng-template #legend>\n <ul\n wr-chart-legend\n class=\"wr-donut-chart__legend\"\n [items]=\"legendItems()\"\n [position]=\"legendPosition()\"\n [toggleable]=\"toggleableLegend()\"\n [(hiddenSeries)]=\"hiddenSegments\"\n ></ul>\n</ng-template>\n\n@if (legendShown() && legendFirst()) {\n <ng-container [ngTemplateOutlet]=\"legend\" />\n}\n\n<div class=\"wr-donut-chart__surface\" [style.width.px]=\"size()\">\n <!-- The name sits on the DRAWING, not on this wrapper. `img` is a\n children-presentational role, so with it out here WebKit dropped the whole\n subtree — including the centre value and label, which are real text and are\n the headline datum the legend does not carry. -->\n <svg #svg viewBox=\"0 0 100 100\" role=\"img\" [attr.aria-label]=\"resolvedAriaLabel()\">\n @if (track(); as ring) {\n <!-- The frame the chart keeps with no slice to draw: the ring itself, as a track. -->\n <path class=\"wr-donut-chart__track\" [attr.d]=\"ring\" />\n }\n <!-- Every slice is stroked in the SURFACE colour (`--wr-donut-chart-slice-gap-color`,\n from the stylesheet), so adjacent arcs are separated by a visible gap rather than\n by the boundary between two fills. Without it the only thing dividing two slices\n is the colour change itself, and for a reader who cannot separate hue two\n neighbours merge into one arc and the chart reads as having fewer slices than it\n has. A gap is a shape, and it survives greyscale, printing and a monochrome\n display. The stroke does not scale with the drawing, so the gap is the same\n pixels at any `size`; its width is the stylesheet's. -->\n @if (!shown) {\n @for (slice of slices(); track $index) {\n <!-- A hidden slice draws nothing at all; the index stays the slice's own, which is\n what the tooltip looks it up by. `data-wr-index` is what the chart's one hover\n listener reads, and `data-wr-series` the slice's legend row, which the hover\n dims by. -->\n @if (!slice.hidden) {\n <path\n class=\"wr-donut-chart__slice\"\n [attr.d]=\"slice.path\"\n [attr.fill]=\"slice.color\"\n [style.--wr-donut-chart-slice-color]=\"slice.color\"\n [attr.data-wr-index]=\"$index\"\n [attr.data-wr-series]=\"$index\"\n stroke-linejoin=\"round\"\n vector-effect=\"non-scaling-stroke\"\n />\n }\n }\n <!-- A sliver's wider hover target in a pie, filled with nothing: see `hits`, which is\n empty for the ring and with the tooltip off. Last, so it wins the pointer over the\n slices it reaches into; `fill`, so the unpainted stroke is not hit-tested and the\n edges stay where `hits` put them. It carries its slice's index and legend row, so\n the hover reads it as the slice. -->\n @for (hit of hits(); track hit.index) {\n <path\n class=\"wr-donut-chart__hit\"\n [attr.d]=\"hit.path\"\n [attr.data-wr-index]=\"hit.index\"\n [attr.data-wr-series]=\"hit.index\"\n fill=\"none\"\n pointer-events=\"fill\"\n />\n }\n }\n </svg>\n <!-- Never with `pie`: a pie has no hole to print in. -->\n @if (showCenter()) {\n <div class=\"wr-donut-chart__center\">\n @if (centerValue()) {\n <div class=\"wr-donut-chart__center-value\">{{ centerValue() }}</div>\n }\n @if (centerLabel()) {\n <div class=\"wr-donut-chart__center-label\">{{ centerLabel() }}</div>\n }\n </div>\n }\n @if (shown) {\n <!-- Empty, loading or failed: the message, over the track the chart keeps. -->\n <wr-chart-state [kind]=\"shown.kind\" [label]=\"shown.label\" />\n }\n</div>\n\n@if (legendShown() && !legendFirst()) {\n <ng-container [ngTemplateOutlet]=\"legend\" />\n}\n\n@if (dataTable() && !shown) {\n <!-- The figures for a screen reader, beside the drawing rather than inside its `img`,\n which would make them presentational. Clipped to nothing by its own stylesheet, so\n it takes no room and draws nothing. -->\n <wr-chart-table [data]=\"tableData()\" />\n}\n",
|
|
435
468
|
dependencies: [
|
|
436
469
|
{
|
|
437
470
|
kind: "directive",
|
|
@@ -462,6 +495,12 @@ var WrDonutChart = class WrDonutChart {
|
|
|
462
495
|
type: WrChartState,
|
|
463
496
|
selector: "wr-chart-state",
|
|
464
497
|
inputs: ["kind", "label"]
|
|
498
|
+
},
|
|
499
|
+
{
|
|
500
|
+
kind: "component",
|
|
501
|
+
type: WrChartTable,
|
|
502
|
+
selector: "wr-chart-table",
|
|
503
|
+
inputs: ["data"]
|
|
465
504
|
}
|
|
466
505
|
],
|
|
467
506
|
viewProviders: [{
|
|
@@ -490,13 +529,14 @@ i0.ɵɵngDeclareClassMetadata({
|
|
|
490
529
|
imports: [
|
|
491
530
|
NgTemplateOutlet,
|
|
492
531
|
WrChartLegend,
|
|
493
|
-
WrChartState
|
|
532
|
+
WrChartState,
|
|
533
|
+
WrChartTable
|
|
494
534
|
],
|
|
495
535
|
viewProviders: [{
|
|
496
536
|
provide: WR_CHART_LEGEND_BLOCK,
|
|
497
537
|
useValue: "wr-donut-chart"
|
|
498
538
|
}],
|
|
499
|
-
template: "@let shown = state();\n\n<!-- The legend, drawn before the drawing or after it so it is in the DOM where it is on\n screen: a toggleable legend's rows are tab stops, and their order follows it. The key\n is `aria-hidden`: the row's text is its name, and the dot carries no word of its own. -->\n<ng-template #legend>\n <ul\n wr-chart-legend\n class=\"wr-donut-chart__legend\"\n [items]=\"legendItems()\"\n [position]=\"legendPosition()\"\n [toggleable]=\"toggleableLegend()\"\n [(hiddenSeries)]=\"hiddenSegments\"\n ></ul>\n</ng-template>\n\n@if (legendShown() && legendFirst()) {\n <ng-container [ngTemplateOutlet]=\"legend\" />\n}\n\n<div class=\"wr-donut-chart__surface\" [style.width.px]=\"size()\">\n <!-- The name sits on the DRAWING, not on this wrapper. `img` is a\n children-presentational role, so with it out here WebKit dropped the whole\n subtree — including the centre value and label, which are real text and are\n the headline datum the legend does not carry. -->\n <svg #svg viewBox=\"0 0 100 100\" role=\"img\" [attr.aria-label]=\"resolvedAriaLabel()\">\n @if (track(); as ring) {\n <!-- The frame the chart keeps with no slice to draw: the ring itself, as a track. -->\n <path class=\"wr-donut-chart__track\" [attr.d]=\"ring\" />\n }\n <!-- Every slice is stroked in the SURFACE colour (`--wr-donut-chart-slice-gap-color`,\n from the stylesheet), so adjacent arcs are separated by a visible gap rather than\n by the boundary between two fills. Without it the only thing dividing two slices\n is the colour change itself, and for a reader who cannot separate hue two\n neighbours merge into one arc and the chart reads as having fewer slices than it\n has. A gap is a shape, and it survives greyscale, printing and a monochrome\n display. The stroke does not scale with the drawing, so the gap is the same\n pixels at any `size`; its width is the stylesheet's. -->\n @if (!shown) {\n @for (slice of slices(); track $index) {\n <!-- A hidden slice draws nothing at all; the index stays the slice's own, which is\n what the tooltip looks it up by. `data-wr-index` is what the chart's one hover\n listener reads, and `data-wr-series` the slice's legend row, which the hover\n dims by. -->\n @if (!slice.hidden) {\n <path\n class=\"wr-donut-chart__slice\"\n [attr.d]=\"slice.path\"\n [attr.fill]=\"slice.color\"\n [style.--wr-donut-chart-slice-color]=\"slice.color\"\n [attr.data-wr-index]=\"$index\"\n [attr.data-wr-series]=\"$index\"\n stroke-linejoin=\"round\"\n vector-effect=\"non-scaling-stroke\"\n />\n }\n }\n <!-- A sliver's wider hover target in a pie, filled with nothing: see `hits`, which is\n empty for the ring and with the tooltip off. Last, so it wins the pointer over the\n slices it reaches into; `fill`, so the unpainted stroke is not hit-tested and the\n edges stay where `hits` put them. It carries its slice's index and legend row, so\n the hover reads it as the slice. -->\n @for (hit of hits(); track hit.index) {\n <path\n class=\"wr-donut-chart__hit\"\n [attr.d]=\"hit.path\"\n [attr.data-wr-index]=\"hit.index\"\n [attr.data-wr-series]=\"hit.index\"\n fill=\"none\"\n pointer-events=\"fill\"\n />\n }\n }\n </svg>\n <!-- Never with `pie`: a pie has no hole to print in. -->\n @if (showCenter()) {\n <div class=\"wr-donut-chart__center\">\n @if (centerValue()) {\n <div class=\"wr-donut-chart__center-value\">{{ centerValue() }}</div>\n }\n @if (centerLabel()) {\n <div class=\"wr-donut-chart__center-label\">{{ centerLabel() }}</div>\n }\n </div>\n }\n @if (shown) {\n <!-- Empty, loading or failed: the message, over the track the chart keeps. -->\n <wr-chart-state [kind]=\"shown.kind\" [label]=\"shown.label\" />\n }\n</div>\n\n@if (legendShown() && !legendFirst()) {\n <ng-container [ngTemplateOutlet]=\"legend\" />\n}\n"
|
|
539
|
+
template: "@let shown = state();\n\n<!-- The legend, drawn before the drawing or after it so it is in the DOM where it is on\n screen: a toggleable legend's rows are tab stops, and their order follows it. The key\n is `aria-hidden`: the row's text is its name, and the dot carries no word of its own. -->\n<ng-template #legend>\n <ul\n wr-chart-legend\n class=\"wr-donut-chart__legend\"\n [items]=\"legendItems()\"\n [position]=\"legendPosition()\"\n [toggleable]=\"toggleableLegend()\"\n [(hiddenSeries)]=\"hiddenSegments\"\n ></ul>\n</ng-template>\n\n@if (legendShown() && legendFirst()) {\n <ng-container [ngTemplateOutlet]=\"legend\" />\n}\n\n<div class=\"wr-donut-chart__surface\" [style.width.px]=\"size()\">\n <!-- The name sits on the DRAWING, not on this wrapper. `img` is a\n children-presentational role, so with it out here WebKit dropped the whole\n subtree — including the centre value and label, which are real text and are\n the headline datum the legend does not carry. -->\n <svg #svg viewBox=\"0 0 100 100\" role=\"img\" [attr.aria-label]=\"resolvedAriaLabel()\">\n @if (track(); as ring) {\n <!-- The frame the chart keeps with no slice to draw: the ring itself, as a track. -->\n <path class=\"wr-donut-chart__track\" [attr.d]=\"ring\" />\n }\n <!-- Every slice is stroked in the SURFACE colour (`--wr-donut-chart-slice-gap-color`,\n from the stylesheet), so adjacent arcs are separated by a visible gap rather than\n by the boundary between two fills. Without it the only thing dividing two slices\n is the colour change itself, and for a reader who cannot separate hue two\n neighbours merge into one arc and the chart reads as having fewer slices than it\n has. A gap is a shape, and it survives greyscale, printing and a monochrome\n display. The stroke does not scale with the drawing, so the gap is the same\n pixels at any `size`; its width is the stylesheet's. -->\n @if (!shown) {\n @for (slice of slices(); track $index) {\n <!-- A hidden slice draws nothing at all; the index stays the slice's own, which is\n what the tooltip looks it up by. `data-wr-index` is what the chart's one hover\n listener reads, and `data-wr-series` the slice's legend row, which the hover\n dims by. -->\n @if (!slice.hidden) {\n <path\n class=\"wr-donut-chart__slice\"\n [attr.d]=\"slice.path\"\n [attr.fill]=\"slice.color\"\n [style.--wr-donut-chart-slice-color]=\"slice.color\"\n [attr.data-wr-index]=\"$index\"\n [attr.data-wr-series]=\"$index\"\n stroke-linejoin=\"round\"\n vector-effect=\"non-scaling-stroke\"\n />\n }\n }\n <!-- A sliver's wider hover target in a pie, filled with nothing: see `hits`, which is\n empty for the ring and with the tooltip off. Last, so it wins the pointer over the\n slices it reaches into; `fill`, so the unpainted stroke is not hit-tested and the\n edges stay where `hits` put them. It carries its slice's index and legend row, so\n the hover reads it as the slice. -->\n @for (hit of hits(); track hit.index) {\n <path\n class=\"wr-donut-chart__hit\"\n [attr.d]=\"hit.path\"\n [attr.data-wr-index]=\"hit.index\"\n [attr.data-wr-series]=\"hit.index\"\n fill=\"none\"\n pointer-events=\"fill\"\n />\n }\n }\n </svg>\n <!-- Never with `pie`: a pie has no hole to print in. -->\n @if (showCenter()) {\n <div class=\"wr-donut-chart__center\">\n @if (centerValue()) {\n <div class=\"wr-donut-chart__center-value\">{{ centerValue() }}</div>\n }\n @if (centerLabel()) {\n <div class=\"wr-donut-chart__center-label\">{{ centerLabel() }}</div>\n }\n </div>\n }\n @if (shown) {\n <!-- Empty, loading or failed: the message, over the track the chart keeps. -->\n <wr-chart-state [kind]=\"shown.kind\" [label]=\"shown.label\" />\n }\n</div>\n\n@if (legendShown() && !legendFirst()) {\n <ng-container [ngTemplateOutlet]=\"legend\" />\n}\n\n@if (dataTable() && !shown) {\n <!-- The figures for a screen reader, beside the drawing rather than inside its `img`,\n which would make them presentational. Clipped to nothing by its own stylesheet, so\n it takes no room and draws nothing. -->\n <wr-chart-table [data]=\"tableData()\" />\n}\n"
|
|
500
540
|
}]
|
|
501
541
|
}],
|
|
502
542
|
ctorParameters: () => [],
|
|
@@ -656,6 +696,14 @@ i0.ɵɵngDeclareClassMetadata({
|
|
|
656
696
|
required: false
|
|
657
697
|
}]
|
|
658
698
|
}],
|
|
699
|
+
dataTable: [{
|
|
700
|
+
type: i0.Input,
|
|
701
|
+
args: [{
|
|
702
|
+
isSignal: true,
|
|
703
|
+
alias: "dataTable",
|
|
704
|
+
required: false
|
|
705
|
+
}]
|
|
706
|
+
}],
|
|
659
707
|
svg: [{
|
|
660
708
|
type: i0.ViewChild,
|
|
661
709
|
args: ["svg", { isSignal: true }]
|