@pioneer-code/pioneer-charts 22.2.15 → 22.2.17

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.
@@ -1,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { Injectable, signal, untracked, inject, ApplicationRef, DOCUMENT, DestroyRef, afterNextRender, TemplateRef, Directive, input, viewChild, contentChild, effect, ViewEncapsulation, Component, model, output, computed } from '@angular/core';
2
+ import { Injectable, signal, untracked, inject, DOCUMENT, ApplicationRef, DestroyRef, afterNextRender, TemplateRef, Directive, input, viewChild, contentChild, effect, ViewEncapsulation, Component, model, output, computed } from '@angular/core';
3
3
  import { takeUntilDestroyed, outputFromObservable } from '@angular/core/rxjs-interop';
4
4
  import { color } from 'd3-color';
5
5
  import { scaleLinear, scaleBand, scaleTime } from 'd3-scale';
@@ -10,8 +10,8 @@ import { axisLeft, axisBottom } from 'd3-axis';
10
10
  import { format } from 'd3-format';
11
11
  import { debounceTime } from 'rxjs/operators';
12
12
  import { range } from 'd3-array';
13
+ import { zoom, zoomIdentity } from 'd3-zoom';
13
14
  import { line, area, arc, pie } from 'd3-shape';
14
- import { zoom } from 'd3-zoom';
15
15
  import { interpolate } from 'd3-interpolate';
16
16
 
17
17
  /**
@@ -385,6 +385,9 @@ class PcacAxisBuilder {
385
385
  .attr('class', 'pcac-y-axis')
386
386
  // Axes are raised above the interactive overlays (see raiseAxes) and take no mouse events
387
387
  .attr('pointer-events', 'none')
388
+ // Nor are they read out: the marks' own names carry each key and value (see marks.ts), and
389
+ // every tick label as well would only bury them.
390
+ .attr('aria-hidden', 'true')
388
391
  .classed('pcac-axis-tick-marks', config.yAxis.tickSize !== undefined)
389
392
  .classed('pcac-axis-line', config.yAxis.showLine)
390
393
  .call(yAxis)
@@ -406,6 +409,7 @@ class PcacAxisBuilder {
406
409
  const group = config.svg.append('g')
407
410
  .attr('class', 'pcac-x-axis')
408
411
  .attr('pointer-events', 'none')
412
+ .attr('aria-hidden', 'true')
409
413
  .classed('pcac-axis-tick-marks', config.xAxis.tickSize !== undefined)
410
414
  .classed('pcac-axis-line', config.xAxis.showLine)
411
415
  .attr('transform', 'translate(0,' + config.height + ')')
@@ -491,6 +495,7 @@ class PcacGridBuilder {
491
495
  drawVerticalGrid(config) {
492
496
  config.svg.append('g')
493
497
  .attr('class', 'pcac-grid pcac-grid-vertical')
498
+ .attr('aria-hidden', 'true')
494
499
  .style('--pcac-grid-color', () => config.color ?? null)
495
500
  .selectAll('g.rule')
496
501
  .data(gridLines(config.xScale, config.numberOfTicks))
@@ -507,6 +512,7 @@ class PcacGridBuilder {
507
512
  drawHorizontalGrid(config) {
508
513
  config.svg.append('g')
509
514
  .attr('class', 'pcac-grid pcac-grid-horizontal')
515
+ .attr('aria-hidden', 'true')
510
516
  .style('--pcac-grid-color', () => config.color ?? null)
511
517
  .selectAll('g.pcac-grid-rule')
512
518
  .data(gridLines(config.yScale, config.numberOfTicks))
@@ -529,7 +535,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImpor
529
535
  }] });
530
536
 
531
537
  class PcacColorService {
532
- primary = '#43425d';
533
538
  primaryLight = '#a3a1fb';
534
539
  success = '#5ee2a0';
535
540
  danger = '#ff6565';
@@ -597,11 +602,6 @@ class PcacColorService {
597
602
  this.customScale = colors.length ? [...colors] : null;
598
603
  this.changed();
599
604
  }
600
- /** @deprecated No chart reads the primary color; it isn't part of the palette. */
601
- setPrimary(color) {
602
- this.primary = color;
603
- this.changed();
604
- }
605
605
  setPrimaryLight(color) {
606
606
  this.primaryLight = color;
607
607
  this.changed();
@@ -642,8 +642,18 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImpor
642
642
 
643
643
  class PcacTransitionService {
644
644
  transitionDuration = 750;
645
+ document = inject(DOCUMENT);
646
+ /**
647
+ * How long the charts animate - bars growing, lines drawing in, hover fades - or 0 when the user
648
+ * has asked their system to reduce motion, so every chart is drawn in its final state at once.
649
+ * Read on every call rather than once, so changing the setting applies from the next draw on.
650
+ */
645
651
  getTransitionDuration() {
646
- return this.transitionDuration;
652
+ return this.prefersReducedMotion() ? 0 : this.transitionDuration;
653
+ }
654
+ /** `false` where there's no `matchMedia` to ask - server-side rendering, a test environment. */
655
+ prefersReducedMotion() {
656
+ return this.document.defaultView?.matchMedia?.('(prefers-reduced-motion: reduce)').matches ?? false;
647
657
  }
648
658
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacTransitionService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
649
659
  static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacTransitionService, providedIn: 'root' });
@@ -674,6 +684,7 @@ class PcacTooltipBuilder {
674
684
  this.shell ??= select(this.document.body)
675
685
  .append('div')
676
686
  .attr('class', 'pcac-d3-tooltip')
687
+ .attr('id', PcacTooltipBuilder.ID)
677
688
  .attr('role', 'tooltip');
678
689
  return this.shell;
679
690
  }
@@ -691,12 +702,18 @@ class PcacTooltipBuilder {
691
702
  * chart rebuilding or being destroyed would close the tooltip another chart is showing.
692
703
  */
693
704
  owner = null;
705
+ /**
706
+ * The tooltip element's id, for a focused mark's `aria-describedby` (see `PcacChart.focusMark`).
707
+ * One per page, like the element.
708
+ */
709
+ static ID = 'pcac-tooltip';
694
710
  /** Space left between the tooltip and whatever it's placed next to (the cursor or an anchor). */
695
711
  static GAP = 8;
696
712
  /**
697
713
  * Shows the tooltip for a hovered datum. Renders `template` when the chart has one projected;
698
714
  * otherwise falls back to the default key/value content, formatted per `valueFormat`/`keyFormat`.
699
715
  * Placed beside `anchor` when one is given (see `positionBeside`), else above the event's position.
716
+ * `event` can be `null` only with an `anchor`: a tooltip shown for keyboard focus has no pointer.
700
717
  * `owner` is what's showing it (see `hideTooltip`).
701
718
  */
702
719
  showTooltip(event, template, context, valueFormat, keyFormat, anchor, owner) {
@@ -711,7 +728,7 @@ class PcacTooltipBuilder {
711
728
  if (anchor) {
712
729
  this.positionBeside(shell, anchor);
713
730
  }
714
- else {
731
+ else if (event) {
715
732
  this.positionAbove(shell, event);
716
733
  }
717
734
  }
@@ -743,7 +760,7 @@ class PcacTooltipBuilder {
743
760
  */
744
761
  renderDefault(data, valueFormat, keyFormat) {
745
762
  this.destroyView();
746
- const { key, value } = this.getBarTipData(data, valueFormat, keyFormat);
763
+ const { key, value } = tooltipText(data, valueFormat, keyFormat);
747
764
  const shell = this.tooltip
748
765
  .classed('pcac-d3-tooltip-default', true)
749
766
  .html(null)
@@ -852,41 +869,6 @@ class PcacTooltipBuilder {
852
869
  .style('left', x + (view?.scrollX ?? 0) + 'px')
853
870
  .style('top', y + (view?.scrollY ?? 0) + 'px');
854
871
  }
855
- /** The default tooltip's two lines as plain text; `key` is null when the datum has none. */
856
- getBarTipData(data, valueFormat, keyFormat) {
857
- let value = data.value;
858
- let key = data.key;
859
- // Formatted the way the value's axis labels it (see `formatValue`), so the tooltip for a
860
- // point reads like the axis it sits against - `1:30pm`, not `13.5`, on a OneDayHours axis.
861
- // A missing value stays blank rather than being formatted as `0%` / `null F`.
862
- if (value !== null && value !== undefined) {
863
- value = formatValue(valueFormat, value) ?? value;
864
- }
865
- if (key !== null && key !== undefined && key !== '') {
866
- // A key that doesn't parse as a date is shown as it is, rather than as "Invalid Date".
867
- if (keyFormat === PcacFormatEnum.DateTime && !Number.isNaN(new Date(key).getTime())) {
868
- key = new Date(key).toLocaleDateString('en-US', {
869
- day: '2-digit',
870
- month: '2-digit',
871
- year: 'numeric',
872
- hour: '2-digit',
873
- minute: '2-digit',
874
- second: '2-digit'
875
- });
876
- }
877
- else if (keyFormat === PcacFormatEnum.Decimal) {
878
- // Only where the key *is* the x value. Every other x format positions points by index,
879
- // so its axis labels the index, not the key - formatting the key would only make it
880
- // disagree with the axis (and tag text keys with a unit: `Mon` read `Monm` on Minutes).
881
- key = formatValue(keyFormat, key) ?? key;
882
- }
883
- }
884
- // A key of 0 (e.g. hour 0) is a real key; only a missing or empty one leaves the line out.
885
- return {
886
- key: key === null || key === undefined || key === '' ? null : String(key),
887
- value: value === null || value === undefined ? '' : String(value),
888
- };
889
- }
890
872
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacTooltipBuilder, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
891
873
  static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacTooltipBuilder, providedIn: 'root' });
892
874
  }
@@ -896,6 +878,44 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImpor
896
878
  providedIn: 'root',
897
879
  }]
898
880
  }] });
881
+ /**
882
+ * The default tooltip's two lines as plain text; `key` is null when the datum has none. Also what a
883
+ * mark's accessible name is made of (see `PcacChart.markLabel`), so the two read the same.
884
+ */
885
+ function tooltipText(data, valueFormat, keyFormat) {
886
+ let value = data.value;
887
+ let key = data.key;
888
+ // Formatted the way the value's axis labels it (see `formatValue`), so the tooltip for a
889
+ // point reads like the axis it sits against - `1:30pm`, not `13.5`, on a OneDayHours axis.
890
+ // A missing value stays blank rather than being formatted as `0%` / `null F`.
891
+ if (value !== null && value !== undefined) {
892
+ value = formatValue(valueFormat, value) ?? value;
893
+ }
894
+ if (key !== null && key !== undefined && key !== '') {
895
+ // A key that doesn't parse as a date is shown as it is, rather than as "Invalid Date".
896
+ if (keyFormat === PcacFormatEnum.DateTime && !Number.isNaN(new Date(key).getTime())) {
897
+ key = new Date(key).toLocaleDateString('en-US', {
898
+ day: '2-digit',
899
+ month: '2-digit',
900
+ year: 'numeric',
901
+ hour: '2-digit',
902
+ minute: '2-digit',
903
+ second: '2-digit'
904
+ });
905
+ }
906
+ else if (keyFormat === PcacFormatEnum.Decimal) {
907
+ // Only where the key *is* the x value. Every other x format positions points by index,
908
+ // so its axis labels the index, not the key - formatting the key would only make it
909
+ // disagree with the axis (and tag text keys with a unit: `Mon` read `Monm` on Minutes).
910
+ key = formatValue(keyFormat, key) ?? key;
911
+ }
912
+ }
913
+ // A key of 0 (e.g. hour 0) is a real key; only a missing or empty one leaves the line out.
914
+ return {
915
+ key: key === null || key === undefined || key === '' ? null : String(key),
916
+ value: value === null || value === undefined ? '' : String(value),
917
+ };
918
+ }
899
919
 
