@pioneer-code/pioneer-charts 22.2.16 → 22.2.18

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
  /**
@@ -102,8 +102,8 @@ class PcacAxisConfig {
102
102
  * the axis. Labels follow the marks (D3 places them at tick length + 3px), and the chart's
103
103
  * margins grow or shrink by the same amount so the plot area makes room for them - a longer
104
104
  * tick means a slightly smaller plot, never labels pushed off the edge. Only the per-tick marks
105
- * change; the axis line's two end-caps keep their default length. Color comes from the theme
106
- * (`.pcac-axis-tick-marks .tick line`, `$gray-900`, the same as the axis line).
105
+ * change; the axis line's two end-caps keep their default length. Colored by `tickColor`, the
106
+ * theme's `$gray-900` (like the axis line) by default.
107
107
  */
108
108
  tickSize;
109
109
  /**
@@ -118,8 +118,8 @@ class PcacAxisConfig {
118
118
  tickLabelColor;
119
119
  /**
120
120
  * Draw a solid line along the axis itself (the full length of the axis, with D3's short
121
- * end-caps). Off by default, as the theme has always hidden it. Color comes from the theme
122
- * (`.pcac-axis-line .domain`, `$gray-900`).
121
+ * end-caps). Off by default, as the theme has always hidden it. Colored by `lineColor`, the
122
+ * theme's `$gray-900` by default.
123
123
  */
124
124
  showLine = false;
125
125
  /**
@@ -152,7 +152,8 @@ class PcacAxisConfig {
152
152
  * (`yAxis`) or key (`xAxis`) in the default tooltip. On the line/area/plot charts the x axis's
153
153
  * format is also what decides how a point's `key` maps to an x position (by index for the
154
154
  * default, `Decimal` and `DateTime` by the key's own value on a linear/time scale - see
155
- * `PcacLineAreaChartConfig`); a bar chart's category axis ignores it. Default `None`, which
155
+ * `PcacLineAreaChartConfig`); on a bar chart's category axis it only formats keys that are
156
+ * numbers, and shows any other key as it is. Default `None`, which
156
157
  * on those charts behaves as `DatasetLength`.
157
158
  */
158
159
  format = PcacFormatEnum.None;
@@ -331,8 +332,24 @@ function formatValue(pcacFormat, value) {
331
332
  *
332
333
  * Numeric formats take their precision from the scale's tick step where the scale has one: a
333
334
  * fixed precision is fine for a whole domain but breaks down once zoom narrows it to a few units.
335
+ *
336
+ * On a category axis (a band scale - a bar chart's groups) only keys that are numbers are formatted
337
+ * - `'0.25'` reads `25%` - and any other key is shown as it is: a format there, easy to set by
338
+ * mistake on the horizontal chart (where y is the category axis), turned every label into `NaN%`
339
+ * or `Chipsm`.
334
340
  */
335
341
  function axisTickFormat(pcacFormat, scale, ticks) {
342
+ const format = valueTickFormat(pcacFormat, scale, ticks);
343
+ if (!format || !('bandwidth' in scale)) {
344
+ return format;
345
+ }
346
+ return (d) => isNumericKey(d) ? format(d) : String(d);
347
+ }
348
+ /** A category key that reads as a number - `0.25`, `'1500'` - rather than text like `'Chips'`. */
349
+ function isNumericKey(key) {
350
+ return (typeof key === 'number' || (typeof key === 'string' && key.trim() !== '')) && Number.isFinite(Number(key));
351
+ }
352
+ function valueTickFormat(pcacFormat, scale, ticks) {
336
353
  const withTicks = scale;
337
354
  switch (pcacFormat) {
338
355
  case PcacFormatEnum.Percentage:
@@ -385,6 +402,9 @@ class PcacAxisBuilder {
385
402
  .attr('class', 'pcac-y-axis')
386
403
  // Axes are raised above the interactive overlays (see raiseAxes) and take no mouse events
387
404
  .attr('pointer-events', 'none')
405
+ // Nor are they read out: the marks' own names carry each key and value (see marks.ts), and
406
+ // every tick label as well would only bury them.
407
+ .attr('aria-hidden', 'true')
388
408
  .classed('pcac-axis-tick-marks', config.yAxis.tickSize !== undefined)
389
409
  .classed('pcac-axis-line', config.yAxis.showLine)
390
410
  .call(yAxis)
@@ -406,6 +426,7 @@ class PcacAxisBuilder {
406
426
  const group = config.svg.append('g')
407
427
  .attr('class', 'pcac-x-axis')
408
428
  .attr('pointer-events', 'none')
429
+ .attr('aria-hidden', 'true')
409
430
  .classed('pcac-axis-tick-marks', config.xAxis.tickSize !== undefined)
410
431
  .classed('pcac-axis-line', config.xAxis.showLine)
411
432
  .attr('transform', 'translate(0,' + config.height + ')')
@@ -491,6 +512,7 @@ class PcacGridBuilder {
491
512
  drawVerticalGrid(config) {
492
513
  config.svg.append('g')
493
514
  .attr('class', 'pcac-grid pcac-grid-vertical')
515
+ .attr('aria-hidden', 'true')
494
516
  .style('--pcac-grid-color', () => config.color ?? null)
495
517
  .selectAll('g.rule')
496
518
  .data(gridLines(config.xScale, config.numberOfTicks))
@@ -507,6 +529,7 @@ class PcacGridBuilder {
507
529
  drawHorizontalGrid(config) {
508
530
  config.svg.append('g')
509
531
  .attr('class', 'pcac-grid pcac-grid-horizontal')
532
+ .attr('aria-hidden', 'true')
510
533
  .style('--pcac-grid-color', () => config.color ?? null)
511
534
  .selectAll('g.pcac-grid-rule')
512
535
  .data(gridLines(config.yScale, config.numberOfTicks))
@@ -529,7 +552,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImpor
529
552
  }] });
530
553
 
531
554
  class PcacColorService {
532
- primary = '#43425d';
533
555
  primaryLight = '#a3a1fb';
534
556
  success = '#5ee2a0';
535
557
  danger = '#ff6565';
@@ -597,11 +619,6 @@ class PcacColorService {
597
619
  this.customScale = colors.length ? [...colors] : null;
598
620
  this.changed();
599
621
  }
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
622
  setPrimaryLight(color) {
606
623
  this.primaryLight = color;
607
624
  this.changed();
@@ -642,8 +659,18 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImpor
642
659
 
643
660
  class PcacTransitionService {
644
661
  transitionDuration = 750;
662
+ document = inject(DOCUMENT);
663
+ /**
664
+ * How long the charts animate - bars growing, lines drawing in, hover fades - or 0 when the user
665
+ * has asked their system to reduce motion, so every chart is drawn in its final state at once.
666
+ * Read on every call rather than once, so changing the setting applies from the next draw on.
667
+ */
645
668
  getTransitionDuration() {
646
- return this.transitionDuration;
669
+ return this.prefersReducedMotion() ? 0 : this.transitionDuration;
670
+ }
671
+ /** `false` where there's no `matchMedia` to ask - server-side rendering, a test environment. */
672
+ prefersReducedMotion() {
673
+ return this.document.defaultView?.matchMedia?.('(prefers-reduced-motion: reduce)').matches ?? false;
647
674
  }
648
675
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacTransitionService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
649
676
  static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacTransitionService, providedIn: 'root' });
@@ -655,6 +682,189 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImpor
655
682
  }]
656
683
  }] });
657
684
 
685
+ /** Marks the elements `makeMarksAccessible` set up, so navigation can find a chart's marks. */
686
+ const MARK_ATTR = 'data-pcac-mark';
687
+ /**
688
+ * Makes a chart's marks usable from the keyboard and readable by a screen reader, alongside the
689
+ * pointer handlers they already have.
690
+ *
691
+ * Every mark gets a role and a name, but only one of them - the chart's "tab stop" - is in the Tab
692
+ * order (see `refreshTabStop`): Tab reaches the chart once, and the arrow keys move between its
693
+ * marks, Home and End to the first and last. A chart of a thousand bars isn't a thousand Tab
694
+ * presses to get past. Focus does what hovering does (`focus`), and Enter or Space what a click
695
+ * does (`activate`); Escape hides the tooltip, as moving the pointer away would - and goes no
696
+ * further while it has one to hide, so it doesn't also close a dialog the chart is in. Keys pressed
697
+ * with Alt, Ctrl or Cmd are left to the browser (Alt+Left is Back).
698
+ *
699
+ * A mark takes focus from the keyboard only: pressing the pointer on one is kept from focusing it,
700
+ * so a click doesn't leave a keyboard-style tooltip and focus ring behind on the clicked mark. It
701
+ * does let go of a mark in the same chart that has focus, which would otherwise stay highlighted,
702
+ * its tooltip gone, while the pointer is at work elsewhere in the chart.
703
+ */
704
+ function makeMarksAccessible(marks, access) {
705
+ const skipped = (d) => access.skip?.(d) ?? false;
706
+ // The marks showing what focus shows (their tooltip, highlighted), until blur or Escape.
707
+ const open = new WeakSet();
708
+ marks
709
+ .attr(MARK_ATTR, (d) => (skipped(d) ? null : ''))
710
+ .attr('aria-hidden', (d) => (skipped(d) ? 'true' : null))
711
+ // An image, with a name, rather than a button: whether the chart's click output has a listener
712
+ // can't be told from here (the pie, donut, line, area and plot charts' own wrappers always
713
+ // listen, to pass it on), and a button that does nothing would be a lie. Enter and Space still
714
+ // do what a click does, and the click listener has browsers report the mark as clickable.
715
+ .attr('role', (d) => (skipped(d) ? null : 'img'))
716
+ .attr('aria-label', function (d) {
717
+ return skipped(d) ? null : access.label(d, this);
718
+ })
719
+ .attr('tabindex', (d) => (skipped(d) ? null : -1))
720
+ // The events are typed plainly as `Event`: with the element type generic here, d3's typings
721
+ // (@types/d3-selection 3.0.12 on) can't narrow them to `MouseEvent`/`KeyboardEvent`.
722
+ .on('mousedown.pcac-mark', function (event) {
723
+ event.preventDefault();
724
+ const focused = this.ownerDocument.activeElement;
725
+ if (focused !== this && focused?.hasAttribute(MARK_ATTR) && sameChart(focused, this)) {
726
+ focused.blur();
727
+ }
728
+ })
729
+ .on('focus.pcac-mark', function (_event, d) {
730
+ open.add(this);
731
+ access.focus(this, d);
732
+ })
733
+ .on('blur.pcac-mark', function (_event, d) {
734
+ open.delete(this);
735
+ access.blur(this, d);
736
+ })
737
+ .on('keydown.pcac-mark', function (event, d) {
738
+ const { key, altKey, ctrlKey, metaKey } = event;
739
+ if (altKey || ctrlKey || metaKey) {
740
+ return;
741
+ }
742
+ switch (key) {
743
+ case 'Enter':
744
+ case ' ':
745
+ event.preventDefault();
746
+ access.activate(d);
747
+ return;
748
+ case 'Escape':
749
+ // Only while there's a tooltip to hide; a second Escape carries on to whatever the
750
+ // chart is in (a dialog closes, as it would have).
751
+ if (open.delete(this)) {
752
+ event.preventDefault();
753
+ event.stopPropagation();
754
+ access.blur(this, d);
755
+ }
756
+ return;
757
+ }
758
+ const target = neighbor(this, key);
759
+ if (target) {
760
+ event.preventDefault();
761
+ moveFocus(this, target);
762
+ }
763
+ });
764
+ }
765
+ /**
766
+ * Notes the chart's Tab stop - and whether it has focus - before a redraw removes every mark, so
767
+ * `refreshTabStop` can put both back: a keyboard user who pressed Enter on a bar, with a click
768
+ * handler that updates the data, stays on that bar rather than being dropped at the top of the
769
+ * page. `null` when the chart has no Tab stop.
770
+ */
771
+ function captureMarkFocus(root) {
772
+ if (!root) {
773
+ return null;
774
+ }
775
+ const marks = navigableMarks(root);
776
+ const index = marks.findIndex((mark) => mark.getAttribute('tabindex') === '0');
777
+ if (index < 0) {
778
+ return null;
779
+ }
780
+ return { index, focused: root.ownerDocument.activeElement === marks[index] };
781
+ }
782
+ /**
783
+ * Puts the chart's one Tab stop (`tabindex="0"`) on a mark that can take focus; every other mark
784
+ * is `-1` already (`makeMarksAccessible`). Call once a chart's marks are drawn, and again whenever
785
+ * marks can have been hidden - by zoom, say - so Tab doesn't land on one that can't be focused and
786
+ * skip the chart.
787
+ *
788
+ * Leaves the Tab stop where it is while that mark can still take focus, so coming back to the chart
789
+ * returns to the mark last visited. After a redraw, given what `captureMarkFocus` noted, it goes
790
+ * back to the same place - the last mark, if there are fewer now - and takes focus back if it had
791
+ * it. Touches only the old and new stops, as it runs on every zoom frame.
792
+ */
793
+ function refreshTabStop(root, previous = null) {
794
+ if (!root) {
795
+ return;
796
+ }
797
+ const current = root.querySelector(`[${MARK_ATTR}][tabindex="0"]`);
798
+ if (current && !previous && !isNotDisplayed(current, root)) {
799
+ return;
800
+ }
801
+ const marks = navigableMarks(root);
802
+ const stop = previous ? marks[Math.min(previous.index, marks.length - 1)] : marks[0];
803
+ if (current && current !== stop) {
804
+ current.setAttribute('tabindex', '-1');
805
+ }
806
+ if (!stop) {
807
+ return;
808
+ }
809
+ stop.setAttribute('tabindex', '0');
810
+ if (previous?.focused) {
811
+ stop.focus({ preventScroll: true });
812
+ }
813
+ }
814
+ /** Whether two marks are in the same chart (the same `<svg>`). */
815
+ function sameChart(a, b) {
816
+ return (a.ownerSVGElement ?? a.parentElement) === (b.ownerSVGElement ?? b.parentElement);
817
+ }
818
+ /** The chart's marks that can take focus now, in drawing order. */
819
+ function navigableMarks(root) {
820
+ return Array.from(root.querySelectorAll(`[${MARK_ATTR}]`)).filter((mark) => !isNotDisplayed(mark, root));
821
+ }
822
+ /**
823
+ * Whether the mark, or a group it's in, isn't displayed: a hidden series, or a point zoomed out of
824
+ * the plot. Read from the `display` attribute and inline style the builders set, rather than from
825
+ * layout, which a browser without one (a test environment) doesn't have.
826
+ */
827
+ function isNotDisplayed(mark, root) {
828
+ for (let node = mark; node && node !== root; node = node.parentElement) {
829
+ if (node.getAttribute('display') === 'none' || node.style?.display === 'none') {
830
+ return true;
831
+ }
832
+ }
833
+ return false;
834
+ }
835
+ /** The mark an arrow, Home or End key moves to from `mark`, or `null` for any other key. */
836
+ function neighbor(mark, key) {
837
+ const root = mark.ownerSVGElement ?? mark.parentElement;
838
+ if (!root) {
839
+ return null;
840
+ }
841
+ const marks = navigableMarks(root);
842
+ const at = marks.indexOf(mark);
843
+ switch (key) {
844
+ case 'ArrowRight':
845
+ case 'ArrowDown':
846
+ return marks[Math.min(at + 1, marks.length - 1)] ?? null;
847
+ case 'ArrowLeft':
848
+ case 'ArrowUp':
849
+ return marks[Math.max(at - 1, 0)] ?? null;
850
+ case 'Home':
851
+ return marks[0] ?? null;
852
+ case 'End':
853
+ return marks[marks.length - 1] ?? null;
854
+ default:
855
+ return null;
856
+ }
857
+ }
858
+ /** Moves focus, and the chart's Tab stop with it, from one mark to another. */
859
+ function moveFocus(from, to) {
860
+ if (from === to) {
861
+ return;
862
+ }
863
+ from.setAttribute('tabindex', '-1');
864
+ to.setAttribute('tabindex', '0');
865
+ to.focus();
866
+ }
867
+
658
868
  class PcacTooltipBuilder {
659
869
  appRef = inject(ApplicationRef);
660
870
  document = inject(DOCUMENT);
@@ -674,6 +884,7 @@ class PcacTooltipBuilder {
674
884
  this.shell ??= select(this.document.body)
675
885
  .append('div')
676
886
  .attr('class', 'pcac-d3-tooltip')
887
+ .attr('id', PcacTooltipBuilder.ID)
677
888
  .attr('role', 'tooltip');
678
889
  return this.shell;
679
890
  }
@@ -691,12 +902,18 @@ class PcacTooltipBuilder {
691
902
  * chart rebuilding or being destroyed would close the tooltip another chart is showing.
692
903
  */
693
904
  owner = null;
905
+ /**
906
+ * The tooltip element's id, for a focused mark's `aria-describedby` (see `PcacChart.showMarkTooltip`).
907
+ * One per page, like the element.
908
+ */
909
+ static ID = 'pcac-tooltip';
694
910
  /** Space left between the tooltip and whatever it's placed next to (the cursor or an anchor). */
695
911
  static GAP = 8;
696
912
  /**
697
913
  * Shows the tooltip for a hovered datum. Renders `template` when the chart has one projected;
698
914
  * otherwise falls back to the default key/value content, formatted per `valueFormat`/`keyFormat`.
699
915
  * Placed beside `anchor` when one is given (see `positionBeside`), else above the event's position.
916
+ * `event` can be `null` only with an `anchor`: a tooltip shown for keyboard focus has no pointer.
700
917
  * `owner` is what's showing it (see `hideTooltip`).
701
918
  */
702
919
  showTooltip(event, template, context, valueFormat, keyFormat, anchor, owner) {
@@ -711,7 +928,7 @@ class PcacTooltipBuilder {
711
928
  if (anchor) {
712
929
  this.positionBeside(shell, anchor);
713
930
  }
714
- else {
931
+ else if (event) {
715
932
  this.positionAbove(shell, event);
716
933
  }
717
934
  }
@@ -743,7 +960,7 @@ class PcacTooltipBuilder {
743
960
  */
744
961
  renderDefault(data, valueFormat, keyFormat) {
745
962
  this.destroyView();
746
- const { key, value } = this.getBarTipData(data, valueFormat, keyFormat);
963
+ const { key, value } = tooltipText(data, valueFormat, keyFormat);
747
964
  const shell = this.tooltip
748
965
  .classed('pcac-d3-tooltip-default', true)
749
966
  .html(null)
@@ -852,41 +1069,6 @@ class PcacTooltipBuilder {
852
1069
  .style('left', x + (view?.scrollX ?? 0) + 'px')
853
1070
  .style('top', y + (view?.scrollY ?? 0) + 'px');
854
1071
  }
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
1072
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacTooltipBuilder, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
891
1073
  static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacTooltipBuilder, providedIn: 'root' });
892
1074
  }
@@ -896,6 +1078,44 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImpor
896
1078
  providedIn: 'root',
897
1079
  }]
898
1080
  }] });
