@pioneer-code/pioneer-charts 22.2.18 → 22.2.20

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';
@@ -245,6 +245,27 @@ class PcacData {
245
245
  * Optional for the same reason as `image`.
246
246
  */
247
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;
259
+ /**
260
+ * The consumer's own identifier for this item - a record's primary key, say. Nothing draws or
261
+ * labels it; it's carried through untouched so a click output (`dotClicked`, `barClicked`,
262
+ * `sliceClicked`, `itemClicked`) can be traced back to the record it came from. Click outputs
263
+ * emit a copy of the item (the chart works on a copy of its config), so matching by object
264
+ * identity doesn't work, and matching by `key` or `image` breaks as soon as two items share one.
265
+ *
266
+ * Optional for the same reason as `image`.
267
+ */
268
+ id;
248
269
  }
249
270
  /**
250
271
  * One side of a `PcacDataRange`. `min` above `max` is read as the other way round; `min` equal to
@@ -2667,40 +2688,6 @@ class PcacBarVerticalChartConfig extends PcacAxisChartConfig {
2667
2688
  // base class and the builders, the axis/grid/tooltip/transition/resize services, and the
2668
2689
  // resolved-config helpers - is internal, so it can change without breaking anyone.
2669
2690
 
2670
- class PcacLegendConfigItem {
2671
- label;
2672
- checked = true;
2673
- colorOverride = null;
2674
- }
2675
- class PcacLegendConfig {
2676
- heading = null;
2677
- items = [];
2678
- }
2679
- let nextLegendId = 0;
2680
- class PcacLegend {
2681
- headingId = `pcac-legend-heading-${nextLegendId++}`;
2682
- colorService = inject(PcacColorService);
2683
- config = model.required(/* @ts-ignore */
2684
- ...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
2685
- itemClicked = output();
2686
- colorScale = computed(() => this.colorService.getColorScale(this.config().items.length), /* @ts-ignore */
2687
- ...(ngDevMode ? [{ debugName: "colorScale" }] : /* istanbul ignore next */ []));
2688
- onItemClicked(index) {
2689
- const items = this.config().items.map((item, i) => i === index ? { ...item, checked: !item.checked } : item);
2690
- this.config.set({ ...this.config(), items });
2691
- this.itemClicked.emit(items);
2692
- }
2693
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacLegend, deps: [], target: i0.ɵɵFactoryTarget.Component });
2694
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.2.0", type: PcacLegend, isStandalone: true, selector: "pcac-legend", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { config: "configChange", itemClicked: "itemClicked" }, host: { attributes: { "role": "group" }, properties: { "attr.aria-labelledby": "config().heading ? headingId : null" } }, ngImport: i0, template: "@if (config().heading) {\n<div class=\"pcac-legend-label\" [id]=\"headingId\"><small>{{config().heading}}</small></div>\n}\n@for(item of config().items; track $index; let i = $index) {\n<div class=\"pcac-legend-item\" [class.pcac-legend-unchecked]=\"!item.checked\"\n role=\"switch\" [attr.aria-checked]=\"item.checked\" tabindex=\"0\" (click)=\"onItemClicked(i)\"\n (keydown.enter)=\"onItemClicked(i)\" (keydown.space)=\"onItemClicked(i); $event.preventDefault()\">\n @let color = item.colorOverride ? item.colorOverride : colorScale()[i];\n <div class=\"pcac-legend-circle\" [style.backgroundColor]=\"color\"></div>\n <small>{{ item.label }}</small>\n</div>\n}\n", styles: [":host{display:flex;align-items:center;flex-wrap:wrap;column-gap:8px}.pcac-legend-label{margin-bottom:2.5px}.pcac-legend-item{cursor:pointer;display:flex;align-items:center;min-height:24px}.pcac-legend-item:hover .pcac-legend-circle{box-shadow:0 0 6px #0000004d;transform:scale(1.2)}.pcac-legend-circle{display:inline-block;width:12px;height:12px;border-radius:50%;margin-right:4px;transition:box-shadow .3s ease,transform .3s ease}@media(prefers-reduced-motion:reduce){.pcac-legend-circle{transition:none}}.pcac-legend-unchecked{opacity:.5}.pcac-legend-item:focus-visible{outline:2px solid currentColor;outline-offset:2px}\n"] });
2695
- }
2696
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacLegend, decorators: [{
2697
- type: Component,
2698
- args: [{ selector: 'pcac-legend', host: {
2699
- role: 'group',
2700
- '[attr.aria-labelledby]': 'config().heading ? headingId : null',
2701
- }, template: "@if (config().heading) {\n<div class=\"pcac-legend-label\" [id]=\"headingId\"><small>{{config().heading}}</small></div>\n}\n@for(item of config().items; track $index; let i = $index) {\n<div class=\"pcac-legend-item\" [class.pcac-legend-unchecked]=\"!item.checked\"\n role=\"switch\" [attr.aria-checked]=\"item.checked\" tabindex=\"0\" (click)=\"onItemClicked(i)\"\n (keydown.enter)=\"onItemClicked(i)\" (keydown.space)=\"onItemClicked(i); $event.preventDefault()\">\n @let color = item.colorOverride ? item.colorOverride : colorScale()[i];\n <div class=\"pcac-legend-circle\" [style.backgroundColor]=\"color\"></div>\n <small>{{ item.label }}</small>\n</div>\n}\n", styles: [":host{display:flex;align-items:center;flex-wrap:wrap;column-gap:8px}.pcac-legend-label{margin-bottom:2.5px}.pcac-legend-item{cursor:pointer;display:flex;align-items:center;min-height:24px}.pcac-legend-item:hover .pcac-legend-circle{box-shadow:0 0 6px #0000004d;transform:scale(1.2)}.pcac-legend-circle{display:inline-block;width:12px;height:12px;border-radius:50%;margin-right:4px;transition:box-shadow .3s ease,transform .3s ease}@media(prefers-reduced-motion:reduce){.pcac-legend-circle{transition:none}}.pcac-legend-unchecked{opacity:.5}.pcac-legend-item:focus-visible{outline:2px solid currentColor;outline-offset:2px}\n"] }]
2702
- }], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }, { type: i0.Output, args: ["configChange"] }], itemClicked: [{ type: i0.Output, args: ["itemClicked"] }] } });
2703
-
2704
2691
  var PcacLineAreaPlotChartConfigType;
