@pioneer-code/pioneer-charts 22.2.17 → 22.2.19

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.
@@ -9,7 +9,7 @@ import { Subject } from 'rxjs';
9
9
  import { axisLeft, axisBottom } from 'd3-axis';
10
10
  import { format } from 'd3-format';
11
11
  import { debounceTime } from 'rxjs/operators';
12
- import { range } from 'd3-array';
12
+ import { extent, range } from 'd3-array';
13
13
  import { zoom, zoomIdentity } from 'd3-zoom';
14
14
  import { line, area, arc, pie } from 'd3-shape';
15
15
  import { interpolate } from 'd3-interpolate';
@@ -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;
@@ -244,6 +245,17 @@ class PcacData {
244
245
  * Optional for the same reason as `image`.
245
246
  */
246
247
  range;
248
+ /**
249
+ * A third number for this point, shown as how full a ring around its mark is - on a scatter of
250
+ * two measures, say, a third one per point. Out of the chart config's `pointGauge.max`: at `max`
251
+ * or above the ring is full, at `0` or below it's empty. Currently honored by the line/area/plot
252
+ * charts only, on the innermost (point-level) `PcacData`, and only drawn when the chart config
253
+ * turns `pointGauge` on (see `PcacPointGaugeConfig`). A point without one gets no ring at all,
254
+ * which can itself say something ("doesn't apply").
255
+ *
256
+ * Optional for the same reason as `image`.
257
+ */
258
+ gauge;
247
259
  }
248
260
  /**
249
261
  * One side of a `PcacDataRange`. `min` above `max` is read as the other way round; `min` equal to
@@ -331,8 +343,24 @@ function formatValue(pcacFormat, value) {
331
343
  *
332
344
  * Numeric formats take their precision from the scale's tick step where the scale has one: a
333
345
  * fixed precision is fine for a whole domain but breaks down once zoom narrows it to a few units.
346
+ *
347
+ * On a category axis (a band scale - a bar chart's groups) only keys that are numbers are formatted
348
+ * - `'0.25'` reads `25%` - and any other key is shown as it is: a format there, easy to set by
349
+ * mistake on the horizontal chart (where y is the category axis), turned every label into `NaN%`
350
+ * or `Chipsm`.
334
351
  */
335
352
  function axisTickFormat(pcacFormat, scale, ticks) {
353
+ const format = valueTickFormat(pcacFormat, scale, ticks);
354
+ if (!format || !('bandwidth' in scale)) {
355
+ return format;
356
+ }
357
+ return (d) => isNumericKey(d) ? format(d) : String(d);
358
+ }
359
+ /** A category key that reads as a number - `0.25`, `'1500'` - rather than text like `'Chips'`. */
360
+ function isNumericKey(key) {
361
+ return (typeof key === 'number' || (typeof key === 'string' && key.trim() !== '')) && Number.isFinite(Number(key));
362
+ }
363
+ function valueTickFormat(pcacFormat, scale, ticks) {
336
364
  const withTicks = scale;
337
365
  switch (pcacFormat) {
338
366
  case PcacFormatEnum.Percentage:
@@ -665,6 +693,189 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImpor
665
693
  }]
666
694
  }] });
667
695
 