1081
+ /**
1082
+ * The default tooltip's two lines as plain text; `key` is null when the datum has none. Also what a
1083
+ * mark's accessible name is made of (see `PcacChart.markLabel`), so the two read the same.
1084
+ */
1085
+ function tooltipText(data, valueFormat, keyFormat) {
1086
+ let value = data.value;
1087
+ let key = data.key;
1088
+ // Formatted the way the value's axis labels it (see `formatValue`), so the tooltip for a
1089
+ // point reads like the axis it sits against - `1:30pm`, not `13.5`, on a OneDayHours axis.
1090
+ // A missing value stays blank rather than being formatted as `0%` / `null F`.
1091
+ if (value !== null && value !== undefined) {
1092
+ value = formatValue(valueFormat, value) ?? value;
1093
+ }
1094
+ if (key !== null && key !== undefined && key !== '') {
1095
+ // A key that doesn't parse as a date is shown as it is, rather than as "Invalid Date".
1096
+ if (keyFormat === PcacFormatEnum.DateTime && !Number.isNaN(new Date(key).getTime())) {
1097
+ key = new Date(key).toLocaleDateString('en-US', {
1098
+ day: '2-digit',
1099
+ month: '2-digit',
1100
+ year: 'numeric',
1101
+ hour: '2-digit',
1102
+ minute: '2-digit',
1103
+ second: '2-digit'
1104
+ });
1105
+ }
1106
+ else if (keyFormat === PcacFormatEnum.Decimal) {
1107
+ // Only where the key *is* the x value. Every other x format positions points by index,
1108
+ // so its axis labels the index, not the key - formatting the key would only make it
1109
+ // disagree with the axis (and tag text keys with a unit: `Mon` read `Monm` on Minutes).
1110
+ key = formatValue(keyFormat, key) ?? key;
1111
+ }
1112
+ }
1113
+ // A key of 0 (e.g. hour 0) is a real key; only a missing or empty one leaves the line out.
1114
+ return {
1115
+ key: key === null || key === undefined || key === '' ? null : String(key),
1116
+ value: value === null || value === undefined ? '' : String(value),
1117
+ };
1118
+ }
899
1119
 
900
1120
  /** The most of its container's width a chart's measured left (label) margin may take. */
901
1121
  const MAX_LABEL_MARGIN_SHARE = 0.5;