2705
2692
  (function (PcacLineAreaPlotChartConfigType) {
2706
2693
  PcacLineAreaPlotChartConfigType["Line"] = "line";
@@ -2757,6 +2744,80 @@ class PcacPointRangeConfig {
2757
2744
  */
2758
2745
  color;
2759
2746
  }
2747
+ /**
2748
+ * Drawing for `PcacData.gauge` on the line/area/plot charts: a ring around each point's mark (its
2749
+ * dot, or its image) whose arc fills clockwise from 12 o'clock in proportion to `gauge / max`,
2750
+ * over a faint full-circle track. Drawn with the mark, so it moves with zoom and fan-out; fan-out
2751
+ * spacing and the chart's edge space grow to fit it. Points without a `gauge` get no ring.
2752
+ */
2753
+ class PcacPointGaugeConfig {
2754
+ /** The `gauge` value of a full ring. Default 1, for values that are already a fraction. */
2755
+ max = 1;
2756
+ /** Ring thickness in px. */
2757
+ width = 2.5;
2758
+ /** Space between the mark (the image box, or a hovered dot) and the ring, in px. */
2759
+ gap = 3;
2760
+ /** Draw the unfilled rest of the ring, so an arc reads as a share of a whole. */
2761
+ showTrack = true;
2762
+ /**
2763
+ * What the gauge measures, e.g. `'PSA'`. When set, each point's screen reader name ends with it
2764
+ * and the point's value - "…, PSA 0.018" - since the ring itself is only visual. Unset, the
2765
+ * ring isn't read at all; say what it means in the chart's `ariaLabel`, or a custom tooltip.
2766
+ */
2767
+ name;
2768
+ /**
2769
+ * Any CSS color for the filled arc. Unset, each takes its series' color. Applied as
2770
+ * `--pcac-point-gauge-color` on the chart's `.dots` groups, so a stylesheet can set it on an
2771
+ * ancestor instead (a config value wins).
2772
+ */
2773
+ color;
2774
+ /** Any CSS color for the track (`--pcac-point-gauge-track-color`). Theme default `$gray-200`. */
2775
+ trackColor;
2776
+ }
2777
+ /**
2778
+ * A line across the plot at one value on an axis (see `PcacLineAreaChartConfig.referenceLines`):
2779
+ * a target, a threshold, a median. Drawn dashed, over the grid and under the series, clipped to
2780
+ * the plot area, and moved with zoom like the data.
2781
+ */
2782
+ class PcacReferenceLine {
2783
+ /** Which axis `value` is on: `'y'` draws a horizontal line, `'x'` a vertical one. */
2784
+ axis = 'y';
2785
+ /**
2786
+ * Where the line sits, in the axis's own terms: a number on the y axis; on the x axis, whatever
2787
+ * a point's `key` would be under `xAxis.format` - a number for `Decimal`, a date (or anything
2788
+ * `new Date()` reads) for `DateTime`, a series index otherwise.
2789
+ */
2790
+ value = 0;
2791
+ /**
2792
+ * A few words drawn at the line's far end, inside the plot: above the right end of a horizontal
2793
+ * line, beside the top of a vertical one. Styled by the theme's `.reference-line-label` rule.
2794
+ */
2795
+ label;
2796
+ /**
2797
+ * Any CSS color for the line and its label. Theme default `$gray-500`. Applied as
2798
+ * `--pcac-reference-line-color` on the line's group, so a stylesheet can set it on an ancestor
2799
+ * instead (a config value wins).
2800
+ */
2801
+ color;
2802
+ }
2803
+ /**
2804
+ * Text pinned to the plot area's corners (see `PcacLineAreaChartConfig.cornerLabels`) - names for
2805
+ * the regions the plot divides into, such as the quadrants between two reference lines. Pinned to
2806
+ * the plot's frame rather than to data, so they stay put when the chart is zoomed. Drawn under the
2807
+ * series, so a point in the corner covers its label rather than the other way round. Any corner
2808
+ * left unset is left empty.
2809
+ */
2810
+ class PcacCornerLabels {
2811
+ topLeft;
2812
+ topRight;
2813
+ bottomLeft;
2814
+ bottomRight;
2815
+ /**
2816
+ * Any CSS color for all four. Theme default `$gray-600`. Applied as `--pcac-corner-label-color`
2817
+ * on their group, so a stylesheet can set it on an ancestor instead (a config value wins).
2818
+ */
2819
+ color;
2820
+ }
2760
2821
  /**
2761
2822
  * The axes' `format` and `domainMin`/`domainMax` (`PcacAxisConfig`) do more here than on the bar
2762
2823
  * charts. `yAxis.domainMin`/`domainMax` are the y scale's domain (default 0..100). `xAxis.format`
@@ -2794,7 +2855,350 @@ class PcacLineAreaChartConfig extends PcacAxisChartConfig {
2794
2855
  * every `PcacPointRangeConfig` default. Points without a `range` draw nothing extra.
2795
2856
  */
2796
2857
  pointRange;
2858
+ /**
2859
+ * Dashed lines at chosen values on either axis (see `PcacReferenceLine`). None when not set.
2860
+ * They are decoration for sighted readers - hidden from screen readers like the grid - so when
2861
+ * one carries meaning, say so in the chart's `ariaLabel`.
2862
+ */
2863
+ referenceLines;
2864
+ /**
2865
+ * Draw each point's `gauge` as a ring around its mark (see `PcacData.gauge`). Off when not set;
2866
+ * `{}` turns it on with every `PcacPointGaugeConfig` default. Points without a `gauge` draw
2867
+ * nothing extra.
2868
+ */
2869
+ pointGauge;
2870
+ /**
2871
+ * Labels in the plot's four corners (see `PcacCornerLabels`). None when not set. Hidden from
2872
+ * screen readers like the grid, so when they carry meaning, say so in the chart's `ariaLabel`.
2873
+ */
2874
+ cornerLabels;
2875
+ }
2876
+
2877
+ /**
2878
+ * A dot plot: every point placed along one value axis (x), and points that share a value - or,
2879
+ * with `binWidth`, fall in the same bin - stacked into a column above it, one mark per point. It
2880
+ * shows how values are distributed while keeping every item visible and hoverable, which suits
2881
+ * items with their own identity (and their own `image`) better than a histogram's bars.
2882
+ *
2883
+ * `data` is series, each holding its points - the same shape as the plot chart - so points can be
2884
+ * colored by group. A point's `value` is its position on the axis and its `key` its name (in the
2885
+ * tooltip and to screen readers). A point whose `value` isn't a number is left out, as is a series
2886
+ * or point with `hide`.
2887
+ *
2888
+ * The axes: `xAxis` is the value axis - `domainMin` / `domainMax` fix its span (by default it
2889
+ * spans the data, rounded out to nice ticks), `format` formats its ticks and the tooltip's value,
2890
+ * and every label, sub label, tick and grid setting applies. There is no y scale - a column's
2891
+ * height is a count of marks, not a value - so the y axis is never drawn; `yAxis` is ignored.
2892
+ */
2893
+ class PcacDotPlotChartConfig extends PcacAxisChartConfig {
2894
+ /**
2895
+ * Group values into bins this wide, in the axis's units, and stack each bin at its center: with
2896
+ * values 7, 7.5 and 8 and a `binWidth` of 1, the 7 and 7.5 share a column. Unset (the default),
2897
+ * only equal values stack. Bins start at `xAxis.domainMin`, or 0 without one.
2898
+ */
2899
+ binWidth;
2900
+ /**
2901
+ * Radius of a point's dot, in px; default 6. Points with an `image` are sized by `pointImage`
2902
+ * instead. Optional, as `colorOverride` is on every chart, so an object literal needn't spell it out.
2903
+ */
2904
+ dotRadius = 6;
2905
+ /** Space between marks stacked in a column, in px; default 2. Optional, likewise. */
2906
+ gap = 2;
2907
+ /**
2908
+ * Bounding box for points' images (`PcacData.image`), drawn in place of their dots, as on the
2909
+ * plot chart. Each field falls back to its `PcacPointImageConfig` default.
2910
+ *
2911
+ * A column too tall for the chart's height shrinks every mark on the chart evenly until it fits,
2912
+ * so no point is ever cut off; give the chart more `height` to keep marks at full size.
2913
+ */
2914
+ pointImage;
2915
+ /**
2916
+ * Series colors, any CSS color, in place of the theme palette, one per series in order. Repeats
2917
+ * when there are more series than colors. Omitted or empty, the theme palette is used.
2918
+ */
2919
+ colorOverride;
2920
+ }
2921
+
2922
+ /** A point's value as a number to place it by, or `null` when it has none. */
2923
+ function dotValue(d) {
2924
+ const value = typeof d.value === 'number' ? d.value : typeof d.value === 'string' && d.value.trim() !== '' ? Number(d.value) : NaN;
2925
+ return Number.isFinite(value) ? value : null;
2926
+ }
2927
+ /**
2928
+ * Stacks every drawable point into columns: points with an equal value share a column or, with a
2929
+ * positive `binWidth`, points in the same bin (bins run from `origin`, each `binWidth` wide) share
2930
+ * one at the bin's center. Within a column, points take levels in data order - series order, then
2931
+ * each series' own order - so the first is at the bottom. Hidden series and points, and points
2932
+ * with no numeric value, are left out.
2933
+ */
2934
+ function stackDots(series, binWidth, origin = 0) {
2935
+ const binned = !!binWidth && binWidth > 0;
2936
+ const levels = new Map();
2937
+ const placements = [];
2938
+ series.forEach((s, seriesIndex) => {
2939
+ if (s.hide) {
2940
+ return;
2941
+ }
2942
+ (s.data ?? []).forEach((d, index) => {
2943
+ const value = dotValue(d);
2944
+ if (d.hide || value === null) {
2945
+ return;
2946
+ }
2947
+ const position = binned
2948
+ ? origin + (Math.floor((value - origin) / binWidth) + 0.5) * binWidth
2949
+ : value;
2950
+ const level = levels.get(position) ?? 0;
2951
+ levels.set(position, level + 1);
2952
+ placements.push({ data: d, series: s, seriesIndex, index, position, level });
2953
+ });
2954
+ });
2955
+ return placements;
2956
+ }
2957
+ /** How many marks the tallest column holds; 0 with none. */
2958
+ function tallestColumn(placements) {
2959
+ return placements.reduce((tallest, p) => Math.max(tallest, p.level + 1), 0);
2960
+ }
2961
+
2962
+ /** How much a hovered dot grows, in px of radius - also room kept for it at the plot's edges. */
2963
+ const DOT_HOVER_GROWTH = 2;
2964
+ /**
2965
+ * Provided per-component (see PcacDotPlotChart's `providers`), like every builder that extends
2966
+ * PcacChart: it holds per-chart-instance state, which a root singleton would share between charts.
2967
+ */
2968
+ class DotPlotChartBuilder extends PcacChart {
2969
+ dotClickedSource = new Subject();
2970
+ dotClicked$ = this.dotClickedSource.asObservable();
2971
+ chartTypeLabel = 'Dot plot';
2972
+ xScale;
2973
+ placements = [];
2974
+ pointImage;
2975
+ /** A mark's size and the gap between stacked marks this build, after any shrinking to fit. */
2976
+ markSize = 0;
2977
+ markGap = 0;
2978
+ dotRadius = 0;
2979
+ buildChart(chartElm, config) {
2980
+ if (!config?.data?.length) {
2981
+ this.hideTooltip();
2982
+ this.clearChart(chartElm);
2983
+ return;
2984
+ }
2985
+ this.hideTooltip();
2986
+ // A column's height is a count of marks, not a value, so there's no y axis to draw. Shallow
2987
+ // copies: initializeAxisState() rewrites `height`, which mustn't reach the consumer's object.
2988
+ const rawXAxis = config.xAxis;
2989
+ config = { ...config, yAxis: { ...config.yAxis, hide: true } };
2990
+ this.initializeAxisState(config, 'x', 0);
2991
+ const defaults = new PcacDotPlotChartConfig();
2992
+ const dotRadius = config.dotRadius ?? defaults.dotRadius;
2993
+ const gap = config.gap ?? defaults.gap;
2994
+ this.pointImage = { ...new PcacPointImageConfig(), ...config.pointImage };
2995
+ const origin = rawXAxis?.domainMin !== undefined ? Number(rawXAxis.domainMin) : 0;
2996
+ this.placements = stackDots(config.data, config.binWidth, origin);
2997
+ const hasImages = this.placements.some((p) => !!p.data.image);
2998
+ const fullSize = hasImages
2999
+ ? Math.max(this.pointImage.maxWidth, this.pointImage.maxHeight)
3000
+ : 2 * (dotRadius + DOT_HOVER_GROWTH);
3001
+ // A mark at the domain's edge is centered on it, so half of it hangs past the plot area.
3002
+ const half = Math.ceil(fullSize / 2);
3003
+ this.reserveEdgeSpace({ left: half, right: half });
3004
+ if (!this.initializeChartState(chartElm, config)) {
3005
+ return;
3006
+ }
3007
+ this.ensureColorCount(config.data.length);
3008
+ this.applyColorOverride(config.colorOverride);
3009
+ // Shrink every mark evenly when the tallest column wouldn't fit the plot's height.
3010
+ const tallest = tallestColumn(this.placements);
3011
+ const fit = tallest ? Math.min(1, this.height / (tallest * (fullSize + gap))) : 1;
3012
+ this.markSize = fullSize * fit;
3013
+ this.markGap = gap * fit;
3014
+ this.dotRadius = dotRadius * fit;
3015
+ this.xScale = this.buildXScale(rawXAxis?.domainMin, rawXAxis?.domainMax);
3016
+ this.drawChart(chartElm);
3017
+ }
3018
+ /**
3019
+ * The value axis: `xAxis.domainMin` / `domainMax` where given, otherwise the data's extent
3020
+ * rounded out to nice ticks - checked on the consumer's own axis config, since the resolved one
3021
+ * fills in 0 - 100 for anything unset.
3022
+ */
3023
+ buildXScale(domainMin, domainMax) {
3024
+ const [lo, hi] = extent(this.placements, (p) => p.position);
3025
+ const min = domainMin !== undefined ? Number(domainMin) : lo ?? 0;
3026
+ const max = domainMax !== undefined ? Number(domainMax) : hi ?? 1;
3027
+ const scale = scaleLinear().domain(min === max ? [min - 1, max + 1] : [min, max]).range([0, this.width]);
3028
+ return domainMin === undefined || domainMax === undefined ? scale.nice(this.xAxis.ticks) : scale;
3029
+ }
3030
+ drawChart(chartElm) {
3031
+ this.buildContainer(chartElm);
3032
+ const yScale = scaleLinear().domain([0, 1]).range([this.height, 0]);
3033
+ this.axisBuilder.drawAxis(this.axisBuilderConfig(this.xScale, yScale));
3034
+ this.drawGrids(this.xScale, yScale);
3035
+ this.axisBuilder.raiseAxes(this.svg);
3036
+ this.drawDots();
3037
+ this.restoreTabStop(chartElm);
3038
+ }
3039
+ /** The center of a placed point's mark, in plot pixels: its column's x, its level's y. */
3040
+ center(p) {
3041
+ const step = this.markSize + this.markGap;
3042
+ return {
3043
+ x: this.xScale(p.position),
3044
+ y: this.height - this.markGap - this.markSize / 2 - p.level * step,
3045
+ };
3046
+ }
3047
+ drawDots() {
3048
+ const self = this;
3049
+ const duration = this.transitionService.getTransitionDuration();
3050
+ const { maxWidth, maxHeight } = this.pointImage;
3051
+ const fit = this.markSize / (this.placements.some((p) => !!p.data.image) ? Math.max(maxWidth, maxHeight) : 1);
3052
+ const imageWidth = maxWidth * fit;
3053
+ const imageHeight = maxHeight * fit;
3054
+ const color = (p) => this.colors[p.seriesIndex];
3055
+ const tooltipOptions = (p, anchor = null) => ({
3056
+ index: p.index,
3057
+ parent: p.series,
3058
+ parentIndex: p.seriesIndex,
3059
+ valueFormat: this.xAxis.format,
3060
+ anchor,
3061
+ });
3062
+ const grow = (mark, p, hovered) => {
3063
+ select(mark).select('.pcac-dot')
3064
+ .interrupt('hover')
3065
+ .transition('hover')
3066
+ .duration(duration / 3)
3067
+ .attr('r', hovered ? this.dotRadius + DOT_HOVER_GROWTH : this.dotRadius)
3068
+ .attr('fill', hovered ? color(p) : 'var(--pcac-dot-fill, #fff)');
3069
+ };
3070
+ const marks = this.svg.append('g')
3071
+ .attr('class', 'pcac-dots')
3072
+ .selectAll('.pcac-dot-mark')
3073
+ .data(this.placements)
3074
+ .enter().append('g')
3075
+ .attr('class', 'pcac-dot-mark')
3076
+ .attr('transform', (p) => `translate(${this.center(p).x}, ${this.center(p).y})`)
3077
+ .on('mouseover', function (event, p) {
3078
+ grow(this, p, true);
3079
+ self.showTooltip(event, p.data, tooltipOptions(p, select(this).select('.pcac-dot, .pcac-dot-image').node()));
3080
+ })
3081
+ .on('mouseout', function (_event, p) {
3082
+ grow(this, p, false);
3083
+ self.hideTooltip();
3084
+ })
3085
+ .on('click', (_event, p) => this.dotClickedSource.next(p.data));
3086
+ makeMarksAccessible(marks, {
3087
+ label: (p) => this.markLabel(p.data, { parent: p.series, valueFormat: this.xAxis.format }),
3088
+ activate: (p) => this.dotClickedSource.next(p.data),
3089
+ focus: (mark, p) => {
3090
+ grow(mark, p, true);
3091
+ this.showMarkTooltip(mark, p.data, tooltipOptions(p, select(mark).select('.pcac-dot, .pcac-dot-image').node()));
3092
+ },
3093
+ blur: (mark, p) => {
3094
+ grow(mark, p, false);
3095
+ this.hideMarkTooltip(mark);
3096
+ },
3097
+ });
3098
+ // Each column builds up from the axis: a mark fades in a beat after the one below it.
3099
+ const delay = (p) => Math.min(p.level * 40, duration);
3100
+ marks.filter((p) => !p.data.image)
3101
+ .append('circle')
3102
+ .attr('class', 'pcac-dot')
3103
+ .attr('r', this.dotRadius)
3104
+ .attr('stroke', color)
3105
+ .attr('fill', 'var(--pcac-dot-fill, #fff)')
3106
+ .attr('opacity', 0)
3107
+ .transition()
3108
+ .delay(delay)
3109
+ .duration(duration / 2)
3110
+ .attr('opacity', 1);
3111
+ marks.filter((p) => !!p.data.image)
3112
+ .append('image')
3113
+ .attr('class', 'pcac-dot-image')
3114
+ .attr('href', (p) => p.data.image)
3115
+ .attr('width', imageWidth)
3116
+ .attr('height', imageHeight)
3117
+ .attr('x', -imageWidth / 2)
3118
+ .attr('y', -imageHeight / 2)
3119
+ .attr('preserveAspectRatio', 'xMidYMid meet')
3120
+ .attr('opacity', 0)
3121
+ .transition()
3122
+ .delay(delay)
3123
+ .duration(duration / 2)
3124
+ .attr('opacity', 1);
3125
+ }
3126
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: DotPlotChartBuilder, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
3127
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: DotPlotChartBuilder });
3128
+ }
3129
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: DotPlotChartBuilder, decorators: [{
3130
+ type: Injectable
3131
+ }] });
3132
+
3133
+ /** A dot plot: points along one value axis, stacked into columns where they share a value (see PcacDotPlotChartConfig). */
3134
+ class PcacDotPlotChart {
3135
+ chartBuilder = inject(DotPlotChartBuilder);
3136
+ config = input.required(/* @ts-ignore */
3137
+ ...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
3138
+ chartElm = viewChild.required('chart', /* @ts-ignore */
3139
+ ...(ngDevMode ? [{ debugName: "chartElm" }] : /* istanbul ignore next */ []));
3140
+ dotClicked = outputFromObservable(this.chartBuilder.dotClicked$);
3141
+ /** Optional consumer `<ng-template pcacTooltip>`, replacing the default tooltip (see PcacTooltipDirective). */
3142
+ tooltipTemplate = contentChild(PcacTooltipDirective, /* @ts-ignore */
3143
+ ...(ngDevMode ? [{ debugName: "tooltipTemplate" }] : /* istanbul ignore next */ []));
3144
+ constructor() {
3145
+ effect(() => this.buildChart());
3146
+ // A getter, so the builder reads the query at hover time rather than in the effect above.
3147
+ this.chartBuilder.tooltipTemplate = () => this.tooltipTemplate()?.templateRef;
3148
+ inject(PcacChartResizeService).observe(this.chartElm, () => {
3149
+ if (this.chartBuilder.containerSizeChanged(this.chartElm())) {
3150
+ this.buildChart();
3151
+ }
3152
+ });
3153
+ }
3154
+ buildChart() {
3155
+ const config = this.config();
3156
+ // Handed over even when empty: the builder clears what it last drew rather than leaving it.
3157
+ if (config) {
3158
+ this.chartBuilder.buildChart(this.chartElm(), config);
3159
+ }
3160
+ }
3161
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacDotPlotChart, deps: [], target: i0.ɵɵFactoryTarget.Component });
3162
+ 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 });
3163
+ }
3164
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacDotPlotChart, decorators: [{
3165
+ type: Component,
3166
+ 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"] }]
3167
+ }], 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 }] }] } });
3168
+
3169
+ class PcacLegendConfigItem {
3170
+ label;
3171
+ checked = true;
3172
+ colorOverride = null;
2797
3173
  }