696
+ /** Marks the elements `makeMarksAccessible` set up, so navigation can find a chart's marks. */
697
+ const MARK_ATTR = 'data-pcac-mark';
698
+ /**
699
+ * Makes a chart's marks usable from the keyboard and readable by a screen reader, alongside the
700
+ * pointer handlers they already have.
701
+ *
702
+ * Every mark gets a role and a name, but only one of them - the chart's "tab stop" - is in the Tab
703
+ * order (see `refreshTabStop`): Tab reaches the chart once, and the arrow keys move between its
704
+ * marks, Home and End to the first and last. A chart of a thousand bars isn't a thousand Tab
705
+ * presses to get past. Focus does what hovering does (`focus`), and Enter or Space what a click
706
+ * does (`activate`); Escape hides the tooltip, as moving the pointer away would - and goes no
707
+ * further while it has one to hide, so it doesn't also close a dialog the chart is in. Keys pressed
708
+ * with Alt, Ctrl or Cmd are left to the browser (Alt+Left is Back).
709
+ *
710
+ * A mark takes focus from the keyboard only: pressing the pointer on one is kept from focusing it,
711
+ * so a click doesn't leave a keyboard-style tooltip and focus ring behind on the clicked mark. It
712
+ * does let go of a mark in the same chart that has focus, which would otherwise stay highlighted,
713
+ * its tooltip gone, while the pointer is at work elsewhere in the chart.
714
+ */
715
+ function makeMarksAccessible(marks, access) {
716
+ const skipped = (d) => access.skip?.(d) ?? false;
717
+ // The marks showing what focus shows (their tooltip, highlighted), until blur or Escape.
718
+ const open = new WeakSet();
719
+ marks
720
+ .attr(MARK_ATTR, (d) => (skipped(d) ? null : ''))
721
+ .attr('aria-hidden', (d) => (skipped(d) ? 'true' : null))
722
+ // An image, with a name, rather than a button: whether the chart's click output has a listener
723
+ // can't be told from here (the pie, donut, line, area and plot charts' own wrappers always
724
+ // listen, to pass it on), and a button that does nothing would be a lie. Enter and Space still
725
+ // do what a click does, and the click listener has browsers report the mark as clickable.
726
+ .attr('role', (d) => (skipped(d) ? null : 'img'))
727
+ .attr('aria-label', function (d) {
728
+ return skipped(d) ? null : access.label(d, this);
729
+ })
730
+ .attr('tabindex', (d) => (skipped(d) ? null : -1))
731
+ // The events are typed plainly as `Event`: with the element type generic here, d3's typings
732
+ // (@types/d3-selection 3.0.12 on) can't narrow them to `MouseEvent`/`KeyboardEvent`.
733
+ .on('mousedown.pcac-mark', function (event) {
734
+ event.preventDefault();
735
+ const focused = this.ownerDocument.activeElement;
736
+ if (focused !== this && focused?.hasAttribute(MARK_ATTR) && sameChart(focused, this)) {
737
+ focused.blur();
738
+ }
739
+ })
740
+ .on('focus.pcac-mark', function (_event, d) {
741
+ open.add(this);
742
+ access.focus(this, d);
743
+ })
744
+ .on('blur.pcac-mark', function (_event, d) {
745
+ open.delete(this);
746
+ access.blur(this, d);
747
+ })
748
+ .on('keydown.pcac-mark', function (event, d) {
749
+ const { key, altKey, ctrlKey, metaKey } = event;
750
+ if (altKey || ctrlKey || metaKey) {
751
+ return;
752
+ }
753
+ switch (key) {
754
+ case 'Enter':
755
+ case ' ':
756
+ event.preventDefault();
757
+ access.activate(d);
758
+ return;
759
+ case 'Escape':
760
+ // Only while there's a tooltip to hide; a second Escape carries on to whatever the
761
+ // chart is in (a dialog closes, as it would have).
762
+ if (open.delete(this)) {
763
+ event.preventDefault();
764
+ event.stopPropagation();
765
+ access.blur(this, d);
766
+ }
767
+ return;
768
+ }
769
+ const target = neighbor(this, key);
770
+ if (target) {
771
+ event.preventDefault();
772
+ moveFocus(this, target);
773
+ }
774
+ });
775
+ }
776
+ /**
777
+ * Notes the chart's Tab stop - and whether it has focus - before a redraw removes every mark, so
778
+ * `refreshTabStop` can put both back: a keyboard user who pressed Enter on a bar, with a click
779
+ * handler that updates the data, stays on that bar rather than being dropped at the top of the
780
+ * page. `null` when the chart has no Tab stop.
781
+ */
782
+ function captureMarkFocus(root) {
783
+ if (!root) {
784
+ return null;
785
+ }
786
+ const marks = navigableMarks(root);
787
+ const index = marks.findIndex((mark) => mark.getAttribute('tabindex') === '0');
788
+ if (index < 0) {
789
+ return null;
790
+ }
791
+ return { index, focused: root.ownerDocument.activeElement === marks[index] };
792
+ }
793
+ /**
794
+ * Puts the chart's one Tab stop (`tabindex="0"`) on a mark that can take focus; every other mark
795
+ * is `-1` already (`makeMarksAccessible`). Call once a chart's marks are drawn, and again whenever
796
+ * marks can have been hidden - by zoom, say - so Tab doesn't land on one that can't be focused and
797
+ * skip the chart.
798
+ *
799
+ * Leaves the Tab stop where it is while that mark can still take focus, so coming back to the chart
800
+ * returns to the mark last visited. After a redraw, given what `captureMarkFocus` noted, it goes
801
+ * back to the same place - the last mark, if there are fewer now - and takes focus back if it had
802
+ * it. Touches only the old and new stops, as it runs on every zoom frame.
803
+ */
804
+ function refreshTabStop(root, previous = null) {
805
+ if (!root) {
806
+ return;
807
+ }
808
+ const current = root.querySelector(`[${MARK_ATTR}][tabindex="0"]`);
809
+ if (current && !previous && !isNotDisplayed(current, root)) {
810
+ return;
811
+ }
812
+ const marks = navigableMarks(root);
813
+ const stop = previous ? marks[Math.min(previous.index, marks.length - 1)] : marks[0];
814
+ if (current && current !== stop) {
815
+ current.setAttribute('tabindex', '-1');
816
+ }
817
+ if (!stop) {
818
+ return;
819
+ }
820
+ stop.setAttribute('tabindex', '0');
821
+ if (previous?.focused) {
822
+ stop.focus({ preventScroll: true });
823
+ }
824
+ }
825
+ /** Whether two marks are in the same chart (the same `<svg>`). */
826
+ function sameChart(a, b) {
827
+ return (a.ownerSVGElement ?? a.parentElement) === (b.ownerSVGElement ?? b.parentElement);
828
+ }
829
+ /** The chart's marks that can take focus now, in drawing order. */
830
+ function navigableMarks(root) {
831
+ return Array.from(root.querySelectorAll(`[${MARK_ATTR}]`)).filter((mark) => !isNotDisplayed(mark, root));
832
+ }
833
+ /**
834
+ * Whether the mark, or a group it's in, isn't displayed: a hidden series, or a point zoomed out of
835
+ * the plot. Read from the `display` attribute and inline style the builders set, rather than from
836
+ * layout, which a browser without one (a test environment) doesn't have.
837
+ */
838
+ function isNotDisplayed(mark, root) {
839
+ for (let node = mark; node && node !== root; node = node.parentElement) {
840
+ if (node.getAttribute('display') === 'none' || node.style?.display === 'none') {
841
+ return true;
842
+ }
843
+ }
844
+ return false;
845
+ }
846
+ /** The mark an arrow, Home or End key moves to from `mark`, or `null` for any other key. */
847
+ function neighbor(mark, key) {
848
+ const root = mark.ownerSVGElement ?? mark.parentElement;
849
+ if (!root) {
850
+ return null;
851
+ }
852
+ const marks = navigableMarks(root);
853
+ const at = marks.indexOf(mark);
854
+ switch (key) {
855
+ case 'ArrowRight':
856
+ case 'ArrowDown':
857
+ return marks[Math.min(at + 1, marks.length - 1)] ?? null;
858
+ case 'ArrowLeft':
859
+ case 'ArrowUp':
860
+ return marks[Math.max(at - 1, 0)] ?? null;
861
+ case 'Home':
862
+ return marks[0] ?? null;
863
+ case 'End':
864
+ return marks[marks.length - 1] ?? null;
865
+ default:
866
+ return null;
867
+ }
868
+ }
869
+ /** Moves focus, and the chart's Tab stop with it, from one mark to another. */
870
+ function moveFocus(from, to) {
871
+ if (from === to) {
872
+ return;
873
+ }
874
+ from.setAttribute('tabindex', '-1');
875
+ to.setAttribute('tabindex', '0');
876
+ to.focus();
877
+ }
878
+
668
879
  class PcacTooltipBuilder {
669
880
  appRef = inject(ApplicationRef);
670
881
  document = inject(DOCUMENT);
@@ -703,7 +914,7 @@ class PcacTooltipBuilder {
703
914
  */
704
915
  owner = null;
705
916
  /**
706
- * The tooltip element's id, for a focused mark's `aria-describedby` (see `PcacChart.focusMark`).
917
+ * The tooltip element's id, for a focused mark's `aria-describedby` (see `PcacChart.showMarkTooltip`).
707
918
  * One per page, like the element.
708
919
  */
709
920
  static ID = 'pcac-tooltip';
@@ -1199,6 +1410,36 @@ class PcacChart {
1199
1410
  element.setAttribute('aria-describedby', PcacTooltipBuilder.ID);
1200
1411
  }
1201
1412
  }
1413
+ /**
1414
+ * Where the chart's Tab stop was before the last redraw removed its marks, and whether it had
1415
+ * focus; put back by `restoreTabStop`. Kept until then - across a build that couldn't draw (no
1416
+ * width yet) - and not overwritten by a second clear in the same build, which finds no marks.
1417
+ */
1418
+ markFocus = null;
1419
+ noteMarkFocus(chartElm) {
1420
+ this.markFocus = captureMarkFocus(chartElm.nativeElement) ?? this.markFocus;
1421
+ }
1422
+ /**
1423
+ * Puts the chart's Tab stop on its new marks - where it was before the redraw, with focus if it
1424
+ * had it (see marks.ts). Every builder calls this once its marks are drawn.
1425
+ */
1426
+ restoreTabStop(chartElm) {
1427
+ refreshTabStop(chartElm.nativeElement, this.markFocus);
1428
+ this.markFocus = null;
1429
+ }
1430
+ /**
1431
+ * The chart's accessible name when its config gives no `ariaLabel`: its type, and the titles of
1432
+ * the axes it shows - "Bar chart - x axis: Product, y axis: Units sold". The titles are drawn
1433
+ * inside the axis groups, which are hidden from screen readers (the marks' own names carry each
1434
+ * key and value), so this is the only place they're read out.
1435
+ */
1436
+ defaultChartName() {
1437
+ const axes = [['x', this.xAxis], ['y', this.yAxis]];
1438
+ const titles = axes
1439
+ .filter(([, axis]) => !axis.hide && !!axis.label)
1440
+ .map(([name, axis]) => `${name} axis: ${axis.label}`);
1441
+ return titles.length ? `${this.chartTypeLabel} - ${titles.join(', ')}` : this.chartTypeLabel;
1442
+ }
1202
1443
  /** Keyboard focus leaving a mark: the undoing of `showMarkTooltip`. */
1203
1444
  hideMarkTooltip(element) {
1204
1445
  this.hideTooltip();
@@ -1219,6 +1460,7 @@ class PcacChart {
1219
1460
  */
1220
1461
  clearChart(chartElm) {
1221
1462
  this.hideTooltip();
1463
+ this.noteMarkFocus(chartElm);
1222
1464
  select(chartElm.nativeElement).select('g').remove();
1223
1465
  }
1224
1466
  /**
@@ -1237,6 +1479,7 @@ class PcacChart {
1237
1479
  initializeChartState(chartElm, config) {
1238
1480
  // The rebuild removes the hovered element, which gets no mouseout to close its tooltip.
1239
1481
  this.hideTooltip();
1482
+ this.noteMarkFocus(chartElm);
1240
1483
  select(chartElm.nativeElement).select('g').remove();
1241
1484
  // One color per group or per series within a group, whichever needs more. Bar charts, which
1242
1485
  // color by series across groups, top this up with `ensureColorCount()`. Read before the width
@@ -1265,7 +1508,7 @@ class PcacChart {
1265
1508
  // a screen reader, and keyboard focus on them would announce nothing.)
1266
1509
  select(chartElm.nativeElement)
1267
1510
  .attr('role', 'group')
1268
- .attr('aria-label', config.ariaLabel || this.chartTypeLabel);
1511
+ .attr('aria-label', config.ariaLabel || this.defaultChartName());
1269
1512
  this.height = this.resolveHeight(container, config);
1270
1513
  this.colors = colors;
1271
1514
  this.lastContainerWidth = containerWidth;
@@ -1375,6 +1618,11 @@ class PcacChart {
1375
1618
  if (this.yAxis.tickSize !== undefined) {
1376
1619
  axisY.tickSizeInner(this.yAxis.tickSize);
1377
1620
  }
1621
+ // Labelled as the axis will label them, or a unit suffix went unmeasured and ran off the edge.
1622
+ const format = axisTickFormat(this.yAxis.format, yScale, this.yAxis.ticks);
1623
+ if (format) {
1624
+ axisY.tickFormat(format);
1625
+ }
1378
1626
  let max = 0;
1379
1627
  select(chartElm.nativeElement).append('g')
1380
1628
  .call(axisY)
@@ -1449,177 +1697,52 @@ function fitText(text, maxWidth) {
1449
1697
  text.textContent = withEllipsis(fits);
1450
1698
  }
1451
1699
 
1452
- /** Marks the elements `makeMarksAccessible` set up, so navigation can find a chart's marks. */
1453
- const MARK_ATTR = 'data-pcac-mark';
1454
1700
  /**
1455
- * Makes a chart's marks usable from the keyboard and readable by a screen reader, alongside the
1456
- * pointer handlers they already have.
1457
- *
1458
- * Every mark gets a role and a name, but only one of them - the chart's "tab stop" - is in the Tab
1459
- * order (see `refreshTabStop`): Tab reaches the chart once, and the arrow keys move between its
1460
- * marks, Home and End to the first and last. A chart of a thousand bars isn't a thousand Tab
1461
- * presses to get past. Focus does what hovering does (`focus`), and Enter or Space what a click
1462
- * does (`activate`); Escape hides the tooltip, as moving the pointer away would.
1701
+ * How long each bar is drawn: its value, or 0 when it can't be drawn - a null or non-numeric
1702
+ * value, or `hide` set on the bar or on its whole group. A hidden bar keeps its slot (and so its
1703
+ * color) and just draws nothing, the same way a hidden line/area/plot series keeps its place.
1704
+ * A negative value is drawn as 0 too: the bar charts only draw upward from a 0 baseline, and a
1705
+ * negative size was an invalid SVG `height`/`width` (the bar vanished with a console error) that
1706
+ * also pulled the rest of a stack down over the bars before it.
1463
1707
  *
1464
- * A mark takes focus from the keyboard only: pressing the pointer on one is kept from focusing it,
1465
- * so a click doesn't leave a keyboard-style tooltip and focus ring behind on the clicked mark.
1708
+ * Keyed by the bar's own `PcacData` object so D3 callbacks (which only get the datum) can look
1709
+ * their size up directly.
1466
1710
  */
1467
- function makeMarksAccessible(marks, access) {
1468
- const skipped = (d) => access.skip?.(d) ?? false;
1469
- marks
1470
- .attr(MARK_ATTR, (d) => (skipped(d) ? null : ''))
1471
- .attr('aria-hidden', (d) => (skipped(d) ? 'true' : null))
1472
- // An image, with a name, rather than a button: whether the chart's click output has a listener
1473
- // can't be told from here (the pie, donut, line, area and plot charts' own wrappers always
1474
- // listen, to pass it on), and a button that does nothing would be a lie. Enter and Space still
1475
- // do what a click does, and the click listener has browsers report the mark as clickable.
1476
- .attr('role', (d) => (skipped(d) ? null : 'img'))
1477
- .attr('aria-label', function (d) {
1478
- return skipped(d) ? null : access.label(d, this);
1479
- })
1480
- .attr('tabindex', (d) => (skipped(d) ? null : -1))
1481
- // The events are typed plainly as `Event`: with the element type generic here, d3's typings
1482
- // (@types/d3-selection 3.0.12 on) can't narrow them to `MouseEvent`/`KeyboardEvent`.
1483
- .on('mousedown.pcac-mark', (event) => event.preventDefault())
1484
- .on('focus.pcac-mark', function (_event, d) {
1485
- access.focus(this, d);
1486
- })
1487
- .on('blur.pcac-mark', function (_event, d) {
1488
- access.blur(this, d);
1489
- })
1490
- .on('keydown.pcac-mark', function (event, d) {
1491
- const { key } = event;
1492
- switch (key) {
1493
- case 'Enter':
1494
- case ' ':
1495
- event.preventDefault();
1496
- access.activate(d);
1497
- return;
1498
- case 'Escape':
1499
- access.blur(this, d);
1500
- return;
1501
- }
1502
- const target = neighbor(this, key);
1503
- if (target) {
1504
- event.preventDefault();
1505
- moveFocus(this, target);
1711
+ function barSizes(groups) {
1712
+ const sizes = new Map();
1713
+ for (const group of groups) {
1714
+ for (const bar of group.data ?? []) {
1715
+ const value = Number(bar.value ?? 0);
1716
+ sizes.set(bar, group.hide || bar.hide || !Number.isFinite(value) ? 0 : Math.max(0, value));
1506
1717
  }
1507
- });
1508
- }
1509
- /**
1510
- * Puts the chart's one Tab stop (`tabindex="0"`) on its first mark that can take focus, and takes
1511
- * it off every other. Call once a chart's marks are drawn, and again whenever marks can have been
1512
- * hidden - by zoom, say - so Tab doesn't land on one that can't be focused and skip the chart.
1513
- * Leaves it where it is when that mark can still take focus, so coming back to the chart returns
1514
- * to the mark last visited.
1515
- */
1516
- function refreshTabStop(root) {
1517
- if (!root) {
1518
- return;
1519
- }
1520
- const marks = navigableMarks(root);
1521
- const current = marks.find((mark) => mark.getAttribute('tabindex') === '0');
1522
- const stop = current ?? marks[0];
1523
- for (const mark of root.querySelectorAll(`[${MARK_ATTR}]`)) {
1524
- mark.setAttribute('tabindex', mark === stop ? '0' : '-1');
1525
1718
  }
1526
- }
1527
- /** The chart's marks that can take focus now, in drawing order. */
1528
- function navigableMarks(root) {
1529
- return Array.from(root.querySelectorAll(`[${MARK_ATTR}]`)).filter((mark) => !isNotDisplayed(mark, root));
1719
+ return sizes;
1530
1720
  }
1531
1721
  /**
1532
- * Whether the mark, or a group it's in, isn't displayed: a hidden series, or a point zoomed out of
1533
- * the plot. Read from the `display` attribute and inline style the builders set, rather than from
1534
- * layout, which a browser without one (a test environment) doesn't have.
1722
+ * Where each bar of a stacked group starts: the running total of the bars before it, in data
1723
+ * order, so the first bar sits on the baseline and each later one on top of the previous. Sizes
1724
+ * are the bar's *own* (segment), not a pre-accumulated total, taken from `barSizes` - so a null,
1725
+ * non-numeric or hidden bar adds nothing to the stack.
1535
1726
  */
1536
- function isNotDisplayed(mark, root) {
1537
- for (let node = mark; node && node !== root; node = node.parentElement) {
1538
- if (node.getAttribute('display') === 'none' || node.style?.display === 'none') {
1539
- return true;
1727
+ function stackStarts(groups, sizes = barSizes(groups)) {
1728
+ const starts = new Map();
1729
+ for (const group of groups) {
1730
+ let total = 0;
1731
+ for (const bar of group.data ?? []) {
1732
+ starts.set(bar, total);
1733
+ total += sizes.get(bar) ?? 0;
1540
1734
  }
1541
1735
  }
1542
- return false;
1736
+ return starts;
1543
1737
  }
1544
- /** The mark an arrow, Home or End key moves to from `mark`, or `null` for any other key. */
1545
- function neighbor(mark, key) {
1546
- const root = mark.ownerSVGElement ?? mark.parentElement;
1547
- if (!root) {
1548
- return null;
1549
- }
1550
- const marks = navigableMarks(root);
1551
- const at = marks.indexOf(mark);
1552
- switch (key) {
1553
- case 'ArrowRight':
1554
- case 'ArrowDown':
1555
- return marks[Math.min(at + 1, marks.length - 1)] ?? null;
1556
- case 'ArrowLeft':
1557
- case 'ArrowUp':
1558
- return marks[Math.max(at - 1, 0)] ?? null;
1559
- case 'Home':
1560
- return marks[0] ?? null;
1561
- case 'End':
1562
- return marks[marks.length - 1] ?? null;
1563
- default:
1564
- return null;
1565
- }
1566
- }
1567
- /** Moves focus, and the chart's Tab stop with it, from one mark to another. */
1568
- function moveFocus(from, to) {
1569
- if (from === to) {
1570
- return;
1571
- }
1572
- from.setAttribute('tabindex', '-1');
1573
- to.setAttribute('tabindex', '0');
1574
- to.focus();
1575
- }
1576
-
1577
- /**
1578
- * How long each bar is drawn: its value, or 0 when it can't be drawn - a null or non-numeric
1579
- * value, or `hide` set on the bar or on its whole group. A hidden bar keeps its slot (and so its
1580
- * color) and just draws nothing, the same way a hidden line/area/plot series keeps its place.
1581
- * A negative value is drawn as 0 too: the bar charts only draw upward from a 0 baseline, and a
1582
- * negative size was an invalid SVG `height`/`width` (the bar vanished with a console error) that
1583
- * also pulled the rest of a stack down over the bars before it.
1584
- *
1585
- * Keyed by the bar's own `PcacData` object so D3 callbacks (which only get the datum) can look
1586
- * their size up directly.
1587
- */
1588
- function barSizes(groups) {
1589
- const sizes = new Map();
1590
- for (const group of groups) {
1591
- for (const bar of group.data ?? []) {
1592
- const value = Number(bar.value ?? 0);
1593
- sizes.set(bar, group.hide || bar.hide || !Number.isFinite(value) ? 0 : Math.max(0, value));
1594
- }
1595
- }
1596
- return sizes;
1597
- }
1598
- /**
1599
- * Where each bar of a stacked group starts: the running total of the bars before it, in data
1600
- * order, so the first bar sits on the baseline and each later one on top of the previous. Sizes
1601
- * are the bar's *own* (segment), not a pre-accumulated total, taken from `barSizes` - so a null,
1602
- * non-numeric or hidden bar adds nothing to the stack.
1603
- */
1604
- function stackStarts(groups, sizes = barSizes(groups)) {
1605
- const starts = new Map();
1606
- for (const group of groups) {
1607
- let total = 0;
1608
- for (const bar of group.data ?? []) {
1609
- starts.set(bar, total);
1610
- total += sizes.get(bar) ?? 0;
1611
- }
1612
- }
1613
- return starts;
1614
- }
1615
-
1616
- /** Whether a threshold entry carries per-bar values in its `data`. */
1617
- function hasBars(entry) {
1618
- return (entry.data?.length ?? 0) > 0;
1619
- }
1620
- /** A threshold is only drawn when its value is a finite number. */
1621
- function drawable(threshold) {
1622
- if (!threshold || threshold.value === null || threshold.value === undefined) {
1738
+
1739
+ /** Whether a threshold entry carries per-bar values in its `data`. */
1740
+ function hasBars(entry) {
1741
+ return (entry.data?.length ?? 0) > 0;
1742
+ }
1743
+ /** A threshold is only drawn when its value is a finite number. */
1744
+ function drawable(threshold) {
1745
+ if (!threshold || threshold.value === null || threshold.value === undefined) {
1623
1746
  return null;
1624
1747
  }
1625
1748
  return Number.isFinite(Number(threshold.value)) ? threshold : null;
@@ -1674,6 +1797,24 @@ function seriesKeys(groups) {
1674
1797
  }
1675
1798
  return [...keys];
1676
1799
  }
1800
+ /**
1801
+ * The slots a grouped (not stacked) chart places each group's bars in, and which slot a bar takes:
1802
+ * its series key - so a series sits in the same place in every group - when the keys tell the
1803
+ * series apart (see `hasDistinctSeriesKeys`), and its position in its group otherwise. Placed by
1804
+ * key regardless, bars with no key (`PcacData`'s default `null`) or a repeated one all fell into
1805
+ * one slot and were drawn on top of each other, only the last visible - though they were already
1806
+ * colored by position in that case.
1807
+ */
1808
+ function seriesSlots(groups) {
1809
+ if (hasDistinctSeriesKeys(groups)) {
1810
+ return { domain: seriesKeys(groups), slotOf: (bar) => bar.key };
1811
+ }
1812
+ const size = groups.reduce((max, group) => Math.max(max, group.data?.length ?? 0), 0);
1813
+ return {
1814
+ domain: Array.from({ length: size }, (_, i) => String(i)),
1815
+ slotOf: (_bar, index) => String(index),
1816
+ };
1817
+ }
1677
1818
  /**
1678
1819
  * Whether every bar has a key that is unique within its own group - what coloring bars by series
1679
1820
  * key needs. Without that (keys left `null`, as `PcacData` defaults them, or repeated within a
@@ -1695,27 +1836,43 @@ function hasDistinctSeriesKeys(groups) {
1695
1836
  function canRoundBands(length, count) {
1696
1837
  return count > 0 && length / count >= 2;
1697
1838
  }
1698
- let warnedOfColorOverrideObject = false;
1699
1839
  /**
1700
1840
  * A bar config's `colorOverride` as the plain list of colors every chart now takes. Up to 22.2 the
1701
1841
  * bar charts wrapped it as `{ colors: [...] }`; a config still shaped that way - which TypeScript
1702
- * misses when it's spread together or loaded as JSON - is still read, and development builds warn
1703
- * about it once.
1842
+ * misses when it's spread together or loaded as JSON - is still read, and `warn` is called (see
1843
+ * `colorOverrideWarning`). Only for colors actually set: before 22.2.17 every bar config defaulted
1844
+ * to `{ colors: [] }`, so one saved as JSON back then would warn about an override its author
1845
+ * never chose.
1704
1846
  */
1705
- function barColorOverride(override) {
1847
+ function barColorOverride(override, warn = () => undefined) {
1706
1848
  if (!override || Array.isArray(override)) {
1707
1849
  return override;
1708
1850
  }
1709
- if (typeof ngDevMode !== 'undefined' && ngDevMode && !warnedOfColorOverrideObject) {
1710
- warnedOfColorOverrideObject = true;
1851
+ const colors = override.colors;
1852
+ if (colors?.length) {
1853
+ warn();
1854
+ }
1855
+ return colors;
1856
+ }
1857
+ /**
1858
+ * The development-mode warning about the old `colorOverride` shape, for one chart: each bar builder
1859
+ * keeps its own, so it warns once per chart - like the pie's leftover-`donut` warning - rather than
1860
+ * once per page, which also made it depend on which chart happened to build first.
1861
+ */
1862
+ function colorOverrideWarning() {
1863
+ let warned = false;
1864
+ return () => {
1865
+ if (warned || typeof ngDevMode === 'undefined' || !ngDevMode) {
1866
+ return;
1867
+ }
1868
+ warned = true;
1711
1869
  console.warn('Pioneer Charts: a bar chart\'s `colorOverride` is now a plain array of colors, like the other ' +
1712
1870
  'charts\' - use `colorOverride: [...]` rather than `colorOverride: { colors: [...] }`.');
1713
- }
1714
- return override.colors;
1871
+ };
1715
1872
  }
1716
1873
 
1717
1874
  /**
1718
- * Provided per-component (see PcacBarHorizontalChartComponent's `providers`), not root-scoped:
1875
+ * Provided per-component (see PcacBarHorizontalChart's `providers`), not root-scoped:
1719
1876
  * this builder extends PcacChart, which holds mutable per-chart-instance state (margin, width,
1720
1877
  * height, colors, svg). A root singleton would be shared and clobbered by every
1721
1878
  * <pcac-bar-horizontal-chart> rendered at once.
@@ -1724,6 +1881,10 @@ class BarHorizontalChartBuilder extends PcacChart {
1724
1881
  xScale;
1725
1882
  yScaleStacked;
1726
1883
  yScaleGrouped;
1884
+ /** Warns, once for this chart, about a `colorOverride` in its old `{ colors }` shape. */
1885
+ warnOfColorOverride = colorOverrideWarning();
1886
+ /** A bar's slot in `yScaleGrouped`, from its datum and its index in its group (see `seriesSlots`). */
1887
+ slotOf = (bar) => bar.key;
1727
1888
  barClickedSource = new Subject();
1728
1889
  barClicked$ = this.barClickedSource.asObservable();
1729
1890
  chartTypeLabel = 'Bar chart';
@@ -1742,7 +1903,7 @@ class BarHorizontalChartBuilder extends PcacChart {
1742
1903
  return;
1743
1904
  }
1744
1905
  this.ensureColorCount(seriesKeys(config.data).length);
1745
- this.applyColorOverride(barColorOverride(config.colorOverride));
1906
+ this.applyColorOverride(barColorOverride(config.colorOverride, this.warnOfColorOverride));
1746
1907
  if (!this.buildScales(chartElm, config)) {
1747
1908
  return;
1748
1909
  }
@@ -1759,11 +1920,13 @@ class BarHorizontalChartBuilder extends PcacChart {
1759
1920
  // Rounded to whole pixels for crisp bar edges, while there's room to (see canRoundBands).
1760
1921
  .round(canRoundBands(this.height, config.data.length))
1761
1922
  .padding(0.1);
1923
+ const slots = seriesSlots(config.data);
1924
+ this.slotOf = slots.slotOf;
1762
1925
  this.yScaleGrouped = scaleBand()
1763
1926
  .padding(0.05)
1764
1927
  .range([0, this.yScaleStacked.bandwidth()])
1765
- .round(canRoundBands(this.yScaleStacked.bandwidth(), seriesKeys(config.data).length))
1766
- .domain(seriesKeys(config.data));
1928
+ .round(canRoundBands(this.yScaleStacked.bandwidth(), slots.domain.length))
1929
+ .domain(slots.domain);
1767
1930
  // The left margin is sized to the y axis's labels - unless there is no y axis to size it to
1768
1931
  if (!this.yAxis.hide && !this.setHorizontalMarginsBasedOnContent(chartElm, this.yScaleStacked)) {
1769
1932
  return false;
@@ -1778,7 +1941,7 @@ class BarHorizontalChartBuilder extends PcacChart {
1778
1941
  this.drawGrids(this.xScale, this.yScaleStacked);
1779
1942
  this.addGroups(config);
1780
1943
  this.axisBuilder.raiseAxes(this.svg);
1781
- refreshTabStop(chartElm.nativeElement);
1944
+ this.restoreTabStop(chartElm);
1782
1945
  }
1783
1946
  addGroups(config) {
1784
1947
  const groupsContainer = this.svg.append('g')
@@ -1857,7 +2020,7 @@ class BarHorizontalChartBuilder extends PcacChart {
1857
2020
  // A stacked bar spans its whole group, which is already translated into place; looking its
1858
2021
  // series key up in the group band put it off in another group's slot whenever the key
1859
2022
  // matched a group key.
1860
- .attr('y', (d) => config.isStacked ? 0 : this.yScaleGrouped(d.key) ?? 0)
2023
+ .attr('y', (d, i) => config.isStacked ? 0 : this.yScaleGrouped(this.slotOf(d, i)) ?? 0)
1861
2024
  .attr('data-group-bar-id', (_, i) => {
1862
2025
  return i;
1863
2026
  })
@@ -1948,7 +2111,7 @@ class BarHorizontalChartBuilder extends PcacChart {
1948
2111
  // Placed in its bar's slot up front - only its value (`x`) animates. Set on the transition,
1949
2112
  // it slid in from the top of the group, where the vertical chart's appear in place.
1950
2113
  // ScaleBand can return undefined for a key outside its domain; `.attr()` needs null, not undefined.
1951
- .attr('y', (d) => this.yScaleGrouped(d.key) ?? null)
2114
+ .attr('y', (d, i) => this.yScaleGrouped(this.slotOf(d, i)) ?? null)
1952
2115
  .attr('height', this.yScaleGrouped.bandwidth());
1953
2116
  rects.filter(function () {
1954
2117
  return thresholdOf(this) === null;
@@ -2103,7 +2266,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImpor
2103
2266
  }]
2104
2267
  }] });
2105
2268
 
2106
- class PcacBarHorizontalChartComponent {
2269
+ class PcacBarHorizontalChart {
2107
2270
  chartBuilder = inject(BarHorizontalChartBuilder);
2108
2271
  config = input.required(/* @ts-ignore */
2109
2272
  ...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
@@ -2140,10 +2303,10 @@ class PcacBarHorizontalChartComponent {
2140
2303
  this.chartBuilder.buildChart(this.chartElm(), config);
2141
2304
  }
2142
2305
  }
2143
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacBarHorizontalChartComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
2144
- 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 });
2306
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacBarHorizontalChart, deps: [], target: i0.ɵɵFactoryTarget.Component });
2307
+ 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 });
2145
2308
  }
2146
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacBarHorizontalChartComponent, decorators: [{
2309
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacBarHorizontalChart, decorators: [{
2147
2310
  type: Component,
2148
2311
  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"] }]
2149
2312
  }], 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 }] }] } });
@@ -2154,14 +2317,14 @@ class PcacBarHorizontalChartConfig extends PcacAxisChartConfig {
2154
2317
  spreadColorsPerGroup = false;
2155
2318
  /**
2156
2319
  * Bar colors, any CSS color, in place of the theme palette - by series, or by group with
2157
- * `spreadColorsPerGroup`. Repeated when there are more series (or groups) than colors. Empty,
2158
- * the theme palette is used.
2320
+ * `spreadColorsPerGroup`. Repeated when there are more series (or groups) than colors. Omitted
2321
+ * or empty, the theme palette is used - optional, as on every chart's config.
2159
2322
  */
2160
- colorOverride = [];
2323
+ colorOverride;
2161
2324
  }
2162
2325
 
2163
2326
  /**
2164
- * Provided per-component (see PcacBarVerticalChartComponent's `providers`), not root-scoped:
2327
+ * Provided per-component (see PcacBarVerticalChart's `providers`), not root-scoped:
2165
2328
  * this builder extends PcacChart, which holds mutable per-chart-instance state (margin, width,
2166
2329
  * height, colors, svg). A root singleton would be shared and clobbered by every
2167
2330
  * <pcac-bar-vertical-chart> rendered at once.
@@ -2169,6 +2332,10 @@ class PcacBarHorizontalChartConfig extends PcacAxisChartConfig {
2169
2332
  class BarVerticalChartBuilder extends PcacChart {
2170
2333
  xScaleStacked;
2171
2334
  xScaleGrouped;
2335
+ /** Warns, once for this chart, about a `colorOverride` in its old `{ colors }` shape. */
2336
+ warnOfColorOverride = colorOverrideWarning();
2337
+ /** A bar's slot in `xScaleGrouped`, from its datum and its index in its group (see `seriesSlots`). */
2338
+ slotOf = (bar) => bar.key;
2172
2339
  yScale;
2173
2340
  barClickedSource = new Subject();
2174
2341
  barClicked$ = this.barClickedSource.asObservable();
@@ -2187,7 +2354,7 @@ class BarVerticalChartBuilder extends PcacChart {
2187
2354
  return;
2188
2355
  }
2189
2356
  this.ensureColorCount(seriesKeys(config.data).length);
2190
- this.applyColorOverride(barColorOverride(config.colorOverride));
2357
+ this.applyColorOverride(barColorOverride(config.colorOverride, this.warnOfColorOverride));
2191
2358
  this.buildScales(config);
2192
2359
  this.drawChart(chartElm, config);
2193
2360
  }
@@ -2204,11 +2371,13 @@ class BarVerticalChartBuilder extends PcacChart {
2204
2371
  // Rounded to whole pixels for crisp bar edges, while there's room to (see canRoundBands).
2205
2372
  .round(canRoundBands(this.width, config.data.length))
2206
2373
  .padding(0.1);
2374
+ const slots = seriesSlots(config.data);
2375
+ this.slotOf = slots.slotOf;
2207
2376
  this.xScaleGrouped = scaleBand()
2208
2377
  .padding(0.2)
2209
2378
  .range([0, this.xScaleStacked.bandwidth()])
2210
- .round(canRoundBands(this.xScaleStacked.bandwidth(), seriesKeys(config.data).length))
2211
- .domain(seriesKeys(config.data));
2379
+ .round(canRoundBands(this.xScaleStacked.bandwidth(), slots.domain.length))
2380
+ .domain(slots.domain);
2212
2381
  }
2213
2382
  drawChart(chartElm, config) {
2214
2383
  this.buildContainer(chartElm);
@@ -2216,7 +2385,7 @@ class BarVerticalChartBuilder extends PcacChart {
2216
2385
  this.drawGrids(this.xScaleStacked, this.yScale);
2217
2386
  this.addGroups(config);
2218
2387
  this.axisBuilder.raiseAxes(this.svg);
2219
- refreshTabStop(chartElm.nativeElement);
2388
+ this.restoreTabStop(chartElm);
2220
2389
  }
2221
2390
  addGroups(config) {
2222
2391
  const groupsContainer = this.svg.append('g')
@@ -2296,7 +2465,7 @@ class BarVerticalChartBuilder extends PcacChart {
2296
2465
  // A stacked bar spans its whole group, which is already translated into place; looking its
2297
2466
  // series key up in the group band put it off in another group's slot whenever the key
2298
2467
  // matched a group key.
2299
- .attr('x', (d) => config.isStacked ? 0 : this.xScaleGrouped(d.key) ?? 0)
2468
+ .attr('x', (d, i) => config.isStacked ? 0 : this.xScaleGrouped(this.slotOf(d, i)) ?? 0)
2300
2469
  .attr('data-group-bar-id', (_, i) => {
2301
2470
  return i;
2302
2471
  })
@@ -2414,12 +2583,12 @@ class BarVerticalChartBuilder extends PcacChart {
2414
2583
  }
2415
2584
  applyPreTransitionThresholdStyles(elm) {
2416
2585
  return elm.attr('class', 'pcac-threshold')
2417
- .attr('x', (d) => {
2586
+ .attr('x', (d, i) => {
2418
2587
  // Not every caller's selection has a per-item PcacData bound (the whole-chart threshold
2419
2588
  // rect has none), hence the defensive fallback rather than assuming `d` is always present.
2420
2589
  const datum = d;
2421
2590
  // ScaleBand can return undefined for a key outside its domain; `.attr()` needs null, not undefined.
2422
- return this.xScaleGrouped(datum ? datum.key : '') ?? null;
2591
+ return this.xScaleGrouped(datum ? this.slotOf(datum, i) : '') ?? null;
2423
2592
  })
2424
2593
  .attr('y', () => {
2425
2594
  return this.height;
@@ -2441,38 +2610,532 @@ class BarVerticalChartBuilder extends PcacChart {
2441
2610
  return '3px';
2442
2611
  });
2443
2612
  }
2444
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: BarVerticalChartBuilder, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
2445
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: BarVerticalChartBuilder });
2613
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: BarVerticalChartBuilder, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
2614
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: BarVerticalChartBuilder });
2615
+ }
2616
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: BarVerticalChartBuilder, decorators: [{
2617
+ type: Injectable
2618
+ }] });
2619
+
2620
+ class PcacBarVerticalChart {
2621
+ chartBuilder = inject(BarVerticalChartBuilder);
2622
+ config = input.required(/* @ts-ignore */
2623
+ ...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
2624
+ chartElm = viewChild.required('chart', /* @ts-ignore */
2625
+ ...(ngDevMode ? [{ debugName: "chartElm" }] : /* istanbul ignore next */ []));
2626
+ barClicked = outputFromObservable(this.chartBuilder.barClicked$);
2627
+ /**
2628
+ * Optional consumer `<ng-template pcacTooltip>` projected into this element; replaces the
2629
+ * default tooltip when present (see PcacTooltipDirective).
2630
+ */
2631
+ tooltipTemplate = contentChild(PcacTooltipDirective, /* @ts-ignore */
2632
+ ...(ngDevMode ? [{ debugName: "tooltipTemplate" }] : /* istanbul ignore next */ []));
2633
+ constructor() {
2634
+ // Reacts to config() the same way ngOnChanges used to — reading it here (rather than a
2635
+ // lifecycle hook) is what makes this an effect: it tracks config() as its dependency and
2636
+ // reruns whenever a new value comes in, signal-input-changes-drive-behavior all the way down.
2637
+ effect(() => this.buildChart());
2638
+ // Handed over as a getter so the builder reads the query at hover time, not in the effect
2639
+ // above (see PcacChart.tooltipTemplate).
2640
+ this.chartBuilder.tooltipTemplate = () => this.tooltipTemplate()?.templateRef;
2641
+ inject(PcacChartResizeService).observe(this.chartElm, () => {
2642
+ // Skip the ResizeObserver's routine initial callback when it lands after the effect above
2643
+ // already built successfully at this same width — only a real size change (or a build
2644
+ // that never happened, e.g. the 0-width mount race) should trigger a rebuild here.
2645
+ if (this.chartBuilder.containerSizeChanged(this.chartElm())) {
2646
+ this.buildChart();
2647
+ }
2648
+ });
2649
+ }
2650
+ buildChart() {
2651
+ const config = this.config();
2652
+ // Handed over even when empty: the builder clears what it last drew rather than leaving it.
2653
+ if (config) {
2654
+ this.chartBuilder.buildChart(this.chartElm(), config);
2655
+ }
2656
+ }
2657
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacBarVerticalChart, deps: [], target: i0.ɵɵFactoryTarget.Component });
2658
+ 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 });
2659
+ }
2660
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacBarVerticalChart, decorators: [{
2661
+ type: Component,
2662
+ 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"] }]
2663
+ }], 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 }] }] } });
2664
+
2665
+ class PcacBarVerticalChartConfig extends PcacAxisChartConfig {
2666
+ isStacked = false;
2667
+ thresholds = [];
2668
+ spreadColorsPerGroup = false;
2669
+ /**
2670
+ * Bar colors, any CSS color, in place of the theme palette - by series, or by group with
2671
+ * `spreadColorsPerGroup`. Repeated when there are more series (or groups) than colors. Omitted
2672
+ * or empty, the theme palette is used - optional, as on every chart's config.
2673
+ */
2674
+ colorOverride;
2675
+ }
2676
+
2677
+ // Only what a consumer configures, binds or styles with. The chart plumbing - the `PcacChart`
2678
+ // base class and the builders, the axis/grid/tooltip/transition/resize services, and the
2679
+ // resolved-config helpers - is internal, so it can change without breaking anyone.
2680
+
2681
+ var PcacLineAreaPlotChartConfigType;
2682
+ (function (PcacLineAreaPlotChartConfigType) {
2683
+ PcacLineAreaPlotChartConfigType["Line"] = "line";
2684
+ PcacLineAreaPlotChartConfigType["Area"] = "area";
2685
+ PcacLineAreaPlotChartConfigType["Plot"] = "plot";
2686
+ })(PcacLineAreaPlotChartConfigType || (PcacLineAreaPlotChartConfigType = {}));
2687
+ /**
2688
+ * Sizing for the images drawn in place of a point's dot (see `PcacData.image`). An image is
2689
+ * scaled uniformly (up or down) to fit inside a `maxWidth` x `maxHeight` box, preserving its
2690
+ * aspect ratio, and is centered on the data point exactly where the dot would have been.
2691
+ */
2692
+ class PcacPointImageConfig {
2693
+ maxWidth = 16;
2694
+ maxHeight = 16;
2695
+ }
2696
+ /** How a point's `range` is drawn (see `PcacPointRangeConfig.style`). */
2697
+ var PcacPointRangeStyle;
2698
+ (function (PcacPointRangeStyle) {
2699
+ /** Error bars: a line across each range, capped at both ends. */
2700
+ PcacPointRangeStyle["Whiskers"] = "whiskers";
2701
+ /** A rectangle spanning the x range by the y range; a thin strip when only one is set. */
2702
+ PcacPointRangeStyle["Box"] = "box";
2703
+ /**
2704
+ * A fill strongest at the point's value and fading out to the range's edges: an oval glow
2705
+ * with both ranges (brightest on the value, even off-center), a fading bar with one.
2706
+ */
2707
+ PcacPointRangeStyle["Fade"] = "fade";
2708
+ })(PcacPointRangeStyle || (PcacPointRangeStyle = {}));
2709
+ /** When a point's `range` shows (see `PcacPointRangeConfig.show`). */
2710
+ var PcacPointRangeShow;
2711
+ (function (PcacPointRangeShow) {
2712
+ /** Only the hovered point's range. */
2713
+ PcacPointRangeShow["Hover"] = "hover";
2714
+ /** Every range at `faintOpacity`, the hovered point's at full strength. */
2715
+ PcacPointRangeShow["Faint"] = "faint";
2716
+ /** Every range at full strength; the others dim while a point is hovered. */
2717
+ PcacPointRangeShow["Always"] = "always";
2718
+ })(PcacPointRangeShow || (PcacPointRangeShow = {}));
2719
+ /**
2720
+ * Drawing for `PcacData.range` on the line/area/plot charts. Ranges sit above the lines/areas and
2721
+ * below the points, on the point's true coordinate (a fanned-out point's range stays on its
2722
+ * anchor), clipped to the plot area and following zoom. The chart draws no numbers for them; a
2723
+ * custom tooltip gets the point, `range` included.
2724
+ */
2725
+ class PcacPointRangeConfig {
2726
+ style = PcacPointRangeStyle.Whiskers;
2727
+ show = PcacPointRangeShow.Faint;
2728
+ /** Opacity of the ranges at rest under `show: Faint`, 0 - 1. */
2729
+ faintOpacity = 0.2;
2730
+ /**
2731
+ * Any CSS color for every range on the chart. Unset, each takes its series' color. Applied as
2732
+ * `--pcac-point-range-color` on the chart's `.point-ranges` group, so a stylesheet can set it
2733
+ * on an ancestor instead (a config value wins).
2734
+ */
2735
+ color;
2736
+ }
2737
+ /**
2738
+ * Drawing for `PcacData.gauge` on the line/area/plot charts: a ring around each point's mark (its
2739
+ * dot, or its image) whose arc fills clockwise from 12 o'clock in proportion to `gauge / max`,
2740
+ * over a faint full-circle track. Drawn with the mark, so it moves with zoom and fan-out; fan-out
2741
+ * spacing and the chart's edge space grow to fit it. Points without a `gauge` get no ring.
2742
+ */
2743
+ class PcacPointGaugeConfig {
2744
+ /** The `gauge` value of a full ring. Default 1, for values that are already a fraction. */
2745
+ max = 1;
2746
+ /** Ring thickness in px. */
2747
+ width = 2.5;
2748
+ /** Space between the mark (the image box, or a hovered dot) and the ring, in px. */
2749
+ gap = 3;
2750
+ /** Draw the unfilled rest of the ring, so an arc reads as a share of a whole. */
2751
+ showTrack = true;
2752
+ /**
2753
+ * What the gauge measures, e.g. `'PSA'`. When set, each point's screen reader name ends with it
2754
+ * and the point's value - "…, PSA 0.018" - since the ring itself is only visual. Unset, the
2755
+ * ring isn't read at all; say what it means in the chart's `ariaLabel`, or a custom tooltip.
2756
+ */
2757
+ name;
2758
+ /**
2759
+ * Any CSS color for the filled arc. Unset, each takes its series' color. Applied as
2760
+ * `--pcac-point-gauge-color` on the chart's `.dots` groups, so a stylesheet can set it on an
2761
+ * ancestor instead (a config value wins).
2762
+ */
2763
+ color;
2764
+ /** Any CSS color for the track (`--pcac-point-gauge-track-color`). Theme default `$gray-200`. */
2765
+ trackColor;
2766
+ }
2767
+ /**
2768
+ * A line across the plot at one value on an axis (see `PcacLineAreaChartConfig.referenceLines`):
2769
+ * a target, a threshold, a median. Drawn dashed, over the grid and under the series, clipped to
2770
+ * the plot area, and moved with zoom like the data.
2771
+ */
2772
+ class PcacReferenceLine {
2773
+ /** Which axis `value` is on: `'y'` draws a horizontal line, `'x'` a vertical one. */
2774
+ axis = 'y';
2775
+ /**
2776
+ * Where the line sits, in the axis's own terms: a number on the y axis; on the x axis, whatever
2777
+ * a point's `key` would be under `xAxis.format` - a number for `Decimal`, a date (or anything
2778
+ * `new Date()` reads) for `DateTime`, a series index otherwise.
2779
+ */
2780
+ value = 0;
2781
+ /**
2782
+ * A few words drawn at the line's far end, inside the plot: above the right end of a horizontal
2783
+ * line, beside the top of a vertical one. Styled by the theme's `.reference-line-label` rule.
2784
+ */
2785
+ label;
2786
+ /**
2787
+ * Any CSS color for the line and its label. Theme default `$gray-500`. Applied as
2788
+ * `--pcac-reference-line-color` on the line's group, so a stylesheet can set it on an ancestor
2789
+ * instead (a config value wins).
2790
+ */
2791
+ color;
2792
+ }
2793
+ /**
2794
+ * Text pinned to the plot area's corners (see `PcacLineAreaChartConfig.cornerLabels`) - names for
2795
+ * the regions the plot divides into, such as the quadrants between two reference lines. Pinned to
2796
+ * the plot's frame rather than to data, so they stay put when the chart is zoomed. Drawn under the
2797
+ * series, so a point in the corner covers its label rather than the other way round. Any corner
2798
+ * left unset is left empty.
2799
+ */
2800
+ class PcacCornerLabels {
2801
+ topLeft;
2802
+ topRight;
2803
+ bottomLeft;
2804
+ bottomRight;
2805
+ /**
2806
+ * Any CSS color for all four. Theme default `$gray-600`. Applied as `--pcac-corner-label-color`
2807
+ * on their group, so a stylesheet can set it on an ancestor instead (a config value wins).
2808
+ */
2809
+ color;
2810
+ }
2811
+ /**
2812
+ * The axes' `format` and `domainMin`/`domainMax` (`PcacAxisConfig`) do more here than on the bar
2813
+ * charts. `yAxis.domainMin`/`domainMax` are the y scale's domain (default 0..100). `xAxis.format`
2814
+ * decides how each point's `key` becomes an x position: `Decimal` reads it as a number on a
2815
+ * linear scale from `xAxis.domainMin` to `domainMax`, `DateTime` parses it with `new Date()` on
2816
+ * a time scale between the two (both required), and every other format - including the default -
2817
+ * places points by their index within their series, sizing the axis from the first series'
2818
+ * length and ignoring the domain fields.
2819
+ */
2820
+ class PcacLineAreaChartConfig extends PcacAxisChartConfig {
2821
+ enableEffects = true;
2822
+ /**
2823
+ * Zoom and pan along the x / y axis (scroll / pinch to zoom 1x-10x, drag to pan, never leaving
2824
+ * the original domain). Either, or both, can be on. A gesture is always two-dimensional, so with
2825
+ * only one enabled the other axis simply stays put. Both off by default. The zoom is kept when
2826
+ * the chart redraws - a new config, a series toggled in a legend, a resize (which keeps the same
2827
+ * part of the domain in view) - and dropped when zoom is turned off or the zoomable axes change.
2828
+ */
2829
+ enableZoomX = false;
2830
+ enableZoomY = false;
2831
+ /**
2832
+ * Series colors, any CSS color, in place of the theme palette, one per series in order. Repeats
2833
+ * from the start when there are more series than colors, as the default palette does. Omitted or
2834
+ * empty, the theme palette is used - optional, as on every chart's config.
2835
+ */
2836
+ colorOverride;
2837
+ /**
2838
+ * Bounding box for any point images (`PcacData.image`) on this chart. Optional; each field falls
2839
+ * back to the `PcacPointImageConfig` default when not given, so a consumer only setting `image`
2840
+ * on their data still gets a sensibly-sized result.
2841
+ */
2842
+ pointImage;
2843
+ /**
2844
+ * Draw each point's `range` (see `PcacData.range`). Off when not set; `{}` turns it on with
2845
+ * every `PcacPointRangeConfig` default. Points without a `range` draw nothing extra.
2846
+ */
2847
+ pointRange;
2848
+ /**
2849
+ * Dashed lines at chosen values on either axis (see `PcacReferenceLine`). None when not set.
2850
+ * They are decoration for sighted readers - hidden from screen readers like the grid - so when
2851
+ * one carries meaning, say so in the chart's `ariaLabel`.
2852
+ */
2853
+ referenceLines;
2854
+ /**
2855
+ * Draw each point's `gauge` as a ring around its mark (see `PcacData.gauge`). Off when not set;
2856
+ * `{}` turns it on with every `PcacPointGaugeConfig` default. Points without a `gauge` draw
2857
+ * nothing extra.
2858
+ */
2859
+ pointGauge;
2860
+ /**
2861
+ * Labels in the plot's four corners (see `PcacCornerLabels`). None when not set. Hidden from
2862
+ * screen readers like the grid, so when they carry meaning, say so in the chart's `ariaLabel`.
2863
+ */
2864
+ cornerLabels;
2865
+ }
2866
+
2867
+ /**
2868
+ * A dot plot: every point placed along one value axis (x), and points that share a value - or,
2869
+ * with `binWidth`, fall in the same bin - stacked into a column above it, one mark per point. It
2870
+ * shows how values are distributed while keeping every item visible and hoverable, which suits
2871
+ * items with their own identity (and their own `image`) better than a histogram's bars.
2872
+ *
2873
+ * `data` is series, each holding its points - the same shape as the plot chart - so points can be
2874
+ * colored by group. A point's `value` is its position on the axis and its `key` its name (in the
2875
+ * tooltip and to screen readers). A point whose `value` isn't a number is left out, as is a series
2876
+ * or point with `hide`.
2877
+ *
2878
+ * The axes: `xAxis` is the value axis - `domainMin` / `domainMax` fix its span (by default it
2879
+ * spans the data, rounded out to nice ticks), `format` formats its ticks and the tooltip's value,
2880
+ * and every label, sub label, tick and grid setting applies. There is no y scale - a column's
2881
+ * height is a count of marks, not a value - so the y axis is never drawn; `yAxis` is ignored.
2882
+ */
2883
+ class PcacDotPlotChartConfig extends PcacAxisChartConfig {
2884
+ /**
2885
+ * Group values into bins this wide, in the axis's units, and stack each bin at its center: with
2886
+ * values 7, 7.5 and 8 and a `binWidth` of 1, the 7 and 7.5 share a column. Unset (the default),
2887
+ * only equal values stack. Bins start at `xAxis.domainMin`, or 0 without one.
2888
+ */
2889
+ binWidth;
2890
+ /**
2891
+ * Radius of a point's dot, in px; default 6. Points with an `image` are sized by `pointImage`
2892
+ * instead. Optional, as `colorOverride` is on every chart, so an object literal needn't spell it out.
2893
+ */
2894
+ dotRadius = 6;
2895
+ /** Space between marks stacked in a column, in px; default 2. Optional, likewise. */
2896
+ gap = 2;
2897
+ /**
2898
+ * Bounding box for points' images (`PcacData.image`), drawn in place of their dots, as on the
2899
+ * plot chart. Each field falls back to its `PcacPointImageConfig` default.
2900
+ *
2901
+ * A column too tall for the chart's height shrinks every mark on the chart evenly until it fits,
2902
+ * so no point is ever cut off; give the chart more `height` to keep marks at full size.
2903
+ */
2904
+ pointImage;
2905
+ /**
2906
+ * Series colors, any CSS color, in place of the theme palette, one per series in order. Repeats
2907
+ * when there are more series than colors. Omitted or empty, the theme palette is used.
2908
+ */
2909
+ colorOverride;
2910
+ }
2911
+
2912
+ /** A point's value as a number to place it by, or `null` when it has none. */
2913
+ function dotValue(d) {
2914
+ const value = typeof d.value === 'number' ? d.value : typeof d.value === 'string' && d.value.trim() !== '' ? Number(d.value) : NaN;
2915
+ return Number.isFinite(value) ? value : null;
2916
+ }
2917
+ /**
2918
+ * Stacks every drawable point into columns: points with an equal value share a column or, with a
2919
+ * positive `binWidth`, points in the same bin (bins run from `origin`, each `binWidth` wide) share
2920
+ * one at the bin's center. Within a column, points take levels in data order - series order, then
2921
+ * each series' own order - so the first is at the bottom. Hidden series and points, and points
2922
+ * with no numeric value, are left out.
2923
+ */
2924
+ function stackDots(series, binWidth, origin = 0) {
2925
+ const binned = !!binWidth && binWidth > 0;
2926
+ const levels = new Map();
2927
+ const placements = [];
2928
+ series.forEach((s, seriesIndex) => {
2929
+ if (s.hide) {
2930
+ return;
2931
+ }
2932
+ (s.data ?? []).forEach((d, index) => {
2933
+ const value = dotValue(d);
2934
+ if (d.hide || value === null) {
2935
+ return;
2936
+ }
2937
+ const position = binned
2938
+ ? origin + (Math.floor((value - origin) / binWidth) + 0.5) * binWidth
2939
+ : value;
2940
+ const level = levels.get(position) ?? 0;
2941
+ levels.set(position, level + 1);
2942
+ placements.push({ data: d, series: s, seriesIndex, index, position, level });
2943
+ });
2944
+ });
2945
+ return placements;
2946
+ }
2947
+ /** How many marks the tallest column holds; 0 with none. */
2948
+ function tallestColumn(placements) {
2949
+ return placements.reduce((tallest, p) => Math.max(tallest, p.level + 1), 0);
2950
+ }
2951
+
2952
+ /** How much a hovered dot grows, in px of radius - also room kept for it at the plot's edges. */
2953
+ const DOT_HOVER_GROWTH = 2;
2954
+ /**
2955
+ * Provided per-component (see PcacDotPlotChart's `providers`), like every builder that extends
2956
+ * PcacChart: it holds per-chart-instance state, which a root singleton would share between charts.
2957
+ */
2958
+ class DotPlotChartBuilder extends PcacChart {
2959
+ dotClickedSource = new Subject();
2960
+ dotClicked$ = this.dotClickedSource.asObservable();
2961
+ chartTypeLabel = 'Dot plot';
2962
+ xScale;
2963
+ placements = [];
2964
+ pointImage;
2965
+ /** A mark's size and the gap between stacked marks this build, after any shrinking to fit. */
2966
+ markSize = 0;
2967
+ markGap = 0;
2968
+ dotRadius = 0;
2969
+ buildChart(chartElm, config) {
2970
+ if (!config?.data?.length) {
2971
+ this.hideTooltip();
2972
+ this.clearChart(chartElm);
2973
+ return;
2974
+ }
2975
+ this.hideTooltip();
2976
+ // A column's height is a count of marks, not a value, so there's no y axis to draw. Shallow
2977
+ // copies: initializeAxisState() rewrites `height`, which mustn't reach the consumer's object.
2978
+ const rawXAxis = config.xAxis;
2979
+ config = { ...config, yAxis: { ...config.yAxis, hide: true } };
2980
+ this.initializeAxisState(config, 'x', 0);
2981
+ const defaults = new PcacDotPlotChartConfig();
2982
+ const dotRadius = config.dotRadius ?? defaults.dotRadius;
2983
+ const gap = config.gap ?? defaults.gap;
2984
+ this.pointImage = { ...new PcacPointImageConfig(), ...config.pointImage };
2985
+ const origin = rawXAxis?.domainMin !== undefined ? Number(rawXAxis.domainMin) : 0;
2986
+ this.placements = stackDots(config.data, config.binWidth, origin);
2987
+ const hasImages = this.placements.some((p) => !!p.data.image);
2988
+ const fullSize = hasImages
2989
+ ? Math.max(this.pointImage.maxWidth, this.pointImage.maxHeight)
2990
+ : 2 * (dotRadius + DOT_HOVER_GROWTH);
2991
+ // A mark at the domain's edge is centered on it, so half of it hangs past the plot area.
2992
+ const half = Math.ceil(fullSize / 2);
2993
+ this.reserveEdgeSpace({ left: half, right: half });
2994
+ if (!this.initializeChartState(chartElm, config)) {
2995
+ return;
2996
+ }
2997
+ this.ensureColorCount(config.data.length);
2998
+ this.applyColorOverride(config.colorOverride);
2999
+ // Shrink every mark evenly when the tallest column wouldn't fit the plot's height.
3000
+ const tallest = tallestColumn(this.placements);
3001
+ const fit = tallest ? Math.min(1, this.height / (tallest * (fullSize + gap))) : 1;
3002
+ this.markSize = fullSize * fit;
3003
+ this.markGap = gap * fit;
3004
+ this.dotRadius = dotRadius * fit;
3005
+ this.xScale = this.buildXScale(rawXAxis?.domainMin, rawXAxis?.domainMax);
3006
+ this.drawChart(chartElm);
3007
+ }
3008
+ /**
3009
+ * The value axis: `xAxis.domainMin` / `domainMax` where given, otherwise the data's extent
3010
+ * rounded out to nice ticks - checked on the consumer's own axis config, since the resolved one
3011
+ * fills in 0 - 100 for anything unset.
3012
+ */
3013
+ buildXScale(domainMin, domainMax) {
3014
+ const [lo, hi] = extent(this.placements, (p) => p.position);
3015
+ const min = domainMin !== undefined ? Number(domainMin) : lo ?? 0;
3016
+ const max = domainMax !== undefined ? Number(domainMax) : hi ?? 1;
3017
+ const scale = scaleLinear().domain(min === max ? [min - 1, max + 1] : [min, max]).range([0, this.width]);
3018
+ return domainMin === undefined || domainMax === undefined ? scale.nice(this.xAxis.ticks) : scale;
3019
+ }
3020
+ drawChart(chartElm) {
3021
+ this.buildContainer(chartElm);
3022
+ const yScale = scaleLinear().domain([0, 1]).range([this.height, 0]);
3023
+ this.axisBuilder.drawAxis(this.axisBuilderConfig(this.xScale, yScale));
3024
+ this.drawGrids(this.xScale, yScale);
3025
+ this.axisBuilder.raiseAxes(this.svg);
3026
+ this.drawDots();
3027
+ this.restoreTabStop(chartElm);
3028
+ }
3029
+ /** The center of a placed point's mark, in plot pixels: its column's x, its level's y. */
3030
+ center(p) {
3031
+ const step = this.markSize + this.markGap;
3032
+ return {
3033
+ x: this.xScale(p.position),
3034
+ y: this.height - this.markGap - this.markSize / 2 - p.level * step,
3035
+ };
3036
+ }
3037
+ drawDots() {
3038
+ const self = this;
3039
+ const duration = this.transitionService.getTransitionDuration();
3040
+ const { maxWidth, maxHeight } = this.pointImage;
3041
+ const fit = this.markSize / (this.placements.some((p) => !!p.data.image) ? Math.max(maxWidth, maxHeight) : 1);
3042
+ const imageWidth = maxWidth * fit;
3043
+ const imageHeight = maxHeight * fit;
3044
+ const color = (p) => this.colors[p.seriesIndex];
3045
+ const tooltipOptions = (p, anchor = null) => ({
3046
+ index: p.index,
3047
+ parent: p.series,
3048
+ parentIndex: p.seriesIndex,
3049
+ valueFormat: this.xAxis.format,
3050
+ anchor,
3051
+ });
3052
+ const grow = (mark, p, hovered) => {
3053
+ select(mark).select('.pcac-dot')
3054
+ .interrupt('hover')
3055
+ .transition('hover')
3056
+ .duration(duration / 3)
3057
+ .attr('r', hovered ? this.dotRadius + DOT_HOVER_GROWTH : this.dotRadius)
3058
+ .attr('fill', hovered ? color(p) : 'var(--pcac-dot-fill, #fff)');
3059
+ };
3060
+ const marks = this.svg.append('g')
3061
+ .attr('class', 'pcac-dots')
3062
+ .selectAll('.pcac-dot-mark')
3063
+ .data(this.placements)
3064
+ .enter().append('g')
3065
+ .attr('class', 'pcac-dot-mark')
3066
+ .attr('transform', (p) => `translate(${this.center(p).x}, ${this.center(p).y})`)
3067
+ .on('mouseover', function (event, p) {
3068
+ grow(this, p, true);
3069
+ self.showTooltip(event, p.data, tooltipOptions(p, select(this).select('.pcac-dot, .pcac-dot-image').node()));
3070
+ })
3071
+ .on('mouseout', function (_event, p) {
3072
+ grow(this, p, false);
3073
+ self.hideTooltip();
3074
+ })
3075
+ .on('click', (_event, p) => this.dotClickedSource.next(p.data));
3076
+ makeMarksAccessible(marks, {
3077
+ label: (p) => this.markLabel(p.data, { parent: p.series, valueFormat: this.xAxis.format }),
3078
+ activate: (p) => this.dotClickedSource.next(p.data),
3079
+ focus: (mark, p) => {
3080
+ grow(mark, p, true);
3081
+ this.showMarkTooltip(mark, p.data, tooltipOptions(p, select(mark).select('.pcac-dot, .pcac-dot-image').node()));
3082
+ },
3083
+ blur: (mark, p) => {
3084
+ grow(mark, p, false);
3085
+ this.hideMarkTooltip(mark);
3086
+ },
3087
+ });
3088
+ // Each column builds up from the axis: a mark fades in a beat after the one below it.
3089
+ const delay = (p) => Math.min(p.level * 40, duration);
3090
+ marks.filter((p) => !p.data.image)
3091
+ .append('circle')
3092
+ .attr('class', 'pcac-dot')
3093
+ .attr('r', this.dotRadius)
3094
+ .attr('stroke', color)
3095
+ .attr('fill', 'var(--pcac-dot-fill, #fff)')
3096
+ .attr('opacity', 0)
3097
+ .transition()
3098
+ .delay(delay)
3099
+ .duration(duration / 2)
3100
+ .attr('opacity', 1);
3101
+ marks.filter((p) => !!p.data.image)
3102
+ .append('image')
3103
+ .attr('class', 'pcac-dot-image')
3104
+ .attr('href', (p) => p.data.image)
3105
+ .attr('width', imageWidth)
3106
+ .attr('height', imageHeight)
3107
+ .attr('x', -imageWidth / 2)
3108
+ .attr('y', -imageHeight / 2)
3109
+ .attr('preserveAspectRatio', 'xMidYMid meet')
3110
+ .attr('opacity', 0)
3111
+ .transition()
3112
+ .delay(delay)
3113
+ .duration(duration / 2)
3114
+ .attr('opacity', 1);
3115
+ }
3116
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: DotPlotChartBuilder, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
3117
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: DotPlotChartBuilder });
2446
3118
  }