@@ -1157,6 +1377,63 @@ class PcacChart {
1157
1377
  hideTooltip() {
1158
1378
  this.tooltipBuilder.hideTooltip(this);
1159
1379
  }
1380
+ /**
1381
+ * A mark's accessible name: its parent's key (the bar's group, the point's series), its own key
1382
+ * and its value, formatted as the tooltip formats them - `"Chips, 2024: 680"`.
1383
+ */
1384
+ markLabel(data, options = {}) {
1385
+ const { key, value } = tooltipText(data, options.valueFormat, options.keyFormat);
1386
+ const parentKey = options.parent?.key;
1387
+ const names = [parentKey === null || parentKey === undefined || parentKey === '' ? null : String(parentKey), key]
1388
+ .filter((name) => name !== null);
1389
+ return `${names.join(', ')}${names.length ? ': ' : ''}${value === '' ? 'no value' : value}`;
1390
+ }
1391
+ /**
1392
+ * Keyboard focus on a mark: its tooltip, beside it (there's no pointer to put it above). With a
1393
+ * consumer `pcacTooltip` template, the mark is also described by the tooltip, so a screen reader
1394
+ * reads whatever the template adds to the mark's own name; the default tooltip only repeats it.
1395
+ */
1396
+ showMarkTooltip(element, data, options) {
1397
+ this.showTooltip(null, data, { ...options, anchor: options.anchor ?? element });
1398
+ if (this.tooltipTemplate()) {
1399
+ element.setAttribute('aria-describedby', PcacTooltipBuilder.ID);
1400
+ }
1401
+ }
1402
+ /**
1403
+ * Where the chart's Tab stop was before the last redraw removed its marks, and whether it had
1404
+ * focus; put back by `restoreTabStop`. Kept until then - across a build that couldn't draw (no
1405
+ * width yet) - and not overwritten by a second clear in the same build, which finds no marks.
1406
+ */
1407
+ markFocus = null;
1408
+ noteMarkFocus(chartElm) {
1409
+ this.markFocus = captureMarkFocus(chartElm.nativeElement) ?? this.markFocus;
1410
+ }
1411
+ /**
1412
+ * Puts the chart's Tab stop on its new marks - where it was before the redraw, with focus if it
1413
+ * had it (see marks.ts). Every builder calls this once its marks are drawn.
1414
+ */
1415
+ restoreTabStop(chartElm) {
1416
+ refreshTabStop(chartElm.nativeElement, this.markFocus);
1417
+ this.markFocus = null;
1418
+ }
1419
+ /**
1420
+ * The chart's accessible name when its config gives no `ariaLabel`: its type, and the titles of
1421
+ * the axes it shows - "Bar chart - x axis: Product, y axis: Units sold". The titles are drawn
1422
+ * inside the axis groups, which are hidden from screen readers (the marks' own names carry each
1423
+ * key and value), so this is the only place they're read out.
1424
+ */
1425
+ defaultChartName() {
1426
+ const axes = [['x', this.xAxis], ['y', this.yAxis]];
1427
+ const titles = axes
1428
+ .filter(([, axis]) => !axis.hide && !!axis.label)
1429
+ .map(([name, axis]) => `${name} axis: ${axis.label}`);
1430
+ return titles.length ? `${this.chartTypeLabel} - ${titles.join(', ')}` : this.chartTypeLabel;
1431
+ }
1432
+ /** Keyboard focus leaving a mark: the undoing of `showMarkTooltip`. */
1433
+ hideMarkTooltip(element) {
1434
+ this.hideTooltip();
1435
+ element.removeAttribute('aria-describedby');
1436
+ }
1160
1437
  /**
1161
1438
  * Builders are provided per chart component, so Angular calls this when the component is
1162
1439
  * destroyed. A chart removed while hovered (an `@if` flip, a route change) gets no `mouseout`,
@@ -1172,6 +1449,7 @@ class PcacChart {
1172
1449
  */
1173
1450
  clearChart(chartElm) {
1174
1451
  this.hideTooltip();
1452
+ this.noteMarkFocus(chartElm);
1175
1453
  select(chartElm.nativeElement).select('g').remove();
1176
1454
  }
1177
1455
  /**
@@ -1190,6 +1468,7 @@ class PcacChart {
1190
1468
  initializeChartState(chartElm, config) {
1191
1469
  // The rebuild removes the hovered element, which gets no mouseout to close its tooltip.
1192
1470
  this.hideTooltip();
1471
+ this.noteMarkFocus(chartElm);
1193
1472
  select(chartElm.nativeElement).select('g').remove();
1194
1473
  // One color per group or per series within a group, whichever needs more. Bar charts, which
1195
1474
  // color by series across groups, top this up with `ensureColorCount()`. Read before the width
@@ -1213,10 +1492,12 @@ class PcacChart {
1213
1492
  return false;
1214
1493
  }
1215
1494
  this.width = measuredWidth;
1216
- // Announced as a single image with a name, rather than as a pile of unlabelled shapes.
1495
+ // A named group of marks, each with its own name and role (see marks.ts), rather than a pile of
1496
+ // unlabelled shapes. (A `role="img"`, which this used to be, would hide the marks inside it from
1497
+ // a screen reader, and keyboard focus on them would announce nothing.)
1217
1498
  select(chartElm.nativeElement)
1218
- .attr('role', 'img')
1219
- .attr('aria-label', config.ariaLabel || this.chartTypeLabel);
1499
+ .attr('role', 'group')
1500
+ .attr('aria-label', config.ariaLabel || this.defaultChartName());
1220
1501
  this.height = this.resolveHeight(container, config);
1221
1502
  this.colors = colors;
1222
1503
  this.lastContainerWidth = containerWidth;
@@ -1326,6 +1607,11 @@ class PcacChart {
1326
1607
  if (this.yAxis.tickSize !== undefined) {
1327
1608
  axisY.tickSizeInner(this.yAxis.tickSize);
1328
1609
  }
1610
+ // Labelled as the axis will label them, or a unit suffix went unmeasured and ran off the edge.
1611
+ const format = axisTickFormat(this.yAxis.format, yScale, this.yAxis.ticks);
1612
+ if (format) {
1613
+ axisY.tickFormat(format);
1614
+ }
1329
1615
  let max = 0;
1330
1616
  select(chartElm.nativeElement).append('g')
1331
1617
  .call(axisY)
@@ -1500,6 +1786,24 @@ function seriesKeys(groups) {
1500
1786
  }
1501
1787
  return [...keys];
1502
1788
  }
1789
+ /**
1790
+ * The slots a grouped (not stacked) chart places each group's bars in, and which slot a bar takes:
1791
+ * its series key - so a series sits in the same place in every group - when the keys tell the
1792
+ * series apart (see `hasDistinctSeriesKeys`), and its position in its group otherwise. Placed by
1793
+ * key regardless, bars with no key (`PcacData`'s default `null`) or a repeated one all fell into
1794
+ * one slot and were drawn on top of each other, only the last visible - though they were already
1795
+ * colored by position in that case.
1796
+ */
1797
+ function seriesSlots(groups) {
1798
+ if (hasDistinctSeriesKeys(groups)) {
1799
+ return { domain: seriesKeys(groups), slotOf: (bar) => bar.key };
1800
+ }
1801
+ const size = groups.reduce((max, group) => Math.max(max, group.data?.length ?? 0), 0);
1802
+ return {
1803
+ domain: Array.from({ length: size }, (_, i) => String(i)),
1804
+ slotOf: (_bar, index) => String(index),
1805
+ };
1806
+ }
1503
1807
  /**
1504
1808
  * Whether every bar has a key that is unique within its own group - what coloring bars by series
1505
1809
  * key needs. Without that (keys left `null`, as `PcacData` defaults them, or repeated within a
@@ -1521,9 +1825,43 @@ function hasDistinctSeriesKeys(groups) {
1521
1825
  function canRoundBands(length, count) {
1522
1826
  return count > 0 && length / count >= 2;
1523
1827
  }
1828
+ /**
1829
+ * A bar config's `colorOverride` as the plain list of colors every chart now takes. Up to 22.2 the
1830
+ * bar charts wrapped it as `{ colors: [...] }`; a config still shaped that way - which TypeScript
1831
+ * misses when it's spread together or loaded as JSON - is still read, and `warn` is called (see
1832
+ * `colorOverrideWarning`). Only for colors actually set: before 22.2.17 every bar config defaulted
1833
+ * to `{ colors: [] }`, so one saved as JSON back then would warn about an override its author
1834
+ * never chose.
1835
+ */
1836
+ function barColorOverride(override, warn = () => undefined) {
1837
+ if (!override || Array.isArray(override)) {
1838
+ return override;
1839
+ }
1840
+ const colors = override.colors;
1841
+ if (colors?.length) {
1842
+ warn();
1843
+ }
1844
+ return colors;
1845
+ }
1846
+ /**
1847
+ * The development-mode warning about the old `colorOverride` shape, for one chart: each bar builder
1848
+ * keeps its own, so it warns once per chart - like the pie's leftover-`donut` warning - rather than
1849
+ * once per page, which also made it depend on which chart happened to build first.
1850
+ */
1851
+ function colorOverrideWarning() {
1852
+ let warned = false;
1853
+ return () => {
1854
+ if (warned || typeof ngDevMode === 'undefined' || !ngDevMode) {
1855
+ return;
1856
+ }
1857
+ warned = true;
1858
+ console.warn('Pioneer Charts: a bar chart\'s `colorOverride` is now a plain array of colors, like the other ' +
1859
+ 'charts\' - use `colorOverride: [...]` rather than `colorOverride: { colors: [...] }`.');
1860
+ };
1861
+ }
1524
1862
 
1525
1863
  /**
1526
- * Provided per-component (see PcacBarHorizontalChartComponent's `providers`), not root-scoped:
1864
+ * Provided per-component (see PcacBarHorizontalChart's `providers`), not root-scoped:
1527
1865
  * this builder extends PcacChart, which holds mutable per-chart-instance state (margin, width,
1528
1866
  * height, colors, svg). A root singleton would be shared and clobbered by every
1529
1867
  * <pcac-bar-horizontal-chart> rendered at once.
@@ -1532,6 +1870,10 @@ class BarHorizontalChartBuilder extends PcacChart {
1532
1870
  xScale;
1533
1871
  yScaleStacked;
1534
1872
  yScaleGrouped;
1873
+ /** Warns, once for this chart, about a `colorOverride` in its old `{ colors }` shape. */
1874
+ warnOfColorOverride = colorOverrideWarning();
1875
+ /** A bar's slot in `yScaleGrouped`, from its datum and its index in its group (see `seriesSlots`). */
1876
+ slotOf = (bar) => bar.key;
1535
1877
  barClickedSource = new Subject();
1536
1878
  barClicked$ = this.barClickedSource.asObservable();
1537
1879
  chartTypeLabel = 'Bar chart';
@@ -1550,7 +1892,7 @@ class BarHorizontalChartBuilder extends PcacChart {
1550
1892
  return;
1551
1893
  }
1552
1894
  this.ensureColorCount(seriesKeys(config.data).length);
1553
- this.applyColorOverride(config.colorOverride?.colors);
1895
+ this.applyColorOverride(barColorOverride(config.colorOverride, this.warnOfColorOverride));
1554
1896
  if (!this.buildScales(chartElm, config)) {
1555
1897
  return;
1556
1898
  }
@@ -1567,11 +1909,13 @@ class BarHorizontalChartBuilder extends PcacChart {
1567
1909
  // Rounded to whole pixels for crisp bar edges, while there's room to (see canRoundBands).
1568
1910
  .round(canRoundBands(this.height, config.data.length))
1569
1911
  .padding(0.1);
1912
+ const slots = seriesSlots(config.data);
1913
+ this.slotOf = slots.slotOf;
1570
1914
  this.yScaleGrouped = scaleBand()
1571
1915
  .padding(0.05)
1572
1916
  .range([0, this.yScaleStacked.bandwidth()])
1573
- .round(canRoundBands(this.yScaleStacked.bandwidth(), seriesKeys(config.data).length))
1574
- .domain(seriesKeys(config.data));
1917
+ .round(canRoundBands(this.yScaleStacked.bandwidth(), slots.domain.length))
1918
+ .domain(slots.domain);
1575
1919
  // The left margin is sized to the y axis's labels - unless there is no y axis to size it to
1576
1920
  if (!this.yAxis.hide && !this.setHorizontalMarginsBasedOnContent(chartElm, this.yScaleStacked)) {
1577
1921
  return false;
@@ -1586,6 +1930,7 @@ class BarHorizontalChartBuilder extends PcacChart {
1586
1930
  this.drawGrids(this.xScale, this.yScaleStacked);
1587
1931
  this.addGroups(config);
1588
1932
  this.axisBuilder.raiseAxes(this.svg);
1933
+ this.restoreTabStop(chartElm);
1589
1934
  }
1590
1935
  addGroups(config) {
1591
1936
  const groupsContainer = this.svg.append('g')
@@ -1637,13 +1982,34 @@ class BarHorizontalChartBuilder extends PcacChart {
1637
1982
  }
1638
1983
  return this.colors[byKey ? keys.indexOf(d.key) : Number(bar.getAttribute('data-group-bar-id'))];
1639
1984
  };
1640
- groups.enter().append('rect')
1985
+ // The hover fades run as their own named transition: an unnamed one would cancel the enter
1986
+ // transition still growing the bar, leaving it part-grown until the next rebuild. Shared by
1987
+ // the pointer and keyboard focus (see makeMarksAccessible).
1988
+ const highlight = (bar, d) => {
1989
+ const fill = fillOf(d, bar);
1990
+ select(bar)
1991
+ .transition('hover')
1992
+ .duration(this.transitionService.getTransitionDuration() / 5)
1993
+ .style('fill', color(fill)?.darker(1).toString() ?? fill);
1994
+ };
1995
+ const rest = (bar, d) => {
1996
+ select(bar)
1997
+ .transition('hover')
1998
+ .duration(this.transitionService.getTransitionDuration() / 5)
1999
+ .style('fill', fillOf(d, bar));
2000
+ };
2001
+ const tooltipOptions = (bar) => {
2002
+ const groupIndex = Number(bar.parentNode.getAttribute('data-group-id'));
2003
+ const index = Number(bar.getAttribute('data-group-bar-id'));
2004
+ return { index, parent: config.data[groupIndex], parentIndex: groupIndex, valueFormat: this.xAxis.format };
2005
+ };
2006
+ const bars = groups.enter().append('rect')
1641
2007
  .attr('class', 'pcac-bar')
1642
2008
  .attr('x', (d) => this.xScale(startOf(d)))
1643
2009
  // A stacked bar spans its whole group, which is already translated into place; looking its
1644
2010
  // series key up in the group band put it off in another group's slot whenever the key
1645
2011
  // matched a group key.
1646
- .attr('y', (d) => config.isStacked ? 0 : this.yScaleGrouped(d.key) ?? 0)
2012
+ .attr('y', (d, i) => config.isStacked ? 0 : this.yScaleGrouped(this.slotOf(d, i)) ?? 0)
1647
2013
  .attr('data-group-bar-id', (_, i) => {
1648
2014
  return i;
1649
2015
  })
@@ -1652,30 +2018,33 @@ class BarHorizontalChartBuilder extends PcacChart {
1652
2018
  return fillOf(d, this);
1653
2019
  })
1654
2020
  .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
2021
  .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);
2022
+ highlight(this, d);
1663
2023
  })