3174
+ class PcacLegendConfig {
3175
+ heading = null;
3176
+ items = [];
3177
+ }
3178
+ let nextLegendId = 0;
3179
+ class PcacLegend {
3180
+ headingId = `pcac-legend-heading-${nextLegendId++}`;
3181
+ colorService = inject(PcacColorService);
3182
+ config = model.required(/* @ts-ignore */
3183
+ ...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
3184
+ itemClicked = output();
3185
+ colorScale = computed(() => this.colorService.getColorScale(this.config().items.length), /* @ts-ignore */
3186
+ ...(ngDevMode ? [{ debugName: "colorScale" }] : /* istanbul ignore next */ []));
3187
+ onItemClicked(index) {
3188
+ const items = this.config().items.map((item, i) => i === index ? { ...item, checked: !item.checked } : item);
3189
+ this.config.set({ ...this.config(), items });
3190
+ this.itemClicked.emit(items);
3191
+ }
3192
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacLegend, deps: [], target: i0.ɵɵFactoryTarget.Component });
3193
+ 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"] });
3194
+ }
3195
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacLegend, decorators: [{
3196
+ type: Component,
3197
+ args: [{ selector: 'pcac-legend', host: {
3198
+ role: 'group',
3199
+ '[attr.aria-labelledby]': 'config().heading ? headingId : null',
3200
+ }, 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"] }]
3201
+ }], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }, { type: i0.Output, args: ["configChange"] }], itemClicked: [{ type: i0.Output, args: ["itemClicked"] }] } });
2798
3202
 