2447
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: BarVerticalChartBuilder, decorators: [{
3119
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: DotPlotChartBuilder, decorators: [{
2448
3120
  type: Injectable
2449
3121
  }] });
2450
3122
 
2451
- class PcacBarVerticalChartComponent {
2452
- chartBuilder = inject(BarVerticalChartBuilder);
3123
+ /** A dot plot: points along one value axis, stacked into columns where they share a value (see PcacDotPlotChartConfig). */
3124
+ class PcacDotPlotChart {
3125
+ chartBuilder = inject(DotPlotChartBuilder);
2453
3126
  config = input.required(/* @ts-ignore */
2454
3127
  ...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
2455
3128
  chartElm = viewChild.required('chart', /* @ts-ignore */
2456
3129
  ...(ngDevMode ? [{ debugName: "chartElm" }] : /* istanbul ignore next */ []));
2457
- barClicked = outputFromObservable(this.chartBuilder.barClicked$);
2458
- /**
2459
- * Optional consumer `<ng-template pcacTooltip>` projected into this element; replaces the
2460
- * default tooltip when present (see PcacTooltipDirective).
2461
- */
3130
+ dotClicked = outputFromObservable(this.chartBuilder.dotClicked$);
3131
+ /** Optional consumer `<ng-template pcacTooltip>`, replacing the default tooltip (see PcacTooltipDirective). */
2462
3132
  tooltipTemplate = contentChild(PcacTooltipDirective, /* @ts-ignore */
2463
3133
  ...(ngDevMode ? [{ debugName: "tooltipTemplate" }] : /* istanbul ignore next */ []));
2464
3134
  constructor() {
2465
- // Reacts to config() the same way ngOnChanges used to — reading it here (rather than a
2466
- // lifecycle hook) is what makes this an effect: it tracks config() as its dependency and
2467
- // reruns whenever a new value comes in, signal-input-changes-drive-behavior all the way down.
2468
3135
  effect(() => this.buildChart());
2469
- // Handed over as a getter so the builder reads the query at hover time, not in the effect
2470
- // above (see PcacChart.tooltipTemplate).
3136
+ // A getter, so the builder reads the query at hover time rather than in the effect above.
2471
3137
  this.chartBuilder.tooltipTemplate = () => this.tooltipTemplate()?.templateRef;
2472
3138
  inject(PcacChartResizeService).observe(this.chartElm, () => {
2473
- // Skip the ResizeObserver's routine initial callback when it lands after the effect above
2474
- // already built successfully at this same width — only a real size change (or a build
2475
- // that never happened, e.g. the 0-width mount race) should trigger a rebuild here.
2476
3139
  if (this.chartBuilder.containerSizeChanged(this.chartElm())) {
2477
3140
  this.buildChart();
2478
3141
  }
@@ -2485,29 +3148,13 @@ class PcacBarVerticalChartComponent {
2485
3148
  this.chartBuilder.buildChart(this.chartElm(), config);
2486
3149
  }
2487
3150
  }
2488
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacBarVerticalChartComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
2489
- 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 });
3151
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacDotPlotChart, deps: [], target: i0.ɵɵFactoryTarget.Component });
3152
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.2.0", type: PcacDotPlotChart, isStandalone: true, selector: "pcac-dot-plot-chart", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { dotClicked: "dotClicked" }, host: { properties: { "class.pcac-height-full": "config().heightFull" } }, providers: [DotPlotChartBuilder], 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-dot-plot-chart\">\n <svg #chart></svg>\n</section>\n", styles: [".pcac-dot-plot-chart svg{width:100%;display:block}.pcac-dot-plot-chart .pcac-dot{stroke-width:2px}.pcac-dot-plot-chart .pcac-dot-mark{cursor:pointer}pcac-dot-plot-chart.pcac-height-full{display:block;height:100%}pcac-dot-plot-chart.pcac-height-full .pcac-dot-plot-chart{height:100%}\n"], encapsulation: i0.ViewEncapsulation.None });
2490
3153
  }