1664
2024
  .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 });
2025
+ self.showTooltip(event, d, tooltipOptions(this));
1668
2026
  })
1669
2027
  .on('mouseout', function (_event, d) {
1670
2028
  self.hideTooltip();
1671
- select(this)
1672
- .transition('hover')
1673
- .duration(self.transitionService.getTransitionDuration() / 5)
1674
- .style('fill', fillOf(d, this));
2029
+ rest(this, d);
1675
2030
  })
1676
2031
  .on('click', (_event, d) => {
1677
2032
  this.barClickedSource.next(d);
1678
- })
2033
+ });
2034
+ makeMarksAccessible(bars, {
2035
+ label: (d, bar) => this.markLabel(d, { parent: tooltipOptions(bar).parent, valueFormat: this.xAxis.format }),
2036
+ skip: (d) => !!d.hide,
2037
+ activate: (d) => this.barClickedSource.next(d),
2038
+ focus: (bar, d) => {
2039
+ highlight(bar, d);
2040
+ this.showMarkTooltip(bar, d, tooltipOptions(bar));
2041
+ },
2042
+ blur: (bar, d) => {
2043
+ this.hideMarkTooltip(bar);
2044
+ rest(bar, d);
2045
+ },
2046
+ });
2047
+ bars
1679
2048
  .transition()
1680
2049
  .duration(this.transitionService.getTransitionDuration())
1681
2050
  .attr('width', (d) => {
@@ -1731,7 +2100,7 @@ class BarHorizontalChartBuilder extends PcacChart {
1731
2100
  // Placed in its bar's slot up front - only its value (`x`) animates. Set on the transition,
1732
2101
  // it slid in from the top of the group, where the vertical chart's appear in place.
1733
2102
  // ScaleBand can return undefined for a key outside its domain; `.attr()` needs null, not undefined.
1734
- .attr('y', (d) => this.yScaleGrouped(d.key) ?? null)
2103
+ .attr('y', (d, i) => this.yScaleGrouped(this.slotOf(d, i)) ?? null)
1735
2104
  .attr('height', this.yScaleGrouped.bandwidth());
1736
2105
  rects.filter(function () {
1737
2106
  return thresholdOf(this) === null;
@@ -1886,7 +2255,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImpor
1886
2255
  }]
1887
2256
  }] });
1888
2257
 
1889
- class PcacBarHorizontalChartComponent {
2258
+ class PcacBarHorizontalChart {
1890
2259
  chartBuilder = inject(BarHorizontalChartBuilder);
1891
2260
  config = input.required(/* @ts-ignore */
1892
2261
  ...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
@@ -1923,10 +2292,10 @@ class PcacBarHorizontalChartComponent {
1923
2292
  this.chartBuilder.buildChart(this.chartElm(), config);
1924
2293
  }
1925
2294
  }
1926
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacBarHorizontalChartComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
1927
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.2.0", type: PcacBarHorizontalChartComponent, isStandalone: true, selector: "pcac-bar-horizontal-chart", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { barClicked: "barClicked" }, host: { properties: { "class.pcac-height-full": "config().heightFull" } }, providers: [BarHorizontalChartBuilder], 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-bar-horizontal-chart\">\n <svg #chart></svg>\n</section>\n", styles: [".pcac-bar-horizontal-chart{display:block}.pcac-bar-horizontal-chart svg{width:100%;display:block}pcac-bar-horizontal-chart.pcac-height-full{display:block;height:100%}pcac-bar-horizontal-chart.pcac-height-full .pcac-bar-horizontal-chart{height:100%}\n"], encapsulation: i0.ViewEncapsulation.None });
2295
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacBarHorizontalChart, deps: [], target: i0.ɵɵFactoryTarget.Component });
2296
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.2.0", type: PcacBarHorizontalChart, isStandalone: true, selector: "pcac-bar-horizontal-chart", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { barClicked: "barClicked" }, host: { properties: { "class.pcac-height-full": "config().heightFull" } }, providers: [BarHorizontalChartBuilder], 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-bar-horizontal-chart\">\n <svg #chart></svg>\n</section>\n", styles: [".pcac-bar-horizontal-chart{display:block}.pcac-bar-horizontal-chart svg{width:100%;display:block}pcac-bar-horizontal-chart.pcac-height-full{display:block;height:100%}pcac-bar-horizontal-chart.pcac-height-full .pcac-bar-horizontal-chart{height:100%}\n"], encapsulation: i0.ViewEncapsulation.None });
1928
2297
  }
1929
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacBarHorizontalChartComponent, decorators: [{
2298
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacBarHorizontalChart, decorators: [{
1930
2299
  type: Component,
1931
2300
  args: [{ selector: 'pcac-bar-horizontal-chart', host: { '[class.pcac-height-full]': 'config().heightFull' }, encapsulation: ViewEncapsulation.None, providers: [BarHorizontalChartBuilder], template: "<section class=\"pcac-bar-horizontal-chart\">\n <svg #chart></svg>\n</section>\n", styles: [".pcac-bar-horizontal-chart{display:block}.pcac-bar-horizontal-chart svg{width:100%;display:block}pcac-bar-horizontal-chart.pcac-height-full{display:block;height:100%}pcac-bar-horizontal-chart.pcac-height-full .pcac-bar-horizontal-chart{height:100%}\n"] }]
1932
2301
  }], ctorParameters: () => [], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }], chartElm: [{ type: i0.ViewChild, args: ['chart', { isSignal: true }] }], barClicked: [{ type: i0.Output, args: ["barClicked"] }], tooltipTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => PcacTooltipDirective), { isSignal: true }] }] } });
@@ -1935,14 +2304,16 @@ class PcacBarHorizontalChartConfig extends PcacAxisChartConfig {
1935
2304
  isStacked = false;
1936
2305
  thresholds = [];
1937
2306
  spreadColorsPerGroup = false;
1938
- colorOverride = new PcacBarHorizontalChartColorOverrideConfig();
1939
- }
1940
- class PcacBarHorizontalChartColorOverrideConfig {
1941
- colors = [];
2307
+ /**
2308
+ * Bar colors, any CSS color, in place of the theme palette - by series, or by group with
2309
+ * `spreadColorsPerGroup`. Repeated when there are more series (or groups) than colors. Omitted
2310
+ * or empty, the theme palette is used - optional, as on every chart's config.
2311
+ */
2312
+ colorOverride;
1942
2313
  }
1943
2314
 
1944
2315
  /**
1945
- * Provided per-component (see PcacBarVerticalChartComponent's `providers`), not root-scoped:
2316
+ * Provided per-component (see PcacBarVerticalChart's `providers`), not root-scoped:
1946
2317
  * this builder extends PcacChart, which holds mutable per-chart-instance state (margin, width,
1947
2318
  * height, colors, svg). A root singleton would be shared and clobbered by every
1948
2319
  * <pcac-bar-vertical-chart> rendered at once.
@@ -1950,6 +2321,10 @@ class PcacBarHorizontalChartColorOverrideConfig {
1950
2321
  class BarVerticalChartBuilder extends PcacChart {
1951
2322
  xScaleStacked;
1952
2323
  xScaleGrouped;
2324
+ /** Warns, once for this chart, about a `colorOverride` in its old `{ colors }` shape. */
2325
+ warnOfColorOverride = colorOverrideWarning();
2326
+ /** A bar's slot in `xScaleGrouped`, from its datum and its index in its group (see `seriesSlots`). */
2327
+ slotOf = (bar) => bar.key;
1953
2328
  yScale;
1954
2329
  barClickedSource = new Subject();
1955
2330
  barClicked$ = this.barClickedSource.asObservable();
@@ -1968,7 +2343,7 @@ class BarVerticalChartBuilder extends PcacChart {
1968
2343
  return;
1969
2344
  }
1970
2345
  this.ensureColorCount(seriesKeys(config.data).length);
1971
- this.applyColorOverride(config.colorOverride?.colors);
2346
+ this.applyColorOverride(barColorOverride(config.colorOverride, this.warnOfColorOverride));
1972
2347
  this.buildScales(config);
1973
2348
  this.drawChart(chartElm, config);
1974
2349
  }