2799
3203
  /**
2800
3204
  * Whether a point has an x key to position by. An explicit emptiness check, not truthiness: a
@@ -3305,6 +3709,152 @@ function drawRange(group, extent, style, gradientId) {
3305
3709
  }
3306
3710
  }
3307
3711
 
3712
+ /** A hovered dot's radius - the largest a dot gets, so a ring around it never touches it. */
3713
+ const GAUGE_DOT_RADIUS = 6;
3714
+ /** Whether a point has a gauge value to draw. */
3715
+ function hasGauge(d) {
3716
+ return typeof d.gauge === 'number' && Number.isFinite(d.gauge);
3717
+ }
3718
+ /** How far a ring reaches past the mark it surrounds: its gap plus its full width. */
3719
+ function gaugeExtent(config) {
3720
+ return config.gap + config.width;
3721
+ }
3722
+ /** The share of the ring a value fills, clamped to 0 - 1. A `max` of 0 or less fills nothing. */
3723
+ function gaugeFraction(value, max) {
3724
+ return max > 0 ? Math.min(1, Math.max(0, value / max)) : 0;
3725
+ }
3726
+ /**
3727
+ * Appends a `.point-gauge` ring to each point in `points` that has a `gauge`: a `.point-gauge-track`
3728
+ * circle (unless `showTrack` is off) and a `.point-gauge-arc` path filling clockwise from 12
3729
+ * o'clock. `markRadius` is half of what the ring surrounds - the image box, or a hovered dot - so
3730
+ * the ring's centerline sits `gap + width / 2` beyond it. Returned so the caller can place the
3731
+ * rings (see `drawDots`, which moves them with each point's fan-out offset and enter rise).
3732
+ */
3733
+ function drawPointGauges(points, config, markRadius) {
3734
+ const radius = (d) => markRadius(d) + config.gap + config.width / 2;
3735
+ const gauges = points.filter(hasGauge)
3736
+ .append('g')
3737
+ .attr('class', 'point-gauge')
3738
+ .attr('aria-hidden', 'true');
3739
+ if (config.showTrack) {
3740
+ gauges.append('circle')
3741
+ .attr('class', 'point-gauge-track')
3742
+ .attr('r', radius)
3743
+ .attr('stroke-width', config.width);
3744
+ }
3745
+ gauges.append('path')
3746
+ .attr('class', 'point-gauge-arc')
3747
+ .attr('d', (d) => {
3748
+ const fraction = gaugeFraction(d.gauge, config.max);
3749
+ if (fraction === 0) {
3750
+ return null;
3751
+ }
3752
+ const r = radius(d);
3753
+ // Rounded ends read as a gauge; a full ring has no ends to round.
3754
+ return arc().cornerRadius(fraction < 1 ? config.width / 2 : 0)({
3755
+ innerRadius: r - config.width / 2,
3756
+ outerRadius: r + config.width / 2,
3757
+ startAngle: 0,
3758
+ endAngle: 2 * Math.PI * fraction,
3759
+ });
3760
+ });
3761
+ return gauges;
3762
+ }
3763
+
3764
+ /** How far a reference line's label, and a corner label, sits in from what it's attached to, in px. */
3765
+ const LABEL_INSET = 4;
3766
+ const CORNER_INSET = 8;
3767
+ /**
3768
+ * Where a reference line sits on its axis, in plot pixels, or `null` when its value doesn't place
3769
+ * (a date that won't parse, a non-numeric value) - such a line isn't drawn. An x value is read the
3770
+ * way a point's `key` is under the axis's format (see `getXFormat`).
3771
+ */
3772
+ function referenceLinePosition(line, scales, xFormat) {
3773
+ const position = line.axis === 'x'
3774
+ ? scales.x(xFormat === PcacFormatEnum.DateTime ? new Date(line.value) : Number(line.value))
3775
+ : scales.y(Number(line.value));
3776
+ return Number.isFinite(position) ? position : null;
3777
+ }
3778
+ /**
3779
+ * Draws `lines` into one `.reference-lines` group, clipped to the plot (`clipPathId`) so a line
3780
+ * zoomed past an edge disappears there. Each line is a `.reference-line` group holding the dashed
3781
+ * `<line>` and, when it has one, its `.reference-line-label`. Hidden from screen readers, as the
3782
+ * grid is.
3783
+ */
3784
+ function drawReferenceLines(svg, lines, scales, xFormat, width, height, clipPathId) {
3785
+ if (!lines?.length) {
3786
+ return;
3787
+ }
3788
+ const resolved = lines.map((line) => ({ ...new PcacReferenceLine(), ...line }));
3789
+ const groups = svg.append('g')
3790
+ .attr('class', 'reference-lines')
3791
+ .attr('clip-path', `url(#${clipPathId})`)
3792
+ .attr('aria-hidden', 'true')
3793
+ .selectAll('.reference-line')
3794
+ .data(resolved)
3795
+ .enter().append('g')
3796
+ .attr('class', (line) => `reference-line reference-line-${line.axis}`)
3797
+ .style('--pcac-reference-line-color', (line) => line.color ?? null);
3798
+ groups.append('line').attr('class', 'reference-line-stroke');
3799
+ groups.filter((line) => !!line.label)
3800
+ .append('text')
3801
+ .attr('class', 'reference-line-label')
3802
+ .text((line) => line.label);
3803
+ positionReferenceLines(svg, scales, xFormat, width, height);
3804
+ }
3805
+ /**
3806
+ * Places the chart's reference lines, and their labels, against `scales` - on the first draw and
3807
+ * again on every zoom. A horizontal line's label sits above its right end; a vertical line's beside
3808
+ * its top.
3809
+ */
3810
+ function positionReferenceLines(svg, scales, xFormat, width, height) {
3811
+ const groups = svg.selectAll('.reference-line')
3812
+ .attr('display', (line) => referenceLinePosition(line, scales, xFormat) === null ? 'none' : null);
3813
+ const at = (line) => referenceLinePosition(line, scales, xFormat) ?? 0;
3814
+ groups.select('.reference-line-stroke')
3815
+ .attr('x1', (line) => line.axis === 'x' ? at(line) : 0)
3816
+ .attr('x2', (line) => line.axis === 'x' ? at(line) : width)
3817
+ .attr('y1', (line) => line.axis === 'x' ? 0 : at(line))
3818
+ .attr('y2', (line) => line.axis === 'x' ? height : at(line));
3819
+ groups.select('.reference-line-label')
3820
+ .attr('x', (line) => line.axis === 'x' ? at(line) + LABEL_INSET : width - LABEL_INSET)
3821
+ .attr('y', (line) => line.axis === 'x' ? LABEL_INSET : at(line) - LABEL_INSET)
3822
+ .attr('text-anchor', (line) => line.axis === 'x' ? 'start' : 'end')
3823
+ .attr('dominant-baseline', (line) => line.axis === 'x' ? 'hanging' : 'auto');
3824
+ }
3825
+ /**
3826
+ * Draws `labels` into a `.corner-labels` group, each a `.corner-label` inset from its corner of
3827
+ * the plot area. Pinned to the frame, so zoom leaves them alone. Hidden from screen readers, as
3828
+ * the grid is.
3829
+ */
3830
+ function drawCornerLabels(svg, labels, width, height) {
3831
+ if (!labels) {
3832
+ return;
3833
+ }
3834
+ const corners = [
3835
+ { text: labels.topLeft, x: CORNER_INSET, y: CORNER_INSET, anchor: 'start', baseline: 'hanging', name: 'top-left' },
3836
+ { text: labels.topRight, x: width - CORNER_INSET, y: CORNER_INSET, anchor: 'end', baseline: 'hanging', name: 'top-right' },
3837
+ { text: labels.bottomLeft, x: CORNER_INSET, y: height - CORNER_INSET, anchor: 'start', baseline: 'auto', name: 'bottom-left' },
3838
+ { text: labels.bottomRight, x: width - CORNER_INSET, y: height - CORNER_INSET, anchor: 'end', baseline: 'auto', name: 'bottom-right' },
3839
+ ].filter((corner) => !!corner.text);
3840
+ if (corners.length === 0) {
3841
+ return;
3842
+ }
3843
+ svg.append('g')
3844
+ .attr('class', 'corner-labels')
3845
+ .attr('aria-hidden', 'true')
3846
+ .style('--pcac-corner-label-color', () => labels.color ?? null)
3847
+ .selectAll('.corner-label')
3848
+ .data(corners)
3849
+ .enter().append('text')
3850
+ .attr('class', (corner) => `corner-label corner-label-${corner.name}`)
3851
+ .attr('x', (corner) => corner.x)
3852
+ .attr('y', (corner) => corner.y)
3853
+ .attr('text-anchor', (corner) => corner.anchor)
3854
+ .attr('dominant-baseline', (corner) => corner.baseline)
3855
+ .text((corner) => corner.text);
3856
+ }
3857
+
3308
3858
  /**
3309
3859
  * Finds every set of points that share a coordinate across all of the chart's visible series.
3310
3860
  * Coincidence is decided from the data rather than from scaled pixels, so this can run before
@@ -3509,6 +4059,8 @@ class PlaChartBuilder extends PcacChart {
3509
4059
  hoveredPoint = null;
3510
4060
  /** `config.pointRange` with its defaults applied, or `null` while ranges are off. */