2491
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacBarVerticalChartComponent, decorators: [{
3154
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacDotPlotChart, decorators: [{
2492
3155
  type: Component,
2493
- 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"] }]
2494
- }], 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 }] }] } });
2495
-
2496
- class PcacBarVerticalChartConfig extends PcacAxisChartConfig {
2497
- isStacked = false;
2498
- thresholds = [];
2499
- spreadColorsPerGroup = false;
2500
- /**
2501
- * Bar colors, any CSS color, in place of the theme palette - by series, or by group with
2502
- * `spreadColorsPerGroup`. Repeated when there are more series (or groups) than colors. Empty,
2503
- * the theme palette is used.
2504
- */
2505
- colorOverride = [];
2506
- }
2507
-
2508
- // Only what a consumer configures, binds or styles with. The chart plumbing - the `PcacChart`
2509
- // base class and the builders, the axis/grid/tooltip/transition/resize services, and the
2510
- // resolved-config helpers - is internal, so it can change without breaking anyone.
3156
+ args: [{ selector: 'pcac-dot-plot-chart', host: { '[class.pcac-height-full]': 'config().heightFull' }, encapsulation: ViewEncapsulation.None, providers: [DotPlotChartBuilder], template: "<section class=\"pcac-dot-plot-chart\">\n <svg #chart></svg>\n</section>\n", styles: [".pcac-dot-plot-chart svg{width:100%;display:block}.pcac-dot-plot-chart .pcac-dot{stroke-width:2px}.pcac-dot-plot-chart .pcac-dot-mark{cursor:pointer}pcac-dot-plot-chart.pcac-height-full{display:block;height:100%}pcac-dot-plot-chart.pcac-height-full .pcac-dot-plot-chart{height:100%}\n"] }]
3157
+ }], ctorParameters: () => [], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }], chartElm: [{ type: i0.ViewChild, args: ['chart', { isSignal: true }] }], dotClicked: [{ type: i0.Output, args: ["dotClicked"] }], tooltipTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => PcacTooltipDirective), { isSignal: true }] }] } });
2511
3158
 