@@ -1985,11 +2360,13 @@ class BarVerticalChartBuilder extends PcacChart {
1985
2360
  // Rounded to whole pixels for crisp bar edges, while there's room to (see canRoundBands).
1986
2361
  .round(canRoundBands(this.width, config.data.length))
1987
2362
  .padding(0.1);
2363
+ const slots = seriesSlots(config.data);
2364
+ this.slotOf = slots.slotOf;
1988
2365
  this.xScaleGrouped = scaleBand()
1989
2366
  .padding(0.2)
1990
2367
  .range([0, this.xScaleStacked.bandwidth()])
1991
- .round(canRoundBands(this.xScaleStacked.bandwidth(), seriesKeys(config.data).length))
1992
- .domain(seriesKeys(config.data));
2368
+ .round(canRoundBands(this.xScaleStacked.bandwidth(), slots.domain.length))
2369
+ .domain(slots.domain);
1993
2370
  }
1994
2371
  drawChart(chartElm, config) {
1995
2372
  this.buildContainer(chartElm);
@@ -1997,6 +2374,7 @@ class BarVerticalChartBuilder extends PcacChart {
1997
2374
  this.drawGrids(this.xScaleStacked, this.yScale);
1998
2375
  this.addGroups(config);
1999
2376
  this.axisBuilder.raiseAxes(this.svg);
2377
+ this.restoreTabStop(chartElm);
2000
2378
  }
2001
2379
  addGroups(config) {
2002
2380
  const groupsContainer = this.svg.append('g')
@@ -2050,12 +2428,33 @@ class BarVerticalChartBuilder extends PcacChart {
2050
2428
  }
2051
2429
  return this.colors[byKey ? keys.indexOf(d.key) : Number(bar.getAttribute('data-group-bar-id'))];
2052
2430
  };
2053
- group.enter().append('rect')
2431
+ // The hover fades run as their own named transition: an unnamed one would cancel the enter
2432
+ // transition still growing the bar, leaving it part-grown until the next rebuild. Shared by
2433
+ // the pointer and keyboard focus (see makeMarksAccessible).
2434
+ const highlight = (bar, d) => {
2435
+ const fill = fillOf(d, bar);
2436
+ select(bar)
2437
+ .transition('hover')
2438
+ .duration(this.transitionService.getTransitionDuration() / 5)
2439
+ .style('fill', color(fill)?.darker(1).toString() ?? fill);
2440
+ };
2441
+ const rest = (bar, d) => {
2442
+ select(bar)
2443
+ .transition('hover')
2444
+ .duration(this.transitionService.getTransitionDuration() / 5)
2445
+ .style('fill', fillOf(d, bar));
2446
+ };
2447
+ const tooltipOptions = (bar) => {
2448
+ const groupIndex = Number(bar.parentNode.getAttribute('data-group-id'));
2449
+ const index = Number(bar.getAttribute('data-group-bar-id'));
2450
+ return { index, parent: config.data[groupIndex], parentIndex: groupIndex, valueFormat: this.yAxis.format };
2451
+ };
2452
+ const bars = group.enter().append('rect')
2054
2453
  .attr('class', 'pcac-bar')
2055
2454
  // A stacked bar spans its whole group, which is already translated into place; looking its
2056
2455
  // series key up in the group band put it off in another group's slot whenever the key
2057
2456
  // matched a group key.
2058
- .attr('x', (d) => config.isStacked ? 0 : this.xScaleGrouped(d.key) ?? 0)
2457
+ .attr('x', (d, i) => config.isStacked ? 0 : this.xScaleGrouped(this.slotOf(d, i)) ?? 0)
2059
2458
  .attr('data-group-bar-id', (_, i) => {
2060
2459
  return i;
2061
2460
  })
@@ -2066,30 +2465,33 @@ class BarVerticalChartBuilder extends PcacChart {
2066
2465
  return this.height;
2067
2466
  })
2068
2467
  .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
2468
  .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);
2469
+ highlight(this, d);
2077
2470
  })
2078
2471
  .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 });
2472
+ self.showTooltip(event, d, tooltipOptions(this));
2082
2473
  })
2083
2474
  .on('mouseout', function (_event, d) {
2084
2475
  self.hideTooltip();
2085
- select(this)
2086
- .transition('hover')
2087
- .duration(self.transitionService.getTransitionDuration() / 5)
2088
- .style('fill', fillOf(d, this));
2476
+ rest(this, d);
2089
2477
  })
2090
2478
  .on('click', (_, d) => {
2091
2479
  this.barClickedSource.next(d);
2092
- })
2480
+ });
2481
+ makeMarksAccessible(bars, {
2482
+ label: (d, bar) => this.markLabel(d, { parent: tooltipOptions(bar).parent, valueFormat: this.yAxis.format }),
2483
+ skip: (d) => !!d.hide,
2484
+ activate: (d) => this.barClickedSource.next(d),
2485
+ focus: (bar, d) => {
2486
+ highlight(bar, d);
2487
+ this.showMarkTooltip(bar, d, tooltipOptions(bar));
2488
+ },
2489
+ blur: (bar, d) => {
2490
+ this.hideMarkTooltip(bar);
2491
+ rest(bar, d);
2492
+ },
2493
+ });
2494
+ bars
2093
2495
  .transition()
2094
2496
  .duration(this.transitionService.getTransitionDuration())
2095
2497
  .attr('width', !config.isStacked ? this.xScaleGrouped.bandwidth() : this.xScaleStacked.bandwidth())
@@ -2170,12 +2572,12 @@ class BarVerticalChartBuilder extends PcacChart {
2170
2572
  }
2171
2573
  applyPreTransitionThresholdStyles(elm) {
2172
2574
  return elm.attr('class', 'pcac-threshold')
2173
- .attr('x', (d) => {
2575
+ .attr('x', (d, i) => {
2174
2576
  // Not every caller's selection has a per-item PcacData bound (the whole-chart threshold
2175
2577
  // rect has none), hence the defensive fallback rather than assuming `d` is always present.
2176
2578
  const datum = d;
2177
2579
  // ScaleBand can return undefined for a key outside its domain; `.attr()` needs null, not undefined.
2178
- return this.xScaleGrouped(datum ? datum.key : '') ?? null;
2580
+ return this.xScaleGrouped(datum ? this.slotOf(datum, i) : '') ?? null;
2179
2581
  })
2180
2582
  .attr('y', () => {
2181
2583
  return this.height;
@@ -2204,7 +2606,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImpor
2204
2606
  type: Injectable
2205
2607
  }] });
2206
2608
 
2207
- class PcacBarVerticalChartComponent {
2609
+ class PcacBarVerticalChart {
2208
2610
  chartBuilder = inject(BarVerticalChartBuilder);
2209
2611
  config = input.required(/* @ts-ignore */
2210
2612
  ...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
@@ -2241,10 +2643,10 @@ class PcacBarVerticalChartComponent {
2241
2643
  this.chartBuilder.buildChart(this.chartElm(), config);
2242
2644
  }
2243
2645
  }
2244
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacBarVerticalChartComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
2245
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.2.0", type: PcacBarVerticalChartComponent, isStandalone: true, selector: "pcac-bar-vertical-chart", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { barClicked: "barClicked" }, host: { properties: { "class.pcac-height-full": "config().heightFull" } }, providers: [BarVerticalChartBuilder], 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-bar-vertical-chart\">\n <svg #chart></svg>\n</section>\n", styles: [".pcac-bar-vertical-chart svg{width:100%;display:block}pcac-bar-vertical-chart.pcac-height-full{display:block;height:100%}pcac-bar-vertical-chart.pcac-height-full .pcac-bar-vertical-chart{height:100%}\n"], encapsulation: i0.ViewEncapsulation.None });
2646
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacBarVerticalChart, deps: [], target: i0.ɵɵFactoryTarget.Component });
2647
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.2.0", type: PcacBarVerticalChart, isStandalone: true, selector: "pcac-bar-vertical-chart", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { barClicked: "barClicked" }, host: { properties: { "class.pcac-height-full": "config().heightFull" } }, providers: [BarVerticalChartBuilder], 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-bar-vertical-chart\">\n <svg #chart></svg>\n</section>\n", styles: [".pcac-bar-vertical-chart svg{width:100%;display:block}pcac-bar-vertical-chart.pcac-height-full{display:block;height:100%}pcac-bar-vertical-chart.pcac-height-full .pcac-bar-vertical-chart{height:100%}\n"], encapsulation: i0.ViewEncapsulation.None });
2246
2648
  }
2247
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacBarVerticalChartComponent, decorators: [{
2649
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacBarVerticalChart, decorators: [{
2248
2650
  type: Component,
2249
2651
  args: [{ selector: 'pcac-bar-vertical-chart', host: { '[class.pcac-height-full]': 'config().heightFull' }, encapsulation: ViewEncapsulation.None, providers: [BarVerticalChartBuilder], template: "<section class=\"pcac-bar-vertical-chart\">\n <svg #chart></svg>\n</section>\n", styles: [".pcac-bar-vertical-chart svg{width:100%;display:block}pcac-bar-vertical-chart.pcac-height-full{display:block;height:100%}pcac-bar-vertical-chart.pcac-height-full .pcac-bar-vertical-chart{height:100%}\n"] }]
2250
2652
  }], ctorParameters: () => [], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }], chartElm: [{ type: i0.ViewChild, args: ['chart', { isSignal: true }] }], barClicked: [{ type: i0.Output, args: ["barClicked"] }], tooltipTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => PcacTooltipDirective), { isSignal: true }] }] } });
@@ -2253,10 +2655,12 @@ class PcacBarVerticalChartConfig extends PcacAxisChartConfig {
2253
2655
  isStacked = false;
2254
2656
  thresholds = [];
2255
2657
  spreadColorsPerGroup = false;
2256
- colorOverride = new PcacBarVerticalChartColorOverrideConfig();
2257
- }
2258
- class PcacBarVerticalChartColorOverrideConfig {
2259
- colors = [];
2658
+ /**
2659
+ * Bar colors, any CSS color, in place of the theme palette - by series, or by group with
2660
+ * `spreadColorsPerGroup`. Repeated when there are more series (or groups) than colors. Omitted
2661
+ * or empty, the theme palette is used - optional, as on every chart's config.
2662
+ */
2663
+ colorOverride;
2260
2664
  }
2261
2665
 
2262
2666
  // Only what a consumer configures, binds or styles with. The chart plumbing - the `PcacChart`
@@ -2272,7 +2676,9 @@ class PcacLegendConfig {
2272
2676
  heading = null;
2273
2677
  items = [];
2274
2678
  }
2679
+ let nextLegendId = 0;
2275
2680
  class PcacLegend {
2681
+ headingId = `pcac-legend-heading-${nextLegendId++}`;
2276
2682
  colorService = inject(PcacColorService);
2277
2683
  config = model.required(/* @ts-ignore */
2278
2684
  ...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
@@ -2285,11 +2691,14 @@ class PcacLegend {
2285
2691
  this.itemClicked.emit(items);
2286
2692
  }
2287
2693
  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"] });
2694
+ 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: "@if (config().heading) {\n<div class=\"pcac-legend-label\" [id]=\"headingId\"><small>{{config().heading}}</small></div>\n}\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}@media(prefers-reduced-motion:reduce){.pcac-legend-circle{transition:none}}.pcac-legend-unchecked{opacity:.5}.pcac-legend-item:focus-visible{outline:2px solid currentColor;outline-offset:2px}\n"] });
2289
2695
  }