3511
4061
  pointRange = null;
4062
+ /** `pointGauge` with its defaults, or `null` while it's off. */
4063
+ pointGauge = null;
3512
4064
  /** Each drawn range's `.point-range` group, by its point, so hover can find the one to focus. */
3513
4065
  rangeGroupOf = new Map();
3514
4066
  /**
@@ -3537,6 +4089,8 @@ class PlaChartBuilder extends PcacChart {
3537
4089
  // A hidden axis keeps 8px rather than 0 so a dot on the edge of the plot isn't clipped
3538
4090
  this.initializeAxisState(this.config, 'y', 8);
3539
4091
  this.chartTypeLabel = CHART_TYPE_LABELS[type];
4092
+ // Before the layout: a ring widens what fan-out and the edge space have to make room for.
4093
+ this.pointGauge = this.config.pointGauge ? { ...new PcacPointGaugeConfig(), ...this.config.pointGauge } : null;
3540
4094
  this.resolvePointLayout(type);
3541
4095
  this.reservePointSpace();
3542
4096
  this.pointRange = this.config.pointRange ? { ...new PcacPointRangeConfig(), ...this.config.pointRange } : null;
@@ -3609,6 +4163,9 @@ class PlaChartBuilder extends PcacChart {
3609
4163
  .selectAll('.fan-out-spoke')
3610
4164
  .attr('x2', (member) => this.spokeEnd(member, zoomedScales).dx)
3611
4165
  .attr('y2', (member) => this.spokeEnd(member, zoomedScales).dy);
4166
+ // Reference lines sit at data values, so they move with it; corner labels are pinned to the
4167
+ // frame and stay put.
4168
+ positionReferenceLines(this.svg, zoomedScales, this.xAxis.format, this.width, this.height);
3612
4169
  // The hover crosshair positions and labels against the scales, so it takes the zoomed ones.
3613
4170
  if (this.effectsEnabled) {
3614
4171
  this.effectsBuilder.updateScales(newX, newY);
@@ -3635,6 +4192,9 @@ class PlaChartBuilder extends PcacChart {
3635
4192
  this.createReusableClipPath();
3636
4193
  this.axisBuilder.drawAxis(this.axisBuilderConfig(this.scales.x, this.scales.y));
3637
4194
  this.drawGrids(this.scales.x, this.scales.y);
4195
+ // Over the grid, under the series: guides, not data.
4196
+ drawCornerLabels(this.svg, config.cornerLabels, this.width, this.height);
4197
+ drawReferenceLines(this.svg, config.referenceLines, this.scales, this.xAxis.format, this.width, this.height, this.plotClipPathId);
3638
4198
  this.drawLineArea(config, type);
3639
4199
  this.effectsEnabled = !!config.enableEffects && type !== PcacLineAreaPlotChartConfigType.Plot;
3640
4200
  if (this.effectsEnabled) {
@@ -3681,9 +4241,11 @@ class PlaChartBuilder extends PcacChart {
3681
4241
  }
3682
4242
  this.fanOut = { ...new PcacPointFanOutConfig(), ...fanOut };
3683
4243
  // A group's members are kept apart by the size of what's drawn for them: the image box when
3684
- // any member has an image, else a hovered dot (r = 6).
4244
+ // any member has an image, else a hovered dot (r = 6) - plus a gauge ring on both sides when
4245
+ // any member has one.
3685
4246
  const { maxWidth, maxHeight } = this.pointImage;
3686
- const markSize = (group) => group.members.some((member) => !!member.data.image) ? Math.max(maxWidth, maxHeight) : 12;
4247
+ const ring = (group) => this.pointGauge && group.members.some((member) => hasGauge(member.data)) ? 2 * gaugeExtent(this.pointGauge) : 0;
4248
+ const markSize = (group) => (group.members.some((member) => !!member.data.image) ? Math.max(maxWidth, maxHeight) : 2 * GAUGE_DOT_RADIUS) + ring(group);
3687
4249
  const radius = (group) => this.fanOut.radius ?? fanOutRadius(group.members.length, markSize(group), this.fanOut.gap);
3688
4250
  this.fanOutOffsets = fanOutOffsets(this.coincidentGroups, radius);
3689
4251
  }
@@ -3698,13 +4260,16 @@ class PlaChartBuilder extends PcacChart {
3698
4260
  * `initializeAxisState()` and `initializeChartState()`, see `reserveEdgeSpace`.
3699
4261
  */
