@pioneer-code/pioneer-charts 22.0.0 → 22.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -9
- package/fesm2022/pioneer-code-pioneer-charts.mjs +326 -214
- package/fesm2022/pioneer-code-pioneer-charts.mjs.map +1 -1
- package/package.json +5 -3
- package/scss/core/theme/imports.scss +17 -11
- package/scss/pioneer-charts.scss +5 -0
- package/types/pioneer-code-pioneer-charts.d.ts +119 -61
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { Injectable, inject,
|
|
2
|
+
import { Injectable, inject, DestroyRef, afterNextRender, input, viewChild, effect, ViewEncapsulation, Component, model, output, computed } from '@angular/core';
|
|
3
3
|
import { color } from 'd3-color';
|
|
4
4
|
import { scaleLinear, scaleBand } from 'd3-scale';
|
|
5
5
|
import { select as select$1 } from 'd3-selection';
|
|
@@ -7,6 +7,8 @@ import { Subject } from 'rxjs';
|
|
|
7
7
|
import { axisLeft, axisBottom } from 'd3-axis';
|
|
8
8
|
import { format } from 'd3-format';
|
|
9
9
|
import { select, scaleTime, zoom } from 'd3';
|
|
10
|
+
import { takeUntilDestroyed, outputFromObservable } from '@angular/core/rxjs-interop';
|
|
11
|
+
import { debounceTime } from 'rxjs/operators';
|
|
10
12
|
import { range } from 'd3-array';
|
|
11
13
|
import { line, area, arc, pie } from 'd3-shape';
|
|
12
14
|
import { interpolate } from 'd3-interpolate';
|
|
@@ -73,7 +75,7 @@ class PcacAxisBuilder {
|
|
|
73
75
|
.call(yAxis);
|
|
74
76
|
}
|
|
75
77
|
drawXAxis(config) {
|
|
76
|
-
if (config.
|
|
78
|
+
if (config.hideXAxis)
|
|
77
79
|
return;
|
|
78
80
|
config.svg.selectAll('.pcac-x-axis').remove();
|
|
79
81
|
const xAxis = axisBottom(config.xScale).ticks(config.numberOfTicks);
|
|
@@ -97,7 +99,7 @@ class PcacAxisBuilder {
|
|
|
97
99
|
});
|
|
98
100
|
break;
|
|
99
101
|
case PcacFormatEnum.Decimal:
|
|
100
|
-
xAxis.tickFormat((d
|
|
102
|
+
xAxis.tickFormat((d) => format(".2s")(d));
|
|
101
103
|
break;
|
|
102
104
|
}
|
|
103
105
|
}
|
|
@@ -118,28 +120,30 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.2", ngImpor
|
|
|
118
120
|
|
|
119
121
|
class PcacGridBuilder {
|
|
120
122
|
drawVerticalGrid(config) {
|
|
123
|
+
const xScale = config.xScale;
|
|
121
124
|
config.svg.append('g')
|
|
122
125
|
.attr('class', 'pcac-grid')
|
|
123
126
|
.selectAll('g.rule')
|
|
124
|
-
.data(
|
|
127
|
+
.data(xScale.ticks(5))
|
|
125
128
|
.enter().append('svg:g')
|
|
126
129
|
.attr('class', 'pcac-grid-rule')
|
|
127
|
-
.attr('transform', (d) => (`translate(${
|
|
130
|
+
.attr('transform', (d) => (`translate(${xScale(d)}, 0)`))
|
|
128
131
|
.append('svg:line')
|
|
129
132
|
.attr('y1', 0)
|
|
130
133
|
.attr('y2', config.height)
|
|
131
134
|
.attr('class', (d, i) => (i === 0 ? 'pcac-grid-rule-last' : ''));
|
|
132
135
|
}
|
|
133
136
|
drawHorizontalGrid(config) {
|
|
137
|
+
const yScale = config.yScale;
|
|
134
138
|
config.svg.append('g')
|
|
135
139
|
.attr('class', 'pcac-grid')
|
|
136
140
|
.selectAll('g.pcac-grid-rule')
|
|
137
|
-
.data(
|
|
141
|
+
.data(yScale.ticks(config.numberOfTicks))
|
|
138
142
|
.enter().append('svg:g')
|
|
139
143
|
.attr('class', 'pcac-grid-rule')
|
|
140
144
|
.append('svg:line')
|
|
141
|
-
.attr('y1', (d) =>
|
|
142
|
-
.attr('y2', (d) =>
|
|
145
|
+
.attr('y1', (d) => yScale(d) ?? null)
|
|
146
|
+
.attr('y2', (d) => yScale(d) ?? null)
|
|
143
147
|
.attr('x1', 0)
|
|
144
148
|
.attr('x2', config.width)
|
|
145
149
|
.attr('class', (_, i) => (i === 0 ? 'pcac-grid-rule-last' : ''));
|
|
@@ -211,8 +215,8 @@ class PcacColorService {
|
|
|
211
215
|
setBlue(color) {
|
|
212
216
|
this.blue = color;
|
|
213
217
|
}
|
|
214
|
-
setAlert() {
|
|
215
|
-
|
|
218
|
+
setAlert(color) {
|
|
219
|
+
this.alert = color;
|
|
216
220
|
}
|
|
217
221
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacColorService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
218
222
|
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacColorService, providedIn: 'root' });
|
|
@@ -242,7 +246,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.2", ngImpor
|
|
|
242
246
|
class PcacTooltipBuilder {
|
|
243
247
|
tooltip = select('body')
|
|
244
248
|
.append('div')
|
|
245
|
-
.attr('class', 'pcac-d3-tooltip');
|
|
249
|
+
.attr('class', 'pcac-d3-tooltip');
|
|
246
250
|
showBarTooltip(event, data, valueFormat, keyFormat) {
|
|
247
251
|
this.tooltip.style('left', event.pageX - 60 + 'px')
|
|
248
252
|
.style('top', event.pageY - 55 + 'px')
|
|
@@ -299,22 +303,62 @@ class PcacChart {
|
|
|
299
303
|
tooltipBuilder = inject(PcacTooltipBuilder);
|
|
300
304
|
colorService = inject(PcacColorService);
|
|
301
305
|
margin = { top: 8, right: 16, bottom: 20, left: 40 };
|
|
302
|
-
svg;
|
|
306
|
+
svg;
|
|
303
307
|
width = 400;
|
|
304
308
|
height = 400;
|
|
305
309
|
colors = [];
|
|
306
|
-
startData = [];
|
|
307
|
-
|
|
310
|
+
startData = [];
|
|
311
|
+
/**
|
|
312
|
+
* Raw, unadjusted container width measured by the last successful `initializeChartState()`
|
|
313
|
+
* call, or `null` if none has succeeded yet. Deliberately tracked separately from `width`:
|
|
314
|
+
* some builders (e.g. bar-horizontal-chart's `setHorizontalMarginsBasedOnContent`) recompute
|
|
315
|
+
* `width`/`margin.left` mid-build from measured axis-label sizes, so `width` alone isn't a
|
|
316
|
+
* stable basis for "did the container itself resize" — the raw container measurement is.
|
|
317
|
+
*/
|
|
318
|
+
lastContainerWidth = null;
|
|
308
319
|
/**
|
|
309
|
-
* Prior to building a chart, we need to initialize the state of the chart
|
|
320
|
+
* Prior to building a chart, we need to initialize the state of the chart.
|
|
321
|
+
*
|
|
322
|
+
* Returns `false` (and leaves `width`/`height`/`colors` untouched) if the container hasn't
|
|
323
|
+
* been laid out yet, so its `clientWidth` measures 0 — this happens when a chart mounts
|
|
324
|
+
* already holding data (e.g. behind a loading gate) and its first `ngOnChanges` fires before
|
|
325
|
+
* the browser has committed layout for its own just-created DOM node. Callers should bail out
|
|
326
|
+
* of their build on `false` rather than proceeding with a degenerate width; `PcacChartResizeService`
|
|
327
|
+
* (wired up by every chart component) retries the build once the container has a real size.
|
|
310
328
|
* @param chartElm Reference to SVG on dom
|
|
311
329
|
* @param config Chart specific configuration
|
|
312
330
|
*/
|
|
313
331
|
initializeChartState(chartElm, config) {
|
|
314
332
|
select$1(chartElm.nativeElement).select('g').remove();
|
|
315
|
-
|
|
333
|
+
const containerWidth = chartElm.nativeElement.parentNode.clientWidth;
|
|
334
|
+
const measuredWidth = containerWidth - this.margin.left - this.margin.right;
|
|
335
|
+
if (measuredWidth <= 0) {
|
|
336
|
+
return false;
|
|
337
|
+
}
|
|
338
|
+
this.width = measuredWidth;
|
|
316
339
|
this.height = config.height;
|
|
317
|
-
this.colors = this.colorService.getColorScale(Math.max(config.data.length, config.data[0]
|
|
340
|
+
this.colors = this.colorService.getColorScale(Math.max(config.data.length, config.data[0]?.data ? config.data[0].data.length : 0));
|
|
341
|
+
this.lastContainerWidth = containerWidth;
|
|
342
|
+
return true;
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* True if the container's current raw layout width differs from the one measured by the last
|
|
346
|
+
* successful build, or if no successful build has happened yet.
|
|
347
|
+
*
|
|
348
|
+
* `PcacChartResizeService`'s `ResizeObserver` is guaranteed to fire once as soon as it starts
|
|
349
|
+
* observing — that's what lets a chart recover from the 0-width race described on
|
|
350
|
+
* `initializeChartState`, but it also means that "routine" first callback usually lands
|
|
351
|
+
* moments after `ngOnChanges` already built successfully at the same width. Without this
|
|
352
|
+
* check, that redundant callback would restart the chart's enter transition mid-animation for
|
|
353
|
+
* no visual change. Only `ngOnChanges` (which reacts to data, not size) should skip this check.
|
|
354
|
+
* @param chartElm Reference to SVG on dom
|
|
355
|
+
*/
|
|
356
|
+
containerSizeChanged(chartElm) {
|
|
357
|
+
if (this.lastContainerWidth === null) {
|
|
358
|
+
return true;
|
|
359
|
+
}
|
|
360
|
+
const containerWidth = chartElm.nativeElement.parentNode.clientWidth;
|
|
361
|
+
return containerWidth > 0 && containerWidth !== this.lastContainerWidth;
|
|
318
362
|
}
|
|
319
363
|
/**
|
|
320
364
|
* 1) Set the width and height of the SVG
|
|
@@ -353,8 +397,9 @@ class PcacChart {
|
|
|
353
397
|
select$1(chartElm.nativeElement).append('g')
|
|
354
398
|
.call(axisY)
|
|
355
399
|
.each((d, i, n) => {
|
|
356
|
-
|
|
357
|
-
|
|
400
|
+
const width = n[i].getBBox().width;
|
|
401
|
+
if (width > max) {
|
|
402
|
+
max = width;
|
|
358
403
|
}
|
|
359
404
|
})
|
|
360
405
|
.remove();
|
|
@@ -364,6 +409,12 @@ class PcacChart {
|
|
|
364
409
|
}
|
|
365
410
|
}
|
|
366
411
|
|
|
412
|
+
/**
|
|
413
|
+
* Provided per-component (see PcacBarHorizontalChartComponent's `providers`), not root-scoped:
|
|
414
|
+
* this builder extends PcacChart, which holds mutable per-chart-instance state (margin, width,
|
|
415
|
+
* height, colors, svg). A root singleton would be shared and clobbered by every
|
|
416
|
+
* <pcac-bar-horizontal-chart> rendered at once.
|
|
417
|
+
*/
|
|
367
418
|
class BarHorizontalChartBuilder extends PcacChart {
|
|
368
419
|
xScale;
|
|
369
420
|
yScaleStacked;
|
|
@@ -373,13 +424,15 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
373
424
|
cachedMargins;
|
|
374
425
|
barClicked$ = this.barClickedSource.asObservable();
|
|
375
426
|
buildChart(chartElm, config) {
|
|
427
|
+
if (!config?.data?.length) {
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
376
430
|
this.config = JSON.parse(JSON.stringify(config));
|
|
377
431
|
if (this.config.hideAxis) {
|
|
378
432
|
this.adjustForHiddenAxis();
|
|
379
433
|
}
|
|
380
|
-
this.initializeChartState(chartElm, this.config)
|
|
381
|
-
|
|
382
|
-
return; // TODO: Figure out why this is happening on initial load sometimes
|
|
434
|
+
if (!this.initializeChartState(chartElm, this.config)) {
|
|
435
|
+
return;
|
|
383
436
|
}
|
|
384
437
|
if (config.colorOverride && config.colorOverride.colors) {
|
|
385
438
|
this.colors = config.colorOverride.colors.reverse();
|
|
@@ -398,14 +451,6 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
398
451
|
this.margin.left = 0;
|
|
399
452
|
this.margin.right = 0;
|
|
400
453
|
}
|
|
401
|
-
setStartState(data) {
|
|
402
|
-
if (data && data.data) {
|
|
403
|
-
for (let i = 0, l = data.data.length; i < l; ++i) {
|
|
404
|
-
data.data[i].value = 0;
|
|
405
|
-
this.setStartState(data.data[i]);
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
454
|
buildScales(chartElm, config) {
|
|
410
455
|
config.data[0].data.map((d) => {
|
|
411
456
|
return d.value;
|
|
@@ -439,6 +484,7 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
439
484
|
this.gridBuilder.drawVerticalGrid({
|
|
440
485
|
svg: this.svg,
|
|
441
486
|
numberOfTicks: config.numberOfTicks || 5,
|
|
487
|
+
width: this.width,
|
|
442
488
|
height: this.height,
|
|
443
489
|
xScale: this.xScale,
|
|
444
490
|
yScale: this.yScaleStacked
|
|
@@ -501,9 +547,9 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
501
547
|
})
|
|
502
548
|
.attr('width', 0)
|
|
503
549
|
.on('mouseover', function (event, d) {
|
|
504
|
-
select$1(this
|
|
550
|
+
select$1(this)
|
|
505
551
|
.transition()
|
|
506
|
-
.duration(
|
|
552
|
+
.duration(self.transitionService.getTransitionDuration() / 7.5)
|
|
507
553
|
.style('fill', () => {
|
|
508
554
|
if (config.spreadColorsPerGroup) {
|
|
509
555
|
const groupIndex = parseInt(this.parentNode.getAttribute('data-group-id'), 10);
|
|
@@ -524,7 +570,7 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
524
570
|
self.tooltipBuilder.hideTooltip();
|
|
525
571
|
select$1(this)
|
|
526
572
|
.transition()
|
|
527
|
-
.duration(
|
|
573
|
+
.duration(self.transitionService.getTransitionDuration() / 5)
|
|
528
574
|
.style('fill', () => {
|
|
529
575
|
if (config.spreadColorsPerGroup) {
|
|
530
576
|
const groupIndex = parseInt(this.parentNode.getAttribute('data-group-id'), 10);
|
|
@@ -534,7 +580,7 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
534
580
|
return self.colors[groupIndex];
|
|
535
581
|
});
|
|
536
582
|
})
|
|
537
|
-
.on('click', (d) => {
|
|
583
|
+
.on('click', (_event, d) => {
|
|
538
584
|
this.barClickedSource.next(d);
|
|
539
585
|
})
|
|
540
586
|
.transition()
|
|
@@ -554,7 +600,7 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
554
600
|
})
|
|
555
601
|
.transition()
|
|
556
602
|
.duration(this.transitionService.getTransitionDuration())
|
|
557
|
-
.attr('x', (
|
|
603
|
+
.attr('x', (_, i) => {
|
|
558
604
|
return this.xScale(config.thresholds[i].value);
|
|
559
605
|
});
|
|
560
606
|
}
|
|
@@ -565,7 +611,7 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
565
611
|
.attr('data-group-threshold-id', (_, i) => {
|
|
566
612
|
return i;
|
|
567
613
|
})
|
|
568
|
-
.on('mousemove', function (event
|
|
614
|
+
.on('mousemove', function (event) {
|
|
569
615
|
const index = Number(this.parentElement.dataset['groupId']);
|
|
570
616
|
self.tooltipBuilder.showBarTooltip(event, config.isStacked ?
|
|
571
617
|
config.thresholds[index].data[0] :
|
|
@@ -584,7 +630,7 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
584
630
|
return i;
|
|
585
631
|
})
|
|
586
632
|
.attr('height', this.yScaleGrouped.bandwidth())
|
|
587
|
-
.on('mousemove', function (event
|
|
633
|
+
.on('mousemove', function (event) {
|
|
588
634
|
const target = event.target;
|
|
589
635
|
const index = Number(target.getAttribute("data-group-threshold-id"));
|
|
590
636
|
self.tooltipBuilder.showBarTooltip(event, config.thresholds[Number(this.parentElement.dataset['groupId'])].data[index], config.tickFormat || PcacFormatEnum.None);
|
|
@@ -592,7 +638,8 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
592
638
|
.transition()
|
|
593
639
|
.duration(this.transitionService.getTransitionDuration())
|
|
594
640
|
.attr('y', (d) => {
|
|
595
|
-
return
|
|
641
|
+
// ScaleBand can return undefined for a key outside its domain; `.attr()` needs null, not undefined.
|
|
642
|
+
return this.yScaleGrouped(d.key) ?? null;
|
|
596
643
|
})
|
|
597
644
|
.attr('x', (d, i, n) => {
|
|
598
645
|
return this.xScale(config.thresholds[n[0].parentElement.dataset['groupId']].data[i].value);
|
|
@@ -615,13 +662,67 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
615
662
|
});
|
|
616
663
|
}
|
|
617
664
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: BarHorizontalChartBuilder, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
|
618
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: BarHorizontalChartBuilder
|
|
665
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: BarHorizontalChartBuilder });
|
|
619
666
|
}
|
|
620
667
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: BarHorizontalChartBuilder, decorators: [{
|
|
668
|
+
type: Injectable
|
|
669
|
+
}] });
|
|
670
|
+
|
|
671
|
+
/**
|
|
672
|
+
* Rebuilds a chart whenever its container's real, laid-out size changes.
|
|
673
|
+
*
|
|
674
|
+
* A plain `window:resize` listener (the previous approach) misses any layout-driven size change
|
|
675
|
+
* that isn't a viewport resize — a sidebar collapsing, a tab becoming active, a flex/grid reflow.
|
|
676
|
+
* It also can't help a chart that mounts already holding data (e.g. behind a loading gate): that
|
|
677
|
+
* chart's first `ngOnChanges` can fire before the browser has committed layout for its own
|
|
678
|
+
* just-created DOM node, so `PcacChart.initializeChartState()` measures a 0-width container and
|
|
679
|
+
* bails out with nothing drawn — and with no resize ever firing, nothing retries it.
|
|
680
|
+
*
|
|
681
|
+
* `ResizeObserver`'s callback contract guarantees real, laid-out dimensions on every firing,
|
|
682
|
+
* including its first, so observing the container naturally retries that exact case.
|
|
683
|
+
*/
|
|
684
|
+
class PcacChartResizeService {
|
|
685
|
+
/**
|
|
686
|
+
* Call once from a chart component's constructor (an injection context).
|
|
687
|
+
* @param chartElm Signal resolving to the chart's `<svg>` element ref, e.g. a `viewChild.required` query.
|
|
688
|
+
* @param rebuild Invoked whenever the chart's container size changes: immediately for the
|
|
689
|
+
* observer's first (guaranteed-initial) callback, debounced for every one after that.
|
|
690
|
+
*/
|
|
691
|
+
observe(chartElm, rebuild) {
|
|
692
|
+
const destroyRef = inject(DestroyRef);
|
|
693
|
+
const trigger$ = new Subject();
|
|
694
|
+
trigger$.pipe(debounceTime(300), takeUntilDestroyed(destroyRef)).subscribe(rebuild);
|
|
695
|
+
// chartElm() is a required viewChild query: unreadable until this component's own view has
|
|
696
|
+
// been created, so we defer the observe() call itself rather than reading it eagerly here.
|
|
697
|
+
afterNextRender(() => {
|
|
698
|
+
const container = chartElm().nativeElement.parentNode;
|
|
699
|
+
// The observer's first callback is its guaranteed initial one (see the class doc comment) -
|
|
700
|
+
// it's correcting an already-wrong first paint (e.g. a host layout, like a Material sidenav,
|
|
701
|
+
// that hasn't finished settling its width yet when this chart's very first build ran), not
|
|
702
|
+
// responding to live resize churn, so it shouldn't sit behind the same 300ms debounce meant
|
|
703
|
+
// for that. Left debounced, that correction could land while the wrong-width build's own
|
|
704
|
+
// enter transition is still visibly mid-animation, restarting it partway through - firing it
|
|
705
|
+
// immediately instead means the correction lands within a frame or two, before there's
|
|
706
|
+
// anything to visibly interrupt. Every callback after the first is still debounced normally.
|
|
707
|
+
let firstCallback = true;
|
|
708
|
+
const observer = new ResizeObserver(() => {
|
|
709
|
+
if (firstCallback) {
|
|
710
|
+
firstCallback = false;
|
|
711
|
+
rebuild();
|
|
712
|
+
return;
|
|
713
|
+
}
|
|
714
|
+
trigger$.next();
|
|
715
|
+
});
|
|
716
|
+
observer.observe(container);
|
|
717
|
+
destroyRef.onDestroy(() => observer.disconnect());
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacChartResizeService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
721
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacChartResizeService, providedIn: 'root' });
|
|
722
|
+
}
|
|
723
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacChartResizeService, decorators: [{
|
|
621
724
|
type: Injectable,
|
|
622
|
-
args: [{
|
|
623
|
-
providedIn: 'root',
|
|
624
|
-
}]
|
|
725
|
+
args: [{ providedIn: 'root' }]
|
|
625
726
|
}] });
|
|
626
727
|
|
|
627
728
|
class PcacBarHorizontalChartComponent {
|
|
@@ -629,42 +730,34 @@ class PcacBarHorizontalChartComponent {
|
|
|
629
730
|
config = input.required(/* @ts-ignore */
|
|
630
731
|
...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
|
|
631
732
|
chartElm = viewChild.required('chart');
|
|
632
|
-
barClicked =
|
|
633
|
-
resizeWindowTimeout;
|
|
733
|
+
barClicked = outputFromObservable(this.chartBuilder.barClicked$);
|
|
634
734
|
constructor() {
|
|
635
|
-
|
|
636
|
-
|
|
735
|
+
// Reacts to config() the same way ngOnChanges used to — reading it here (rather than a
|
|
736
|
+
// lifecycle hook) is what makes this an effect: it tracks config() as its dependency and
|
|
737
|
+
// reruns whenever a new value comes in, signal-input-changes-drive-behavior all the way down.
|
|
738
|
+
effect(() => this.buildChart());
|
|
739
|
+
inject(PcacChartResizeService).observe(this.chartElm, () => {
|
|
740
|
+
// Skip the ResizeObserver's routine initial callback when it lands after the effect above
|
|
741
|
+
// already built successfully at this same width — only a real size change (or a build
|
|
742
|
+
// that never happened, e.g. the 0-width mount race) should trigger a rebuild here.
|
|
743
|
+
if (this.chartBuilder.containerSizeChanged(this.chartElm())) {
|
|
744
|
+
this.buildChart();
|
|
745
|
+
}
|
|
637
746
|
});
|
|
638
747
|
}
|
|
639
|
-
ngOnChanges() {
|
|
640
|
-
this.buildChart();
|
|
641
|
-
}
|
|
642
748
|
buildChart() {
|
|
643
749
|
const config = this.config();
|
|
644
750
|
if (config && config.data && config.data.length > 0) {
|
|
645
751
|
this.chartBuilder.buildChart(this.chartElm(), config);
|
|
646
752
|
}
|
|
647
753
|
}
|
|
648
|
-
/**
|
|
649
|
-
* Opting against fromEvent due to incompatibility with rxjs 5 => 6
|
|
650
|
-
*/
|
|
651
|
-
onResize() {
|
|
652
|
-
const self = this;
|
|
653
|
-
clearTimeout(this.resizeWindowTimeout);
|
|
654
|
-
this.resizeWindowTimeout = setTimeout(() => {
|
|
655
|
-
self.buildChart();
|
|
656
|
-
}, 300);
|
|
657
|
-
}
|
|
658
754
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacBarHorizontalChartComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
659
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.0.2", type: PcacBarHorizontalChartComponent, isStandalone: true, selector: "pcac-bar-horizontal-chart", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { barClicked: "barClicked" },
|
|
755
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.0.2", type: PcacBarHorizontalChartComponent, isStandalone: true, selector: "pcac-bar-horizontal-chart", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { barClicked: "barClicked" }, providers: [BarHorizontalChartBuilder], 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-d3-tooltip{position:absolute;text-align:center;font-size:14px;padding:.5rem;pointer-events:none;display:none;background-color:#000000bf;color:#fff;border-radius:5px}\n"], encapsulation: i0.ViewEncapsulation.None });
|
|
660
756
|
}
|
|
661
757
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacBarHorizontalChartComponent, decorators: [{
|
|
662
758
|
type: Component,
|
|
663
|
-
args: [{ selector: 'pcac-bar-horizontal-chart',
|
|
664
|
-
}], 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"] }]
|
|
665
|
-
type: HostListener,
|
|
666
|
-
args: ['window:resize']
|
|
667
|
-
}] } });
|
|
759
|
+
args: [{ selector: 'pcac-bar-horizontal-chart', 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-d3-tooltip{position:absolute;text-align:center;font-size:14px;padding:.5rem;pointer-events:none;display:none;background-color:#000000bf;color:#fff;border-radius:5px}\n"] }]
|
|
760
|
+
}], 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"] }] } });
|
|
668
761
|
|
|
669
762
|
class PcacBarHorizontalChartConfig extends PcacChartConfig {
|
|
670
763
|
domainMax = 100;
|
|
@@ -681,6 +774,12 @@ class PcacBarHorizontalChartColorOverrideConfig {
|
|
|
681
774
|
colors = [];
|
|
682
775
|
}
|
|
683
776
|
|
|
777
|
+
/**
|
|
778
|
+
* Provided per-component (see PcacBarVerticalChartComponent's `providers`), not root-scoped:
|
|
779
|
+
* this builder extends PcacChart, which holds mutable per-chart-instance state (margin, width,
|
|
780
|
+
* height, colors, svg). A root singleton would be shared and clobbered by every
|
|
781
|
+
* <pcac-bar-vertical-chart> rendered at once.
|
|
782
|
+
*/
|
|
684
783
|
class BarVerticalChartBuilder extends PcacChart {
|
|
685
784
|
xScaleStacked;
|
|
686
785
|
xScaleGrouped;
|
|
@@ -688,15 +787,17 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
688
787
|
barClickedSource = new Subject();
|
|
689
788
|
barClicked$ = this.barClickedSource.asObservable();
|
|
690
789
|
buildChart(chartElm, config) {
|
|
790
|
+
if (!config?.data?.length) {
|
|
791
|
+
return;
|
|
792
|
+
}
|
|
691
793
|
if (config.colorOverride && config.colorOverride.colors) {
|
|
692
794
|
this.colors = config.colorOverride.colors;
|
|
693
795
|
}
|
|
694
796
|
if (config.hideAxis) {
|
|
695
797
|
this.adjustForHiddenAxis(config);
|
|
696
798
|
}
|
|
697
|
-
this.initializeChartState(chartElm, config)
|
|
698
|
-
|
|
699
|
-
return; // TODO: Figure out why this is happening on initial load sometimes
|
|
799
|
+
if (!this.initializeChartState(chartElm, config)) {
|
|
800
|
+
return;
|
|
700
801
|
}
|
|
701
802
|
if (config.colorOverride && config.colorOverride.colors) {
|
|
702
803
|
this.colors = config.colorOverride.colors.reverse();
|
|
@@ -754,6 +855,7 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
754
855
|
svg: this.svg,
|
|
755
856
|
numberOfTicks: config.numberOfTicks || 5,
|
|
756
857
|
width: this.width,
|
|
858
|
+
height: this.height,
|
|
757
859
|
xScale: this.xScaleStacked,
|
|
758
860
|
yScale: this.yScale
|
|
759
861
|
});
|
|
@@ -873,12 +975,12 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
873
975
|
.attr('data-group-threshold-id', (_, i) => {
|
|
874
976
|
return i;
|
|
875
977
|
})
|
|
876
|
-
.on('mousemove', (event
|
|
978
|
+
.on('mousemove', (event) => {
|
|
877
979
|
this.tooltipBuilder.showBarTooltip(event, config.thresholds[0], config.tickFormat || PcacFormatEnum.None);
|
|
878
980
|
})
|
|
879
981
|
.transition()
|
|
880
982
|
.duration(this.transitionService.getTransitionDuration())
|
|
881
|
-
.attr('y', (
|
|
983
|
+
.attr('y', (_, i) => {
|
|
882
984
|
return this.yScale(config.thresholds[i].value);
|
|
883
985
|
});
|
|
884
986
|
}
|
|
@@ -897,7 +999,7 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
897
999
|
})
|
|
898
1000
|
.transition()
|
|
899
1001
|
.duration(this.transitionService.getTransitionDuration())
|
|
900
|
-
.attr('y', (
|
|
1002
|
+
.attr('y', (_, i) => {
|
|
901
1003
|
return this.yScale(config.isStacked ? config.thresholds[i].data[0].value : config.thresholds[i].value);
|
|
902
1004
|
});
|
|
903
1005
|
}
|
|
@@ -922,7 +1024,11 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
922
1024
|
applyPreTransitionThresholdStyles(elm, config) {
|
|
923
1025
|
return elm.attr('class', 'pcac-threshold')
|
|
924
1026
|
.attr('x', (d) => {
|
|
925
|
-
|
|
1027
|
+
// Not every caller's selection has a per-item PcacData bound (the whole-chart threshold
|
|
1028
|
+
// rect has none), hence the defensive fallback rather than assuming `d` is always present.
|
|
1029
|
+
const datum = d;
|
|
1030
|
+
// ScaleBand can return undefined for a key outside its domain; `.attr()` needs null, not undefined.
|
|
1031
|
+
return this.xScaleGrouped(datum ? datum.key : '') ?? null;
|
|
926
1032
|
})
|
|
927
1033
|
.attr('y', () => {
|
|
928
1034
|
return this.height;
|
|
@@ -945,13 +1051,10 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
945
1051
|
});
|
|
946
1052
|
}
|
|
947
1053
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: BarVerticalChartBuilder, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
|
948
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: BarVerticalChartBuilder
|
|
1054
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: BarVerticalChartBuilder });
|
|
949
1055
|
}
|
|
950
1056
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: BarVerticalChartBuilder, decorators: [{
|
|
951
|
-
type: Injectable
|
|
952
|
-
args: [{
|
|
953
|
-
providedIn: 'root',
|
|
954
|
-
}]
|
|
1057
|
+
type: Injectable
|
|
955
1058
|
}] });
|
|
956
1059
|
|
|
957
1060
|
class PcacBarVerticalChartComponent {
|
|
@@ -959,42 +1062,34 @@ class PcacBarVerticalChartComponent {
|
|
|
959
1062
|
config = input.required(/* @ts-ignore */
|
|
960
1063
|
...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
|
|
961
1064
|
chartElm = viewChild.required('chart');
|
|
962
|
-
barClicked =
|
|
963
|
-
resizeWindowTimeout;
|
|
1065
|
+
barClicked = outputFromObservable(this.chartBuilder.barClicked$);
|
|
964
1066
|
constructor() {
|
|
965
|
-
|
|
966
|
-
|
|
1067
|
+
// Reacts to config() the same way ngOnChanges used to — reading it here (rather than a
|
|
1068
|
+
// lifecycle hook) is what makes this an effect: it tracks config() as its dependency and
|
|
1069
|
+
// reruns whenever a new value comes in, signal-input-changes-drive-behavior all the way down.
|
|
1070
|
+
effect(() => this.buildChart());
|
|
1071
|
+
inject(PcacChartResizeService).observe(this.chartElm, () => {
|
|
1072
|
+
// Skip the ResizeObserver's routine initial callback when it lands after the effect above
|
|
1073
|
+
// already built successfully at this same width — only a real size change (or a build
|
|
1074
|
+
// that never happened, e.g. the 0-width mount race) should trigger a rebuild here.
|
|
1075
|
+
if (this.chartBuilder.containerSizeChanged(this.chartElm())) {
|
|
1076
|
+
this.buildChart();
|
|
1077
|
+
}
|
|
967
1078
|
});
|
|
968
1079
|
}
|
|
969
|
-
ngOnChanges() {
|
|
970
|
-
this.buildChart();
|
|
971
|
-
}
|
|
972
1080
|
buildChart() {
|
|
973
1081
|
const config = this.config();
|
|
974
1082
|
if (config && config.data && config.data.length > 0) {
|
|
975
1083
|
this.chartBuilder.buildChart(this.chartElm(), config);
|
|
976
1084
|
}
|
|
977
1085
|
}
|
|
978
|
-
/**
|
|
979
|
-
* Opting against fromEvent due to incompatibility with rxjs 5 => 6
|
|
980
|
-
*/
|
|
981
|
-
onResize() {
|
|
982
|
-
const self = this;
|
|
983
|
-
clearTimeout(this.resizeWindowTimeout);
|
|
984
|
-
this.resizeWindowTimeout = setTimeout(() => {
|
|
985
|
-
self.buildChart();
|
|
986
|
-
}, 300);
|
|
987
|
-
}
|
|
988
1086
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacBarVerticalChartComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
989
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.0.2", type: PcacBarVerticalChartComponent, isStandalone: true, selector: "pcac-bar-vertical-chart", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { barClicked: "barClicked" },
|
|
1087
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.0.2", type: PcacBarVerticalChartComponent, isStandalone: true, selector: "pcac-bar-vertical-chart", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { barClicked: "barClicked" }, providers: [BarVerticalChartBuilder], 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}\n"], encapsulation: i0.ViewEncapsulation.None });
|
|
990
1088
|
}
|
|
991
1089
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacBarVerticalChartComponent, decorators: [{
|
|
992
1090
|
type: Component,
|
|
993
|
-
args: [{ selector: 'pcac-bar-vertical-chart',
|
|
994
|
-
}], 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"] }]
|
|
995
|
-
type: HostListener,
|
|
996
|
-
args: ['window:resize']
|
|
997
|
-
}] } });
|
|
1091
|
+
args: [{ selector: 'pcac-bar-vertical-chart', 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}\n"] }]
|
|
1092
|
+
}], 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"] }] } });
|
|
998
1093
|
|
|
999
1094
|
class PcacBarVerticalChartConfig extends PcacChartConfig {
|
|
1000
1095
|
domainMax = 100;
|
|
@@ -1028,26 +1123,37 @@ class PcacLegend {
|
|
|
1028
1123
|
colorScale = computed(() => this.colorService.getColorScale(this.config().items.length), /* @ts-ignore */
|
|
1029
1124
|
...(ngDevMode ? [{ debugName: "colorScale" }] : /* istanbul ignore next */ []));
|
|
1030
1125
|
onItemClicked(index) {
|
|
1031
|
-
const
|
|
1032
|
-
|
|
1033
|
-
this.
|
|
1034
|
-
this.itemClicked.emit(data.items);
|
|
1126
|
+
const items = this.config().items.map((item, i) => i === index ? { ...item, checked: !item.checked } : item);
|
|
1127
|
+
this.config.set({ ...this.config(), items });
|
|
1128
|
+
this.itemClicked.emit(items);
|
|
1035
1129
|
}
|
|
1036
1130
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacLegend, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1037
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.2", 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: "<label class=\"pcac-legend-label\"><small>{{config().heading}}</small></label>\n@for(item of config().items; track item; let i = $index; let first = $first; let last = $last;) {\n<div class=\"pcac-legend-item\" [class.pcac-legend-item-last]=\"last\" [class.pcac-legend-unchecked]=\"!item.checked\"\n (click)=\"onItemClicked(i)\">\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}", 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}\n"]
|
|
1131
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.2", 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: "<label class=\"pcac-legend-label\"><small>{{config().heading}}</small></label>\n@for(item of config().items; track item; let i = $index; let first = $first; let last = $last;) {\n<div class=\"pcac-legend-item\" [class.pcac-legend-item-last]=\"last\" [class.pcac-legend-unchecked]=\"!item.checked\"\n (click)=\"onItemClicked(i)\">\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}", 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}\n"] });
|
|
1038
1132
|
}
|
|
1039
1133
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacLegend, decorators: [{
|
|
1040
1134
|
type: Component,
|
|
1041
|
-
args: [{ selector: 'pcac-legend',
|
|
1135
|
+
args: [{ selector: 'pcac-legend', template: "<label class=\"pcac-legend-label\"><small>{{config().heading}}</small></label>\n@for(item of config().items; track item; let i = $index; let first = $first; let last = $last;) {\n<div class=\"pcac-legend-item\" [class.pcac-legend-item-last]=\"last\" [class.pcac-legend-unchecked]=\"!item.checked\"\n (click)=\"onItemClicked(i)\">\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}", 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}\n"] }]
|
|
1042
1136
|
}], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }, { type: i0.Output, args: ["configChange"] }], itemClicked: [{ type: i0.Output, args: ["itemClicked"] }] } });
|
|
1043
1137
|
|
|
1138
|
+
/**
|
|
1139
|
+
* Provided per-component (see PcacLineAreaChartComponent's `providers`), not root-scoped: this
|
|
1140
|
+
* holds mutable per-chart-instance state (`config`, `lines`) despite looking like a stateless
|
|
1141
|
+
* helper. A root singleton would be shared and clobbered by every `<pcac-line-area-chart>`
|
|
1142
|
+
* rendered at once — each instance's hover effects would end up reading/writing whichever
|
|
1143
|
+
* chart's `buildEffects()` ran last, not their own.
|
|
1144
|
+
*/
|
|
1044
1145
|
class PlaChartEffectsBuilder {
|
|
1045
1146
|
config;
|
|
1147
|
+
// .getTotalLength()/.getPointAtLength() below are SVGGeometryElement methods - the paths this
|
|
1148
|
+
// collects are always <path> elements (see PlaChartBuilder.drawLine/.drawArea). A chart draws
|
|
1149
|
+
// one or the other depending on its `type` (never both), so this selector is never ambiguous.
|
|
1150
|
+
// Plot-type charts draw neither (just standalone dots, no connecting geometry) - updateEffects()
|
|
1151
|
+
// below guards against that rather than this collecting nothing for it to index into.
|
|
1046
1152
|
lines = [];
|
|
1047
1153
|
buildEffects(config) {
|
|
1048
1154
|
this.config = config;
|
|
1049
1155
|
this.lines = [];
|
|
1050
|
-
this.config.svg.selectAll('.line').each((d, i, n) => {
|
|
1156
|
+
this.config.svg.selectAll('.line, .area').each((d, i, n) => {
|
|
1051
1157
|
this.lines.push(n[i]);
|
|
1052
1158
|
});
|
|
1053
1159
|
this.buildCollection();
|
|
@@ -1128,13 +1234,20 @@ class PlaChartEffectsBuilder {
|
|
|
1128
1234
|
updateEffects(mousePos) {
|
|
1129
1235
|
this.config.svg.selectAll('.effect-group')
|
|
1130
1236
|
.attr('transform', (data, index, nodes) => {
|
|
1237
|
+
const line = this.lines[index];
|
|
1238
|
+
if (!line) {
|
|
1239
|
+
// No connected line/area geometry for this group to walk (a plot-type chart, whose
|
|
1240
|
+
// dots aren't joined by a path) — nothing to position the crosshair against, so leave
|
|
1241
|
+
// it where it was rather than reading .getTotalLength() off undefined.
|
|
1242
|
+
return null;
|
|
1243
|
+
}
|
|
1131
1244
|
let beginning = 0;
|
|
1132
|
-
let end =
|
|
1245
|
+
let end = line.getTotalLength();
|
|
1133
1246
|
let target = 0;
|
|
1134
1247
|
let pos;
|
|
1135
1248
|
while (true) {
|
|
1136
1249
|
target = Math.floor((beginning + end) / 2);
|
|
1137
|
-
pos =
|
|
1250
|
+
pos = line.getPointAtLength(target);
|
|
1138
1251
|
if ((target === end || target === beginning) && pos.x !== mousePos[0]) {
|
|
1139
1252
|
break;
|
|
1140
1253
|
}
|
|
@@ -1155,13 +1268,10 @@ class PlaChartEffectsBuilder {
|
|
|
1155
1268
|
});
|
|
1156
1269
|
}
|
|
1157
1270
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PlaChartEffectsBuilder, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1158
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PlaChartEffectsBuilder
|
|
1271
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PlaChartEffectsBuilder });
|
|
1159
1272
|
}
|
|
1160
1273
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PlaChartEffectsBuilder, decorators: [{
|
|
1161
|
-
type: Injectable
|
|
1162
|
-
args: [{
|
|
1163
|
-
providedIn: 'root',
|
|
1164
|
-
}]
|
|
1274
|
+
type: Injectable
|
|
1165
1275
|
}] });
|
|
1166
1276
|
|
|
1167
1277
|
var PcacLineAreaPlotChartConfigType;
|
|
@@ -1277,7 +1387,14 @@ function buildZoomBehavior(width, height, zoomedFn) {
|
|
|
1277
1387
|
.on("zoom", zoomedFn);
|
|
1278
1388
|
}
|
|
1279
1389
|
|
|
1390
|
+
/**
|
|
1391
|
+
* Provided per-component (see PcacLineAreaChartComponent's `providers`), not root-scoped: this
|
|
1392
|
+
* builder extends PcacChart, which holds mutable per-chart-instance state (margin, width,
|
|
1393
|
+
* height, colors, svg). A root singleton would be shared and clobbered by every
|
|
1394
|
+
* <pcac-line-area-chart> rendered at once.
|
|
1395
|
+
*/
|
|
1280
1396
|
class PlaChartBuilder extends PcacChart {
|
|
1397
|
+
effectsBuilder = inject(PlaChartEffectsBuilder);
|
|
1281
1398
|
scales;
|
|
1282
1399
|
lineGenerator;
|
|
1283
1400
|
areaGenerator;
|
|
@@ -1287,13 +1404,16 @@ class PlaChartBuilder extends PcacChart {
|
|
|
1287
1404
|
clipPathId; // <-- added
|
|
1288
1405
|
dotClicked$ = this.dotClickedSource.asObservable();
|
|
1289
1406
|
buildChart(chartElm, config, type) {
|
|
1407
|
+
if (!config?.data?.length) {
|
|
1408
|
+
return;
|
|
1409
|
+
}
|
|
1290
1410
|
this.config = JSON.parse(JSON.stringify(config));
|
|
1291
|
-
this.startData = range(this.config.data[0].data.length).map(() => {
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
});
|
|
1411
|
+
this.startData = range(this.config.data[0].data.length).map(() => ({
|
|
1412
|
+
key: '',
|
|
1413
|
+
value: 0,
|
|
1414
|
+
hide: false,
|
|
1415
|
+
data: []
|
|
1416
|
+
}));
|
|
1297
1417
|
if (this.config.hideAxis) {
|
|
1298
1418
|
this.config.height = this.config.height + 12;
|
|
1299
1419
|
this.margin.top = 8;
|
|
@@ -1301,7 +1421,9 @@ class PlaChartBuilder extends PcacChart {
|
|
|
1301
1421
|
this.margin.left = 8;
|
|
1302
1422
|
this.margin.right = 8;
|
|
1303
1423
|
}
|
|
1304
|
-
this.initializeChartState(chartElm, this.config)
|
|
1424
|
+
if (!this.initializeChartState(chartElm, this.config)) {
|
|
1425
|
+
return;
|
|
1426
|
+
}
|
|
1305
1427
|
if (this.config.colorOverride) {
|
|
1306
1428
|
this.colors = this.config.colorOverride;
|
|
1307
1429
|
}
|
|
@@ -1310,7 +1432,6 @@ class PlaChartBuilder extends PcacChart {
|
|
|
1310
1432
|
this.areaGenerator = buildAreaGenerator(config.xFormat, this.scales, this.height);
|
|
1311
1433
|
if (this.config.enableZoom) {
|
|
1312
1434
|
this.zoomBehavior = buildZoomBehavior(this.width, this.height, (event) => {
|
|
1313
|
-
console.log('Zoom Event', event);
|
|
1314
1435
|
// Rescale x
|
|
1315
1436
|
const newX = event.transform.rescaleX(this.scales.x);
|
|
1316
1437
|
// Update axis
|
|
@@ -1355,13 +1476,14 @@ class PlaChartBuilder extends PcacChart {
|
|
|
1355
1476
|
svg: this.svg,
|
|
1356
1477
|
numberOfTicks: config.numberOfTicks || 5,
|
|
1357
1478
|
width: this.width,
|
|
1479
|
+
height: this.height,
|
|
1358
1480
|
xScale: this.scales.x,
|
|
1359
1481
|
yScale: this.scales.y
|
|
1360
1482
|
});
|
|
1361
1483
|
}
|
|
1362
1484
|
this.drawLineArea(config, type);
|
|
1363
1485
|
if (config.enableEffects) {
|
|
1364
|
-
|
|
1486
|
+
this.effectsBuilder.buildEffects({
|
|
1365
1487
|
svg: this.svg,
|
|
1366
1488
|
height: this.height,
|
|
1367
1489
|
width: this.width,
|
|
@@ -1380,15 +1502,20 @@ class PlaChartBuilder extends PcacChart {
|
|
|
1380
1502
|
.append('clipPath')
|
|
1381
1503
|
.attr('id', this.clipPathId)
|
|
1382
1504
|
.append('rect')
|
|
1383
|
-
.attr('x',
|
|
1505
|
+
.attr('x', -10) // extend clip-path a bit left to avoid cutting off a dot at the x-domain's minimum
|
|
1384
1506
|
.attr('y', -10) // extend clip-path a bit above to avoid cutting off top of line
|
|
1385
|
-
.attr('width', this.width)
|
|
1507
|
+
.attr('width', this.width + 20) // +20 to also cover a dot at the x-domain's maximum
|
|
1386
1508
|
.attr('height', this.height + 20); // +20 to ensure dots at bottom are not clipped
|
|
1387
1509
|
}
|
|
1388
1510
|
attachZoomBehavior() {
|
|
1389
1511
|
if (!this.config.enableZoom)
|
|
1390
1512
|
return;
|
|
1391
1513
|
// Add a transparent rect to capture zoom events
|
|
1514
|
+
//
|
|
1515
|
+
// d3's `ZoomBehavior<Element, unknown>` vs. our concretely-typed `Selection<SVGRectElement|SVGGElement, ...>`
|
|
1516
|
+
// is a known D3+TS typings friction point: `.call()` structurally compares nested generic Selection
|
|
1517
|
+
// methods (`.merge()`, `.select()`, ...) and those never line up across two different concrete element
|
|
1518
|
+
// types, even though a zoom behavior works on any element at runtime. Narrow, local `any` escape hatch.
|
|
1392
1519
|
this.svg.insert('rect', ':first-child')
|
|
1393
1520
|
.attr('width', this.width)
|
|
1394
1521
|
.attr('height', this.height)
|
|
@@ -1421,7 +1548,7 @@ class PlaChartBuilder extends PcacChart {
|
|
|
1421
1548
|
.attr('d', this.lineGenerator(this.startData))
|
|
1422
1549
|
.transition()
|
|
1423
1550
|
.duration(this.transitionService.getTransitionDuration())
|
|
1424
|
-
.attr('d', this.lineGenerator)
|
|
1551
|
+
.attr('d', this.lineGenerator)
|
|
1425
1552
|
.attr('stroke', () => {
|
|
1426
1553
|
return this.colors[index];
|
|
1427
1554
|
})
|
|
@@ -1437,12 +1564,12 @@ class PlaChartBuilder extends PcacChart {
|
|
|
1437
1564
|
.attr('class', 'area')
|
|
1438
1565
|
.style('opacity', 0.5)
|
|
1439
1566
|
.style('fill', () => {
|
|
1440
|
-
return this.colors[index];
|
|
1567
|
+
return this.colors[index];
|
|
1441
1568
|
})
|
|
1442
|
-
.attr('d', this.
|
|
1569
|
+
.attr('d', this.areaGenerator(this.startData))
|
|
1443
1570
|
.transition()
|
|
1444
1571
|
.duration(this.transitionService.getTransitionDuration())
|
|
1445
|
-
.attr('d', this.areaGenerator);
|
|
1572
|
+
.attr('d', this.areaGenerator);
|
|
1446
1573
|
}
|
|
1447
1574
|
drawDots(config) {
|
|
1448
1575
|
const self = this;
|
|
@@ -1460,7 +1587,7 @@ class PlaChartBuilder extends PcacChart {
|
|
|
1460
1587
|
.attr('cx', (d, i) => {
|
|
1461
1588
|
return getXFormat(config.xFormat, d, i, this.scales.x);
|
|
1462
1589
|
})
|
|
1463
|
-
.attr('cy', (
|
|
1590
|
+
.attr('cy', (_) => {
|
|
1464
1591
|
return this.scales.y(0);
|
|
1465
1592
|
})
|
|
1466
1593
|
.attr('fill', '#fff')
|
|
@@ -1480,7 +1607,7 @@ class PlaChartBuilder extends PcacChart {
|
|
|
1480
1607
|
.attr('r', 4)
|
|
1481
1608
|
.attr('fill', '#fff');
|
|
1482
1609
|
})
|
|
1483
|
-
.on('click', (
|
|
1610
|
+
.on('click', (_event, d) => {
|
|
1484
1611
|
this.dotClickedSource.next(d);
|
|
1485
1612
|
})
|
|
1486
1613
|
.transition()
|
|
@@ -1492,71 +1619,64 @@ class PlaChartBuilder extends PcacChart {
|
|
|
1492
1619
|
.attr('style', () => config.data[index].hide ? 'display: none' : null);
|
|
1493
1620
|
}
|
|
1494
1621
|
}
|
|
1622
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PlaChartBuilder, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
|
1623
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PlaChartBuilder });
|
|
1495
1624
|
}
|
|
1625
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PlaChartBuilder, decorators: [{
|
|
1626
|
+
type: Injectable
|
|
1627
|
+
}] });
|
|
1496
1628
|
|
|
1497
1629
|
class PcacLineAreaChartComponent {
|
|
1498
|
-
chartBuilder =
|
|
1630
|
+
chartBuilder = inject(PlaChartBuilder);
|
|
1499
1631
|
config = input.required(/* @ts-ignore */
|
|
1500
1632
|
...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
|
|
1501
1633
|
type = input.required(/* @ts-ignore */
|
|
1502
1634
|
...(ngDevMode ? [{ debugName: "type" }] : /* istanbul ignore next */ []));
|
|
1503
1635
|
chartElm = viewChild.required('chart');
|
|
1504
|
-
dotClicked =
|
|
1505
|
-
resizeWindowTimeout;
|
|
1636
|
+
dotClicked = outputFromObservable(this.chartBuilder.dotClicked$);
|
|
1506
1637
|
constructor() {
|
|
1507
|
-
|
|
1508
|
-
|
|
1638
|
+
// Reacts to config()/type() the same way ngOnChanges used to — reading them here (rather
|
|
1639
|
+
// than a lifecycle hook) is what makes this an effect: it tracks whichever signals
|
|
1640
|
+
// buildChart() reads and reruns whenever either changes. That includes type(), which the old
|
|
1641
|
+
// ngOnChanges deliberately ignored (it only compared changes['config']) — in practice type()
|
|
1642
|
+
// is always bound to a constant per wrapper (PcacLineChart/PcacAreaChart/PcacPlotChart), so
|
|
1643
|
+
// this is unreachable today, but reacting to it is the more correct behavior regardless.
|
|
1644
|
+
effect(() => this.buildChart());
|
|
1645
|
+
inject(PcacChartResizeService).observe(this.chartElm, () => {
|
|
1646
|
+
// Skip the ResizeObserver's routine initial callback when it lands after the effect above
|
|
1647
|
+
// already built successfully at this same width — only a real size change (or a build
|
|
1648
|
+
// that never happened, e.g. the 0-width mount race) should trigger a rebuild here.
|
|
1649
|
+
if (this.chartBuilder.containerSizeChanged(this.chartElm())) {
|
|
1650
|
+
this.buildChart();
|
|
1651
|
+
}
|
|
1509
1652
|
});
|
|
1510
1653
|
}
|
|
1511
|
-
ngOnChanges(changes) {
|
|
1512
|
-
if (changes['config'].currentValue !== changes['config'].previousValue) {
|
|
1513
|
-
this.buildChart();
|
|
1514
|
-
}
|
|
1515
|
-
}
|
|
1516
1654
|
buildChart() {
|
|
1517
1655
|
const config = this.config();
|
|
1518
1656
|
if (config && config.data && config.data.length > 0) {
|
|
1519
1657
|
this.chartBuilder.buildChart(this.chartElm(), config, this.type());
|
|
1520
1658
|
}
|
|
1521
1659
|
}
|
|
1522
|
-
/**
|
|
1523
|
-
* Opting against fromEvent due to incompatibility with rxjs 5 => 6
|
|
1524
|
-
*/
|
|
1525
|
-
onResize() {
|
|
1526
|
-
const self = this;
|
|
1527
|
-
clearTimeout(this.resizeWindowTimeout);
|
|
1528
|
-
this.resizeWindowTimeout = setTimeout(() => {
|
|
1529
|
-
self.buildChart();
|
|
1530
|
-
}, 300);
|
|
1531
|
-
}
|
|
1532
1660
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacLineAreaChartComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1533
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.0.2", 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 } }, outputs: { dotClicked: "dotClicked" },
|
|
1661
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.0.2", 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 } }, outputs: { dotClicked: "dotClicked" }, 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 .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-d3-tooltip{position:absolute;text-align:center;font-size:14px;padding:.5rem;pointer-events:none;display:none;background-color:#000000bf;color:#fff;border-radius:5px}\n"], encapsulation: i0.ViewEncapsulation.None });
|
|
1534
1662
|
}
|
|
1535
1663
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacLineAreaChartComponent, decorators: [{
|
|
1536
1664
|
type: Component,
|
|
1537
|
-
args: [{ selector: 'pcac-line-area-chart',
|
|
1538
|
-
}], 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"] }]
|
|
1539
|
-
type: HostListener,
|
|
1540
|
-
args: ['window:resize']
|
|
1541
|
-
}] } });
|
|
1665
|
+
args: [{ selector: 'pcac-line-area-chart', 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 .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-d3-tooltip{position:absolute;text-align:center;font-size:14px;padding:.5rem;pointer-events:none;display:none;background-color:#000000bf;color:#fff;border-radius:5px}\n"] }]
|
|
1666
|
+
}], 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"] }] } });
|
|
1542
1667
|
|
|
1543
1668
|
class PcacPlotChart {
|
|
1544
1669
|
config = input.required(/* @ts-ignore */
|
|
1545
1670
|
...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
|
|
1546
1671
|
types = PcacLineAreaPlotChartConfigType;
|
|
1547
1672
|
dotClicked = output();
|
|
1548
|
-
chart = viewChild(PcacLineAreaChartComponent, /* @ts-ignore */
|
|
1549
|
-
...(ngDevMode ? [{ debugName: "chart" }] : /* istanbul ignore next */ []));
|
|
1550
|
-
onResize() {
|
|
1551
|
-
this.chart()?.onResize();
|
|
1552
|
-
}
|
|
1553
1673
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacPlotChart, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1554
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.
|
|
1674
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "22.0.2", type: PcacPlotChart, isStandalone: true, selector: "pcac-plot-chart", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { dotClicked: "dotClicked" }, ngImport: i0, template: "<pcac-line-area-chart [config]=\"config()\" [type]=\"types.Plot\" (dotClicked)=\"dotClicked.emit($event)\"/>", dependencies: [{ kind: "component", type: PcacLineAreaChartComponent, selector: "pcac-line-area-chart", inputs: ["config", "type"], outputs: ["dotClicked"] }] });
|
|
1555
1675
|
}
|
|
1556
1676
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacPlotChart, decorators: [{
|
|
1557
1677
|
type: Component,
|
|
1558
|
-
args: [{ selector: 'pcac-plot-chart',
|
|
1559
|
-
}], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }], dotClicked: [{ type: i0.Output, args: ["dotClicked"] }]
|
|
1678
|
+
args: [{ selector: 'pcac-plot-chart', imports: [PcacLineAreaChartComponent], template: "<pcac-line-area-chart [config]=\"config()\" [type]=\"types.Plot\" (dotClicked)=\"dotClicked.emit($event)\"/>" }]
|
|
1679
|
+
}], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }], dotClicked: [{ type: i0.Output, args: ["dotClicked"] }] } });
|
|
1560
1680
|
|
|
1561
1681
|
class PcacPlotChartConfig extends PcacLineAreaChartConfig {
|
|
1562
1682
|
}
|
|
@@ -1566,18 +1686,13 @@ class PcacLineChart {
|
|
|
1566
1686
|
...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
|
|
1567
1687
|
types = PcacLineAreaPlotChartConfigType;
|
|
1568
1688
|
dotClicked = output();
|
|
1569
|
-
chart = viewChild(PcacLineAreaChartComponent, /* @ts-ignore */
|
|
1570
|
-
...(ngDevMode ? [{ debugName: "chart" }] : /* istanbul ignore next */ []));
|
|
1571
|
-
onResize() {
|
|
1572
|
-
this.chart()?.onResize();
|
|
1573
|
-
}
|
|
1574
1689
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacLineChart, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1575
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.
|
|
1690
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "22.0.2", type: PcacLineChart, isStandalone: true, selector: "pcac-line-chart", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { dotClicked: "dotClicked" }, ngImport: i0, template: "<pcac-line-area-chart [config]=\"config()\" [type]=\"types.Line\" />", dependencies: [{ kind: "component", type: PcacLineAreaChartComponent, selector: "pcac-line-area-chart", inputs: ["config", "type"], outputs: ["dotClicked"] }] });
|
|
1576
1691
|
}
|
|
1577
1692
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacLineChart, decorators: [{
|
|
1578
1693
|
type: Component,
|
|
1579
|
-
args: [{ selector: 'pcac-line-chart',
|
|
1580
|
-
}], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }], dotClicked: [{ type: i0.Output, args: ["dotClicked"] }]
|
|
1694
|
+
args: [{ selector: 'pcac-line-chart', imports: [PcacLineAreaChartComponent], template: "<pcac-line-area-chart [config]=\"config()\" [type]=\"types.Line\" />" }]
|
|
1695
|
+
}], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }], dotClicked: [{ type: i0.Output, args: ["dotClicked"] }] } });
|
|
1581
1696
|
|
|
1582
1697
|
class PcacLineChartConfig extends PcacLineAreaChartConfig {
|
|
1583
1698
|
}
|
|
@@ -1587,18 +1702,13 @@ class PcacAreaChart {
|
|
|
1587
1702
|
...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
|
|
1588
1703
|
types = PcacLineAreaPlotChartConfigType;
|
|
1589
1704
|
dotClicked = output();
|
|
1590
|
-
chart = viewChild(PcacLineAreaChartComponent, /* @ts-ignore */
|
|
1591
|
-
...(ngDevMode ? [{ debugName: "chart" }] : /* istanbul ignore next */ []));
|
|
1592
|
-
onResize() {
|
|
1593
|
-
this.chart()?.onResize();
|
|
1594
|
-
}
|
|
1595
1705
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacAreaChart, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1596
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.
|
|
1706
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "22.0.2", type: PcacAreaChart, isStandalone: true, selector: "pcac-area-chart", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { dotClicked: "dotClicked" }, ngImport: i0, template: "<pcac-line-area-chart [config]=\"config()\" [type]=\"types.Area\" />", dependencies: [{ kind: "component", type: PcacLineAreaChartComponent, selector: "pcac-line-area-chart", inputs: ["config", "type"], outputs: ["dotClicked"] }] });
|
|
1597
1707
|
}
|
|
1598
1708
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacAreaChart, decorators: [{
|
|
1599
1709
|
type: Component,
|
|
1600
|
-
args: [{ selector: 'pcac-area-chart',
|
|
1601
|
-
}], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }], dotClicked: [{ type: i0.Output, args: ["dotClicked"] }]
|
|
1710
|
+
args: [{ selector: 'pcac-area-chart', imports: [PcacLineAreaChartComponent], template: "<pcac-line-area-chart [config]=\"config()\" [type]=\"types.Area\" />" }]
|
|
1711
|
+
}], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }], dotClicked: [{ type: i0.Output, args: ["dotClicked"] }] } });
|
|
1602
1712
|
|
|
1603
1713
|
class PcacAreaChartConfig extends PcacLineAreaChartConfig {
|
|
1604
1714
|
}
|
|
@@ -1607,6 +1717,12 @@ class PcacAreaChartConfig extends PcacLineAreaChartConfig {
|
|
|
1607
1717
|
// export * from './plot-line-area-chart.component';
|
|
1608
1718
|
// export * from './plot-line-area-chart.model';
|
|
1609
1719
|
|
|
1720
|
+
/**
|
|
1721
|
+
* Provided per-component (see PcacPieChartComponent's `providers`), not root-scoped:
|
|
1722
|
+
* this builder extends PcacChart, which holds mutable per-chart-instance state (margin, width,
|
|
1723
|
+
* height, colors, svg). A root singleton would be shared and clobbered by every
|
|
1724
|
+
* <pcac-pie-chart> rendered at once.
|
|
1725
|
+
*/
|
|
1610
1726
|
class PieChartBuilder extends PcacChart {
|
|
1611
1727
|
radius;
|
|
1612
1728
|
arcShape;
|
|
@@ -1615,7 +1731,12 @@ class PieChartBuilder extends PcacChart {
|
|
|
1615
1731
|
sliceClickedSource = new Subject();
|
|
1616
1732
|
sliceClicked$ = this.sliceClickedSource.asObservable();
|
|
1617
1733
|
buildChart(chartElm, config) {
|
|
1618
|
-
|
|
1734
|
+
if (!config?.data?.length) {
|
|
1735
|
+
return;
|
|
1736
|
+
}
|
|
1737
|
+
if (!this.initializeChartState(chartElm, config)) {
|
|
1738
|
+
return;
|
|
1739
|
+
}
|
|
1619
1740
|
this.radius = Math.min(Math.min(this.height, this.width), Math.min(this.height, this.width)) / 2;
|
|
1620
1741
|
this.buildShapes(config);
|
|
1621
1742
|
this.drawChart(chartElm, config);
|
|
@@ -1630,7 +1751,7 @@ class PieChartBuilder extends PcacChart {
|
|
|
1630
1751
|
.outerRadius(this.radius - radiusOffset + radiusOffset);
|
|
1631
1752
|
this.pieAngles = pie()
|
|
1632
1753
|
.sort(null)
|
|
1633
|
-
.value((d) => d.value);
|
|
1754
|
+
.value((d) => d.value);
|
|
1634
1755
|
}
|
|
1635
1756
|
drawChart(chartElm, config) {
|
|
1636
1757
|
this.buildContainer(chartElm, true);
|
|
@@ -1662,7 +1783,7 @@ class PieChartBuilder extends PcacChart {
|
|
|
1662
1783
|
.attr('d', self.arcShape)
|
|
1663
1784
|
.style('fill', self.colors[d.index]);
|
|
1664
1785
|
})
|
|
1665
|
-
.on('click', (
|
|
1786
|
+
.on('click', (_event, d) => {
|
|
1666
1787
|
this.sliceClickedSource.next(d.data);
|
|
1667
1788
|
})
|
|
1668
1789
|
.transition()
|
|
@@ -1672,18 +1793,17 @@ class PieChartBuilder extends PcacChart {
|
|
|
1672
1793
|
});
|
|
1673
1794
|
}
|
|
1674
1795
|
tweenChart(b) {
|
|
1796
|
+
// `innerRadius`/`outerRadius` aren't part of PieArcDatum - arcShape's own .innerRadius()/.outerRadius()
|
|
1797
|
+
// accessors are fixed constants and never read them from the datum, so this is a legacy no-op kept for parity.
|
|
1675
1798
|
b.innerRadius = 0;
|
|
1676
1799
|
const i = interpolate({ startAngle: 0, endAngle: 0 }, b);
|
|
1677
|
-
return (t) => this.arcShape(i(t))
|
|
1800
|
+
return (t) => this.arcShape(i(t)) ?? '';
|
|
1678
1801
|
}
|
|
1679
1802
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PieChartBuilder, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
|
1680
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PieChartBuilder
|
|
1803
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PieChartBuilder });
|
|
1681
1804
|
}
|
|
1682
1805
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PieChartBuilder, decorators: [{
|
|
1683
|
-
type: Injectable
|
|
1684
|
-
args: [{
|
|
1685
|
-
providedIn: 'root',
|
|
1686
|
-
}]
|
|
1806
|
+
type: Injectable
|
|
1687
1807
|
}] });
|
|
1688
1808
|
|
|
1689
1809
|
class PcacPieChartComponent {
|
|
@@ -1691,42 +1811,34 @@ class PcacPieChartComponent {
|
|
|
1691
1811
|
config = input.required(/* @ts-ignore */
|
|
1692
1812
|
...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
|
|
1693
1813
|
chartElm = viewChild.required('chart');
|
|
1694
|
-
sliceClicked =
|
|
1695
|
-
resizeWindowTimeout;
|
|
1814
|
+
sliceClicked = outputFromObservable(this.chartBuilder.sliceClicked$);
|
|
1696
1815
|
constructor() {
|
|
1697
|
-
|
|
1698
|
-
|
|
1816
|
+
// Reacts to config() the same way ngOnChanges used to — reading it here (rather than a
|
|
1817
|
+
// lifecycle hook) is what makes this an effect: it tracks config() as its dependency and
|
|
1818
|
+
// reruns whenever a new value comes in, signal-input-changes-drive-behavior all the way down.
|
|
1819
|
+
effect(() => this.buildChart());
|
|
1820
|
+
inject(PcacChartResizeService).observe(this.chartElm, () => {
|
|
1821
|
+
// Skip the ResizeObserver's routine initial callback when it lands after the effect above
|
|
1822
|
+
// already built successfully at this same width — only a real size change (or a build
|
|
1823
|
+
// that never happened, e.g. the 0-width mount race) should trigger a rebuild here.
|
|
1824
|
+
if (this.chartBuilder.containerSizeChanged(this.chartElm())) {
|
|
1825
|
+
this.buildChart();
|
|
1826
|
+
}
|
|
1699
1827
|
});
|
|
1700
1828
|
}
|
|
1701
|
-
ngOnChanges() {
|
|
1702
|
-
this.buildChart();
|
|
1703
|
-
}
|
|
1704
1829
|
buildChart() {
|
|
1705
1830
|
const config = this.config();
|
|
1706
1831
|
if (config && config.data && config.data.length > 0) {
|
|
1707
1832
|
this.chartBuilder.buildChart(this.chartElm(), config);
|
|
1708
1833
|
}
|
|
1709
1834
|
}
|
|
1710
|
-
/**
|
|
1711
|
-
* Opting against fromEvent due to incompatibility with rxjs 5 => 6
|
|
1712
|
-
*/
|
|
1713
|
-
onResize() {
|
|
1714
|
-
const self = this;
|
|
1715
|
-
clearTimeout(this.resizeWindowTimeout);
|
|
1716
|
-
this.resizeWindowTimeout = setTimeout(() => {
|
|
1717
|
-
self.buildChart();
|
|
1718
|
-
}, 300);
|
|
1719
|
-
}
|
|
1720
1835
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacPieChartComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1721
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.0.2", type: PcacPieChartComponent, isStandalone: true, selector: "pcac-pie-chart", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { sliceClicked: "sliceClicked" },
|
|
1836
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.0.2", 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], 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}.pcac-pie-chart .dot{fill:none;stroke-width:1px}\n"], encapsulation: i0.ViewEncapsulation.None });
|
|
1722
1837
|
}
|
|
1723
1838
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacPieChartComponent, decorators: [{
|
|
1724
1839
|
type: Component,
|
|
1725
|
-
args: [{ selector: 'pcac-pie-chart',
|
|
1726
|
-
}], 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"] }]
|
|
1727
|
-
type: HostListener,
|
|
1728
|
-
args: ['window:resize']
|
|
1729
|
-
}] } });
|
|
1840
|
+
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}.pcac-pie-chart .dot{fill:none;stroke-width:1px}\n"] }]
|
|
1841
|
+
}], 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"] }] } });
|
|
1730
1842
|
|
|
1731
1843
|
class PcacPieChartConfig extends PcacChartConfig {
|
|
1732
1844
|
numberOfTicks = 5;
|
|
@@ -1740,5 +1852,5 @@ class PcacPieChartConfig extends PcacChartConfig {
|
|
|
1740
1852
|
* Generated bundle index. Do not edit.
|
|
1741
1853
|
*/
|
|
1742
1854
|
|
|
1743
|
-
export { BarHorizontalChartBuilder, BarVerticalChartBuilder, PcacAreaChart, PcacAreaChartConfig, PcacAxisBuilder, PcacBarHorizontalChartColorOverrideConfig, PcacBarHorizontalChartComponent, PcacBarHorizontalChartConfig, PcacBarVerticalChartColorOverrideConfig, PcacBarVerticalChartComponent, PcacBarVerticalChartConfig, PcacChart, PcacChartConfig, PcacColorService, PcacData, PcacFormatEnum, PcacGridBuilder, PcacLegend, PcacLegendConfig, PcacLegendConfigItem, PcacLineChart, PcacLineChartConfig, PcacPieChartComponent, PcacPieChartConfig, PcacPlotChart, PcacPlotChartConfig, PcacTooltipBuilder, PcacTransitionService, PieChartBuilder };
|
|
1855
|
+
export { BarHorizontalChartBuilder, BarVerticalChartBuilder, PcacAreaChart, PcacAreaChartConfig, PcacAxisBuilder, PcacBarHorizontalChartColorOverrideConfig, PcacBarHorizontalChartComponent, PcacBarHorizontalChartConfig, PcacBarVerticalChartColorOverrideConfig, PcacBarVerticalChartComponent, PcacBarVerticalChartConfig, PcacChart, PcacChartConfig, PcacChartResizeService, PcacColorService, PcacData, PcacFormatEnum, PcacGridBuilder, PcacLegend, PcacLegendConfig, PcacLegendConfigItem, PcacLineChart, PcacLineChartConfig, PcacPieChartComponent, PcacPieChartConfig, PcacPlotChart, PcacPlotChartConfig, PcacTooltipBuilder, PcacTransitionService, PieChartBuilder };
|
|
1744
1856
|
//# sourceMappingURL=pioneer-code-pioneer-charts.mjs.map
|