2290
2696
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacLegend, decorators: [{
2291
2697
  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"] }]
2698
+ args: [{ selector: 'pcac-legend', host: {
2699
+ role: 'group',
2700
+ '[attr.aria-labelledby]': 'config().heading ? headingId : null',
2701
+ }, template: "@if (config().heading) {\n<div class=\"pcac-legend-label\" [id]=\"headingId\"><small>{{config().heading}}</small></div>\n}\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}@media(prefers-reduced-motion:reduce){.pcac-legend-circle{transition:none}}.pcac-legend-unchecked{opacity:.5}.pcac-legend-item:focus-visible{outline:2px solid currentColor;outline-offset:2px}\n"] }]
2293
2702
  }], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }, { type: i0.Output, args: ["configChange"] }], itemClicked: [{ type: i0.Output, args: ["itemClicked"] }] } });
2294
2703
 
2295
2704
  var PcacLineAreaPlotChartConfigType;
@@ -2362,15 +2771,18 @@ class PcacLineAreaChartConfig extends PcacAxisChartConfig {
2362
2771
  /**
2363
2772
  * Zoom and pan along the x / y axis (scroll / pinch to zoom 1x-10x, drag to pan, never leaving
2364
2773
  * 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.
2774
+ * only one enabled the other axis simply stays put. Both off by default. The zoom is kept when
2775
+ * the chart redraws - a new config, a series toggled in a legend, a resize (which keeps the same
2776
+ * part of the domain in view) - and dropped when zoom is turned off or the zoomable axes change.
2366
2777
  */
2367
2778
  enableZoomX = false;
2368
2779
  enableZoomY = false;
2369
2780
  /**
2370
- * Hex color codes to override the default colors, one per series in order. Repeats from the
2371
- * start when there are more series than colors, as the default palette does.
2781
+ * Series colors, any CSS color, in place of the theme palette, one per series in order. Repeats
2782
+ * from the start when there are more series than colors, as the default palette does. Omitted or
2783
+ * empty, the theme palette is used - optional, as on every chart's config.
2372
2784
  */
2373
- colorOverride = [];
2785
+ colorOverride;
2374
2786
  /**
2375
2787
  * Bounding box for any point images (`PcacData.image`) on this chart. Optional; each field falls
2376
2788
  * back to the `PcacPointImageConfig` default when not given, so a consumer only setting `image`
@@ -2454,7 +2866,9 @@ class PlaChartEffectsBuilder {
2454
2866
  }
2455
2867
  buildCollection() {
2456
2868
  const collection = this.config.svg.append('g')
2457
- .attr('class', 'effects');
2869
+ .attr('class', 'effects')
2870
+ // The hover crosshair repeats, for the pointer, what the points' own names say.
2871
+ .attr('aria-hidden', 'true');
2458
2872
  collection.append('path')
2459
2873
  .attr('class', 'effect-line');
2460
2874
  const mousePerLine = collection.selectAll('.effect-group')
@@ -3028,10 +3442,28 @@ const CHART_TYPE_LABELS = {
3028
3442
  */
3029
3443
  class PlaChartBuilder extends PcacChart {
3030
3444
  effectsBuilder = inject(PlaChartEffectsBuilder);
3445
+ /**
3446
+ * The scales as drawn: `baseScales` with the zoom this build started at (see `keptZoom`) applied.
3447
+ * A zoom gesture rescales from `baseScales`, never from these.
3448
+ */
3031
3449
  scales;
3450
+ /** The unzoomed scales, spanning the whole domain. */
3451
+ baseScales;
3452
+ /**
3453
+ * The zoom a rebuild picks up again, so a new config (a series toggled in the legend, live
3454
+ * data) or a resize doesn't throw away where the user had zoomed to. The pan is kept as a share
3455
+ * of the plot's size, which is what carries it across a resize: the same part of the domain
3456
+ * stays in view. `axes` is which axes were zoomable; a build where that differs starts unzoomed.
3457
+ */
3458
+ keptZoom = null;
3459
+ /** The zoom this build starts at, if any; applied to the zoom behavior once it's attached. */
3460
+ startZoom = null;
3461
+ /** Set while `startZoom` is handed to the zoom behavior, whose resulting zoom event is skipped. */
3462
+ restoringZoom = false;
3032
3463
  lineGenerator;
3033
3464
  areaGenerator;
3034
- zoomBehavior;
3465
+ /** This build's zoom behavior; `null` while zoom is off. */
3466
+ zoomBehavior = null;
3035
3467
  dotClickedSource = new Subject();
3036
3468
  config;
3037
3469
  /**
@@ -3112,21 +3544,29 @@ class PlaChartBuilder extends PcacChart {
3112
3544
  return;
3113
3545
  }
3114
3546
  this.applyColorOverride(this.config.colorOverride);
3115
- this.scales = new PlaChartScalesBuilder().build(this.xAxis, this.yAxis, this.config.data, this.width, this.height);
3547
+ this.baseScales = new PlaChartScalesBuilder().build(this.xAxis, this.yAxis, this.config.data, this.width, this.height);
3548
+ this.startZoom = this.resumeZoom();
3549
+ this.scales = this.startZoom ? this.zoomedScales(this.startZoom) : this.baseScales;
3116
3550
  this.lineGenerator = buildLineGenerator(this.xAxis.format, this.scales);
3117
3551
  this.areaGenerator = buildAreaGenerator(this.xAxis.format, this.scales, this.height);
3118
3552
  if (this.zoomEnabled) {
3119
- this.zoomBehavior = buildZoomBehavior(this.width, this.height, (event) => {
3553
+ const behavior = buildZoomBehavior(this.width, this.height, (event) => {
3120
3554
  // Zoom moves the points, not the mouse: the hovered one slides out from under a still
3121
3555
  // cursor (or is hidden outright, see `pointDisplay`), and either way the browser never
3122
3556
  // sends it a mouseout - its tooltip would stay up, and its dot stay grown, until the
3123
3557
  // cursor happened to cross it again. So the hover is ended here, on every zoom event.
3558
+ // The build's own starting zoom, handed to the behavior: already drawn that way. And a
3559
+ // gesture begun on an earlier build - a drag still going when live data or a resize redrew
3560
+ // the chart, which d3-zoom carries on through listeners on the window - belongs to a
3561
+ // drawing that's gone: left to run, it moved this one and overwrote the kept zoom with its
3562
+ // own, and the next gesture snapped back.
3563
+ if (this.restoringZoom || behavior !== this.zoomBehavior) {
3564
+ return;
3565
+ }
3124
3566
  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 };
3567
+ this.keepZoom(event.transform);
3568
+ const zoomedScales = this.zoomedScales(event.transform);
3569
+ const { x: newX, y: newY } = zoomedScales;
3130
3570
  // Update the zoomed axes, each with its grid: the grid hangs off the axis's ticks, so it
3131
3571
  // is redrawn against the rescaled scale and dropped back underneath everything (append
3132
3572
  // puts it on top).
@@ -3159,6 +3599,8 @@ class PlaChartBuilder extends PcacChart {
3159
3599
  this.svg.selectAll('.dots').selectAll('.point')
3160
3600
  .attr('transform', (d, i) => this.pointTransform(d, i, zoomedScales))
3161
3601
  .attr('display', (d, i) => this.pointDisplay(d, i, zoomedScales));
3602
+ // The chart's Tab stop may just have been zoomed out of the plot, and hidden.
3603
+ refreshTabStop(this.svg.node()?.ownerSVGElement ?? null);
3162
3604
  // A fan-out's anchor is positioned like the points it belongs to, so it moves the same way;
3163
3605
  // its spokes are re-aimed because the ring's shift back into the plot (`fanOutShift`)
3164
3606
  // depends on where the anchor now is.
@@ -3180,6 +3622,10 @@ class PlaChartBuilder extends PcacChart {
3180
3622
  this.svg.selectAll('.fan-outs').raise();
3181
3623
  this.svg.selectAll('.dots').raise();
3182
3624
  });
3625
+ this.zoomBehavior = behavior;
3626
+ }
3627
+ else {
3628
+ this.zoomBehavior = null;
3183
3629
  }
3184
3630
  this.drawChart(chartElm, this.config, type);
3185
3631
  }
@@ -3213,6 +3659,7 @@ class PlaChartBuilder extends PcacChart {
3213
3659
  this.drawPointRanges();
3214
3660
  this.drawFanOuts();
3215
3661
  this.drawDots(config);
3662
+ this.restoreTabStop(chartElm);
3216
3663
  }
3217
3664
  /**
3218
3665
  * Resolves `pointImage`, finds the points that share a coordinate and, on a plot chart with
@@ -3291,8 +3738,46 @@ class PlaChartBuilder extends PcacChart {
3291
3738
  get zoomEnabled() {
3292
3739
  return !!(this.config.enableZoomX || this.config.enableZoomY);
3293
3740
  }
3741
+ /** Which axes zoom, as `keptZoom.axes` records them. */
3742
+ get zoomAxes() {
3743
+ return `${!!this.config.enableZoomX}${!!this.config.enableZoomY}`;
3744
+ }
3745
+ /**
3746
+ * `baseScales` under a zoom transform. A d3 zoom transform is always two-dimensional; only the
3747
+ * enabled axes follow it and the other keeps its original scale, so that component of the
3748
+ * gesture is simply ignored.
3749
+ */
3750
+ zoomedScales(transform) {
3751
+ return {
3752
+ x: this.config.enableZoomX ? transform.rescaleX(this.baseScales.x) : this.baseScales.x,
3753
+ y: this.config.enableZoomY ? transform.rescaleY(this.baseScales.y) : this.baseScales.y,
3754
+ };
3755
+ }
3756
+ /** Records a zoom for the next build to resume (see `keptZoom`). */
3757
+ keepZoom(transform) {
3758
+ this.keptZoom = {
3759
+ k: transform.k,
3760
+ x: transform.x / this.width,
3761
+ y: transform.y / this.height,
3762
+ axes: this.zoomAxes,
3763
+ };
3764
+ }
3765
+ /**
3766
+ * The zoom this build starts at: the kept one, fitted to this build's plot size, or `null` for
3767
+ * none - zoom off, the zoomable axes changed, or never zoomed. Forgets the kept zoom when it
3768
+ * can't be resumed, so turning zoom off and on again starts unzoomed.
3769
+ */
3770
+ resumeZoom() {
3771
+ const kept = this.keptZoom;
3772
+ if (!kept || !this.zoomEnabled || kept.axes !== this.zoomAxes) {
3773
+ this.keptZoom = null;
3774
+ return null;
3775
+ }
3776
+ return zoomIdentity.translate(kept.x * this.width, kept.y * this.height).scale(kept.k);
3777
+ }
3294
3778
  attachZoomBehavior() {
3295
- if (!this.zoomEnabled)
3779
+ const zoom = this.zoomBehavior;
3780
+ if (!this.zoomEnabled || !zoom)
3296
3781
  return;
3297
3782
  // A transparent rect so the empty plot area is a hit target too: a `<g>` has no area of its
3298
3783
  // own, so wheel/drag only reaches it through something painted. The rect is only ever that -
@@ -3313,7 +3798,14 @@ class PlaChartBuilder extends PcacChart {
3313
3798
  .attr('height', this.height)
3314
3799
  .attr('fill', 'none')
3315
3800
  .attr('pointer-events', 'all');
3316
- this.svg.call(this.zoomBehavior);
3801
+ this.svg.call(zoom);
3802
+ // A resumed zoom is already drawn (`scales`); the behavior is told it too, so the next gesture
3803
+ // carries on from there rather than from the whole domain.
3804
+ if (this.startZoom) {
3805
+ this.restoringZoom = true;
3806
+ this.svg.call(zoom.transform, this.startZoom);
3807
+ this.restoringZoom = false;
3808
+ }
3317
3809
  }
3318
3810
  drawLineArea(config, type) {
3319
3811
  for (let i = 0; i < config.data.length; i++) {
@@ -3519,34 +4011,27 @@ class PlaChartBuilder extends PcacChart {
3519
4011
  .attr('class', 'point')
3520
4012
  .attr('transform', (d, i) => this.pointTransform(d, i, this.scales))
3521
4013
  .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]);
4014
+ .on('mouseover', function (_event, d) {
4015
+ self.enterPoint(this, d, series, index);
3545
4016
  })
3546
4017
  .on('mouseout', () => this.leavePoint())
3547
4018
  .on('click', (_event, d) => {
3548
4019
  this.dotClickedSource.next(d);
3549
4020
  });
4021
+ makeMarksAccessible(points, {
4022
+ label: (d) => this.markLabel(d, { parent: series, valueFormat: this.yAxis.format, keyFormat: this.xAxis.format }),
4023
+ activate: (d) => this.dotClickedSource.next(d),
4024
+ focus: (point, d) => {
4025
+ this.enterPoint(point, d, series, index);
4026
+ if (this.tooltipTemplate()) {
4027
+ point.setAttribute('aria-describedby', PcacTooltipBuilder.ID);
4028
+ }
4029
+ },
4030
+ blur: (point) => {
4031
+ this.leavePoint();
4032
+ point.removeAttribute('aria-describedby');
4033
+ },
4034
+ });
3550
4035
  points.filter((d) => !d.image)
3551
4036
  .append('circle')
3552
4037
  .attr('class', 'dot')
@@ -3579,6 +4064,35 @@ class PlaChartBuilder extends PcacChart {
3579
4064
  .attr('y', (d) => -maxHeight / 2 + this.offsetOf(d).dy);
3580
4065
  }
3581
4066
  }
4067
+ /**
4068
+ * Starts a hover on a point - its tooltip, beside it; its range brought forward; its dot grown -
4069
+ * for the pointer and keyboard focus alike (see makeMarksAccessible). Ended by `leavePoint`.
4070
+ */
4071
+ enterPoint(point, d, series, index) {
4072
+ const duration = this.transitionService.getTransitionDuration();
4073
+ this.hoveredPoint = point;
4074
+ this.focusPointRange(d);
4075
+ // `d` is the very element bound from `series.data`, so identity lookup is exact.
4076
+ this.showTooltip(null, d, {
4077
+ index: series.data.indexOf(d),
4078
+ parent: series,
4079
+ parentIndex: index,
4080
+ coincident: this.coincidentWith(d),
4081
+ valueFormat: this.yAxis.format,
4082
+ keyFormat: this.xAxis.format,
4083
+ // The dot or image itself rather than the group, so the tooltip clears what's drawn.
4084
+ anchor: select(point).select('.dot, .dot-image').node() ?? point,
4085
+ });
4086
+ // No-op for an image point (no circle inside to grow). Its own transition name, so it
4087
+ // runs alongside the enter rise rather than cancelling it (see DOT_HOVER_TRANSITION);
4088
+ // it only takes over the entry's size tween, which it would otherwise fight over `r`.
4089
+ select(point).select('.dot')
4090
+ .interrupt(DOT_GROW_TRANSITION)
4091
+ .transition(DOT_HOVER_TRANSITION)
4092
+ .duration(duration / 3)
4093
+ .attr('r', 6)
4094
+ .attr('fill', this.colors[index]);
4095
+ }
3582
4096
  /**
3583
4097
  * Ends the current hover, if there is one: hides the tooltip and shrinks the dot back. Shared by
3584
4098
  * the point's own mouseout and the zoom handler, which has to end a hover the browser won't
@@ -3736,11 +4250,11 @@ class PcacLineAreaChartComponent {
3736
4250
  }
3737
4251
  }
3738
4252
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacLineAreaChartComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
3739
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.2.0", type: PcacLineAreaChartComponent, isStandalone: true, selector: "pcac-line-area-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: { dotClicked: "dotClicked" }, host: { properties: { "class.pcac-height-full": "config().heightFull" } }, providers: [PlaChartBuilder, PlaChartEffectsBuilder], viewQueries: [{ propertyName: "chartElm", first: true, predicate: ["chart"], descendants: true, isSignal: true }], ngImport: i0, template: "<section class=\"pcac-line-area-chart\">\n <svg #chart></svg>\n</section>\n\n", styles: [".pcac-line-area-chart svg{width:100%;display:block}.pcac-line-area-chart .dot{stroke-width:2px}.pcac-line-area-chart .fan-out-spoke{stroke:var(--pcac-fan-out-spoke-color, #ced4da);stroke-width:1px}.pcac-line-area-chart .fan-out-anchor{fill:var(--pcac-fan-out-anchor-color, #6c757d)}.pcac-line-area-chart .point-ranges .point-range-series{--pcac-point-range-resolved-color: var(--pcac-point-range-color, var(--pcac-point-range-series-color))}.pcac-line-area-chart .point-ranges .point-range{opacity:var(--pcac-point-range-resting-opacity, 1);transition:opacity .15s ease-out}.pcac-line-area-chart .point-ranges .point-range.is-focused{opacity:1}.pcac-line-area-chart .point-ranges.pcac-range-hover{--pcac-point-range-resting-opacity: 0}.pcac-line-area-chart .point-ranges.pcac-range-faint{--pcac-point-range-resting-opacity: var(--pcac-point-range-faint-opacity, .2)}.pcac-line-area-chart .point-ranges.pcac-range-always.has-focus .point-range:not(.is-focused){opacity:.5}.pcac-line-area-chart .point-ranges .point-range-whisker,.pcac-line-area-chart .point-ranges .point-range-cap{stroke:var(--pcac-point-range-resolved-color);stroke-width:1.25px}.pcac-line-area-chart .point-ranges .point-range-box{fill:var(--pcac-point-range-resolved-color);fill-opacity:.1;stroke:var(--pcac-point-range-resolved-color);stroke-opacity:.7;stroke-width:1.25px}.pcac-line-area-chart .point-ranges .point-range-stop{stop-color:var(--pcac-point-range-resolved-color)}.pcac-line-area-chart .point-ranges .is-focused .point-range-whisker,.pcac-line-area-chart .point-ranges .is-focused .point-range-cap,.pcac-line-area-chart .point-ranges .is-focused .point-range-box{stroke-width:1.75px}.pcac-line-area-chart .point-ranges .is-focused .point-range-box{fill-opacity:.18}@media(prefers-reduced-motion:reduce){.pcac-line-area-chart .point-ranges .point-range{transition:none}}.pcac-line-area-chart .effects-canvas{fill:none}.pcac-line-area-chart .effect-line{stroke:#ced4da;stroke-width:1px;opacity:0}.pcac-line-area-chart .effect-circle{stroke-width:1px;fill:none;opacity:0}.pcac-line-area-chart .effect-text{font-size:11px;font-weight:700;fill:#343a40}pcac-line-chart.pcac-height-full,pcac-area-chart.pcac-height-full,pcac-plot-chart.pcac-height-full,pcac-line-area-chart.pcac-height-full{display:block;height:100%}pcac-line-area-chart.pcac-height-full .pcac-line-area-chart{height:100%}\n"], encapsulation: i0.ViewEncapsulation.None });
4253
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.2.0", type: PcacLineAreaChartComponent, isStandalone: true, selector: "pcac-line-area-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: { dotClicked: "dotClicked" }, host: { properties: { "class.pcac-height-full": "config().heightFull" } }, providers: [PlaChartBuilder, PlaChartEffectsBuilder], viewQueries: [{ propertyName: "chartElm", first: true, predicate: ["chart"], descendants: true, isSignal: true }], ngImport: i0, template: "<section class=\"pcac-line-area-chart\">\n <svg #chart></svg>\n</section>\n\n", styles: [".pcac-line-area-chart svg{width:100%;display:block}.pcac-line-area-chart .dot{stroke-width:2px}.pcac-line-area-chart .fan-out-spoke{stroke:var(--pcac-fan-out-spoke-color, #ced4da);stroke-width:1px}.pcac-line-area-chart .fan-out-anchor{fill:var(--pcac-fan-out-anchor-color, #6c757d)}.pcac-line-area-chart .point-ranges .point-range-series{--pcac-point-range-resolved-color: var(--pcac-point-range-color, var(--pcac-point-range-series-color))}.pcac-line-area-chart .point-ranges .point-range{opacity:var(--pcac-point-range-resting-opacity, 1);transition:opacity .15s ease-out}.pcac-line-area-chart .point-ranges .point-range.is-focused{opacity:1}.pcac-line-area-chart .point-ranges.pcac-range-hover{--pcac-point-range-resting-opacity: 0}.pcac-line-area-chart .point-ranges.pcac-range-faint{--pcac-point-range-resting-opacity: var(--pcac-point-range-faint-opacity, .2)}.pcac-line-area-chart .point-ranges.pcac-range-always.has-focus .point-range:not(.is-focused){opacity:.5}.pcac-line-area-chart .point-ranges .point-range-whisker,.pcac-line-area-chart .point-ranges .point-range-cap{stroke:var(--pcac-point-range-resolved-color);stroke-width:1.25px}.pcac-line-area-chart .point-ranges .point-range-box{fill:var(--pcac-point-range-resolved-color);fill-opacity:.1;stroke:var(--pcac-point-range-resolved-color);stroke-opacity:.7;stroke-width:1.25px}.pcac-line-area-chart .point-ranges .point-range-stop{stop-color:var(--pcac-point-range-resolved-color)}.pcac-line-area-chart .point-ranges .is-focused .point-range-whisker,.pcac-line-area-chart .point-ranges .is-focused .point-range-cap,.pcac-line-area-chart .point-ranges .is-focused .point-range-box{stroke-width:1.75px}.pcac-line-area-chart .point-ranges .is-focused .point-range-box{fill-opacity:.18}@media(prefers-reduced-motion:reduce){.pcac-line-area-chart .point-ranges .point-range{transition:none}}.pcac-line-area-chart .effects-canvas{fill:none}.pcac-line-area-chart .effect-line{stroke:var(--pcac-crosshair-line-color, #ced4da);stroke-width:1px;opacity:0}.pcac-line-area-chart .effect-circle{stroke-width:1px;fill:none;opacity:0}.pcac-line-area-chart .effect-text{font-size:11px;font-weight:700;fill:var(--pcac-crosshair-text-color, #343a40)}pcac-line-chart.pcac-height-full,pcac-area-chart.pcac-height-full,pcac-plot-chart.pcac-height-full,pcac-line-area-chart.pcac-height-full{display:block;height:100%}pcac-line-area-chart.pcac-height-full .pcac-line-area-chart{height:100%}\n"], encapsulation: i0.ViewEncapsulation.None });
3740
4254
  }
3741
4255
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacLineAreaChartComponent, decorators: [{
3742
4256
  type: Component,
3743
- args: [{ selector: 'pcac-line-area-chart', host: { '[class.pcac-height-full]': 'config().heightFull' }, encapsulation: ViewEncapsulation.None, providers: [PlaChartBuilder, PlaChartEffectsBuilder], template: "<section class=\"pcac-line-area-chart\">\n <svg #chart></svg>\n</section>\n\n", styles: [".pcac-line-area-chart svg{width:100%;display:block}.pcac-line-area-chart .dot{stroke-width:2px}.pcac-line-area-chart .fan-out-spoke{stroke:var(--pcac-fan-out-spoke-color, #ced4da);stroke-width:1px}.pcac-line-area-chart .fan-out-anchor{fill:var(--pcac-fan-out-anchor-color, #6c757d)}.pcac-line-area-chart .point-ranges .point-range-series{--pcac-point-range-resolved-color: var(--pcac-point-range-color, var(--pcac-point-range-series-color))}.pcac-line-area-chart .point-ranges .point-range{opacity:var(--pcac-point-range-resting-opacity, 1);transition:opacity .15s ease-out}.pcac-line-area-chart .point-ranges .point-range.is-focused{opacity:1}.pcac-line-area-chart .point-ranges.pcac-range-hover{--pcac-point-range-resting-opacity: 0}.pcac-line-area-chart .point-ranges.pcac-range-faint{--pcac-point-range-resting-opacity: var(--pcac-point-range-faint-opacity, .2)}.pcac-line-area-chart .point-ranges.pcac-range-always.has-focus .point-range:not(.is-focused){opacity:.5}.pcac-line-area-chart .point-ranges .point-range-whisker,.pcac-line-area-chart .point-ranges .point-range-cap{stroke:var(--pcac-point-range-resolved-color);stroke-width:1.25px}.pcac-line-area-chart .point-ranges .point-range-box{fill:var(--pcac-point-range-resolved-color);fill-opacity:.1;stroke:var(--pcac-point-range-resolved-color);stroke-opacity:.7;stroke-width:1.25px}.pcac-line-area-chart .point-ranges .point-range-stop{stop-color:var(--pcac-point-range-resolved-color)}.pcac-line-area-chart .point-ranges .is-focused .point-range-whisker,.pcac-line-area-chart .point-ranges .is-focused .point-range-cap,.pcac-line-area-chart .point-ranges .is-focused .point-range-box{stroke-width:1.75px}.pcac-line-area-chart .point-ranges .is-focused .point-range-box{fill-opacity:.18}@media(prefers-reduced-motion:reduce){.pcac-line-area-chart .point-ranges .point-range{transition:none}}.pcac-line-area-chart .effects-canvas{fill:none}.pcac-line-area-chart .effect-line{stroke:#ced4da;stroke-width:1px;opacity:0}.pcac-line-area-chart .effect-circle{stroke-width:1px;fill:none;opacity:0}.pcac-line-area-chart .effect-text{font-size:11px;font-weight:700;fill:#343a40}pcac-line-chart.pcac-height-full,pcac-area-chart.pcac-height-full,pcac-plot-chart.pcac-height-full,pcac-line-area-chart.pcac-height-full{display:block;height:100%}pcac-line-area-chart.pcac-height-full .pcac-line-area-chart{height:100%}\n"] }]
4257
+ args: [{ selector: 'pcac-line-area-chart', host: { '[class.pcac-height-full]': 'config().heightFull' }, encapsulation: ViewEncapsulation.None, providers: [PlaChartBuilder, PlaChartEffectsBuilder], template: "<section class=\"pcac-line-area-chart\">\n <svg #chart></svg>\n</section>\n\n", styles: [".pcac-line-area-chart svg{width:100%;display:block}.pcac-line-area-chart .dot{stroke-width:2px}.pcac-line-area-chart .fan-out-spoke{stroke:var(--pcac-fan-out-spoke-color, #ced4da);stroke-width:1px}.pcac-line-area-chart .fan-out-anchor{fill:var(--pcac-fan-out-anchor-color, #6c757d)}.pcac-line-area-chart .point-ranges .point-range-series{--pcac-point-range-resolved-color: var(--pcac-point-range-color, var(--pcac-point-range-series-color))}.pcac-line-area-chart .point-ranges .point-range{opacity:var(--pcac-point-range-resting-opacity, 1);transition:opacity .15s ease-out}.pcac-line-area-chart .point-ranges .point-range.is-focused{opacity:1}.pcac-line-area-chart .point-ranges.pcac-range-hover{--pcac-point-range-resting-opacity: 0}.pcac-line-area-chart .point-ranges.pcac-range-faint{--pcac-point-range-resting-opacity: var(--pcac-point-range-faint-opacity, .2)}.pcac-line-area-chart .point-ranges.pcac-range-always.has-focus .point-range:not(.is-focused){opacity:.5}.pcac-line-area-chart .point-ranges .point-range-whisker,.pcac-line-area-chart .point-ranges .point-range-cap{stroke:var(--pcac-point-range-resolved-color);stroke-width:1.25px}.pcac-line-area-chart .point-ranges .point-range-box{fill:var(--pcac-point-range-resolved-color);fill-opacity:.1;stroke:var(--pcac-point-range-resolved-color);stroke-opacity:.7;stroke-width:1.25px}.pcac-line-area-chart .point-ranges .point-range-stop{stop-color:var(--pcac-point-range-resolved-color)}.pcac-line-area-chart .point-ranges .is-focused .point-range-whisker,.pcac-line-area-chart .point-ranges .is-focused .point-range-cap,.pcac-line-area-chart .point-ranges .is-focused .point-range-box{stroke-width:1.75px}.pcac-line-area-chart .point-ranges .is-focused .point-range-box{fill-opacity:.18}@media(prefers-reduced-motion:reduce){.pcac-line-area-chart .point-ranges .point-range{transition:none}}.pcac-line-area-chart .effects-canvas{fill:none}.pcac-line-area-chart .effect-line{stroke:var(--pcac-crosshair-line-color, #ced4da);stroke-width:1px;opacity:0}.pcac-line-area-chart .effect-circle{stroke-width:1px;fill:none;opacity:0}.pcac-line-area-chart .effect-text{font-size:11px;font-weight:700;fill:var(--pcac-crosshair-text-color, #343a40)}pcac-line-chart.pcac-height-full,pcac-area-chart.pcac-height-full,pcac-plot-chart.pcac-height-full,pcac-line-area-chart.pcac-height-full{display:block;height:100%}pcac-line-area-chart.pcac-height-full .pcac-line-area-chart{height:100%}\n"] }]
3744
4258
  }], 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 }] }], dotClicked: [{ type: i0.Output, args: ["dotClicked"] }], tooltipTemplate: [{ type: i0.Input, args: [{ isSignal: true, alias: "tooltipTemplate", required: false }] }] } });
3745
4259
 
3746
4260
  class PcacPlotChart {
@@ -3933,7 +4447,7 @@ class PieDonutChartBuilder extends PcacChart {
3933
4447
  this.warnedOfDonutOnPie = true;
3934
4448
  console.warn('Pioneer Charts: <pcac-pie-chart> ignores `donut`. For a donut, use <pcac-donut-chart> with ' +
3935
4449
  'PcacDonutChartConfig, which takes innerRadius, label, subLabel, labelColor and subLabelColor ' +
3936
- 'directly - see the 22.3.0 CHANGELOG.');
4450
+ 'directly - see the 22.2.16 CHANGELOG.');
3937
4451
  }
3938
4452
  /** `ratio` is the hole's radius as a share of the chart's: 0 for a pie. */
3939
4453
  buildShapes(ratio) {
@@ -3958,7 +4472,33 @@ class PieDonutChartBuilder extends PcacChart {
3958
4472
  drawChart(chartElm, config) {
3959
4473
  this.buildContainer(chartElm, true);
3960
4474
  const self = this;
3961
- this.svg.selectAll('.pcac-arc')
4475
+ // Pops the slice out, darkened, for the pointer and keyboard focus alike (see
4476
+ // makeMarksAccessible).
4477
+ const pop = (slice, d) => {
4478
+ const t = transition().duration(this.transitionService.getTransitionDuration() / 3);
4479
+ const c = color(this.colors[d.index]);
4480
+ const ct = c ? c.darker(1).toString() : this.colors[d.index];
4481
+ const selected = select(slice);
4482
+ // Hovered mid-way through the enter sweep, the slice is finished first: growing it straight
4483
+ // from its part-swept path morphed it oddly on the way out to the hover shape. Only then -
4484
+ // re-entering a slice mid-way through its hover shrink must grow it from where it is, not
4485
+ // snap it back to rest first (which flickered).
4486
+ if (active(slice, 'enter')) {
4487
+ selected.interrupt('enter').attr('d', this.arcShape(d));
4488
+ }
4489
+ selected
4490
+ .transition(t)
4491
+ .attr('d', this.arcOverShape)
4492
+ .style('fill', ct);
4493
+ };
4494
+ const rest = (slice, d) => {
4495
+ select(slice)
4496
+ .transition()
4497
+ .duration(this.transitionService.getTransitionDuration() / 3)
4498
+ .attr('d', this.arcShape)
4499
+ .style('fill', this.colors[d.index]);
4500
+ };
4501
+ const slices = this.svg.selectAll('.pcac-arc')
3962
4502
  .data(this.pieAngles(config.data))
3963
4503
  .enter().append('g')
3964
4504
  .attr('class', 'pcac-arc')
@@ -3967,36 +4507,33 @@ class PieDonutChartBuilder extends PcacChart {
3967
4507
  return this.colors[i];
3968
4508
  })
3969
4509
  .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);
4510
+ pop(this, d);
3985
4511
  })
3986
4512
  .on('mousemove', (event, d) => {
3987
4513
  self.showTooltip(event, d.data, { index: d.index });
3988
4514
  })
3989
4515
  .on('mouseout', function (_, d) {
3990
4516
  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]);
4517
+ rest(this, d);
3996
4518
  })