900
920
  /** The most of its container's width a chart's measured left (label) margin may take. */
901
921
  const MAX_LABEL_MARGIN_SHARE = 0.5;
@@ -1157,6 +1177,33 @@ class PcacChart {
1157
1177
  hideTooltip() {
1158
1178
  this.tooltipBuilder.hideTooltip(this);
1159
1179
  }
1180
+ /**
1181
+ * A mark's accessible name: its parent's key (the bar's group, the point's series), its own key
1182
+ * and its value, formatted as the tooltip formats them - `"Chips, 2024: 680"`.
1183
+ */
1184
+ markLabel(data, options = {}) {
1185
+ const { key, value } = tooltipText(data, options.valueFormat, options.keyFormat);
1186
+ const parentKey = options.parent?.key;
1187
+ const names = [parentKey === null || parentKey === undefined || parentKey === '' ? null : String(parentKey), key]
1188
+ .filter((name) => name !== null);
1189
+ return `${names.join(', ')}${names.length ? ': ' : ''}${value === '' ? 'no value' : value}`;
1190
+ }
1191
+ /**
1192
+ * Keyboard focus on a mark: its tooltip, beside it (there's no pointer to put it above). With a
1193
+ * consumer `pcacTooltip` template, the mark is also described by the tooltip, so a screen reader
1194
+ * reads whatever the template adds to the mark's own name; the default tooltip only repeats it.
1195
+ */
1196
+ showMarkTooltip(element, data, options) {
1197
+ this.showTooltip(null, data, { ...options, anchor: options.anchor ?? element });
1198
+ if (this.tooltipTemplate()) {
1199
+ element.setAttribute('aria-describedby', PcacTooltipBuilder.ID);
1200
+ }
1201
+ }
1202
+ /** Keyboard focus leaving a mark: the undoing of `showMarkTooltip`. */
1203
+ hideMarkTooltip(element) {
1204
+ this.hideTooltip();
1205
+ element.removeAttribute('aria-describedby');
1206
+ }
1160
1207
  /**
1161
1208
  * Builders are provided per chart component, so Angular calls this when the component is
1162
1209
  * destroyed. A chart removed while hovered (an `@if` flip, a route change) gets no `mouseout`,
@@ -1202,7 +1249,10 @@ class PcacChart {
1202
1249
  const container = chartElm.nativeElement.parentNode;
1203
1250
  const containerWidth = container.clientWidth;
1204
1251
  const measuredWidth = containerWidth - this.margin.left - this.margin.right;
1205
- if (measuredWidth <= 0) {
1252
+ // `!(> 0)` rather than `<= 0`, so a width that can't be measured at all - `NaN`, as when a page
1253
+ // is rendered on the server, where there's no layout and `clientWidth` is undefined - also
1254
+ // draws nothing, rather than drawing a chart `NaN` pixels wide.
1255
+ if (!(measuredWidth > 0)) {
1206
1256
  // The previous drawing was just removed above, so nothing is on screen any more. Forget the
1207
1257
  // size it was drawn at, or a container that comes back at that same width (a hidden tab
1208
1258
  // shown again) would read as unchanged to `containerSizeChanged()` and never be redrawn.
@@ -1210,9 +1260,11 @@ class PcacChart {
1210
1260
  return false;
1211
1261
  }
1212
1262
  this.width = measuredWidth;
1213
- // Announced as a single image with a name, rather than as a pile of unlabelled shapes.
1263
+ // A named group of marks, each with its own name and role (see marks.ts), rather than a pile of
1264
+ // unlabelled shapes. (A `role="img"`, which this used to be, would hide the marks inside it from
1265
+ // a screen reader, and keyboard focus on them would announce nothing.)
1214
1266
  select(chartElm.nativeElement)
1215
- .attr('role', 'img')
1267
+ .attr('role', 'group')
1216
1268
  .attr('aria-label', config.ariaLabel || this.chartTypeLabel);
1217
1269
  this.height = this.resolveHeight(container, config);
1218
1270
  this.colors = colors;
@@ -1397,6 +1449,131 @@ function fitText(text, maxWidth) {
1397
1449
  text.textContent = withEllipsis(fits);
1398
1450
  }
1399
1451
 
1452
+ /** Marks the elements `makeMarksAccessible` set up, so navigation can find a chart's marks. */
1453
+ const MARK_ATTR = 'data-pcac-mark';
1454
+ /**
1455
+ * Makes a chart's marks usable from the keyboard and readable by a screen reader, alongside the
1456
+ * pointer handlers they already have.
1457
+ *
1458
+ * Every mark gets a role and a name, but only one of them - the chart's "tab stop" - is in the Tab
1459
+ * order (see `refreshTabStop`): Tab reaches the chart once, and the arrow keys move between its
1460
+ * marks, Home and End to the first and last. A chart of a thousand bars isn't a thousand Tab
1461
+ * presses to get past. Focus does what hovering does (`focus`), and Enter or Space what a click
1462
+ * does (`activate`); Escape hides the tooltip, as moving the pointer away would.
1463
+ *
1464
+ * A mark takes focus from the keyboard only: pressing the pointer on one is kept from focusing it,
1465
+ * so a click doesn't leave a keyboard-style tooltip and focus ring behind on the clicked mark.
1466
+ */
1467
+ function makeMarksAccessible(marks, access) {
1468
+ const skipped = (d) => access.skip?.(d) ?? false;
1469
+ marks
1470
+ .attr(MARK_ATTR, (d) => (skipped(d) ? null : ''))
1471
+ .attr('aria-hidden', (d) => (skipped(d) ? 'true' : null))
1472
+ // An image, with a name, rather than a button: whether the chart's click output has a listener
1473
+ // can't be told from here (the pie, donut, line, area and plot charts' own wrappers always
1474
+ // listen, to pass it on), and a button that does nothing would be a lie. Enter and Space still
1475
+ // do what a click does, and the click listener has browsers report the mark as clickable.
1476
+ .attr('role', (d) => (skipped(d) ? null : 'img'))
1477
+ .attr('aria-label', function (d) {
1478
+ return skipped(d) ? null : access.label(d, this);
1479
+ })
1480
+ .attr('tabindex', (d) => (skipped(d) ? null : -1))
1481
+ // The events are typed plainly as `Event`: with the element type generic here, d3's typings
1482
+ // (@types/d3-selection 3.0.12 on) can't narrow them to `MouseEvent`/`KeyboardEvent`.
1483
+ .on('mousedown.pcac-mark', (event) => event.preventDefault())
1484
+ .on('focus.pcac-mark', function (_event, d) {
1485
+ access.focus(this, d);
1486
+ })
1487
+ .on('blur.pcac-mark', function (_event, d) {
1488
+ access.blur(this, d);
1489
+ })
1490
+ .on('keydown.pcac-mark', function (event, d) {
1491
+ const { key } = event;
1492
+ switch (key) {
1493
+ case 'Enter':
1494
+ case ' ':
1495
+ event.preventDefault();
1496
+ access.activate(d);
1497
+ return;
1498
+ case 'Escape':
1499
+ access.blur(this, d);
1500
+ return;
1501
+ }
1502
+ const target = neighbor(this, key);
1503
+ if (target) {
1504
+ event.preventDefault();
1505
+ moveFocus(this, target);
1506
+ }
1507
+ });
1508
+ }
1509
+ /**
1510
+ * Puts the chart's one Tab stop (`tabindex="0"`) on its first mark that can take focus, and takes
1511
+ * it off every other. Call once a chart's marks are drawn, and again whenever marks can have been
1512
+ * hidden - by zoom, say - so Tab doesn't land on one that can't be focused and skip the chart.
1513
+ * Leaves it where it is when that mark can still take focus, so coming back to the chart returns
1514
+ * to the mark last visited.
1515
+ */
1516
+ function refreshTabStop(root) {
1517
+ if (!root) {
1518
+ return;
1519
+ }
1520
+ const marks = navigableMarks(root);
1521
+ const current = marks.find((mark) => mark.getAttribute('tabindex') === '0');
1522
+ const stop = current ?? marks[0];
1523
+ for (const mark of root.querySelectorAll(`[${MARK_ATTR}]`)) {
1524
+ mark.setAttribute('tabindex', mark === stop ? '0' : '-1');
1525
+ }
1526
+ }
1527
+ /** The chart's marks that can take focus now, in drawing order. */
1528
+ function navigableMarks(root) {
1529
+ return Array.from(root.querySelectorAll(`[${MARK_ATTR}]`)).filter((mark) => !isNotDisplayed(mark, root));
1530
+ }
1531
+ /**
1532
+ * Whether the mark, or a group it's in, isn't displayed: a hidden series, or a point zoomed out of
1533
+ * the plot. Read from the `display` attribute and inline style the builders set, rather than from
1534
+ * layout, which a browser without one (a test environment) doesn't have.
1535
+ */
1536
+ function isNotDisplayed(mark, root) {
1537
+ for (let node = mark; node && node !== root; node = node.parentElement) {
1538
+ if (node.getAttribute('display') === 'none' || node.style?.display === 'none') {
1539
+ return true;
1540
+ }
1541
+ }
1542
+ return false;
1543
+ }
1544
+ /** The mark an arrow, Home or End key moves to from `mark`, or `null` for any other key. */
1545
+ function neighbor(mark, key) {
1546
+ const root = mark.ownerSVGElement ?? mark.parentElement;
1547
+ if (!root) {
1548
+ return null;
1549
+ }
1550
+ const marks = navigableMarks(root);
1551
+ const at = marks.indexOf(mark);
1552
+ switch (key) {
1553
+ case 'ArrowRight':
1554
+ case 'ArrowDown':
1555
+ return marks[Math.min(at + 1, marks.length - 1)] ?? null;
1556
+ case 'ArrowLeft':
1557
+ case 'ArrowUp':
1558
+ return marks[Math.max(at - 1, 0)] ?? null;
1559
+ case 'Home':
1560
+ return marks[0] ?? null;
1561
+ case 'End':
1562
+ return marks[marks.length - 1] ?? null;
1563
+ default:
1564
+ return null;
1565
+ }
1566
+ }
1567
+ /** Moves focus, and the chart's Tab stop with it, from one mark to another. */
1568
+ function moveFocus(from, to) {
1569
+ if (from === to) {
1570
+ return;
1571
+ }
1572
+ from.setAttribute('tabindex', '-1');
1573
+ to.setAttribute('tabindex', '0');
1574
+ to.focus();
1575
+ }
1576
+
1400
1577
  /**
1401
1578
  * How long each bar is drawn: its value, or 0 when it can't be drawn - a null or non-numeric
1402
1579
  * value, or `hide` set on the bar or on its whole group. A hidden bar keeps its slot (and so its
@@ -1518,6 +1695,24 @@ function hasDistinctSeriesKeys(groups) {
1518
1695
  function canRoundBands(length, count) {
1519
1696
  return count > 0 && length / count >= 2;
1520
1697
  }
1698
+ let warnedOfColorOverrideObject = false;
1699
+ /**
1700
+ * A bar config's `colorOverride` as the plain list of colors every chart now takes. Up to 22.2 the
1701
+ * bar charts wrapped it as `{ colors: [...] }`; a config still shaped that way - which TypeScript
1702
+ * misses when it's spread together or loaded as JSON - is still read, and development builds warn
1703
+ * about it once.
1704
+ */
1705
+ function barColorOverride(override) {
1706
+ if (!override || Array.isArray(override)) {
1707
+ return override;
1708
+ }
1709
+ if (typeof ngDevMode !== 'undefined' && ngDevMode && !warnedOfColorOverrideObject) {
1710
+ warnedOfColorOverrideObject = true;
1711
+ console.warn('Pioneer Charts: a bar chart\'s `colorOverride` is now a plain array of colors, like the other ' +
1712
+ 'charts\' - use `colorOverride: [...]` rather than `colorOverride: { colors: [...] }`.');
1713
+ }
1714
+ return override.colors;
1715
+ }
1521
1716
 
1522
1717
  /**
1523
1718
  * Provided per-component (see PcacBarHorizontalChartComponent's `providers`), not root-scoped:
@@ -1547,7 +1742,7 @@ class BarHorizontalChartBuilder extends PcacChart {
1547
1742
  return;
1548
1743
  }
1549
1744
  this.ensureColorCount(seriesKeys(config.data).length);
1550
- this.applyColorOverride(config.colorOverride?.colors);
1745
+ this.applyColorOverride(barColorOverride(config.colorOverride));
1551
1746
  if (!this.buildScales(chartElm, config)) {
1552
1747
  return;
1553
1748
  }
@@ -1583,6 +1778,7 @@ class BarHorizontalChartBuilder extends PcacChart {
1583
1778
  this.drawGrids(this.xScale, this.yScaleStacked);
1584
1779
  this.addGroups(config);
1585
1780
  this.axisBuilder.raiseAxes(this.svg);
1781
+ refreshTabStop(chartElm.nativeElement);
1586
1782
  }
1587
1783
  addGroups(config) {
1588
1784
  const groupsContainer = this.svg.append('g')
@@ -1634,7 +1830,28 @@ class BarHorizontalChartBuilder extends PcacChart {
1634
1830
  }
1635
1831
  return this.colors[byKey ? keys.indexOf(d.key) : Number(bar.getAttribute('data-group-bar-id'))];
1636
1832
  };
1637
- groups.enter().append('rect')
1833
+ // The hover fades run as their own named transition: an unnamed one would cancel the enter
1834
+ // transition still growing the bar, leaving it part-grown until the next rebuild. Shared by
1835
+ // the pointer and keyboard focus (see makeMarksAccessible).
1836
+ const highlight = (bar, d) => {
1837
+ const fill = fillOf(d, bar);
1838
+ select(bar)
1839
+ .transition('hover')
1840
+ .duration(this.transitionService.getTransitionDuration() / 5)
1841
+ .style('fill', color(fill)?.darker(1).toString() ?? fill);
1842
+ };
1843
+ const rest = (bar, d) => {
1844
+ select(bar)
1845
+ .transition('hover')
1846
+ .duration(this.transitionService.getTransitionDuration() / 5)
1847
+ .style('fill', fillOf(d, bar));
1848
+ };
1849
+ const tooltipOptions = (bar) => {
1850
+ const groupIndex = Number(bar.parentNode.getAttribute('data-group-id'));
1851
+ const index = Number(bar.getAttribute('data-group-bar-id'));
1852
+ return { index, parent: config.data[groupIndex], parentIndex: groupIndex, valueFormat: this.xAxis.format };
1853
+ };
1854
+ const bars = groups.enter().append('rect')
1638
1855
  .attr('class', 'pcac-bar')
1639
1856
  .attr('x', (d) => this.xScale(startOf(d)))
1640
1857
  // A stacked bar spans its whole group, which is already translated into place; looking its
@@ -1649,30 +1866,33 @@ class BarHorizontalChartBuilder extends PcacChart {
1649
1866
  return fillOf(d, this);
1650
1867
  })
1651
1868
  .attr('width', 0)
1652
- // The hover fades run as their own named transition: an unnamed one would cancel the enter
1653
- // transition still growing the bar, leaving it part-grown until the next rebuild.
1654
1869
  .on('mouseover', function (_event, d) {
1655
- const fill = fillOf(d, this);
1656
- select(this)
1657
- .transition('hover')
1658
- .duration(self.transitionService.getTransitionDuration() / 5)
1659
- .style('fill', color(fill)?.darker(1).toString() ?? fill);
1870
+ highlight(this, d);
1660
1871
  })
1661
1872
  .on('mousemove', function (event, d) {
1662
- const groupIndex = Number(this.parentNode.getAttribute('data-group-id'));
1663
- const index = Number(this.getAttribute('data-group-bar-id'));
1664
- self.showTooltip(event, d, { index, parent: config.data[groupIndex], parentIndex: groupIndex, valueFormat: self.xAxis.format });
1873
+ self.showTooltip(event, d, tooltipOptions(this));
1665
1874
  })
1666
1875
  .on('mouseout', function (_event, d) {
1667
1876
  self.hideTooltip();
1668
- select(this)
1669
- .transition('hover')
1670
- .duration(self.transitionService.getTransitionDuration() / 5)
1671
- .style('fill', fillOf(d, this));
1877
+ rest(this, d);
1672
1878
  })
1673
1879
  .on('click', (_event, d) => {
1674
1880
  this.barClickedSource.next(d);
1675
- })
1881
+ });
1882
+ makeMarksAccessible(bars, {
1883
+ label: (d, bar) => this.markLabel(d, { parent: tooltipOptions(bar).parent, valueFormat: this.xAxis.format }),
1884
+ skip: (d) => !!d.hide,
1885
+ activate: (d) => this.barClickedSource.next(d),
1886
+ focus: (bar, d) => {
1887
+ highlight(bar, d);
1888
+ this.showMarkTooltip(bar, d, tooltipOptions(bar));
1889
+ },
1890
+ blur: (bar, d) => {
1891
+ this.hideMarkTooltip(bar);
1892
+ rest(bar, d);
1893
+ },
1894
+ });
1895
+ bars
1676
1896
  .transition()
1677
1897
  .duration(this.transitionService.getTransitionDuration())
1678
1898
  .attr('width', (d) => {
@@ -1932,10 +2152,12 @@ class PcacBarHorizontalChartConfig extends PcacAxisChartConfig {
1932
2152
  isStacked = false;
1933
2153
  thresholds = [];
1934
2154
  spreadColorsPerGroup = false;
1935
- colorOverride = new PcacBarHorizontalChartColorOverrideConfig();
1936
- }
1937
- class PcacBarHorizontalChartColorOverrideConfig {
1938
- colors = [];
2155
+ /**
2156
+ * Bar colors, any CSS color, in place of the theme palette - by series, or by group with
2157
+ * `spreadColorsPerGroup`. Repeated when there are more series (or groups) than colors. Empty,
2158
+ * the theme palette is used.
2159
+ */
2160
+ colorOverride = [];
1939
2161
  }