2512
3159
  class PcacLegendConfigItem {
2513
3160
  label;
@@ -2533,110 +3180,16 @@ class PcacLegend {
2533
3180
  this.itemClicked.emit(items);
2534
3181
  }
2535
3182
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacLegend, deps: [], target: i0.ɵɵFactoryTarget.Component });
2536
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.2.0", type: PcacLegend, isStandalone: true, selector: "pcac-legend", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { config: "configChange", itemClicked: "itemClicked" }, host: { attributes: { "role": "group" }, properties: { "attr.aria-labelledby": "config().heading ? headingId : null" } }, ngImport: i0, template: "<div class=\"pcac-legend-label\" [id]=\"headingId\"><small>{{config().heading}}</small></div>\n@for(item of config().items; track $index; let i = $index) {\n<div class=\"pcac-legend-item\" [class.pcac-legend-unchecked]=\"!item.checked\"\n role=\"switch\" [attr.aria-checked]=\"item.checked\" tabindex=\"0\" (click)=\"onItemClicked(i)\"\n (keydown.enter)=\"onItemClicked(i)\" (keydown.space)=\"onItemClicked(i); $event.preventDefault()\">\n @let color = item.colorOverride ? item.colorOverride : colorScale()[i];\n <div class=\"pcac-legend-circle\" [style.backgroundColor]=\"color\"></div>\n <small>{{ item.label }}</small>\n</div>\n}\n", styles: [":host{display:flex;align-items:center;flex-wrap:wrap;column-gap:8px}.pcac-legend-label{margin-bottom:2.5px}.pcac-legend-item{cursor:pointer;display:flex;align-items:center;min-height:24px}.pcac-legend-item:hover .pcac-legend-circle{box-shadow:0 0 6px #0000004d;transform:scale(1.2)}.pcac-legend-circle{display:inline-block;width:12px;height:12px;border-radius:50%;margin-right:4px;transition:box-shadow .3s ease,transform .3s ease}.pcac-legend-unchecked{opacity:.5}.pcac-legend-item:focus-visible{outline:2px solid currentColor;outline-offset:2px}\n"] });
3183
+ 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"] });
2537
3184
  }
2538
3185
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacLegend, decorators: [{
2539
3186
  type: Component,
2540
3187
  args: [{ selector: 'pcac-legend', host: {
2541
3188
  role: 'group',
2542
3189
  '[attr.aria-labelledby]': 'config().heading ? headingId : null',
2543
- }, template: "<div class=\"pcac-legend-label\" [id]=\"headingId\"><small>{{config().heading}}</small></div>\n@for(item of config().items; track $index; let i = $index) {\n<div class=\"pcac-legend-item\" [class.pcac-legend-unchecked]=\"!item.checked\"\n role=\"switch\" [attr.aria-checked]=\"item.checked\" tabindex=\"0\" (click)=\"onItemClicked(i)\"\n (keydown.enter)=\"onItemClicked(i)\" (keydown.space)=\"onItemClicked(i); $event.preventDefault()\">\n @let color = item.colorOverride ? item.colorOverride : colorScale()[i];\n <div class=\"pcac-legend-circle\" [style.backgroundColor]=\"color\"></div>\n <small>{{ item.label }}</small>\n</div>\n}\n", styles: [":host{display:flex;align-items:center;flex-wrap:wrap;column-gap:8px}.pcac-legend-label{margin-bottom:2.5px}.pcac-legend-item{cursor:pointer;display:flex;align-items:center;min-height:24px}.pcac-legend-item:hover .pcac-legend-circle{box-shadow:0 0 6px #0000004d;transform:scale(1.2)}.pcac-legend-circle{display:inline-block;width:12px;height:12px;border-radius:50%;margin-right:4px;transition:box-shadow .3s ease,transform .3s ease}.pcac-legend-unchecked{opacity:.5}.pcac-legend-item:focus-visible{outline:2px solid currentColor;outline-offset:2px}\n"] }]
3190
+ }, 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"] }]
2544
3191
  }], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }, { type: i0.Output, args: ["configChange"] }], itemClicked: [{ type: i0.Output, args: ["itemClicked"] }] } });
2545
3192
 
