@pioneer-code/pioneer-charts 22.2.18 → 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.
- package/fesm2022/pioneer-code-pioneer-charts.mjs +925 -47
- package/fesm2022/pioneer-code-pioneer-charts.mjs.map +1 -1
- package/package.json +1 -1
- package/scss/dot-plot-chart/dot-plot-chart.component.scss +27 -0
- package/scss/plot-line-area-chart/plot-line-area-chart.component.scss +33 -0
- package/scss/proximity-chart/proximity-chart.component.scss +68 -0
- package/types/pioneer-code-pioneer-charts.d.ts +249 -21
|
@@ -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,17 @@ 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;
|
|
248
259
|
}
|
|
249
260
|
/**
|
|
250
261
|
* One side of a `PcacDataRange`. `min` above `max` is read as the other way round; `min` equal to
|
|
@@ -2667,40 +2678,6 @@ class PcacBarVerticalChartConfig extends PcacAxisChartConfig {
|
|
|
2667
2678
|
// base class and the builders, the axis/grid/tooltip/transition/resize services, and the
|
|
2668
2679
|
// resolved-config helpers - is internal, so it can change without breaking anyone.
|
|
2669
2680
|
|
|
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
2681
|
var PcacLineAreaPlotChartConfigType;
|
|
2705
2682
|
(function (PcacLineAreaPlotChartConfigType) {
|
|
2706
2683
|
PcacLineAreaPlotChartConfigType["Line"] = "line";
|
|
@@ -2757,6 +2734,80 @@ class PcacPointRangeConfig {
|
|
|
2757
2734
|
*/
|
|
2758
2735
|
color;
|
|
2759
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
|
+
}
|
|
2760
2811
|
/**
|
|
2761
2812
|
* The axes' `format` and `domainMin`/`domainMax` (`PcacAxisConfig`) do more here than on the bar
|
|
2762
2813
|
* charts. `yAxis.domainMin`/`domainMax` are the y scale's domain (default 0..100). `xAxis.format`
|
|
@@ -2794,7 +2845,350 @@ class PcacLineAreaChartConfig extends PcacAxisChartConfig {
|
|
|
2794
2845
|
* every `PcacPointRangeConfig` default. Points without a `range` draw nothing extra.
|
|
2795
2846
|
*/
|
|
2796
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 });
|
|
3118
|
+
}
|
|
3119
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: DotPlotChartBuilder, decorators: [{
|
|
3120
|
+
type: Injectable
|
|
3121
|
+
}] });
|
|
3122
|
+
|
|
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);
|
|
3126
|
+
config = input.required(/* @ts-ignore */
|
|
3127
|
+
...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
|
|
3128
|
+
chartElm = viewChild.required('chart', /* @ts-ignore */
|
|
3129
|
+
...(ngDevMode ? [{ debugName: "chartElm" }] : /* istanbul ignore next */ []));
|
|
3130
|
+
dotClicked = outputFromObservable(this.chartBuilder.dotClicked$);
|
|
3131
|
+
/** Optional consumer `<ng-template pcacTooltip>`, replacing the default tooltip (see PcacTooltipDirective). */
|
|
3132
|
+
tooltipTemplate = contentChild(PcacTooltipDirective, /* @ts-ignore */
|
|
3133
|
+
...(ngDevMode ? [{ debugName: "tooltipTemplate" }] : /* istanbul ignore next */ []));
|
|
3134
|
+
constructor() {
|
|
3135
|
+
effect(() => this.buildChart());
|
|
3136
|
+
// A getter, so the builder reads the query at hover time rather than in the effect above.
|
|
3137
|
+
this.chartBuilder.tooltipTemplate = () => this.tooltipTemplate()?.templateRef;
|
|
3138
|
+
inject(PcacChartResizeService).observe(this.chartElm, () => {
|
|
3139
|
+
if (this.chartBuilder.containerSizeChanged(this.chartElm())) {
|
|
3140
|
+
this.buildChart();
|
|
3141
|
+
}
|
|
3142
|
+
});
|
|
3143
|
+
}
|
|
3144
|
+
buildChart() {
|
|
3145
|
+
const config = this.config();
|
|
3146
|
+
// Handed over even when empty: the builder clears what it last drew rather than leaving it.
|
|
3147
|
+
if (config) {
|
|
3148
|
+
this.chartBuilder.buildChart(this.chartElm(), config);
|
|
3149
|
+
}
|
|
3150
|
+
}
|
|
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 });
|
|
2797
3153
|
}
|
|
3154
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacDotPlotChart, decorators: [{
|
|
3155
|
+
type: Component,
|
|
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 }] }] } });
|
|
3158
|
+
|
|
3159
|
+
class PcacLegendConfigItem {
|
|
3160
|
+
label;
|
|
3161
|
+
checked = true;
|
|
3162
|
+
colorOverride = null;
|
|
3163
|
+
}
|
|
3164
|
+
class PcacLegendConfig {
|
|
3165
|
+
heading = null;
|
|
3166
|
+
items = [];
|
|
3167
|
+
}
|
|
3168
|
+
let nextLegendId = 0;
|
|
3169
|
+
class PcacLegend {
|
|
3170
|
+
headingId = `pcac-legend-heading-${nextLegendId++}`;
|
|
3171
|
+
colorService = inject(PcacColorService);
|
|
3172
|
+
config = model.required(/* @ts-ignore */
|
|
3173
|
+
...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
|
|
3174
|
+
itemClicked = output();
|
|
3175
|
+
colorScale = computed(() => this.colorService.getColorScale(this.config().items.length), /* @ts-ignore */
|
|
3176
|
+
...(ngDevMode ? [{ debugName: "colorScale" }] : /* istanbul ignore next */ []));
|
|
3177
|
+
onItemClicked(index) {
|
|
3178
|
+
const items = this.config().items.map((item, i) => i === index ? { ...item, checked: !item.checked } : item);
|
|
3179
|
+
this.config.set({ ...this.config(), items });
|
|
3180
|
+
this.itemClicked.emit(items);
|
|
3181
|
+
}
|
|
3182
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacLegend, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
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"] });
|
|
3184
|
+
}
|
|
3185
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacLegend, decorators: [{
|
|
3186
|
+
type: Component,
|
|
3187
|
+
args: [{ selector: 'pcac-legend', host: {
|
|
3188
|
+
role: 'group',
|
|
3189
|
+
'[attr.aria-labelledby]': 'config().heading ? headingId : null',
|
|
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"] }]
|
|
3191
|
+
}], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }, { type: i0.Output, args: ["configChange"] }], itemClicked: [{ type: i0.Output, args: ["itemClicked"] }] } });
|
|
2798
3192
|
|
|
2799
3193
|
/**
|
|
2800
3194
|
* Whether a point has an x key to position by. An explicit emptiness check, not truthiness: a
|
|
@@ -3305,6 +3699,152 @@ function drawRange(group, extent, style, gradientId) {
|
|
|
3305
3699
|
}
|
|
3306
3700
|
}
|
|
3307
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
|
+
|
|
3308
3848
|
/**
|
|
3309
3849
|
* Finds every set of points that share a coordinate across all of the chart's visible series.
|
|
3310
3850
|
* Coincidence is decided from the data rather than from scaled pixels, so this can run before
|
|
@@ -3509,6 +4049,8 @@ class PlaChartBuilder extends PcacChart {
|
|
|
3509
4049
|
hoveredPoint = null;
|
|
3510
4050
|
/** `config.pointRange` with its defaults applied, or `null` while ranges are off. */
|
|
3511
4051
|
pointRange = null;
|
|
4052
|
+
/** `pointGauge` with its defaults, or `null` while it's off. */
|
|
4053
|
+
pointGauge = null;
|
|
3512
4054
|
/** Each drawn range's `.point-range` group, by its point, so hover can find the one to focus. */
|
|
3513
4055
|
rangeGroupOf = new Map();
|
|
3514
4056
|
/**
|
|
@@ -3537,6 +4079,8 @@ class PlaChartBuilder extends PcacChart {
|
|
|
3537
4079
|
// A hidden axis keeps 8px rather than 0 so a dot on the edge of the plot isn't clipped
|
|
3538
4080
|
this.initializeAxisState(this.config, 'y', 8);
|
|
3539
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;
|
|
3540
4084
|
this.resolvePointLayout(type);
|
|
3541
4085
|
this.reservePointSpace();
|
|
3542
4086
|
this.pointRange = this.config.pointRange ? { ...new PcacPointRangeConfig(), ...this.config.pointRange } : null;
|
|
@@ -3609,6 +4153,9 @@ class PlaChartBuilder extends PcacChart {
|
|
|
3609
4153
|
.selectAll('.fan-out-spoke')
|
|
3610
4154
|
.attr('x2', (member) => this.spokeEnd(member, zoomedScales).dx)
|
|
3611
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);
|
|
3612
4159
|
// The hover crosshair positions and labels against the scales, so it takes the zoomed ones.
|
|
3613
4160
|
if (this.effectsEnabled) {
|
|
3614
4161
|
this.effectsBuilder.updateScales(newX, newY);
|
|
@@ -3635,6 +4182,9 @@ class PlaChartBuilder extends PcacChart {
|
|
|
3635
4182
|
this.createReusableClipPath();
|
|
3636
4183
|
this.axisBuilder.drawAxis(this.axisBuilderConfig(this.scales.x, this.scales.y));
|
|
3637
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);
|
|
3638
4188
|
this.drawLineArea(config, type);
|
|
3639
4189
|
this.effectsEnabled = !!config.enableEffects && type !== PcacLineAreaPlotChartConfigType.Plot;
|
|
3640
4190
|
if (this.effectsEnabled) {
|
|
@@ -3681,9 +4231,11 @@ class PlaChartBuilder extends PcacChart {
|
|
|
3681
4231
|
}
|
|
3682
4232
|
this.fanOut = { ...new PcacPointFanOutConfig(), ...fanOut };
|
|
3683
4233
|
// 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)
|
|
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.
|
|
3685
4236
|
const { maxWidth, maxHeight } = this.pointImage;
|
|
3686
|
-
const
|
|
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);
|
|
3687
4239
|
const radius = (group) => this.fanOut.radius ?? fanOutRadius(group.members.length, markSize(group), this.fanOut.gap);
|
|
3688
4240
|
this.fanOutOffsets = fanOutOffsets(this.coincidentGroups, radius);
|
|
3689
4241
|
}
|
|
@@ -3698,13 +4250,16 @@ class PlaChartBuilder extends PcacChart {
|
|
|
3698
4250
|
* `initializeAxisState()` and `initializeChartState()`, see `reserveEdgeSpace`.
|
|
3699
4251
|
*/
|
|
3700
4252
|
reservePointSpace() {
|
|
3701
|
-
const
|
|
3702
|
-
|
|
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) {
|
|
3703
4258
|
this.clipBuffer = 10;
|
|
3704
4259
|
return;
|
|
3705
4260
|
}
|
|
3706
|
-
const halfWidth = Math.ceil(this.pointImage.maxWidth / 2);
|
|
3707
|
-
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;
|
|
3708
4263
|
this.clipBuffer = Math.max(10, halfWidth, halfHeight);
|
|
3709
4264
|
this.reserveEdgeSpace({ top: halfHeight, bottom: halfHeight, left: halfWidth, right: halfWidth });
|
|
3710
4265
|
}
|
|
@@ -4005,6 +4560,9 @@ class PlaChartBuilder extends PcacChart {
|
|
|
4005
4560
|
.attr('class', 'dots')
|
|
4006
4561
|
.attr('clip-path', `url(#${this.clipPathId})`)
|
|
4007
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)
|
|
4008
4566
|
.selectAll('.point')
|
|
4009
4567
|
.data(series.data)
|
|
4010
4568
|
.enter().append('g')
|
|
@@ -4019,7 +4577,8 @@ class PlaChartBuilder extends PcacChart {
|
|
|
4019
4577
|
this.dotClickedSource.next(d);
|
|
4020
4578
|
});
|
|
4021
4579
|
makeMarksAccessible(points, {
|
|
4022
|
-
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),
|
|
4023
4582
|
activate: (d) => this.dotClickedSource.next(d),
|
|
4024
4583
|
focus: (point, d) => {
|
|
4025
4584
|
this.enterPoint(point, d, series, index);
|
|
@@ -4062,8 +4621,31 @@ class PlaChartBuilder extends PcacChart {
|
|
|
4062
4621
|
.transition()
|
|
4063
4622
|
.duration(duration)
|
|
4064
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
|
+
}
|
|
4065
4640
|
}
|
|
4066
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
|
+
}
|
|
4067
4649
|
/**
|
|
4068
4650
|
* Starts a hover on a point - its tooltip, beside it; its range brought forward; its dot grown -
|
|
4069
4651
|
* for the pointer and keyboard focus alike (see makeMarksAccessible). Ended by `leavePoint`.
|
|
@@ -4250,11 +4832,11 @@ class PcacLineAreaChartComponent {
|
|
|
4250
4832
|
}
|
|
4251
4833
|
}
|
|
4252
4834
|
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 });
|
|
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 });
|
|
4254
4836
|
}
|
|
4255
4837
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacLineAreaChartComponent, decorators: [{
|
|
4256
4838
|
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"] }]
|
|
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"] }]
|
|
4258
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 }] }] } });
|
|
4259
4841
|
|
|
4260
4842
|
class PcacPlotChart {
|
|
@@ -4325,8 +4907,304 @@ class PcacAreaChartConfig extends PcacLineAreaChartConfig {
|
|
|
4325
4907
|
// export * from './plot-line-area-chart.model';
|
|
4326
4908
|
// The rest of that model stays internal (the shared PcacLineAreaChartConfig is reached through
|
|
4327
4909
|
// the per-chart PcacLineChartConfig/PcacAreaChartConfig/PcacPlotChartConfig subclasses), but
|
|
4328
|
-
// the point-image
|
|
4329
|
-
// 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 }] }] } });
|
|
4330
5208
|
|
|
4331
5209
|
/** Which chart the shared `<pcac-pie-donut-chart>` draws; each wrapper binds its own. */
|
|
4332
5210
|
var PcacPieDonutChartType;
|
|
@@ -4718,5 +5596,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImpor
|
|
|
4718
5596
|
* Generated bundle index. Do not edit.
|
|
4719
5597
|
*/
|
|
4720
5598
|
|
|
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 };
|
|
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 };
|
|
4722
5600
|
//# sourceMappingURL=pioneer-code-pioneer-charts.mjs.map
|