1940
2162
 
1941
2163
  /**
@@ -1965,7 +2187,7 @@ class BarVerticalChartBuilder extends PcacChart {
1965
2187
  return;
1966
2188
  }
1967
2189
  this.ensureColorCount(seriesKeys(config.data).length);
1968
- this.applyColorOverride(config.colorOverride?.colors);
2190
+ this.applyColorOverride(barColorOverride(config.colorOverride));
1969
2191
  this.buildScales(config);
1970
2192
  this.drawChart(chartElm, config);
1971
2193
  }
@@ -1994,6 +2216,7 @@ class BarVerticalChartBuilder extends PcacChart {
1994
2216
  this.drawGrids(this.xScaleStacked, this.yScale);
1995
2217
  this.addGroups(config);
1996
2218
  this.axisBuilder.raiseAxes(this.svg);
2219
+ refreshTabStop(chartElm.nativeElement);
1997
2220
  }
1998
2221
  addGroups(config) {
1999
2222
  const groupsContainer = this.svg.append('g')
@@ -2047,7 +2270,28 @@ class BarVerticalChartBuilder extends PcacChart {
2047
2270
  }
2048
2271
  return this.colors[byKey ? keys.indexOf(d.key) : Number(bar.getAttribute('data-group-bar-id'))];
2049
2272
  };
2050
- group.enter().append('rect')
2273
+ // The hover fades run as their own named transition: an unnamed one would cancel the enter
2274
+ // transition still growing the bar, leaving it part-grown until the next rebuild. Shared by
2275
+ // the pointer and keyboard focus (see makeMarksAccessible).
2276
+ const highlight = (bar, d) => {
2277
+ const fill = fillOf(d, bar);
2278
+ select(bar)
2279
+ .transition('hover')
2280
+ .duration(this.transitionService.getTransitionDuration() / 5)
2281
+ .style('fill', color(fill)?.darker(1).toString() ?? fill);
2282
+ };
2283
+ const rest = (bar, d) => {
2284
+ select(bar)
2285
+ .transition('hover')
2286
+ .duration(this.transitionService.getTransitionDuration() / 5)
2287
+ .style('fill', fillOf(d, bar));
2288
+ };
2289
+ const tooltipOptions = (bar) => {
2290
+ const groupIndex = Number(bar.parentNode.getAttribute('data-group-id'));
2291
+ const index = Number(bar.getAttribute('data-group-bar-id'));
2292
+ return { index, parent: config.data[groupIndex], parentIndex: groupIndex, valueFormat: this.yAxis.format };
2293
+ };
2294
+ const bars = group.enter().append('rect')
2051
2295
  .attr('class', 'pcac-bar')
2052
2296
  // A stacked bar spans its whole group, which is already translated into place; looking its
2053
2297
  // series key up in the group band put it off in another group's slot whenever the key
@@ -2063,30 +2307,33 @@ class BarVerticalChartBuilder extends PcacChart {
2063
2307
  return this.height;
2064
2308
  })
2065
2309
  .attr('height', 0)
2066
- // The hover fades run as their own named transition: an unnamed one would cancel the enter
2067
- // transition still growing the bar, leaving it part-grown until the next rebuild.
2068
2310
  .on('mouseover', function (_event, d) {
2069
- const fill = fillOf(d, this);
2070
- select(this)
2071
- .transition('hover')
2072
- .duration(self.transitionService.getTransitionDuration() / 5)
2073
- .style('fill', color(fill)?.darker(1).toString() ?? fill);
2311
+ highlight(this, d);
2074
2312
  })
2075
2313
  .on('mousemove', function (event, d) {
2076
- const groupIndex = Number(this.parentNode.getAttribute('data-group-id'));
2077
- const index = Number(this.getAttribute('data-group-bar-id'));
2078
- self.showTooltip(event, d, { index, parent: config.data[groupIndex], parentIndex: groupIndex, valueFormat: self.yAxis.format });
2314
+ self.showTooltip(event, d, tooltipOptions(this));
2079
2315
  })
2080
2316
  .on('mouseout', function (_event, d) {
2081
2317
  self.hideTooltip();
2082
- select(this)
2083
- .transition('hover')
2084
- .duration(self.transitionService.getTransitionDuration() / 5)
2085
- .style('fill', fillOf(d, this));
2318
+ rest(this, d);
2086
2319
  })
2087
2320
  .on('click', (_, d) => {
2088
2321
  this.barClickedSource.next(d);
2089
- })
2322
+ });
2323
+ makeMarksAccessible(bars, {
2324
+ label: (d, bar) => this.markLabel(d, { parent: tooltipOptions(bar).parent, valueFormat: this.yAxis.format }),
2325
+ skip: (d) => !!d.hide,
2326
+ activate: (d) => this.barClickedSource.next(d),
2327
+ focus: (bar, d) => {
2328
+ highlight(bar, d);
2329
+ this.showMarkTooltip(bar, d, tooltipOptions(bar));
2330
+ },
2331
+ blur: (bar, d) => {
2332
+ this.hideMarkTooltip(bar);
2333
+ rest(bar, d);
2334
+ },
2335
+ });
2336
+ bars
2090
2337
  .transition()
2091
2338
  .duration(this.transitionService.getTransitionDuration())
2092
2339
  .attr('width', !config.isStacked ? this.xScaleGrouped.bandwidth() : this.xScaleStacked.bandwidth())
@@ -2250,10 +2497,12 @@ class PcacBarVerticalChartConfig extends PcacAxisChartConfig {
2250
2497
  isStacked = false;
2251
2498
  thresholds = [];
2252
2499
  spreadColorsPerGroup = false;
2253
- colorOverride = new PcacBarVerticalChartColorOverrideConfig();
2254
- }
2255
- class PcacBarVerticalChartColorOverrideConfig {
2256
- colors = [];
2500
+ /**
2501
+ * Bar colors, any CSS color, in place of the theme palette - by series, or by group with
2502
+ * `spreadColorsPerGroup`. Repeated when there are more series (or groups) than colors. Empty,
2503
+ * the theme palette is used.
2504
+ */
2505
+ colorOverride = [];
2257
2506
  }
