@pioneer-code/pioneer-charts 22.2.14 → 22.2.16
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/LICENSE +21 -0
- package/README.md +11 -7
- package/fesm2022/pioneer-code-pioneer-charts.mjs +708 -391
- package/fesm2022/pioneer-code-pioneer-charts.mjs.map +1 -1
- package/package.json +11 -3
- package/scss/legend/legend.component.scss +7 -5
- package/scss/pie-donut-chart/pie-donut-chart.component.scss +6 -0
- package/scss/pioneer-charts.scss +6 -6
- package/themes/pioneer-charts.css +4 -4
- package/themes/pioneer-charts.min.css +1 -1
- package/types/pioneer-code-pioneer-charts.d.ts +67 -35
- package/scss/pie-chart/pie-chart.component.scss +0 -10
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { Injectable, inject, ApplicationRef, DOCUMENT, DestroyRef, afterNextRender, TemplateRef, Directive, input, viewChild, contentChild, effect, ViewEncapsulation, Component, model, output, computed } from '@angular/core';
|
|
2
|
+
import { Injectable, signal, untracked, inject, ApplicationRef, DOCUMENT, DestroyRef, afterNextRender, TemplateRef, Directive, input, viewChild, contentChild, effect, ViewEncapsulation, Component, model, output, computed } from '@angular/core';
|
|
3
3
|
import { takeUntilDestroyed, outputFromObservable } from '@angular/core/rxjs-interop';
|
|
4
4
|
import { color } from 'd3-color';
|
|
5
5
|
import { scaleLinear, scaleBand, scaleTime } from 'd3-scale';
|
|
6
6
|
import { select } from 'd3-selection';
|
|
7
|
-
import { transition } from 'd3-transition';
|
|
7
|
+
import { transition, active } from 'd3-transition';
|
|
8
8
|
import { Subject } from 'rxjs';
|
|
9
9
|
import { axisLeft, axisBottom } from 'd3-axis';
|
|
10
10
|
import { format } from 'd3-format';
|
|
@@ -19,10 +19,10 @@ import { interpolate } from 'd3-interpolate';
|
|
|
19
19
|
* INewChart extends IChart
|
|
20
20
|
*/
|
|
21
21
|
class PcacChartConfig {
|
|
22
|
+
data = [];
|
|
22
23
|
/**
|
|
23
24
|
* Height in pixels
|
|
24
25
|
*/
|
|
25
|
-
data = [];
|
|
26
26
|
height = 200;
|
|
27
27
|
/**
|
|
28
28
|
* When true, `height` becomes a *minimum* height: if the container the chart is placed in is
|
|
@@ -297,6 +297,33 @@ function formatHourOfDay(value) {
|
|
|
297
297
|
const period = hour24 < 12 ? 'am' : 'pm';
|
|
298
298
|
return minutes === 0 ? `${hour}${period}` : `${hour}:${String(minutes).padStart(2, '0')}${period}`;
|
|
299
299
|
}
|
|
300
|
+
/** Plain numbers with thousands separators - `1,500`, `0.05` - for the `Decimal` format. */
|
|
301
|
+
const formatDecimal = format(',~f');
|
|
302
|
+
/**
|
|
303
|
+
* A single value (not a tick) in `pcacFormat`, the way an axis in that format labels it - so a
|
|
304
|
+
* tooltip reads like the axis it's measured against. Returns null for the formats that have no
|
|
305
|
+
* formatting of their own, and for a value the format can't read as a number, which callers show
|
|
306
|
+
* as it is.
|
|
307
|
+
*/
|
|
308
|
+
function formatValue(pcacFormat, value) {
|
|
309
|
+
const numeric = typeof value === 'number' || (typeof value === 'string' && value.trim() !== '')
|
|
310
|
+
? Number(value)
|
|
311
|
+
: NaN;
|
|
312
|
+
switch (pcacFormat) {
|
|
313
|
+
case PcacFormatEnum.Percentage:
|
|
314
|
+
return Number.isFinite(numeric) ? formatPercent(numeric) : null;
|
|
315
|
+
case PcacFormatEnum.Decimal:
|
|
316
|
+
return Number.isFinite(numeric) ? formatDecimal(numeric) : null;
|
|
317
|
+
case PcacFormatEnum.OneDayHours:
|
|
318
|
+
return Number.isFinite(numeric) ? formatHourOfDay(numeric) : null;
|
|
319
|
+
case PcacFormatEnum.Minutes:
|
|
320
|
+
return Number.isFinite(numeric) ? value + 'm' : null;
|
|
321
|
+
case PcacFormatEnum.Fahrenheit:
|
|
322
|
+
return Number.isFinite(numeric) ? value + ' F' : null;
|
|
323
|
+
default:
|
|
324
|
+
return null;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
300
327
|
/**
|
|
301
328
|
* The tick label format for an axis in `format`, shared by both axes (so a format means the same
|
|
302
329
|
* thing on x and y) and by anything that labels a value on that axis, like the line/area hover
|
|
@@ -313,7 +340,7 @@ function axisTickFormat(pcacFormat, scale, ticks) {
|
|
|
313
340
|
case PcacFormatEnum.Decimal:
|
|
314
341
|
// Plain numbers with thousands separators - `1,500`, `0.05` - rather than SI prefixes, which
|
|
315
342
|
// turned a differential of 0.05 into `50m` (reading as minutes, like the Minutes format).
|
|
316
|
-
return withTicks.tickFormat ? withTicks.tickFormat(ticks, ',~f') : (d) =>
|
|
343
|
+
return withTicks.tickFormat ? withTicks.tickFormat(ticks, ',~f') : (d) => formatDecimal(Number(d));
|
|
317
344
|
case PcacFormatEnum.Minutes:
|
|
318
345
|
return (d) => d + 'm';
|
|
319
346
|
case PcacFormatEnum.Fahrenheit:
|
|
@@ -421,10 +448,10 @@ class PcacAxisBuilder {
|
|
|
421
448
|
text('pcac-axis-sub-label', layout.length, edge, 'end', sub.max);
|
|
422
449
|
}
|
|
423
450
|
}
|
|
424
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
425
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.
|
|
451
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacAxisBuilder, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
452
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacAxisBuilder, providedIn: 'root' });
|
|
426
453
|
}
|
|
427
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
454
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacAxisBuilder, decorators: [{
|
|
428
455
|
type: Injectable,
|
|
429
456
|
args: [{
|
|
430
457
|
providedIn: 'root',
|
|
@@ -472,8 +499,7 @@ class PcacGridBuilder {
|
|
|
472
499
|
.attr('transform', (x) => (`translate(${x}, 0)`))
|
|
473
500
|
.append('svg:line')
|
|
474
501
|
.attr('y1', 0)
|
|
475
|
-
.attr('y2', config.height)
|
|
476
|
-
.attr('class', (d, i) => (i === 0 ? 'pcac-grid-rule-last' : ''));
|
|
502
|
+
.attr('y2', config.height);
|
|
477
503
|
}
|
|
478
504
|
/**
|
|
479
505
|
* Horizontal lines, one per y-axis tick (or category), running the plot's full width.
|
|
@@ -490,13 +516,12 @@ class PcacGridBuilder {
|
|
|
490
516
|
.attr('y1', (y) => y)
|
|
491
517
|
.attr('y2', (y) => y)
|
|
492
518
|
.attr('x1', 0)
|
|
493
|
-
.attr('x2', config.width)
|
|
494
|
-
.attr('class', (_, i) => (i === 0 ? 'pcac-grid-rule-last' : ''));
|
|
519
|
+
.attr('x2', config.width);
|
|
495
520
|
}
|
|
496
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
497
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.
|
|
521
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacGridBuilder, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
522
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacGridBuilder, providedIn: 'root' });
|
|
498
523
|
}
|
|
499
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
524
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacGridBuilder, decorators: [{
|
|
500
525
|
type: Injectable,
|
|
501
526
|
args: [{
|
|
502
527
|
providedIn: 'root',
|
|
@@ -512,6 +537,22 @@ class PcacColorService {
|
|
|
512
537
|
orange = '#ffa177';
|
|
513
538
|
blue = '#55d8fe';
|
|
514
539
|
alert = 'red';
|
|
540
|
+
/**
|
|
541
|
+
* Bumped by every setter, and read by the getters, so anything reading colors inside a reactive
|
|
542
|
+
* context tracks palette changes: the legend's `colorScale` computed recomputes, and every chart
|
|
543
|
+
* (whose build runs in an `effect`) redraws - together, rather than the legend keeping the old
|
|
544
|
+
* swatches while newly built charts took the new palette.
|
|
545
|
+
*/
|
|
546
|
+
version = signal(0, /* @ts-ignore */
|
|
547
|
+
...(ngDevMode ? [{ debugName: "version" }] : /* istanbul ignore next */ []));
|
|
548
|
+
/**
|
|
549
|
+
* Bumps `version` from a setter. `untracked`, because Angular forbids writing a signal inside a
|
|
550
|
+
* `computed` - and a consumer deriving its theme reactively (`computed(() => { setScale(...);
|
|
551
|
+
* ... })`) called these setters there without error before they were reactive.
|
|
552
|
+
*/
|
|
553
|
+
changed() {
|
|
554
|
+
untracked(() => this.version.update((v) => v + 1));
|
|
555
|
+
}
|
|
515
556
|
/** A consumer's own scale from `setScale()`; replaces the default palette while set. */
|
|
516
557
|
customScale = null;
|
|
517
558
|
/**
|
|
@@ -534,6 +575,7 @@ class PcacColorService {
|
|
|
534
575
|
* @param numberOfNodes Number of items in dynamically build collection of colors
|
|
535
576
|
*/
|
|
536
577
|
getColorScale(numberOfNodes) {
|
|
578
|
+
this.version();
|
|
537
579
|
const palette = [];
|
|
538
580
|
for (let i = 0; i < numberOfNodes; i++) {
|
|
539
581
|
const mark = i % this.scale.length;
|
|
@@ -542,6 +584,7 @@ class PcacColorService {
|
|
|
542
584
|
return palette;
|
|
543
585
|
}
|
|
544
586
|
getAlert() {
|
|
587
|
+
this.version();
|
|
545
588
|
return this.alert;
|
|
546
589
|
}
|
|
547
590
|
/**
|
|
@@ -552,36 +595,45 @@ class PcacColorService {
|
|
|
552
595
|
*/
|
|
553
596
|
setScale(colors) {
|
|
554
597
|
this.customScale = colors.length ? [...colors] : null;
|
|
598
|
+
this.changed();
|
|
555
599
|
}
|
|
556
600
|
/** @deprecated No chart reads the primary color; it isn't part of the palette. */
|
|
557
601
|
setPrimary(color) {
|
|
558
602
|
this.primary = color;
|
|
603
|
+
this.changed();
|
|
559
604
|
}
|
|
560
605
|
setPrimaryLight(color) {
|
|
561
606
|
this.primaryLight = color;
|
|
607
|
+
this.changed();
|
|
562
608
|
}
|
|
563
609
|
setSuccess(color) {
|
|
564
610
|
this.success = color;
|
|
611
|
+
this.changed();
|
|
565
612
|
}
|
|
566
613
|
setDanger(color) {
|
|
567
614
|
this.danger = color;
|
|
615
|
+
this.changed();
|
|
568
616
|
}
|
|
569
617
|
setWarning(color) {
|
|
570
618
|
this.warning = color;
|
|
619
|
+
this.changed();
|
|
571
620
|
}
|
|
572
621
|
setOrange(color) {
|
|
573
622
|
this.orange = color;
|
|
623
|
+
this.changed();
|
|
574
624
|
}
|
|
575
625
|
setBlue(color) {
|
|
576
626
|
this.blue = color;
|
|
627
|
+
this.changed();
|
|
577
628
|
}
|
|
578
629
|
setAlert(color) {
|
|
579
630
|
this.alert = color;
|
|
631
|
+
this.changed();
|
|
580
632
|
}
|
|
581
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
582
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.
|
|
633
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacColorService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
634
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacColorService, providedIn: 'root' });
|
|
583
635
|
}
|
|
584
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
636
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacColorService, decorators: [{
|
|
585
637
|
type: Injectable,
|
|
586
638
|
args: [{
|
|
587
639
|
providedIn: 'root',
|
|
@@ -593,10 +645,10 @@ class PcacTransitionService {
|
|
|
593
645
|
getTransitionDuration() {
|
|
594
646
|
return this.transitionDuration;
|
|
595
647
|
}
|
|
596
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
597
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.
|
|
648
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacTransitionService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
649
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacTransitionService, providedIn: 'root' });
|
|
598
650
|
}
|
|
599
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
651
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacTransitionService, decorators: [{
|
|
600
652
|
type: Injectable,
|
|
601
653
|
args: [{
|
|
602
654
|
providedIn: 'root',
|
|
@@ -663,13 +715,6 @@ class PcacTooltipBuilder {
|
|
|
663
715
|
this.positionAbove(shell, event);
|
|
664
716
|
}
|
|
665
717
|
}
|
|
666
|
-
/**
|
|
667
|
-
* @deprecated Builders should call `PcacChart.showTooltip()`, which routes through a chart's
|
|
668
|
-
* projected `pcacTooltip` template. This only ever renders the default content.
|
|
669
|
-
*/
|
|
670
|
-
showBarTooltip(event, data, valueFormat, keyFormat) {
|
|
671
|
-
this.showTooltip(event, undefined, { $implicit: data, parent: null, isThreshold: false, index: 0, parentIndex: null, coincident: [] }, valueFormat, keyFormat);
|
|
672
|
-
}
|
|
673
718
|
/**
|
|
674
719
|
* Hides the tooltip. Given an `owner`, only if that owner is the one showing it - so a chart can
|
|
675
720
|
* release the tooltip on rebuild or destroy without closing one another chart has open. Without
|
|
@@ -759,12 +804,25 @@ class PcacTooltipBuilder {
|
|
|
759
804
|
}
|
|
760
805
|
/**
|
|
761
806
|
* Centers the tooltip horizontally on the cursor and sits it just above. Measured from the real
|
|
762
|
-
* box rather than fixed offsets so it works for content of any size.
|
|
807
|
+
* box rather than fixed offsets so it works for content of any size. Kept on screen like
|
|
808
|
+
* `positionBeside`: slid in from whichever side edge it would cross (the left one winning if it's
|
|
809
|
+
* wider than the viewport), and dropped below the cursor when there's no room above - hovering
|
|
810
|
+
* a bar at the page's edge used to cut the tooltip off.
|
|
763
811
|
*/
|
|
764
812
|
positionAbove(shell, event) {
|
|
813
|
+
const gap = PcacTooltipBuilder.GAP;
|
|
814
|
+
const width = shell.offsetWidth;
|
|
815
|
+
const height = shell.offsetHeight;
|
|
816
|
+
const viewport = this.document.documentElement;
|
|
817
|
+
const scrollX = this.document.defaultView?.scrollX ?? 0;
|
|
818
|
+
const scrollY = this.document.defaultView?.scrollY ?? 0;
|
|
819
|
+
const centered = event.pageX - width / 2;
|
|
820
|
+
const left = Math.max(scrollX, Math.min(centered, scrollX + viewport.clientWidth - width));
|
|
821
|
+
const above = event.pageY - height - gap;
|
|
822
|
+
const top = above >= scrollY ? above : event.pageY + gap;
|
|
765
823
|
this.tooltip
|
|
766
|
-
.style('left',
|
|
767
|
-
.style('top',
|
|
824
|
+
.style('left', left + 'px')
|
|
825
|
+
.style('top', top + 'px');
|
|
768
826
|
}
|
|
769
827
|
/**
|
|
770
828
|
* Places the tooltip diagonally off one corner of `anchor`'s rendered box, so it never covers
|
|
@@ -798,30 +856,29 @@ class PcacTooltipBuilder {
|
|
|
798
856
|
getBarTipData(data, valueFormat, keyFormat) {
|
|
799
857
|
let value = data.value;
|
|
800
858
|
let key = data.key;
|
|
859
|
+
// Formatted the way the value's axis labels it (see `formatValue`), so the tooltip for a
|
|
860
|
+
// point reads like the axis it sits against - `1:30pm`, not `13.5`, on a OneDayHours axis.
|
|
801
861
|
// A missing value stays blank rather than being formatted as `0%` / `null F`.
|
|
802
|
-
if (
|
|
803
|
-
|
|
804
|
-
case PcacFormatEnum.Percentage:
|
|
805
|
-
// Same fraction rule, and the same formatting, as a Percentage axis's ticks.
|
|
806
|
-
value = formatPercent(Number(value));
|
|
807
|
-
break;
|
|
808
|
-
case PcacFormatEnum.Fahrenheit:
|
|
809
|
-
value = `${value} F`;
|
|
810
|
-
break;
|
|
811
|
-
}
|
|
862
|
+
if (value !== null && value !== undefined) {
|
|
863
|
+
value = formatValue(valueFormat, value) ?? value;
|
|
812
864
|
}
|
|
813
|
-
if (key &&
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
865
|
+
if (key !== null && key !== undefined && key !== '') {
|
|
866
|
+
// A key that doesn't parse as a date is shown as it is, rather than as "Invalid Date".
|
|
867
|
+
if (keyFormat === PcacFormatEnum.DateTime && !Number.isNaN(new Date(key).getTime())) {
|
|
868
|
+
key = new Date(key).toLocaleDateString('en-US', {
|
|
869
|
+
day: '2-digit',
|
|
870
|
+
month: '2-digit',
|
|
871
|
+
year: 'numeric',
|
|
872
|
+
hour: '2-digit',
|
|
873
|
+
minute: '2-digit',
|
|
874
|
+
second: '2-digit'
|
|
875
|
+
});
|
|
876
|
+
}
|
|
877
|
+
else if (keyFormat === PcacFormatEnum.Decimal) {
|
|
878
|
+
// Only where the key *is* the x value. Every other x format positions points by index,
|
|
879
|
+
// so its axis labels the index, not the key - formatting the key would only make it
|
|
880
|
+
// disagree with the axis (and tag text keys with a unit: `Mon` read `Monm` on Minutes).
|
|
881
|
+
key = formatValue(keyFormat, key) ?? key;
|
|
825
882
|
}
|
|
826
883
|
}
|
|
827
884
|
// A key of 0 (e.g. hour 0) is a real key; only a missing or empty one leaves the line out.
|
|
@@ -830,16 +887,22 @@ class PcacTooltipBuilder {
|
|
|
830
887
|
value: value === null || value === undefined ? '' : String(value),
|
|
831
888
|
};
|
|
832
889
|
}
|
|
833
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
834
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.
|
|
890
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacTooltipBuilder, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
891
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacTooltipBuilder, providedIn: 'root' });
|
|
835
892
|
}
|
|
836
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
893
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacTooltipBuilder, decorators: [{
|
|
837
894
|
type: Injectable,
|
|
838
895
|
args: [{
|
|
839
896
|
providedIn: 'root',
|
|
840
897
|
}]
|
|
841
898
|
}] });
|
|
842
899
|
|
|
900
|
+
/** The most of its container's width a chart's measured left (label) margin may take. */
|
|
901
|
+
const MAX_LABEL_MARGIN_SHARE = 0.5;
|
|
902
|
+
/** D3's gap between a tick and its label (`axis.tickPadding()`), which the builders never change. */
|
|
903
|
+
const TICK_PADDING = 3;
|
|
904
|
+
/** D3's default tick length (`axis.tickSizeInner()`), used while an axis's `tickSize` isn't set. */
|
|
905
|
+
const DEFAULT_TICK_SIZE = 6;
|
|
843
906
|
// Decorated only so Angular accepts its `ngOnDestroy` hook, which the builders extending it inherit;
|
|
844
907
|
// never provided itself - each builder is provided by its own chart component.
|
|
845
908
|
class PcacChart {
|
|
@@ -866,9 +929,20 @@ class PcacChart {
|
|
|
866
929
|
width = 400;
|
|
867
930
|
height = 400;
|
|
868
931
|
colors = [];
|
|
932
|
+
/**
|
|
933
|
+
* How wide a y-axis tick label may be once `setHorizontalMarginsBasedOnContent` has capped the
|
|
934
|
+
* margin, or `null` while the labels fit as they are. See `truncateYTickLabels`.
|
|
935
|
+
*/
|
|
936
|
+
yTickLabelMaxWidth = null;
|
|
869
937
|
startData = [];
|
|
870
938
|
/** The chart's accessible name when its config gives no `ariaLabel`; each builder names its type. */
|
|
871
939
|
chartTypeLabel = 'Chart';
|
|
940
|
+
/** Grows the palette to at least `count` colors, repeating it as `getColorScale` does. */
|
|
941
|
+
ensureColorCount(count) {
|
|
942
|
+
if (this.colors.length < count) {
|
|
943
|
+
this.colors = this.colorService.getColorScale(count);
|
|
944
|
+
}
|
|
945
|
+
}
|
|
872
946
|
/**
|
|
873
947
|
* Swaps a consumer's `colorOverride` in for the theme palette `initializeChartState` set, in
|
|
874
948
|
* order. Checks `length` rather than truthiness: every config class defaults its override to
|
|
@@ -1091,18 +1165,6 @@ class PcacChart {
|
|
|
1091
1165
|
ngOnDestroy() {
|
|
1092
1166
|
this.hideTooltip();
|
|
1093
1167
|
}
|
|
1094
|
-
/**
|
|
1095
|
-
* Prior to building a chart, we need to initialize the state of the chart.
|
|
1096
|
-
*
|
|
1097
|
-
* Returns `false` (and leaves `width`/`height`/`colors` untouched) if the container hasn't
|
|
1098
|
-
* been laid out yet, so its `clientWidth` measures 0 — this happens when a chart mounts
|
|
1099
|
-
* already holding data (e.g. behind a loading gate) and its first `ngOnChanges` fires before
|
|
1100
|
-
* the browser has committed layout for its own just-created DOM node. Callers should bail out
|
|
1101
|
-
* of their build on `false` rather than proceeding with a degenerate width; `PcacChartResizeService`
|
|
1102
|
-
* (wired up by every chart component) retries the build once the container has a real size.
|
|
1103
|
-
* @param chartElm Reference to SVG on dom
|
|
1104
|
-
* @param config Chart specific configuration
|
|
1105
|
-
*/
|
|
1106
1168
|
/**
|
|
1107
1169
|
* Removes whatever the chart last drew, for a build with no data to draw. Builders call it
|
|
1108
1170
|
* rather than just returning, which left the previous data on screen when a consumer emptied
|
|
@@ -1112,14 +1174,38 @@ class PcacChart {
|
|
|
1112
1174
|
this.hideTooltip();
|
|
1113
1175
|
select(chartElm.nativeElement).select('g').remove();
|
|
1114
1176
|
}
|
|
1177
|
+
/**
|
|
1178
|
+
* Prior to building a chart, we need to initialize the state of the chart.
|
|
1179
|
+
*
|
|
1180
|
+
* Returns `false` (and leaves `width`/`height`/`colors` untouched) if the container hasn't
|
|
1181
|
+
* been laid out yet, so its `clientWidth` measures 0 — this happens when a chart mounts
|
|
1182
|
+
* already holding data (e.g. behind a loading gate) and its first build `effect` run fires
|
|
1183
|
+
* before the browser has committed layout for its own just-created DOM node. Callers should
|
|
1184
|
+
* bail out of their build on `false` rather than proceeding with a degenerate width;
|
|
1185
|
+
* `PcacChartResizeService` (wired up by every chart component) retries the build once the
|
|
1186
|
+
* container has a real size.
|
|
1187
|
+
* @param chartElm Reference to SVG on dom
|
|
1188
|
+
* @param config Chart specific configuration
|
|
1189
|
+
*/
|
|
1115
1190
|
initializeChartState(chartElm, config) {
|
|
1116
1191
|
// The rebuild removes the hovered element, which gets no mouseout to close its tooltip.
|
|
1117
1192
|
this.hideTooltip();
|
|
1118
1193
|
select(chartElm.nativeElement).select('g').remove();
|
|
1194
|
+
// One color per group or per series within a group, whichever needs more. Bar charts, which
|
|
1195
|
+
// color by series across groups, top this up with `ensureColorCount()`. Read before the width
|
|
1196
|
+
// check below, even though a build that fails it draws nothing: this runs inside each chart
|
|
1197
|
+
// component's build `effect`, and reading the palette is what makes that effect redraw the
|
|
1198
|
+
// chart when the palette changes (see `PcacColorService`) - including a chart whose first
|
|
1199
|
+
// build found its container not laid out yet. (A loop rather than `Math.max(...)` over the
|
|
1200
|
+
// groups: spreading one argument per group overflows the call stack at a few hundred thousand.)
|
|
1201
|
+
const colors = this.colorService.getColorScale(config.data.reduce((max, d) => Math.max(max, d.data?.length ?? 0), config.data.length));
|
|
1119
1202
|
const container = chartElm.nativeElement.parentNode;
|
|
1120
1203
|
const containerWidth = container.clientWidth;
|
|
1121
1204
|
const measuredWidth = containerWidth - this.margin.left - this.margin.right;
|
|
1122
|
-
|
|
1205
|
+
// `!(> 0)` rather than `<= 0`, so a width that can't be measured at all - `NaN`, as when a page
|
|
1206
|
+
// is rendered on the server, where there's no layout and `clientWidth` is undefined - also
|
|
1207
|
+
// draws nothing, rather than drawing a chart `NaN` pixels wide.
|
|
1208
|
+
if (!(measuredWidth > 0)) {
|
|
1123
1209
|
// The previous drawing was just removed above, so nothing is on screen any more. Forget the
|
|
1124
1210
|
// size it was drawn at, or a container that comes back at that same width (a hidden tab
|
|
1125
1211
|
// shown again) would read as unchanged to `containerSizeChanged()` and never be redrawn.
|
|
@@ -1132,9 +1218,7 @@ class PcacChart {
|
|
|
1132
1218
|
.attr('role', 'img')
|
|
1133
1219
|
.attr('aria-label', config.ariaLabel || this.chartTypeLabel);
|
|
1134
1220
|
this.height = this.resolveHeight(container, config);
|
|
1135
|
-
|
|
1136
|
-
// largest group, since bars index colors by their position within their own group.
|
|
1137
|
-
this.colors = this.colorService.getColorScale(Math.max(config.data.length, ...config.data.map((d) => d.data?.length ?? 0)));
|
|
1221
|
+
this.colors = colors;
|
|
1138
1222
|
this.lastContainerWidth = containerWidth;
|
|
1139
1223
|
this.lastContainerHeight = container.clientHeight;
|
|
1140
1224
|
this.lastHeightFull = config.heightFull === true;
|
|
@@ -1172,9 +1256,10 @@ class PcacChart {
|
|
|
1172
1256
|
* `PcacChartResizeService`'s `ResizeObserver` is guaranteed to fire once as soon as it starts
|
|
1173
1257
|
* observing — that's what lets a chart recover from the 0-width race described on
|
|
1174
1258
|
* `initializeChartState`, but it also means that "routine" first callback usually lands
|
|
1175
|
-
* moments after `
|
|
1176
|
-
* check, that redundant callback would restart the chart's enter transition
|
|
1177
|
-
* no visual change. Only
|
|
1259
|
+
* moments after the component's build `effect` already built successfully at the same width.
|
|
1260
|
+
* Without this check, that redundant callback would restart the chart's enter transition
|
|
1261
|
+
* mid-animation for no visual change. Only that effect (which reacts to config, not size) should
|
|
1262
|
+
* skip this check.
|
|
1178
1263
|
* @param chartElm Reference to SVG on dom
|
|
1179
1264
|
*/
|
|
1180
1265
|
containerSizeChanged(chartElm) {
|
|
@@ -1227,10 +1312,16 @@ class PcacChart {
|
|
|
1227
1312
|
* the label, so measuring at a different length would put the labels off by the difference)
|
|
1228
1313
|
* and adds its `axisLabelSpace()` back on top, since the measurement replaces whatever
|
|
1229
1314
|
* `initializeAxisState()` reserved for the label / sub labels.
|
|
1315
|
+
*
|
|
1316
|
+
* The margin never takes more than `MAX_LABEL_MARGIN_SHARE` of the container: labels wider than
|
|
1317
|
+
* that are cut off at the chart's left edge rather than squeezing the plot to nothing (it used
|
|
1318
|
+
* to go to a negative width, and no bars drew at all). Returns `false`, like
|
|
1319
|
+
* `initializeChartState()`, if there is still no room left to draw in.
|
|
1230
1320
|
* @param chartElm Reference to SVG on dom
|
|
1231
1321
|
* @param yScale D3 scale transformation object (d3.ScaleBand)
|
|
1232
1322
|
*/
|
|
1233
1323
|
setHorizontalMarginsBasedOnContent(chartElm, yScale) {
|
|
1324
|
+
this.yTickLabelMaxWidth = null;
|
|
1234
1325
|
const axisY = axisLeft(yScale).ticks(5);
|
|
1235
1326
|
if (this.yAxis.tickSize !== undefined) {
|
|
1236
1327
|
axisY.tickSizeInner(this.yAxis.tickSize);
|
|
@@ -1250,22 +1341,72 @@ class PcacChart {
|
|
|
1250
1341
|
// double-counted it, and since `margin` persists on the builder between builds, the amount
|
|
1251
1342
|
// double-counted grew on the next rebuild - the plot area came out narrower than the
|
|
1252
1343
|
// container allowed and then shrank further after the first resize.
|
|
1253
|
-
const
|
|
1344
|
+
const containerWidth = this.width + this.margin.left + this.margin.right;
|
|
1345
|
+
const labelSpace = axisLabelSpace(this.yAxis);
|
|
1346
|
+
const left = Math.min(max + labelSpace, containerWidth * MAX_LABEL_MARGIN_SHARE);
|
|
1254
1347
|
this.width = this.width + this.margin.left - left;
|
|
1255
1348
|
this.margin.left = left;
|
|
1349
|
+
if (left < max + labelSpace) {
|
|
1350
|
+
// Capped: the labels are shortened to what's left between the axis title's band and the
|
|
1351
|
+
// ticks (see `truncateYTickLabels`), rather than running on past the chart's edge - and
|
|
1352
|
+
// over the title.
|
|
1353
|
+
const tickOverhead = Math.max(this.yAxis.tickSize ?? DEFAULT_TICK_SIZE, 0) + TICK_PADDING;
|
|
1354
|
+
this.yTickLabelMaxWidth = Math.max(0, left - labelSpace - tickOverhead);
|
|
1355
|
+
}
|
|
1356
|
+
return this.width > 0;
|
|
1256
1357
|
}
|
|
1257
|
-
|
|
1258
|
-
|
|
1358
|
+
/**
|
|
1359
|
+
* Shortens every y-axis tick label wider than the room `setHorizontalMarginsBasedOnContent` left
|
|
1360
|
+
* for it, ending it in "…". Call after the axis is drawn. Does nothing when the labels fit.
|
|
1361
|
+
*/
|
|
1362
|
+
truncateYTickLabels() {
|
|
1363
|
+
const maxWidth = this.yTickLabelMaxWidth;
|
|
1364
|
+
if (maxWidth === null) {
|
|
1365
|
+
return;
|
|
1366
|
+
}
|
|
1367
|
+
this.svg.selectAll('.pcac-y-axis .tick text').each(function () {
|
|
1368
|
+
fitText(this, maxWidth);
|
|
1369
|
+
});
|
|
1370
|
+
}
|
|
1371
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacChart, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1372
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacChart });
|
|
1259
1373
|
}
|
|
1260
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
1374
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacChart, decorators: [{
|
|
1261
1375
|
type: Injectable
|
|
1262
1376
|
}] });
|
|
1377
|
+
/**
|
|
1378
|
+
* Shortens `text` to the longest prefix that, with "…" appended, fits in `maxWidth` - just "…"
|
|
1379
|
+
* if nothing does. Measured with `getComputedTextLength()`, so the text must be rendered; left
|
|
1380
|
+
* alone where that isn't available (a DOM without layout).
|
|
1381
|
+
*/
|
|
1382
|
+
function fitText(text, maxWidth) {
|
|
1383
|
+
if (typeof text.getComputedTextLength !== 'function' || text.getComputedTextLength() <= maxWidth) {
|
|
1384
|
+
return;
|
|
1385
|
+
}
|
|
1386
|
+
const full = text.textContent ?? '';
|
|
1387
|
+
const withEllipsis = (length) => full.slice(0, length).trimEnd() + '…';
|
|
1388
|
+
let fits = 0;
|
|
1389
|
+
let tooLong = full.length;
|
|
1390
|
+
while (tooLong - fits > 1) {
|
|
1391
|
+
const mid = Math.floor((fits + tooLong) / 2);
|
|
1392
|
+
text.textContent = withEllipsis(mid);
|
|
1393
|
+
if (text.getComputedTextLength() <= maxWidth) {
|
|
1394
|
+
fits = mid;
|
|
1395
|
+
}
|
|
1396
|
+
else {
|
|
1397
|
+
tooLong = mid;
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
text.textContent = withEllipsis(fits);
|
|
1401
|
+
}
|
|
1263
1402
|
|
|
1264
1403
|
/**
|
|
1265
1404
|
* How long each bar is drawn: its value, or 0 when it can't be drawn - a null or non-numeric
|
|
1266
1405
|
* value, or `hide` set on the bar or on its whole group. A hidden bar keeps its slot (and so its
|
|
1267
1406
|
* color) and just draws nothing, the same way a hidden line/area/plot series keeps its place.
|
|
1268
|
-
*
|
|
1407
|
+
* A negative value is drawn as 0 too: the bar charts only draw upward from a 0 baseline, and a
|
|
1408
|
+
* negative size was an invalid SVG `height`/`width` (the bar vanished with a console error) that
|
|
1409
|
+
* also pulled the rest of a stack down over the bars before it.
|
|
1269
1410
|
*
|
|
1270
1411
|
* Keyed by the bar's own `PcacData` object so D3 callbacks (which only get the datum) can look
|
|
1271
1412
|
* their size up directly.
|
|
@@ -1275,7 +1416,7 @@ function barSizes(groups) {
|
|
|
1275
1416
|
for (const group of groups) {
|
|
1276
1417
|
for (const bar of group.data ?? []) {
|
|
1277
1418
|
const value = Number(bar.value ?? 0);
|
|
1278
|
-
sizes.set(bar, group.hide || bar.hide || !Number.isFinite(value) ? 0 : value);
|
|
1419
|
+
sizes.set(bar, group.hide || bar.hide || !Number.isFinite(value) ? 0 : Math.max(0, value));
|
|
1279
1420
|
}
|
|
1280
1421
|
}
|
|
1281
1422
|
return sizes;
|
|
@@ -1359,6 +1500,27 @@ function seriesKeys(groups) {
|
|
|
1359
1500
|
}
|
|
1360
1501
|
return [...keys];
|
|
1361
1502
|
}
|
|
1503
|
+
/**
|
|
1504
|
+
* Whether every bar has a key that is unique within its own group - what coloring bars by series
|
|
1505
|
+
* key needs. Without that (keys left `null`, as `PcacData` defaults them, or repeated within a
|
|
1506
|
+
* group, as stacked data often has), coloring by key would paint every bar sharing a key the
|
|
1507
|
+
* same color, so the bars fall back to being colored by their position in the group.
|
|
1508
|
+
*/
|
|
1509
|
+
function hasDistinctSeriesKeys(groups) {
|
|
1510
|
+
return groups.every((group) => {
|
|
1511
|
+
const keys = (group.data ?? []).map((bar) => bar.key);
|
|
1512
|
+
return keys.every((key) => key !== null && key !== undefined && key !== '')
|
|
1513
|
+
&& new Set(keys).size === keys.length;
|
|
1514
|
+
});
|
|
1515
|
+
}
|
|
1516
|
+
/**
|
|
1517
|
+
* Whether a band scale spanning `length` pixels across `count` bands can round them to whole
|
|
1518
|
+
* pixels. Rounding gives crisp bar edges, but it floors the step - so with more bands than pixels
|
|
1519
|
+
* every band collapses to 0 and nothing draws. Only rounded while each band gets at least 2px.
|
|
1520
|
+
*/
|
|
1521
|
+
function canRoundBands(length, count) {
|
|
1522
|
+
return count > 0 && length / count >= 2;
|
|
1523
|
+
}
|
|
1362
1524
|
|
|
1363
1525
|
/**
|
|
1364
1526
|
* Provided per-component (see PcacBarHorizontalChartComponent's `providers`), not root-scoped:
|
|
@@ -1371,7 +1533,6 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
1371
1533
|
yScaleStacked;
|
|
1372
1534
|
yScaleGrouped;
|
|
1373
1535
|
barClickedSource = new Subject();
|
|
1374
|
-
config;
|
|
1375
1536
|
barClicked$ = this.barClickedSource.asObservable();
|
|
1376
1537
|
chartTypeLabel = 'Bar chart';
|
|
1377
1538
|
buildChart(chartElm, config) {
|
|
@@ -1379,15 +1540,23 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
1379
1540
|
this.clearChart(chartElm);
|
|
1380
1541
|
return;
|
|
1381
1542
|
}
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1543
|
+
// Shallow copy, as the vertical chart does: initializeAxisState() rewrites `height`, which
|
|
1544
|
+
// must not land on the consumer's config - but the data stays the consumer's own objects, so
|
|
1545
|
+
// `barClicked` and the tooltip hand back the very `PcacData` they passed in. (A JSON deep copy
|
|
1546
|
+
// used to hand back clones, which never matched the consumer's data by identity.)
|
|
1547
|
+
config = { ...config };
|
|
1548
|
+
this.initializeAxisState(config, 'x');
|
|
1549
|
+
if (!this.initializeChartState(chartElm, config)) {
|
|
1385
1550
|
return;
|
|
1386
1551
|
}
|
|
1552
|
+
this.ensureColorCount(seriesKeys(config.data).length);
|
|
1387
1553
|
this.applyColorOverride(config.colorOverride?.colors);
|
|
1388
|
-
this.buildScales(chartElm,
|
|
1389
|
-
|
|
1554
|
+
if (!this.buildScales(chartElm, config)) {
|
|
1555
|
+
return;
|
|
1556
|
+
}
|
|
1557
|
+
this.drawChart(chartElm, config);
|
|
1390
1558
|
}
|
|
1559
|
+
/** Returns `false` if the container leaves no room to draw in once the labels are measured. */
|
|
1391
1560
|
buildScales(chartElm, config) {
|
|
1392
1561
|
// Bars grow from 0, so only `domainMax` is read; `xAxis.domainMin` is ignored.
|
|
1393
1562
|
this.xScale = scaleLinear()
|
|
@@ -1395,20 +1564,25 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
1395
1564
|
this.yScaleStacked = scaleBand()
|
|
1396
1565
|
.domain(config.data.map((d) => d.key))
|
|
1397
1566
|
.range([this.height, 0])
|
|
1567
|
+
// Rounded to whole pixels for crisp bar edges, while there's room to (see canRoundBands).
|
|
1568
|
+
.round(canRoundBands(this.height, config.data.length))
|
|
1398
1569
|
.padding(0.1);
|
|
1399
1570
|
this.yScaleGrouped = scaleBand()
|
|
1400
1571
|
.padding(0.05)
|
|
1401
|
-
.
|
|
1572
|
+
.range([0, this.yScaleStacked.bandwidth()])
|
|
1573
|
+
.round(canRoundBands(this.yScaleStacked.bandwidth(), seriesKeys(config.data).length))
|
|
1402
1574
|
.domain(seriesKeys(config.data));
|
|
1403
1575
|
// The left margin is sized to the y axis's labels - unless there is no y axis to size it to
|
|
1404
|
-
if (!this.yAxis.hide) {
|
|
1405
|
-
|
|
1576
|
+
if (!this.yAxis.hide && !this.setHorizontalMarginsBasedOnContent(chartElm, this.yScaleStacked)) {
|
|
1577
|
+
return false;
|
|
1406
1578
|
}
|
|
1407
1579
|
this.xScale.range([0, this.width]);
|
|
1580
|
+
return true;
|
|
1408
1581
|
}
|
|
1409
1582
|
drawChart(chartElm, config) {
|
|
1410
1583
|
this.buildContainer(chartElm);
|
|
1411
1584
|
this.axisBuilder.drawAxis(this.axisBuilderConfig(this.xScale, this.yScaleStacked));
|
|
1585
|
+
this.truncateYTickLabels();
|
|
1412
1586
|
this.drawGrids(this.xScale, this.yScaleStacked);
|
|
1413
1587
|
this.addGroups(config);
|
|
1414
1588
|
this.axisBuilder.raiseAxes(this.svg);
|
|
@@ -1451,60 +1625,53 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
1451
1625
|
const starts = config.isStacked ? stackStarts(config.data, sizes) : new Map();
|
|
1452
1626
|
const startOf = (d) => starts.get(d) ?? 0;
|
|
1453
1627
|
const endOf = (d) => startOf(d) + (sizes.get(d) ?? 0);
|
|
1628
|
+
// Colored by series - the bar's key's place among every group's keys, the same slot it's drawn
|
|
1629
|
+
// in - rather than by its position in its own group, which differs when groups hold different
|
|
1630
|
+
// series. By position after all when the keys can't tell series apart (see
|
|
1631
|
+
// `hasDistinctSeriesKeys`), and with `spreadColorsPerGroup`, by group instead.
|
|
1632
|
+
const keys = seriesKeys(config.data);
|
|
1633
|
+
const byKey = hasDistinctSeriesKeys(config.data);
|
|
1634
|
+
const fillOf = (d, bar) => {
|
|
1635
|
+
if (config.spreadColorsPerGroup) {
|
|
1636
|
+
return this.colors[Number(bar.parentNode.getAttribute('data-group-id'))];
|
|
1637
|
+
}
|
|
1638
|
+
return this.colors[byKey ? keys.indexOf(d.key) : Number(bar.getAttribute('data-group-bar-id'))];
|
|
1639
|
+
};
|
|
1454
1640
|
groups.enter().append('rect')
|
|
1455
1641
|
.attr('class', 'pcac-bar')
|
|
1456
1642
|
.attr('x', (d) => this.xScale(startOf(d)))
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1643
|
+
// A stacked bar spans its whole group, which is already translated into place; looking its
|
|
1644
|
+
// series key up in the group band put it off in another group's slot whenever the key
|
|
1645
|
+
// matched a group key.
|
|
1646
|
+
.attr('y', (d) => config.isStacked ? 0 : this.yScaleGrouped(d.key) ?? 0)
|
|
1461
1647
|
.attr('data-group-bar-id', (_, i) => {
|
|
1462
1648
|
return i;
|
|
1463
1649
|
})
|
|
1464
1650
|
.attr('height', !config.isStacked ? this.yScaleGrouped.bandwidth() : this.yScaleStacked.bandwidth())
|
|
1465
|
-
.style('fill', (d
|
|
1466
|
-
|
|
1467
|
-
const groupIndex = parseInt(n[0].parentNode.getAttribute('data-group-id'), 10);
|
|
1468
|
-
return this.colors[groupIndex];
|
|
1469
|
-
}
|
|
1470
|
-
return this.colors[i];
|
|
1651
|
+
.style('fill', function (d) {
|
|
1652
|
+
return fillOf(d, this);
|
|
1471
1653
|
})
|
|
1472
1654
|
.attr('width', 0)
|
|
1473
|
-
|
|
1655
|
+
// The hover fades run as their own named transition: an unnamed one would cancel the enter
|
|
1656
|
+
// transition still growing the bar, leaving it part-grown until the next rebuild.
|
|
1657
|
+
.on('mouseover', function (_event, d) {
|
|
1658
|
+
const fill = fillOf(d, this);
|
|
1474
1659
|
select(this)
|
|
1475
|
-
.transition()
|
|
1476
|
-
.duration(self.transitionService.getTransitionDuration() /
|
|
1477
|
-
.style('fill', ()
|
|
1478
|
-
if (config.spreadColorsPerGroup) {
|
|
1479
|
-
const groupIndex = parseInt(this.parentNode.getAttribute('data-group-id'), 10);
|
|
1480
|
-
const c = color(self.colors[groupIndex]);
|
|
1481
|
-
const ct = c ? c.darker(1).toString() : self.colors[groupIndex];
|
|
1482
|
-
return ct;
|
|
1483
|
-
}
|
|
1484
|
-
const groupIndex = parseInt(this.getAttribute('data-group-bar-id'), 10);
|
|
1485
|
-
const c = color(self.colors[groupIndex]);
|
|
1486
|
-
const ct = c ? c.darker(1).toString() : self.colors[groupIndex];
|
|
1487
|
-
return ct;
|
|
1488
|
-
});
|
|
1660
|
+
.transition('hover')
|
|
1661
|
+
.duration(self.transitionService.getTransitionDuration() / 5)
|
|
1662
|
+
.style('fill', color(fill)?.darker(1).toString() ?? fill);
|
|
1489
1663
|
})
|
|
1490
1664
|
.on('mousemove', function (event, d) {
|
|
1491
1665
|
const groupIndex = Number(this.parentNode.getAttribute('data-group-id'));
|
|
1492
1666
|
const index = Number(this.getAttribute('data-group-bar-id'));
|
|
1493
1667
|
self.showTooltip(event, d, { index, parent: config.data[groupIndex], parentIndex: groupIndex, valueFormat: self.xAxis.format });
|
|
1494
1668
|
})
|
|
1495
|
-
.on('mouseout', function () {
|
|
1669
|
+
.on('mouseout', function (_event, d) {
|
|
1496
1670
|
self.hideTooltip();
|
|
1497
1671
|
select(this)
|
|
1498
|
-
.transition()
|
|
1672
|
+
.transition('hover')
|
|
1499
1673
|
.duration(self.transitionService.getTransitionDuration() / 5)
|
|
1500
|
-
.style('fill', ()
|
|
1501
|
-
if (config.spreadColorsPerGroup) {
|
|
1502
|
-
const groupIndex = parseInt(this.parentNode.getAttribute('data-group-id'), 10);
|
|
1503
|
-
return self.colors[groupIndex];
|
|
1504
|
-
}
|
|
1505
|
-
const groupIndex = parseInt(this.getAttribute('data-group-bar-id'), 10);
|
|
1506
|
-
return self.colors[groupIndex];
|
|
1507
|
-
});
|
|
1674
|
+
.style('fill', fillOf(d, this));
|
|
1508
1675
|
})
|
|
1509
1676
|
.on('click', (_event, d) => {
|
|
1510
1677
|
this.barClickedSource.next(d);
|
|
@@ -1561,6 +1728,10 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
1561
1728
|
.attr('data-group-threshold-id', (_, i) => {
|
|
1562
1729
|
return i;
|
|
1563
1730
|
})
|
|
1731
|
+
// Placed in its bar's slot up front - only its value (`x`) animates. Set on the transition,
|
|
1732
|
+
// it slid in from the top of the group, where the vertical chart's appear in place.
|
|
1733
|
+
// ScaleBand can return undefined for a key outside its domain; `.attr()` needs null, not undefined.
|
|
1734
|
+
.attr('y', (d) => this.yScaleGrouped(d.key) ?? null)
|
|
1564
1735
|
.attr('height', this.yScaleGrouped.bandwidth());
|
|
1565
1736
|
rects.filter(function () {
|
|
1566
1737
|
return thresholdOf(this) === null;
|
|
@@ -1576,10 +1747,6 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
1576
1747
|
})
|
|
1577
1748
|
.transition()
|
|
1578
1749
|
.duration(this.transitionService.getTransitionDuration())
|
|
1579
|
-
.attr('y', (d) => {
|
|
1580
|
-
// ScaleBand can return undefined for a key outside its domain; `.attr()` needs null, not undefined.
|
|
1581
|
-
return this.yScaleGrouped(d.key) ?? null;
|
|
1582
|
-
})
|
|
1583
1750
|
.attr('x', (_, i, nodes) => {
|
|
1584
1751
|
return this.xScale(Number(thresholdOf(nodes[i])?.value));
|
|
1585
1752
|
});
|
|
@@ -1600,10 +1767,10 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
1600
1767
|
this.hideTooltip();
|
|
1601
1768
|
});
|
|
1602
1769
|
}
|
|
1603
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
1604
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.
|
|
1770
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: BarHorizontalChartBuilder, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
|
1771
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: BarHorizontalChartBuilder });
|
|
1605
1772
|
}
|
|
1606
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
1773
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: BarHorizontalChartBuilder, decorators: [{
|
|
1607
1774
|
type: Injectable
|
|
1608
1775
|
}] });
|
|
1609
1776
|
|
|
@@ -1613,7 +1780,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImpor
|
|
|
1613
1780
|
* A plain `window:resize` listener (the previous approach) misses any layout-driven size change
|
|
1614
1781
|
* that isn't a viewport resize — a sidebar collapsing, a tab becoming active, a flex/grid reflow.
|
|
1615
1782
|
* It also can't help a chart that mounts already holding data (e.g. behind a loading gate): that
|
|
1616
|
-
* chart's first `
|
|
1783
|
+
* chart's first build `effect` run can fire before the browser has committed layout for its own
|
|
1617
1784
|
* just-created DOM node, so `PcacChart.initializeChartState()` measures a 0-width container and
|
|
1618
1785
|
* bails out with nothing drawn — and with no resize ever firing, nothing retries it.
|
|
1619
1786
|
*
|
|
@@ -1656,10 +1823,10 @@ class PcacChartResizeService {
|
|
|
1656
1823
|
destroyRef.onDestroy(() => observer.disconnect());
|
|
1657
1824
|
});
|
|
1658
1825
|
}
|
|
1659
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
1660
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.
|
|
1826
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacChartResizeService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1827
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacChartResizeService, providedIn: 'root' });
|
|
1661
1828
|
}
|
|
1662
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
1829
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacChartResizeService, decorators: [{
|
|
1663
1830
|
type: Injectable,
|
|
1664
1831
|
args: [{ providedIn: 'root' }]
|
|
1665
1832
|
}] });
|
|
@@ -1709,10 +1876,10 @@ class PcacTooltipDirective {
|
|
|
1709
1876
|
static ngTemplateContextGuard(_dir, _ctx) {
|
|
1710
1877
|
return true;
|
|
1711
1878
|
}
|
|
1712
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
1713
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "22.
|
|
1879
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacTooltipDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1880
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "22.2.0", type: PcacTooltipDirective, isStandalone: true, selector: "ng-template[pcacTooltip]", ngImport: i0 });
|
|
1714
1881
|
}
|
|
1715
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
1882
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacTooltipDirective, decorators: [{
|
|
1716
1883
|
type: Directive,
|
|
1717
1884
|
args: [{
|
|
1718
1885
|
selector: 'ng-template[pcacTooltip]'
|
|
@@ -1756,10 +1923,10 @@ class PcacBarHorizontalChartComponent {
|
|
|
1756
1923
|
this.chartBuilder.buildChart(this.chartElm(), config);
|
|
1757
1924
|
}
|
|
1758
1925
|
}
|
|
1759
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
1760
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.
|
|
1926
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacBarHorizontalChartComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1927
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.2.0", type: PcacBarHorizontalChartComponent, isStandalone: true, selector: "pcac-bar-horizontal-chart", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { barClicked: "barClicked" }, host: { properties: { "class.pcac-height-full": "config().heightFull" } }, providers: [BarHorizontalChartBuilder], queries: [{ propertyName: "tooltipTemplate", first: true, predicate: PcacTooltipDirective, descendants: true, isSignal: true }], viewQueries: [{ propertyName: "chartElm", first: true, predicate: ["chart"], descendants: true, isSignal: true }], ngImport: i0, template: "<section class=\"pcac-bar-horizontal-chart\">\n <svg #chart></svg>\n</section>\n", styles: [".pcac-bar-horizontal-chart{display:block}.pcac-bar-horizontal-chart svg{width:100%;display:block}pcac-bar-horizontal-chart.pcac-height-full{display:block;height:100%}pcac-bar-horizontal-chart.pcac-height-full .pcac-bar-horizontal-chart{height:100%}\n"], encapsulation: i0.ViewEncapsulation.None });
|
|
1761
1928
|
}
|
|
1762
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
1929
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacBarHorizontalChartComponent, decorators: [{
|
|
1763
1930
|
type: Component,
|
|
1764
1931
|
args: [{ selector: 'pcac-bar-horizontal-chart', host: { '[class.pcac-height-full]': 'config().heightFull' }, encapsulation: ViewEncapsulation.None, providers: [BarHorizontalChartBuilder], template: "<section class=\"pcac-bar-horizontal-chart\">\n <svg #chart></svg>\n</section>\n", styles: [".pcac-bar-horizontal-chart{display:block}.pcac-bar-horizontal-chart svg{width:100%;display:block}pcac-bar-horizontal-chart.pcac-height-full{display:block;height:100%}pcac-bar-horizontal-chart.pcac-height-full .pcac-bar-horizontal-chart{height:100%}\n"] }]
|
|
1765
1932
|
}], ctorParameters: () => [], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }], chartElm: [{ type: i0.ViewChild, args: ['chart', { isSignal: true }] }], barClicked: [{ type: i0.Output, args: ["barClicked"] }], tooltipTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => PcacTooltipDirective), { isSignal: true }] }] } });
|
|
@@ -1800,6 +1967,7 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
1800
1967
|
if (!this.initializeChartState(chartElm, config)) {
|
|
1801
1968
|
return;
|
|
1802
1969
|
}
|
|
1970
|
+
this.ensureColorCount(seriesKeys(config.data).length);
|
|
1803
1971
|
this.applyColorOverride(config.colorOverride?.colors);
|
|
1804
1972
|
this.buildScales(config);
|
|
1805
1973
|
this.drawChart(chartElm, config);
|
|
@@ -1813,11 +1981,14 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
1813
1981
|
.domain([this.yAxis.domainMax, 0]);
|
|
1814
1982
|
this.xScaleStacked = scaleBand()
|
|
1815
1983
|
.domain(config.data.map((d) => d.key))
|
|
1816
|
-
.
|
|
1984
|
+
.range([0, this.width])
|
|
1985
|
+
// Rounded to whole pixels for crisp bar edges, while there's room to (see canRoundBands).
|
|
1986
|
+
.round(canRoundBands(this.width, config.data.length))
|
|
1817
1987
|
.padding(0.1);
|
|
1818
1988
|
this.xScaleGrouped = scaleBand()
|
|
1819
1989
|
.padding(0.2)
|
|
1820
|
-
.
|
|
1990
|
+
.range([0, this.xScaleStacked.bandwidth()])
|
|
1991
|
+
.round(canRoundBands(this.xScaleStacked.bandwidth(), seriesKeys(config.data).length))
|
|
1821
1992
|
.domain(seriesKeys(config.data));
|
|
1822
1993
|
}
|
|
1823
1994
|
drawChart(chartElm, config) {
|
|
@@ -1867,70 +2038,60 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
1867
2038
|
const starts = config.isStacked ? stackStarts(config.data, sizes) : new Map();
|
|
1868
2039
|
const startOf = (d) => starts.get(d) ?? 0;
|
|
1869
2040
|
const endOf = (d) => startOf(d) + (sizes.get(d) ?? 0);
|
|
2041
|
+
// Colored by series - the bar's key's place among every group's keys, the same slot it's drawn
|
|
2042
|
+
// in - rather than by its position in its own group, which differs when groups hold different
|
|
2043
|
+
// series. By position after all when the keys can't tell series apart (see
|
|
2044
|
+
// `hasDistinctSeriesKeys`), and with `spreadColorsPerGroup`, by group instead.
|
|
2045
|
+
const keys = seriesKeys(config.data);
|
|
2046
|
+
const byKey = hasDistinctSeriesKeys(config.data);
|
|
2047
|
+
const fillOf = (d, bar) => {
|
|
2048
|
+
if (config.spreadColorsPerGroup) {
|
|
2049
|
+
return this.colors[Number(bar.parentNode.getAttribute('data-group-id'))];
|
|
2050
|
+
}
|
|
2051
|
+
return this.colors[byKey ? keys.indexOf(d.key) : Number(bar.getAttribute('data-group-bar-id'))];
|
|
2052
|
+
};
|
|
1870
2053
|
group.enter().append('rect')
|
|
1871
2054
|
.attr('class', 'pcac-bar')
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
2055
|
+
// A stacked bar spans its whole group, which is already translated into place; looking its
|
|
2056
|
+
// series key up in the group band put it off in another group's slot whenever the key
|
|
2057
|
+
// matched a group key.
|
|
2058
|
+
.attr('x', (d) => config.isStacked ? 0 : this.xScaleGrouped(d.key) ?? 0)
|
|
1876
2059
|
.attr('data-group-bar-id', (_, i) => {
|
|
1877
2060
|
return i;
|
|
1878
2061
|
})
|
|
1879
|
-
.style('fill', (d
|
|
1880
|
-
|
|
1881
|
-
const groupIndex = parseInt(n[0].parentNode.getAttribute('data-group-id'), 10);
|
|
1882
|
-
return this.colors[groupIndex];
|
|
1883
|
-
}
|
|
1884
|
-
return this.colors[i];
|
|
2062
|
+
.style('fill', function (d) {
|
|
2063
|
+
return fillOf(d, this);
|
|
1885
2064
|
})
|
|
1886
2065
|
.attr('y', () => {
|
|
1887
2066
|
return this.height;
|
|
1888
2067
|
})
|
|
1889
2068
|
.attr('height', 0)
|
|
1890
|
-
|
|
2069
|
+
// The hover fades run as their own named transition: an unnamed one would cancel the enter
|
|
2070
|
+
// transition still growing the bar, leaving it part-grown until the next rebuild.
|
|
2071
|
+
.on('mouseover', function (_event, d) {
|
|
2072
|
+
const fill = fillOf(d, this);
|
|
1891
2073
|
select(this)
|
|
1892
|
-
.transition()
|
|
2074
|
+
.transition('hover')
|
|
1893
2075
|
.duration(self.transitionService.getTransitionDuration() / 5)
|
|
1894
|
-
.style('fill', ()
|
|
1895
|
-
if (config.spreadColorsPerGroup) {
|
|
1896
|
-
const groupIndex = parseInt(this.parentNode.getAttribute('data-group-id'), 10);
|
|
1897
|
-
const c = color(self.colors[groupIndex]);
|
|
1898
|
-
const ct = c ? c.darker(1).toString() : self.colors[groupIndex];
|
|
1899
|
-
return ct;
|
|
1900
|
-
}
|
|
1901
|
-
const groupIndex = parseInt(this.getAttribute('data-group-bar-id'), 10);
|
|
1902
|
-
const c = color(self.colors[groupIndex]);
|
|
1903
|
-
const ct = c ? c.darker(1).toString() : self.colors[groupIndex];
|
|
1904
|
-
return ct;
|
|
1905
|
-
});
|
|
2076
|
+
.style('fill', color(fill)?.darker(1).toString() ?? fill);
|
|
1906
2077
|
})
|
|
1907
2078
|
.on('mousemove', function (event, d) {
|
|
1908
2079
|
const groupIndex = Number(this.parentNode.getAttribute('data-group-id'));
|
|
1909
2080
|
const index = Number(this.getAttribute('data-group-bar-id'));
|
|
1910
2081
|
self.showTooltip(event, d, { index, parent: config.data[groupIndex], parentIndex: groupIndex, valueFormat: self.yAxis.format });
|
|
1911
2082
|
})
|
|
1912
|
-
.on('mouseout', function () {
|
|
2083
|
+
.on('mouseout', function (_event, d) {
|
|
1913
2084
|
self.hideTooltip();
|
|
1914
2085
|
select(this)
|
|
1915
|
-
.transition()
|
|
2086
|
+
.transition('hover')
|
|
1916
2087
|
.duration(self.transitionService.getTransitionDuration() / 5)
|
|
1917
|
-
.style('fill', ()
|
|
1918
|
-
if (config.spreadColorsPerGroup) {
|
|
1919
|
-
const groupIndex = parseInt(this.parentNode.getAttribute('data-group-id'), 10);
|
|
1920
|
-
return self.colors[groupIndex];
|
|
1921
|
-
}
|
|
1922
|
-
const groupIndex = parseInt(this.getAttribute('data-group-bar-id'), 10);
|
|
1923
|
-
return self.colors[groupIndex];
|
|
1924
|
-
});
|
|
2088
|
+
.style('fill', fillOf(d, this));
|
|
1925
2089
|
})
|
|
1926
2090
|
.on('click', (_, d) => {
|
|
1927
2091
|
this.barClickedSource.next(d);
|
|
1928
2092
|
})
|
|
1929
2093
|
.transition()
|
|
1930
2094
|
.duration(this.transitionService.getTransitionDuration())
|
|
1931
|
-
// .transition(
|
|
1932
|
-
// transition().duration(this.transitionService.getTransitionDuration())
|
|
1933
|
-
// )
|
|
1934
2095
|
.attr('width', !config.isStacked ? this.xScaleGrouped.bandwidth() : this.xScaleStacked.bandwidth())
|
|
1935
2096
|
.attr('y', (d) => {
|
|
1936
2097
|
return this.yScale(endOf(d));
|
|
@@ -2036,10 +2197,10 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
2036
2197
|
return '3px';
|
|
2037
2198
|
});
|
|
2038
2199
|
}
|
|
2039
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
2040
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.
|
|
2200
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: BarVerticalChartBuilder, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
|
2201
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: BarVerticalChartBuilder });
|
|
2041
2202
|
}
|
|
2042
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
2203
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: BarVerticalChartBuilder, decorators: [{
|
|
2043
2204
|
type: Injectable
|
|
2044
2205
|
}] });
|
|
2045
2206
|
|
|
@@ -2080,10 +2241,10 @@ class PcacBarVerticalChartComponent {
|
|
|
2080
2241
|
this.chartBuilder.buildChart(this.chartElm(), config);
|
|
2081
2242
|
}
|
|
2082
2243
|
}
|
|
2083
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
2084
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.
|
|
2244
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacBarVerticalChartComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
2245
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.2.0", type: PcacBarVerticalChartComponent, isStandalone: true, selector: "pcac-bar-vertical-chart", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { barClicked: "barClicked" }, host: { properties: { "class.pcac-height-full": "config().heightFull" } }, providers: [BarVerticalChartBuilder], queries: [{ propertyName: "tooltipTemplate", first: true, predicate: PcacTooltipDirective, descendants: true, isSignal: true }], viewQueries: [{ propertyName: "chartElm", first: true, predicate: ["chart"], descendants: true, isSignal: true }], ngImport: i0, template: "<section class=\"pcac-bar-vertical-chart\">\n <svg #chart></svg>\n</section>\n", styles: [".pcac-bar-vertical-chart svg{width:100%;display:block}pcac-bar-vertical-chart.pcac-height-full{display:block;height:100%}pcac-bar-vertical-chart.pcac-height-full .pcac-bar-vertical-chart{height:100%}\n"], encapsulation: i0.ViewEncapsulation.None });
|
|
2085
2246
|
}
|
|
2086
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
2247
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacBarVerticalChartComponent, decorators: [{
|
|
2087
2248
|
type: Component,
|
|
2088
2249
|
args: [{ selector: 'pcac-bar-vertical-chart', host: { '[class.pcac-height-full]': 'config().heightFull' }, encapsulation: ViewEncapsulation.None, providers: [BarVerticalChartBuilder], template: "<section class=\"pcac-bar-vertical-chart\">\n <svg #chart></svg>\n</section>\n", styles: [".pcac-bar-vertical-chart svg{width:100%;display:block}pcac-bar-vertical-chart.pcac-height-full{display:block;height:100%}pcac-bar-vertical-chart.pcac-height-full .pcac-bar-vertical-chart{height:100%}\n"] }]
|
|
2089
2250
|
}], ctorParameters: () => [], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }], chartElm: [{ type: i0.ViewChild, args: ['chart', { isSignal: true }] }], barClicked: [{ type: i0.Output, args: ["barClicked"] }], tooltipTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => PcacTooltipDirective), { isSignal: true }] }] } });
|
|
@@ -2123,12 +2284,12 @@ class PcacLegend {
|
|
|
2123
2284
|
this.config.set({ ...this.config(), items });
|
|
2124
2285
|
this.itemClicked.emit(items);
|
|
2125
2286
|
}
|
|
2126
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
2127
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.
|
|
2287
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacLegend, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
2288
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.2.0", type: PcacLegend, isStandalone: true, selector: "pcac-legend", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { config: "configChange", itemClicked: "itemClicked" }, ngImport: i0, template: "<div class=\"pcac-legend-label\"><small>{{config().heading}}</small></div>\n@for(item of config().items; track $index; let i = $index) {\n<div class=\"pcac-legend-item\" [class.pcac-legend-unchecked]=\"!item.checked\"\n role=\"switch\" [attr.aria-checked]=\"item.checked\" tabindex=\"0\" (click)=\"onItemClicked(i)\"\n (keydown.enter)=\"onItemClicked(i)\" (keydown.space)=\"onItemClicked(i); $event.preventDefault()\">\n @let color = item.colorOverride ? item.colorOverride : colorScale()[i];\n <div class=\"pcac-legend-circle\" [style.backgroundColor]=\"color\"></div>\n <small>{{ item.label }}</small>\n</div>\n}\n", styles: [":host{display:flex;align-items:center;flex-wrap:wrap;column-gap:8px}.pcac-legend-label{margin-bottom:2.5px}.pcac-legend-item{cursor:pointer;display:flex;align-items:center;min-height:24px}.pcac-legend-item:hover .pcac-legend-circle{box-shadow:0 0 6px #0000004d;transform:scale(1.2)}.pcac-legend-circle{display:inline-block;width:12px;height:12px;border-radius:50%;margin-right:4px;transition:box-shadow .3s ease,transform .3s ease}.pcac-legend-unchecked{opacity:.5}.pcac-legend-item:focus-visible{outline:2px solid currentColor;outline-offset:2px}\n"] });
|
|
2128
2289
|
}
|
|
2129
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
2290
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacLegend, decorators: [{
|
|
2130
2291
|
type: Component,
|
|
2131
|
-
args: [{ selector: 'pcac-legend', template: "<div class=\"pcac-legend-label\"><small>{{config().heading}}</small></div>\n@for(item of config().items; track $index; let i = $index
|
|
2292
|
+
args: [{ selector: 'pcac-legend', template: "<div class=\"pcac-legend-label\"><small>{{config().heading}}</small></div>\n@for(item of config().items; track $index; let i = $index) {\n<div class=\"pcac-legend-item\" [class.pcac-legend-unchecked]=\"!item.checked\"\n role=\"switch\" [attr.aria-checked]=\"item.checked\" tabindex=\"0\" (click)=\"onItemClicked(i)\"\n (keydown.enter)=\"onItemClicked(i)\" (keydown.space)=\"onItemClicked(i); $event.preventDefault()\">\n @let color = item.colorOverride ? item.colorOverride : colorScale()[i];\n <div class=\"pcac-legend-circle\" [style.backgroundColor]=\"color\"></div>\n <small>{{ item.label }}</small>\n</div>\n}\n", styles: [":host{display:flex;align-items:center;flex-wrap:wrap;column-gap:8px}.pcac-legend-label{margin-bottom:2.5px}.pcac-legend-item{cursor:pointer;display:flex;align-items:center;min-height:24px}.pcac-legend-item:hover .pcac-legend-circle{box-shadow:0 0 6px #0000004d;transform:scale(1.2)}.pcac-legend-circle{display:inline-block;width:12px;height:12px;border-radius:50%;margin-right:4px;transition:box-shadow .3s ease,transform .3s ease}.pcac-legend-unchecked{opacity:.5}.pcac-legend-item:focus-visible{outline:2px solid currentColor;outline-offset:2px}\n"] }]
|
|
2132
2293
|
}], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }, { type: i0.Output, args: ["configChange"] }], itemClicked: [{ type: i0.Output, args: ["itemClicked"] }] } });
|
|
2133
2294
|
|
|
2134
2295
|
var PcacLineAreaPlotChartConfigType;
|
|
@@ -2223,45 +2384,73 @@ class PcacLineAreaChartConfig extends PcacAxisChartConfig {
|
|
|
2223
2384
|
pointRange;
|
|
2224
2385
|
}
|
|
2225
2386
|
|
|
2387
|
+
/**
|
|
2388
|
+
* Whether a point has an x key to position by. An explicit emptiness check, not truthiness: a
|
|
2389
|
+
* Decimal key of `0` is a perfectly good coordinate (the left edge of a `domainMin: 0` axis) and
|
|
2390
|
+
* used to be read as "no key" - drawn at pixel 0 whatever the domain, and pinned there under zoom.
|
|
2391
|
+
*/
|
|
2392
|
+
function hasKey(data) {
|
|
2393
|
+
return data.key !== null && data.key !== undefined && data.key !== '';
|
|
2394
|
+
}
|
|
2395
|
+
function getXFormat(type, data, index, xScale) {
|
|
2396
|
+
switch (type) {
|
|
2397
|
+
case PcacFormatEnum.DateTime:
|
|
2398
|
+
if (hasKey(data)) {
|
|
2399
|
+
return xScale(new Date(data.key));
|
|
2400
|
+
}
|
|
2401
|
+
return 0;
|
|
2402
|
+
case PcacFormatEnum.Decimal:
|
|
2403
|
+
if (hasKey(data)) {
|
|
2404
|
+
return xScale(Number(data.key));
|
|
2405
|
+
}
|
|
2406
|
+
return 0;
|
|
2407
|
+
default:
|
|
2408
|
+
return xScale(index);
|
|
2409
|
+
}
|
|
2410
|
+
}
|
|
2411
|
+
|
|
2412
|
+
/** Whether a point has a numeric value to draw at. */
|
|
2413
|
+
function hasValue(d) {
|
|
2414
|
+
return d.value !== null && d.value !== undefined && d.value !== '' && Number.isFinite(Number(d.value));
|
|
2415
|
+
}
|
|
2416
|
+
|
|
2226
2417
|
/**
|
|
2227
2418
|
* Provided per-component (see PcacLineAreaChartComponent's `providers`), not root-scoped: this
|
|
2228
|
-
* holds mutable per-chart-instance state (`config`, `
|
|
2419
|
+
* holds mutable per-chart-instance state (`config`, `series`) despite looking like a stateless
|
|
2229
2420
|
* helper. A root singleton would be shared and clobbered by every `<pcac-line-area-chart>`
|
|
2230
2421
|
* rendered at once — each instance's hover effects would end up reading/writing whichever
|
|
2231
2422
|
* chart's `buildEffects()` ran last, not their own.
|
|
2232
2423
|
*/
|
|
2233
2424
|
class PlaChartEffectsBuilder {
|
|
2234
2425
|
config;
|
|
2235
|
-
//
|
|
2236
|
-
//
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
lines = [];
|
|
2426
|
+
// The series that get an effect group, each with its index in `config.data` (which is what its
|
|
2427
|
+
// line's color is picked by, so a skipped empty series doesn't shift the colors after it).
|
|
2428
|
+
series = [];
|
|
2429
|
+
/** Where the cursor last was over the plot, while the crosshair is showing; null otherwise. */
|
|
2430
|
+
lastMousePos = null;
|
|
2241
2431
|
buildEffects(config) {
|
|
2242
2432
|
this.config = config;
|
|
2243
|
-
this.
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
// wrong path.
|
|
2248
|
-
this.config.svg.selectAll('.line, .area')
|
|
2249
|
-
.filter((d) => d?.length !== 0)
|
|
2250
|
-
.each((d, i, n) => {
|
|
2251
|
-
this.lines.push(n[i]);
|
|
2252
|
-
});
|
|
2433
|
+
this.lastMousePos = null;
|
|
2434
|
+
this.series = config.data
|
|
2435
|
+
.map((data, index) => ({ data, index }))
|
|
2436
|
+
.filter(({ data }) => data.data.length > 0);
|
|
2253
2437
|
this.buildCollection();
|
|
2254
2438
|
this.buildCanvas();
|
|
2255
2439
|
}
|
|
2256
2440
|
/**
|
|
2257
|
-
* Swaps in the scales a zoom has rescaled. The crosshair
|
|
2258
|
-
*
|
|
2259
|
-
*
|
|
2260
|
-
* the pixel against the original domain.
|
|
2441
|
+
* Swaps in the scales a zoom has rescaled. The crosshair positions and labels its points
|
|
2442
|
+
* against the scales, so a zoom has to hand them over here or it would track the unzoomed
|
|
2443
|
+
* lines.
|
|
2261
2444
|
*/
|
|
2262
2445
|
updateScales(x, y) {
|
|
2263
2446
|
this.config.x = x;
|
|
2264
2447
|
this.config.y = y;
|
|
2448
|
+
// A wheel zoom moves the lines under a cursor that stays put, and sends no mousemove - so the
|
|
2449
|
+
// crosshair is re-read at the same spot, or it would sit on the pre-zoom values until the
|
|
2450
|
+
// mouse next moved.
|
|
2451
|
+
if (this.lastMousePos) {
|
|
2452
|
+
this.onMouseMove(this.lastMousePos);
|
|
2453
|
+
}
|
|
2265
2454
|
}
|
|
2266
2455
|
buildCollection() {
|
|
2267
2456
|
const collection = this.config.svg.append('g')
|
|
@@ -2269,18 +2458,14 @@ class PlaChartEffectsBuilder {
|
|
|
2269
2458
|
collection.append('path')
|
|
2270
2459
|
.attr('class', 'effect-line');
|
|
2271
2460
|
const mousePerLine = collection.selectAll('.effect-group')
|
|
2272
|
-
.data(this.
|
|
2273
|
-
return elm.data.length > 0;
|
|
2274
|
-
}))
|
|
2461
|
+
.data(this.series)
|
|
2275
2462
|
.enter().append('g')
|
|
2276
2463
|
.attr('class', 'effect-group')
|
|
2277
|
-
.attr('style', (
|
|
2464
|
+
.attr('style', ({ data }) => data.hide ? 'display: none' : null);
|
|
2278
2465
|
mousePerLine.append('circle')
|
|
2279
2466
|
.attr('r', 7)
|
|
2280
2467
|
.attr('class', 'effect-circle')
|
|
2281
|
-
.style('stroke', (
|
|
2282
|
-
return this.config.colors[i];
|
|
2283
|
-
});
|
|
2468
|
+
.style('stroke', ({ index }) => this.config.colors[index]);
|
|
2284
2469
|
mousePerLine.append('text')
|
|
2285
2470
|
.attr('class', 'effect-text')
|
|
2286
2471
|
.attr('y', 1.5)
|
|
@@ -2320,6 +2505,7 @@ class PlaChartEffectsBuilder {
|
|
|
2320
2505
|
.style('opacity', '1');
|
|
2321
2506
|
}
|
|
2322
2507
|
hideEffects() {
|
|
2508
|
+
this.lastMousePos = null;
|
|
2323
2509
|
this.config.svg.select('.effect-line')
|
|
2324
2510
|
.style('opacity', '0');
|
|
2325
2511
|
this.config.svg.selectAll('.effect-group circle')
|
|
@@ -2328,6 +2514,7 @@ class PlaChartEffectsBuilder {
|
|
|
2328
2514
|
.style('opacity', '0');
|
|
2329
2515
|
}
|
|
2330
2516
|
onMouseMove(mousePos) {
|
|
2517
|
+
this.lastMousePos = mousePos;
|
|
2331
2518
|
this.updateLine(mousePos);
|
|
2332
2519
|
this.updateEffects(mousePos);
|
|
2333
2520
|
}
|
|
@@ -2337,39 +2524,63 @@ class PlaChartEffectsBuilder {
|
|
|
2337
2524
|
}
|
|
2338
2525
|
updateEffects(mousePos) {
|
|
2339
2526
|
this.config.svg.selectAll('.effect-group')
|
|
2340
|
-
.
|
|
2341
|
-
const
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
let beginning = 0;
|
|
2349
|
-
let end = line.getTotalLength();
|
|
2350
|
-
let pos;
|
|
2351
|
-
while (true) {
|
|
2352
|
-
const target = Math.floor((beginning + end) / 2);
|
|
2353
|
-
pos = line.getPointAtLength(target);
|
|
2354
|
-
if ((target === end || target === beginning) && pos.x !== mousePos[0]) {
|
|
2355
|
-
break;
|
|
2356
|
-
}
|
|
2357
|
-
if (pos.x > mousePos[0]) {
|
|
2358
|
-
end = target;
|
|
2359
|
-
}
|
|
2360
|
-
else if (pos.x < mousePos[0]) {
|
|
2361
|
-
beginning = target;
|
|
2362
|
-
}
|
|
2363
|
-
else {
|
|
2364
|
-
break;
|
|
2365
|
-
}
|
|
2527
|
+
.each((series, index, nodes) => {
|
|
2528
|
+
const group = select(nodes[index]);
|
|
2529
|
+
const value = this.valueAt(series.data.data, mousePos[0]);
|
|
2530
|
+
// No value under the cursor (a gap in the series): nothing to mark, so the group is
|
|
2531
|
+
// hidden rather than left at its last position.
|
|
2532
|
+
group.attr('visibility', value === null ? 'hidden' : null);
|
|
2533
|
+
if (value === null) {
|
|
2534
|
+
return;
|
|
2366
2535
|
}
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
.text(this.formatValue(value));
|
|
2370
|
-
return 'translate(' + mousePos[0] + ',' + pos.y + ')';
|
|
2536
|
+
group.attr('transform', 'translate(' + mousePos[0] + ',' + this.config.y(value) + ')');
|
|
2537
|
+
group.select('text').text(this.formatValue(value));
|
|
2371
2538
|
});
|
|
2372
2539
|
}
|
|
2540
|
+
/**
|
|
2541
|
+
* The series' value at plot x `mouseX`, interpolated along the segment of the line that spans it
|
|
2542
|
+
* - the same (linear) join the line/area draws between two consecutive points - or null if it
|
|
2543
|
+
* falls in a gap, where the line isn't drawn. Beyond the line's leftmost/rightmost point it holds
|
|
2544
|
+
* that point's value.
|
|
2545
|
+
*
|
|
2546
|
+
* Works on the segments in data order and never assumes x increases along them: DateTime or
|
|
2547
|
+
* Decimal data can come newest-first (or in any order), and the line still joins consecutive
|
|
2548
|
+
* points - reading "the first point" as the leftmost one showed the newest value everywhere.
|
|
2549
|
+
*
|
|
2550
|
+
* Worked out from the data rather than by walking the drawn path: an area's outline doubles
|
|
2551
|
+
* back along its baseline, so a search over the path's geometry could land on the bottom edge
|
|
2552
|
+
* and read the wrong value.
|
|
2553
|
+
*/
|
|
2554
|
+
valueAt(points, mouseX) {
|
|
2555
|
+
const xAt = (i) => getXFormat(this.config.xFormat, points[i], i, this.config.x);
|
|
2556
|
+
const valueOf = (i) => Number(points[i].value);
|
|
2557
|
+
const drawn = points.map((_, i) => i).filter((i) => hasValue(points[i]));
|
|
2558
|
+
if (!drawn.length) {
|
|
2559
|
+
return null;
|
|
2560
|
+
}
|
|
2561
|
+
// A segment joins two points next to each other in the data, both with a value - a point
|
|
2562
|
+
// without one between them breaks the line (`defined(hasValue)`).
|
|
2563
|
+
for (let i = 1; i < points.length; i++) {
|
|
2564
|
+
if (!hasValue(points[i - 1]) || !hasValue(points[i])) {
|
|
2565
|
+
continue;
|
|
2566
|
+
}
|
|
2567
|
+
const [xa, xb] = [xAt(i - 1), xAt(i)];
|
|
2568
|
+
if (mouseX < Math.min(xa, xb) || mouseX > Math.max(xa, xb)) {
|
|
2569
|
+
continue;
|
|
2570
|
+
}
|
|
2571
|
+
const [va, vb] = [valueOf(i - 1), valueOf(i)];
|
|
2572
|
+
return xb === xa ? vb : va + (vb - va) * (mouseX - xa) / (xb - xa);
|
|
2573
|
+
}
|
|
2574
|
+
const leftmost = drawn.reduce((min, i) => (xAt(i) < xAt(min) ? i : min));
|
|
2575
|
+
const rightmost = drawn.reduce((max, i) => (xAt(i) > xAt(max) ? i : max));
|
|
2576
|
+
if (mouseX <= xAt(leftmost)) {
|
|
2577
|
+
return valueOf(leftmost);
|
|
2578
|
+
}
|
|
2579
|
+
if (mouseX >= xAt(rightmost)) {
|
|
2580
|
+
return valueOf(rightmost);
|
|
2581
|
+
}
|
|
2582
|
+
return null;
|
|
2583
|
+
}
|
|
2373
2584
|
/**
|
|
2374
2585
|
* The crosshair's value, formatted the way the y axis labels its ticks - same format, same
|
|
2375
2586
|
* step-based precision - rather than rounded to a whole number, which read a 0-1 axis as 0 or 1.
|
|
@@ -2380,10 +2591,10 @@ class PlaChartEffectsBuilder {
|
|
|
2380
2591
|
?? y.tickFormat(this.config.yTicks);
|
|
2381
2592
|
return formatter(value);
|
|
2382
2593
|
}
|
|
2383
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
2384
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.
|
|
2594
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PlaChartEffectsBuilder, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
2595
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PlaChartEffectsBuilder });
|
|
2385
2596
|
}
|
|
2386
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
2597
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PlaChartEffectsBuilder, decorators: [{
|
|
2387
2598
|
type: Injectable
|
|
2388
2599
|
}] });
|
|
2389
2600
|
|
|
@@ -2445,6 +2656,10 @@ class PlaChartScales {
|
|
|
2445
2656
|
* `format`/`domainMin`/`domainMax` defaults are already applied - see `PcacLineAreaChartConfig`
|
|
2446
2657
|
* for what each format does with them.
|
|
2447
2658
|
*/
|
|
2659
|
+
/** The number of points in the longest series. */
|
|
2660
|
+
function longestSeriesLength(data) {
|
|
2661
|
+
return data.reduce((max, series) => Math.max(max, series.data.length), 0);
|
|
2662
|
+
}
|
|
2448
2663
|
class PlaChartScalesBuilder {
|
|
2449
2664
|
build(xAxis, yAxis, data, chartWidth, chartHeight) {
|
|
2450
2665
|
const resp = new PlaChartScales();
|
|
@@ -2463,9 +2678,11 @@ class PlaChartScalesBuilder {
|
|
|
2463
2678
|
.domain([xAxis.domainMin, xAxis.domainMax])
|
|
2464
2679
|
.range([0, chartWidth]);
|
|
2465
2680
|
default:
|
|
2466
|
-
// DatasetLength and every other format position points by index
|
|
2681
|
+
// DatasetLength and every other format position points by index - across the longest
|
|
2682
|
+
// series, not the first, which may be shorter or empty (an empty one gave [0, -1], an
|
|
2683
|
+
// inverted scale that pushed every point off the plot).
|
|
2467
2684
|
return scaleLinear()
|
|
2468
|
-
.domain([0,
|
|
2685
|
+
.domain([0, Math.max(0, longestSeriesLength(data) - 1)])
|
|
2469
2686
|
.range([0, chartWidth]);
|
|
2470
2687
|
}
|
|
2471
2688
|
}
|
|
@@ -2476,36 +2693,6 @@ class PlaChartScalesBuilder {
|
|
|
2476
2693
|
}
|
|
2477
2694
|
}
|
|
2478
2695
|
|
|
2479
|
-
/**
|
|
2480
|
-
* Whether a point has an x key to position by. An explicit emptiness check, not truthiness: a
|
|
2481
|
-
* Decimal key of `0` is a perfectly good coordinate (the left edge of a `domainMin: 0` axis) and
|
|
2482
|
-
* used to be read as "no key" - drawn at pixel 0 whatever the domain, and pinned there under zoom.
|
|
2483
|
-
*/
|
|
2484
|
-
function hasKey(data) {
|
|
2485
|
-
return data.key !== null && data.key !== undefined && data.key !== '';
|
|
2486
|
-
}
|
|
2487
|
-
function getXFormat(type, data, index, xScale) {
|
|
2488
|
-
switch (type) {
|
|
2489
|
-
case PcacFormatEnum.DateTime:
|
|
2490
|
-
if (hasKey(data)) {
|
|
2491
|
-
return xScale(new Date(data.key));
|
|
2492
|
-
}
|
|
2493
|
-
return 0;
|
|
2494
|
-
case PcacFormatEnum.Decimal:
|
|
2495
|
-
if (hasKey(data)) {
|
|
2496
|
-
return xScale(Number(data.key));
|
|
2497
|
-
}
|
|
2498
|
-
return 0;
|
|
2499
|
-
default:
|
|
2500
|
-
return xScale(index);
|
|
2501
|
-
}
|
|
2502
|
-
}
|
|
2503
|
-
|
|
2504
|
-
/** Whether a point has a numeric value to draw at. */
|
|
2505
|
-
function hasValue(d) {
|
|
2506
|
-
return d.value !== null && d.value !== undefined && d.value !== '' && Number.isFinite(Number(d.value));
|
|
2507
|
-
}
|
|
2508
|
-
|
|
2509
2696
|
function buildLineGenerator(format, scales) {
|
|
2510
2697
|
return line()
|
|
2511
2698
|
// A point with no numeric value leaves a gap rather than a NaN in the path, which browsers stop
|
|
@@ -2721,10 +2908,12 @@ function findCoincidentGroups(series, xFormat) {
|
|
|
2721
2908
|
return;
|
|
2722
2909
|
}
|
|
2723
2910
|
s.data.forEach((data, index) => {
|
|
2724
|
-
|
|
2911
|
+
// Same test as the line/dots use, so a point that isn't drawn (`''`, NaN) never joins a ring.
|
|
2912
|
+
if (!hasValue(data)) {
|
|
2725
2913
|
return;
|
|
2726
2914
|
}
|
|
2727
|
-
|
|
2915
|
+
// By numeric value, so `5` and `'5'` - drawn at the same spot - are recognized as sharing it.
|
|
2916
|
+
const key = `${xPositionKey(xFormat, data, index)}|${Number(data.value)}`;
|
|
2728
2917
|
let members = byPosition.get(key);
|
|
2729
2918
|
if (!members) {
|
|
2730
2919
|
members = [];
|
|
@@ -2812,12 +3001,6 @@ function clamp(value, min, max) {
|
|
|
2812
3001
|
return Math.min(Math.max(value, min), max);
|
|
2813
3002
|
}
|
|
2814
3003
|
|
|
2815
|
-
/**
|
|
2816
|
-
* Provided per-component (see PcacLineAreaChartComponent's `providers`), not root-scoped: this
|
|
2817
|
-
* builder extends PcacChart, which holds mutable per-chart-instance state (margin, width,
|
|
2818
|
-
* height, colors, svg). A root singleton would be shared and clobbered by every
|
|
2819
|
-
* <pcac-line-area-chart> rendered at once.
|
|
2820
|
-
*/
|
|
2821
3004
|
/** Half the theme's 2px line stroke: how far the lines/areas/fan-outs clip-path reaches past the plot. */
|
|
2822
3005
|
const PLOT_CLIP_ALLOWANCE = 1;
|
|
2823
3006
|
/**
|
|
@@ -2837,6 +3020,12 @@ const CHART_TYPE_LABELS = {
|
|
|
2837
3020
|
[PcacLineAreaPlotChartConfigType.Area]: 'Area chart',
|
|
2838
3021
|
[PcacLineAreaPlotChartConfigType.Plot]: 'Plot chart',
|
|
2839
3022
|
};
|
|
3023
|
+
/**
|
|
3024
|
+
* Provided per-component (see PcacLineAreaChartComponent's `providers`), not root-scoped: this
|
|
3025
|
+
* builder extends PcacChart, which holds mutable per-chart-instance state (margin, width,
|
|
3026
|
+
* height, colors, svg). A root singleton would be shared and clobbered by every
|
|
3027
|
+
* <pcac-line-area-chart> rendered at once.
|
|
3028
|
+
*/
|
|
2840
3029
|
class PlaChartBuilder extends PcacChart {
|
|
2841
3030
|
effectsBuilder = inject(PlaChartEffectsBuilder);
|
|
2842
3031
|
scales;
|
|
@@ -2845,7 +3034,16 @@ class PlaChartBuilder extends PcacChart {
|
|
|
2845
3034
|
zoomBehavior;
|
|
2846
3035
|
dotClickedSource = new Subject();
|
|
2847
3036
|
config;
|
|
2848
|
-
|
|
3037
|
+
/**
|
|
3038
|
+
* Numbers this chart's clip-path ids (and, through `plotClipPathId`, its range gradients'),
|
|
3039
|
+
* which have to be unique in the whole page: `url(#id)` resolves to the first match in the
|
|
3040
|
+
* document, so a duplicate would clip one chart with another's rect. A per-instance counter
|
|
3041
|
+
* rather than the timestamp-plus-random stamp this used to be, which two charts rebuilding in
|
|
3042
|
+
* the same millisecond (every chart on a page reacts to a window resize at once) could share.
|
|
3043
|
+
*/
|
|
3044
|
+
static nextInstanceId = 0;
|
|
3045
|
+
instanceId = ++PlaChartBuilder.nextInstanceId;
|
|
3046
|
+
clipPathId;
|
|
2849
3047
|
/**
|
|
2850
3048
|
* A second clip-path for everything that isn't a point - lines, areas, fan-out anchors and
|
|
2851
3049
|
* spokes: the plot area plus `PLOT_CLIP_ALLOWANCE`. These have no business past the axes; the
|
|
@@ -2881,6 +3079,12 @@ class PlaChartBuilder extends PcacChart {
|
|
|
2881
3079
|
pointRange = null;
|
|
2882
3080
|
/** Each drawn range's `.point-range` group, by its point, so hover can find the one to focus. */
|
|
2883
3081
|
rangeGroupOf = new Map();
|
|
3082
|
+
/**
|
|
3083
|
+
* Whether this build has the hover crosshair: `enableEffects`, on a line or area chart. A plot
|
|
3084
|
+
* chart has no line for it to follow, so it gets none - its circles had nowhere to go and sat
|
|
3085
|
+
* stacked in the plot's top-left corner.
|
|
3086
|
+
*/
|
|
3087
|
+
effectsEnabled = false;
|
|
2884
3088
|
dotClicked$ = this.dotClickedSource.asObservable();
|
|
2885
3089
|
buildChart(chartElm, config, type) {
|
|
2886
3090
|
if (!config?.data?.length) {
|
|
@@ -2892,7 +3096,7 @@ class PlaChartBuilder extends PcacChart {
|
|
|
2892
3096
|
// no mouseout, so its tooltip is closed here (see `leavePoint`).
|
|
2893
3097
|
this.leavePoint();
|
|
2894
3098
|
this.config = JSON.parse(JSON.stringify(config));
|
|
2895
|
-
this.startData = range(this.config.data
|
|
3099
|
+
this.startData = range(longestSeriesLength(this.config.data)).map(() => ({
|
|
2896
3100
|
key: '',
|
|
2897
3101
|
value: 0,
|
|
2898
3102
|
hide: false,
|
|
@@ -2942,10 +3146,12 @@ class PlaChartBuilder extends PcacChart {
|
|
|
2942
3146
|
// used to do, and which also overwrote the original generators' x accessor for good) is
|
|
2943
3147
|
// only right for the default DatasetLength format; a DateTime/Decimal chart's lines
|
|
2944
3148
|
// drifted away from its dots as soon as it was zoomed.
|
|
3149
|
+
// Interrupted first: a zoom during the enter transition would otherwise have the rest of
|
|
3150
|
+
// that transition keep drawing the unzoomed shape over this one.
|
|
2945
3151
|
const zoomedLine = buildLineGenerator(this.xAxis.format, zoomedScales);
|
|
2946
3152
|
const zoomedArea = buildAreaGenerator(this.xAxis.format, zoomedScales, this.height);
|
|
2947
|
-
this.svg.selectAll('.line').attr('d', (d) => zoomedLine(d));
|
|
2948
|
-
this.svg.selectAll('.area').attr('d', (d) => zoomedArea(d));
|
|
3153
|
+
this.svg.selectAll('.line').interrupt().attr('d', (d) => zoomedLine(d));
|
|
3154
|
+
this.svg.selectAll('.area').interrupt().attr('d', (d) => zoomedArea(d));
|
|
2949
3155
|
// Update dots / point images. Nested selectAll (not a flat svg.selectAll('.point')) so
|
|
2950
3156
|
// that `i` is the point's index *within its own series* - the x format default
|
|
2951
3157
|
// (DatasetLength) positions by index, and a flat selection would number every series'
|
|
@@ -2961,9 +3167,8 @@ class PlaChartBuilder extends PcacChart {
|
|
|
2961
3167
|
.selectAll('.fan-out-spoke')
|
|
2962
3168
|
.attr('x2', (member) => this.spokeEnd(member, zoomedScales).dx)
|
|
2963
3169
|
.attr('y2', (member) => this.spokeEnd(member, zoomedScales).dy);
|
|
2964
|
-
// The hover crosshair
|
|
2965
|
-
|
|
2966
|
-
if (this.config.enableEffects) {
|
|
3170
|
+
// The hover crosshair positions and labels against the scales, so it takes the zoomed ones.
|
|
3171
|
+
if (this.effectsEnabled) {
|
|
2967
3172
|
this.effectsBuilder.updateScales(newX, newY);
|
|
2968
3173
|
}
|
|
2969
3174
|
// Ranges are drawn in plot coordinates rather than hung off a translate, so every one is
|
|
@@ -2985,7 +3190,8 @@ class PlaChartBuilder extends PcacChart {
|
|
|
2985
3190
|
this.axisBuilder.drawAxis(this.axisBuilderConfig(this.scales.x, this.scales.y));
|
|
2986
3191
|
this.drawGrids(this.scales.x, this.scales.y);
|
|
2987
3192
|
this.drawLineArea(config, type);
|
|
2988
|
-
|
|
3193
|
+
this.effectsEnabled = !!config.enableEffects && type !== PcacLineAreaPlotChartConfigType.Plot;
|
|
3194
|
+
if (this.effectsEnabled) {
|
|
2989
3195
|
this.effectsBuilder.buildEffects({
|
|
2990
3196
|
svg: this.svg,
|
|
2991
3197
|
height: this.height,
|
|
@@ -2994,6 +3200,7 @@ class PlaChartBuilder extends PcacChart {
|
|
|
2994
3200
|
colors: this.colors,
|
|
2995
3201
|
x: this.scales.x,
|
|
2996
3202
|
y: this.scales.y,
|
|
3203
|
+
xFormat: this.xAxis.format,
|
|
2997
3204
|
yFormat: this.yAxis.format,
|
|
2998
3205
|
yTicks: this.yAxis.ticks,
|
|
2999
3206
|
});
|
|
@@ -3055,10 +3262,10 @@ class PlaChartBuilder extends PcacChart {
|
|
|
3055
3262
|
this.reserveEdgeSpace({ top: halfHeight, bottom: halfHeight, left: halfWidth, right: halfWidth });
|
|
3056
3263
|
}
|
|
3057
3264
|
createReusableClipPath() {
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
this.
|
|
3061
|
-
this.
|
|
3265
|
+
// The previous build's <defs> went with the rest of its drawing (see initializeChartState),
|
|
3266
|
+
// so the same ids are free again.
|
|
3267
|
+
this.clipPathId = `pcac-clip-${this.instanceId}`;
|
|
3268
|
+
this.plotClipPathId = `pcac-clip-plot-${this.instanceId}`;
|
|
3062
3269
|
const defs = this.svg.append('defs');
|
|
3063
3270
|
defs.append('clipPath')
|
|
3064
3271
|
.attr('id', this.clipPathId)
|
|
@@ -3125,15 +3332,15 @@ class PlaChartBuilder extends PcacChart {
|
|
|
3125
3332
|
.append('path')
|
|
3126
3333
|
.datum(lineData)
|
|
3127
3334
|
.attr('class', 'line')
|
|
3335
|
+
// Set up front rather than on the transition, so a zoom interrupting it (see the zoom
|
|
3336
|
+
// handler) doesn't leave the line uncolored, or a hidden one showing.
|
|
3337
|
+
.attr('stroke', this.colors[index])
|
|
3338
|
+
.attr('fill', 'none')
|
|
3339
|
+
.attr('style', hide ? 'display: none' : null)
|
|
3128
3340
|
.attr('d', this.lineGenerator(this.startData))
|
|
3129
3341
|
.transition()
|
|
3130
3342
|
.duration(this.transitionService.getTransitionDuration())
|
|
3131
|
-
.attr('d', this.lineGenerator)
|
|
3132
|
-
.attr('stroke', () => {
|
|
3133
|
-
return this.colors[index];
|
|
3134
|
-
})
|
|
3135
|
-
.attr('fill', 'none')
|
|
3136
|
-
.attr('style', () => hide ? 'display: none' : null);
|
|
3343
|
+
.attr('d', this.lineGenerator);
|
|
3137
3344
|
}
|
|
3138
3345
|
drawArea(lineData, index, hide = false) {
|
|
3139
3346
|
this.svg.append('g')
|
|
@@ -3182,7 +3389,9 @@ class PlaChartBuilder extends PcacChart {
|
|
|
3182
3389
|
.style('--pcac-point-range-series-color', () => this.colors[seriesIndex])
|
|
3183
3390
|
.style('display', () => series.hide ? 'none' : null);
|
|
3184
3391
|
series.data.forEach((point) => {
|
|
3185
|
-
|
|
3392
|
+
// A point with no value draws no dot (see `pointDisplay`), so it draws no range either -
|
|
3393
|
+
// one would stand around a coordinate with nothing on it (on the baseline, for `''`).
|
|
3394
|
+
if (point.range && hasValue(point)) {
|
|
3186
3395
|
this.rangeGroupOf.set(point, seriesGroup.append('g').attr('class', 'point-range').node());
|
|
3187
3396
|
}
|
|
3188
3397
|
});
|
|
@@ -3302,7 +3511,7 @@ class PlaChartBuilder extends PcacChart {
|
|
|
3302
3511
|
const series = config.data[index];
|
|
3303
3512
|
const points = this.svg.append('g')
|
|
3304
3513
|
.attr('class', 'dots')
|
|
3305
|
-
.attr('clip-path', `url(#${this.clipPathId})`)
|
|
3514
|
+
.attr('clip-path', `url(#${this.clipPathId})`)
|
|
3306
3515
|
.attr('style', series.hide ? 'display: none' : null)
|
|
3307
3516
|
.selectAll('.point')
|
|
3308
3517
|
.data(series.data)
|
|
@@ -3408,9 +3617,13 @@ class PlaChartBuilder extends PcacChart {
|
|
|
3408
3617
|
* the clip-path's buffer do the work, showed a point up to a whole half-mark beyond the axis
|
|
3409
3618
|
* with its center already outside. Also takes it out of hover's reach, as a hidden group
|
|
3410
3619
|
* receives no pointer events.
|
|
3620
|
+
*
|
|
3621
|
+
* A point with no value to plot isn't drawn at all - the same test the line/area uses to leave
|
|
3622
|
+
* a gap (`hasValue`). An empty string used to slip through: the scale reads `''` as 0, so the
|
|
3623
|
+
* line left a gap while a dot sat (hoverable) on the baseline.
|
|
3411
3624
|
*/
|
|
3412
3625
|
pointDisplay(d, i, scales) {
|
|
3413
|
-
return this.pointVisible(d, i, scales) ? null : 'none';
|
|
3626
|
+
return hasValue(d) && this.pointVisible(d, i, scales) ? null : 'none';
|
|
3414
3627
|
}
|
|
3415
3628
|
pointVisible(d, i, scales) {
|
|
3416
3629
|
const { x, y } = this.markCenter(d, i, scales);
|
|
@@ -3470,10 +3683,10 @@ class PlaChartBuilder extends PcacChart {
|
|
|
3470
3683
|
.filter((member) => member.data !== d)
|
|
3471
3684
|
.map((member) => ({ data: member.data, parent: member.series, index: member.index, parentIndex: member.seriesIndex }));
|
|
3472
3685
|
}
|
|
3473
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
3474
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.
|
|
3686
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PlaChartBuilder, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
|
3687
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PlaChartBuilder });
|
|
3475
3688
|
}
|
|
3476
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
3689
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PlaChartBuilder, decorators: [{
|
|
3477
3690
|
type: Injectable
|
|
3478
3691
|
}] });
|
|
3479
3692
|
|
|
@@ -3522,10 +3735,10 @@ class PcacLineAreaChartComponent {
|
|
|
3522
3735
|
this.chartBuilder.buildChart(this.chartElm(), config, this.type());
|
|
3523
3736
|
}
|
|
3524
3737
|
}
|
|
3525
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
3526
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.
|
|
3738
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacLineAreaChartComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
3739
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.2.0", type: PcacLineAreaChartComponent, isStandalone: true, selector: "pcac-line-area-chart", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null }, type: { classPropertyName: "type", publicName: "type", isSignal: true, isRequired: true, transformFunction: null }, tooltipTemplate: { classPropertyName: "tooltipTemplate", publicName: "tooltipTemplate", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { dotClicked: "dotClicked" }, host: { properties: { "class.pcac-height-full": "config().heightFull" } }, providers: [PlaChartBuilder, PlaChartEffectsBuilder], viewQueries: [{ propertyName: "chartElm", first: true, predicate: ["chart"], descendants: true, isSignal: true }], ngImport: i0, template: "<section class=\"pcac-line-area-chart\">\n <svg #chart></svg>\n</section>\n\n", styles: [".pcac-line-area-chart svg{width:100%;display:block}.pcac-line-area-chart .dot{stroke-width:2px}.pcac-line-area-chart .fan-out-spoke{stroke:var(--pcac-fan-out-spoke-color, #ced4da);stroke-width:1px}.pcac-line-area-chart .fan-out-anchor{fill:var(--pcac-fan-out-anchor-color, #6c757d)}.pcac-line-area-chart .point-ranges .point-range-series{--pcac-point-range-resolved-color: var(--pcac-point-range-color, var(--pcac-point-range-series-color))}.pcac-line-area-chart .point-ranges .point-range{opacity:var(--pcac-point-range-resting-opacity, 1);transition:opacity .15s ease-out}.pcac-line-area-chart .point-ranges .point-range.is-focused{opacity:1}.pcac-line-area-chart .point-ranges.pcac-range-hover{--pcac-point-range-resting-opacity: 0}.pcac-line-area-chart .point-ranges.pcac-range-faint{--pcac-point-range-resting-opacity: var(--pcac-point-range-faint-opacity, .2)}.pcac-line-area-chart .point-ranges.pcac-range-always.has-focus .point-range:not(.is-focused){opacity:.5}.pcac-line-area-chart .point-ranges .point-range-whisker,.pcac-line-area-chart .point-ranges .point-range-cap{stroke:var(--pcac-point-range-resolved-color);stroke-width:1.25px}.pcac-line-area-chart .point-ranges .point-range-box{fill:var(--pcac-point-range-resolved-color);fill-opacity:.1;stroke:var(--pcac-point-range-resolved-color);stroke-opacity:.7;stroke-width:1.25px}.pcac-line-area-chart .point-ranges .point-range-stop{stop-color:var(--pcac-point-range-resolved-color)}.pcac-line-area-chart .point-ranges .is-focused .point-range-whisker,.pcac-line-area-chart .point-ranges .is-focused .point-range-cap,.pcac-line-area-chart .point-ranges .is-focused .point-range-box{stroke-width:1.75px}.pcac-line-area-chart .point-ranges .is-focused .point-range-box{fill-opacity:.18}@media(prefers-reduced-motion:reduce){.pcac-line-area-chart .point-ranges .point-range{transition:none}}.pcac-line-area-chart .effects-canvas{fill:none}.pcac-line-area-chart .effect-line{stroke:#ced4da;stroke-width:1px;opacity:0}.pcac-line-area-chart .effect-circle{stroke-width:1px;fill:none;opacity:0}.pcac-line-area-chart .effect-text{font-size:11px;font-weight:700;fill:#343a40}pcac-line-chart.pcac-height-full,pcac-area-chart.pcac-height-full,pcac-plot-chart.pcac-height-full,pcac-line-area-chart.pcac-height-full{display:block;height:100%}pcac-line-area-chart.pcac-height-full .pcac-line-area-chart{height:100%}\n"], encapsulation: i0.ViewEncapsulation.None });
|
|
3527
3740
|
}
|
|
3528
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
3741
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacLineAreaChartComponent, decorators: [{
|
|
3529
3742
|
type: Component,
|
|
3530
3743
|
args: [{ selector: 'pcac-line-area-chart', host: { '[class.pcac-height-full]': 'config().heightFull' }, encapsulation: ViewEncapsulation.None, providers: [PlaChartBuilder, PlaChartEffectsBuilder], template: "<section class=\"pcac-line-area-chart\">\n <svg #chart></svg>\n</section>\n\n", styles: [".pcac-line-area-chart svg{width:100%;display:block}.pcac-line-area-chart .dot{stroke-width:2px}.pcac-line-area-chart .fan-out-spoke{stroke:var(--pcac-fan-out-spoke-color, #ced4da);stroke-width:1px}.pcac-line-area-chart .fan-out-anchor{fill:var(--pcac-fan-out-anchor-color, #6c757d)}.pcac-line-area-chart .point-ranges .point-range-series{--pcac-point-range-resolved-color: var(--pcac-point-range-color, var(--pcac-point-range-series-color))}.pcac-line-area-chart .point-ranges .point-range{opacity:var(--pcac-point-range-resting-opacity, 1);transition:opacity .15s ease-out}.pcac-line-area-chart .point-ranges .point-range.is-focused{opacity:1}.pcac-line-area-chart .point-ranges.pcac-range-hover{--pcac-point-range-resting-opacity: 0}.pcac-line-area-chart .point-ranges.pcac-range-faint{--pcac-point-range-resting-opacity: var(--pcac-point-range-faint-opacity, .2)}.pcac-line-area-chart .point-ranges.pcac-range-always.has-focus .point-range:not(.is-focused){opacity:.5}.pcac-line-area-chart .point-ranges .point-range-whisker,.pcac-line-area-chart .point-ranges .point-range-cap{stroke:var(--pcac-point-range-resolved-color);stroke-width:1.25px}.pcac-line-area-chart .point-ranges .point-range-box{fill:var(--pcac-point-range-resolved-color);fill-opacity:.1;stroke:var(--pcac-point-range-resolved-color);stroke-opacity:.7;stroke-width:1.25px}.pcac-line-area-chart .point-ranges .point-range-stop{stop-color:var(--pcac-point-range-resolved-color)}.pcac-line-area-chart .point-ranges .is-focused .point-range-whisker,.pcac-line-area-chart .point-ranges .is-focused .point-range-cap,.pcac-line-area-chart .point-ranges .is-focused .point-range-box{stroke-width:1.75px}.pcac-line-area-chart .point-ranges .is-focused .point-range-box{fill-opacity:.18}@media(prefers-reduced-motion:reduce){.pcac-line-area-chart .point-ranges .point-range{transition:none}}.pcac-line-area-chart .effects-canvas{fill:none}.pcac-line-area-chart .effect-line{stroke:#ced4da;stroke-width:1px;opacity:0}.pcac-line-area-chart .effect-circle{stroke-width:1px;fill:none;opacity:0}.pcac-line-area-chart .effect-text{font-size:11px;font-weight:700;fill:#343a40}pcac-line-chart.pcac-height-full,pcac-area-chart.pcac-height-full,pcac-plot-chart.pcac-height-full,pcac-line-area-chart.pcac-height-full{display:block;height:100%}pcac-line-area-chart.pcac-height-full .pcac-line-area-chart{height:100%}\n"] }]
|
|
3531
3744
|
}], 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 }] }] } });
|
|
@@ -3541,10 +3754,10 @@ class PcacPlotChart {
|
|
|
3541
3754
|
*/
|
|
3542
3755
|
tooltipTemplate = contentChild(PcacTooltipDirective, /* @ts-ignore */
|
|
3543
3756
|
...(ngDevMode ? [{ debugName: "tooltipTemplate" }] : /* istanbul ignore next */ []));
|
|
3544
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
3545
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.
|
|
3757
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacPlotChart, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
3758
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.2.0", type: PcacPlotChart, isStandalone: true, selector: "pcac-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" } }, queries: [{ propertyName: "tooltipTemplate", first: true, predicate: PcacTooltipDirective, descendants: true, isSignal: true }], ngImport: i0, template: "<pcac-line-area-chart [config]=\"config()\" [tooltipTemplate]=\"tooltipTemplate()?.templateRef\" [type]=\"types.Plot\" (dotClicked)=\"dotClicked.emit($event)\"/>", dependencies: [{ kind: "component", type: PcacLineAreaChartComponent, selector: "pcac-line-area-chart", inputs: ["config", "type", "tooltipTemplate"], outputs: ["dotClicked"] }] });
|
|
3546
3759
|
}
|
|
3547
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
3760
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacPlotChart, decorators: [{
|
|
3548
3761
|
type: Component,
|
|
3549
3762
|
args: [{ selector: 'pcac-plot-chart', host: { '[class.pcac-height-full]': 'config().heightFull' }, imports: [PcacLineAreaChartComponent], template: "<pcac-line-area-chart [config]=\"config()\" [tooltipTemplate]=\"tooltipTemplate()?.templateRef\" [type]=\"types.Plot\" (dotClicked)=\"dotClicked.emit($event)\"/>" }]
|
|
3550
3763
|
}], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }], dotClicked: [{ type: i0.Output, args: ["dotClicked"] }], tooltipTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => PcacTooltipDirective), { isSignal: true }] }] } });
|
|
@@ -3560,10 +3773,10 @@ class PcacLineChart {
|
|
|
3560
3773
|
*/
|
|
3561
3774
|
tooltipTemplate = contentChild(PcacTooltipDirective, /* @ts-ignore */
|
|
3562
3775
|
...(ngDevMode ? [{ debugName: "tooltipTemplate" }] : /* istanbul ignore next */ []));
|
|
3563
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
3564
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.
|
|
3776
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacLineChart, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
3777
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.2.0", type: PcacLineChart, isStandalone: true, selector: "pcac-line-chart", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { dotClicked: "dotClicked" }, host: { properties: { "class.pcac-height-full": "config().heightFull" } }, queries: [{ propertyName: "tooltipTemplate", first: true, predicate: PcacTooltipDirective, descendants: true, isSignal: true }], ngImport: i0, template: "<pcac-line-area-chart [config]=\"config()\" [tooltipTemplate]=\"tooltipTemplate()?.templateRef\" [type]=\"types.Line\" (dotClicked)=\"dotClicked.emit($event)\" />", dependencies: [{ kind: "component", type: PcacLineAreaChartComponent, selector: "pcac-line-area-chart", inputs: ["config", "type", "tooltipTemplate"], outputs: ["dotClicked"] }] });
|
|
3565
3778
|
}
|
|
3566
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
3779
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacLineChart, decorators: [{
|
|
3567
3780
|
type: Component,
|
|
3568
3781
|
args: [{ selector: 'pcac-line-chart', host: { '[class.pcac-height-full]': 'config().heightFull' }, imports: [PcacLineAreaChartComponent], template: "<pcac-line-area-chart [config]=\"config()\" [tooltipTemplate]=\"tooltipTemplate()?.templateRef\" [type]=\"types.Line\" (dotClicked)=\"dotClicked.emit($event)\" />" }]
|
|
3569
3782
|
}], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }], dotClicked: [{ type: i0.Output, args: ["dotClicked"] }], tooltipTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => PcacTooltipDirective), { isSignal: true }] }] } });
|
|
@@ -3582,10 +3795,10 @@ class PcacAreaChart {
|
|
|
3582
3795
|
*/
|
|
3583
3796
|
tooltipTemplate = contentChild(PcacTooltipDirective, /* @ts-ignore */
|
|
3584
3797
|
...(ngDevMode ? [{ debugName: "tooltipTemplate" }] : /* istanbul ignore next */ []));
|
|
3585
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
3586
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.
|
|
3798
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacAreaChart, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
3799
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.2.0", type: PcacAreaChart, isStandalone: true, selector: "pcac-area-chart", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { dotClicked: "dotClicked" }, host: { properties: { "class.pcac-height-full": "config().heightFull" } }, queries: [{ propertyName: "tooltipTemplate", first: true, predicate: PcacTooltipDirective, descendants: true, isSignal: true }], ngImport: i0, template: "<pcac-line-area-chart [config]=\"config()\" [tooltipTemplate]=\"tooltipTemplate()?.templateRef\" [type]=\"types.Area\" (dotClicked)=\"dotClicked.emit($event)\" />", dependencies: [{ kind: "component", type: PcacLineAreaChartComponent, selector: "pcac-line-area-chart", inputs: ["config", "type", "tooltipTemplate"], outputs: ["dotClicked"] }] });
|
|
3587
3800
|
}
|
|
3588
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
3801
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacAreaChart, decorators: [{
|
|
3589
3802
|
type: Component,
|
|
3590
3803
|
args: [{ selector: 'pcac-area-chart', host: { '[class.pcac-height-full]': 'config().heightFull' }, imports: [PcacLineAreaChartComponent], template: "<pcac-line-area-chart [config]=\"config()\" [tooltipTemplate]=\"tooltipTemplate()?.templateRef\" [type]=\"types.Area\" (dotClicked)=\"dotClicked.emit($event)\" />" }]
|
|
3591
3804
|
}], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }], dotClicked: [{ type: i0.Output, args: ["dotClicked"] }], tooltipTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => PcacTooltipDirective), { isSignal: true }] }] } });
|
|
@@ -3601,14 +3814,34 @@ class PcacAreaChartConfig extends PcacLineAreaChartConfig {
|
|
|
3601
3814
|
// the point-image and point-range types are part of those configs' public shape, so they're
|
|
3602
3815
|
// exported alone.
|
|
3603
3816
|
|
|
3817
|
+
/** Which chart the shared `<pcac-pie-donut-chart>` draws; each wrapper binds its own. */
|
|
3818
|
+
var PcacPieDonutChartType;
|
|
3819
|
+
(function (PcacPieDonutChartType) {
|
|
3820
|
+
PcacPieDonutChartType["Pie"] = "pie";
|
|
3821
|
+
PcacPieDonutChartType["Donut"] = "donut";
|
|
3822
|
+
})(PcacPieDonutChartType || (PcacPieDonutChartType = {}));
|
|
3604
3823
|
/**
|
|
3605
|
-
*
|
|
3606
|
-
*
|
|
3824
|
+
* What the pie and donut charts share. Internal: consumers configure `PcacPieChartConfig` or
|
|
3825
|
+
* `PcacDonutChartConfig`, the same way the line, area and plot charts share
|
|
3826
|
+
* `PcacLineAreaChartConfig`.
|
|
3607
3827
|
*/
|
|
3608
|
-
class
|
|
3828
|
+
class PcacPieDonutChartConfig extends PcacChartConfig {
|
|
3609
3829
|
/**
|
|
3610
|
-
*
|
|
3611
|
-
*
|
|
3830
|
+
* Slice colors, any CSS color, in data order - the first slice takes the first color - in place
|
|
3831
|
+
* of the theme palette. Repeated when there are more slices than colors. Omitted or empty, the
|
|
3832
|
+
* theme palette is used. Match a `<pcac-legend>` to it with each item's `colorOverride`.
|
|
3833
|
+
*/
|
|
3834
|
+
colorOverride;
|
|
3835
|
+
}
|
|
3836
|
+
|
|
3837
|
+
/**
|
|
3838
|
+
* A pie with its slices drawn as a ring around an empty center, which can hold a short label -
|
|
3839
|
+
* typically the total the slices add up to.
|
|
3840
|
+
*/
|
|
3841
|
+
class PcacDonutChartConfig extends PcacPieDonutChartConfig {
|
|
3842
|
+
/**
|
|
3843
|
+
* Radius of the hole as a fraction of the chart's radius, from 0 (no hole - a pie) to 0.9.
|
|
3844
|
+
* Values outside that range are clamped.
|
|
3612
3845
|
*/
|
|
3613
3846
|
innerRadius = 0.6;
|
|
3614
3847
|
/**
|
|
@@ -3620,28 +3853,15 @@ class PcacPieDonutConfig {
|
|
|
3620
3853
|
subLabel;
|
|
3621
3854
|
/**
|
|
3622
3855
|
* `label` color, any CSS color; theme default `$gray-800`. Applied as
|
|
3623
|
-
* `--pcac-
|
|
3624
|
-
* set it on an ancestor instead (a config value wins).
|
|
3856
|
+
* `--pcac-donut-center-label-color` on the chart's `.pcac-donut-center` group, so a stylesheet
|
|
3857
|
+
* can set it on an ancestor instead (a config value wins).
|
|
3625
3858
|
*/
|
|
3626
3859
|
labelColor;
|
|
3627
|
-
/** `subLabel` color, likewise (`--pcac-
|
|
3860
|
+
/** `subLabel` color, likewise (`--pcac-donut-center-sub-label-color`); theme default `$gray-600`. */
|
|
3628
3861
|
subLabelColor;
|
|
3629
3862
|
}
|
|
3630
|
-
class PcacPieChartConfig extends PcacChartConfig {
|
|
3631
|
-
/**
|
|
3632
|
-
* Draw the pie as a donut. Off when not set; `{}` turns it on with every `PcacPieDonutConfig`
|
|
3633
|
-
* default. Slices, hover and `sliceClicked` behave the same either way.
|
|
3634
|
-
*/
|
|
3635
|
-
donut;
|
|
3636
|
-
/**
|
|
3637
|
-
* Slice colors, any CSS color, in data order - the first slice takes the first color - in place
|
|
3638
|
-
* of the theme palette. Repeated when there are more slices than colors. Omitted or empty, the
|
|
3639
|
-
* theme palette is used. Match a `<pcac-legend>` to it with each item's `colorOverride`.
|
|
3640
|
-
*/
|
|
3641
|
-
colorOverride;
|
|
3642
|
-
}
|
|
3643
3863
|
|
|
3644
|
-
/** The largest `
|
|
3864
|
+
/** The largest `PcacDonutChartConfig.innerRadius` honored, so a ring is always left to draw. */
|
|
3645
3865
|
const MAX_DONUT_INNER_RADIUS = 0.9;
|
|
3646
3866
|
/** Smallest font a center line is drawn at; a line that can't fit the hole at this size is left out. */
|
|
3647
3867
|
const MIN_CENTER_FONT_SIZE = 8;
|
|
@@ -3653,12 +3873,12 @@ const CENTER_TEXT_WIDTH = 1.6;
|
|
|
3653
3873
|
*/
|
|
3654
3874
|
const ESTIMATED_GLYPH_WIDTH = 0.6;
|
|
3655
3875
|
/**
|
|
3656
|
-
* Provided per-component (see
|
|
3876
|
+
* Provided per-component (see PcacPieDonutChartComponent's `providers`), not root-scoped:
|
|
3657
3877
|
* this builder extends PcacChart, which holds mutable per-chart-instance state (margin, width,
|
|
3658
3878
|
* height, colors, svg). A root singleton would be shared and clobbered by every
|
|
3659
|
-
* <pcac-pie-chart> rendered at once.
|
|
3879
|
+
* <pcac-pie-donut-chart> rendered at once.
|
|
3660
3880
|
*/
|
|
3661
|
-
class
|
|
3881
|
+
class PieDonutChartBuilder extends PcacChart {
|
|
3662
3882
|
radius;
|
|
3663
3883
|
innerRadius = 0;
|
|
3664
3884
|
arcShape;
|
|
@@ -3667,39 +3887,68 @@ class PieChartBuilder extends PcacChart {
|
|
|
3667
3887
|
sliceClickedSource = new Subject();
|
|
3668
3888
|
sliceClicked$ = this.sliceClickedSource.asObservable();
|
|
3669
3889
|
chartTypeLabel = 'Pie chart';
|
|
3670
|
-
|
|
3890
|
+
/**
|
|
3891
|
+
* Draws `config` as a pie, or - for `PcacPieDonutChartType.Donut` - as a donut, reading the ring
|
|
3892
|
+
* settings off the config (`PcacDonutChartConfig`), with its defaults for any left unset.
|
|
3893
|
+
*/
|
|
3894
|
+
buildChart(chartElm, config, type) {
|
|
3671
3895
|
if (!config?.data?.length) {
|
|
3672
3896
|
this.clearChart(chartElm);
|
|
3673
3897
|
return;
|
|
3674
3898
|
}
|
|
3675
3899
|
// The pie deliberately opts out of `heightFull`: `height` here feeds the radius rather than a
|
|
3676
3900
|
// drawing area, so growing into a tall container would silently change the size of the pie
|
|
3677
|
-
// itself. `
|
|
3678
|
-
// here rather than being absent from the type. (`<pcac-pie-chart>` also never gets the
|
|
3901
|
+
// itself. `PcacPieDonutChartConfig` inherits the property from PcacChartConfig, so it's neutralized
|
|
3902
|
+
// here rather than being absent from the type. (`<pcac-pie-donut-chart>` also never gets the
|
|
3679
3903
|
// `pcac-height-full` class the other charts use to stretch their host.)
|
|
3904
|
+
const donut = type === PcacPieDonutChartType.Donut ? donutSettings(config) : null;
|
|
3905
|
+
if (type === PcacPieDonutChartType.Pie) {
|
|
3906
|
+
this.warnOfDonutOnPie(config);
|
|
3907
|
+
}
|
|
3908
|
+
// Announced for what it draws: a ring, or - a donut with no hole included - a pie (see
|
|
3909
|
+
// PcacChart.chartTypeLabel).
|
|
3910
|
+
this.chartTypeLabel = donut && donut.innerRadius > 0 ? 'Donut chart' : 'Pie chart';
|
|
3680
3911
|
if (!this.initializeChartState(chartElm, { ...config, heightFull: false })) {
|
|
3681
3912
|
return;
|
|
3682
3913
|
}
|
|
3683
3914
|
this.applyColorOverride(config.colorOverride);
|
|
3684
|
-
this.radius = Math.min(
|
|
3685
|
-
this.buildShapes(
|
|
3915
|
+
this.radius = Math.min(this.height, this.width) / 2;
|
|
3916
|
+
this.buildShapes(donut?.innerRadius ?? 0);
|
|
3686
3917
|
this.drawChart(chartElm, config);
|
|
3687
|
-
if (
|
|
3688
|
-
this.drawCenter(
|
|
3918
|
+
if (donut && this.innerRadius > 0) {
|
|
3919
|
+
this.drawCenter(donut);
|
|
3920
|
+
}
|
|
3921
|
+
}
|
|
3922
|
+
warnedOfDonutOnPie = false;
|
|
3923
|
+
/**
|
|
3924
|
+
* Development builds only: a pie config still carrying 22.2's `donut` option. It isn't read any
|
|
3925
|
+
* more - the donut is PcacDonutChart now - and TypeScript doesn't always catch it (a config built
|
|
3926
|
+
* by spreading, or loaded as JSON, compiles fine), so the chart would quietly draw a plain pie.
|
|
3927
|
+
* Warned once per chart.
|
|
3928
|
+
*/
|
|
3929
|
+
warnOfDonutOnPie(config) {
|
|
3930
|
+
if (typeof ngDevMode === 'undefined' || !ngDevMode || this.warnedOfDonutOnPie || !('donut' in config)) {
|
|
3931
|
+
return;
|
|
3689
3932
|
}
|
|
3933
|
+
this.warnedOfDonutOnPie = true;
|
|
3934
|
+
console.warn('Pioneer Charts: <pcac-pie-chart> ignores `donut`. For a donut, use <pcac-donut-chart> with ' +
|
|
3935
|
+
'PcacDonutChartConfig, which takes innerRadius, label, subLabel, labelColor and subLabelColor ' +
|
|
3936
|
+
'directly - see the 22.3.0 CHANGELOG.');
|
|
3690
3937
|
}
|
|
3691
|
-
|
|
3938
|
+
/** `ratio` is the hole's radius as a share of the chart's: 0 for a pie. */
|
|
3939
|
+
buildShapes(ratio) {
|
|
3692
3940
|
const radiusOffset = 10;
|
|
3693
|
-
|
|
3694
|
-
const
|
|
3941
|
+
// Never negative: in a container under 20px the offset would otherwise turn the pie inside out.
|
|
3942
|
+
const outerRadius = Math.max(0, this.radius - radiusOffset);
|
|
3695
3943
|
// Sized against the resting slice, so the hole stays put when a hovered slice grows outward.
|
|
3696
3944
|
this.innerRadius = Math.max(0, outerRadius * Math.min(Math.max(ratio, 0), MAX_DONUT_INNER_RADIUS));
|
|
3697
3945
|
this.arcShape = arc()
|
|
3698
3946
|
.innerRadius(this.innerRadius)
|
|
3699
3947
|
.outerRadius(outerRadius);
|
|
3948
|
+
// A pie too small to draw anything at rest (see above) doesn't pop out a disc on hover either.
|
|
3700
3949
|
this.arcOverShape = arc()
|
|
3701
3950
|
.innerRadius(this.innerRadius)
|
|
3702
|
-
.outerRadius(outerRadius + radiusOffset);
|
|
3951
|
+
.outerRadius(outerRadius > 0 ? outerRadius + radiusOffset : 0);
|
|
3703
3952
|
this.pieAngles = pie()
|
|
3704
3953
|
.sort(null)
|
|
3705
3954
|
// A hidden slice takes no angle but keeps its index - and so its color, matching a legend -
|
|
@@ -3721,7 +3970,16 @@ class PieChartBuilder extends PcacChart {
|
|
|
3721
3970
|
const t = transition().duration(self.transitionService.getTransitionDuration() / 3);
|
|
3722
3971
|
const c = color(self.colors[d.index]);
|
|
3723
3972
|
const ct = c ? c.darker(1).toString() : self.colors[d.index];
|
|
3724
|
-
select(this)
|
|
3973
|
+
const slice = select(this);
|
|
3974
|
+
// Hovered mid-way through the enter sweep, the slice is finished first: growing it straight
|
|
3975
|
+
// from its part-swept path morphed it oddly on the way out to the hover shape. Only then -
|
|
3976
|
+
// re-entering a slice mid-way through its hover shrink must grow it from where it is, not
|
|
3977
|
+
// snap it back to rest first (which flickered).
|
|
3978
|
+
if (active(this, 'enter')) {
|
|
3979
|
+
slice.interrupt('enter').attr('d', self.arcShape(d));
|
|
3980
|
+
}
|
|
3981
|
+
slice
|
|
3982
|
+
.transition(t)
|
|
3725
3983
|
.attr('d', self.arcOverShape)
|
|
3726
3984
|
.style('fill', ct);
|
|
3727
3985
|
})
|
|
@@ -3739,7 +3997,8 @@ class PieChartBuilder extends PcacChart {
|
|
|
3739
3997
|
.on('click', (_event, d) => {
|
|
3740
3998
|
this.sliceClickedSource.next(d.data);
|
|
3741
3999
|
})
|
|
3742
|
-
|
|
4000
|
+
// Named, so the hover transitions (unnamed) and the check above can tell it apart from them.
|
|
4001
|
+
.transition('enter')
|
|
3743
4002
|
.duration(this.transitionService.getTransitionDuration())
|
|
3744
4003
|
.attrTween('d', (b) => {
|
|
3745
4004
|
return this.tweenChart(b);
|
|
@@ -3757,12 +4016,12 @@ class PieChartBuilder extends PcacChart {
|
|
|
3757
4016
|
}
|
|
3758
4017
|
const maxWidth = this.innerRadius * CENTER_TEXT_WIDTH;
|
|
3759
4018
|
const center = this.svg.append('g')
|
|
3760
|
-
.attr('class', 'pcac-
|
|
4019
|
+
.attr('class', 'pcac-donut-center')
|
|
3761
4020
|
.attr('pointer-events', 'none')
|
|
3762
|
-
.style('--pcac-
|
|
3763
|
-
.style('--pcac-
|
|
3764
|
-
const label = this.drawCenterLine(center, 'pcac-
|
|
3765
|
-
const subLabel = this.drawCenterLine(center, 'pcac-
|
|
4021
|
+
.style('--pcac-donut-center-label-color', () => donut.labelColor ?? null)
|
|
4022
|
+
.style('--pcac-donut-center-sub-label-color', () => donut.subLabelColor ?? null);
|
|
4023
|
+
const label = this.drawCenterLine(center, 'pcac-donut-center-label', donut.label, Math.min(this.innerRadius * 0.5, 40), maxWidth);
|
|
4024
|
+
const subLabel = this.drawCenterLine(center, 'pcac-donut-center-sub-label', donut.subLabel, Math.min(this.innerRadius * 0.2, 16), maxWidth);
|
|
3766
4025
|
if (!label && !subLabel) {
|
|
3767
4026
|
center.remove();
|
|
3768
4027
|
return;
|
|
@@ -3804,34 +4063,47 @@ class PieChartBuilder extends PcacChart {
|
|
|
3804
4063
|
const i = interpolate({ startAngle: 0, endAngle: 0 }, b);
|
|
3805
4064
|
return (t) => this.arcShape(i(t)) ?? '';
|
|
3806
4065
|
}
|
|
3807
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
3808
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.
|
|
4066
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PieDonutChartBuilder, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
|
4067
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PieDonutChartBuilder });
|
|
3809
4068
|
}
|
|
3810
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
4069
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PieDonutChartBuilder, decorators: [{
|
|
3811
4070
|
type: Injectable
|
|
3812
4071
|
}] });
|
|
4072
|
+
/** A donut config with its defaults filled in for whatever the consumer left unset. */
|
|
4073
|
+
function donutSettings(config) {
|
|
4074
|
+
const defaults = new PcacDonutChartConfig();
|
|
4075
|
+
// Unset or not a number (NaN, say - an empty number input's value), the default: a NaN ratio
|
|
4076
|
+
// survived the clamp and made every slice's path NaN, so nothing drew.
|
|
4077
|
+
const innerRadius = Number.isFinite(config.innerRadius) ? config.innerRadius : defaults.innerRadius ?? 0;
|
|
4078
|
+
return { ...config, innerRadius };
|
|
4079
|
+
}
|
|
3813
4080
|
|
|
3814
|
-
|
|
3815
|
-
|
|
4081
|
+
/**
|
|
4082
|
+
* The chart the pie and donut charts share, drawn by `PcacPieChart` and `PcacDonutChart` with
|
|
4083
|
+
* their own `type`. Internal, like `<pcac-line-area-chart>` behind the line, area and plot charts.
|
|
4084
|
+
*/
|
|
4085
|
+
class PcacPieDonutChartComponent {
|
|
4086
|
+
chartBuilder = inject(PieDonutChartBuilder);
|
|
3816
4087
|
config = input.required(/* @ts-ignore */
|
|
3817
4088
|
...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
|
|
4089
|
+
type = input.required(/* @ts-ignore */
|
|
4090
|
+
...(ngDevMode ? [{ debugName: "type" }] : /* istanbul ignore next */ []));
|
|
3818
4091
|
chartElm = viewChild.required('chart', /* @ts-ignore */
|
|
3819
4092
|
...(ngDevMode ? [{ debugName: "chartElm" }] : /* istanbul ignore next */ []));
|
|
3820
4093
|
sliceClicked = outputFromObservable(this.chartBuilder.sliceClicked$);
|
|
3821
4094
|
/**
|
|
3822
|
-
*
|
|
3823
|
-
*
|
|
4095
|
+
* The consumer's `<ng-template pcacTooltip>`, forwarded by the wrapper it was projected into:
|
|
4096
|
+
* a content query here wouldn't see it through the wrapper's template (see
|
|
4097
|
+
* PcacLineAreaChartComponent.tooltipTemplate).
|
|
3824
4098
|
*/
|
|
3825
|
-
tooltipTemplate =
|
|
3826
|
-
...(ngDevMode ? [{ debugName: "tooltipTemplate" }] : /* istanbul ignore next */ []));
|
|
4099
|
+
tooltipTemplate = input(/* @ts-ignore */
|
|
4100
|
+
...(ngDevMode ? [undefined, { debugName: "tooltipTemplate" }] : /* istanbul ignore next */ []));
|
|
3827
4101
|
constructor() {
|
|
3828
|
-
//
|
|
3829
|
-
// lifecycle hook) is what makes this an effect: it tracks config() as its dependency and
|
|
3830
|
-
// reruns whenever a new value comes in, signal-input-changes-drive-behavior all the way down.
|
|
4102
|
+
// Tracks config() and type(), rebuilding whenever either changes.
|
|
3831
4103
|
effect(() => this.buildChart());
|
|
3832
|
-
// Handed over as a getter so the builder reads the
|
|
4104
|
+
// Handed over as a getter so the builder reads the input at hover time, not in the effect
|
|
3833
4105
|
// above (see PcacChart.tooltipTemplate).
|
|
3834
|
-
this.chartBuilder.tooltipTemplate = () => this.tooltipTemplate()
|
|
4106
|
+
this.chartBuilder.tooltipTemplate = () => this.tooltipTemplate();
|
|
3835
4107
|
inject(PcacChartResizeService).observe(this.chartElm, () => {
|
|
3836
4108
|
// Skip the ResizeObserver's routine initial callback when it lands after the effect above
|
|
3837
4109
|
// already built successfully at this same width — only a real size change (or a build
|
|
@@ -3843,18 +4115,63 @@ class PcacPieChartComponent {
|
|
|
3843
4115
|
}
|
|
3844
4116
|
buildChart() {
|
|
3845
4117
|
const config = this.config();
|
|
4118
|
+
const type = this.type();
|
|
3846
4119
|
// Handed over even when empty: the builder clears what it last drew rather than leaving it.
|
|
3847
4120
|
if (config) {
|
|
3848
|
-
this.chartBuilder.buildChart(this.chartElm(), config);
|
|
4121
|
+
this.chartBuilder.buildChart(this.chartElm(), config, type);
|
|
3849
4122
|
}
|
|
3850
4123
|
}
|
|
3851
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
3852
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.
|
|
4124
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacPieDonutChartComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
4125
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.2.0", type: PcacPieDonutChartComponent, isStandalone: true, selector: "pcac-pie-donut-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: { sliceClicked: "sliceClicked" }, providers: [PieDonutChartBuilder], viewQueries: [{ propertyName: "chartElm", first: true, predicate: ["chart"], descendants: true, isSignal: true }], ngImport: i0, template: "<!-- pcac-pie-chart kept alongside for app CSS written against 22.2 and earlier, when this section\n belonged to the one pie component (the donut included). -->\n<section class=\"pcac-pie-donut-chart pcac-pie-chart\">\n <svg #chart></svg>\n</section>\n\n", styles: [".pcac-pie-donut-chart svg{width:100%;display:block}\n"], encapsulation: i0.ViewEncapsulation.None });
|
|
4126
|
+
}
|
|
4127
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacPieDonutChartComponent, decorators: [{
|
|
4128
|
+
type: Component,
|
|
4129
|
+
args: [{ selector: 'pcac-pie-donut-chart', encapsulation: ViewEncapsulation.None, providers: [PieDonutChartBuilder], template: "<!-- pcac-pie-chart kept alongside for app CSS written against 22.2 and earlier, when this section\n belonged to the one pie component (the donut included). -->\n<section class=\"pcac-pie-donut-chart pcac-pie-chart\">\n <svg #chart></svg>\n</section>\n\n", styles: [".pcac-pie-donut-chart svg{width:100%;display:block}\n"] }]
|
|
4130
|
+
}], 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 }] }], sliceClicked: [{ type: i0.Output, args: ["sliceClicked"] }], tooltipTemplate: [{ type: i0.Input, args: [{ isSignal: true, alias: "tooltipTemplate", required: false }] }] } });
|
|
4131
|
+
|
|
4132
|
+
class PcacPieChart {
|
|
4133
|
+
config = input.required(/* @ts-ignore */
|
|
4134
|
+
...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
|
|
4135
|
+
types = PcacPieDonutChartType;
|
|
4136
|
+
sliceClicked = output();
|
|
4137
|
+
/**
|
|
4138
|
+
* Optional consumer `<ng-template pcacTooltip>` projected into this element, forwarded to the
|
|
4139
|
+
* inner chart (see PcacPieDonutChartComponent.tooltipTemplate).
|
|
4140
|
+
*/
|
|
4141
|
+
tooltipTemplate = contentChild(PcacTooltipDirective, /* @ts-ignore */
|
|
4142
|
+
...(ngDevMode ? [{ debugName: "tooltipTemplate" }] : /* istanbul ignore next */ []));
|
|
4143
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacPieChart, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
4144
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.2.0", type: PcacPieChart, isStandalone: true, selector: "pcac-pie-chart", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { sliceClicked: "sliceClicked" }, queries: [{ propertyName: "tooltipTemplate", first: true, predicate: PcacTooltipDirective, descendants: true, isSignal: true }], ngImport: i0, template: "<pcac-pie-donut-chart [config]=\"config()\" [tooltipTemplate]=\"tooltipTemplate()?.templateRef\" [type]=\"types.Pie\" (sliceClicked)=\"sliceClicked.emit($event)\" />\n", dependencies: [{ kind: "component", type: PcacPieDonutChartComponent, selector: "pcac-pie-donut-chart", inputs: ["config", "type", "tooltipTemplate"], outputs: ["sliceClicked"] }] });
|
|
4145
|
+
}
|
|
4146
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacPieChart, decorators: [{
|
|
4147
|
+
type: Component,
|
|
4148
|
+
args: [{ selector: 'pcac-pie-chart', imports: [PcacPieDonutChartComponent], template: "<pcac-pie-donut-chart [config]=\"config()\" [tooltipTemplate]=\"tooltipTemplate()?.templateRef\" [type]=\"types.Pie\" (sliceClicked)=\"sliceClicked.emit($event)\" />\n" }]
|
|
4149
|
+
}], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }], sliceClicked: [{ type: i0.Output, args: ["sliceClicked"] }], tooltipTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => PcacTooltipDirective), { isSignal: true }] }] } });
|
|
4150
|
+
|
|
4151
|
+
class PcacPieChartConfig extends PcacPieDonutChartConfig {
|
|
4152
|
+
}
|
|
4153
|
+
|
|
4154
|
+
class PcacDonutChart {
|
|
4155
|
+
config = input.required(/* @ts-ignore */
|
|
4156
|
+
...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
|
|
4157
|
+
types = PcacPieDonutChartType;
|
|
4158
|
+
sliceClicked = output();
|
|
4159
|
+
/**
|
|
4160
|
+
* Optional consumer `<ng-template pcacTooltip>` projected into this element, forwarded to the
|
|
4161
|
+
* inner chart (see PcacPieDonutChartComponent.tooltipTemplate).
|
|
4162
|
+
*/
|
|
4163
|
+
tooltipTemplate = contentChild(PcacTooltipDirective, /* @ts-ignore */
|
|
4164
|
+
...(ngDevMode ? [{ debugName: "tooltipTemplate" }] : /* istanbul ignore next */ []));
|
|
4165
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacDonutChart, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
4166
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.2.0", type: PcacDonutChart, isStandalone: true, selector: "pcac-donut-chart", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { sliceClicked: "sliceClicked" }, queries: [{ propertyName: "tooltipTemplate", first: true, predicate: PcacTooltipDirective, descendants: true, isSignal: true }], ngImport: i0, template: "<pcac-pie-donut-chart [config]=\"config()\" [tooltipTemplate]=\"tooltipTemplate()?.templateRef\" [type]=\"types.Donut\" (sliceClicked)=\"sliceClicked.emit($event)\" />\n", dependencies: [{ kind: "component", type: PcacPieDonutChartComponent, selector: "pcac-pie-donut-chart", inputs: ["config", "type", "tooltipTemplate"], outputs: ["sliceClicked"] }] });
|
|
3853
4167
|
}
|
|
3854
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
4168
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacDonutChart, decorators: [{
|
|
3855
4169
|
type: Component,
|
|
3856
|
-
args: [{ selector: 'pcac-
|
|
3857
|
-
}],
|
|
4170
|
+
args: [{ selector: 'pcac-donut-chart', imports: [PcacPieDonutChartComponent], template: "<pcac-pie-donut-chart [config]=\"config()\" [tooltipTemplate]=\"tooltipTemplate()?.templateRef\" [type]=\"types.Donut\" (sliceClicked)=\"sliceClicked.emit($event)\" />\n" }]
|
|
4171
|
+
}], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }], sliceClicked: [{ type: i0.Output, args: ["sliceClicked"] }], tooltipTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => PcacTooltipDirective), { isSignal: true }] }] } });
|
|
4172
|
+
|
|
4173
|
+
// The shared <pcac-pie-donut-chart> and its PcacPieDonutChartConfig stay internal, like the
|
|
4174
|
+
// line/area/plot charts' base: consumers use the pie and donut wrappers and their configs.
|
|
3858
4175
|
|
|
3859
4176
|
/*
|
|
3860
4177
|
* Public API Surface of pioneer-charts
|
|
@@ -3864,5 +4181,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImpor
|
|
|
3864
4181
|
* Generated bundle index. Do not edit.
|
|
3865
4182
|
*/
|
|
3866
4183
|
|
|
3867
|
-
export { PcacAreaChart, PcacAreaChartConfig, PcacAxisChartConfig, PcacAxisConfig, PcacAxisSubLabels, PcacBarHorizontalChartColorOverrideConfig, PcacBarHorizontalChartComponent, PcacBarHorizontalChartConfig, PcacBarVerticalChartColorOverrideConfig, PcacBarVerticalChartComponent, PcacBarVerticalChartConfig, PcacChartConfig, PcacColorService, PcacData, PcacDataRange, PcacFormatEnum, PcacLegend, PcacLegendConfig, PcacLegendConfigItem, PcacLineChart, PcacLineChartConfig,
|
|
4184
|
+
export { PcacAreaChart, PcacAreaChartConfig, PcacAxisChartConfig, PcacAxisConfig, PcacAxisSubLabels, PcacBarHorizontalChartColorOverrideConfig, PcacBarHorizontalChartComponent, PcacBarHorizontalChartConfig, PcacBarVerticalChartColorOverrideConfig, PcacBarVerticalChartComponent, PcacBarVerticalChartConfig, PcacChartConfig, PcacColorService, PcacData, PcacDataRange, PcacDonutChart, PcacDonutChartConfig, PcacFormatEnum, PcacLegend, PcacLegendConfig, PcacLegendConfigItem, PcacLineChart, PcacLineChartConfig, PcacPieChart, PcacPieChartConfig, PcacPlotChart, PcacPlotChartConfig, PcacPointFanOutConfig, PcacPointImageConfig, PcacPointRangeConfig, PcacPointRangeShow, PcacPointRangeStyle, PcacRangeBounds, PcacTooltipDirective };
|
|
3868
4185
|
//# sourceMappingURL=pioneer-code-pioneer-charts.mjs.map
|