3700
4262
  reservePointSpace() {
3701
- const hasImages = this.config.data.some((series) => series.data.some((point) => !!point.image));
3702
- if (!hasImages) {
4263
+ const points = this.config.data.flatMap((series) => series.data);
4264
+ const hasImages = points.some((point) => !!point.image);
4265
+ // A gauge ring reaches past its mark on every side, so it needs the same room the mark does.
4266
+ const ring = this.pointGauge && points.some(hasGauge) ? Math.ceil(gaugeExtent(this.pointGauge)) : 0;
4267
+ if (!hasImages && !ring) {
3703
4268
  this.clipBuffer = 10;
3704
4269
  return;
3705
4270
  }
3706
- const halfWidth = Math.ceil(this.pointImage.maxWidth / 2);
3707
- const halfHeight = Math.ceil(this.pointImage.maxHeight / 2);
4271
+ const halfWidth = (hasImages ? Math.ceil(this.pointImage.maxWidth / 2) : GAUGE_DOT_RADIUS) + ring;
4272
+ const halfHeight = (hasImages ? Math.ceil(this.pointImage.maxHeight / 2) : GAUGE_DOT_RADIUS) + ring;
3708
4273
  this.clipBuffer = Math.max(10, halfWidth, halfHeight);
3709
4274
  this.reserveEdgeSpace({ top: halfHeight, bottom: halfHeight, left: halfWidth, right: halfWidth });
3710
4275
  }
@@ -4005,6 +4570,9 @@ class PlaChartBuilder extends PcacChart {
4005
4570
  .attr('class', 'dots')
4006
4571
  .attr('clip-path', `url(#${this.clipPathId})`)
4007
4572
  .attr('style', series.hide ? 'display: none' : null)
4573
+ // After `style`, which replaces the whole attribute.
4574
+ .style('--pcac-point-gauge-color', () => this.pointGauge?.color ?? null)
4575
+ .style('--pcac-point-gauge-track-color', () => this.pointGauge?.trackColor ?? null)
4008
4576
  .selectAll('.point')
4009
4577
  .data(series.data)
4010
4578
  .enter().append('g')
@@ -4019,7 +4587,8 @@ class PlaChartBuilder extends PcacChart {
4019
4587
  this.dotClickedSource.next(d);
4020
4588
  });
4021
4589
  makeMarksAccessible(points, {
4022
- label: (d) => this.markLabel(d, { parent: series, valueFormat: this.yAxis.format, keyFormat: this.xAxis.format }),
4590
+ label: (d) => this.markLabel(d, { parent: series, valueFormat: this.yAxis.format, keyFormat: this.xAxis.format })
4591
+ + this.gaugeLabel(d),
4023
4592
  activate: (d) => this.dotClickedSource.next(d),
4024
4593
  focus: (point, d) => {
4025
4594
  this.enterPoint(point, d, series, index);
@@ -4062,8 +4631,31 @@ class PlaChartBuilder extends PcacChart {
4062
4631
  .transition()
4063
4632
  .duration(duration)
4064
4633
  .attr('y', (d) => -maxHeight / 2 + this.offsetOf(d).dy);
4634
+ // Gauge rings around the image box or the dot, rising in with the mark they surround.
4635
+ if (this.pointGauge) {
4636
+ const markRadius = (d) => d.image ? Math.max(maxWidth, maxHeight) / 2 : GAUGE_DOT_RADIUS;
4637
+ drawPointGauges(points, this.pointGauge, markRadius)
4638
+ .style('--pcac-point-gauge-series-color', () => this.colors[index])
4639
+ .attr('transform', (d) => `translate(${this.offsetOf(d).dx}, ${rise(d)})`)
4640
+ .transition()
4641
+ .duration(duration)
4642
+ // Tweened as a number rather than `.attr('transform', ...)`: d3's transform interpolation
4643
+ // parses through SVG DOM APIs (`transform.baseVal`) that not every environment has.
4644
+ .attrTween('transform', (d) => {
4645
+ const { dx, dy } = this.offsetOf(d);
4646
+ const from = rise(d);
4647
+ return (t) => `translate(${dx}, ${from + (dy - from) * t})`;
4648
+ });
4649
+ }
4065
4650
  }
4066
4651
  }
4652
+ /**
4653
+ * The end of a point's screen reader name for its gauge - ", PSA 0.018" - when `pointGauge` has a
4654
+ * `name` and the point a `gauge`; otherwise nothing, the ring being only visual.
4655
+ */
4656
+ gaugeLabel(d) {
4657
+ return this.pointGauge?.name && hasGauge(d) ? `, ${this.pointGauge.name} ${d.gauge}` : '';
4658
+ }
4067
4659
  /**
4068
4660
  * Starts a hover on a point - its tooltip, beside it; its range brought forward; its dot grown -
4069
4661
  * for the pointer and keyboard focus alike (see makeMarksAccessible). Ended by `leavePoint`.
@@ -4250,11 +4842,11 @@ class PcacLineAreaChartComponent {
4250
4842
  }
4251
4843
  }
4252
4844
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacLineAreaChartComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
4253
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.2.0", type: PcacLineAreaChartComponent, isStandalone: true, selector: "pcac-line-area-chart", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null }, type: { classPropertyName: "type", publicName: "type", isSignal: true, isRequired: true, transformFunction: null }, tooltipTemplate: { classPropertyName: "tooltipTemplate", publicName: "tooltipTemplate", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { dotClicked: "dotClicked" }, host: { properties: { "class.pcac-height-full": "config().heightFull" } }, providers: [PlaChartBuilder, PlaChartEffectsBuilder], viewQueries: [{ propertyName: "chartElm", first: true, predicate: ["chart"], descendants: true, isSignal: true }], ngImport: i0, template: "<section class=\"pcac-line-area-chart\">\n <svg #chart></svg>\n</section>\n\n", styles: [".pcac-line-area-chart svg{width:100%;display:block}.pcac-line-area-chart .dot{stroke-width:2px}.pcac-line-area-chart .fan-out-spoke{stroke:var(--pcac-fan-out-spoke-color, #ced4da);stroke-width:1px}.pcac-line-area-chart .fan-out-anchor{fill:var(--pcac-fan-out-anchor-color, #6c757d)}.pcac-line-area-chart .point-ranges .point-range-series{--pcac-point-range-resolved-color: var(--pcac-point-range-color, var(--pcac-point-range-series-color))}.pcac-line-area-chart .point-ranges .point-range{opacity:var(--pcac-point-range-resting-opacity, 1);transition:opacity .15s ease-out}.pcac-line-area-chart .point-ranges .point-range.is-focused{opacity:1}.pcac-line-area-chart .point-ranges.pcac-range-hover{--pcac-point-range-resting-opacity: 0}.pcac-line-area-chart .point-ranges.pcac-range-faint{--pcac-point-range-resting-opacity: var(--pcac-point-range-faint-opacity, .2)}.pcac-line-area-chart .point-ranges.pcac-range-always.has-focus .point-range:not(.is-focused){opacity:.5}.pcac-line-area-chart .point-ranges .point-range-whisker,.pcac-line-area-chart .point-ranges .point-range-cap{stroke:var(--pcac-point-range-resolved-color);stroke-width:1.25px}.pcac-line-area-chart .point-ranges .point-range-box{fill:var(--pcac-point-range-resolved-color);fill-opacity:.1;stroke:var(--pcac-point-range-resolved-color);stroke-opacity:.7;stroke-width:1.25px}.pcac-line-area-chart .point-ranges .point-range-stop{stop-color:var(--pcac-point-range-resolved-color)}.pcac-line-area-chart .point-ranges .is-focused .point-range-whisker,.pcac-line-area-chart .point-ranges .is-focused .point-range-cap,.pcac-line-area-chart .point-ranges .is-focused .point-range-box{stroke-width:1.75px}.pcac-line-area-chart .point-ranges .is-focused .point-range-box{fill-opacity:.18}@media(prefers-reduced-motion:reduce){.pcac-line-area-chart .point-ranges .point-range{transition:none}}.pcac-line-area-chart .effects-canvas{fill:none}.pcac-line-area-chart .effect-line{stroke:var(--pcac-crosshair-line-color, #ced4da);stroke-width:1px;opacity:0}.pcac-line-area-chart .effect-circle{stroke-width:1px;fill:none;opacity:0}.pcac-line-area-chart .effect-text{font-size:11px;font-weight:700;fill:var(--pcac-crosshair-text-color, #343a40)}pcac-line-chart.pcac-height-full,pcac-area-chart.pcac-height-full,pcac-plot-chart.pcac-height-full,pcac-line-area-chart.pcac-height-full{display:block;height:100%}pcac-line-area-chart.pcac-height-full .pcac-line-area-chart{height:100%}\n"], encapsulation: i0.ViewEncapsulation.None });
4845
+ 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 });
4254
4846
  }
4255
4847
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacLineAreaChartComponent, decorators: [{
4256
4848
  type: Component,
4257
- args: [{ selector: 'pcac-line-area-chart', host: { '[class.pcac-height-full]': 'config().heightFull' }, encapsulation: ViewEncapsulation.None, providers: [PlaChartBuilder, PlaChartEffectsBuilder], template: "<section class=\"pcac-line-area-chart\">\n <svg #chart></svg>\n</section>\n\n", styles: [".pcac-line-area-chart svg{width:100%;display:block}.pcac-line-area-chart .dot{stroke-width:2px}.pcac-line-area-chart .fan-out-spoke{stroke:var(--pcac-fan-out-spoke-color, #ced4da);stroke-width:1px}.pcac-line-area-chart .fan-out-anchor{fill:var(--pcac-fan-out-anchor-color, #6c757d)}.pcac-line-area-chart .point-ranges .point-range-series{--pcac-point-range-resolved-color: var(--pcac-point-range-color, var(--pcac-point-range-series-color))}.pcac-line-area-chart .point-ranges .point-range{opacity:var(--pcac-point-range-resting-opacity, 1);transition:opacity .15s ease-out}.pcac-line-area-chart .point-ranges .point-range.is-focused{opacity:1}.pcac-line-area-chart .point-ranges.pcac-range-hover{--pcac-point-range-resting-opacity: 0}.pcac-line-area-chart .point-ranges.pcac-range-faint{--pcac-point-range-resting-opacity: var(--pcac-point-range-faint-opacity, .2)}.pcac-line-area-chart .point-ranges.pcac-range-always.has-focus .point-range:not(.is-focused){opacity:.5}.pcac-line-area-chart .point-ranges .point-range-whisker,.pcac-line-area-chart .point-ranges .point-range-cap{stroke:var(--pcac-point-range-resolved-color);stroke-width:1.25px}.pcac-line-area-chart .point-ranges .point-range-box{fill:var(--pcac-point-range-resolved-color);fill-opacity:.1;stroke:var(--pcac-point-range-resolved-color);stroke-opacity:.7;stroke-width:1.25px}.pcac-line-area-chart .point-ranges .point-range-stop{stop-color:var(--pcac-point-range-resolved-color)}.pcac-line-area-chart .point-ranges .is-focused .point-range-whisker,.pcac-line-area-chart .point-ranges .is-focused .point-range-cap,.pcac-line-area-chart .point-ranges .is-focused .point-range-box{stroke-width:1.75px}.pcac-line-area-chart .point-ranges .is-focused .point-range-box{fill-opacity:.18}@media(prefers-reduced-motion:reduce){.pcac-line-area-chart .point-ranges .point-range{transition:none}}.pcac-line-area-chart .effects-canvas{fill:none}.pcac-line-area-chart .effect-line{stroke:var(--pcac-crosshair-line-color, #ced4da);stroke-width:1px;opacity:0}.pcac-line-area-chart .effect-circle{stroke-width:1px;fill:none;opacity:0}.pcac-line-area-chart .effect-text{font-size:11px;font-weight:700;fill:var(--pcac-crosshair-text-color, #343a40)}pcac-line-chart.pcac-height-full,pcac-area-chart.pcac-height-full,pcac-plot-chart.pcac-height-full,pcac-line-area-chart.pcac-height-full{display:block;height:100%}pcac-line-area-chart.pcac-height-full .pcac-line-area-chart{height:100%}\n"] }]
4849
+ 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"] }]
4258
4850
  }], 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 }] }] } });
4259
4851
 
4260
4852
  class PcacPlotChart {
@@ -4325,8 +4917,304 @@ class PcacAreaChartConfig extends PcacLineAreaChartConfig {
4325
4917
  // export * from './plot-line-area-chart.model';
4326
4918
  // The rest of that model stays internal (the shared PcacLineAreaChartConfig is reached through
4327
4919
  // the per-chart PcacLineChartConfig/PcacAreaChartConfig/PcacPlotChartConfig subclasses), but
4328
- // the point-image and point-range types are part of those configs' public shape, so they're
4329
- // exported alone.
4920
+ // the point-image, point-range, point-gauge, reference-line and corner-label types are part of those configs'
4921
+ // public shape, so they're exported alone.
4922
+
4923
+ /**
4924
+ * A proximity chart: one item in the middle (`center`) and others (`data`) around it, each placed
4925
+ * closer in or further out by its `value` - how similar it is to the center, say, or how far from
4926
+ * it. It answers "what's nearest to this?" at a glance: the closest matches sit tight around the
4927
+ * center, weaker ones out on the rim.
4928
+ *
4929
+ * Each item in `data` is one point: `key` is its name (tooltip, screen readers), `value` its
4930
+ * closeness in whatever units the chart's `closeValue` / `farValue` use, and `image` optionally
4931
+ * drawn in place of its dot. Items go around the center clockwise from `startAngle` in data order,
4932
+ * evenly spaced, so put the closest first to have it at the top. An item whose `value` isn't a
4933
+ * number, or with `hide`, is left out. Best with a handful to a dozen or so items; past that they
4934
+ * crowd one another around the ring.
4935
+ */
4936
+ class PcacProximityChartConfig extends PcacChartConfig {
4937
+ /** The item the others are measured against, drawn in the middle. Its `value` isn't used. */
4938
+ center = new PcacData();
4939
+ /**
4940
+ * The `value` that sits right up against the center, and the one that sits on the outer rim;
4941
+ * values in between are placed proportionally, and anything beyond either is held at it.
4942
+ * The defaults suit a similarity from 0 to 1 (1 = identical, closest in). For a distance, swap
4943
+ * them: `closeValue: 0, farValue: <largest distance>`.
4944
+ */
4945
+ closeValue = 1;
4946
+ farValue = 0;
4947
+ /**
4948
+ * Values to draw a faint guide ring at, each labelled in `format` - e.g. `[0.95, 0.9, 0.85]` with
4949
+ * `Percentage` reads "95%", "90%", "85%". None when not set.
4950
+ */
4951
+ rings;
4952
+ /** How values read on the ring labels, in the tooltip and to screen readers; see `PcacFormatEnum`. */
4953
+ format;
4954
+ /**
4955
+ * Write each item's `key` under it, and the center's under the center. Default false: names are
4956
+ * in the tooltip either way. Keep it off for long names or a crowded ring.
4957
+ */
4958
+ showLabels = false;
4959
+ /** Draw a faint line from the center to each item. Default true. */
4960
+ showSpokes = true;
4961
+ /** Where the first item sits, in degrees clockwise from 12 o'clock. Default 0. */
4962
+ startAngle = 0;
4963
+ /** Size of the center item's image (or twice its dot's radius), in px. Default 64. */
4964
+ centerSize = 64;
4965
+ /** Size of each surrounding item's image (or twice its dot's radius), in px. Default 40. */
4966
+ itemSize = 40;
4967
+ /**
4968
+ * Item colors, any CSS color, used in data order for the dots of items without an `image` (the
4969
+ * center takes the first). Repeated when there are more items than colors. Omitted or empty, the
4970
+ * theme palette is used.
4971
+ */
4972
+ colorOverride;
4973
+ }
4974
+
4975
+ /** An item's value as a number, or `null` when it has none. */
4976
+ function proximityValue(d) {
4977
+ const value = typeof d.value === 'number' ? d.value : typeof d.value === 'string' && d.value.trim() !== '' ? Number(d.value) : NaN;
4978
+ return Number.isFinite(value) ? value : null;
4979
+ }
4980
+ /**
4981
+ * Where a value sits between the center and the rim: 0 at `closeValue`, 1 at `farValue`, in
4982
+ * proportion between them and held at either end beyond them. Equal ends put everything at 0.
4983
+ */
4984
+ function proximityDistance(value, closeValue, farValue) {
4985
+ if (closeValue === farValue) {
4986
+ return 0;
4987
+ }
4988
+ return Math.min(1, Math.max(0, (value - closeValue) / (farValue - closeValue)));
4989
+ }
4990
+ /**
4991
+ * Places every drawable item evenly around the center, clockwise from `startAngle` (degrees from
4992
+ * 12 o'clock) in data order, each at its value's distance. Hidden items and items without a
4993
+ * numeric value are left out, and don't take up a slot.
4994
+ */
4995
+ function placeProximity(data, closeValue, farValue, startAngle = 0) {
4996
+ const drawable = data
4997
+ .map((d, index) => ({ d, index, value: proximityValue(d) }))
4998
+ .filter((item) => !item.d.hide && item.value !== null);
4999
+ const start = (startAngle * Math.PI) / 180;
5000
+ return drawable.map(({ d, index, value }, slot) => ({
5001
+ data: d,
5002
+ index,
5003
+ value,
5004
+ angle: start + (slot / drawable.length) * 2 * Math.PI,
5005
+ distance: proximityDistance(value, closeValue, farValue),
5006
+ }));
5007
+ }
5008
+
5009
+ /** Space kept between the center's mark and the nearest an item can sit, in px. */
5010
+ const CENTER_GAP = 6;
5011
+ /** Room kept outside the rim for a ring label, in px. */
5012
+ const RIM_LABEL_ROOM = 4;
5013
+ /** Room a name takes below its item with `showLabels` - the gap and one line of 11px text - in px. */
5014
+ const ITEM_LABEL_ROOM = 16;
5015
+ /**
5016
+ * Provided per-component (see PcacProximityChart's `providers`), like every builder that extends
5017
+ * PcacChart: it holds per-chart-instance state, which a root singleton would share between charts.
5018
+ */
5019
+ class ProximityChartBuilder extends PcacChart {
5020
+ itemClickedSource = new Subject();
5021
+ itemClicked$ = this.itemClickedSource.asObservable();
5022
+ chartTypeLabel = 'Proximity chart';
5023
+ buildChart(chartElm, config) {
5024
+ this.hideTooltip();
5025
+ if (!config?.center && !config?.data?.length) {
5026
+ this.clearChart(chartElm);
5027
+ return;
5028
+ }
5029
+ // No axes, so an even margin all round rather than the axis charts' defaults.
5030
+ this.margin = { top: 8, right: 8, bottom: 8, left: 8 };
5031
+ if (!this.initializeChartState(chartElm, config)) {
5032
+ return;
5033
+ }
5034
+ const defaults = new PcacProximityChartConfig();
5035
+ const closeValue = config.closeValue ?? defaults.closeValue;
5036
+ const farValue = config.farValue ?? defaults.farValue;
5037
+ const centerSize = config.centerSize ?? defaults.centerSize;
5038
+ const itemSize = config.itemSize ?? defaults.itemSize;
5039
+ const placements = placeProximity(config.data ?? [], closeValue, farValue, config.startAngle ?? defaults.startAngle);
5040
+ this.ensureColorCount(placements.length + 1);
5041
+ this.applyColorOverride(config.colorOverride);
5042
+ // Items run from just outside the center's mark to the rim, their own half-size kept inside it -
5043
+ // and, with names under them, the name of an item at the bottom of the rim too.
5044
+ const inner = centerSize / 2 + CENTER_GAP + itemSize / 2;
5045
+ const edgeRoom = itemSize / 2 + (config.showLabels ? ITEM_LABEL_ROOM : RIM_LABEL_ROOM);
5046
+ const outer = Math.max(inner, Math.min(this.width, this.height) / 2 - edgeRoom);
5047
+ const radiusOf = (distance) => inner + distance * (outer - inner);
5048
+ this.buildContainer(chartElm, true);
5049
+ // Ring labels go halfway between the first two items, where no item sits to cover them.
5050
+ const labelAngle = (((config.startAngle ?? defaults.startAngle) * Math.PI) / 180) + Math.PI / Math.max(1, placements.length);
5051
+ this.drawRings(config, closeValue, farValue, radiusOf, labelAngle);
5052
+ const marks = placements.map((p) => {
5053
+ const r = radiusOf(p.distance);
5054
+ return {
5055
+ data: p.data,
5056
+ placement: p,
5057
+ x: r * Math.sin(p.angle),
5058
+ y: -r * Math.cos(p.angle),
5059
+ size: itemSize,
5060
+ color: this.colors[(p.index + 1) % this.colors.length],
5061
+ };
5062
+ });
5063
+ if (config.showSpokes ?? defaults.showSpokes) {
5064
+ this.svg.append('g')
5065
+ .attr('class', 'pcac-proximity-spokes')
5066
+ .attr('aria-hidden', 'true')
5067
+ .selectAll('line')
5068
+ .data(marks)
5069
+ .enter().append('line')
5070
+ .attr('class', 'pcac-proximity-spoke')
5071
+ .attr('x1', 0).attr('y1', 0)
5072
+ .attr('x2', (m) => m.x).attr('y2', (m) => m.y);
5073
+ }
5074
+ const center = config.center
5075
+ ? { data: config.center, placement: null, x: 0, y: 0, size: centerSize, color: this.colors[0] }
5076
+ : null;
5077
+ this.drawMarks(center ? [...marks, center] : marks, config);
5078
+ this.restoreTabStop(chartElm);
5079
+ }
5080
+ /** Faint guide rings at `config.rings`' values, each labelled at `labelAngle` in `config.format`. */
5081
+ drawRings(config, closeValue, farValue, radiusOf, labelAngle) {
5082
+ const rings = (config.rings ?? []).filter((v) => Number.isFinite(v));
5083
+ if (!rings.length) {
5084
+ return;
5085
+ }
5086
+ const groups = this.svg.append('g')
5087
+ .attr('class', 'pcac-proximity-rings')
5088
+ .attr('aria-hidden', 'true')
5089
+ .selectAll('g')
5090
+ .data(rings)
5091
+ .enter().append('g')
5092
+ .attr('class', 'pcac-proximity-ring');
5093
+ const r = (v) => radiusOf(proximityDistance(v, closeValue, farValue));
5094
+ groups.append('circle').attr('r', r).attr('fill', 'none');
5095
+ groups.append('text')
5096
+ .attr('class', 'pcac-proximity-ring-label')
5097
+ .attr('x', (v) => r(v) * Math.sin(labelAngle))
5098
+ .attr('y', (v) => -r(v) * Math.cos(labelAngle))
5099
+ .attr('text-anchor', 'middle')
5100
+ .attr('dominant-baseline', 'middle')
5101
+ .text((v) => formatValue(config.format, v) ?? String(v));
5102
+ }
5103
+ drawMarks(marks, config) {
5104
+ const self = this;
5105
+ const duration = this.transitionService.getTransitionDuration();
5106
+ const tooltipOptions = (m, anchor) => ({
5107
+ index: m.placement?.index ?? -1,
5108
+ parent: null,
5109
+ valueFormat: config.format,
5110
+ anchor,
5111
+ });
5112
+ const markOf = (group) => select(group).select('.pcac-proximity-dot, .pcac-proximity-image').node();
5113
+ const highlight = (group, on) => select(group).classed('is-active', on);
5114
+ const groups = this.svg.append('g')
5115
+ .attr('class', 'pcac-proximity-items')
5116
+ .selectAll('g')
5117
+ .data(marks)
5118
+ .enter().append('g')
5119
+ .attr('class', (m) => m.placement ? 'pcac-proximity-item' : 'pcac-proximity-item pcac-proximity-center')
5120
+ .attr('transform', (m) => `translate(${m.x}, ${m.y})`)
5121
+ .on('mouseover', function (event, m) {
5122
+ highlight(this, true);
5123
+ self.showTooltip(event, m.data, tooltipOptions(m, markOf(this)));
5124
+ })
5125
+ .on('mouseout', function () {
5126
+ highlight(this, false);
5127
+ self.hideTooltip();
5128
+ })
5129
+ .on('click', (_event, m) => this.itemClickedSource.next(m.data));
5130
+ makeMarksAccessible(groups, {
5131
+ label: (m) => m.placement
5132
+ ? this.markLabel(m.data, { valueFormat: config.format })
5133
+ : `${m.data.key ?? ''}, in the center`,
5134
+ activate: (m) => this.itemClickedSource.next(m.data),
5135
+ focus: (group, m) => {
5136
+ highlight(group, true);
5137
+ this.showMarkTooltip(group, m.data, tooltipOptions(m, markOf(group)));
5138
+ },
5139
+ blur: (group) => {
5140
+ highlight(group, false);
5141
+ this.hideMarkTooltip(group);
5142
+ },
5143
+ });
5144
+ groups.filter((m) => !m.data.image)
5145
+ .append('circle')
5146
+ .attr('class', 'pcac-proximity-dot')
5147
+ .attr('r', (m) => m.size / 2)
5148
+ .attr('fill', (m) => m.color)
5149
+ // What the theme's hover ring (`stroke: currentColor`) takes: the dot's own color.
5150
+ .style('color', (m) => m.color);
5151
+ groups.filter((m) => !!m.data.image)
5152
+ .append('image')
5153
+ .attr('class', 'pcac-proximity-image')
5154
+ .attr('href', (m) => m.data.image)
5155
+ .attr('width', (m) => m.size)
5156
+ .attr('height', (m) => m.size)
5157
+ .attr('x', (m) => -m.size / 2)
5158
+ .attr('y', (m) => -m.size / 2)
5159
+ .attr('preserveAspectRatio', 'xMidYMid meet');
5160
+ if (config.showLabels) {
5161
+ groups.append('text')
5162
+ .attr('class', 'pcac-proximity-label')
5163
+ .attr('aria-hidden', 'true')
5164
+ .attr('y', (m) => m.size / 2 + 12)
5165
+ .attr('text-anchor', 'middle')
5166
+ .text((m) => String(m.data.key ?? ''));
5167
+ }
5168
+ // The items fade in from the center outward, closest first.
5169
+ groups.attr('opacity', 0)
5170
+ .transition()
5171
+ .delay((m) => (m.placement ? m.placement.distance * duration / 2 : 0))
5172
+ .duration(duration / 2)
5173
+ .attr('opacity', 1);
5174
+ }
5175
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: ProximityChartBuilder, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
5176
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: ProximityChartBuilder });
5177
+ }
5178
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: ProximityChartBuilder, decorators: [{
5179
+ type: Injectable
5180
+ }] });
5181
+
5182
+ /** A proximity chart: an item in the middle, others around it by closeness (see PcacProximityChartConfig). */
5183
+ class PcacProximityChart {
5184
+ chartBuilder = inject(ProximityChartBuilder);
5185
+ config = input.required(/* @ts-ignore */
5186
+ ...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
5187
+ chartElm = viewChild.required('chart', /* @ts-ignore */
5188
+ ...(ngDevMode ? [{ debugName: "chartElm" }] : /* istanbul ignore next */ []));
5189
+ /** An item - or the center - was clicked, or activated with Enter or Space. */
5190
+ itemClicked = outputFromObservable(this.chartBuilder.itemClicked$);
5191
+ /** Optional consumer `<ng-template pcacTooltip>`, replacing the default tooltip (see PcacTooltipDirective). */
5192
+ tooltipTemplate = contentChild(PcacTooltipDirective, /* @ts-ignore */
5193
+ ...(ngDevMode ? [{ debugName: "tooltipTemplate" }] : /* istanbul ignore next */ []));
5194
+ constructor() {
5195
+ effect(() => this.buildChart());
5196
+ // A getter, so the builder reads the query at hover time rather than in the effect above.
5197
+ this.chartBuilder.tooltipTemplate = () => this.tooltipTemplate()?.templateRef;
5198
+ inject(PcacChartResizeService).observe(this.chartElm, () => {
5199
+ if (this.chartBuilder.containerSizeChanged(this.chartElm())) {
5200
+ this.buildChart();
5201
+ }
5202
+ });
5203
+ }
5204
+ buildChart() {
5205
+ const config = this.config();
5206
+ // Handed over even when empty: the builder clears what it last drew rather than leaving it.
5207
+ if (config) {
5208
+ this.chartBuilder.buildChart(this.chartElm(), config);
5209
+ }
5210
+ }
5211
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacProximityChart, deps: [], target: i0.ɵɵFactoryTarget.Component });
5212
+ 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 });
5213
+ }
5214
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacProximityChart, decorators: [{
5215
+ type: Component,
5216
+ 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"] }]
5217
+ }], 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 }] }] } });
4330
5218
 