2258
2507
 
2259
2508
  // Only what a consumer configures, binds or styles with. The chart plumbing - the `PcacChart`
@@ -2269,7 +2518,9 @@ class PcacLegendConfig {
2269
2518
  heading = null;
2270
2519
  items = [];
2271
2520
  }
2521
+ let nextLegendId = 0;
2272
2522
  class PcacLegend {
2523
+ headingId = `pcac-legend-heading-${nextLegendId++}`;
2273
2524
  colorService = inject(PcacColorService);
2274
2525
  config = model.required(/* @ts-ignore */
2275
2526
  ...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
@@ -2282,11 +2533,14 @@ class PcacLegend {
2282
2533
  this.itemClicked.emit(items);
2283
2534
  }
2284
2535
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacLegend, deps: [], target: i0.ɵɵFactoryTarget.Component });
2285
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.2.0", type: PcacLegend, isStandalone: true, selector: "pcac-legend", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { config: "configChange", itemClicked: "itemClicked" }, ngImport: i0, template: "<div class=\"pcac-legend-label\"><small>{{config().heading}}</small></div>\n@for(item of config().items; track $index; let i = $index; let last = $last;) {\n<div class=\"pcac-legend-item\" [class.pcac-legend-item-last]=\"last\" [class.pcac-legend-unchecked]=\"!item.checked\"\n role=\"switch\" [attr.aria-checked]=\"item.checked\" tabindex=\"0\" (click)=\"onItemClicked(i)\"\n (keydown.enter)=\"onItemClicked(i)\" (keydown.space)=\"onItemClicked(i); $event.preventDefault()\">\n @let color = item.colorOverride ? item.colorOverride : colorScale()[i];\n <div class=\"pcac-legend-circle\" [style.backgroundColor]=\"color\"></div>\n <small>{{ item.label }}</small>\n</div>\n}\n", styles: [":host{display:flex;align-items:center}.pcac-legend-label{margin-right:8px;margin-bottom:2.5px}.pcac-legend-item{cursor:pointer;display:flex;align-items:center;margin-right:8px}.pcac-legend-item:hover .pcac-legend-circle{box-shadow:0 0 6px #0000004d;transform:scale(1.2)}.pcac-legend-circle{display:inline-block;width:12px;height:12px;border-radius:50%;margin-right:4px;transition:box-shadow .3s ease,transform .3s ease}.pcac-legend-unchecked{opacity:.5}.pcac-legend-item-last{margin-right:0}.pcac-legend-item:focus-visible{outline:2px solid currentColor;outline-offset:2px}\n"] });
2536
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.2.0", type: PcacLegend, isStandalone: true, selector: "pcac-legend", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { config: "configChange", itemClicked: "itemClicked" }, host: { attributes: { "role": "group" }, properties: { "attr.aria-labelledby": "config().heading ? headingId : null" } }, ngImport: i0, template: "<div class=\"pcac-legend-label\" [id]=\"headingId\"><small>{{config().heading}}</small></div>\n@for(item of config().items; track $index; let i = $index) {\n<div class=\"pcac-legend-item\" [class.pcac-legend-unchecked]=\"!item.checked\"\n role=\"switch\" [attr.aria-checked]=\"item.checked\" tabindex=\"0\" (click)=\"onItemClicked(i)\"\n (keydown.enter)=\"onItemClicked(i)\" (keydown.space)=\"onItemClicked(i); $event.preventDefault()\">\n @let color = item.colorOverride ? item.colorOverride : colorScale()[i];\n <div class=\"pcac-legend-circle\" [style.backgroundColor]=\"color\"></div>\n <small>{{ item.label }}</small>\n</div>\n}\n", styles: [":host{display:flex;align-items:center;flex-wrap:wrap;column-gap:8px}.pcac-legend-label{margin-bottom:2.5px}.pcac-legend-item{cursor:pointer;display:flex;align-items:center;min-height:24px}.pcac-legend-item:hover .pcac-legend-circle{box-shadow:0 0 6px #0000004d;transform:scale(1.2)}.pcac-legend-circle{display:inline-block;width:12px;height:12px;border-radius:50%;margin-right:4px;transition:box-shadow .3s ease,transform .3s ease}.pcac-legend-unchecked{opacity:.5}.pcac-legend-item:focus-visible{outline:2px solid currentColor;outline-offset:2px}\n"] });
2286
2537
  }
2287
2538
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacLegend, decorators: [{
2288
2539
  type: Component,
2289
- args: [{ selector: 'pcac-legend', template: "<div class=\"pcac-legend-label\"><small>{{config().heading}}</small></div>\n@for(item of config().items; track $index; let i = $index; let last = $last;) {\n<div class=\"pcac-legend-item\" [class.pcac-legend-item-last]=\"last\" [class.pcac-legend-unchecked]=\"!item.checked\"\n role=\"switch\" [attr.aria-checked]=\"item.checked\" tabindex=\"0\" (click)=\"onItemClicked(i)\"\n (keydown.enter)=\"onItemClicked(i)\" (keydown.space)=\"onItemClicked(i); $event.preventDefault()\">\n @let color = item.colorOverride ? item.colorOverride : colorScale()[i];\n <div class=\"pcac-legend-circle\" [style.backgroundColor]=\"color\"></div>\n <small>{{ item.label }}</small>\n</div>\n}\n", styles: [":host{display:flex;align-items:center}.pcac-legend-label{margin-right:8px;margin-bottom:2.5px}.pcac-legend-item{cursor:pointer;display:flex;align-items:center;margin-right:8px}.pcac-legend-item:hover .pcac-legend-circle{box-shadow:0 0 6px #0000004d;transform:scale(1.2)}.pcac-legend-circle{display:inline-block;width:12px;height:12px;border-radius:50%;margin-right:4px;transition:box-shadow .3s ease,transform .3s ease}.pcac-legend-unchecked{opacity:.5}.pcac-legend-item-last{margin-right:0}.pcac-legend-item:focus-visible{outline:2px solid currentColor;outline-offset:2px}\n"] }]
2540
+ args: [{ selector: 'pcac-legend', host: {
2541
+ role: 'group',
2542
+ '[attr.aria-labelledby]': 'config().heading ? headingId : null',
2543
+ }, template: "<div class=\"pcac-legend-label\" [id]=\"headingId\"><small>{{config().heading}}</small></div>\n@for(item of config().items; track $index; let i = $index) {\n<div class=\"pcac-legend-item\" [class.pcac-legend-unchecked]=\"!item.checked\"\n role=\"switch\" [attr.aria-checked]=\"item.checked\" tabindex=\"0\" (click)=\"onItemClicked(i)\"\n (keydown.enter)=\"onItemClicked(i)\" (keydown.space)=\"onItemClicked(i); $event.preventDefault()\">\n @let color = item.colorOverride ? item.colorOverride : colorScale()[i];\n <div class=\"pcac-legend-circle\" [style.backgroundColor]=\"color\"></div>\n <small>{{ item.label }}</small>\n</div>\n}\n", styles: [":host{display:flex;align-items:center;flex-wrap:wrap;column-gap:8px}.pcac-legend-label{margin-bottom:2.5px}.pcac-legend-item{cursor:pointer;display:flex;align-items:center;min-height:24px}.pcac-legend-item:hover .pcac-legend-circle{box-shadow:0 0 6px #0000004d;transform:scale(1.2)}.pcac-legend-circle{display:inline-block;width:12px;height:12px;border-radius:50%;margin-right:4px;transition:box-shadow .3s ease,transform .3s ease}.pcac-legend-unchecked{opacity:.5}.pcac-legend-item:focus-visible{outline:2px solid currentColor;outline-offset:2px}\n"] }]
2290
2544
  }], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }, { type: i0.Output, args: ["configChange"] }], itemClicked: [{ type: i0.Output, args: ["itemClicked"] }] } });
2291
2545
 
2292
2546
  var PcacLineAreaPlotChartConfigType;
