@pioneer-code/pioneer-charts 21.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 +381 -256
- package/fesm2022/pioneer-code-pioneer-charts.mjs.map +1 -1
- package/package.json +9 -6
- 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, input, viewChild,
|
|
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
|
}
|
|
@@ -106,10 +108,10 @@ class PcacAxisBuilder {
|
|
|
106
108
|
.attr('transform', 'translate(0,' + config.height + ')')
|
|
107
109
|
.call(xAxis);
|
|
108
110
|
}
|
|
109
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
110
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
111
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacAxisBuilder, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
112
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacAxisBuilder, providedIn: 'root' });
|
|
111
113
|
}
|
|
112
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
114
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacAxisBuilder, decorators: [{
|
|
113
115
|
type: Injectable,
|
|
114
116
|
args: [{
|
|
115
117
|
providedIn: 'root',
|
|
@@ -118,36 +120,38 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.0", 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' : ''));
|
|
146
150
|
}
|
|
147
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
148
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
151
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacGridBuilder, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
152
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacGridBuilder, providedIn: 'root' });
|
|
149
153
|
}
|
|
150
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
154
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacGridBuilder, decorators: [{
|
|
151
155
|
type: Injectable,
|
|
152
156
|
args: [{
|
|
153
157
|
providedIn: 'root',
|
|
@@ -211,13 +215,13 @@ 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
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
218
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
221
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacColorService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
222
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacColorService, providedIn: 'root' });
|
|
219
223
|
}
|
|
220
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
224
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacColorService, decorators: [{
|
|
221
225
|
type: Injectable,
|
|
222
226
|
args: [{
|
|
223
227
|
providedIn: 'root',
|
|
@@ -229,10 +233,10 @@ class PcacTransitionService {
|
|
|
229
233
|
getTransitionDuration() {
|
|
230
234
|
return this.transitionDuration;
|
|
231
235
|
}
|
|
232
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
233
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
236
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacTransitionService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
237
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacTransitionService, providedIn: 'root' });
|
|
234
238
|
}
|
|
235
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
239
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacTransitionService, decorators: [{
|
|
236
240
|
type: Injectable,
|
|
237
241
|
args: [{
|
|
238
242
|
providedIn: 'root',
|
|
@@ -242,7 +246,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.0", 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')
|
|
@@ -282,10 +286,10 @@ class PcacTooltipBuilder {
|
|
|
282
286
|
let finalValue = value ? value.toString() : value;
|
|
283
287
|
return key ? key + '</br>' + finalValue : `${finalValue}`;
|
|
284
288
|
}
|
|
285
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
286
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
289
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacTooltipBuilder, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
290
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacTooltipBuilder, providedIn: 'root' });
|
|
287
291
|
}
|
|
288
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
292
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacTooltipBuilder, decorators: [{
|
|
289
293
|
type: Injectable,
|
|
290
294
|
args: [{
|
|
291
295
|
providedIn: 'root',
|
|
@@ -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);
|
|
@@ -614,56 +661,103 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
614
661
|
this.tooltipBuilder.hideTooltip();
|
|
615
662
|
});
|
|
616
663
|
}
|
|
617
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
618
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
664
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: BarHorizontalChartBuilder, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
|
665
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: BarHorizontalChartBuilder });
|
|
619
666
|
}
|
|
620
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
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 {
|
|
628
729
|
chartBuilder = inject(BarHorizontalChartBuilder);
|
|
629
|
-
config = input.required(
|
|
730
|
+
config = input.required(/* @ts-ignore */
|
|
731
|
+
...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
|
|
630
732
|
chartElm = viewChild.required('chart');
|
|
631
|
-
barClicked =
|
|
632
|
-
resizeWindowTimeout;
|
|
733
|
+
barClicked = outputFromObservable(this.chartBuilder.barClicked$);
|
|
633
734
|
constructor() {
|
|
634
|
-
|
|
635
|
-
|
|
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
|
+
}
|
|
636
746
|
});
|
|
637
747
|
}
|
|
638
|
-
ngOnChanges() {
|
|
639
|
-
this.buildChart();
|
|
640
|
-
}
|
|
641
748
|
buildChart() {
|
|
642
749
|
const config = this.config();
|
|
643
750
|
if (config && config.data && config.data.length > 0) {
|
|
644
751
|
this.chartBuilder.buildChart(this.chartElm(), config);
|
|
645
752
|
}
|
|
646
753
|
}
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
*/
|
|
650
|
-
onResize() {
|
|
651
|
-
const self = this;
|
|
652
|
-
clearTimeout(this.resizeWindowTimeout);
|
|
653
|
-
this.resizeWindowTimeout = setTimeout(() => {
|
|
654
|
-
self.buildChart();
|
|
655
|
-
}, 300);
|
|
656
|
-
}
|
|
657
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.0", ngImport: i0, type: PcacBarHorizontalChartComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
658
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "21.0.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: { listeners: { "window:resize": "onResize()" } }, viewQueries: [{ propertyName: "chartElm", first: true, predicate: ["chart"], descendants: true, isSignal: true }], usesOnChanges: 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 });
|
|
754
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacBarHorizontalChartComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
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 });
|
|
659
756
|
}
|
|
660
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
757
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacBarHorizontalChartComponent, decorators: [{
|
|
661
758
|
type: Component,
|
|
662
|
-
args: [{ selector: 'pcac-bar-horizontal-chart', encapsulation: ViewEncapsulation.None, 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"] }]
|
|
663
|
-
}], 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"] }]
|
|
664
|
-
type: HostListener,
|
|
665
|
-
args: ['window:resize']
|
|
666
|
-
}] } });
|
|
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"] }] } });
|
|
667
761
|
|
|
668
762
|
class PcacBarHorizontalChartConfig extends PcacChartConfig {
|
|
669
763
|
domainMax = 100;
|
|
@@ -680,6 +774,12 @@ class PcacBarHorizontalChartColorOverrideConfig {
|
|
|
680
774
|
colors = [];
|
|
681
775
|
}
|
|
682
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
|
+
*/
|
|
683
783
|
class BarVerticalChartBuilder extends PcacChart {
|
|
684
784
|
xScaleStacked;
|
|
685
785
|
xScaleGrouped;
|
|
@@ -687,15 +787,17 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
687
787
|
barClickedSource = new Subject();
|
|
688
788
|
barClicked$ = this.barClickedSource.asObservable();
|
|
689
789
|
buildChart(chartElm, config) {
|
|
790
|
+
if (!config?.data?.length) {
|
|
791
|
+
return;
|
|
792
|
+
}
|
|
690
793
|
if (config.colorOverride && config.colorOverride.colors) {
|
|
691
794
|
this.colors = config.colorOverride.colors;
|
|
692
795
|
}
|
|
693
796
|
if (config.hideAxis) {
|
|
694
797
|
this.adjustForHiddenAxis(config);
|
|
695
798
|
}
|
|
696
|
-
this.initializeChartState(chartElm, config)
|
|
697
|
-
|
|
698
|
-
return; // TODO: Figure out why this is happening on initial load sometimes
|
|
799
|
+
if (!this.initializeChartState(chartElm, config)) {
|
|
800
|
+
return;
|
|
699
801
|
}
|
|
700
802
|
if (config.colorOverride && config.colorOverride.colors) {
|
|
701
803
|
this.colors = config.colorOverride.colors.reverse();
|
|
@@ -753,6 +855,7 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
753
855
|
svg: this.svg,
|
|
754
856
|
numberOfTicks: config.numberOfTicks || 5,
|
|
755
857
|
width: this.width,
|
|
858
|
+
height: this.height,
|
|
756
859
|
xScale: this.xScaleStacked,
|
|
757
860
|
yScale: this.yScale
|
|
758
861
|
});
|
|
@@ -872,12 +975,12 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
872
975
|
.attr('data-group-threshold-id', (_, i) => {
|
|
873
976
|
return i;
|
|
874
977
|
})
|
|
875
|
-
.on('mousemove', (event
|
|
978
|
+
.on('mousemove', (event) => {
|
|
876
979
|
this.tooltipBuilder.showBarTooltip(event, config.thresholds[0], config.tickFormat || PcacFormatEnum.None);
|
|
877
980
|
})
|
|
878
981
|
.transition()
|
|
879
982
|
.duration(this.transitionService.getTransitionDuration())
|
|
880
|
-
.attr('y', (
|
|
983
|
+
.attr('y', (_, i) => {
|
|
881
984
|
return this.yScale(config.thresholds[i].value);
|
|
882
985
|
});
|
|
883
986
|
}
|
|
@@ -896,7 +999,7 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
896
999
|
})
|
|
897
1000
|
.transition()
|
|
898
1001
|
.duration(this.transitionService.getTransitionDuration())
|
|
899
|
-
.attr('y', (
|
|
1002
|
+
.attr('y', (_, i) => {
|
|
900
1003
|
return this.yScale(config.isStacked ? config.thresholds[i].data[0].value : config.thresholds[i].value);
|
|
901
1004
|
});
|
|
902
1005
|
}
|
|
@@ -921,7 +1024,11 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
921
1024
|
applyPreTransitionThresholdStyles(elm, config) {
|
|
922
1025
|
return elm.attr('class', 'pcac-threshold')
|
|
923
1026
|
.attr('x', (d) => {
|
|
924
|
-
|
|
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;
|
|
925
1032
|
})
|
|
926
1033
|
.attr('y', () => {
|
|
927
1034
|
return this.height;
|
|
@@ -943,56 +1050,46 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
943
1050
|
return '3px';
|
|
944
1051
|
});
|
|
945
1052
|
}
|
|
946
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
947
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
1053
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: BarVerticalChartBuilder, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
|
1054
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: BarVerticalChartBuilder });
|
|
948
1055
|
}
|
|
949
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
950
|
-
type: Injectable
|
|
951
|
-
args: [{
|
|
952
|
-
providedIn: 'root',
|
|
953
|
-
}]
|
|
1056
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: BarVerticalChartBuilder, decorators: [{
|
|
1057
|
+
type: Injectable
|
|
954
1058
|
}] });
|
|
955
1059
|
|
|
956
1060
|
class PcacBarVerticalChartComponent {
|
|
957
1061
|
chartBuilder = inject(BarVerticalChartBuilder);
|
|
958
|
-
config = input.required(
|
|
1062
|
+
config = input.required(/* @ts-ignore */
|
|
1063
|
+
...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
|
|
959
1064
|
chartElm = viewChild.required('chart');
|
|
960
|
-
barClicked =
|
|
961
|
-
resizeWindowTimeout;
|
|
1065
|
+
barClicked = outputFromObservable(this.chartBuilder.barClicked$);
|
|
962
1066
|
constructor() {
|
|
963
|
-
|
|
964
|
-
|
|
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
|
+
}
|
|
965
1078
|
});
|
|
966
1079
|
}
|
|
967
|
-
ngOnChanges() {
|
|
968
|
-
this.buildChart();
|
|
969
|
-
}
|
|
970
1080
|
buildChart() {
|
|
971
1081
|
const config = this.config();
|
|
972
1082
|
if (config && config.data && config.data.length > 0) {
|
|
973
1083
|
this.chartBuilder.buildChart(this.chartElm(), config);
|
|
974
1084
|
}
|
|
975
1085
|
}
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
*/
|
|
979
|
-
onResize() {
|
|
980
|
-
const self = this;
|
|
981
|
-
clearTimeout(this.resizeWindowTimeout);
|
|
982
|
-
this.resizeWindowTimeout = setTimeout(() => {
|
|
983
|
-
self.buildChart();
|
|
984
|
-
}, 300);
|
|
985
|
-
}
|
|
986
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.0", ngImport: i0, type: PcacBarVerticalChartComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
987
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "21.0.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: { listeners: { "window:resize": "onResize()" } }, viewQueries: [{ propertyName: "chartElm", first: true, predicate: ["chart"], descendants: true, isSignal: true }], usesOnChanges: 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 });
|
|
1086
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacBarVerticalChartComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
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 });
|
|
988
1088
|
}
|
|
989
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
1089
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacBarVerticalChartComponent, decorators: [{
|
|
990
1090
|
type: Component,
|
|
991
|
-
args: [{ selector: 'pcac-bar-vertical-chart', encapsulation: ViewEncapsulation.None, 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"] }]
|
|
992
|
-
}], 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"] }]
|
|
993
|
-
type: HostListener,
|
|
994
|
-
args: ['window:resize']
|
|
995
|
-
}] } });
|
|
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"] }] } });
|
|
996
1093
|
|
|
997
1094
|
class PcacBarVerticalChartConfig extends PcacChartConfig {
|
|
998
1095
|
domainMax = 100;
|
|
@@ -1020,30 +1117,43 @@ class PcacLegendConfig {
|
|
|
1020
1117
|
}
|
|
1021
1118
|
class PcacLegend {
|
|
1022
1119
|
colorService = inject(PcacColorService);
|
|
1023
|
-
config = model.required(
|
|
1120
|
+
config = model.required(/* @ts-ignore */
|
|
1121
|
+
...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
|
|
1024
1122
|
itemClicked = output();
|
|
1025
|
-
colorScale = computed(() => this.colorService.getColorScale(this.config().items.length),
|
|
1123
|
+
colorScale = computed(() => this.colorService.getColorScale(this.config().items.length), /* @ts-ignore */
|
|
1124
|
+
...(ngDevMode ? [{ debugName: "colorScale" }] : /* istanbul ignore next */ []));
|
|
1026
1125
|
onItemClicked(index) {
|
|
1027
|
-
const
|
|
1028
|
-
|
|
1029
|
-
this.
|
|
1030
|
-
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);
|
|
1031
1129
|
}
|
|
1032
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
1033
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "
|
|
1130
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacLegend, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
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"] });
|
|
1034
1132
|
}
|
|
1035
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
1133
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacLegend, decorators: [{
|
|
1036
1134
|
type: Component,
|
|
1037
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"] }]
|
|
1038
1136
|
}], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }, { type: i0.Output, args: ["configChange"] }], itemClicked: [{ type: i0.Output, args: ["itemClicked"] }] } });
|
|
1039
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
|
+
*/
|
|
1040
1145
|
class PlaChartEffectsBuilder {
|
|
1041
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.
|
|
1042
1152
|
lines = [];
|
|
1043
1153
|
buildEffects(config) {
|
|
1044
1154
|
this.config = config;
|
|
1045
1155
|
this.lines = [];
|
|
1046
|
-
this.config.svg.selectAll('.line').each((d, i, n) => {
|
|
1156
|
+
this.config.svg.selectAll('.line, .area').each((d, i, n) => {
|
|
1047
1157
|
this.lines.push(n[i]);
|
|
1048
1158
|
});
|
|
1049
1159
|
this.buildCollection();
|
|
@@ -1124,13 +1234,20 @@ class PlaChartEffectsBuilder {
|
|
|
1124
1234
|
updateEffects(mousePos) {
|
|
1125
1235
|
this.config.svg.selectAll('.effect-group')
|
|
1126
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
|
+
}
|
|
1127
1244
|
let beginning = 0;
|
|
1128
|
-
let end =
|
|
1245
|
+
let end = line.getTotalLength();
|
|
1129
1246
|
let target = 0;
|
|
1130
1247
|
let pos;
|
|
1131
1248
|
while (true) {
|
|
1132
1249
|
target = Math.floor((beginning + end) / 2);
|
|
1133
|
-
pos =
|
|
1250
|
+
pos = line.getPointAtLength(target);
|
|
1134
1251
|
if ((target === end || target === beginning) && pos.x !== mousePos[0]) {
|
|
1135
1252
|
break;
|
|
1136
1253
|
}
|
|
@@ -1150,14 +1267,11 @@ class PlaChartEffectsBuilder {
|
|
|
1150
1267
|
return 'translate(' + mousePos[0] + ',' + pos.y + ')';
|
|
1151
1268
|
});
|
|
1152
1269
|
}
|
|
1153
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
1154
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
1270
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PlaChartEffectsBuilder, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1271
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PlaChartEffectsBuilder });
|
|
1155
1272
|
}
|
|
1156
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
1157
|
-
type: Injectable
|
|
1158
|
-
args: [{
|
|
1159
|
-
providedIn: 'root',
|
|
1160
|
-
}]
|
|
1273
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PlaChartEffectsBuilder, decorators: [{
|
|
1274
|
+
type: Injectable
|
|
1161
1275
|
}] });
|
|
1162
1276
|
|
|
1163
1277
|
var PcacLineAreaPlotChartConfigType;
|
|
@@ -1273,7 +1387,14 @@ function buildZoomBehavior(width, height, zoomedFn) {
|
|
|
1273
1387
|
.on("zoom", zoomedFn);
|
|
1274
1388
|
}
|
|
1275
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
|
+
*/
|
|
1276
1396
|
class PlaChartBuilder extends PcacChart {
|
|
1397
|
+
effectsBuilder = inject(PlaChartEffectsBuilder);
|
|
1277
1398
|
scales;
|
|
1278
1399
|
lineGenerator;
|
|
1279
1400
|
areaGenerator;
|
|
@@ -1283,13 +1404,16 @@ class PlaChartBuilder extends PcacChart {
|
|
|
1283
1404
|
clipPathId; // <-- added
|
|
1284
1405
|
dotClicked$ = this.dotClickedSource.asObservable();
|
|
1285
1406
|
buildChart(chartElm, config, type) {
|
|
1407
|
+
if (!config?.data?.length) {
|
|
1408
|
+
return;
|
|
1409
|
+
}
|
|
1286
1410
|
this.config = JSON.parse(JSON.stringify(config));
|
|
1287
|
-
this.startData = range(this.config.data[0].data.length).map(() => {
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
});
|
|
1411
|
+
this.startData = range(this.config.data[0].data.length).map(() => ({
|
|
1412
|
+
key: '',
|
|
1413
|
+
value: 0,
|
|
1414
|
+
hide: false,
|
|
1415
|
+
data: []
|
|
1416
|
+
}));
|
|
1293
1417
|
if (this.config.hideAxis) {
|
|
1294
1418
|
this.config.height = this.config.height + 12;
|
|
1295
1419
|
this.margin.top = 8;
|
|
@@ -1297,7 +1421,9 @@ class PlaChartBuilder extends PcacChart {
|
|
|
1297
1421
|
this.margin.left = 8;
|
|
1298
1422
|
this.margin.right = 8;
|
|
1299
1423
|
}
|
|
1300
|
-
this.initializeChartState(chartElm, this.config)
|
|
1424
|
+
if (!this.initializeChartState(chartElm, this.config)) {
|
|
1425
|
+
return;
|
|
1426
|
+
}
|
|
1301
1427
|
if (this.config.colorOverride) {
|
|
1302
1428
|
this.colors = this.config.colorOverride;
|
|
1303
1429
|
}
|
|
@@ -1306,7 +1432,6 @@ class PlaChartBuilder extends PcacChart {
|
|
|
1306
1432
|
this.areaGenerator = buildAreaGenerator(config.xFormat, this.scales, this.height);
|
|
1307
1433
|
if (this.config.enableZoom) {
|
|
1308
1434
|
this.zoomBehavior = buildZoomBehavior(this.width, this.height, (event) => {
|
|
1309
|
-
console.log('Zoom Event', event);
|
|
1310
1435
|
// Rescale x
|
|
1311
1436
|
const newX = event.transform.rescaleX(this.scales.x);
|
|
1312
1437
|
// Update axis
|
|
@@ -1351,13 +1476,14 @@ class PlaChartBuilder extends PcacChart {
|
|
|
1351
1476
|
svg: this.svg,
|
|
1352
1477
|
numberOfTicks: config.numberOfTicks || 5,
|
|
1353
1478
|
width: this.width,
|
|
1479
|
+
height: this.height,
|
|
1354
1480
|
xScale: this.scales.x,
|
|
1355
1481
|
yScale: this.scales.y
|
|
1356
1482
|
});
|
|
1357
1483
|
}
|
|
1358
1484
|
this.drawLineArea(config, type);
|
|
1359
1485
|
if (config.enableEffects) {
|
|
1360
|
-
|
|
1486
|
+
this.effectsBuilder.buildEffects({
|
|
1361
1487
|
svg: this.svg,
|
|
1362
1488
|
height: this.height,
|
|
1363
1489
|
width: this.width,
|
|
@@ -1376,15 +1502,20 @@ class PlaChartBuilder extends PcacChart {
|
|
|
1376
1502
|
.append('clipPath')
|
|
1377
1503
|
.attr('id', this.clipPathId)
|
|
1378
1504
|
.append('rect')
|
|
1379
|
-
.attr('x',
|
|
1505
|
+
.attr('x', -10) // extend clip-path a bit left to avoid cutting off a dot at the x-domain's minimum
|
|
1380
1506
|
.attr('y', -10) // extend clip-path a bit above to avoid cutting off top of line
|
|
1381
|
-
.attr('width', this.width)
|
|
1507
|
+
.attr('width', this.width + 20) // +20 to also cover a dot at the x-domain's maximum
|
|
1382
1508
|
.attr('height', this.height + 20); // +20 to ensure dots at bottom are not clipped
|
|
1383
1509
|
}
|
|
1384
1510
|
attachZoomBehavior() {
|
|
1385
1511
|
if (!this.config.enableZoom)
|
|
1386
1512
|
return;
|
|
1387
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.
|
|
1388
1519
|
this.svg.insert('rect', ':first-child')
|
|
1389
1520
|
.attr('width', this.width)
|
|
1390
1521
|
.attr('height', this.height)
|
|
@@ -1417,7 +1548,7 @@ class PlaChartBuilder extends PcacChart {
|
|
|
1417
1548
|
.attr('d', this.lineGenerator(this.startData))
|
|
1418
1549
|
.transition()
|
|
1419
1550
|
.duration(this.transitionService.getTransitionDuration())
|
|
1420
|
-
.attr('d', this.lineGenerator)
|
|
1551
|
+
.attr('d', this.lineGenerator)
|
|
1421
1552
|
.attr('stroke', () => {
|
|
1422
1553
|
return this.colors[index];
|
|
1423
1554
|
})
|
|
@@ -1433,12 +1564,12 @@ class PlaChartBuilder extends PcacChart {
|
|
|
1433
1564
|
.attr('class', 'area')
|
|
1434
1565
|
.style('opacity', 0.5)
|
|
1435
1566
|
.style('fill', () => {
|
|
1436
|
-
return this.colors[index];
|
|
1567
|
+
return this.colors[index];
|
|
1437
1568
|
})
|
|
1438
|
-
.attr('d', this.
|
|
1569
|
+
.attr('d', this.areaGenerator(this.startData))
|
|
1439
1570
|
.transition()
|
|
1440
1571
|
.duration(this.transitionService.getTransitionDuration())
|
|
1441
|
-
.attr('d', this.areaGenerator);
|
|
1572
|
+
.attr('d', this.areaGenerator);
|
|
1442
1573
|
}
|
|
1443
1574
|
drawDots(config) {
|
|
1444
1575
|
const self = this;
|
|
@@ -1456,7 +1587,7 @@ class PlaChartBuilder extends PcacChart {
|
|
|
1456
1587
|
.attr('cx', (d, i) => {
|
|
1457
1588
|
return getXFormat(config.xFormat, d, i, this.scales.x);
|
|
1458
1589
|
})
|
|
1459
|
-
.attr('cy', (
|
|
1590
|
+
.attr('cy', (_) => {
|
|
1460
1591
|
return this.scales.y(0);
|
|
1461
1592
|
})
|
|
1462
1593
|
.attr('fill', '#fff')
|
|
@@ -1476,7 +1607,7 @@ class PlaChartBuilder extends PcacChart {
|
|
|
1476
1607
|
.attr('r', 4)
|
|
1477
1608
|
.attr('fill', '#fff');
|
|
1478
1609
|
})
|
|
1479
|
-
.on('click', (
|
|
1610
|
+
.on('click', (_event, d) => {
|
|
1480
1611
|
this.dotClickedSource.next(d);
|
|
1481
1612
|
})
|
|
1482
1613
|
.transition()
|
|
@@ -1488,105 +1619,96 @@ class PlaChartBuilder extends PcacChart {
|
|
|
1488
1619
|
.attr('style', () => config.data[index].hide ? 'display: none' : null);
|
|
1489
1620
|
}
|
|
1490
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 });
|
|
1491
1624
|
}
|
|
1625
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PlaChartBuilder, decorators: [{
|
|
1626
|
+
type: Injectable
|
|
1627
|
+
}] });
|
|
1492
1628
|
|
|
1493
1629
|
class PcacLineAreaChartComponent {
|
|
1494
|
-
chartBuilder =
|
|
1495
|
-
config = input.required(
|
|
1496
|
-
|
|
1630
|
+
chartBuilder = inject(PlaChartBuilder);
|
|
1631
|
+
config = input.required(/* @ts-ignore */
|
|
1632
|
+
...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
|
|
1633
|
+
type = input.required(/* @ts-ignore */
|
|
1634
|
+
...(ngDevMode ? [{ debugName: "type" }] : /* istanbul ignore next */ []));
|
|
1497
1635
|
chartElm = viewChild.required('chart');
|
|
1498
|
-
dotClicked =
|
|
1499
|
-
resizeWindowTimeout;
|
|
1636
|
+
dotClicked = outputFromObservable(this.chartBuilder.dotClicked$);
|
|
1500
1637
|
constructor() {
|
|
1501
|
-
|
|
1502
|
-
|
|
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
|
+
}
|
|
1503
1652
|
});
|
|
1504
1653
|
}
|
|
1505
|
-
ngOnChanges(changes) {
|
|
1506
|
-
if (changes['config'].currentValue !== changes['config'].previousValue) {
|
|
1507
|
-
this.buildChart();
|
|
1508
|
-
}
|
|
1509
|
-
}
|
|
1510
1654
|
buildChart() {
|
|
1511
1655
|
const config = this.config();
|
|
1512
1656
|
if (config && config.data && config.data.length > 0) {
|
|
1513
1657
|
this.chartBuilder.buildChart(this.chartElm(), config, this.type());
|
|
1514
1658
|
}
|
|
1515
1659
|
}
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
*/
|
|
1519
|
-
onResize() {
|
|
1520
|
-
const self = this;
|
|
1521
|
-
clearTimeout(this.resizeWindowTimeout);
|
|
1522
|
-
this.resizeWindowTimeout = setTimeout(() => {
|
|
1523
|
-
self.buildChart();
|
|
1524
|
-
}, 300);
|
|
1525
|
-
}
|
|
1526
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.0", ngImport: i0, type: PcacLineAreaChartComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1527
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "21.0.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 } }, outputs: { dotClicked: "dotClicked" }, host: { listeners: { "window:resize": "onResize()" } }, viewQueries: [{ propertyName: "chartElm", first: true, predicate: ["chart"], descendants: true, isSignal: true }], usesOnChanges: 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 });
|
|
1660
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacLineAreaChartComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
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 });
|
|
1528
1662
|
}
|
|
1529
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
1663
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacLineAreaChartComponent, decorators: [{
|
|
1530
1664
|
type: Component,
|
|
1531
|
-
args: [{ selector: 'pcac-line-area-chart', encapsulation: ViewEncapsulation.None, 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"] }]
|
|
1532
|
-
}], 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"] }]
|
|
1533
|
-
type: HostListener,
|
|
1534
|
-
args: ['window:resize']
|
|
1535
|
-
}] } });
|
|
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"] }] } });
|
|
1536
1667
|
|
|
1537
1668
|
class PcacPlotChart {
|
|
1538
|
-
config = input.required(
|
|
1669
|
+
config = input.required(/* @ts-ignore */
|
|
1670
|
+
...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
|
|
1539
1671
|
types = PcacLineAreaPlotChartConfigType;
|
|
1540
1672
|
dotClicked = output();
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
this.chart()?.onResize();
|
|
1544
|
-
}
|
|
1545
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.0", ngImport: i0, type: PcacPlotChart, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1546
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "21.0.0", type: PcacPlotChart, isStandalone: true, selector: "pcac-plot-chart", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { dotClicked: "dotClicked" }, viewQueries: [{ propertyName: "chart", first: true, predicate: PcacLineAreaChartComponent, descendants: true, isSignal: true }], 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"] }] });
|
|
1673
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacPlotChart, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
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"] }] });
|
|
1547
1675
|
}
|
|
1548
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
1676
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacPlotChart, decorators: [{
|
|
1549
1677
|
type: Component,
|
|
1550
1678
|
args: [{ selector: 'pcac-plot-chart', imports: [PcacLineAreaChartComponent], template: "<pcac-line-area-chart [config]=\"config()\" [type]=\"types.Plot\" (dotClicked)=\"dotClicked.emit($event)\"/>" }]
|
|
1551
|
-
}], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }], dotClicked: [{ type: i0.Output, args: ["dotClicked"] }]
|
|
1679
|
+
}], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }], dotClicked: [{ type: i0.Output, args: ["dotClicked"] }] } });
|
|
1552
1680
|
|
|
1553
1681
|
class PcacPlotChartConfig extends PcacLineAreaChartConfig {
|
|
1554
1682
|
}
|
|
1555
1683
|
|
|
1556
1684
|
class PcacLineChart {
|
|
1557
|
-
config = input.required(
|
|
1685
|
+
config = input.required(/* @ts-ignore */
|
|
1686
|
+
...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
|
|
1558
1687
|
types = PcacLineAreaPlotChartConfigType;
|
|
1559
1688
|
dotClicked = output();
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
this.chart()?.onResize();
|
|
1563
|
-
}
|
|
1564
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.0", ngImport: i0, type: PcacLineChart, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1565
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "21.0.0", type: PcacLineChart, isStandalone: true, selector: "pcac-line-chart", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { dotClicked: "dotClicked" }, viewQueries: [{ propertyName: "chart", first: true, predicate: PcacLineAreaChartComponent, descendants: true, isSignal: true }], 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"] }] });
|
|
1689
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacLineChart, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
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"] }] });
|
|
1566
1691
|
}
|
|
1567
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
1692
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacLineChart, decorators: [{
|
|
1568
1693
|
type: Component,
|
|
1569
1694
|
args: [{ selector: 'pcac-line-chart', imports: [PcacLineAreaChartComponent], template: "<pcac-line-area-chart [config]=\"config()\" [type]=\"types.Line\" />" }]
|
|
1570
|
-
}], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }], dotClicked: [{ type: i0.Output, args: ["dotClicked"] }]
|
|
1695
|
+
}], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }], dotClicked: [{ type: i0.Output, args: ["dotClicked"] }] } });
|
|
1571
1696
|
|
|
1572
1697
|
class PcacLineChartConfig extends PcacLineAreaChartConfig {
|
|
1573
1698
|
}
|
|
1574
1699
|
|
|
1575
1700
|
class PcacAreaChart {
|
|
1576
|
-
config = input.required(
|
|
1701
|
+
config = input.required(/* @ts-ignore */
|
|
1702
|
+
...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
|
|
1577
1703
|
types = PcacLineAreaPlotChartConfigType;
|
|
1578
1704
|
dotClicked = output();
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
this.chart()?.onResize();
|
|
1582
|
-
}
|
|
1583
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.0", ngImport: i0, type: PcacAreaChart, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1584
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "21.0.0", type: PcacAreaChart, isStandalone: true, selector: "pcac-area-chart", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { dotClicked: "dotClicked" }, viewQueries: [{ propertyName: "chart", first: true, predicate: PcacLineAreaChartComponent, descendants: true, isSignal: true }], 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"] }] });
|
|
1705
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacAreaChart, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
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"] }] });
|
|
1585
1707
|
}
|
|
1586
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
1708
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacAreaChart, decorators: [{
|
|
1587
1709
|
type: Component,
|
|
1588
1710
|
args: [{ selector: 'pcac-area-chart', imports: [PcacLineAreaChartComponent], template: "<pcac-line-area-chart [config]=\"config()\" [type]=\"types.Area\" />" }]
|
|
1589
|
-
}], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }], dotClicked: [{ type: i0.Output, args: ["dotClicked"] }]
|
|
1711
|
+
}], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }], dotClicked: [{ type: i0.Output, args: ["dotClicked"] }] } });
|
|
1590
1712
|
|
|
1591
1713
|
class PcacAreaChartConfig extends PcacLineAreaChartConfig {
|
|
1592
1714
|
}
|
|
@@ -1595,6 +1717,12 @@ class PcacAreaChartConfig extends PcacLineAreaChartConfig {
|
|
|
1595
1717
|
// export * from './plot-line-area-chart.component';
|
|
1596
1718
|
// export * from './plot-line-area-chart.model';
|
|
1597
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
|
+
*/
|
|
1598
1726
|
class PieChartBuilder extends PcacChart {
|
|
1599
1727
|
radius;
|
|
1600
1728
|
arcShape;
|
|
@@ -1603,7 +1731,12 @@ class PieChartBuilder extends PcacChart {
|
|
|
1603
1731
|
sliceClickedSource = new Subject();
|
|
1604
1732
|
sliceClicked$ = this.sliceClickedSource.asObservable();
|
|
1605
1733
|
buildChart(chartElm, config) {
|
|
1606
|
-
|
|
1734
|
+
if (!config?.data?.length) {
|
|
1735
|
+
return;
|
|
1736
|
+
}
|
|
1737
|
+
if (!this.initializeChartState(chartElm, config)) {
|
|
1738
|
+
return;
|
|
1739
|
+
}
|
|
1607
1740
|
this.radius = Math.min(Math.min(this.height, this.width), Math.min(this.height, this.width)) / 2;
|
|
1608
1741
|
this.buildShapes(config);
|
|
1609
1742
|
this.drawChart(chartElm, config);
|
|
@@ -1618,7 +1751,7 @@ class PieChartBuilder extends PcacChart {
|
|
|
1618
1751
|
.outerRadius(this.radius - radiusOffset + radiusOffset);
|
|
1619
1752
|
this.pieAngles = pie()
|
|
1620
1753
|
.sort(null)
|
|
1621
|
-
.value((d) => d.value);
|
|
1754
|
+
.value((d) => d.value);
|
|
1622
1755
|
}
|
|
1623
1756
|
drawChart(chartElm, config) {
|
|
1624
1757
|
this.buildContainer(chartElm, true);
|
|
@@ -1650,7 +1783,7 @@ class PieChartBuilder extends PcacChart {
|
|
|
1650
1783
|
.attr('d', self.arcShape)
|
|
1651
1784
|
.style('fill', self.colors[d.index]);
|
|
1652
1785
|
})
|
|
1653
|
-
.on('click', (
|
|
1786
|
+
.on('click', (_event, d) => {
|
|
1654
1787
|
this.sliceClickedSource.next(d.data);
|
|
1655
1788
|
})
|
|
1656
1789
|
.transition()
|
|
@@ -1660,60 +1793,52 @@ class PieChartBuilder extends PcacChart {
|
|
|
1660
1793
|
});
|
|
1661
1794
|
}
|
|
1662
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.
|
|
1663
1798
|
b.innerRadius = 0;
|
|
1664
1799
|
const i = interpolate({ startAngle: 0, endAngle: 0 }, b);
|
|
1665
|
-
return (t) => this.arcShape(i(t))
|
|
1800
|
+
return (t) => this.arcShape(i(t)) ?? '';
|
|
1666
1801
|
}
|
|
1667
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
1668
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
1802
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PieChartBuilder, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
|
1803
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PieChartBuilder });
|
|
1669
1804
|
}
|
|
1670
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
1671
|
-
type: Injectable
|
|
1672
|
-
args: [{
|
|
1673
|
-
providedIn: 'root',
|
|
1674
|
-
}]
|
|
1805
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PieChartBuilder, decorators: [{
|
|
1806
|
+
type: Injectable
|
|
1675
1807
|
}] });
|
|
1676
1808
|
|
|
1677
1809
|
class PcacPieChartComponent {
|
|
1678
1810
|
chartBuilder = inject(PieChartBuilder);
|
|
1679
|
-
config = input.required(
|
|
1811
|
+
config = input.required(/* @ts-ignore */
|
|
1812
|
+
...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
|
|
1680
1813
|
chartElm = viewChild.required('chart');
|
|
1681
|
-
sliceClicked =
|
|
1682
|
-
resizeWindowTimeout;
|
|
1814
|
+
sliceClicked = outputFromObservable(this.chartBuilder.sliceClicked$);
|
|
1683
1815
|
constructor() {
|
|
1684
|
-
|
|
1685
|
-
|
|
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
|
+
}
|
|
1686
1827
|
});
|
|
1687
1828
|
}
|
|
1688
|
-
ngOnChanges() {
|
|
1689
|
-
this.buildChart();
|
|
1690
|
-
}
|
|
1691
1829
|
buildChart() {
|
|
1692
1830
|
const config = this.config();
|
|
1693
1831
|
if (config && config.data && config.data.length > 0) {
|
|
1694
1832
|
this.chartBuilder.buildChart(this.chartElm(), config);
|
|
1695
1833
|
}
|
|
1696
1834
|
}
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
*/
|
|
1700
|
-
onResize() {
|
|
1701
|
-
const self = this;
|
|
1702
|
-
clearTimeout(this.resizeWindowTimeout);
|
|
1703
|
-
this.resizeWindowTimeout = setTimeout(() => {
|
|
1704
|
-
self.buildChart();
|
|
1705
|
-
}, 300);
|
|
1706
|
-
}
|
|
1707
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.0", ngImport: i0, type: PcacPieChartComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1708
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "21.0.0", type: PcacPieChartComponent, isStandalone: true, selector: "pcac-pie-chart", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { sliceClicked: "sliceClicked" }, host: { listeners: { "window:resize": "onResize()" } }, viewQueries: [{ propertyName: "chartElm", first: true, predicate: ["chart"], descendants: true, isSignal: true }], usesOnChanges: 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 });
|
|
1835
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacPieChartComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
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 });
|
|
1709
1837
|
}
|
|
1710
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
1838
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: PcacPieChartComponent, decorators: [{
|
|
1711
1839
|
type: Component,
|
|
1712
|
-
args: [{ selector: 'pcac-pie-chart', encapsulation: ViewEncapsulation.None, 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"] }]
|
|
1713
|
-
}], 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"] }]
|
|
1714
|
-
type: HostListener,
|
|
1715
|
-
args: ['window:resize']
|
|
1716
|
-
}] } });
|
|
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"] }] } });
|
|
1717
1842
|
|
|
1718
1843
|
class PcacPieChartConfig extends PcacChartConfig {
|
|
1719
1844
|
numberOfTicks = 5;
|
|
@@ -1727,5 +1852,5 @@ class PcacPieChartConfig extends PcacChartConfig {
|
|
|
1727
1852
|
* Generated bundle index. Do not edit.
|
|
1728
1853
|
*/
|
|
1729
1854
|
|
|
1730
|
-
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 };
|
|
1731
1856
|
//# sourceMappingURL=pioneer-code-pioneer-charts.mjs.map
|