4331
5219
  /** Which chart the shared `<pcac-pie-donut-chart>` draws; each wrapper binds its own. */
4332
5220
  var PcacPieDonutChartType;
@@ -4718,5 +5606,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImpor
4718
5606
  * Generated bundle index. Do not edit.
4719
5607
  */
4720
5608
 
4721
- export { PcacAreaChart, PcacAreaChartConfig, PcacAxisChartConfig, PcacAxisConfig, PcacAxisSubLabels, PcacBarHorizontalChart, PcacBarHorizontalChart as PcacBarHorizontalChartComponent, PcacBarHorizontalChartConfig, PcacBarVerticalChart, PcacBarVerticalChart as PcacBarVerticalChartComponent, PcacBarVerticalChartConfig, PcacChartConfig, PcacColorService, PcacData, PcacDataRange, PcacDonutChart, PcacDonutChartConfig, PcacFormatEnum, PcacLegend, PcacLegendConfig, PcacLegendConfigItem, PcacLineChart, PcacLineChartConfig, PcacPieChart, PcacPieChartConfig, PcacPlotChart, PcacPlotChartConfig, PcacPointFanOutConfig, PcacPointImageConfig, PcacPointRangeConfig, PcacPointRangeShow, PcacPointRangeStyle, PcacRangeBounds, PcacTooltipDirective };
5609
+ 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 };
4722
5610
  //# sourceMappingURL=pioneer-code-pioneer-charts.mjs.map