@@ -2359,7 +2613,9 @@ class PcacLineAreaChartConfig extends PcacAxisChartConfig {
2359
2613
  /**
2360
2614
  * Zoom and pan along the x / y axis (scroll / pinch to zoom 1x-10x, drag to pan, never leaving
2361
2615
  * the original domain). Either, or both, can be on. A gesture is always two-dimensional, so with
2362
- * only one enabled the other axis simply stays put. Both off by default.
2616
+ * only one enabled the other axis simply stays put. Both off by default. The zoom is kept when
2617
+ * the chart redraws - a new config, a series toggled in a legend, a resize (which keeps the same
2618
+ * part of the domain in view) - and dropped when zoom is turned off or the zoomable axes change.
2363
2619
  */
2364
2620
  enableZoomX = false;
2365
2621
  enableZoomY = false;
@@ -2451,7 +2707,9 @@ class PlaChartEffectsBuilder {
2451
2707
  }
2452
2708
  buildCollection() {
2453
2709
  const collection = this.config.svg.append('g')
2454
- .attr('class', 'effects');
2710
+ .attr('class', 'effects')
2711
+ // The hover crosshair repeats, for the pointer, what the points' own names say.
2712
+ .attr('aria-hidden', 'true');
2455
2713
  collection.append('path')
2456
2714
  .attr('class', 'effect-line');
2457
2715
  const mousePerLine = collection.selectAll('.effect-group')
@@ -3025,7 +3283,24 @@ const CHART_TYPE_LABELS = {
3025
3283
  */
3026
3284
  class PlaChartBuilder extends PcacChart {
3027
3285
  effectsBuilder = inject(PlaChartEffectsBuilder);
3286
+ /**
3287
+ * The scales as drawn: `baseScales` with the zoom this build started at (see `keptZoom`) applied.
3288
+ * A zoom gesture rescales from `baseScales`, never from these.
3289
+ */
3028
3290
  scales;
3291
+ /** The unzoomed scales, spanning the whole domain. */
3292
+ baseScales;
3293
+ /**
3294
+ * The zoom a rebuild picks up again, so a new config (a series toggled in the legend, live
3295
+ * data) or a resize doesn't throw away where the user had zoomed to. The pan is kept as a share
3296
+ * of the plot's size, which is what carries it across a resize: the same part of the domain
3297
+ * stays in view. `axes` is which axes were zoomable; a build where that differs starts unzoomed.
3298
+ */
3299
+ keptZoom = null;
3300
+ /** The zoom this build starts at, if any; applied to the zoom behavior once it's attached. */
3301
+ startZoom = null;
3302
+ /** Set while `startZoom` is handed to the zoom behavior, whose resulting zoom event is skipped. */
3303
+ restoringZoom = false;
3029
3304
  lineGenerator;
3030
3305
  areaGenerator;
3031
3306
  zoomBehavior;
@@ -3109,7 +3384,9 @@ class PlaChartBuilder extends PcacChart {
3109
3384
  return;
3110
3385
  }
3111
3386
  this.applyColorOverride(this.config.colorOverride);
3112
- this.scales = new PlaChartScalesBuilder().build(this.xAxis, this.yAxis, this.config.data, this.width, this.height);
3387
+ this.baseScales = new PlaChartScalesBuilder().build(this.xAxis, this.yAxis, this.config.data, this.width, this.height);
3388
+ this.startZoom = this.resumeZoom();
3389
+ this.scales = this.startZoom ? this.zoomedScales(this.startZoom) : this.baseScales;
3113
3390
  this.lineGenerator = buildLineGenerator(this.xAxis.format, this.scales);
3114
3391
  this.areaGenerator = buildAreaGenerator(this.xAxis.format, this.scales, this.height);
3115
3392
  if (this.zoomEnabled) {
@@ -3118,12 +3395,14 @@ class PlaChartBuilder extends PcacChart {
3118
3395
  // cursor (or is hidden outright, see `pointDisplay`), and either way the browser never
3119
3396
  // sends it a mouseout - its tooltip would stay up, and its dot stay grown, until the
3120
3397
  // cursor happened to cross it again. So the hover is ended here, on every zoom event.
3398
+ // The build's own starting zoom, handed to the behavior: already drawn that way.
3399
+ if (this.restoringZoom) {
3400
+ return;
3401
+ }
3121
3402
  this.leavePoint();
3122
- // A d3 zoom transform is always two-dimensional; only the enabled axes follow it and the
3123
- // other keeps its original scale, so that component of the gesture is simply ignored.
3124
- const newX = this.config.enableZoomX ? event.transform.rescaleX(this.scales.x) : this.scales.x;
3125
- const newY = this.config.enableZoomY ? event.transform.rescaleY(this.scales.y) : this.scales.y;
3126
- const zoomedScales = { x: newX, y: newY };
3403
+ this.keepZoom(event.transform);
3404
+ const zoomedScales = this.zoomedScales(event.transform);
3405
+ const { x: newX, y: newY } = zoomedScales;
3127
3406
  // Update the zoomed axes, each with its grid: the grid hangs off the axis's ticks, so it
3128
3407
  // is redrawn against the rescaled scale and dropped back underneath everything (append
3129
3408
  // puts it on top).
@@ -3156,6 +3435,8 @@ class PlaChartBuilder extends PcacChart {
3156
3435
  this.svg.selectAll('.dots').selectAll('.point')
3157
3436
  .attr('transform', (d, i) => this.pointTransform(d, i, zoomedScales))
3158
3437
  .attr('display', (d, i) => this.pointDisplay(d, i, zoomedScales));
3438
+ // The chart's Tab stop may just have been zoomed out of the plot, and hidden.
3439
+ refreshTabStop(this.svg.node()?.ownerSVGElement ?? null);
3159
3440
  // A fan-out's anchor is positioned like the points it belongs to, so it moves the same way;
3160
3441
  // its spokes are re-aimed because the ring's shift back into the plot (`fanOutShift`)
3161
3442
  // depends on where the anchor now is.
@@ -3210,6 +3491,7 @@ class PlaChartBuilder extends PcacChart {
3210
3491
  this.drawPointRanges();
3211
3492
  this.drawFanOuts();
3212
3493
  this.drawDots(config);
3494
+ refreshTabStop(chartElm.nativeElement);
3213
3495
  }
3214
3496
  /**
3215
3497
  * Resolves `pointImage`, finds the points that share a coordinate and, on a plot chart with
@@ -3288,6 +3570,43 @@ class PlaChartBuilder extends PcacChart {
3288
3570
  get zoomEnabled() {
3289
3571
  return !!(this.config.enableZoomX || this.config.enableZoomY);
3290
3572
  }
3573
+ /** Which axes zoom, as `keptZoom.axes` records them. */
3574
+ get zoomAxes() {
3575
+ return `${!!this.config.enableZoomX}${!!this.config.enableZoomY}`;
3576
+ }
3577
+ /**
3578
+ * `baseScales` under a zoom transform. A d3 zoom transform is always two-dimensional; only the
3579
+ * enabled axes follow it and the other keeps its original scale, so that component of the
3580
+ * gesture is simply ignored.
3581
+ */
3582
+ zoomedScales(transform) {
3583
+ return {
3584
+ x: this.config.enableZoomX ? transform.rescaleX(this.baseScales.x) : this.baseScales.x,
3585
+ y: this.config.enableZoomY ? transform.rescaleY(this.baseScales.y) : this.baseScales.y,
3586
+ };
3587
+ }
3588
+ /** Records a zoom for the next build to resume (see `keptZoom`). */
3589
+ keepZoom(transform) {
3590
+ this.keptZoom = {
3591
+ k: transform.k,
3592
+ x: transform.x / this.width,
3593
+ y: transform.y / this.height,
3594
+ axes: this.zoomAxes,
3595
+ };
3596
+ }
3597
+ /**
3598
+ * The zoom this build starts at: the kept one, fitted to this build's plot size, or `null` for
3599
+ * none - zoom off, the zoomable axes changed, or never zoomed. Forgets the kept zoom when it
3600
+ * can't be resumed, so turning zoom off and on again starts unzoomed.
3601
+ */
3602
+ resumeZoom() {
3603
+ const kept = this.keptZoom;
3604
+ if (!kept || !this.zoomEnabled || kept.axes !== this.zoomAxes) {
3605
+ this.keptZoom = null;
3606
+ return null;
3607
+ }
3608
+ return zoomIdentity.translate(kept.x * this.width, kept.y * this.height).scale(kept.k);
3609
+ }
3291
3610
  attachZoomBehavior() {
3292
3611
  if (!this.zoomEnabled)
3293
3612
  return;
@@ -3311,6 +3630,13 @@ class PlaChartBuilder extends PcacChart {
3311
3630
  .attr('fill', 'none')
3312
3631
  .attr('pointer-events', 'all');
3313
3632
  this.svg.call(this.zoomBehavior);
3633
+ // A resumed zoom is already drawn (`scales`); the behavior is told it too, so the next gesture
3634
+ // carries on from there rather than from the whole domain.
3635
+ if (this.startZoom) {
3636
+ this.restoringZoom = true;
3637
+ this.svg.call(this.zoomBehavior.transform, this.startZoom);
3638
+ this.restoringZoom = false;
3639
+ }
3314
3640
  }
3315
3641
  drawLineArea(config, type) {
3316
3642
  for (let i = 0; i < config.data.length; i++) {
@@ -3516,34 +3842,27 @@ class PlaChartBuilder extends PcacChart {
3516
3842
  .attr('class', 'point')
3517
3843
  .attr('transform', (d, i) => this.pointTransform(d, i, this.scales))
3518
3844
  .attr('display', (d, i) => this.pointDisplay(d, i, this.scales))
3519
- .on('mouseover', function (event, d) {
3520
- self.hoveredPoint = this;
3521
- self.focusPointRange(d);
3522
- // `d` is the very element bound from `series.data` above, so identity lookup is exact.
3523
- self.showTooltip(event, d, {
3524
- index: series.data.indexOf(d),
3525
- parent: series,
3526
- parentIndex: index,
3527
- coincident: self.coincidentWith(d),
3528
- valueFormat: self.yAxis.format,
3529
- keyFormat: self.xAxis.format,
3530
- // The dot or image itself rather than the group, so the tooltip clears what's drawn.
3531
- anchor: select(this).select('.dot, .dot-image').node(),
3532
- });
3533
- // No-op for an image point (no circle inside to grow). Its own transition name, so it
3534
- // runs alongside the enter rise rather than cancelling it (see DOT_HOVER_TRANSITION);
3535
- // it only takes over the entry's size tween, which it would otherwise fight over `r`.
3536
- select(this).select('.dot')
3537
- .interrupt(DOT_GROW_TRANSITION)
3538
- .transition(DOT_HOVER_TRANSITION)
3539
- .duration(duration / 3)
3540
- .attr('r', 6)
3541
- .attr('fill', self.colors[index]);
3845
+ .on('mouseover', function (_event, d) {
3846
+ self.enterPoint(this, d, series, index);
3542
3847
  })
3543
3848
  .on('mouseout', () => this.leavePoint())
3544
3849
  .on('click', (_event, d) => {
3545
3850
  this.dotClickedSource.next(d);
3546
3851
  });
3852
+ makeMarksAccessible(points, {
3853
+ label: (d) => this.markLabel(d, { parent: series, valueFormat: this.yAxis.format, keyFormat: this.xAxis.format }),
3854
+ activate: (d) => this.dotClickedSource.next(d),
3855
+ focus: (point, d) => {
3856
+ this.enterPoint(point, d, series, index);
3857
+ if (this.tooltipTemplate()) {
3858
+ point.setAttribute('aria-describedby', PcacTooltipBuilder.ID);
3859
+ }
3860
+ },
3861
+ blur: (point) => {
3862
+ this.leavePoint();
3863
+ point.removeAttribute('aria-describedby');
3864
+ },
3865
+ });
3547
3866
  points.filter((d) => !d.image)
3548
3867
  .append('circle')
3549
3868
  .attr('class', 'dot')
@@ -3576,6 +3895,35 @@ class PlaChartBuilder extends PcacChart {
3576
3895
  .attr('y', (d) => -maxHeight / 2 + this.offsetOf(d).dy);
3577
3896
  }
3578
3897
  }
3898
+ /**
3899
+ * Starts a hover on a point - its tooltip, beside it; its range brought forward; its dot grown -
3900
+ * for the pointer and keyboard focus alike (see makeMarksAccessible). Ended by `leavePoint`.
3901
+ */
3902
+ enterPoint(point, d, series, index) {
3903
+ const duration = this.transitionService.getTransitionDuration();
3904
+ this.hoveredPoint = point;
3905
+ this.focusPointRange(d);
3906
+ // `d` is the very element bound from `series.data`, so identity lookup is exact.
3907
+ this.showTooltip(null, d, {
3908
+ index: series.data.indexOf(d),
3909
+ parent: series,
3910
+ parentIndex: index,
3911
+ coincident: this.coincidentWith(d),
3912
+ valueFormat: this.yAxis.format,
3913
+ keyFormat: this.xAxis.format,
3914
+ // The dot or image itself rather than the group, so the tooltip clears what's drawn.
3915
+ anchor: select(point).select('.dot, .dot-image').node() ?? point,
3916
+ });
3917
+ // No-op for an image point (no circle inside to grow). Its own transition name, so it
3918
+ // runs alongside the enter rise rather than cancelling it (see DOT_HOVER_TRANSITION);
3919
+ // it only takes over the entry's size tween, which it would otherwise fight over `r`.
3920
+ select(point).select('.dot')
3921
+ .interrupt(DOT_GROW_TRANSITION)
3922
+ .transition(DOT_HOVER_TRANSITION)
3923
+ .duration(duration / 3)
3924
+ .attr('r', 6)
3925
+ .attr('fill', this.colors[index]);
3926
+ }
3579
3927
  /**
3580
3928
  * Ends the current hover, if there is one: hides the tooltip and shrinks the dot back. Shared by
3581
3929
  * the point's own mouseout and the zoom handler, which has to end a hover the browser won't
@@ -3811,14 +4159,34 @@ class PcacAreaChartConfig extends PcacLineAreaChartConfig {
3811
4159
  // the point-image and point-range types are part of those configs' public shape, so they're
3812
4160
  // exported alone.
3813
4161
 
4162
+ /** Which chart the shared `<pcac-pie-donut-chart>` draws; each wrapper binds its own. */
4163
+ var PcacPieDonutChartType;
4164
+ (function (PcacPieDonutChartType) {
4165
+ PcacPieDonutChartType["Pie"] = "pie";
4166
+ PcacPieDonutChartType["Donut"] = "donut";
4167
+ })(PcacPieDonutChartType || (PcacPieDonutChartType = {}));
4168
+ /**
4169
+ * What the pie and donut charts share. Internal: consumers configure `PcacPieChartConfig` or
4170
+ * `PcacDonutChartConfig`, the same way the line, area and plot charts share
4171
+ * `PcacLineAreaChartConfig`.
4172
+ */
4173
+ class PcacPieDonutChartConfig extends PcacChartConfig {
4174
+ /**
4175
+ * Slice colors, any CSS color, in data order - the first slice takes the first color - in place
4176
+ * of the theme palette. Repeated when there are more slices than colors. Omitted or empty, the
4177
+ * theme palette is used. Match a `<pcac-legend>` to it with each item's `colorOverride`.
4178
+ */
4179
+ colorOverride;
4180
+ }
4181
+
3814
4182
  /**
3815
- * Turns the pie into a donut: slices drawn as a ring around an empty center, which can hold a
3816
- * short label - typically the total the slices add up to.
4183
+ * A pie with its slices drawn as a ring around an empty center, which can hold a short label -
4184
+ * typically the total the slices add up to.
3817
4185
  */
3818
- class PcacPieDonutConfig {
4186
+ class PcacDonutChartConfig extends PcacPieDonutChartConfig {
3819
4187
  /**
3820
- * Radius of the hole as a fraction of the pie's radius, from 0 (a plain pie) to 0.9. Values
3821
- * outside that range are clamped.
4188
+ * Radius of the hole as a fraction of the chart's radius, from 0 (no hole - a pie) to 0.9.
4189
+ * Values outside that range are clamped.
3822
4190
  */
3823
4191
  innerRadius = 0.6;
3824
4192
  /**
@@ -3830,28 +4198,15 @@ class PcacPieDonutConfig {
3830
4198
  subLabel;
3831
4199
  /**
3832
4200
  * `label` color, any CSS color; theme default `$gray-800`. Applied as
3833
- * `--pcac-pie-center-label-color` on the chart's `.pcac-pie-center` group, so a stylesheet can
3834
- * set it on an ancestor instead (a config value wins).
4201
+ * `--pcac-donut-center-label-color` on the chart's `.pcac-donut-center` group, so a stylesheet
4202
+ * can set it on an ancestor instead (a config value wins).
3835
4203
  */
3836
4204
  labelColor;
3837
- /** `subLabel` color, likewise (`--pcac-pie-center-sub-label-color`); theme default `$gray-600`. */
4205
+ /** `subLabel` color, likewise (`--pcac-donut-center-sub-label-color`); theme default `$gray-600`. */
3838
4206
  subLabelColor;
3839
4207
  }
3840
- class PcacPieChartConfig extends PcacChartConfig {
3841
- /**
3842
- * Draw the pie as a donut. Off when not set; `{}` turns it on with every `PcacPieDonutConfig`
3843
- * default. Slices, hover and `sliceClicked` behave the same either way.
3844
- */
3845
- donut;
3846
- /**
3847
- * Slice colors, any CSS color, in data order - the first slice takes the first color - in place
3848
- * of the theme palette. Repeated when there are more slices than colors. Omitted or empty, the
3849
- * theme palette is used. Match a `<pcac-legend>` to it with each item's `colorOverride`.
3850
- */
3851
- colorOverride;
3852
- }
3853
4208
 
3854
- /** The largest `PcacPieDonutConfig.innerRadius` honored, so a ring is always left to draw. */
4209
+ /** The largest `PcacDonutChartConfig.innerRadius` honored, so a ring is always left to draw. */
3855
4210
  const MAX_DONUT_INNER_RADIUS = 0.9;
3856
4211
  /** Smallest font a center line is drawn at; a line that can't fit the hole at this size is left out. */
3857
4212
  const MIN_CENTER_FONT_SIZE = 8;
@@ -3863,12 +4218,12 @@ const CENTER_TEXT_WIDTH = 1.6;
3863
4218
  */
3864
4219
  const ESTIMATED_GLYPH_WIDTH = 0.6;
3865
4220
  /**
3866
- * Provided per-component (see PcacPieChartComponent's `providers`), not root-scoped:
4221
+ * Provided per-component (see PcacPieDonutChartComponent's `providers`), not root-scoped:
3867
4222
  * this builder extends PcacChart, which holds mutable per-chart-instance state (margin, width,
3868
4223
  * height, colors, svg). A root singleton would be shared and clobbered by every
3869
- * <pcac-pie-chart> rendered at once.
4224
+ * <pcac-pie-donut-chart> rendered at once.
3870
4225
  */
3871
- class PieChartBuilder extends PcacChart {
4226
+ class PieDonutChartBuilder extends PcacChart {
3872
4227
  radius;
3873
4228
  innerRadius = 0;
3874
4229
  arcShape;
@@ -3877,32 +4232,59 @@ class PieChartBuilder extends PcacChart {
3877
4232
  sliceClickedSource = new Subject();
3878
4233
  sliceClicked$ = this.sliceClickedSource.asObservable();
3879
4234
  chartTypeLabel = 'Pie chart';
3880
- buildChart(chartElm, config) {
4235
+ /**
4236
+ * Draws `config` as a pie, or - for `PcacPieDonutChartType.Donut` - as a donut, reading the ring
4237
+ * settings off the config (`PcacDonutChartConfig`), with its defaults for any left unset.
4238
+ */
4239
+ buildChart(chartElm, config, type) {
3881
4240
  if (!config?.data?.length) {
3882
4241
  this.clearChart(chartElm);
3883
4242
  return;
3884
4243
  }
3885
4244
  // The pie deliberately opts out of `heightFull`: `height` here feeds the radius rather than a
3886
4245
  // drawing area, so growing into a tall container would silently change the size of the pie
3887
- // itself. `PcacPieChartConfig` inherits the property from PcacChartConfig, so it's neutralized
3888
- // here rather than being absent from the type. (`<pcac-pie-chart>` also never gets the
4246
+ // itself. `PcacPieDonutChartConfig` inherits the property from PcacChartConfig, so it's neutralized
4247
+ // here rather than being absent from the type. (`<pcac-pie-donut-chart>` also never gets the
3889
4248
  // `pcac-height-full` class the other charts use to stretch their host.)
4249
+ const donut = type === PcacPieDonutChartType.Donut ? donutSettings(config) : null;
4250
+ if (type === PcacPieDonutChartType.Pie) {
4251
+ this.warnOfDonutOnPie(config);
4252
+ }
4253
+ // Announced for what it draws: a ring, or - a donut with no hole included - a pie (see
4254
+ // PcacChart.chartTypeLabel).
4255
+ this.chartTypeLabel = donut && donut.innerRadius > 0 ? 'Donut chart' : 'Pie chart';
3890
4256
  if (!this.initializeChartState(chartElm, { ...config, heightFull: false })) {
3891
4257
  return;
3892
4258
  }
3893
4259
  this.applyColorOverride(config.colorOverride);
3894
4260
  this.radius = Math.min(this.height, this.width) / 2;
3895
- this.buildShapes(config.donut);
4261
+ this.buildShapes(donut?.innerRadius ?? 0);
3896
4262
  this.drawChart(chartElm, config);
3897
- if (config.donut && this.innerRadius > 0) {
3898
- this.drawCenter(config.donut);
4263
+ if (donut && this.innerRadius > 0) {
4264
+ this.drawCenter(donut);
4265
+ }
4266
+ }
4267
+ warnedOfDonutOnPie = false;
4268
+ /**
4269
+ * Development builds only: a pie config still carrying 22.2's `donut` option. It isn't read any
4270
+ * more - the donut is PcacDonutChart now - and TypeScript doesn't always catch it (a config built
4271
+ * by spreading, or loaded as JSON, compiles fine), so the chart would quietly draw a plain pie.
4272
+ * Warned once per chart.
4273
+ */
4274
+ warnOfDonutOnPie(config) {
4275
+ if (typeof ngDevMode === 'undefined' || !ngDevMode || this.warnedOfDonutOnPie || !('donut' in config)) {
4276
+ return;
3899
4277
  }
4278
+ this.warnedOfDonutOnPie = true;
4279
+ console.warn('Pioneer Charts: <pcac-pie-chart> ignores `donut`. For a donut, use <pcac-donut-chart> with ' +
4280
+ 'PcacDonutChartConfig, which takes innerRadius, label, subLabel, labelColor and subLabelColor ' +
4281
+ 'directly - see the 22.2.16 CHANGELOG.');
3900
4282
  }
3901
- buildShapes(donut) {
4283
+ /** `ratio` is the hole's radius as a share of the chart's: 0 for a pie. */
4284
+ buildShapes(ratio) {
3902
4285
  const radiusOffset = 10;
3903
4286
  // Never negative: in a container under 20px the offset would otherwise turn the pie inside out.
3904
4287
  const outerRadius = Math.max(0, this.radius - radiusOffset);
3905
- const ratio = donut ? (donut.innerRadius ?? new PcacPieDonutConfig().innerRadius) : 0;
3906
4288
  // Sized against the resting slice, so the hole stays put when a hovered slice grows outward.
3907
4289
  this.innerRadius = Math.max(0, outerRadius * Math.min(Math.max(ratio, 0), MAX_DONUT_INNER_RADIUS));
3908
4290
  this.arcShape = arc()
@@ -3921,7 +4303,33 @@ class PieChartBuilder extends PcacChart {
3921
4303
  drawChart(chartElm, config) {
3922
4304
  this.buildContainer(chartElm, true);
3923
4305
  const self = this;
3924
- this.svg.selectAll('.pcac-arc')
4306
+ // Pops the slice out, darkened, for the pointer and keyboard focus alike (see
4307
+ // makeMarksAccessible).
4308
+ const pop = (slice, d) => {
4309
+ const t = transition().duration(this.transitionService.getTransitionDuration() / 3);
4310
+ const c = color(this.colors[d.index]);
4311
+ const ct = c ? c.darker(1).toString() : this.colors[d.index];
4312
+ const selected = select(slice);
4313
+ // Hovered mid-way through the enter sweep, the slice is finished first: growing it straight
4314
+ // from its part-swept path morphed it oddly on the way out to the hover shape. Only then -
4315
+ // re-entering a slice mid-way through its hover shrink must grow it from where it is, not
4316
+ // snap it back to rest first (which flickered).
4317
+ if (active(slice, 'enter')) {
4318
+ selected.interrupt('enter').attr('d', this.arcShape(d));
4319
+ }
4320
+ selected
4321
+ .transition(t)
4322
+ .attr('d', this.arcOverShape)
4323
+ .style('fill', ct);
4324
+ };
4325
+ const rest = (slice, d) => {
4326
+ select(slice)
4327
+ .transition()
4328
+ .duration(this.transitionService.getTransitionDuration() / 3)
4329
+ .attr('d', this.arcShape)
4330
+ .style('fill', this.colors[d.index]);
4331
+ };
4332
+ const slices = this.svg.selectAll('.pcac-arc')
3925
4333
  .data(this.pieAngles(config.data))
3926
4334
  .enter().append('g')
3927
4335
  .attr('class', 'pcac-arc')
@@ -3930,36 +4338,33 @@ class PieChartBuilder extends PcacChart {
3930
4338
  return this.colors[i];
3931
4339
  })
3932
4340
  .on('mouseover', function (_, d) {
3933
- const t = transition().duration(self.transitionService.getTransitionDuration() / 3);
3934
- const c = color(self.colors[d.index]);
3935
- const ct = c ? c.darker(1).toString() : self.colors[d.index];
3936
- const slice = select(this);
3937
- // Hovered mid-way through the enter sweep, the slice is finished first: growing it straight
3938
- // from its part-swept path morphed it oddly on the way out to the hover shape. Only then -
3939
- // re-entering a slice mid-way through its hover shrink must grow it from where it is, not
3940
- // snap it back to rest first (which flickered).
3941
- if (active(this, 'enter')) {
3942
- slice.interrupt('enter').attr('d', self.arcShape(d));
3943
- }
3944
- slice
3945
- .transition(t)
3946
- .attr('d', self.arcOverShape)
3947
- .style('fill', ct);
4341
+ pop(this, d);
3948
4342
  })
3949
4343
  .on('mousemove', (event, d) => {
3950
4344
  self.showTooltip(event, d.data, { index: d.index });
3951
4345
  })
3952
4346
  .on('mouseout', function (_, d) {
3953
4347
  self.hideTooltip();
3954
- select(this)
3955
- .transition()
3956
- .duration(self.transitionService.getTransitionDuration() / 3)
3957
- .attr('d', self.arcShape)
3958
- .style('fill', self.colors[d.index]);
4348
+ rest(this, d);
3959
4349
  })
3960
4350
  .on('click', (_event, d) => {
3961
4351
  this.sliceClickedSource.next(d.data);
3962
- })
4352
+ });
4353
+ makeMarksAccessible(slices, {
4354
+ label: (d) => this.markLabel(d.data),
4355
+ skip: (d) => !!d.data.hide,
4356
+ activate: (d) => this.sliceClickedSource.next(d.data),
4357
+ focus: (slice, d) => {
4358
+ pop(slice, d);
4359
+ this.showMarkTooltip(slice, d.data, { index: d.index });
4360
+ },
4361
+ blur: (slice, d) => {
4362
+ this.hideMarkTooltip(slice);
4363
+ rest(slice, d);
4364
+ },
4365
+ });
4366
+ refreshTabStop(chartElm.nativeElement);
4367
+ slices
3963
4368
  // Named, so the hover transitions (unnamed) and the check above can tell it apart from them.
3964
4369
  .transition('enter')
3965
4370
  .duration(this.transitionService.getTransitionDuration())
@@ -3979,12 +4384,12 @@ class PieChartBuilder extends PcacChart {
3979
4384
  }
3980
4385
  const maxWidth = this.innerRadius * CENTER_TEXT_WIDTH;
3981
4386
  const center = this.svg.append('g')
3982
- .attr('class', 'pcac-pie-center')
4387
+ .attr('class', 'pcac-donut-center')
3983
4388
  .attr('pointer-events', 'none')
3984
- .style('--pcac-pie-center-label-color', () => donut.labelColor ?? null)
3985
- .style('--pcac-pie-center-sub-label-color', () => donut.subLabelColor ?? null);
3986
- const label = this.drawCenterLine(center, 'pcac-pie-center-label', donut.label, Math.min(this.innerRadius * 0.5, 40), maxWidth);
3987
- const subLabel = this.drawCenterLine(center, 'pcac-pie-center-sub-label', donut.subLabel, Math.min(this.innerRadius * 0.2, 16), maxWidth);
4389
+ .style('--pcac-donut-center-label-color', () => donut.labelColor ?? null)
4390
+ .style('--pcac-donut-center-sub-label-color', () => donut.subLabelColor ?? null);
4391
+ const label = this.drawCenterLine(center, 'pcac-donut-center-label', donut.label, Math.min(this.innerRadius * 0.5, 40), maxWidth);
4392
+ const subLabel = this.drawCenterLine(center, 'pcac-donut-center-sub-label', donut.subLabel, Math.min(this.innerRadius * 0.2, 16), maxWidth);
3988
4393
  if (!label && !subLabel) {
3989
4394
  center.remove();
3990
4395
  return;
@@ -4026,34 +4431,47 @@ class PieChartBuilder extends PcacChart {
4026
4431
  const i = interpolate({ startAngle: 0, endAngle: 0 }, b);
4027
4432
  return (t) => this.arcShape(i(t)) ?? '';
4028
4433
  }
4029
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PieChartBuilder, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
4030
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PieChartBuilder });
4434
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PieDonutChartBuilder, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
4435
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PieDonutChartBuilder });
4031
4436
  }
4032
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PieChartBuilder, decorators: [{
4437
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PieDonutChartBuilder, decorators: [{
4033
4438
  type: Injectable
4034
4439
  }] });
4440
+ /** A donut config with its defaults filled in for whatever the consumer left unset. */
4441
+ function donutSettings(config) {
4442
+ const defaults = new PcacDonutChartConfig();
4443
+ // Unset or not a number (NaN, say - an empty number input's value), the default: a NaN ratio
4444
+ // survived the clamp and made every slice's path NaN, so nothing drew.
4445
+ const innerRadius = Number.isFinite(config.innerRadius) ? config.innerRadius : defaults.innerRadius ?? 0;
4446
+ return { ...config, innerRadius };
4447
+ }
4035
4448
 
4036
- class PcacPieChartComponent {
4037
- chartBuilder = inject(PieChartBuilder);
4449
+ /**
4450
+ * The chart the pie and donut charts share, drawn by `PcacPieChart` and `PcacDonutChart` with
4451
+ * their own `type`. Internal, like `<pcac-line-area-chart>` behind the line, area and plot charts.
4452
+ */
4453
+ class PcacPieDonutChartComponent {
4454
+ chartBuilder = inject(PieDonutChartBuilder);
4038
4455
  config = input.required(/* @ts-ignore */
4039
4456
  ...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
4457
+ type = input.required(/* @ts-ignore */
4458
+ ...(ngDevMode ? [{ debugName: "type" }] : /* istanbul ignore next */ []));
4040
4459
  chartElm = viewChild.required('chart', /* @ts-ignore */
4041
4460
  ...(ngDevMode ? [{ debugName: "chartElm" }] : /* istanbul ignore next */ []));
4042
4461
  sliceClicked = outputFromObservable(this.chartBuilder.sliceClicked$);
4043
4462
  /**
4044
- * Optional consumer `<ng-template pcacTooltip>` projected into this element; replaces the
4045
- * default tooltip when present (see PcacTooltipDirective).
4463
+ * The consumer's `<ng-template pcacTooltip>`, forwarded by the wrapper it was projected into:
4464
+ * a content query here wouldn't see it through the wrapper's template (see
4465
+ * PcacLineAreaChartComponent.tooltipTemplate).
4046
4466
  */
4047
- tooltipTemplate = contentChild(PcacTooltipDirective, /* @ts-ignore */
4048
- ...(ngDevMode ? [{ debugName: "tooltipTemplate" }] : /* istanbul ignore next */ []));
4467
+ tooltipTemplate = input(/* @ts-ignore */
4468
+ ...(ngDevMode ? [undefined, { debugName: "tooltipTemplate" }] : /* istanbul ignore next */ []));
4049
4469
  constructor() {
4050
- // Reacts to config() the same way ngOnChanges used to — reading it here (rather than a
4051
- // lifecycle hook) is what makes this an effect: it tracks config() as its dependency and
4052
- // reruns whenever a new value comes in, signal-input-changes-drive-behavior all the way down.
4470
+ // Tracks config() and type(), rebuilding whenever either changes.
4053
4471
  effect(() => this.buildChart());
4054
- // Handed over as a getter so the builder reads the query at hover time, not in the effect
4472
+ // Handed over as a getter so the builder reads the input at hover time, not in the effect
4055
4473
  // above (see PcacChart.tooltipTemplate).
4056
- this.chartBuilder.tooltipTemplate = () => this.tooltipTemplate()?.templateRef;
4474
+ this.chartBuilder.tooltipTemplate = () => this.tooltipTemplate();
4057
4475
  inject(PcacChartResizeService).observe(this.chartElm, () => {
4058
4476
  // Skip the ResizeObserver's routine initial callback when it lands after the effect above
4059
4477
  // already built successfully at this same width — only a real size change (or a build
@@ -4065,18 +4483,63 @@ class PcacPieChartComponent {
4065
4483
  }
4066
4484
  buildChart() {
4067
4485
  const config = this.config();
4486
+ const type = this.type();
4068
4487
  // Handed over even when empty: the builder clears what it last drew rather than leaving it.
4069
4488
  if (config) {
4070
- this.chartBuilder.buildChart(this.chartElm(), config);
4489
+ this.chartBuilder.buildChart(this.chartElm(), config, type);
4071
4490
  }
4072
4491
  }
4073
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacPieChartComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
4074
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.2.0", type: PcacPieChartComponent, isStandalone: true, selector: "pcac-pie-chart", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { sliceClicked: "sliceClicked" }, providers: [PieChartBuilder], queries: [{ propertyName: "tooltipTemplate", first: true, predicate: PcacTooltipDirective, descendants: true, isSignal: true }], viewQueries: [{ propertyName: "chartElm", first: true, predicate: ["chart"], descendants: true, isSignal: true }], ngImport: i0, template: "<section class=\"pcac-pie-chart\">\n <svg #chart></svg>\n</section>\n\n", styles: [".pcac-pie-chart svg{width:100%;display:block}\n"], encapsulation: i0.ViewEncapsulation.None });
4492
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacPieDonutChartComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
4493
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.2.0", type: PcacPieDonutChartComponent, isStandalone: true, selector: "pcac-pie-donut-chart", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null }, type: { classPropertyName: "type", publicName: "type", isSignal: true, isRequired: true, transformFunction: null }, tooltipTemplate: { classPropertyName: "tooltipTemplate", publicName: "tooltipTemplate", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { sliceClicked: "sliceClicked" }, providers: [PieDonutChartBuilder], viewQueries: [{ propertyName: "chartElm", first: true, predicate: ["chart"], descendants: true, isSignal: true }], ngImport: i0, template: "<!-- pcac-pie-chart kept alongside for app CSS written against 22.2 and earlier, when this section\n belonged to the one pie component (the donut included). -->\n<section class=\"pcac-pie-donut-chart pcac-pie-chart\">\n <svg #chart></svg>\n</section>\n\n", styles: [".pcac-pie-donut-chart svg{width:100%;display:block}\n"], encapsulation: i0.ViewEncapsulation.None });
4494
+ }
4495
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacPieDonutChartComponent, decorators: [{
4496
+ type: Component,
4497
+ args: [{ selector: 'pcac-pie-donut-chart', encapsulation: ViewEncapsulation.None, providers: [PieDonutChartBuilder], template: "<!-- pcac-pie-chart kept alongside for app CSS written against 22.2 and earlier, when this section\n belonged to the one pie component (the donut included). -->\n<section class=\"pcac-pie-donut-chart pcac-pie-chart\">\n <svg #chart></svg>\n</section>\n\n", styles: [".pcac-pie-donut-chart svg{width:100%;display:block}\n"] }]
4498
+ }], ctorParameters: () => [], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }], type: [{ type: i0.Input, args: [{ isSignal: true, alias: "type", required: true }] }], chartElm: [{ type: i0.ViewChild, args: ['chart', { isSignal: true }] }], sliceClicked: [{ type: i0.Output, args: ["sliceClicked"] }], tooltipTemplate: [{ type: i0.Input, args: [{ isSignal: true, alias: "tooltipTemplate", required: false }] }] } });
4499
+
4500
+ class PcacPieChart {
4501
+ config = input.required(/* @ts-ignore */
4502
+ ...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
4503
+ types = PcacPieDonutChartType;
4504
+ sliceClicked = output();
4505
+ /**
4506
+ * Optional consumer `<ng-template pcacTooltip>` projected into this element, forwarded to the
4507
+ * inner chart (see PcacPieDonutChartComponent.tooltipTemplate).
4508
+ */
4509
+ tooltipTemplate = contentChild(PcacTooltipDirective, /* @ts-ignore */
4510
+ ...(ngDevMode ? [{ debugName: "tooltipTemplate" }] : /* istanbul ignore next */ []));
4511
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacPieChart, deps: [], target: i0.ɵɵFactoryTarget.Component });
4512
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.2.0", type: PcacPieChart, isStandalone: true, selector: "pcac-pie-chart", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { sliceClicked: "sliceClicked" }, queries: [{ propertyName: "tooltipTemplate", first: true, predicate: PcacTooltipDirective, descendants: true, isSignal: true }], ngImport: i0, template: "<pcac-pie-donut-chart [config]=\"config()\" [tooltipTemplate]=\"tooltipTemplate()?.templateRef\" [type]=\"types.Pie\" (sliceClicked)=\"sliceClicked.emit($event)\" />\n", dependencies: [{ kind: "component", type: PcacPieDonutChartComponent, selector: "pcac-pie-donut-chart", inputs: ["config", "type", "tooltipTemplate"], outputs: ["sliceClicked"] }] });
4513
+ }
4514
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacPieChart, decorators: [{
4515
+ type: Component,
4516
+ args: [{ selector: 'pcac-pie-chart', imports: [PcacPieDonutChartComponent], template: "<pcac-pie-donut-chart [config]=\"config()\" [tooltipTemplate]=\"tooltipTemplate()?.templateRef\" [type]=\"types.Pie\" (sliceClicked)=\"sliceClicked.emit($event)\" />\n" }]
4517
+ }], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }], sliceClicked: [{ type: i0.Output, args: ["sliceClicked"] }], tooltipTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => PcacTooltipDirective), { isSignal: true }] }] } });
4518
+
4519
+ class PcacPieChartConfig extends PcacPieDonutChartConfig {
4520
+ }
4521
+
4522
+ class PcacDonutChart {
4523
+ config = input.required(/* @ts-ignore */
4524
+ ...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
4525
+ types = PcacPieDonutChartType;
4526
+ sliceClicked = output();
4527
+ /**
4528
+ * Optional consumer `<ng-template pcacTooltip>` projected into this element, forwarded to the
4529
+ * inner chart (see PcacPieDonutChartComponent.tooltipTemplate).
4530
+ */
4531
+ tooltipTemplate = contentChild(PcacTooltipDirective, /* @ts-ignore */
4532
+ ...(ngDevMode ? [{ debugName: "tooltipTemplate" }] : /* istanbul ignore next */ []));
4533
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacDonutChart, deps: [], target: i0.ɵɵFactoryTarget.Component });
4534
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.2.0", type: PcacDonutChart, isStandalone: true, selector: "pcac-donut-chart", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { sliceClicked: "sliceClicked" }, queries: [{ propertyName: "tooltipTemplate", first: true, predicate: PcacTooltipDirective, descendants: true, isSignal: true }], ngImport: i0, template: "<pcac-pie-donut-chart [config]=\"config()\" [tooltipTemplate]=\"tooltipTemplate()?.templateRef\" [type]=\"types.Donut\" (sliceClicked)=\"sliceClicked.emit($event)\" />\n", dependencies: [{ kind: "component", type: PcacPieDonutChartComponent, selector: "pcac-pie-donut-chart", inputs: ["config", "type", "tooltipTemplate"], outputs: ["sliceClicked"] }] });
4075
4535
  }
