@pioneer-code/pioneer-charts 22.2.14 → 22.2.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,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
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
862
|
+
if (value !== null && value !== undefined) {
|
|
863
|
+
value = formatValue(valueFormat, value) ?? value;
|
|
864
|
+
}
|
|
865
|
+
if (key !== null && key !== undefined && key !== '') {
|
|
866
|
+
// A key that doesn't parse as a date is shown as it is, rather than as "Invalid Date".
|
|
867
|
+
if (keyFormat === PcacFormatEnum.DateTime && !Number.isNaN(new Date(key).getTime())) {
|
|
868
|
+
key = new Date(key).toLocaleDateString('en-US', {
|
|
869
|
+
day: '2-digit',
|
|
870
|
+
month: '2-digit',
|
|
871
|
+
year: 'numeric',
|
|
872
|
+
hour: '2-digit',
|
|
873
|
+
minute: '2-digit',
|
|
874
|
+
second: '2-digit'
|
|
875
|
+
});
|
|
811
876
|
}
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
day: '2-digit',
|
|
818
|
-
month: '2-digit',
|
|
819
|
-
year: 'numeric',
|
|
820
|
-
hour: '2-digit',
|
|
821
|
-
minute: '2-digit',
|
|
822
|
-
second: '2-digit'
|
|
823
|
-
});
|
|
824
|
-
break;
|
|
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,10 +1174,31 @@ 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;
|
|
@@ -1132,9 +1215,7 @@ class PcacChart {
|
|
|
1132
1215
|
.attr('role', 'img')
|
|
1133
1216
|
.attr('aria-label', config.ariaLabel || this.chartTypeLabel);
|
|
1134
1217
|
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)));
|
|
1218
|
+
this.colors = colors;
|
|
1138
1219
|
this.lastContainerWidth = containerWidth;
|
|
1139
1220
|
this.lastContainerHeight = container.clientHeight;
|
|
1140
1221
|
this.lastHeightFull = config.heightFull === true;
|
|
@@ -1172,9 +1253,10 @@ class PcacChart {
|
|
|
1172
1253
|
* `PcacChartResizeService`'s `ResizeObserver` is guaranteed to fire once as soon as it starts
|
|
1173
1254
|
* observing — that's what lets a chart recover from the 0-width race described on
|
|
1174
1255
|
* `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
|
|
1256
|
+
* moments after the component's build `effect` already built successfully at the same width.
|
|
1257
|
+
* Without this check, that redundant callback would restart the chart's enter transition
|
|
1258
|
+
* mid-animation for no visual change. Only that effect (which reacts to config, not size) should
|
|
1259
|
+
* skip this check.
|
|
1178
1260
|
* @param chartElm Reference to SVG on dom
|
|
1179
1261
|
*/
|
|
1180
1262
|
containerSizeChanged(chartElm) {
|
|
@@ -1227,10 +1309,16 @@ class PcacChart {
|
|
|
1227
1309
|
* the label, so measuring at a different length would put the labels off by the difference)
|
|
1228
1310
|
* and adds its `axisLabelSpace()` back on top, since the measurement replaces whatever
|
|
1229
1311
|
* `initializeAxisState()` reserved for the label / sub labels.
|
|
1312
|
+
*
|
|
1313
|
+
* The margin never takes more than `MAX_LABEL_MARGIN_SHARE` of the container: labels wider than
|
|
1314
|
+
* that are cut off at the chart's left edge rather than squeezing the plot to nothing (it used
|
|
1315
|
+
* to go to a negative width, and no bars drew at all). Returns `false`, like
|
|
1316
|
+
* `initializeChartState()`, if there is still no room left to draw in.
|
|
1230
1317
|
* @param chartElm Reference to SVG on dom
|
|
1231
1318
|
* @param yScale D3 scale transformation object (d3.ScaleBand)
|
|
1232
1319
|
*/
|
|
1233
1320
|
setHorizontalMarginsBasedOnContent(chartElm, yScale) {
|
|
1321
|
+
this.yTickLabelMaxWidth = null;
|
|
1234
1322
|
const axisY = axisLeft(yScale).ticks(5);
|
|
1235
1323
|
if (this.yAxis.tickSize !== undefined) {
|
|
1236
1324
|
axisY.tickSizeInner(this.yAxis.tickSize);
|
|
@@ -1250,22 +1338,72 @@ class PcacChart {
|
|
|
1250
1338
|
// double-counted it, and since `margin` persists on the builder between builds, the amount
|
|
1251
1339
|
// double-counted grew on the next rebuild - the plot area came out narrower than the
|
|
1252
1340
|
// container allowed and then shrank further after the first resize.
|
|
1253
|
-
const
|
|
1341
|
+
const containerWidth = this.width + this.margin.left + this.margin.right;
|
|
1342
|
+
const labelSpace = axisLabelSpace(this.yAxis);
|
|
1343
|
+
const left = Math.min(max + labelSpace, containerWidth * MAX_LABEL_MARGIN_SHARE);
|
|
1254
1344
|
this.width = this.width + this.margin.left - left;
|
|
1255
1345
|
this.margin.left = left;
|
|
1346
|
+
if (left < max + labelSpace) {
|
|
1347
|
+
// Capped: the labels are shortened to what's left between the axis title's band and the
|
|
1348
|
+
// ticks (see `truncateYTickLabels`), rather than running on past the chart's edge - and
|
|
1349
|
+
// over the title.
|
|
1350
|
+
const tickOverhead = Math.max(this.yAxis.tickSize ?? DEFAULT_TICK_SIZE, 0) + TICK_PADDING;
|
|
1351
|
+
this.yTickLabelMaxWidth = Math.max(0, left - labelSpace - tickOverhead);
|
|
1352
|
+
}
|
|
1353
|
+
return this.width > 0;
|
|
1354
|
+
}
|
|
1355
|
+
/**
|
|
1356
|
+
* Shortens every y-axis tick label wider than the room `setHorizontalMarginsBasedOnContent` left
|
|
1357
|
+
* for it, ending it in "…". Call after the axis is drawn. Does nothing when the labels fit.
|
|
1358
|
+
*/
|
|
1359
|
+
truncateYTickLabels() {
|
|
1360
|
+
const maxWidth = this.yTickLabelMaxWidth;
|
|
1361
|
+
if (maxWidth === null) {
|
|
1362
|
+
return;
|
|
1363
|
+
}
|
|
1364
|
+
this.svg.selectAll('.pcac-y-axis .tick text').each(function () {
|
|
1365
|
+
fitText(this, maxWidth);
|
|
1366
|
+
});
|
|
1256
1367
|
}
|
|
1257
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
1258
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.
|
|
1368
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacChart, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1369
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacChart });
|
|
1259
1370
|
}
|
|
1260
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
1371
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacChart, decorators: [{
|
|
1261
1372
|
type: Injectable
|
|
1262
1373
|
}] });
|
|
1374
|
+
/**
|
|
1375
|
+
* Shortens `text` to the longest prefix that, with "…" appended, fits in `maxWidth` - just "…"
|
|
1376
|
+
* if nothing does. Measured with `getComputedTextLength()`, so the text must be rendered; left
|
|
1377
|
+
* alone where that isn't available (a DOM without layout).
|
|
1378
|
+
*/
|
|
1379
|
+
function fitText(text, maxWidth) {
|
|
1380
|
+
if (typeof text.getComputedTextLength !== 'function' || text.getComputedTextLength() <= maxWidth) {
|
|
1381
|
+
return;
|
|
1382
|
+
}
|
|
1383
|
+
const full = text.textContent ?? '';
|
|
1384
|
+
const withEllipsis = (length) => full.slice(0, length).trimEnd() + '…';
|
|
1385
|
+
let fits = 0;
|
|
1386
|
+
let tooLong = full.length;
|
|
1387
|
+
while (tooLong - fits > 1) {
|
|
1388
|
+
const mid = Math.floor((fits + tooLong) / 2);
|
|
1389
|
+
text.textContent = withEllipsis(mid);
|
|
1390
|
+
if (text.getComputedTextLength() <= maxWidth) {
|
|
1391
|
+
fits = mid;
|
|
1392
|
+
}
|
|
1393
|
+
else {
|
|
1394
|
+
tooLong = mid;
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
text.textContent = withEllipsis(fits);
|
|
1398
|
+
}
|
|
1263
1399
|
|
|
1264
1400
|
/**
|
|
1265
1401
|
* How long each bar is drawn: its value, or 0 when it can't be drawn - a null or non-numeric
|
|
1266
1402
|
* value, or `hide` set on the bar or on its whole group. A hidden bar keeps its slot (and so its
|
|
1267
1403
|
* color) and just draws nothing, the same way a hidden line/area/plot series keeps its place.
|
|
1268
|
-
*
|
|
1404
|
+
* A negative value is drawn as 0 too: the bar charts only draw upward from a 0 baseline, and a
|
|
1405
|
+
* negative size was an invalid SVG `height`/`width` (the bar vanished with a console error) that
|
|
1406
|
+
* also pulled the rest of a stack down over the bars before it.
|
|
1269
1407
|
*
|
|
1270
1408
|
* Keyed by the bar's own `PcacData` object so D3 callbacks (which only get the datum) can look
|
|
1271
1409
|
* their size up directly.
|
|
@@ -1275,7 +1413,7 @@ function barSizes(groups) {
|
|
|
1275
1413
|
for (const group of groups) {
|
|
1276
1414
|
for (const bar of group.data ?? []) {
|
|
1277
1415
|
const value = Number(bar.value ?? 0);
|
|
1278
|
-
sizes.set(bar, group.hide || bar.hide || !Number.isFinite(value) ? 0 : value);
|
|
1416
|
+
sizes.set(bar, group.hide || bar.hide || !Number.isFinite(value) ? 0 : Math.max(0, value));
|
|
1279
1417
|
}
|
|
1280
1418
|
}
|
|
1281
1419
|
return sizes;
|
|
@@ -1359,6 +1497,27 @@ function seriesKeys(groups) {
|
|
|
1359
1497
|
}
|
|
1360
1498
|
return [...keys];
|
|
1361
1499
|
}
|
|
1500
|
+
/**
|
|
1501
|
+
* Whether every bar has a key that is unique within its own group - what coloring bars by series
|
|
1502
|
+
* key needs. Without that (keys left `null`, as `PcacData` defaults them, or repeated within a
|
|
1503
|
+
* group, as stacked data often has), coloring by key would paint every bar sharing a key the
|
|
1504
|
+
* same color, so the bars fall back to being colored by their position in the group.
|
|
1505
|
+
*/
|
|
1506
|
+
function hasDistinctSeriesKeys(groups) {
|
|
1507
|
+
return groups.every((group) => {
|
|
1508
|
+
const keys = (group.data ?? []).map((bar) => bar.key);
|
|
1509
|
+
return keys.every((key) => key !== null && key !== undefined && key !== '')
|
|
1510
|
+
&& new Set(keys).size === keys.length;
|
|
1511
|
+
});
|
|
1512
|
+
}
|
|
1513
|
+
/**
|
|
1514
|
+
* Whether a band scale spanning `length` pixels across `count` bands can round them to whole
|
|
1515
|
+
* pixels. Rounding gives crisp bar edges, but it floors the step - so with more bands than pixels
|
|
1516
|
+
* every band collapses to 0 and nothing draws. Only rounded while each band gets at least 2px.
|
|
1517
|
+
*/
|
|
1518
|
+
function canRoundBands(length, count) {
|
|
1519
|
+
return count > 0 && length / count >= 2;
|
|
1520
|
+
}
|
|
1362
1521
|
|
|
1363
1522
|
/**
|
|
1364
1523
|
* Provided per-component (see PcacBarHorizontalChartComponent's `providers`), not root-scoped:
|
|
@@ -1371,7 +1530,6 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
1371
1530
|
yScaleStacked;
|
|
1372
1531
|
yScaleGrouped;
|
|
1373
1532
|
barClickedSource = new Subject();
|
|
1374
|
-
config;
|
|
1375
1533
|
barClicked$ = this.barClickedSource.asObservable();
|
|
1376
1534
|
chartTypeLabel = 'Bar chart';
|
|
1377
1535
|
buildChart(chartElm, config) {
|
|
@@ -1379,15 +1537,23 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
1379
1537
|
this.clearChart(chartElm);
|
|
1380
1538
|
return;
|
|
1381
1539
|
}
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1540
|
+
// Shallow copy, as the vertical chart does: initializeAxisState() rewrites `height`, which
|
|
1541
|
+
// must not land on the consumer's config - but the data stays the consumer's own objects, so
|
|
1542
|
+
// `barClicked` and the tooltip hand back the very `PcacData` they passed in. (A JSON deep copy
|
|
1543
|
+
// used to hand back clones, which never matched the consumer's data by identity.)
|
|
1544
|
+
config = { ...config };
|
|
1545
|
+
this.initializeAxisState(config, 'x');
|
|
1546
|
+
if (!this.initializeChartState(chartElm, config)) {
|
|
1385
1547
|
return;
|
|
1386
1548
|
}
|
|
1549
|
+
this.ensureColorCount(seriesKeys(config.data).length);
|
|
1387
1550
|
this.applyColorOverride(config.colorOverride?.colors);
|
|
1388
|
-
this.buildScales(chartElm,
|
|
1389
|
-
|
|
1551
|
+
if (!this.buildScales(chartElm, config)) {
|
|
1552
|
+
return;
|
|
1553
|
+
}
|
|
1554
|
+
this.drawChart(chartElm, config);
|
|
1390
1555
|
}
|
|
1556
|
+
/** Returns `false` if the container leaves no room to draw in once the labels are measured. */
|
|
1391
1557
|
buildScales(chartElm, config) {
|
|
1392
1558
|
// Bars grow from 0, so only `domainMax` is read; `xAxis.domainMin` is ignored.
|
|
1393
1559
|
this.xScale = scaleLinear()
|
|
@@ -1395,20 +1561,25 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
1395
1561
|
this.yScaleStacked = scaleBand()
|
|
1396
1562
|
.domain(config.data.map((d) => d.key))
|
|
1397
1563
|
.range([this.height, 0])
|
|
1564
|
+
// Rounded to whole pixels for crisp bar edges, while there's room to (see canRoundBands).
|
|
1565
|
+
.round(canRoundBands(this.height, config.data.length))
|
|
1398
1566
|
.padding(0.1);
|
|
1399
1567
|
this.yScaleGrouped = scaleBand()
|
|
1400
1568
|
.padding(0.05)
|
|
1401
|
-
.
|
|
1569
|
+
.range([0, this.yScaleStacked.bandwidth()])
|
|
1570
|
+
.round(canRoundBands(this.yScaleStacked.bandwidth(), seriesKeys(config.data).length))
|
|
1402
1571
|
.domain(seriesKeys(config.data));
|
|
1403
1572
|
// 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
|
-
|
|
1573
|
+
if (!this.yAxis.hide && !this.setHorizontalMarginsBasedOnContent(chartElm, this.yScaleStacked)) {
|
|
1574
|
+
return false;
|
|
1406
1575
|
}
|
|
1407
1576
|
this.xScale.range([0, this.width]);
|
|
1577
|
+
return true;
|
|
1408
1578
|
}
|
|
1409
1579
|
drawChart(chartElm, config) {
|
|
1410
1580
|
this.buildContainer(chartElm);
|
|
1411
1581
|
this.axisBuilder.drawAxis(this.axisBuilderConfig(this.xScale, this.yScaleStacked));
|
|
1582
|
+
this.truncateYTickLabels();
|
|
1412
1583
|
this.drawGrids(this.xScale, this.yScaleStacked);
|
|
1413
1584
|
this.addGroups(config);
|
|
1414
1585
|
this.axisBuilder.raiseAxes(this.svg);
|
|
@@ -1451,60 +1622,53 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
1451
1622
|
const starts = config.isStacked ? stackStarts(config.data, sizes) : new Map();
|
|
1452
1623
|
const startOf = (d) => starts.get(d) ?? 0;
|
|
1453
1624
|
const endOf = (d) => startOf(d) + (sizes.get(d) ?? 0);
|
|
1625
|
+
// Colored by series - the bar's key's place among every group's keys, the same slot it's drawn
|
|
1626
|
+
// in - rather than by its position in its own group, which differs when groups hold different
|
|
1627
|
+
// series. By position after all when the keys can't tell series apart (see
|
|
1628
|
+
// `hasDistinctSeriesKeys`), and with `spreadColorsPerGroup`, by group instead.
|
|
1629
|
+
const keys = seriesKeys(config.data);
|
|
1630
|
+
const byKey = hasDistinctSeriesKeys(config.data);
|
|
1631
|
+
const fillOf = (d, bar) => {
|
|
1632
|
+
if (config.spreadColorsPerGroup) {
|
|
1633
|
+
return this.colors[Number(bar.parentNode.getAttribute('data-group-id'))];
|
|
1634
|
+
}
|
|
1635
|
+
return this.colors[byKey ? keys.indexOf(d.key) : Number(bar.getAttribute('data-group-bar-id'))];
|
|
1636
|
+
};
|
|
1454
1637
|
groups.enter().append('rect')
|
|
1455
1638
|
.attr('class', 'pcac-bar')
|
|
1456
1639
|
.attr('x', (d) => this.xScale(startOf(d)))
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1640
|
+
// A stacked bar spans its whole group, which is already translated into place; looking its
|
|
1641
|
+
// series key up in the group band put it off in another group's slot whenever the key
|
|
1642
|
+
// matched a group key.
|
|
1643
|
+
.attr('y', (d) => config.isStacked ? 0 : this.yScaleGrouped(d.key) ?? 0)
|
|
1461
1644
|
.attr('data-group-bar-id', (_, i) => {
|
|
1462
1645
|
return i;
|
|
1463
1646
|
})
|
|
1464
1647
|
.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];
|
|
1648
|
+
.style('fill', function (d) {
|
|
1649
|
+
return fillOf(d, this);
|
|
1471
1650
|
})
|
|
1472
1651
|
.attr('width', 0)
|
|
1473
|
-
|
|
1652
|
+
// The hover fades run as their own named transition: an unnamed one would cancel the enter
|
|
1653
|
+
// transition still growing the bar, leaving it part-grown until the next rebuild.
|
|
1654
|
+
.on('mouseover', function (_event, d) {
|
|
1655
|
+
const fill = fillOf(d, this);
|
|
1474
1656
|
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
|
-
});
|
|
1657
|
+
.transition('hover')
|
|
1658
|
+
.duration(self.transitionService.getTransitionDuration() / 5)
|
|
1659
|
+
.style('fill', color(fill)?.darker(1).toString() ?? fill);
|
|
1489
1660
|
})
|
|
1490
1661
|
.on('mousemove', function (event, d) {
|
|
1491
1662
|
const groupIndex = Number(this.parentNode.getAttribute('data-group-id'));
|
|
1492
1663
|
const index = Number(this.getAttribute('data-group-bar-id'));
|
|
1493
1664
|
self.showTooltip(event, d, { index, parent: config.data[groupIndex], parentIndex: groupIndex, valueFormat: self.xAxis.format });
|
|
1494
1665
|
})
|
|
1495
|
-
.on('mouseout', function () {
|
|
1666
|
+
.on('mouseout', function (_event, d) {
|
|
1496
1667
|
self.hideTooltip();
|
|
1497
1668
|
select(this)
|
|
1498
|
-
.transition()
|
|
1669
|
+
.transition('hover')
|
|
1499
1670
|
.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
|
-
});
|
|
1671
|
+
.style('fill', fillOf(d, this));
|
|
1508
1672
|
})
|
|
1509
1673
|
.on('click', (_event, d) => {
|
|
1510
1674
|
this.barClickedSource.next(d);
|
|
@@ -1561,6 +1725,10 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
1561
1725
|
.attr('data-group-threshold-id', (_, i) => {
|
|
1562
1726
|
return i;
|
|
1563
1727
|
})
|
|
1728
|
+
// Placed in its bar's slot up front - only its value (`x`) animates. Set on the transition,
|
|
1729
|
+
// it slid in from the top of the group, where the vertical chart's appear in place.
|
|
1730
|
+
// ScaleBand can return undefined for a key outside its domain; `.attr()` needs null, not undefined.
|
|
1731
|
+
.attr('y', (d) => this.yScaleGrouped(d.key) ?? null)
|
|
1564
1732
|
.attr('height', this.yScaleGrouped.bandwidth());
|
|
1565
1733
|
rects.filter(function () {
|
|
1566
1734
|
return thresholdOf(this) === null;
|
|
@@ -1576,10 +1744,6 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
1576
1744
|
})
|
|
1577
1745
|
.transition()
|
|
1578
1746
|
.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
1747
|
.attr('x', (_, i, nodes) => {
|
|
1584
1748
|
return this.xScale(Number(thresholdOf(nodes[i])?.value));
|
|
1585
1749
|
});
|
|
@@ -1600,10 +1764,10 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
1600
1764
|
this.hideTooltip();
|
|
1601
1765
|
});
|
|
1602
1766
|
}
|
|
1603
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
1604
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.
|
|
1767
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: BarHorizontalChartBuilder, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
|
1768
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: BarHorizontalChartBuilder });
|
|
1605
1769
|
}
|
|
1606
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
1770
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: BarHorizontalChartBuilder, decorators: [{
|
|
1607
1771
|
type: Injectable
|
|
1608
1772
|
}] });
|
|
1609
1773
|
|
|
@@ -1613,7 +1777,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImpor
|
|
|
1613
1777
|
* A plain `window:resize` listener (the previous approach) misses any layout-driven size change
|
|
1614
1778
|
* that isn't a viewport resize — a sidebar collapsing, a tab becoming active, a flex/grid reflow.
|
|
1615
1779
|
* It also can't help a chart that mounts already holding data (e.g. behind a loading gate): that
|
|
1616
|
-
* chart's first `
|
|
1780
|
+
* chart's first build `effect` run can fire before the browser has committed layout for its own
|
|
1617
1781
|
* just-created DOM node, so `PcacChart.initializeChartState()` measures a 0-width container and
|
|
1618
1782
|
* bails out with nothing drawn — and with no resize ever firing, nothing retries it.
|
|
1619
1783
|
*
|
|
@@ -1656,10 +1820,10 @@ class PcacChartResizeService {
|
|
|
1656
1820
|
destroyRef.onDestroy(() => observer.disconnect());
|
|
1657
1821
|
});
|
|
1658
1822
|
}
|
|
1659
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
1660
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.
|
|
1823
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacChartResizeService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1824
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacChartResizeService, providedIn: 'root' });
|
|
1661
1825
|
}
|
|
1662
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
1826
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacChartResizeService, decorators: [{
|
|
1663
1827
|
type: Injectable,
|
|
1664
1828
|
args: [{ providedIn: 'root' }]
|
|
1665
1829
|
}] });
|
|
@@ -1709,10 +1873,10 @@ class PcacTooltipDirective {
|
|
|
1709
1873
|
static ngTemplateContextGuard(_dir, _ctx) {
|
|
1710
1874
|
return true;
|
|
1711
1875
|
}
|
|
1712
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
1713
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "22.
|
|
1876
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacTooltipDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1877
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "22.2.0", type: PcacTooltipDirective, isStandalone: true, selector: "ng-template[pcacTooltip]", ngImport: i0 });
|
|
1714
1878
|
}
|
|
1715
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
1879
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacTooltipDirective, decorators: [{
|
|
1716
1880
|
type: Directive,
|
|
1717
1881
|
args: [{
|
|
1718
1882
|
selector: 'ng-template[pcacTooltip]'
|
|
@@ -1756,10 +1920,10 @@ class PcacBarHorizontalChartComponent {
|
|
|
1756
1920
|
this.chartBuilder.buildChart(this.chartElm(), config);
|
|
1757
1921
|
}
|
|
1758
1922
|
}
|
|
1759
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
1760
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.
|
|
1923
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacBarHorizontalChartComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1924
|
+
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
1925
|
}
|
|
1762
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
1926
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacBarHorizontalChartComponent, decorators: [{
|
|
1763
1927
|
type: Component,
|
|
1764
1928
|
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
1929
|
}], 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 +1964,7 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
1800
1964
|
if (!this.initializeChartState(chartElm, config)) {
|
|
1801
1965
|
return;
|
|
1802
1966
|
}
|
|
1967
|
+
this.ensureColorCount(seriesKeys(config.data).length);
|
|
1803
1968
|
this.applyColorOverride(config.colorOverride?.colors);
|
|
1804
1969
|
this.buildScales(config);
|
|
1805
1970
|
this.drawChart(chartElm, config);
|
|
@@ -1813,11 +1978,14 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
1813
1978
|
.domain([this.yAxis.domainMax, 0]);
|
|
1814
1979
|
this.xScaleStacked = scaleBand()
|
|
1815
1980
|
.domain(config.data.map((d) => d.key))
|
|
1816
|
-
.
|
|
1981
|
+
.range([0, this.width])
|
|
1982
|
+
// Rounded to whole pixels for crisp bar edges, while there's room to (see canRoundBands).
|
|
1983
|
+
.round(canRoundBands(this.width, config.data.length))
|
|
1817
1984
|
.padding(0.1);
|
|
1818
1985
|
this.xScaleGrouped = scaleBand()
|
|
1819
1986
|
.padding(0.2)
|
|
1820
|
-
.
|
|
1987
|
+
.range([0, this.xScaleStacked.bandwidth()])
|
|
1988
|
+
.round(canRoundBands(this.xScaleStacked.bandwidth(), seriesKeys(config.data).length))
|
|
1821
1989
|
.domain(seriesKeys(config.data));
|
|
1822
1990
|
}
|
|
1823
1991
|
drawChart(chartElm, config) {
|
|
@@ -1867,70 +2035,60 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
1867
2035
|
const starts = config.isStacked ? stackStarts(config.data, sizes) : new Map();
|
|
1868
2036
|
const startOf = (d) => starts.get(d) ?? 0;
|
|
1869
2037
|
const endOf = (d) => startOf(d) + (sizes.get(d) ?? 0);
|
|
2038
|
+
// Colored by series - the bar's key's place among every group's keys, the same slot it's drawn
|
|
2039
|
+
// in - rather than by its position in its own group, which differs when groups hold different
|
|
2040
|
+
// series. By position after all when the keys can't tell series apart (see
|
|
2041
|
+
// `hasDistinctSeriesKeys`), and with `spreadColorsPerGroup`, by group instead.
|
|
2042
|
+
const keys = seriesKeys(config.data);
|
|
2043
|
+
const byKey = hasDistinctSeriesKeys(config.data);
|
|
2044
|
+
const fillOf = (d, bar) => {
|
|
2045
|
+
if (config.spreadColorsPerGroup) {
|
|
2046
|
+
return this.colors[Number(bar.parentNode.getAttribute('data-group-id'))];
|
|
2047
|
+
}
|
|
2048
|
+
return this.colors[byKey ? keys.indexOf(d.key) : Number(bar.getAttribute('data-group-bar-id'))];
|
|
2049
|
+
};
|
|
1870
2050
|
group.enter().append('rect')
|
|
1871
2051
|
.attr('class', 'pcac-bar')
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
2052
|
+
// A stacked bar spans its whole group, which is already translated into place; looking its
|
|
2053
|
+
// series key up in the group band put it off in another group's slot whenever the key
|
|
2054
|
+
// matched a group key.
|
|
2055
|
+
.attr('x', (d) => config.isStacked ? 0 : this.xScaleGrouped(d.key) ?? 0)
|
|
1876
2056
|
.attr('data-group-bar-id', (_, i) => {
|
|
1877
2057
|
return i;
|
|
1878
2058
|
})
|
|
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];
|
|
2059
|
+
.style('fill', function (d) {
|
|
2060
|
+
return fillOf(d, this);
|
|
1885
2061
|
})
|
|
1886
2062
|
.attr('y', () => {
|
|
1887
2063
|
return this.height;
|
|
1888
2064
|
})
|
|
1889
2065
|
.attr('height', 0)
|
|
1890
|
-
|
|
2066
|
+
// The hover fades run as their own named transition: an unnamed one would cancel the enter
|
|
2067
|
+
// transition still growing the bar, leaving it part-grown until the next rebuild.
|
|
2068
|
+
.on('mouseover', function (_event, d) {
|
|
2069
|
+
const fill = fillOf(d, this);
|
|
1891
2070
|
select(this)
|
|
1892
|
-
.transition()
|
|
2071
|
+
.transition('hover')
|
|
1893
2072
|
.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
|
-
});
|
|
2073
|
+
.style('fill', color(fill)?.darker(1).toString() ?? fill);
|
|
1906
2074
|
})
|
|
1907
2075
|
.on('mousemove', function (event, d) {
|
|
1908
2076
|
const groupIndex = Number(this.parentNode.getAttribute('data-group-id'));
|
|
1909
2077
|
const index = Number(this.getAttribute('data-group-bar-id'));
|
|
1910
2078
|
self.showTooltip(event, d, { index, parent: config.data[groupIndex], parentIndex: groupIndex, valueFormat: self.yAxis.format });
|
|
1911
2079
|
})
|
|
1912
|
-
.on('mouseout', function () {
|
|
2080
|
+
.on('mouseout', function (_event, d) {
|
|
1913
2081
|
self.hideTooltip();
|
|
1914
2082
|
select(this)
|
|
1915
|
-
.transition()
|
|
2083
|
+
.transition('hover')
|
|
1916
2084
|
.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
|
-
});
|
|
2085
|
+
.style('fill', fillOf(d, this));
|
|
1925
2086
|
})
|
|
1926
2087
|
.on('click', (_, d) => {
|
|
1927
2088
|
this.barClickedSource.next(d);
|
|
1928
2089
|
})
|
|
1929
2090
|
.transition()
|
|
1930
2091
|
.duration(this.transitionService.getTransitionDuration())
|
|
1931
|
-
// .transition(
|
|
1932
|
-
// transition().duration(this.transitionService.getTransitionDuration())
|
|
1933
|
-
// )
|
|
1934
2092
|
.attr('width', !config.isStacked ? this.xScaleGrouped.bandwidth() : this.xScaleStacked.bandwidth())
|
|
1935
2093
|
.attr('y', (d) => {
|
|
1936
2094
|
return this.yScale(endOf(d));
|
|
@@ -2036,10 +2194,10 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
2036
2194
|
return '3px';
|
|
2037
2195
|
});
|
|
2038
2196
|
}
|
|
2039
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
2040
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.
|
|
2197
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: BarVerticalChartBuilder, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
|
2198
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: BarVerticalChartBuilder });
|
|
2041
2199
|
}
|
|
2042
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
2200
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: BarVerticalChartBuilder, decorators: [{
|
|
2043
2201
|
type: Injectable
|
|
2044
2202
|
}] });
|
|
2045
2203
|
|
|
@@ -2080,10 +2238,10 @@ class PcacBarVerticalChartComponent {
|
|
|
2080
2238
|
this.chartBuilder.buildChart(this.chartElm(), config);
|
|
2081
2239
|
}
|
|
2082
2240
|
}
|
|
2083
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
2084
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.
|
|
2241
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacBarVerticalChartComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
2242
|
+
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
2243
|
}
|
|
2086
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
2244
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacBarVerticalChartComponent, decorators: [{
|
|
2087
2245
|
type: Component,
|
|
2088
2246
|
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
2247
|
}], 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,10 +2281,10 @@ class PcacLegend {
|
|
|
2123
2281
|
this.config.set({ ...this.config(), items });
|
|
2124
2282
|
this.itemClicked.emit(items);
|
|
2125
2283
|
}
|
|
2126
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
2127
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.
|
|
2284
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacLegend, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
2285
|
+
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; let last = $last;) {\n<div class=\"pcac-legend-item\" [class.pcac-legend-item-last]=\"last\" [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}.pcac-legend-label{margin-right:8px;margin-bottom:2.5px}.pcac-legend-item{cursor:pointer;display:flex;align-items:center;margin-right:8px}.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-last{margin-right:0}.pcac-legend-item:focus-visible{outline:2px solid currentColor;outline-offset:2px}\n"] });
|
|
2128
2286
|
}
|
|
2129
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
2287
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacLegend, decorators: [{
|
|
2130
2288
|
type: Component,
|
|
2131
2289
|
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; let last = $last;) {\n<div class=\"pcac-legend-item\" [class.pcac-legend-item-last]=\"last\" [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}.pcac-legend-label{margin-right:8px;margin-bottom:2.5px}.pcac-legend-item{cursor:pointer;display:flex;align-items:center;margin-right:8px}.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-last{margin-right:0}.pcac-legend-item:focus-visible{outline:2px solid currentColor;outline-offset:2px}\n"] }]
|
|
2132
2290
|
}], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }, { type: i0.Output, args: ["configChange"] }], itemClicked: [{ type: i0.Output, args: ["itemClicked"] }] } });
|
|
@@ -2223,45 +2381,73 @@ class PcacLineAreaChartConfig extends PcacAxisChartConfig {
|
|
|
2223
2381
|
pointRange;
|
|
2224
2382
|
}
|
|
2225
2383
|
|
|
2384
|
+
/**
|
|
2385
|
+
* Whether a point has an x key to position by. An explicit emptiness check, not truthiness: a
|
|
2386
|
+
* Decimal key of `0` is a perfectly good coordinate (the left edge of a `domainMin: 0` axis) and
|
|
2387
|
+
* used to be read as "no key" - drawn at pixel 0 whatever the domain, and pinned there under zoom.
|
|
2388
|
+
*/
|
|
2389
|
+
function hasKey(data) {
|
|
2390
|
+
return data.key !== null && data.key !== undefined && data.key !== '';
|
|
2391
|
+
}
|
|
2392
|
+
function getXFormat(type, data, index, xScale) {
|
|
2393
|
+
switch (type) {
|
|
2394
|
+
case PcacFormatEnum.DateTime:
|
|
2395
|
+
if (hasKey(data)) {
|
|
2396
|
+
return xScale(new Date(data.key));
|
|
2397
|
+
}
|
|
2398
|
+
return 0;
|
|
2399
|
+
case PcacFormatEnum.Decimal:
|
|
2400
|
+
if (hasKey(data)) {
|
|
2401
|
+
return xScale(Number(data.key));
|
|
2402
|
+
}
|
|
2403
|
+
return 0;
|
|
2404
|
+
default:
|
|
2405
|
+
return xScale(index);
|
|
2406
|
+
}
|
|
2407
|
+
}
|
|
2408
|
+
|
|
2409
|
+
/** Whether a point has a numeric value to draw at. */
|
|
2410
|
+
function hasValue(d) {
|
|
2411
|
+
return d.value !== null && d.value !== undefined && d.value !== '' && Number.isFinite(Number(d.value));
|
|
2412
|
+
}
|
|
2413
|
+
|
|
2226
2414
|
/**
|
|
2227
2415
|
* Provided per-component (see PcacLineAreaChartComponent's `providers`), not root-scoped: this
|
|
2228
|
-
* holds mutable per-chart-instance state (`config`, `
|
|
2416
|
+
* holds mutable per-chart-instance state (`config`, `series`) despite looking like a stateless
|
|
2229
2417
|
* helper. A root singleton would be shared and clobbered by every `<pcac-line-area-chart>`
|
|
2230
2418
|
* rendered at once — each instance's hover effects would end up reading/writing whichever
|
|
2231
2419
|
* chart's `buildEffects()` ran last, not their own.
|
|
2232
2420
|
*/
|
|
2233
2421
|
class PlaChartEffectsBuilder {
|
|
2234
2422
|
config;
|
|
2235
|
-
//
|
|
2236
|
-
//
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
lines = [];
|
|
2423
|
+
// The series that get an effect group, each with its index in `config.data` (which is what its
|
|
2424
|
+
// line's color is picked by, so a skipped empty series doesn't shift the colors after it).
|
|
2425
|
+
series = [];
|
|
2426
|
+
/** Where the cursor last was over the plot, while the crosshair is showing; null otherwise. */
|
|
2427
|
+
lastMousePos = null;
|
|
2241
2428
|
buildEffects(config) {
|
|
2242
2429
|
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
|
-
});
|
|
2430
|
+
this.lastMousePos = null;
|
|
2431
|
+
this.series = config.data
|
|
2432
|
+
.map((data, index) => ({ data, index }))
|
|
2433
|
+
.filter(({ data }) => data.data.length > 0);
|
|
2253
2434
|
this.buildCollection();
|
|
2254
2435
|
this.buildCanvas();
|
|
2255
2436
|
}
|
|
2256
2437
|
/**
|
|
2257
|
-
* Swaps in the scales a zoom has rescaled. The crosshair
|
|
2258
|
-
*
|
|
2259
|
-
*
|
|
2260
|
-
* the pixel against the original domain.
|
|
2438
|
+
* Swaps in the scales a zoom has rescaled. The crosshair positions and labels its points
|
|
2439
|
+
* against the scales, so a zoom has to hand them over here or it would track the unzoomed
|
|
2440
|
+
* lines.
|
|
2261
2441
|
*/
|
|
2262
2442
|
updateScales(x, y) {
|
|
2263
2443
|
this.config.x = x;
|
|
2264
2444
|
this.config.y = y;
|
|
2445
|
+
// A wheel zoom moves the lines under a cursor that stays put, and sends no mousemove - so the
|
|
2446
|
+
// crosshair is re-read at the same spot, or it would sit on the pre-zoom values until the
|
|
2447
|
+
// mouse next moved.
|
|
2448
|
+
if (this.lastMousePos) {
|
|
2449
|
+
this.onMouseMove(this.lastMousePos);
|
|
2450
|
+
}
|
|
2265
2451
|
}
|
|
2266
2452
|
buildCollection() {
|
|
2267
2453
|
const collection = this.config.svg.append('g')
|
|
@@ -2269,18 +2455,14 @@ class PlaChartEffectsBuilder {
|
|
|
2269
2455
|
collection.append('path')
|
|
2270
2456
|
.attr('class', 'effect-line');
|
|
2271
2457
|
const mousePerLine = collection.selectAll('.effect-group')
|
|
2272
|
-
.data(this.
|
|
2273
|
-
return elm.data.length > 0;
|
|
2274
|
-
}))
|
|
2458
|
+
.data(this.series)
|
|
2275
2459
|
.enter().append('g')
|
|
2276
2460
|
.attr('class', 'effect-group')
|
|
2277
|
-
.attr('style', (
|
|
2461
|
+
.attr('style', ({ data }) => data.hide ? 'display: none' : null);
|
|
2278
2462
|
mousePerLine.append('circle')
|
|
2279
2463
|
.attr('r', 7)
|
|
2280
2464
|
.attr('class', 'effect-circle')
|
|
2281
|
-
.style('stroke', (
|
|
2282
|
-
return this.config.colors[i];
|
|
2283
|
-
});
|
|
2465
|
+
.style('stroke', ({ index }) => this.config.colors[index]);
|
|
2284
2466
|
mousePerLine.append('text')
|
|
2285
2467
|
.attr('class', 'effect-text')
|
|
2286
2468
|
.attr('y', 1.5)
|
|
@@ -2320,6 +2502,7 @@ class PlaChartEffectsBuilder {
|
|
|
2320
2502
|
.style('opacity', '1');
|
|
2321
2503
|
}
|
|
2322
2504
|
hideEffects() {
|
|
2505
|
+
this.lastMousePos = null;
|
|
2323
2506
|
this.config.svg.select('.effect-line')
|
|
2324
2507
|
.style('opacity', '0');
|
|
2325
2508
|
this.config.svg.selectAll('.effect-group circle')
|
|
@@ -2328,6 +2511,7 @@ class PlaChartEffectsBuilder {
|
|
|
2328
2511
|
.style('opacity', '0');
|
|
2329
2512
|
}
|
|
2330
2513
|
onMouseMove(mousePos) {
|
|
2514
|
+
this.lastMousePos = mousePos;
|
|
2331
2515
|
this.updateLine(mousePos);
|
|
2332
2516
|
this.updateEffects(mousePos);
|
|
2333
2517
|
}
|
|
@@ -2337,39 +2521,63 @@ class PlaChartEffectsBuilder {
|
|
|
2337
2521
|
}
|
|
2338
2522
|
updateEffects(mousePos) {
|
|
2339
2523
|
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
|
-
}
|
|
2524
|
+
.each((series, index, nodes) => {
|
|
2525
|
+
const group = select(nodes[index]);
|
|
2526
|
+
const value = this.valueAt(series.data.data, mousePos[0]);
|
|
2527
|
+
// No value under the cursor (a gap in the series): nothing to mark, so the group is
|
|
2528
|
+
// hidden rather than left at its last position.
|
|
2529
|
+
group.attr('visibility', value === null ? 'hidden' : null);
|
|
2530
|
+
if (value === null) {
|
|
2531
|
+
return;
|
|
2366
2532
|
}
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
.text(this.formatValue(value));
|
|
2370
|
-
return 'translate(' + mousePos[0] + ',' + pos.y + ')';
|
|
2533
|
+
group.attr('transform', 'translate(' + mousePos[0] + ',' + this.config.y(value) + ')');
|
|
2534
|
+
group.select('text').text(this.formatValue(value));
|
|
2371
2535
|
});
|
|
2372
2536
|
}
|
|
2537
|
+
/**
|
|
2538
|
+
* The series' value at plot x `mouseX`, interpolated along the segment of the line that spans it
|
|
2539
|
+
* - the same (linear) join the line/area draws between two consecutive points - or null if it
|
|
2540
|
+
* falls in a gap, where the line isn't drawn. Beyond the line's leftmost/rightmost point it holds
|
|
2541
|
+
* that point's value.
|
|
2542
|
+
*
|
|
2543
|
+
* Works on the segments in data order and never assumes x increases along them: DateTime or
|
|
2544
|
+
* Decimal data can come newest-first (or in any order), and the line still joins consecutive
|
|
2545
|
+
* points - reading "the first point" as the leftmost one showed the newest value everywhere.
|
|
2546
|
+
*
|
|
2547
|
+
* Worked out from the data rather than by walking the drawn path: an area's outline doubles
|
|
2548
|
+
* back along its baseline, so a search over the path's geometry could land on the bottom edge
|
|
2549
|
+
* and read the wrong value.
|
|
2550
|
+
*/
|
|
2551
|
+
valueAt(points, mouseX) {
|
|
2552
|
+
const xAt = (i) => getXFormat(this.config.xFormat, points[i], i, this.config.x);
|
|
2553
|
+
const valueOf = (i) => Number(points[i].value);
|
|
2554
|
+
const drawn = points.map((_, i) => i).filter((i) => hasValue(points[i]));
|
|
2555
|
+
if (!drawn.length) {
|
|
2556
|
+
return null;
|
|
2557
|
+
}
|
|
2558
|
+
// A segment joins two points next to each other in the data, both with a value - a point
|
|
2559
|
+
// without one between them breaks the line (`defined(hasValue)`).
|
|
2560
|
+
for (let i = 1; i < points.length; i++) {
|
|
2561
|
+
if (!hasValue(points[i - 1]) || !hasValue(points[i])) {
|
|
2562
|
+
continue;
|
|
2563
|
+
}
|
|
2564
|
+
const [xa, xb] = [xAt(i - 1), xAt(i)];
|
|
2565
|
+
if (mouseX < Math.min(xa, xb) || mouseX > Math.max(xa, xb)) {
|
|
2566
|
+
continue;
|
|
2567
|
+
}
|
|
2568
|
+
const [va, vb] = [valueOf(i - 1), valueOf(i)];
|
|
2569
|
+
return xb === xa ? vb : va + (vb - va) * (mouseX - xa) / (xb - xa);
|
|
2570
|
+
}
|
|
2571
|
+
const leftmost = drawn.reduce((min, i) => (xAt(i) < xAt(min) ? i : min));
|
|
2572
|
+
const rightmost = drawn.reduce((max, i) => (xAt(i) > xAt(max) ? i : max));
|
|
2573
|
+
if (mouseX <= xAt(leftmost)) {
|
|
2574
|
+
return valueOf(leftmost);
|
|
2575
|
+
}
|
|
2576
|
+
if (mouseX >= xAt(rightmost)) {
|
|
2577
|
+
return valueOf(rightmost);
|
|
2578
|
+
}
|
|
2579
|
+
return null;
|
|
2580
|
+
}
|
|
2373
2581
|
/**
|
|
2374
2582
|
* The crosshair's value, formatted the way the y axis labels its ticks - same format, same
|
|
2375
2583
|
* step-based precision - rather than rounded to a whole number, which read a 0-1 axis as 0 or 1.
|
|
@@ -2380,10 +2588,10 @@ class PlaChartEffectsBuilder {
|
|
|
2380
2588
|
?? y.tickFormat(this.config.yTicks);
|
|
2381
2589
|
return formatter(value);
|
|
2382
2590
|
}
|
|
2383
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
2384
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.
|
|
2591
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PlaChartEffectsBuilder, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
2592
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PlaChartEffectsBuilder });
|
|
2385
2593
|
}
|
|
2386
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
2594
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PlaChartEffectsBuilder, decorators: [{
|
|
2387
2595
|
type: Injectable
|
|
2388
2596
|
}] });
|
|
2389
2597
|
|
|
@@ -2445,6 +2653,10 @@ class PlaChartScales {
|
|
|
2445
2653
|
* `format`/`domainMin`/`domainMax` defaults are already applied - see `PcacLineAreaChartConfig`
|
|
2446
2654
|
* for what each format does with them.
|
|
2447
2655
|
*/
|
|
2656
|
+
/** The number of points in the longest series. */
|
|
2657
|
+
function longestSeriesLength(data) {
|
|
2658
|
+
return data.reduce((max, series) => Math.max(max, series.data.length), 0);
|
|
2659
|
+
}
|
|
2448
2660
|
class PlaChartScalesBuilder {
|
|
2449
2661
|
build(xAxis, yAxis, data, chartWidth, chartHeight) {
|
|
2450
2662
|
const resp = new PlaChartScales();
|
|
@@ -2463,9 +2675,11 @@ class PlaChartScalesBuilder {
|
|
|
2463
2675
|
.domain([xAxis.domainMin, xAxis.domainMax])
|
|
2464
2676
|
.range([0, chartWidth]);
|
|
2465
2677
|
default:
|
|
2466
|
-
// DatasetLength and every other format position points by index
|
|
2678
|
+
// DatasetLength and every other format position points by index - across the longest
|
|
2679
|
+
// series, not the first, which may be shorter or empty (an empty one gave [0, -1], an
|
|
2680
|
+
// inverted scale that pushed every point off the plot).
|
|
2467
2681
|
return scaleLinear()
|
|
2468
|
-
.domain([0,
|
|
2682
|
+
.domain([0, Math.max(0, longestSeriesLength(data) - 1)])
|
|
2469
2683
|
.range([0, chartWidth]);
|
|
2470
2684
|
}
|
|
2471
2685
|
}
|
|
@@ -2476,36 +2690,6 @@ class PlaChartScalesBuilder {
|
|
|
2476
2690
|
}
|
|
2477
2691
|
}
|
|
2478
2692
|
|
|
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
2693
|
function buildLineGenerator(format, scales) {
|
|
2510
2694
|
return line()
|
|
2511
2695
|
// A point with no numeric value leaves a gap rather than a NaN in the path, which browsers stop
|
|
@@ -2721,10 +2905,12 @@ function findCoincidentGroups(series, xFormat) {
|
|
|
2721
2905
|
return;
|
|
2722
2906
|
}
|
|
2723
2907
|
s.data.forEach((data, index) => {
|
|
2724
|
-
|
|
2908
|
+
// Same test as the line/dots use, so a point that isn't drawn (`''`, NaN) never joins a ring.
|
|
2909
|
+
if (!hasValue(data)) {
|
|
2725
2910
|
return;
|
|
2726
2911
|
}
|
|
2727
|
-
|
|
2912
|
+
// By numeric value, so `5` and `'5'` - drawn at the same spot - are recognized as sharing it.
|
|
2913
|
+
const key = `${xPositionKey(xFormat, data, index)}|${Number(data.value)}`;
|
|
2728
2914
|
let members = byPosition.get(key);
|
|
2729
2915
|
if (!members) {
|
|
2730
2916
|
members = [];
|
|
@@ -2812,12 +2998,6 @@ function clamp(value, min, max) {
|
|
|
2812
2998
|
return Math.min(Math.max(value, min), max);
|
|
2813
2999
|
}
|
|
2814
3000
|
|
|
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
3001
|
/** Half the theme's 2px line stroke: how far the lines/areas/fan-outs clip-path reaches past the plot. */
|
|
2822
3002
|
const PLOT_CLIP_ALLOWANCE = 1;
|
|
2823
3003
|
/**
|
|
@@ -2837,6 +3017,12 @@ const CHART_TYPE_LABELS = {
|
|
|
2837
3017
|
[PcacLineAreaPlotChartConfigType.Area]: 'Area chart',
|
|
2838
3018
|
[PcacLineAreaPlotChartConfigType.Plot]: 'Plot chart',
|
|
2839
3019
|
};
|
|
3020
|
+
/**
|
|
3021
|
+
* Provided per-component (see PcacLineAreaChartComponent's `providers`), not root-scoped: this
|
|
3022
|
+
* builder extends PcacChart, which holds mutable per-chart-instance state (margin, width,
|
|
3023
|
+
* height, colors, svg). A root singleton would be shared and clobbered by every
|
|
3024
|
+
* <pcac-line-area-chart> rendered at once.
|
|
3025
|
+
*/
|
|
2840
3026
|
class PlaChartBuilder extends PcacChart {
|
|
2841
3027
|
effectsBuilder = inject(PlaChartEffectsBuilder);
|
|
2842
3028
|
scales;
|
|
@@ -2845,7 +3031,16 @@ class PlaChartBuilder extends PcacChart {
|
|
|
2845
3031
|
zoomBehavior;
|
|
2846
3032
|
dotClickedSource = new Subject();
|
|
2847
3033
|
config;
|
|
2848
|
-
|
|
3034
|
+
/**
|
|
3035
|
+
* Numbers this chart's clip-path ids (and, through `plotClipPathId`, its range gradients'),
|
|
3036
|
+
* which have to be unique in the whole page: `url(#id)` resolves to the first match in the
|
|
3037
|
+
* document, so a duplicate would clip one chart with another's rect. A per-instance counter
|
|
3038
|
+
* rather than the timestamp-plus-random stamp this used to be, which two charts rebuilding in
|
|
3039
|
+
* the same millisecond (every chart on a page reacts to a window resize at once) could share.
|
|
3040
|
+
*/
|
|
3041
|
+
static nextInstanceId = 0;
|
|
3042
|
+
instanceId = ++PlaChartBuilder.nextInstanceId;
|
|
3043
|
+
clipPathId;
|
|
2849
3044
|
/**
|
|
2850
3045
|
* A second clip-path for everything that isn't a point - lines, areas, fan-out anchors and
|
|
2851
3046
|
* spokes: the plot area plus `PLOT_CLIP_ALLOWANCE`. These have no business past the axes; the
|
|
@@ -2881,6 +3076,12 @@ class PlaChartBuilder extends PcacChart {
|
|
|
2881
3076
|
pointRange = null;
|
|
2882
3077
|
/** Each drawn range's `.point-range` group, by its point, so hover can find the one to focus. */
|
|
2883
3078
|
rangeGroupOf = new Map();
|
|
3079
|
+
/**
|
|
3080
|
+
* Whether this build has the hover crosshair: `enableEffects`, on a line or area chart. A plot
|
|
3081
|
+
* chart has no line for it to follow, so it gets none - its circles had nowhere to go and sat
|
|
3082
|
+
* stacked in the plot's top-left corner.
|
|
3083
|
+
*/
|
|
3084
|
+
effectsEnabled = false;
|
|
2884
3085
|
dotClicked$ = this.dotClickedSource.asObservable();
|
|
2885
3086
|
buildChart(chartElm, config, type) {
|
|
2886
3087
|
if (!config?.data?.length) {
|
|
@@ -2892,7 +3093,7 @@ class PlaChartBuilder extends PcacChart {
|
|
|
2892
3093
|
// no mouseout, so its tooltip is closed here (see `leavePoint`).
|
|
2893
3094
|
this.leavePoint();
|
|
2894
3095
|
this.config = JSON.parse(JSON.stringify(config));
|
|
2895
|
-
this.startData = range(this.config.data
|
|
3096
|
+
this.startData = range(longestSeriesLength(this.config.data)).map(() => ({
|
|
2896
3097
|
key: '',
|
|
2897
3098
|
value: 0,
|
|
2898
3099
|
hide: false,
|
|
@@ -2942,10 +3143,12 @@ class PlaChartBuilder extends PcacChart {
|
|
|
2942
3143
|
// used to do, and which also overwrote the original generators' x accessor for good) is
|
|
2943
3144
|
// only right for the default DatasetLength format; a DateTime/Decimal chart's lines
|
|
2944
3145
|
// drifted away from its dots as soon as it was zoomed.
|
|
3146
|
+
// Interrupted first: a zoom during the enter transition would otherwise have the rest of
|
|
3147
|
+
// that transition keep drawing the unzoomed shape over this one.
|
|
2945
3148
|
const zoomedLine = buildLineGenerator(this.xAxis.format, zoomedScales);
|
|
2946
3149
|
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));
|
|
3150
|
+
this.svg.selectAll('.line').interrupt().attr('d', (d) => zoomedLine(d));
|
|
3151
|
+
this.svg.selectAll('.area').interrupt().attr('d', (d) => zoomedArea(d));
|
|
2949
3152
|
// Update dots / point images. Nested selectAll (not a flat svg.selectAll('.point')) so
|
|
2950
3153
|
// that `i` is the point's index *within its own series* - the x format default
|
|
2951
3154
|
// (DatasetLength) positions by index, and a flat selection would number every series'
|
|
@@ -2961,9 +3164,8 @@ class PlaChartBuilder extends PcacChart {
|
|
|
2961
3164
|
.selectAll('.fan-out-spoke')
|
|
2962
3165
|
.attr('x2', (member) => this.spokeEnd(member, zoomedScales).dx)
|
|
2963
3166
|
.attr('y2', (member) => this.spokeEnd(member, zoomedScales).dy);
|
|
2964
|
-
// The hover crosshair
|
|
2965
|
-
|
|
2966
|
-
if (this.config.enableEffects) {
|
|
3167
|
+
// The hover crosshair positions and labels against the scales, so it takes the zoomed ones.
|
|
3168
|
+
if (this.effectsEnabled) {
|
|
2967
3169
|
this.effectsBuilder.updateScales(newX, newY);
|
|
2968
3170
|
}
|
|
2969
3171
|
// Ranges are drawn in plot coordinates rather than hung off a translate, so every one is
|
|
@@ -2985,7 +3187,8 @@ class PlaChartBuilder extends PcacChart {
|
|
|
2985
3187
|
this.axisBuilder.drawAxis(this.axisBuilderConfig(this.scales.x, this.scales.y));
|
|
2986
3188
|
this.drawGrids(this.scales.x, this.scales.y);
|
|
2987
3189
|
this.drawLineArea(config, type);
|
|
2988
|
-
|
|
3190
|
+
this.effectsEnabled = !!config.enableEffects && type !== PcacLineAreaPlotChartConfigType.Plot;
|
|
3191
|
+
if (this.effectsEnabled) {
|
|
2989
3192
|
this.effectsBuilder.buildEffects({
|
|
2990
3193
|
svg: this.svg,
|
|
2991
3194
|
height: this.height,
|
|
@@ -2994,6 +3197,7 @@ class PlaChartBuilder extends PcacChart {
|
|
|
2994
3197
|
colors: this.colors,
|
|
2995
3198
|
x: this.scales.x,
|
|
2996
3199
|
y: this.scales.y,
|
|
3200
|
+
xFormat: this.xAxis.format,
|
|
2997
3201
|
yFormat: this.yAxis.format,
|
|
2998
3202
|
yTicks: this.yAxis.ticks,
|
|
2999
3203
|
});
|
|
@@ -3055,10 +3259,10 @@ class PlaChartBuilder extends PcacChart {
|
|
|
3055
3259
|
this.reserveEdgeSpace({ top: halfHeight, bottom: halfHeight, left: halfWidth, right: halfWidth });
|
|
3056
3260
|
}
|
|
3057
3261
|
createReusableClipPath() {
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
this.
|
|
3061
|
-
this.
|
|
3262
|
+
// The previous build's <defs> went with the rest of its drawing (see initializeChartState),
|
|
3263
|
+
// so the same ids are free again.
|
|
3264
|
+
this.clipPathId = `pcac-clip-${this.instanceId}`;
|
|
3265
|
+
this.plotClipPathId = `pcac-clip-plot-${this.instanceId}`;
|
|
3062
3266
|
const defs = this.svg.append('defs');
|
|
3063
3267
|
defs.append('clipPath')
|
|
3064
3268
|
.attr('id', this.clipPathId)
|
|
@@ -3125,15 +3329,15 @@ class PlaChartBuilder extends PcacChart {
|
|
|
3125
3329
|
.append('path')
|
|
3126
3330
|
.datum(lineData)
|
|
3127
3331
|
.attr('class', 'line')
|
|
3332
|
+
// Set up front rather than on the transition, so a zoom interrupting it (see the zoom
|
|
3333
|
+
// handler) doesn't leave the line uncolored, or a hidden one showing.
|
|
3334
|
+
.attr('stroke', this.colors[index])
|
|
3335
|
+
.attr('fill', 'none')
|
|
3336
|
+
.attr('style', hide ? 'display: none' : null)
|
|
3128
3337
|
.attr('d', this.lineGenerator(this.startData))
|
|
3129
3338
|
.transition()
|
|
3130
3339
|
.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);
|
|
3340
|
+
.attr('d', this.lineGenerator);
|
|
3137
3341
|
}
|
|
3138
3342
|
drawArea(lineData, index, hide = false) {
|
|
3139
3343
|
this.svg.append('g')
|
|
@@ -3182,7 +3386,9 @@ class PlaChartBuilder extends PcacChart {
|
|
|
3182
3386
|
.style('--pcac-point-range-series-color', () => this.colors[seriesIndex])
|
|
3183
3387
|
.style('display', () => series.hide ? 'none' : null);
|
|
3184
3388
|
series.data.forEach((point) => {
|
|
3185
|
-
|
|
3389
|
+
// A point with no value draws no dot (see `pointDisplay`), so it draws no range either -
|
|
3390
|
+
// one would stand around a coordinate with nothing on it (on the baseline, for `''`).
|
|
3391
|
+
if (point.range && hasValue(point)) {
|
|
3186
3392
|
this.rangeGroupOf.set(point, seriesGroup.append('g').attr('class', 'point-range').node());
|
|
3187
3393
|
}
|
|
3188
3394
|
});
|
|
@@ -3302,7 +3508,7 @@ class PlaChartBuilder extends PcacChart {
|
|
|
3302
3508
|
const series = config.data[index];
|
|
3303
3509
|
const points = this.svg.append('g')
|
|
3304
3510
|
.attr('class', 'dots')
|
|
3305
|
-
.attr('clip-path', `url(#${this.clipPathId})`)
|
|
3511
|
+
.attr('clip-path', `url(#${this.clipPathId})`)
|
|
3306
3512
|
.attr('style', series.hide ? 'display: none' : null)
|
|
3307
3513
|
.selectAll('.point')
|
|
3308
3514
|
.data(series.data)
|
|
@@ -3408,9 +3614,13 @@ class PlaChartBuilder extends PcacChart {
|
|
|
3408
3614
|
* the clip-path's buffer do the work, showed a point up to a whole half-mark beyond the axis
|
|
3409
3615
|
* with its center already outside. Also takes it out of hover's reach, as a hidden group
|
|
3410
3616
|
* receives no pointer events.
|
|
3617
|
+
*
|
|
3618
|
+
* A point with no value to plot isn't drawn at all - the same test the line/area uses to leave
|
|
3619
|
+
* a gap (`hasValue`). An empty string used to slip through: the scale reads `''` as 0, so the
|
|
3620
|
+
* line left a gap while a dot sat (hoverable) on the baseline.
|
|
3411
3621
|
*/
|
|
3412
3622
|
pointDisplay(d, i, scales) {
|
|
3413
|
-
return this.pointVisible(d, i, scales) ? null : 'none';
|
|
3623
|
+
return hasValue(d) && this.pointVisible(d, i, scales) ? null : 'none';
|
|
3414
3624
|
}
|
|
3415
3625
|
pointVisible(d, i, scales) {
|
|
3416
3626
|
const { x, y } = this.markCenter(d, i, scales);
|
|
@@ -3470,10 +3680,10 @@ class PlaChartBuilder extends PcacChart {
|
|
|
3470
3680
|
.filter((member) => member.data !== d)
|
|
3471
3681
|
.map((member) => ({ data: member.data, parent: member.series, index: member.index, parentIndex: member.seriesIndex }));
|
|
3472
3682
|
}
|
|
3473
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
3474
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.
|
|
3683
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PlaChartBuilder, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
|
3684
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PlaChartBuilder });
|
|
3475
3685
|
}
|
|
3476
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
3686
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PlaChartBuilder, decorators: [{
|
|
3477
3687
|
type: Injectable
|
|
3478
3688
|
}] });
|
|
3479
3689
|
|
|
@@ -3522,10 +3732,10 @@ class PcacLineAreaChartComponent {
|
|
|
3522
3732
|
this.chartBuilder.buildChart(this.chartElm(), config, this.type());
|
|
3523
3733
|
}
|
|
3524
3734
|
}
|
|
3525
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
3526
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.
|
|
3735
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacLineAreaChartComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
3736
|
+
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
3737
|
}
|
|
3528
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
3738
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacLineAreaChartComponent, decorators: [{
|
|
3529
3739
|
type: Component,
|
|
3530
3740
|
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
3741
|
}], 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 +3751,10 @@ class PcacPlotChart {
|
|
|
3541
3751
|
*/
|
|
3542
3752
|
tooltipTemplate = contentChild(PcacTooltipDirective, /* @ts-ignore */
|
|
3543
3753
|
...(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.
|
|
3754
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacPlotChart, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
3755
|
+
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
3756
|
}
|
|
3547
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
3757
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacPlotChart, decorators: [{
|
|
3548
3758
|
type: Component,
|
|
3549
3759
|
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
3760
|
}], 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 +3770,10 @@ class PcacLineChart {
|
|
|
3560
3770
|
*/
|
|
3561
3771
|
tooltipTemplate = contentChild(PcacTooltipDirective, /* @ts-ignore */
|
|
3562
3772
|
...(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.
|
|
3773
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacLineChart, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
3774
|
+
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
3775
|
}
|
|
3566
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
3776
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacLineChart, decorators: [{
|
|
3567
3777
|
type: Component,
|
|
3568
3778
|
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
3779
|
}], 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 +3792,10 @@ class PcacAreaChart {
|
|
|
3582
3792
|
*/
|
|
3583
3793
|
tooltipTemplate = contentChild(PcacTooltipDirective, /* @ts-ignore */
|
|
3584
3794
|
...(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.
|
|
3795
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacAreaChart, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
3796
|
+
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
3797
|
}
|
|
3588
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
3798
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacAreaChart, decorators: [{
|
|
3589
3799
|
type: Component,
|
|
3590
3800
|
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
3801
|
}], 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 }] }] } });
|
|
@@ -3681,7 +3891,7 @@ class PieChartBuilder extends PcacChart {
|
|
|
3681
3891
|
return;
|
|
3682
3892
|
}
|
|
3683
3893
|
this.applyColorOverride(config.colorOverride);
|
|
3684
|
-
this.radius = Math.min(
|
|
3894
|
+
this.radius = Math.min(this.height, this.width) / 2;
|
|
3685
3895
|
this.buildShapes(config.donut);
|
|
3686
3896
|
this.drawChart(chartElm, config);
|
|
3687
3897
|
if (config.donut && this.innerRadius > 0) {
|
|
@@ -3690,16 +3900,18 @@ class PieChartBuilder extends PcacChart {
|
|
|
3690
3900
|
}
|
|
3691
3901
|
buildShapes(donut) {
|
|
3692
3902
|
const radiusOffset = 10;
|
|
3693
|
-
|
|
3903
|
+
// Never negative: in a container under 20px the offset would otherwise turn the pie inside out.
|
|
3904
|
+
const outerRadius = Math.max(0, this.radius - radiusOffset);
|
|
3694
3905
|
const ratio = donut ? (donut.innerRadius ?? new PcacPieDonutConfig().innerRadius) : 0;
|
|
3695
3906
|
// Sized against the resting slice, so the hole stays put when a hovered slice grows outward.
|
|
3696
3907
|
this.innerRadius = Math.max(0, outerRadius * Math.min(Math.max(ratio, 0), MAX_DONUT_INNER_RADIUS));
|
|
3697
3908
|
this.arcShape = arc()
|
|
3698
3909
|
.innerRadius(this.innerRadius)
|
|
3699
3910
|
.outerRadius(outerRadius);
|
|
3911
|
+
// A pie too small to draw anything at rest (see above) doesn't pop out a disc on hover either.
|
|
3700
3912
|
this.arcOverShape = arc()
|
|
3701
3913
|
.innerRadius(this.innerRadius)
|
|
3702
|
-
.outerRadius(outerRadius + radiusOffset);
|
|
3914
|
+
.outerRadius(outerRadius > 0 ? outerRadius + radiusOffset : 0);
|
|
3703
3915
|
this.pieAngles = pie()
|
|
3704
3916
|
.sort(null)
|
|
3705
3917
|
// A hidden slice takes no angle but keeps its index - and so its color, matching a legend -
|
|
@@ -3721,7 +3933,16 @@ class PieChartBuilder extends PcacChart {
|
|
|
3721
3933
|
const t = transition().duration(self.transitionService.getTransitionDuration() / 3);
|
|
3722
3934
|
const c = color(self.colors[d.index]);
|
|
3723
3935
|
const ct = c ? c.darker(1).toString() : self.colors[d.index];
|
|
3724
|
-
select(this)
|
|
3936
|
+
const slice = select(this);
|
|
3937
|
+
// Hovered mid-way through the enter sweep, the slice is finished first: growing it straight
|
|
3938
|
+
// from its part-swept path morphed it oddly on the way out to the hover shape. Only then -
|
|
3939
|
+
// re-entering a slice mid-way through its hover shrink must grow it from where it is, not
|
|
3940
|
+
// snap it back to rest first (which flickered).
|
|
3941
|
+
if (active(this, 'enter')) {
|
|
3942
|
+
slice.interrupt('enter').attr('d', self.arcShape(d));
|
|
3943
|
+
}
|
|
3944
|
+
slice
|
|
3945
|
+
.transition(t)
|
|
3725
3946
|
.attr('d', self.arcOverShape)
|
|
3726
3947
|
.style('fill', ct);
|
|
3727
3948
|
})
|
|
@@ -3739,7 +3960,8 @@ class PieChartBuilder extends PcacChart {
|
|
|
3739
3960
|
.on('click', (_event, d) => {
|
|
3740
3961
|
this.sliceClickedSource.next(d.data);
|
|
3741
3962
|
})
|
|
3742
|
-
|
|
3963
|
+
// Named, so the hover transitions (unnamed) and the check above can tell it apart from them.
|
|
3964
|
+
.transition('enter')
|
|
3743
3965
|
.duration(this.transitionService.getTransitionDuration())
|
|
3744
3966
|
.attrTween('d', (b) => {
|
|
3745
3967
|
return this.tweenChart(b);
|
|
@@ -3804,10 +4026,10 @@ class PieChartBuilder extends PcacChart {
|
|
|
3804
4026
|
const i = interpolate({ startAngle: 0, endAngle: 0 }, b);
|
|
3805
4027
|
return (t) => this.arcShape(i(t)) ?? '';
|
|
3806
4028
|
}
|
|
3807
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
3808
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.
|
|
4029
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PieChartBuilder, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
|
4030
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PieChartBuilder });
|
|
3809
4031
|
}
|
|
3810
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
4032
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PieChartBuilder, decorators: [{
|
|
3811
4033
|
type: Injectable
|
|
3812
4034
|
}] });
|
|
3813
4035
|
|
|
@@ -3848,12 +4070,12 @@ class PcacPieChartComponent {
|
|
|
3848
4070
|
this.chartBuilder.buildChart(this.chartElm(), config);
|
|
3849
4071
|
}
|
|
3850
4072
|
}
|
|
3851
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
3852
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.
|
|
4073
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacPieChartComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
4074
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.2.0", type: PcacPieChartComponent, isStandalone: true, selector: "pcac-pie-chart", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { sliceClicked: "sliceClicked" }, providers: [PieChartBuilder], 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-pie-chart\">\n <svg #chart></svg>\n</section>\n\n", styles: [".pcac-pie-chart svg{width:100%;display:block}\n"], encapsulation: i0.ViewEncapsulation.None });
|
|
3853
4075
|
}
|
|
3854
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
4076
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacPieChartComponent, decorators: [{
|
|
3855
4077
|
type: Component,
|
|
3856
|
-
args: [{ selector: 'pcac-pie-chart', encapsulation: ViewEncapsulation.None, providers: [PieChartBuilder], template: "<section class=\"pcac-pie-chart\">\n <svg #chart></svg>\n</section>\n\n", styles: [".pcac-pie-chart svg{width:100%;display:block}
|
|
4078
|
+
args: [{ selector: 'pcac-pie-chart', encapsulation: ViewEncapsulation.None, providers: [PieChartBuilder], template: "<section class=\"pcac-pie-chart\">\n <svg #chart></svg>\n</section>\n\n", styles: [".pcac-pie-chart svg{width:100%;display:block}\n"] }]
|
|
3857
4079
|
}], ctorParameters: () => [], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }], chartElm: [{ type: i0.ViewChild, args: ['chart', { isSignal: true }] }], sliceClicked: [{ type: i0.Output, args: ["sliceClicked"] }], tooltipTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => PcacTooltipDirective), { isSignal: true }] }] } });
|
|
3858
4080
|
|
|
3859
4081
|
/*
|