3997
4519
  .on('click', (_event, d) => {
3998
4520
  this.sliceClickedSource.next(d.data);
3999
- })
4521
+ });
4522
+ makeMarksAccessible(slices, {
4523
+ label: (d) => this.markLabel(d.data),
4524
+ skip: (d) => !!d.data.hide,
4525
+ activate: (d) => this.sliceClickedSource.next(d.data),
4526
+ focus: (slice, d) => {
4527
+ pop(slice, d);
4528
+ this.showMarkTooltip(slice, d.data, { index: d.index });
4529
+ },
4530
+ blur: (slice, d) => {
4531
+ this.hideMarkTooltip(slice);
4532
+ rest(slice, d);
4533
+ },
4534
+ });
4535
+ this.restoreTabStop(chartElm);
4536
+ slices
4000
4537
  // Named, so the hover transitions (unnamed) and the check above can tell it apart from them.
4001
4538
  .transition('enter')
4002
4539
  .duration(this.transitionService.getTransitionDuration())
@@ -4181,5 +4718,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImpor
4181
4718
  * Generated bundle index. Do not edit.
4182
4719
  */
4183
4720
 
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 };
4721
+ export { PcacAreaChart, PcacAreaChartConfig, PcacAxisChartConfig, PcacAxisConfig, PcacAxisSubLabels, PcacBarHorizontalChart, PcacBarHorizontalChart as PcacBarHorizontalChartComponent, PcacBarHorizontalChartConfig, PcacBarVerticalChart, PcacBarVerticalChart as 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
4722
  //# sourceMappingURL=pioneer-code-pioneer-charts.mjs.map