4076
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacPieChartComponent, decorators: [{
4536
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacDonutChart, decorators: [{
4077
4537
  type: Component,
4078
- args: [{ selector: 'pcac-pie-chart', encapsulation: ViewEncapsulation.None, providers: [PieChartBuilder], template: "<section class=\"pcac-pie-chart\">\n <svg #chart></svg>\n</section>\n\n", styles: [".pcac-pie-chart svg{width:100%;display:block}\n"] }]
4079
- }], ctorParameters: () => [], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }], chartElm: [{ type: i0.ViewChild, args: ['chart', { isSignal: true }] }], sliceClicked: [{ type: i0.Output, args: ["sliceClicked"] }], tooltipTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => PcacTooltipDirective), { isSignal: true }] }] } });
4538
+ args: [{ selector: 'pcac-donut-chart', imports: [PcacPieDonutChartComponent], template: "<pcac-pie-donut-chart [config]=\"config()\" [tooltipTemplate]=\"tooltipTemplate()?.templateRef\" [type]=\"types.Donut\" (sliceClicked)=\"sliceClicked.emit($event)\" />\n" }]
4539
+ }], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }], sliceClicked: [{ type: i0.Output, args: ["sliceClicked"] }], tooltipTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => PcacTooltipDirective), { isSignal: true }] }] } });
4540
+
4541
+ // The shared <pcac-pie-donut-chart> and its PcacPieDonutChartConfig stay internal, like the
4542
+ // line/area/plot charts' base: consumers use the pie and donut wrappers and their configs.
4080
4543
 