2546
- var PcacLineAreaPlotChartConfigType;
2547
- (function (PcacLineAreaPlotChartConfigType) {
2548
- PcacLineAreaPlotChartConfigType["Line"] = "line";
2549
- PcacLineAreaPlotChartConfigType["Area"] = "area";
2550
- PcacLineAreaPlotChartConfigType["Plot"] = "plot";
2551
- })(PcacLineAreaPlotChartConfigType || (PcacLineAreaPlotChartConfigType = {}));
2552
- /**
2553
- * Sizing for the images drawn in place of a point's dot (see `PcacData.image`). An image is
2554
- * scaled uniformly (up or down) to fit inside a `maxWidth` x `maxHeight` box, preserving its
2555
- * aspect ratio, and is centered on the data point exactly where the dot would have been.
2556
- */
2557
- class PcacPointImageConfig {
2558
- maxWidth = 16;
2559
- maxHeight = 16;
2560
- }
2561
- /** How a point's `range` is drawn (see `PcacPointRangeConfig.style`). */
2562
- var PcacPointRangeStyle;
2563
- (function (PcacPointRangeStyle) {
2564
- /** Error bars: a line across each range, capped at both ends. */
2565
- PcacPointRangeStyle["Whiskers"] = "whiskers";
2566
- /** A rectangle spanning the x range by the y range; a thin strip when only one is set. */
2567
- PcacPointRangeStyle["Box"] = "box";
2568
- /**
2569
- * A fill strongest at the point's value and fading out to the range's edges: an oval glow
2570
- * with both ranges (brightest on the value, even off-center), a fading bar with one.
2571
- */
2572
- PcacPointRangeStyle["Fade"] = "fade";
2573
- })(PcacPointRangeStyle || (PcacPointRangeStyle = {}));
2574
- /** When a point's `range` shows (see `PcacPointRangeConfig.show`). */
2575
- var PcacPointRangeShow;
2576
- (function (PcacPointRangeShow) {
2577
- /** Only the hovered point's range. */
2578
- PcacPointRangeShow["Hover"] = "hover";
2579
- /** Every range at `faintOpacity`, the hovered point's at full strength. */
2580
- PcacPointRangeShow["Faint"] = "faint";
2581
- /** Every range at full strength; the others dim while a point is hovered. */
2582
- PcacPointRangeShow["Always"] = "always";
2583
- })(PcacPointRangeShow || (PcacPointRangeShow = {}));
2584
- /**
2585
- * Drawing for `PcacData.range` on the line/area/plot charts. Ranges sit above the lines/areas and
2586
- * below the points, on the point's true coordinate (a fanned-out point's range stays on its
2587
- * anchor), clipped to the plot area and following zoom. The chart draws no numbers for them; a
2588
- * custom tooltip gets the point, `range` included.
2589
- */
2590
- class PcacPointRangeConfig {
2591
- style = PcacPointRangeStyle.Whiskers;
2592
- show = PcacPointRangeShow.Faint;
2593
- /** Opacity of the ranges at rest under `show: Faint`, 0 - 1. */
2594
- faintOpacity = 0.2;
2595
- /**
2596
- * Any CSS color for every range on the chart. Unset, each takes its series' color. Applied as
2597
- * `--pcac-point-range-color` on the chart's `.point-ranges` group, so a stylesheet can set it
2598
- * on an ancestor instead (a config value wins).
2599
- */
2600
- color;
2601
- }
2602
- /**
2603
- * The axes' `format` and `domainMin`/`domainMax` (`PcacAxisConfig`) do more here than on the bar
2604
- * charts. `yAxis.domainMin`/`domainMax` are the y scale's domain (default 0..100). `xAxis.format`
2605
- * decides how each point's `key` becomes an x position: `Decimal` reads it as a number on a
2606
- * linear scale from `xAxis.domainMin` to `domainMax`, `DateTime` parses it with `new Date()` on
2607
- * a time scale between the two (both required), and every other format - including the default -
2608
- * places points by their index within their series, sizing the axis from the first series'
2609
- * length and ignoring the domain fields.
2610
- */
2611
- class PcacLineAreaChartConfig extends PcacAxisChartConfig {
2612
- enableEffects = true;
2613
- /**
2614
- * Zoom and pan along the x / y axis (scroll / pinch to zoom 1x-10x, drag to pan, never leaving
2615
- * the original domain). Either, or both, can be on. A gesture is always two-dimensional, so with
2616
- * only one enabled the other axis simply stays put. Both off by default. The zoom is kept when
2617
- * the chart redraws - a new config, a series toggled in a legend, a resize (which keeps the same
2618
- * part of the domain in view) - and dropped when zoom is turned off or the zoomable axes change.
2619
- */
2620
- enableZoomX = false;
2621
- enableZoomY = false;
2622
- /**
2623
- * Hex color codes to override the default colors, one per series in order. Repeats from the
2624
- * start when there are more series than colors, as the default palette does.
2625
- */
2626
- colorOverride = [];
2627
- /**
2628
- * Bounding box for any point images (`PcacData.image`) on this chart. Optional; each field falls
2629
- * back to the `PcacPointImageConfig` default when not given, so a consumer only setting `image`
2630
- * on their data still gets a sensibly-sized result.
2631
- */
2632
- pointImage;
2633
- /**
2634
- * Draw each point's `range` (see `PcacData.range`). Off when not set; `{}` turns it on with
2635
- * every `PcacPointRangeConfig` default. Points without a `range` draw nothing extra.
2636
- */
2637
- pointRange;
2638
- }
2639
-
2640
3193
  /**
2641
3194
  * Whether a point has an x key to position by. An explicit emptiness check, not truthiness: a
2642
3195
  * Decimal key of `0` is a perfectly good coordinate (the left edge of a `domainMin: 0` axis) and
@@ -3146,6 +3699,152 @@ function drawRange(group, extent, style, gradientId) {
3146
3699
  }
3147
3700
  }
3148
3701
 
3702
+ /** A hovered dot's radius - the largest a dot gets, so a ring around it never touches it. */
3703
+ const GAUGE_DOT_RADIUS = 6;
3704
+ /** Whether a point has a gauge value to draw. */
3705
+ function hasGauge(d) {
3706
+ return typeof d.gauge === 'number' && Number.isFinite(d.gauge);
3707
+ }
3708
+ /** How far a ring reaches past the mark it surrounds: its gap plus its full width. */
3709
+ function gaugeExtent(config) {
3710
+ return config.gap + config.width;
3711
+ }
3712
+ /** The share of the ring a value fills, clamped to 0 - 1. A `max` of 0 or less fills nothing. */
3713
+ function gaugeFraction(value, max) {
3714
+ return max > 0 ? Math.min(1, Math.max(0, value / max)) : 0;
3715
+ }
3716
+ /**
3717
+ * Appends a `.point-gauge` ring to each point in `points` that has a `gauge`: a `.point-gauge-track`
3718
+ * circle (unless `showTrack` is off) and a `.point-gauge-arc` path filling clockwise from 12
3719
+ * o'clock. `markRadius` is half of what the ring surrounds - the image box, or a hovered dot - so
3720
+ * the ring's centerline sits `gap + width / 2` beyond it. Returned so the caller can place the
3721
+ * rings (see `drawDots`, which moves them with each point's fan-out offset and enter rise).
3722
+ */
3723
+ function drawPointGauges(points, config, markRadius) {
3724
+ const radius = (d) => markRadius(d) + config.gap + config.width / 2;
3725
+ const gauges = points.filter(hasGauge)
3726
+ .append('g')
3727
+ .attr('class', 'point-gauge')
3728
+ .attr('aria-hidden', 'true');
3729
+ if (config.showTrack) {
3730
+ gauges.append('circle')
3731
+ .attr('class', 'point-gauge-track')
3732
+ .attr('r', radius)
3733
+ .attr('stroke-width', config.width);
3734
+ }
3735
+ gauges.append('path')
3736
+ .attr('class', 'point-gauge-arc')
3737
+ .attr('d', (d) => {
3738
+ const fraction = gaugeFraction(d.gauge, config.max);
3739
+ if (fraction === 0) {
3740
+ return null;
3741
+ }
3742
+ const r = radius(d);
3743
+ // Rounded ends read as a gauge; a full ring has no ends to round.
3744
+ return arc().cornerRadius(fraction < 1 ? config.width / 2 : 0)({
3745
+ innerRadius: r - config.width / 2,
3746
+ outerRadius: r + config.width / 2,
3747
+ startAngle: 0,
3748
+ endAngle: 2 * Math.PI * fraction,
3749
+ });
3750
+ });
3751
+ return gauges;
3752
+ }
3753
+
3754
+ /** How far a reference line's label, and a corner label, sits in from what it's attached to, in px. */
3755
+ const LABEL_INSET = 4;
3756
+ const CORNER_INSET = 8;
3757
+ /**
3758
+ * Where a reference line sits on its axis, in plot pixels, or `null` when its value doesn't place
3759
+ * (a date that won't parse, a non-numeric value) - such a line isn't drawn. An x value is read the
3760
+ * way a point's `key` is under the axis's format (see `getXFormat`).
3761
+ */
3762
+ function referenceLinePosition(line, scales, xFormat) {
3763
+ const position = line.axis === 'x'
3764
+ ? scales.x(xFormat === PcacFormatEnum.DateTime ? new Date(line.value) : Number(line.value))
3765
+ : scales.y(Number(line.value));
3766
+ return Number.isFinite(position) ? position : null;
3767
+ }
3768
+ /**
3769
+ * Draws `lines` into one `.reference-lines` group, clipped to the plot (`clipPathId`) so a line
3770
+ * zoomed past an edge disappears there. Each line is a `.reference-line` group holding the dashed
3771
+ * `<line>` and, when it has one, its `.reference-line-label`. Hidden from screen readers, as the
3772
+ * grid is.
3773
+ */
3774
+ function drawReferenceLines(svg, lines, scales, xFormat, width, height, clipPathId) {
3775
+ if (!lines?.length) {
3776
+ return;
3777
+ }
3778
+ const resolved = lines.map((line) => ({ ...new PcacReferenceLine(), ...line }));
3779
+ const groups = svg.append('g')
3780
+ .attr('class', 'reference-lines')
3781
+ .attr('clip-path', `url(#${clipPathId})`)
3782
+ .attr('aria-hidden', 'true')
3783
+ .selectAll('.reference-line')
3784
+ .data(resolved)
3785
+ .enter().append('g')
3786
+ .attr('class', (line) => `reference-line reference-line-${line.axis}`)
3787
+ .style('--pcac-reference-line-color', (line) => line.color ?? null);
3788
+ groups.append('line').attr('class', 'reference-line-stroke');
3789
+ groups.filter((line) => !!line.label)
3790
+ .append('text')
3791
+ .attr('class', 'reference-line-label')
3792
+ .text((line) => line.label);
3793
+ positionReferenceLines(svg, scales, xFormat, width, height);
3794
+ }
3795
+ /**
3796
+ * Places the chart's reference lines, and their labels, against `scales` - on the first draw and
3797
+ * again on every zoom. A horizontal line's label sits above its right end; a vertical line's beside
3798
+ * its top.
3799
+ */
3800
+ function positionReferenceLines(svg, scales, xFormat, width, height) {
3801
+ const groups = svg.selectAll('.reference-line')
3802
+ .attr('display', (line) => referenceLinePosition(line, scales, xFormat) === null ? 'none' : null);
3803
+ const at = (line) => referenceLinePosition(line, scales, xFormat) ?? 0;
3804
+ groups.select('.reference-line-stroke')
3805
+ .attr('x1', (line) => line.axis === 'x' ? at(line) : 0)
3806
+ .attr('x2', (line) => line.axis === 'x' ? at(line) : width)
3807
+ .attr('y1', (line) => line.axis === 'x' ? 0 : at(line))
3808
+ .attr('y2', (line) => line.axis === 'x' ? height : at(line));
3809
+ groups.select('.reference-line-label')
3810
+ .attr('x', (line) => line.axis === 'x' ? at(line) + LABEL_INSET : width - LABEL_INSET)
3811
+ .attr('y', (line) => line.axis === 'x' ? LABEL_INSET : at(line) - LABEL_INSET)
3812
+ .attr('text-anchor', (line) => line.axis === 'x' ? 'start' : 'end')
3813
+ .attr('dominant-baseline', (line) => line.axis === 'x' ? 'hanging' : 'auto');
3814
+ }
3815
+ /**
3816
+ * Draws `labels` into a `.corner-labels` group, each a `.corner-label` inset from its corner of
3817
+ * the plot area. Pinned to the frame, so zoom leaves them alone. Hidden from screen readers, as
3818
+ * the grid is.
3819
+ */
3820
+ function drawCornerLabels(svg, labels, width, height) {
3821
+ if (!labels) {
3822
+ return;
3823
+ }
3824
+ const corners = [
3825
+ { text: labels.topLeft, x: CORNER_INSET, y: CORNER_INSET, anchor: 'start', baseline: 'hanging', name: 'top-left' },
3826
+ { text: labels.topRight, x: width - CORNER_INSET, y: CORNER_INSET, anchor: 'end', baseline: 'hanging', name: 'top-right' },
3827
+ { text: labels.bottomLeft, x: CORNER_INSET, y: height - CORNER_INSET, anchor: 'start', baseline: 'auto', name: 'bottom-left' },
3828
+ { text: labels.bottomRight, x: width - CORNER_INSET, y: height - CORNER_INSET, anchor: 'end', baseline: 'auto', name: 'bottom-right' },
3829
+ ].filter((corner) => !!corner.text);
3830
+ if (corners.length === 0) {
3831
+ return;
3832
+ }
3833
+ svg.append('g')
3834
+ .attr('class', 'corner-labels')
3835
+ .attr('aria-hidden', 'true')
3836
+ .style('--pcac-corner-label-color', () => labels.color ?? null)
3837
+ .selectAll('.corner-label')
3838
+ .data(corners)
3839
+ .enter().append('text')
3840
+ .attr('class', (corner) => `corner-label corner-label-${corner.name}`)
3841
+ .attr('x', (corner) => corner.x)
3842
+ .attr('y', (corner) => corner.y)
3843
+ .attr('text-anchor', (corner) => corner.anchor)
3844
+ .attr('dominant-baseline', (corner) => corner.baseline)
3845
+ .text((corner) => corner.text);
3846
+ }
3847
+
3149
3848
  /**
3150
3849
  * Finds every set of points that share a coordinate across all of the chart's visible series.
3151
3850
  * Coincidence is decided from the data rather than from scaled pixels, so this can run before
@@ -3303,7 +4002,8 @@ class PlaChartBuilder extends PcacChart {
3303
4002
  restoringZoom = false;
3304
4003
  lineGenerator;
3305
4004
  areaGenerator;
3306
- zoomBehavior;
4005
+ /** This build's zoom behavior; `null` while zoom is off. */
4006
+ zoomBehavior = null;
3307
4007
  dotClickedSource = new Subject();
3308
4008
  config;
3309
4009
  /**
@@ -3349,6 +4049,8 @@ class PlaChartBuilder extends PcacChart {
3349
4049
  hoveredPoint = null;
3350
4050
  /** `config.pointRange` with its defaults applied, or `null` while ranges are off. */
3351
4051
  pointRange = null;
4052
+ /** `pointGauge` with its defaults, or `null` while it's off. */
4053
+ pointGauge = null;
3352
4054
  /** Each drawn range's `.point-range` group, by its point, so hover can find the one to focus. */
3353
4055
  rangeGroupOf = new Map();
3354
4056
  /**
@@ -3377,6 +4079,8 @@ class PlaChartBuilder extends PcacChart {
3377
4079
  // A hidden axis keeps 8px rather than 0 so a dot on the edge of the plot isn't clipped
3378
4080
  this.initializeAxisState(this.config, 'y', 8);
3379
4081
  this.chartTypeLabel = CHART_TYPE_LABELS[type];
4082
+ // Before the layout: a ring widens what fan-out and the edge space have to make room for.
4083
+ this.pointGauge = this.config.pointGauge ? { ...new PcacPointGaugeConfig(), ...this.config.pointGauge } : null;
3380
4084
  this.resolvePointLayout(type);
3381
4085
  this.reservePointSpace();
3382
4086
  this.pointRange = this.config.pointRange ? { ...new PcacPointRangeConfig(), ...this.config.pointRange } : null;
@@ -3390,13 +4094,17 @@ class PlaChartBuilder extends PcacChart {
3390
4094
  this.lineGenerator = buildLineGenerator(this.xAxis.format, this.scales);
3391
4095
  this.areaGenerator = buildAreaGenerator(this.xAxis.format, this.scales, this.height);
3392
4096
  if (this.zoomEnabled) {
3393
- this.zoomBehavior = buildZoomBehavior(this.width, this.height, (event) => {
4097
+ const behavior = buildZoomBehavior(this.width, this.height, (event) => {
3394
4098
  // Zoom moves the points, not the mouse: the hovered one slides out from under a still
3395
4099
  // cursor (or is hidden outright, see `pointDisplay`), and either way the browser never
3396
4100
  // sends it a mouseout - its tooltip would stay up, and its dot stay grown, until the
3397
4101
  // cursor happened to cross it again. So the hover is ended here, on every zoom event.
3398
- // The build's own starting zoom, handed to the behavior: already drawn that way.
3399
- if (this.restoringZoom) {
4102
+ // The build's own starting zoom, handed to the behavior: already drawn that way. And a
4103
+ // gesture begun on an earlier build - a drag still going when live data or a resize redrew
4104
+ // the chart, which d3-zoom carries on through listeners on the window - belongs to a
4105
+ // drawing that's gone: left to run, it moved this one and overwrote the kept zoom with its
4106
+ // own, and the next gesture snapped back.
4107
+ if (this.restoringZoom || behavior !== this.zoomBehavior) {
3400
4108
  return;
3401
4109
  }
3402
4110
  this.leavePoint();
@@ -3445,6 +4153,9 @@ class PlaChartBuilder extends PcacChart {
3445
4153
  .selectAll('.fan-out-spoke')
3446
4154
  .attr('x2', (member) => this.spokeEnd(member, zoomedScales).dx)
3447
4155
  .attr('y2', (member) => this.spokeEnd(member, zoomedScales).dy);
4156
+ // Reference lines sit at data values, so they move with it; corner labels are pinned to the
4157
+ // frame and stay put.
4158
+ positionReferenceLines(this.svg, zoomedScales, this.xAxis.format, this.width, this.height);
3448
4159
  // The hover crosshair positions and labels against the scales, so it takes the zoomed ones.
3449
4160
  if (this.effectsEnabled) {
3450
4161
  this.effectsBuilder.updateScales(newX, newY);
@@ -3458,6 +4169,10 @@ class PlaChartBuilder extends PcacChart {
3458
4169
  this.svg.selectAll('.fan-outs').raise();
3459
4170
  this.svg.selectAll('.dots').raise();
3460
4171
  });
4172
+ this.zoomBehavior = behavior;
4173
+ }
4174
+ else {
4175
+ this.zoomBehavior = null;
3461
4176
  }
3462
4177
  this.drawChart(chartElm, this.config, type);
3463
4178
  }
@@ -3467,6 +4182,9 @@ class PlaChartBuilder extends PcacChart {
3467
4182
  this.createReusableClipPath();
3468
4183
  this.axisBuilder.drawAxis(this.axisBuilderConfig(this.scales.x, this.scales.y));
3469
4184
  this.drawGrids(this.scales.x, this.scales.y);
4185
+ // Over the grid, under the series: guides, not data.
4186
+ drawCornerLabels(this.svg, config.cornerLabels, this.width, this.height);
4187
+ drawReferenceLines(this.svg, config.referenceLines, this.scales, this.xAxis.format, this.width, this.height, this.plotClipPathId);
3470
4188
  this.drawLineArea(config, type);
3471
4189
  this.effectsEnabled = !!config.enableEffects && type !== PcacLineAreaPlotChartConfigType.Plot;
3472
4190
  if (this.effectsEnabled) {
@@ -3491,7 +4209,7 @@ class PlaChartBuilder extends PcacChart {
3491
4209
  this.drawPointRanges();
3492
4210
  this.drawFanOuts();
3493
4211
  this.drawDots(config);
3494
- refreshTabStop(chartElm.nativeElement);
4212
+ this.restoreTabStop(chartElm);
3495
4213
  }
3496
4214
  /**
3497
4215
  * Resolves `pointImage`, finds the points that share a coordinate and, on a plot chart with
@@ -3513,9 +4231,11 @@ class PlaChartBuilder extends PcacChart {
3513
4231
  }
3514
4232
  this.fanOut = { ...new PcacPointFanOutConfig(), ...fanOut };
3515
4233
  // A group's members are kept apart by the size of what's drawn for them: the image box when
3516
- // any member has an image, else a hovered dot (r = 6).
4234
+ // any member has an image, else a hovered dot (r = 6) - plus a gauge ring on both sides when
4235
+ // any member has one.
3517
4236
  const { maxWidth, maxHeight } = this.pointImage;
3518
- const markSize = (group) => group.members.some((member) => !!member.data.image) ? Math.max(maxWidth, maxHeight) : 12;
4237
+ const ring = (group) => this.pointGauge && group.members.some((member) => hasGauge(member.data)) ? 2 * gaugeExtent(this.pointGauge) : 0;
4238
+ const markSize = (group) => (group.members.some((member) => !!member.data.image) ? Math.max(maxWidth, maxHeight) : 2 * GAUGE_DOT_RADIUS) + ring(group);
3519
4239
  const radius = (group) => this.fanOut.radius ?? fanOutRadius(group.members.length, markSize(group), this.fanOut.gap);
3520
4240
  this.fanOutOffsets = fanOutOffsets(this.coincidentGroups, radius);
3521
4241
  }
@@ -3530,13 +4250,16 @@ class PlaChartBuilder extends PcacChart {
3530
4250
  * `initializeAxisState()` and `initializeChartState()`, see `reserveEdgeSpace`.
3531
4251
  */
