@pioneer-code/pioneer-charts 22.2.16 → 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`,
@@ -1213,9 +1260,11 @@ class PcacChart {
1213
1260
  return false;
1214
1261
  }
1215
1262
  this.width = measuredWidth;
1216
- // 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.)
1217
1266
  select(chartElm.nativeElement)
1218
- .attr('role', 'img')
1267
+ .attr('role', 'group')
1219
1268
  .attr('aria-label', config.ariaLabel || this.chartTypeLabel);
1220
1269
  this.height = this.resolveHeight(container, config);
1221
1270
  this.colors = colors;
@@ -1400,6 +1449,131 @@ function fitText(text, maxWidth) {
1400
1449
  text.textContent = withEllipsis(fits);
1401
1450
  }
1402
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
+
1403
1577
  /**
1404
1578
  * How long each bar is drawn: its value, or 0 when it can't be drawn - a null or non-numeric
1405
1579
  * value, or `hide` set on the bar or on its whole group. A hidden bar keeps its slot (and so its
@@ -1521,6 +1695,24 @@ function hasDistinctSeriesKeys(groups) {
1521
1695
  function canRoundBands(length, count) {
1522
1696
  return count > 0 && length / count >= 2;
1523
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
+ }
1524
1716
 
1525
1717
  /**
1526
1718
  * Provided per-component (see PcacBarHorizontalChartComponent's `providers`), not root-scoped:
@@ -1550,7 +1742,7 @@ class BarHorizontalChartBuilder extends PcacChart {
1550
1742
  return;
1551
1743
  }
1552
1744
  this.ensureColorCount(seriesKeys(config.data).length);
1553
- this.applyColorOverride(config.colorOverride?.colors);
1745
+ this.applyColorOverride(barColorOverride(config.colorOverride));
1554
1746
  if (!this.buildScales(chartElm, config)) {
1555
1747
  return;
1556
1748
  }
@@ -1586,6 +1778,7 @@ class BarHorizontalChartBuilder extends PcacChart {
1586
1778
  this.drawGrids(this.xScale, this.yScaleStacked);
1587
1779
  this.addGroups(config);
1588
1780
  this.axisBuilder.raiseAxes(this.svg);
1781
+ refreshTabStop(chartElm.nativeElement);
1589
1782
  }
1590
1783
  addGroups(config) {
1591
1784
  const groupsContainer = this.svg.append('g')
@@ -1637,7 +1830,28 @@ class BarHorizontalChartBuilder extends PcacChart {
1637
1830
  }
1638
1831
  return this.colors[byKey ? keys.indexOf(d.key) : Number(bar.getAttribute('data-group-bar-id'))];
1639
1832
  };
1640
- 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')
1641
1855
  .attr('class', 'pcac-bar')
1642
1856
  .attr('x', (d) => this.xScale(startOf(d)))
1643
1857
  // A stacked bar spans its whole group, which is already translated into place; looking its
@@ -1652,30 +1866,33 @@ class BarHorizontalChartBuilder extends PcacChart {
1652
1866
  return fillOf(d, this);
1653
1867
  })
1654
1868
  .attr('width', 0)
1655
- // The hover fades run as their own named transition: an unnamed one would cancel the enter
1656
- // transition still growing the bar, leaving it part-grown until the next rebuild.
1657
1869
  .on('mouseover', function (_event, d) {
1658
- const fill = fillOf(d, this);
1659
- select(this)
1660
- .transition('hover')
1661
- .duration(self.transitionService.getTransitionDuration() / 5)
1662
- .style('fill', color(fill)?.darker(1).toString() ?? fill);
1870
+ highlight(this, d);
1663
1871
  })
1664
1872
  .on('mousemove', function (event, d) {
1665
- const groupIndex = Number(this.parentNode.getAttribute('data-group-id'));
1666
- const index = Number(this.getAttribute('data-group-bar-id'));
1667
- self.showTooltip(event, d, { index, parent: config.data[groupIndex], parentIndex: groupIndex, valueFormat: self.xAxis.format });
1873
+ self.showTooltip(event, d, tooltipOptions(this));
1668
1874
  })
1669
1875
  .on('mouseout', function (_event, d) {
1670
1876
  self.hideTooltip();
1671
- select(this)
1672
- .transition('hover')
1673
- .duration(self.transitionService.getTransitionDuration() / 5)
1674
- .style('fill', fillOf(d, this));
1877
+ rest(this, d);
1675
1878
  })
1676
1879
  .on('click', (_event, d) => {
1677
1880
  this.barClickedSource.next(d);
1678
- })
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
1679
1896
  .transition()
1680
1897
  .duration(this.transitionService.getTransitionDuration())
1681
1898
  .attr('width', (d) => {
@@ -1935,10 +2152,12 @@ class PcacBarHorizontalChartConfig extends PcacAxisChartConfig {
1935
2152
  isStacked = false;
1936
2153
  thresholds = [];
1937
2154
  spreadColorsPerGroup = false;
1938
- colorOverride = new PcacBarHorizontalChartColorOverrideConfig();
1939
- }
1940
- class PcacBarHorizontalChartColorOverrideConfig {
1941
- 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 = [];
1942
2161
  }
1943
2162
 
1944
2163
  /**
@@ -1968,7 +2187,7 @@ class BarVerticalChartBuilder extends PcacChart {
1968
2187
  return;
1969
2188
  }
1970
2189
  this.ensureColorCount(seriesKeys(config.data).length);
1971
- this.applyColorOverride(config.colorOverride?.colors);
2190
+ this.applyColorOverride(barColorOverride(config.colorOverride));
1972
2191
  this.buildScales(config);
1973
2192
  this.drawChart(chartElm, config);
1974
2193
  }
@@ -1997,6 +2216,7 @@ class BarVerticalChartBuilder extends PcacChart {
1997
2216
  this.drawGrids(this.xScaleStacked, this.yScale);
1998
2217
  this.addGroups(config);
1999
2218
  this.axisBuilder.raiseAxes(this.svg);
2219
+ refreshTabStop(chartElm.nativeElement);
2000
2220
  }
2001
2221
  addGroups(config) {
2002
2222
  const groupsContainer = this.svg.append('g')
@@ -2050,7 +2270,28 @@ class BarVerticalChartBuilder extends PcacChart {
2050
2270
  }
2051
2271
  return this.colors[byKey ? keys.indexOf(d.key) : Number(bar.getAttribute('data-group-bar-id'))];
2052
2272
  };
2053
- 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')
2054
2295
  .attr('class', 'pcac-bar')
2055
2296
  // A stacked bar spans its whole group, which is already translated into place; looking its
2056
2297
  // series key up in the group band put it off in another group's slot whenever the key
@@ -2066,30 +2307,33 @@ class BarVerticalChartBuilder extends PcacChart {
2066
2307
  return this.height;
2067
2308
  })
2068
2309
  .attr('height', 0)
2069
- // The hover fades run as their own named transition: an unnamed one would cancel the enter
2070
- // transition still growing the bar, leaving it part-grown until the next rebuild.
2071
2310
  .on('mouseover', function (_event, d) {
2072
- const fill = fillOf(d, this);
2073
- select(this)
2074
- .transition('hover')
2075
- .duration(self.transitionService.getTransitionDuration() / 5)
2076
- .style('fill', color(fill)?.darker(1).toString() ?? fill);
2311
+ highlight(this, d);
2077
2312
  })
2078
2313
  .on('mousemove', function (event, d) {
2079
- const groupIndex = Number(this.parentNode.getAttribute('data-group-id'));
2080
- const index = Number(this.getAttribute('data-group-bar-id'));
2081
- self.showTooltip(event, d, { index, parent: config.data[groupIndex], parentIndex: groupIndex, valueFormat: self.yAxis.format });
2314
+ self.showTooltip(event, d, tooltipOptions(this));
2082
2315
  })
2083
2316
  .on('mouseout', function (_event, d) {
2084
2317
  self.hideTooltip();
2085
- select(this)
2086
- .transition('hover')
2087
- .duration(self.transitionService.getTransitionDuration() / 5)
2088
- .style('fill', fillOf(d, this));
2318
+ rest(this, d);
2089
2319
  })
2090
2320
  .on('click', (_, d) => {
2091
2321
  this.barClickedSource.next(d);
2092
- })
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
2093
2337
  .transition()
2094
2338
  .duration(this.transitionService.getTransitionDuration())
2095
2339
  .attr('width', !config.isStacked ? this.xScaleGrouped.bandwidth() : this.xScaleStacked.bandwidth())
@@ -2253,10 +2497,12 @@ class PcacBarVerticalChartConfig extends PcacAxisChartConfig {
2253
2497
  isStacked = false;
2254
2498
  thresholds = [];
2255
2499
  spreadColorsPerGroup = false;
2256
- colorOverride = new PcacBarVerticalChartColorOverrideConfig();
2257
- }
2258
- class PcacBarVerticalChartColorOverrideConfig {
2259
- 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 = [];
2260
2506
  }
2261
2507
 
2262
2508
  // Only what a consumer configures, binds or styles with. The chart plumbing - the `PcacChart`
@@ -2272,7 +2518,9 @@ class PcacLegendConfig {
2272
2518
  heading = null;
2273
2519
  items = [];
2274
2520
  }
2521
+ let nextLegendId = 0;
2275
2522
  class PcacLegend {
2523
+ headingId = `pcac-legend-heading-${nextLegendId++}`;
2276
2524
  colorService = inject(PcacColorService);
2277
2525
  config = model.required(/* @ts-ignore */
2278
2526
  ...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
@@ -2285,11 +2533,14 @@ class PcacLegend {
2285
2533
  this.itemClicked.emit(items);
2286
2534
  }
2287
2535
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacLegend, deps: [], target: i0.ɵɵFactoryTarget.Component });
2288
- 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) {\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"] });
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"] });
2289
2537
  }
2290
2538
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacLegend, decorators: [{
2291
2539
  type: Component,
2292
- 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) {\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"] }]
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"] }]
2293
2544
  }], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }, { type: i0.Output, args: ["configChange"] }], itemClicked: [{ type: i0.Output, args: ["itemClicked"] }] } });
2294
2545
 
2295
2546
  var PcacLineAreaPlotChartConfigType;
@@ -2362,7 +2613,9 @@ class PcacLineAreaChartConfig extends PcacAxisChartConfig {
2362
2613
  /**
2363
2614
  * Zoom and pan along the x / y axis (scroll / pinch to zoom 1x-10x, drag to pan, never leaving
2364
2615
  * the original domain). Either, or both, can be on. A gesture is always two-dimensional, so with
2365
- * 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.
2366
2619
  */
2367
2620
  enableZoomX = false;
2368
2621
  enableZoomY = false;
@@ -2454,7 +2707,9 @@ class PlaChartEffectsBuilder {
2454
2707
  }
2455
2708
  buildCollection() {
2456
2709
  const collection = this.config.svg.append('g')
2457
- .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');
2458
2713
  collection.append('path')
2459
2714
  .attr('class', 'effect-line');
2460
2715
  const mousePerLine = collection.selectAll('.effect-group')
@@ -3028,7 +3283,24 @@ const CHART_TYPE_LABELS = {
3028
3283
  */
3029
3284
  class PlaChartBuilder extends PcacChart {
3030
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
+ */
3031
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;
3032
3304
  lineGenerator;
3033
3305
  areaGenerator;
3034
3306
  zoomBehavior;
@@ -3112,7 +3384,9 @@ class PlaChartBuilder extends PcacChart {
3112
3384
  return;
3113
3385
  }
3114
3386
  this.applyColorOverride(this.config.colorOverride);
3115
- 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;
3116
3390
  this.lineGenerator = buildLineGenerator(this.xAxis.format, this.scales);
3117
3391
  this.areaGenerator = buildAreaGenerator(this.xAxis.format, this.scales, this.height);
3118
3392
  if (this.zoomEnabled) {
@@ -3121,12 +3395,14 @@ class PlaChartBuilder extends PcacChart {
3121
3395
  // cursor (or is hidden outright, see `pointDisplay`), and either way the browser never
3122
3396
  // sends it a mouseout - its tooltip would stay up, and its dot stay grown, until the
3123
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
+ }
3124
3402
  this.leavePoint();
3125
- // A d3 zoom transform is always two-dimensional; only the enabled axes follow it and the
3126
- // other keeps its original scale, so that component of the gesture is simply ignored.
3127
- const newX = this.config.enableZoomX ? event.transform.rescaleX(this.scales.x) : this.scales.x;
3128
- const newY = this.config.enableZoomY ? event.transform.rescaleY(this.scales.y) : this.scales.y;
3129
- 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;
3130
3406
  // Update the zoomed axes, each with its grid: the grid hangs off the axis's ticks, so it
3131
3407
  // is redrawn against the rescaled scale and dropped back underneath everything (append
3132
3408
  // puts it on top).
@@ -3159,6 +3435,8 @@ class PlaChartBuilder extends PcacChart {
3159
3435
  this.svg.selectAll('.dots').selectAll('.point')
3160
3436
  .attr('transform', (d, i) => this.pointTransform(d, i, zoomedScales))
3161
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);
3162
3440
  // A fan-out's anchor is positioned like the points it belongs to, so it moves the same way;
3163
3441
  // its spokes are re-aimed because the ring's shift back into the plot (`fanOutShift`)
3164
3442
  // depends on where the anchor now is.
@@ -3213,6 +3491,7 @@ class PlaChartBuilder extends PcacChart {
3213
3491
  this.drawPointRanges();
3214
3492
  this.drawFanOuts();
3215
3493
  this.drawDots(config);
3494
+ refreshTabStop(chartElm.nativeElement);
3216
3495
  }
3217
3496
  /**
3218
3497
  * Resolves `pointImage`, finds the points that share a coordinate and, on a plot chart with
@@ -3291,6 +3570,43 @@ class PlaChartBuilder extends PcacChart {
3291
3570
  get zoomEnabled() {
3292
3571
  return !!(this.config.enableZoomX || this.config.enableZoomY);
3293
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
+ }
3294
3610
  attachZoomBehavior() {
3295
3611
  if (!this.zoomEnabled)
3296
3612
  return;
@@ -3314,6 +3630,13 @@ class PlaChartBuilder extends PcacChart {
3314
3630
  .attr('fill', 'none')
3315
3631
  .attr('pointer-events', 'all');
3316
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
+ }
3317
3640
  }
3318
3641
  drawLineArea(config, type) {
3319
3642
  for (let i = 0; i < config.data.length; i++) {
@@ -3519,34 +3842,27 @@ class PlaChartBuilder extends PcacChart {
3519
3842
  .attr('class', 'point')
3520
3843
  .attr('transform', (d, i) => this.pointTransform(d, i, this.scales))
3521
3844
  .attr('display', (d, i) => this.pointDisplay(d, i, this.scales))
3522
- .on('mouseover', function (event, d) {
3523
- self.hoveredPoint = this;
3524
- self.focusPointRange(d);
3525
- // `d` is the very element bound from `series.data` above, so identity lookup is exact.
3526
- self.showTooltip(event, d, {
3527
- index: series.data.indexOf(d),
3528
- parent: series,
3529
- parentIndex: index,
3530
- coincident: self.coincidentWith(d),
3531
- valueFormat: self.yAxis.format,
3532
- keyFormat: self.xAxis.format,
3533
- // The dot or image itself rather than the group, so the tooltip clears what's drawn.
3534
- anchor: select(this).select('.dot, .dot-image').node(),
3535
- });
3536
- // No-op for an image point (no circle inside to grow). Its own transition name, so it
3537
- // runs alongside the enter rise rather than cancelling it (see DOT_HOVER_TRANSITION);
3538
- // it only takes over the entry's size tween, which it would otherwise fight over `r`.
3539
- select(this).select('.dot')
3540
- .interrupt(DOT_GROW_TRANSITION)
3541
- .transition(DOT_HOVER_TRANSITION)
3542
- .duration(duration / 3)
3543
- .attr('r', 6)
3544
- .attr('fill', self.colors[index]);
3845
+ .on('mouseover', function (_event, d) {
3846
+ self.enterPoint(this, d, series, index);
3545
3847
  })
3546
3848
  .on('mouseout', () => this.leavePoint())
3547
3849
  .on('click', (_event, d) => {
3548
3850
  this.dotClickedSource.next(d);
3549
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
+ });
3550
3866
  points.filter((d) => !d.image)
3551
3867
  .append('circle')
3552
3868
  .attr('class', 'dot')
@@ -3579,6 +3895,35 @@ class PlaChartBuilder extends PcacChart {
3579
3895
  .attr('y', (d) => -maxHeight / 2 + this.offsetOf(d).dy);
3580
3896
  }
3581
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
+ }
3582
3927
  /**
3583
3928
  * Ends the current hover, if there is one: hides the tooltip and shrinks the dot back. Shared by
3584
3929
  * the point's own mouseout and the zoom handler, which has to end a hover the browser won't
@@ -3933,7 +4278,7 @@ class PieDonutChartBuilder extends PcacChart {
3933
4278
  this.warnedOfDonutOnPie = true;
3934
4279
  console.warn('Pioneer Charts: <pcac-pie-chart> ignores `donut`. For a donut, use <pcac-donut-chart> with ' +
3935
4280
  'PcacDonutChartConfig, which takes innerRadius, label, subLabel, labelColor and subLabelColor ' +
3936
- 'directly - see the 22.3.0 CHANGELOG.');
4281
+ 'directly - see the 22.2.16 CHANGELOG.');
3937
4282
  }
3938
4283
  /** `ratio` is the hole's radius as a share of the chart's: 0 for a pie. */
3939
4284
  buildShapes(ratio) {
@@ -3958,7 +4303,33 @@ class PieDonutChartBuilder extends PcacChart {
3958
4303
  drawChart(chartElm, config) {
3959
4304
  this.buildContainer(chartElm, true);
3960
4305
  const self = this;
3961
- 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')
3962
4333
  .data(this.pieAngles(config.data))
3963
4334
  .enter().append('g')
3964
4335
  .attr('class', 'pcac-arc')
@@ -3967,36 +4338,33 @@ class PieDonutChartBuilder extends PcacChart {
3967
4338
  return this.colors[i];
3968
4339
  })
3969
4340
  .on('mouseover', function (_, d) {
3970
- const t = transition().duration(self.transitionService.getTransitionDuration() / 3);
3971
- const c = color(self.colors[d.index]);
3972
- const ct = c ? c.darker(1).toString() : self.colors[d.index];
3973
- const slice = select(this);
3974
- // Hovered mid-way through the enter sweep, the slice is finished first: growing it straight
3975
- // from its part-swept path morphed it oddly on the way out to the hover shape. Only then -
3976
- // re-entering a slice mid-way through its hover shrink must grow it from where it is, not
3977
- // snap it back to rest first (which flickered).
3978
- if (active(this, 'enter')) {
3979
- slice.interrupt('enter').attr('d', self.arcShape(d));
3980
- }
3981
- slice
3982
- .transition(t)
3983
- .attr('d', self.arcOverShape)
3984
- .style('fill', ct);
4341
+ pop(this, d);
3985
4342
  })
3986
4343
  .on('mousemove', (event, d) => {
3987
4344
  self.showTooltip(event, d.data, { index: d.index });
3988
4345
  })
3989
4346
  .on('mouseout', function (_, d) {
3990
4347
  self.hideTooltip();
3991
- select(this)
3992
- .transition()
3993
- .duration(self.transitionService.getTransitionDuration() / 3)
3994
- .attr('d', self.arcShape)
3995
- .style('fill', self.colors[d.index]);
4348
+ rest(this, d);
3996
4349
  })
3997
4350
  .on('click', (_event, d) => {
3998
4351
  this.sliceClickedSource.next(d.data);
3999
- })
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
4000
4368
  // Named, so the hover transitions (unnamed) and the check above can tell it apart from them.
4001
4369
  .transition('enter')
4002
4370
  .duration(this.transitionService.getTransitionDuration())
@@ -4181,5 +4549,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImpor
4181
4549
  * Generated bundle index. Do not edit.
4182
4550
  */
4183
4551
 
4184
- export { PcacAreaChart, PcacAreaChartConfig, PcacAxisChartConfig, PcacAxisConfig, PcacAxisSubLabels, PcacBarHorizontalChartColorOverrideConfig, PcacBarHorizontalChartComponent, PcacBarHorizontalChartConfig, PcacBarVerticalChartColorOverrideConfig, 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 };
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 };
4185
4553
  //# sourceMappingURL=pioneer-code-pioneer-charts.mjs.map