4081
4544
  /*
4082
4545
  * Public API Surface of pioneer-charts
@@ -4086,5 +4549,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImpor
4086
4549
  * Generated bundle index. Do not edit.
4087
4550
  */
4088
4551
 
4089
- export { PcacAreaChart, PcacAreaChartConfig, PcacAxisChartConfig, PcacAxisConfig, PcacAxisSubLabels, PcacBarHorizontalChartColorOverrideConfig, PcacBarHorizontalChartComponent, PcacBarHorizontalChartConfig, PcacBarVerticalChartColorOverrideConfig, PcacBarVerticalChartComponent, PcacBarVerticalChartConfig, PcacChartConfig, PcacColorService, PcacData, PcacDataRange, PcacFormatEnum, PcacLegend, PcacLegendConfig, PcacLegendConfigItem, PcacLineChart, PcacLineChartConfig, PcacPieChartComponent, PcacPieChartConfig, PcacPieDonutConfig, PcacPlotChart, PcacPlotChartConfig, PcacPointFanOutConfig, PcacPointImageConfig, PcacPointRangeConfig, PcacPointRangeShow, PcacPointRangeStyle, PcacRangeBounds, PcacTooltipDirective };
4552
+ export { PcacAreaChart, PcacAreaChartConfig, PcacAxisChartConfig, PcacAxisConfig, PcacAxisSubLabels, PcacBarHorizontalChartComponent, PcacBarHorizontalChartConfig, PcacBarVerticalChartComponent, PcacBarVerticalChartConfig, PcacChartConfig, PcacColorService, PcacData, PcacDataRange, PcacDonutChart, PcacDonutChartConfig, PcacFormatEnum, PcacLegend, PcacLegendConfig, PcacLegendConfigItem, PcacLineChart, PcacLineChartConfig, PcacPieChart, PcacPieChartConfig, PcacPlotChart, PcacPlotChartConfig, PcacPointFanOutConfig, PcacPointImageConfig, PcacPointRangeConfig, PcacPointRangeShow, PcacPointRangeStyle, PcacRangeBounds, PcacTooltipDirective };
4090
4553
  //# sourceMappingURL=pioneer-code-pioneer-charts.mjs.map