3532
4252
  reservePointSpace() {
3533
- const hasImages = this.config.data.some((series) => series.data.some((point) => !!point.image));
3534
- if (!hasImages) {
4253
+ const points = this.config.data.flatMap((series) => series.data);
4254
+ const hasImages = points.some((point) => !!point.image);
4255
+ // A gauge ring reaches past its mark on every side, so it needs the same room the mark does.
4256
+ const ring = this.pointGauge && points.some(hasGauge) ? Math.ceil(gaugeExtent(this.pointGauge)) : 0;
4257
+ if (!hasImages && !ring) {
3535
4258
  this.clipBuffer = 10;
3536
4259
  return;
3537
4260
  }
3538
- const halfWidth = Math.ceil(this.pointImage.maxWidth / 2);
3539
- const halfHeight = Math.ceil(this.pointImage.maxHeight / 2);
4261
+ const halfWidth = (hasImages ? Math.ceil(this.pointImage.maxWidth / 2) : GAUGE_DOT_RADIUS) + ring;
4262
+ const halfHeight = (hasImages ? Math.ceil(this.pointImage.maxHeight / 2) : GAUGE_DOT_RADIUS) + ring;
3540
4263
  this.clipBuffer = Math.max(10, halfWidth, halfHeight);
3541
4264
  this.reserveEdgeSpace({ top: halfHeight, bottom: halfHeight, left: halfWidth, right: halfWidth });
3542
4265
  }
@@ -3608,7 +4331,8 @@ class PlaChartBuilder extends PcacChart {
3608
4331
  return zoomIdentity.translate(kept.x * this.width, kept.y * this.height).scale(kept.k);
3609
4332
  }
3610
4333
  attachZoomBehavior() {
3611
- if (!this.zoomEnabled)
4334
+ const zoom = this.zoomBehavior;
4335
+ if (!this.zoomEnabled || !zoom)
3612
4336
  return;
3613
4337
  // A transparent rect so the empty plot area is a hit target too: a `<g>` has no area of its
3614
4338
  // own, so wheel/drag only reaches it through something painted. The rect is only ever that -
@@ -3629,12 +4353,12 @@ class PlaChartBuilder extends PcacChart {
3629
4353
  .attr('height', this.height)
3630
4354
  .attr('fill', 'none')
3631
4355
  .attr('pointer-events', 'all');
3632
- this.svg.call(this.zoomBehavior);
4356
+ this.svg.call(zoom);
3633
4357
  // A resumed zoom is already drawn (`scales`); the behavior is told it too, so the next gesture
3634
4358
  // carries on from there rather than from the whole domain.
3635
4359
  if (this.startZoom) {
3636
4360
  this.restoringZoom = true;
3637
- this.svg.call(this.zoomBehavior.transform, this.startZoom);
4361
+ this.svg.call(zoom.transform, this.startZoom);
3638
4362
  this.restoringZoom = false;
3639
4363
  }
3640
4364
  }
@@ -3836,6 +4560,9 @@ class PlaChartBuilder extends PcacChart {
3836
4560
  .attr('class', 'dots')
3837
4561
  .attr('clip-path', `url(#${this.clipPathId})`)
3838
4562
  .attr('style', series.hide ? 'display: none' : null)
4563
+ // After `style`, which replaces the whole attribute.
4564
+ .style('--pcac-point-gauge-color', () => this.pointGauge?.color ?? null)
4565
+ .style('--pcac-point-gauge-track-color', () => this.pointGauge?.trackColor ?? null)
3839
4566
  .selectAll('.point')
3840
4567
  .data(series.data)
3841
4568
  .enter().append('g')
@@ -3850,7 +4577,8 @@ class PlaChartBuilder extends PcacChart {
3850
4577
  this.dotClickedSource.next(d);
3851
4578
  });
3852
4579
  makeMarksAccessible(points, {
3853
- label: (d) => this.markLabel(d, { parent: series, valueFormat: this.yAxis.format, keyFormat: this.xAxis.format }),
4580
+ label: (d) => this.markLabel(d, { parent: series, valueFormat: this.yAxis.format, keyFormat: this.xAxis.format })
4581
+ + this.gaugeLabel(d),
3854
4582
  activate: (d) => this.dotClickedSource.next(d),
3855
4583
  focus: (point, d) => {
3856
4584
  this.enterPoint(point, d, series, index);
@@ -3893,8 +4621,31 @@ class PlaChartBuilder extends PcacChart {
3893
4621
  .transition()
3894
4622
  .duration(duration)
3895
4623
  .attr('y', (d) => -maxHeight / 2 + this.offsetOf(d).dy);
4624
+ // Gauge rings around the image box or the dot, rising in with the mark they surround.
4625
+ if (this.pointGauge) {
4626
+ const markRadius = (d) => d.image ? Math.max(maxWidth, maxHeight) / 2 : GAUGE_DOT_RADIUS;
4627
+ drawPointGauges(points, this.pointGauge, markRadius)
4628
+ .style('--pcac-point-gauge-series-color', () => this.colors[index])
4629
+ .attr('transform', (d) => `translate(${this.offsetOf(d).dx}, ${rise(d)})`)
4630
+ .transition()
4631
+ .duration(duration)
4632
+ // Tweened as a number rather than `.attr('transform', ...)`: d3's transform interpolation
4633
+ // parses through SVG DOM APIs (`transform.baseVal`) that not every environment has.
4634
+ .attrTween('transform', (d) => {
4635
+ const { dx, dy } = this.offsetOf(d);
4636
+ const from = rise(d);
4637
+ return (t) => `translate(${dx}, ${from + (dy - from) * t})`;
4638
+ });
4639
+ }
3896
4640
  }
3897
4641
  }
4642
+ /**
4643
+ * The end of a point's screen reader name for its gauge - ", PSA 0.018" - when `pointGauge` has a
4644
+ * `name` and the point a `gauge`; otherwise nothing, the ring being only visual.
4645
+ */
4646
+ gaugeLabel(d) {
4647
+ return this.pointGauge?.name && hasGauge(d) ? `, ${this.pointGauge.name} ${d.gauge}` : '';
4648
+ }
3898
4649
  /**
3899
4650
  * Starts a hover on a point - its tooltip, beside it; its range brought forward; its dot grown -
3900
4651
  * for the pointer and keyboard focus alike (see makeMarksAccessible). Ended by `leavePoint`.
@@ -4081,11 +4832,11 @@ class PcacLineAreaChartComponent {
4081
4832
  }
4082
4833
  }
4083
4834
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacLineAreaChartComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
4084
- 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 });
4835
+ 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 .reference-line-stroke{stroke:var(--pcac-reference-line-color, #adb5bd);stroke-width:1px;stroke-dasharray:4 4}.pcac-line-area-chart .reference-line-label{font-size:11px;fill:var(--pcac-reference-line-color, #adb5bd)}.pcac-line-area-chart .point-gauge-track{fill:none;stroke:var(--pcac-point-gauge-track-color, #e9ecef)}.pcac-line-area-chart .point-gauge-arc{fill:var(--pcac-point-gauge-color, var(--pcac-point-gauge-series-color))}.pcac-line-area-chart .corner-label{font-size:12px;font-weight:500;fill:var(--pcac-corner-label-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 });
4085
4836
  }
4086
4837
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacLineAreaChartComponent, decorators: [{
4087
4838
  type: Component,
4088
- 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"] }]
4839
+ 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 .reference-line-stroke{stroke:var(--pcac-reference-line-color, #adb5bd);stroke-width:1px;stroke-dasharray:4 4}.pcac-line-area-chart .reference-line-label{font-size:11px;fill:var(--pcac-reference-line-color, #adb5bd)}.pcac-line-area-chart .point-gauge-track{fill:none;stroke:var(--pcac-point-gauge-track-color, #e9ecef)}.pcac-line-area-chart .point-gauge-arc{fill:var(--pcac-point-gauge-color, var(--pcac-point-gauge-series-color))}.pcac-line-area-chart .corner-label{font-size:12px;font-weight:500;fill:var(--pcac-corner-label-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"] }]
4089
4840
  }], 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 }] }] } });
4090
4841
 
4091
4842
  class PcacPlotChart {
@@ -4156,8 +4907,304 @@ class PcacAreaChartConfig extends PcacLineAreaChartConfig {
4156
4907
  // export * from './plot-line-area-chart.model';
4157
4908
  // The rest of that model stays internal (the shared PcacLineAreaChartConfig is reached through
4158
4909
  // the per-chart PcacLineChartConfig/PcacAreaChartConfig/PcacPlotChartConfig subclasses), but
4159
- // the point-image and point-range types are part of those configs' public shape, so they're
4160
- // exported alone.
4910
+ // the point-image, point-range, point-gauge, reference-line and corner-label types are part of those configs'
4911
+ // public shape, so they're exported alone.
4912
+
4913
+ /**
4914
+ * A proximity chart: one item in the middle (`center`) and others (`data`) around it, each placed
4915
+ * closer in or further out by its `value` - how similar it is to the center, say, or how far from
4916
+ * it. It answers "what's nearest to this?" at a glance: the closest matches sit tight around the
4917
+ * center, weaker ones out on the rim.
4918
+ *
4919
+ * Each item in `data` is one point: `key` is its name (tooltip, screen readers), `value` its
4920
+ * closeness in whatever units the chart's `closeValue` / `farValue` use, and `image` optionally
4921
+ * drawn in place of its dot. Items go around the center clockwise from `startAngle` in data order,
4922
+ * evenly spaced, so put the closest first to have it at the top. An item whose `value` isn't a
4923
+ * number, or with `hide`, is left out. Best with a handful to a dozen or so items; past that they
4924
+ * crowd one another around the ring.
4925
+ */
4926
+ class PcacProximityChartConfig extends PcacChartConfig {
4927
+ /** The item the others are measured against, drawn in the middle. Its `value` isn't used. */
4928
+ center = new PcacData();
4929
+ /**
4930
+ * The `value` that sits right up against the center, and the one that sits on the outer rim;
4931
+ * values in between are placed proportionally, and anything beyond either is held at it.
4932
+ * The defaults suit a similarity from 0 to 1 (1 = identical, closest in). For a distance, swap
4933
+ * them: `closeValue: 0, farValue: <largest distance>`.
4934
+ */
4935
+ closeValue = 1;
4936
+ farValue = 0;
4937
+ /**
4938
+ * Values to draw a faint guide ring at, each labelled in `format` - e.g. `[0.95, 0.9, 0.85]` with
4939
+ * `Percentage` reads "95%", "90%", "85%". None when not set.
4940
+ */
4941
+ rings;
4942
+ /** How values read on the ring labels, in the tooltip and to screen readers; see `PcacFormatEnum`. */
4943
+ format;
4944
+ /**
4945
+ * Write each item's `key` under it, and the center's under the center. Default false: names are
4946
+ * in the tooltip either way. Keep it off for long names or a crowded ring.
4947
+ */
4948
+ showLabels = false;
4949
+ /** Draw a faint line from the center to each item. Default true. */
4950
+ showSpokes = true;
4951
+ /** Where the first item sits, in degrees clockwise from 12 o'clock. Default 0. */
4952
+ startAngle = 0;
4953
+ /** Size of the center item's image (or twice its dot's radius), in px. Default 64. */
4954
+ centerSize = 64;
4955
+ /** Size of each surrounding item's image (or twice its dot's radius), in px. Default 40. */
4956
+ itemSize = 40;
4957
+ /**
4958
+ * Item colors, any CSS color, used in data order for the dots of items without an `image` (the
4959
+ * center takes the first). Repeated when there are more items than colors. Omitted or empty, the
4960
+ * theme palette is used.
4961
+ */
4962
+ colorOverride;
4963
+ }
4964
+
4965
+ /** An item's value as a number, or `null` when it has none. */
4966
+ function proximityValue(d) {
4967
+ const value = typeof d.value === 'number' ? d.value : typeof d.value === 'string' && d.value.trim() !== '' ? Number(d.value) : NaN;
4968
+ return Number.isFinite(value) ? value : null;
4969
+ }
4970
+ /**
4971
+ * Where a value sits between the center and the rim: 0 at `closeValue`, 1 at `farValue`, in
4972
+ * proportion between them and held at either end beyond them. Equal ends put everything at 0.
4973
+ */
4974
+ function proximityDistance(value, closeValue, farValue) {
4975
+ if (closeValue === farValue) {
4976
+ return 0;
4977
+ }
4978
+ return Math.min(1, Math.max(0, (value - closeValue) / (farValue - closeValue)));
4979
+ }
4980
+ /**
4981
+ * Places every drawable item evenly around the center, clockwise from `startAngle` (degrees from
4982
+ * 12 o'clock) in data order, each at its value's distance. Hidden items and items without a
4983
+ * numeric value are left out, and don't take up a slot.
4984
+ */
4985
+ function placeProximity(data, closeValue, farValue, startAngle = 0) {
4986
+ const drawable = data
4987
+ .map((d, index) => ({ d, index, value: proximityValue(d) }))
4988
+ .filter((item) => !item.d.hide && item.value !== null);
4989
+ const start = (startAngle * Math.PI) / 180;
4990
+ return drawable.map(({ d, index, value }, slot) => ({
4991
+ data: d,
4992
+ index,
4993
+ value,
4994
+ angle: start + (slot / drawable.length) * 2 * Math.PI,
4995
+ distance: proximityDistance(value, closeValue, farValue),
4996
+ }));
4997
+ }
4998
+
4999
+ /** Space kept between the center's mark and the nearest an item can sit, in px. */
5000
+ const CENTER_GAP = 6;
5001
+ /** Room kept outside the rim for a ring label, in px. */
5002
+ const RIM_LABEL_ROOM = 4;
5003
+ /** Room a name takes below its item with `showLabels` - the gap and one line of 11px text - in px. */
5004
+ const ITEM_LABEL_ROOM = 16;
5005
+ /**
5006
+ * Provided per-component (see PcacProximityChart's `providers`), like every builder that extends
5007
+ * PcacChart: it holds per-chart-instance state, which a root singleton would share between charts.
5008
+ */
5009
+ class ProximityChartBuilder extends PcacChart {
5010
+ itemClickedSource = new Subject();
5011
+ itemClicked$ = this.itemClickedSource.asObservable();
5012
+ chartTypeLabel = 'Proximity chart';
5013
+ buildChart(chartElm, config) {
5014
+ this.hideTooltip();
5015
+ if (!config?.center && !config?.data?.length) {
5016
+ this.clearChart(chartElm);
5017
+ return;
5018
+ }
5019
+ // No axes, so an even margin all round rather than the axis charts' defaults.
5020
+ this.margin = { top: 8, right: 8, bottom: 8, left: 8 };
5021
+ if (!this.initializeChartState(chartElm, config)) {
5022
+ return;
5023
+ }
5024
+ const defaults = new PcacProximityChartConfig();
5025
+ const closeValue = config.closeValue ?? defaults.closeValue;
5026
+ const farValue = config.farValue ?? defaults.farValue;
5027
+ const centerSize = config.centerSize ?? defaults.centerSize;
5028
+ const itemSize = config.itemSize ?? defaults.itemSize;
5029
+ const placements = placeProximity(config.data ?? [], closeValue, farValue, config.startAngle ?? defaults.startAngle);
5030
+ this.ensureColorCount(placements.length + 1);
5031
+ this.applyColorOverride(config.colorOverride);
5032
+ // Items run from just outside the center's mark to the rim, their own half-size kept inside it -
5033
+ // and, with names under them, the name of an item at the bottom of the rim too.
5034
+ const inner = centerSize / 2 + CENTER_GAP + itemSize / 2;
5035
+ const edgeRoom = itemSize / 2 + (config.showLabels ? ITEM_LABEL_ROOM : RIM_LABEL_ROOM);
5036
+ const outer = Math.max(inner, Math.min(this.width, this.height) / 2 - edgeRoom);
5037
+ const radiusOf = (distance) => inner + distance * (outer - inner);
5038
+ this.buildContainer(chartElm, true);
5039
+ // Ring labels go halfway between the first two items, where no item sits to cover them.
5040
+ const labelAngle = (((config.startAngle ?? defaults.startAngle) * Math.PI) / 180) + Math.PI / Math.max(1, placements.length);
5041
+ this.drawRings(config, closeValue, farValue, radiusOf, labelAngle);
5042
+ const marks = placements.map((p) => {
5043
+ const r = radiusOf(p.distance);
5044
+ return {
5045
+ data: p.data,
5046
+ placement: p,
5047
+ x: r * Math.sin(p.angle),
5048
+ y: -r * Math.cos(p.angle),
5049
+ size: itemSize,
5050
+ color: this.colors[(p.index + 1) % this.colors.length],
5051
+ };
5052
+ });
5053
+ if (config.showSpokes ?? defaults.showSpokes) {
5054
+ this.svg.append('g')
5055
+ .attr('class', 'pcac-proximity-spokes')
5056
+ .attr('aria-hidden', 'true')
5057
+ .selectAll('line')
5058
+ .data(marks)
5059
+ .enter().append('line')
5060
+ .attr('class', 'pcac-proximity-spoke')
5061
+ .attr('x1', 0).attr('y1', 0)
5062
+ .attr('x2', (m) => m.x).attr('y2', (m) => m.y);
5063
+ }
5064
+ const center = config.center
5065
+ ? { data: config.center, placement: null, x: 0, y: 0, size: centerSize, color: this.colors[0] }
5066
+ : null;
5067
+ this.drawMarks(center ? [...marks, center] : marks, config);
5068
+ this.restoreTabStop(chartElm);
5069
+ }
5070
+ /** Faint guide rings at `config.rings`' values, each labelled at `labelAngle` in `config.format`. */
5071
+ drawRings(config, closeValue, farValue, radiusOf, labelAngle) {
5072
+ const rings = (config.rings ?? []).filter((v) => Number.isFinite(v));
5073
+ if (!rings.length) {
5074
+ return;
5075
+ }
5076
+ const groups = this.svg.append('g')
5077
+ .attr('class', 'pcac-proximity-rings')
5078
+ .attr('aria-hidden', 'true')
5079
+ .selectAll('g')
5080
+ .data(rings)
5081
+ .enter().append('g')
5082
+ .attr('class', 'pcac-proximity-ring');
5083
+ const r = (v) => radiusOf(proximityDistance(v, closeValue, farValue));
5084
+ groups.append('circle').attr('r', r).attr('fill', 'none');
5085
+ groups.append('text')
5086
+ .attr('class', 'pcac-proximity-ring-label')
5087
+ .attr('x', (v) => r(v) * Math.sin(labelAngle))
5088
+ .attr('y', (v) => -r(v) * Math.cos(labelAngle))
5089
+ .attr('text-anchor', 'middle')
5090
+ .attr('dominant-baseline', 'middle')
5091
+ .text((v) => formatValue(config.format, v) ?? String(v));
5092
+ }
5093
+ drawMarks(marks, config) {
5094
+ const self = this;
5095
+ const duration = this.transitionService.getTransitionDuration();
5096
+ const tooltipOptions = (m, anchor) => ({
5097
+ index: m.placement?.index ?? -1,
5098
+ parent: null,
5099
+ valueFormat: config.format,
5100
+ anchor,
5101
+ });
5102
+ const markOf = (group) => select(group).select('.pcac-proximity-dot, .pcac-proximity-image').node();
5103
+ const highlight = (group, on) => select(group).classed('is-active', on);
5104
+ const groups = this.svg.append('g')
5105
+ .attr('class', 'pcac-proximity-items')
5106
+ .selectAll('g')
5107
+ .data(marks)
5108
+ .enter().append('g')
5109
+ .attr('class', (m) => m.placement ? 'pcac-proximity-item' : 'pcac-proximity-item pcac-proximity-center')
5110
+ .attr('transform', (m) => `translate(${m.x}, ${m.y})`)
5111
+ .on('mouseover', function (event, m) {
5112
+ highlight(this, true);
5113
+ self.showTooltip(event, m.data, tooltipOptions(m, markOf(this)));
5114
+ })
5115
+ .on('mouseout', function () {
5116
+ highlight(this, false);
5117
+ self.hideTooltip();
5118
+ })
5119
+ .on('click', (_event, m) => this.itemClickedSource.next(m.data));
5120
+ makeMarksAccessible(groups, {
5121
+ label: (m) => m.placement
5122
+ ? this.markLabel(m.data, { valueFormat: config.format })
5123
+ : `${m.data.key ?? ''}, in the center`,
5124
+ activate: (m) => this.itemClickedSource.next(m.data),
5125
+ focus: (group, m) => {
5126
+ highlight(group, true);
5127
+ this.showMarkTooltip(group, m.data, tooltipOptions(m, markOf(group)));
5128
+ },
5129
+ blur: (group) => {
5130
+ highlight(group, false);
5131
+ this.hideMarkTooltip(group);
5132
+ },
5133
+ });
5134
+ groups.filter((m) => !m.data.image)
5135
+ .append('circle')
5136
+ .attr('class', 'pcac-proximity-dot')
5137
+ .attr('r', (m) => m.size / 2)
5138
+ .attr('fill', (m) => m.color)
5139
+ // What the theme's hover ring (`stroke: currentColor`) takes: the dot's own color.
5140
+ .style('color', (m) => m.color);
5141
+ groups.filter((m) => !!m.data.image)
5142
+ .append('image')
5143
+ .attr('class', 'pcac-proximity-image')
5144
+ .attr('href', (m) => m.data.image)
5145
+ .attr('width', (m) => m.size)
5146
+ .attr('height', (m) => m.size)
5147
+ .attr('x', (m) => -m.size / 2)
5148
+ .attr('y', (m) => -m.size / 2)
5149
+ .attr('preserveAspectRatio', 'xMidYMid meet');
5150
+ if (config.showLabels) {
5151
+ groups.append('text')
5152
+ .attr('class', 'pcac-proximity-label')
5153
+ .attr('aria-hidden', 'true')
5154
+ .attr('y', (m) => m.size / 2 + 12)
5155
+ .attr('text-anchor', 'middle')
5156
+ .text((m) => String(m.data.key ?? ''));
5157
+ }
5158
+ // The items fade in from the center outward, closest first.
5159
+ groups.attr('opacity', 0)
5160
+ .transition()
5161
+ .delay((m) => (m.placement ? m.placement.distance * duration / 2 : 0))
5162
+ .duration(duration / 2)
5163
+ .attr('opacity', 1);
5164
+ }
5165
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: ProximityChartBuilder, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
5166
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: ProximityChartBuilder });
5167
+ }
5168
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: ProximityChartBuilder, decorators: [{
5169
+ type: Injectable
5170
+ }] });
5171
+
5172
+ /** A proximity chart: an item in the middle, others around it by closeness (see PcacProximityChartConfig). */
5173
+ class PcacProximityChart {
5174
+ chartBuilder = inject(ProximityChartBuilder);
5175
+ config = input.required(/* @ts-ignore */
5176
+ ...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
5177
+ chartElm = viewChild.required('chart', /* @ts-ignore */
5178
+ ...(ngDevMode ? [{ debugName: "chartElm" }] : /* istanbul ignore next */ []));
5179
+ /** An item - or the center - was clicked, or activated with Enter or Space. */
5180
+ itemClicked = outputFromObservable(this.chartBuilder.itemClicked$);
5181
+ /** Optional consumer `<ng-template pcacTooltip>`, replacing the default tooltip (see PcacTooltipDirective). */
5182
+ tooltipTemplate = contentChild(PcacTooltipDirective, /* @ts-ignore */
5183
+ ...(ngDevMode ? [{ debugName: "tooltipTemplate" }] : /* istanbul ignore next */ []));
5184
+ constructor() {
5185
+ effect(() => this.buildChart());
5186
+ // A getter, so the builder reads the query at hover time rather than in the effect above.
5187
+ this.chartBuilder.tooltipTemplate = () => this.tooltipTemplate()?.templateRef;
5188
+ inject(PcacChartResizeService).observe(this.chartElm, () => {
5189
+ if (this.chartBuilder.containerSizeChanged(this.chartElm())) {
5190
+ this.buildChart();
5191
+ }
5192
+ });
5193
+ }
5194
+ buildChart() {
5195
+ const config = this.config();
5196
+ // Handed over even when empty: the builder clears what it last drew rather than leaving it.
5197
+ if (config) {
5198
+ this.chartBuilder.buildChart(this.chartElm(), config);
5199
+ }
5200
+ }
5201
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacProximityChart, deps: [], target: i0.ɵɵFactoryTarget.Component });
5202
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.2.0", type: PcacProximityChart, isStandalone: true, selector: "pcac-proximity-chart", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { itemClicked: "itemClicked" }, host: { properties: { "class.pcac-height-full": "config().heightFull" } }, providers: [ProximityChartBuilder], 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-proximity-chart\">\n <svg #chart></svg>\n</section>\n", styles: [".pcac-proximity-chart svg{width:100%;display:block}.pcac-proximity-chart .pcac-proximity-ring circle{stroke:var(--pcac-proximity-ring-color, #dee2e6);stroke-dasharray:3 4}.pcac-proximity-chart .pcac-proximity-ring-label{font-size:11px;fill:var(--pcac-proximity-ring-label-color, #6c757d)}.pcac-proximity-chart .pcac-proximity-spoke{stroke:var(--pcac-proximity-spoke-color, #dee2e6);stroke-width:1px}.pcac-proximity-chart .pcac-proximity-item{cursor:pointer}.pcac-proximity-chart .pcac-proximity-label,.pcac-proximity-chart .pcac-proximity-ring-label{paint-order:stroke;stroke:var(--pcac-proximity-label-halo-color, #fff);stroke-width:3px;stroke-linejoin:round}.pcac-proximity-chart .pcac-proximity-label{font-size:11px;fill:var(--pcac-proximity-label-color, #343a40)}.pcac-proximity-chart .pcac-proximity-center .pcac-proximity-label{font-weight:600}.pcac-proximity-chart .pcac-proximity-item.is-active .pcac-proximity-dot{stroke:currentColor;stroke-width:2px}.pcac-proximity-chart .pcac-proximity-item.is-active .pcac-proximity-image{filter:drop-shadow(0 0 3px rgba(0,0,0,.35))}pcac-proximity-chart.pcac-height-full{display:block;height:100%}pcac-proximity-chart.pcac-height-full .pcac-proximity-chart{height:100%}\n"], encapsulation: i0.ViewEncapsulation.None });
5203
+ }
5204
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacProximityChart, decorators: [{
5205
+ type: Component,
5206
+ args: [{ selector: 'pcac-proximity-chart', host: { '[class.pcac-height-full]': 'config().heightFull' }, encapsulation: ViewEncapsulation.None, providers: [ProximityChartBuilder], template: "<section class=\"pcac-proximity-chart\">\n <svg #chart></svg>\n</section>\n", styles: [".pcac-proximity-chart svg{width:100%;display:block}.pcac-proximity-chart .pcac-proximity-ring circle{stroke:var(--pcac-proximity-ring-color, #dee2e6);stroke-dasharray:3 4}.pcac-proximity-chart .pcac-proximity-ring-label{font-size:11px;fill:var(--pcac-proximity-ring-label-color, #6c757d)}.pcac-proximity-chart .pcac-proximity-spoke{stroke:var(--pcac-proximity-spoke-color, #dee2e6);stroke-width:1px}.pcac-proximity-chart .pcac-proximity-item{cursor:pointer}.pcac-proximity-chart .pcac-proximity-label,.pcac-proximity-chart .pcac-proximity-ring-label{paint-order:stroke;stroke:var(--pcac-proximity-label-halo-color, #fff);stroke-width:3px;stroke-linejoin:round}.pcac-proximity-chart .pcac-proximity-label{font-size:11px;fill:var(--pcac-proximity-label-color, #343a40)}.pcac-proximity-chart .pcac-proximity-center .pcac-proximity-label{font-weight:600}.pcac-proximity-chart .pcac-proximity-item.is-active .pcac-proximity-dot{stroke:currentColor;stroke-width:2px}.pcac-proximity-chart .pcac-proximity-item.is-active .pcac-proximity-image{filter:drop-shadow(0 0 3px rgba(0,0,0,.35))}pcac-proximity-chart.pcac-height-full{display:block;height:100%}pcac-proximity-chart.pcac-height-full .pcac-proximity-chart{height:100%}\n"] }]
5207
+ }], ctorParameters: () => [], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }], chartElm: [{ type: i0.ViewChild, args: ['chart', { isSignal: true }] }], itemClicked: [{ type: i0.Output, args: ["itemClicked"] }], tooltipTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => PcacTooltipDirective), { isSignal: true }] }] } });
4161
5208
 
4162
5209
  /** Which chart the shared `<pcac-pie-donut-chart>` draws; each wrapper binds its own. */
4163
5210
  var PcacPieDonutChartType;
@@ -4363,7 +5410,7 @@ class PieDonutChartBuilder extends PcacChart {
4363
5410
  rest(slice, d);
4364
5411
  },
4365
5412
  });
4366
- refreshTabStop(chartElm.nativeElement);
5413
+ this.restoreTabStop(chartElm);
4367
5414
  slices
4368
5415
  // Named, so the hover transitions (unnamed) and the check above can tell it apart from them.
4369
5416
  .transition('enter')
@@ -4549,5 +5596,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImpor
4549
5596
  * Generated bundle index. Do not edit.
4550
5597
  */
4551
5598
 
4552
- export { PcacAreaChart, PcacAreaChartConfig, PcacAxisChartConfig, PcacAxisConfig, PcacAxisSubLabels, PcacBarHorizontalChartComponent, PcacBarHorizontalChartConfig, PcacBarVerticalChartComponent, PcacBarVerticalChartConfig, PcacChartConfig, PcacColorService, PcacData, PcacDataRange, PcacDonutChart, PcacDonutChartConfig, PcacFormatEnum, PcacLegend, PcacLegendConfig, PcacLegendConfigItem, PcacLineChart, PcacLineChartConfig, PcacPieChart, PcacPieChartConfig, PcacPlotChart, PcacPlotChartConfig, PcacPointFanOutConfig, PcacPointImageConfig, PcacPointRangeConfig, PcacPointRangeShow, PcacPointRangeStyle, PcacRangeBounds, PcacTooltipDirective };
5599
+ export { PcacAreaChart, PcacAreaChartConfig, PcacAxisChartConfig, PcacAxisConfig, PcacAxisSubLabels, PcacBarHorizontalChart, PcacBarHorizontalChart as PcacBarHorizontalChartComponent, PcacBarHorizontalChartConfig, PcacBarVerticalChart, PcacBarVerticalChart as PcacBarVerticalChartComponent, PcacBarVerticalChartConfig, PcacChartConfig, PcacColorService, PcacCornerLabels, PcacData, PcacDataRange, PcacDonutChart, PcacDonutChartConfig, PcacDotPlotChart, PcacDotPlotChartConfig, PcacFormatEnum, PcacLegend, PcacLegendConfig, PcacLegendConfigItem, PcacLineChart, PcacLineChartConfig, PcacPieChart, PcacPieChartConfig, PcacPlotChart, PcacPlotChartConfig, PcacPointFanOutConfig, PcacPointGaugeConfig, PcacPointImageConfig, PcacPointRangeConfig, PcacPointRangeShow, PcacPointRangeStyle, PcacProximityChart, PcacProximityChartConfig, PcacRangeBounds, PcacReferenceLine, PcacTooltipDirective };
4553
5600
  //# sourceMappingURL=pioneer-code-pioneer-charts.mjs.map