@pioneer-code/pioneer-charts 20.0.3 → 20.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/fesm2022/pioneer-code-pioneer-charts.mjs +834 -803
- package/fesm2022/pioneer-code-pioneer-charts.mjs.map +1 -1
- package/index.d.ts +126 -117
- package/package.json +1 -1
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { axisLeft, axisBottom } from 'd3-axis';
|
|
2
1
|
import * as i0 from '@angular/core';
|
|
3
2
|
import { Injectable, inject, input, viewChild, output, HostListener, ViewEncapsulation, Component } from '@angular/core';
|
|
3
|
+
import { color } from 'd3-color';
|
|
4
|
+
import { scaleLinear, scaleBand } from 'd3-scale';
|
|
4
5
|
import { select as select$1 } from 'd3-selection';
|
|
6
|
+
import { Subject } from 'rxjs';
|
|
7
|
+
import { axisLeft, axisBottom } from 'd3-axis';
|
|
5
8
|
import { select, scaleTime } from 'd3';
|
|
6
|
-
import { transition } from 'd3-transition';
|
|
7
|
-
import { scaleLinear, scaleBand } from 'd3-scale';
|
|
8
9
|
import { line, area, arc, pie } from 'd3-shape';
|
|
9
10
|
import { range } from 'd3-array';
|
|
10
|
-
import { Subject } from 'rxjs';
|
|
11
11
|
import { interpolate } from 'd3-interpolate';
|
|
12
|
-
import {
|
|
12
|
+
import { transition } from 'd3-transition';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Base configuration for all charts.
|
|
@@ -19,8 +19,8 @@ class PcacChartConfig {
|
|
|
19
19
|
/**
|
|
20
20
|
* Height in pixels
|
|
21
21
|
*/
|
|
22
|
-
height = 200;
|
|
23
22
|
data = [];
|
|
23
|
+
height = 200;
|
|
24
24
|
}
|
|
25
25
|
class PcacData {
|
|
26
26
|
key = null;
|
|
@@ -35,6 +35,12 @@ var PcacFormatEnum;
|
|
|
35
35
|
PcacFormatEnum["Minutes"] = "minutes";
|
|
36
36
|
PcacFormatEnum["DateTime"] = "dateTime";
|
|
37
37
|
PcacFormatEnum["Fahrenheit"] = "fahrenheit";
|
|
38
|
+
/**
|
|
39
|
+
* Expectation is we will be given a range of data from 0-23
|
|
40
|
+
* and we will map that to a 12 hour clock with am/pm
|
|
41
|
+
* e.g. 0 = 12am, 1 = 1am, 13 = 1pm, 23 = 11pm
|
|
42
|
+
*/
|
|
43
|
+
PcacFormatEnum["OneDayHours"] = "oneDayHours";
|
|
38
44
|
})(PcacFormatEnum || (PcacFormatEnum = {}));
|
|
39
45
|
|
|
40
46
|
class PcacAxisBuilder {
|
|
@@ -78,6 +84,12 @@ class PcacAxisBuilder {
|
|
|
78
84
|
case PcacFormatEnum.Fahrenheit:
|
|
79
85
|
xAxis.tickFormat((d) => d + 'f');
|
|
80
86
|
break;
|
|
87
|
+
case PcacFormatEnum.OneDayHours:
|
|
88
|
+
xAxis.tickFormat((d, i) => {
|
|
89
|
+
const hour = i % 12 === 0 ? 12 : i % 12;
|
|
90
|
+
const period = i < 12 ? 'am' : 'pm';
|
|
91
|
+
return `${hour}${period}`;
|
|
92
|
+
});
|
|
81
93
|
}
|
|
82
94
|
}
|
|
83
95
|
config.svg.append('g')
|
|
@@ -85,10 +97,10 @@ class PcacAxisBuilder {
|
|
|
85
97
|
.attr('transform', 'translate(0,' + config.height + ')')
|
|
86
98
|
.call(xAxis);
|
|
87
99
|
}
|
|
88
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.
|
|
89
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.
|
|
100
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: PcacAxisBuilder, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
101
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: PcacAxisBuilder, providedIn: 'root' });
|
|
90
102
|
}
|
|
91
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.
|
|
103
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: PcacAxisBuilder, decorators: [{
|
|
92
104
|
type: Injectable,
|
|
93
105
|
args: [{
|
|
94
106
|
providedIn: 'root',
|
|
@@ -123,10 +135,10 @@ class PcacGridBuilder {
|
|
|
123
135
|
.attr('x2', config.width)
|
|
124
136
|
.attr('class', (_, i) => (i === 0 ? 'pcac-grid-rule-last' : ''));
|
|
125
137
|
}
|
|
126
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.
|
|
127
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.
|
|
138
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: PcacGridBuilder, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
139
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: PcacGridBuilder, providedIn: 'root' });
|
|
128
140
|
}
|
|
129
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.
|
|
141
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: PcacGridBuilder, decorators: [{
|
|
130
142
|
type: Injectable,
|
|
131
143
|
args: [{
|
|
132
144
|
providedIn: 'root',
|
|
@@ -193,10 +205,10 @@ class PcacColorService {
|
|
|
193
205
|
setAlert() {
|
|
194
206
|
return this.alert;
|
|
195
207
|
}
|
|
196
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.
|
|
197
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.
|
|
208
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: PcacColorService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
209
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: PcacColorService, providedIn: 'root' });
|
|
198
210
|
}
|
|
199
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.
|
|
211
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: PcacColorService, decorators: [{
|
|
200
212
|
type: Injectable,
|
|
201
213
|
args: [{
|
|
202
214
|
providedIn: 'root',
|
|
@@ -208,10 +220,10 @@ class PcacTransitionService {
|
|
|
208
220
|
getTransitionDuration() {
|
|
209
221
|
return this.transitionDuration;
|
|
210
222
|
}
|
|
211
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.
|
|
212
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.
|
|
223
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: PcacTransitionService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
224
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: PcacTransitionService, providedIn: 'root' });
|
|
213
225
|
}
|
|
214
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.
|
|
226
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: PcacTransitionService, decorators: [{
|
|
215
227
|
type: Injectable,
|
|
216
228
|
args: [{
|
|
217
229
|
providedIn: 'root',
|
|
@@ -261,10 +273,10 @@ class PcacTooltipBuilder {
|
|
|
261
273
|
let finalValue = value ? value.toString() : null;
|
|
262
274
|
return key ? key + '</br>' + finalValue : finalValue;
|
|
263
275
|
}
|
|
264
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.
|
|
265
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.
|
|
276
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: PcacTooltipBuilder, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
277
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: PcacTooltipBuilder, providedIn: 'root' });
|
|
266
278
|
}
|
|
267
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.
|
|
279
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: PcacTooltipBuilder, decorators: [{
|
|
268
280
|
type: Injectable,
|
|
269
281
|
args: [{
|
|
270
282
|
providedIn: 'root',
|
|
@@ -341,365 +353,292 @@ class PcacChart {
|
|
|
341
353
|
this.margin.bottom = this.margin.bottom;
|
|
342
354
|
this.width = this.width - this.margin.left;
|
|
343
355
|
}
|
|
344
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.
|
|
345
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.
|
|
346
|
-
}
|
|
347
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.7", ngImport: i0, type: PcacChart, decorators: [{
|
|
348
|
-
type: Injectable,
|
|
349
|
-
args: [{
|
|
350
|
-
providedIn: 'root',
|
|
351
|
-
}]
|
|
352
|
-
}] });
|
|
353
|
-
|
|
354
|
-
class LineAreaChartEffectsBuilder {
|
|
355
|
-
config;
|
|
356
|
-
lines = [];
|
|
357
|
-
buildEffects(config) {
|
|
358
|
-
this.config = config;
|
|
359
|
-
this.lines = [];
|
|
360
|
-
this.config.svg.selectAll('.line').each((d, i, n) => {
|
|
361
|
-
this.lines.push(n[i]);
|
|
362
|
-
});
|
|
363
|
-
this.buildCollection();
|
|
364
|
-
this.buildCanvas();
|
|
365
|
-
}
|
|
366
|
-
buildCollection() {
|
|
367
|
-
const collection = this.config.svg.append('g')
|
|
368
|
-
.attr('class', 'effects');
|
|
369
|
-
collection.append('path')
|
|
370
|
-
.attr('class', 'effect-line');
|
|
371
|
-
const mousePerLine = collection.selectAll('.effect-group')
|
|
372
|
-
.data(this.config.data.filter((elm) => {
|
|
373
|
-
return elm.data.length > 0;
|
|
374
|
-
}))
|
|
375
|
-
.enter().append('g')
|
|
376
|
-
.attr('class', 'effect-group')
|
|
377
|
-
.attr('style', (d) => d.hide ? 'display: none' : null);
|
|
378
|
-
mousePerLine.append('circle')
|
|
379
|
-
.attr('r', 7)
|
|
380
|
-
.attr('class', 'effect-circle')
|
|
381
|
-
.style('stroke', (d, i) => {
|
|
382
|
-
return this.config.colors[i];
|
|
383
|
-
});
|
|
384
|
-
mousePerLine.append('text')
|
|
385
|
-
.attr('class', 'effect-text')
|
|
386
|
-
.attr('y', 1.5)
|
|
387
|
-
.attr('transform', 'translate(10,3)');
|
|
388
|
-
}
|
|
389
|
-
buildCanvas() {
|
|
390
|
-
this.config.svg.append('rect')
|
|
391
|
-
.attr('class', 'effects-canvas')
|
|
392
|
-
.attr('width', this.config.width)
|
|
393
|
-
.attr('height', this.config.height)
|
|
394
|
-
.attr('pointer-events', 'all')
|
|
395
|
-
.on('mouseout', () => {
|
|
396
|
-
this.hideEffects();
|
|
397
|
-
})
|
|
398
|
-
.on('mouseover', () => {
|
|
399
|
-
this.showEffects();
|
|
400
|
-
})
|
|
401
|
-
.on('mousemove', (event) => {
|
|
402
|
-
const current = event.currentTarget;
|
|
403
|
-
const parent = current.parentElement;
|
|
404
|
-
const xForms = parent?.getAttribute('transform');
|
|
405
|
-
if (!xForms)
|
|
406
|
-
return this.onMouseMove([event.offsetX, event.offsetY]);
|
|
407
|
-
const parts = /translate\(\s*([^\s,)]+)[ ,]([^\s,)]+)/.exec(xForms);
|
|
408
|
-
if (!parts)
|
|
409
|
-
return this.onMouseMove([event.offsetX, event.offsetY]);
|
|
410
|
-
const x = Number(parts[1]);
|
|
411
|
-
this.onMouseMove([event.offsetX - x, event.offsetY]);
|
|
412
|
-
});
|
|
413
|
-
}
|
|
414
|
-
showEffects() {
|
|
415
|
-
this.config.svg.select('.effect-line')
|
|
416
|
-
.style('opacity', '1');
|
|
417
|
-
this.config.svg.selectAll('.effect-group circle')
|
|
418
|
-
.style('opacity', '1');
|
|
419
|
-
this.config.svg.selectAll('.effect-group text')
|
|
420
|
-
.style('opacity', '1');
|
|
421
|
-
}
|
|
422
|
-
hideEffects() {
|
|
423
|
-
this.config.svg.select('.effect-line')
|
|
424
|
-
.style('opacity', '0');
|
|
425
|
-
this.config.svg.selectAll('.effect-group circle')
|
|
426
|
-
.style('opacity', '0');
|
|
427
|
-
this.config.svg.selectAll('.effect-group text')
|
|
428
|
-
.style('opacity', '0');
|
|
429
|
-
}
|
|
430
|
-
onMouseMove(mousePos) {
|
|
431
|
-
this.updateLine(mousePos);
|
|
432
|
-
this.updateEffects(mousePos);
|
|
433
|
-
}
|
|
434
|
-
updateLine(mousePos) {
|
|
435
|
-
this.config.svg.select('.effect-line')
|
|
436
|
-
.attr('d', () => 'M' + mousePos[0] + ',' + this.config.height + ' ' + mousePos[0] + ',' + 0);
|
|
437
|
-
}
|
|
438
|
-
updateEffects(mousePos) {
|
|
439
|
-
this.config.svg.selectAll('.effect-group')
|
|
440
|
-
.attr('transform', (data, index, nodes) => {
|
|
441
|
-
let beginning = 0;
|
|
442
|
-
let end = this.lines[index].getTotalLength();
|
|
443
|
-
let target = 0;
|
|
444
|
-
let pos;
|
|
445
|
-
while (true) {
|
|
446
|
-
target = Math.floor((beginning + end) / 2);
|
|
447
|
-
pos = this.lines[index].getPointAtLength(target);
|
|
448
|
-
if ((target === end || target === beginning) && pos.x !== mousePos[0]) {
|
|
449
|
-
break;
|
|
450
|
-
}
|
|
451
|
-
if (pos.x > mousePos[0]) {
|
|
452
|
-
end = target;
|
|
453
|
-
}
|
|
454
|
-
else if (pos.x < mousePos[0]) {
|
|
455
|
-
beginning = target;
|
|
456
|
-
}
|
|
457
|
-
else {
|
|
458
|
-
break;
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
let textTarget = this.config.y.invert(pos.y);
|
|
462
|
-
select$1(nodes[index]).select('text')
|
|
463
|
-
.text(textTarget.toFixed(0));
|
|
464
|
-
return 'translate(' + mousePos[0] + ',' + pos.y + ')';
|
|
465
|
-
});
|
|
466
|
-
}
|
|
467
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.7", ngImport: i0, type: LineAreaChartEffectsBuilder, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
468
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.1.7", ngImport: i0, type: LineAreaChartEffectsBuilder, providedIn: 'root' });
|
|
356
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: PcacChart, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
357
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: PcacChart, providedIn: 'root' });
|
|
469
358
|
}
|
|
470
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.
|
|
359
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: PcacChart, decorators: [{
|
|
471
360
|
type: Injectable,
|
|
472
361
|
args: [{
|
|
473
362
|
providedIn: 'root',
|
|
474
363
|
}]
|
|
475
364
|
}] });
|
|
476
365
|
|
|
477
|
-
class
|
|
478
|
-
line;
|
|
479
|
-
area;
|
|
366
|
+
class BarHorizontalChartBuilder extends PcacChart {
|
|
480
367
|
xScale;
|
|
481
|
-
|
|
482
|
-
|
|
368
|
+
yScaleStacked;
|
|
369
|
+
yScaleGrouped;
|
|
370
|
+
barClickedSource = new Subject();
|
|
483
371
|
config;
|
|
484
|
-
|
|
372
|
+
cachedMargins;
|
|
373
|
+
barClicked$ = this.barClickedSource.asObservable();
|
|
485
374
|
buildChart(chartElm, config) {
|
|
486
375
|
this.config = JSON.parse(JSON.stringify(config));
|
|
487
|
-
this.startData = range(this.config.data[0].data.length).map((d) => {
|
|
488
|
-
return {
|
|
489
|
-
value: 0,
|
|
490
|
-
key: ''
|
|
491
|
-
};
|
|
492
|
-
});
|
|
493
376
|
if (this.config.hideAxis) {
|
|
494
377
|
this.adjustForHiddenAxis();
|
|
495
378
|
}
|
|
496
379
|
this.initializeChartState(chartElm, this.config);
|
|
497
|
-
|
|
380
|
+
if (this.width <= 0) {
|
|
381
|
+
return; // TODO: Figure out why this is happening on initial load sometimes
|
|
382
|
+
}
|
|
383
|
+
if (config.colorOverride && config.colorOverride.colors) {
|
|
384
|
+
this.colors = config.colorOverride.colors.reverse();
|
|
385
|
+
}
|
|
386
|
+
this.buildScales(chartElm, this.config);
|
|
498
387
|
this.drawChart(chartElm, this.config);
|
|
499
388
|
}
|
|
500
389
|
adjustForHiddenAxis() {
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
this.margin
|
|
505
|
-
this.
|
|
390
|
+
if (!this.cachedMargins) {
|
|
391
|
+
this.cachedMargins = JSON.parse(JSON.stringify(this.margin));
|
|
392
|
+
}
|
|
393
|
+
this.margin = JSON.parse(JSON.stringify(this.cachedMargins));
|
|
394
|
+
this.config.height = this.config.height + this.margin.top + this.margin.bottom;
|
|
395
|
+
this.margin.top = 0;
|
|
396
|
+
this.margin.bottom = 0;
|
|
397
|
+
this.margin.left = 0;
|
|
398
|
+
this.margin.right = 0;
|
|
506
399
|
}
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
break;
|
|
514
|
-
default:
|
|
515
|
-
this.xScale = scaleLinear()
|
|
516
|
-
.domain([0, config.data[0].data.length - 1])
|
|
517
|
-
.range([0, this.width]);
|
|
400
|
+
setStartState(data) {
|
|
401
|
+
if (data && data.data) {
|
|
402
|
+
for (let i = 0, l = data.data.length; i < l; ++i) {
|
|
403
|
+
data.data[i].value = 0;
|
|
404
|
+
this.setStartState(data.data[i]);
|
|
405
|
+
}
|
|
518
406
|
}
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
.x((d, i) => {
|
|
524
|
-
return this.getXFormat(config.xFormat, d, i);
|
|
525
|
-
})
|
|
526
|
-
.y((d) => {
|
|
527
|
-
return this.yScale(d.value);
|
|
528
|
-
});
|
|
529
|
-
this.area = area()
|
|
530
|
-
.x((d, i) => {
|
|
531
|
-
return this.getXFormat(config.xFormat, d, i);
|
|
532
|
-
})
|
|
533
|
-
.y0(this.height)
|
|
534
|
-
.y1((d) => {
|
|
535
|
-
return this.yScale(d.value);
|
|
407
|
+
}
|
|
408
|
+
buildScales(chartElm, config) {
|
|
409
|
+
config.data[0].data.map((d) => {
|
|
410
|
+
return d.value;
|
|
536
411
|
});
|
|
412
|
+
this.xScale = scaleLinear()
|
|
413
|
+
.domain([0, config.domainMax]);
|
|
414
|
+
this.yScaleStacked = scaleBand()
|
|
415
|
+
.domain(config.data.map((d) => d.key))
|
|
416
|
+
.range([this.height, 0])
|
|
417
|
+
.padding(0.1);
|
|
418
|
+
this.yScaleGrouped = scaleBand()
|
|
419
|
+
.padding(0.05)
|
|
420
|
+
.rangeRound([0, this.yScaleStacked.bandwidth()])
|
|
421
|
+
.domain(config.data[0].data.map((d) => d.key));
|
|
422
|
+
this.setHorizontalMarginsBasedOnContent(chartElm, config.data, this.yScaleStacked);
|
|
423
|
+
this.xScale.range([0, this.width]);
|
|
537
424
|
}
|
|
538
425
|
drawChart(chartElm, config) {
|
|
539
426
|
this.buildContainer(chartElm);
|
|
540
|
-
|
|
541
|
-
this.
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
}
|
|
427
|
+
this.axisBuilder.drawAxis({
|
|
428
|
+
svg: this.svg,
|
|
429
|
+
numberOfTicks: config.numberOfTicks || 5,
|
|
430
|
+
height: this.height,
|
|
431
|
+
xScale: this.xScale,
|
|
432
|
+
yScale: this.yScaleStacked,
|
|
433
|
+
xFormat: config.tickFormat || PcacFormatEnum.None,
|
|
434
|
+
yFormat: PcacFormatEnum.None,
|
|
435
|
+
hideXAxis: config.hideAxis
|
|
436
|
+
});
|
|
550
437
|
if (!config.hideGrid) {
|
|
551
|
-
this.gridBuilder.
|
|
438
|
+
this.gridBuilder.drawVerticalGrid({
|
|
552
439
|
svg: this.svg,
|
|
553
440
|
numberOfTicks: config.numberOfTicks || 5,
|
|
554
|
-
|
|
441
|
+
height: this.height,
|
|
555
442
|
xScale: this.xScale,
|
|
556
|
-
yScale: this.
|
|
443
|
+
yScale: this.yScaleStacked
|
|
557
444
|
});
|
|
558
445
|
}
|
|
559
|
-
this.
|
|
560
|
-
if (config.enableEffects) {
|
|
561
|
-
this.drawEffects(config);
|
|
562
|
-
}
|
|
563
|
-
this.drawDots(config);
|
|
446
|
+
this.addGroups(config);
|
|
564
447
|
}
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
448
|
+
addGroups(config) {
|
|
449
|
+
const groupsContainer = this.svg.append('g')
|
|
450
|
+
.attr('class', 'pcac-bars')
|
|
451
|
+
.selectAll('g')
|
|
452
|
+
.data(config.data)
|
|
453
|
+
.enter().append('g')
|
|
454
|
+
.attr('class', 'pcac-bar-group')
|
|
455
|
+
.attr('data-group-id', (d, i) => {
|
|
456
|
+
return i;
|
|
457
|
+
})
|
|
458
|
+
.attr('transform', (d) => 'translate(0,' + this.yScaleStacked(d.key) + ')');
|
|
459
|
+
const group = groupsContainer.selectAll('rect')
|
|
460
|
+
.data((d) => {
|
|
461
|
+
return d.data;
|
|
462
|
+
});
|
|
463
|
+
this.drawBarsPerGroup(group, config);
|
|
464
|
+
// We have no thresholds to draw
|
|
465
|
+
if (!config.thresholds) {
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
// Draw threshold across entire chart
|
|
469
|
+
if (config.thresholds.length === 1 && !config.thresholds[0].data) {
|
|
470
|
+
this.drawThresholdAcrossChart(config);
|
|
471
|
+
}
|
|
472
|
+
// Draw threshold across each group
|
|
473
|
+
if (config.thresholds.length > 1 && (!config.thresholds[0].data || config.isStacked)) {
|
|
474
|
+
this.drawThresholdsPerGroup(group, config);
|
|
475
|
+
}
|
|
476
|
+
// Draw threshold across each bar in group
|
|
477
|
+
if (config.thresholds.length > 1 && config.thresholds[0].data && !config.isStacked) {
|
|
478
|
+
this.drawThresholdsPerBarInGroup(group, config);
|
|
571
479
|
}
|
|
572
480
|
}
|
|
573
|
-
|
|
574
|
-
this
|
|
575
|
-
|
|
576
|
-
.
|
|
577
|
-
.
|
|
578
|
-
.attr('
|
|
579
|
-
.
|
|
580
|
-
|
|
581
|
-
.duration(this.transitionService.getTransitionDuration()))
|
|
582
|
-
.attr('d', this.line) // TODO: strongly type
|
|
583
|
-
.attr('stroke', () => {
|
|
584
|
-
return this.colors[index];
|
|
481
|
+
drawBarsPerGroup(groups, config) {
|
|
482
|
+
const self = this;
|
|
483
|
+
groups.enter().append('rect')
|
|
484
|
+
.attr('class', 'pcac-bar')
|
|
485
|
+
.attr('x', 0)
|
|
486
|
+
.attr('y', (d) => {
|
|
487
|
+
let value = !config.isStacked ? this.yScaleGrouped(d.key) : this.yScaleStacked(d.key);
|
|
488
|
+
return value ? value : 0;
|
|
585
489
|
})
|
|
586
|
-
.attr('
|
|
587
|
-
|
|
490
|
+
.attr('data-group-bar-id', (_, i) => {
|
|
491
|
+
return i;
|
|
492
|
+
})
|
|
493
|
+
.attr('height', !config.isStacked ? this.yScaleGrouped.bandwidth() : this.yScaleStacked.bandwidth())
|
|
494
|
+
.style('fill', (d, i, n) => {
|
|
495
|
+
if (config.spreadColorsPerGroup) {
|
|
496
|
+
const groupIndex = parseInt(n[0].parentNode.getAttribute('data-group-id'), 10);
|
|
497
|
+
return this.colors[groupIndex];
|
|
498
|
+
}
|
|
499
|
+
return this.colors[i];
|
|
500
|
+
})
|
|
501
|
+
.attr('width', 0)
|
|
502
|
+
.on('mouseover', function (event, d) {
|
|
503
|
+
select$1(this
|
|
504
|
+
.transition()
|
|
505
|
+
.duration(this.transitionService.getTransitionDuration() / 7.5))
|
|
506
|
+
.style('fill', () => {
|
|
507
|
+
if (config.spreadColorsPerGroup) {
|
|
508
|
+
const groupIndex = parseInt(this.parentNode.getAttribute('data-group-id'), 10);
|
|
509
|
+
const c = color(self.colors[groupIndex]);
|
|
510
|
+
const ct = c ? c.darker(1).toString() : self.colors[groupIndex];
|
|
511
|
+
return ct;
|
|
512
|
+
}
|
|
513
|
+
const groupIndex = parseInt(this.getAttribute('data-group-bar-id'), 10);
|
|
514
|
+
const c = color(self.colors[groupIndex]);
|
|
515
|
+
const ct = c ? c.darker(1).toString() : self.colors[groupIndex];
|
|
516
|
+
return ct;
|
|
517
|
+
});
|
|
518
|
+
})
|
|
519
|
+
.on('mousemove', (event, d) => {
|
|
520
|
+
self.tooltipBuilder.showBarTooltip(event, d, config.tickFormat || PcacFormatEnum.None);
|
|
521
|
+
})
|
|
522
|
+
.on('mouseout', function (event, d) {
|
|
523
|
+
self.tooltipBuilder.hideTooltip();
|
|
524
|
+
select$1(this)
|
|
525
|
+
.transition()
|
|
526
|
+
.duration(this.transitionService.getTransitionDuration() / 5)
|
|
527
|
+
.style('fill', () => {
|
|
528
|
+
if (config.spreadColorsPerGroup) {
|
|
529
|
+
const groupIndex = parseInt(this.parentNode.getAttribute('data-group-id'), 10);
|
|
530
|
+
return self.colors[groupIndex];
|
|
531
|
+
}
|
|
532
|
+
const groupIndex = parseInt(this.getAttribute('data-group-bar-id'), 10);
|
|
533
|
+
return self.colors[groupIndex];
|
|
534
|
+
});
|
|
535
|
+
})
|
|
536
|
+
.on('click', (d) => {
|
|
537
|
+
this.barClickedSource.next(d);
|
|
538
|
+
})
|
|
539
|
+
.transition()
|
|
540
|
+
.duration(this.transitionService.getTransitionDuration())
|
|
541
|
+
.attr('width', (d) => {
|
|
542
|
+
return this.xScale(d.value);
|
|
543
|
+
});
|
|
588
544
|
}
|
|
589
|
-
|
|
590
|
-
this.svg.append('
|
|
591
|
-
.attr('
|
|
592
|
-
.
|
|
593
|
-
|
|
594
|
-
.attr('class', 'area')
|
|
595
|
-
.style('opacity', 0.5)
|
|
596
|
-
.style('fill', () => {
|
|
597
|
-
return this.colors[index]; // TODO: strongly type
|
|
545
|
+
drawThresholdAcrossChart(config) {
|
|
546
|
+
this.applyPreTransitionThresholdStyles(this.svg.select('.pcac-bars').append('rect'), config)
|
|
547
|
+
.attr('height', this.height)
|
|
548
|
+
.attr('data-group-threshold-id', (_, i) => {
|
|
549
|
+
return i;
|
|
598
550
|
})
|
|
599
|
-
.
|
|
600
|
-
.
|
|
601
|
-
|
|
602
|
-
.
|
|
551
|
+
.on('mousemove', (event, _) => {
|
|
552
|
+
this.tooltipBuilder.showBarTooltip(event, config.thresholds[0], config.tickFormat || PcacFormatEnum.None);
|
|
553
|
+
})
|
|
554
|
+
.transition()
|
|
555
|
+
.duration(this.transitionService.getTransitionDuration())
|
|
556
|
+
.attr('x', (d, i) => {
|
|
557
|
+
return this.xScale(config.thresholds[i].value);
|
|
558
|
+
});
|
|
603
559
|
}
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
}
|
|
560
|
+
drawThresholdsPerGroup(group, config) {
|
|
561
|
+
const self = this;
|
|
562
|
+
this.applyPreTransitionThresholdStyles(this.svg.selectAll('.pcac-bar-group').append('rect'), config)
|
|
563
|
+
.attr('height', this.yScaleStacked.bandwidth())
|
|
564
|
+
.attr('data-group-threshold-id', (_, i) => {
|
|
565
|
+
return i;
|
|
566
|
+
})
|
|
567
|
+
.on('mousemove', function (event, d, i) {
|
|
568
|
+
const index = Number(this.parentElement.dataset['groupId']);
|
|
569
|
+
self.tooltipBuilder.showBarTooltip(event, config.isStacked ?
|
|
570
|
+
config.thresholds[index].data[0] :
|
|
571
|
+
config.thresholds[index], config.tickFormat || PcacFormatEnum.None);
|
|
572
|
+
})
|
|
573
|
+
.transition()
|
|
574
|
+
.duration(this.transitionService.getTransitionDuration())
|
|
575
|
+
.attr('x', (_, i) => {
|
|
576
|
+
return this.xScale(config.isStacked ? config.thresholds[i].data[0].value : config.thresholds[i].value);
|
|
577
|
+
});
|
|
617
578
|
}
|
|
618
|
-
|
|
579
|
+
drawThresholdsPerBarInGroup(group, config) {
|
|
619
580
|
const self = this;
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
self.tooltipBuilder.showBarTooltip(event, d, self.config.yFormat, self.config.xFormat);
|
|
639
|
-
select$1(this).transition(transition()
|
|
640
|
-
.duration(self.transitionService.getTransitionDuration() / 3))
|
|
641
|
-
.attr('r', 6)
|
|
642
|
-
.attr('fill', self.colors[index]);
|
|
643
|
-
})
|
|
644
|
-
.on('mouseout', function () {
|
|
645
|
-
self.tooltipBuilder.hideTooltip();
|
|
646
|
-
select$1(this).transition(transition()
|
|
647
|
-
.duration(self.transitionService.getTransitionDuration() / 3))
|
|
648
|
-
.attr('r', 4)
|
|
649
|
-
.attr('fill', '#fff');
|
|
650
|
-
})
|
|
651
|
-
.on('click', (d, i) => {
|
|
652
|
-
this.dotClickedSource.next(d);
|
|
653
|
-
})
|
|
654
|
-
.transition(transition()
|
|
655
|
-
.duration(this.transitionService.getTransitionDuration()))
|
|
656
|
-
.attr('cy', (d) => {
|
|
657
|
-
return this.yScale(d.value);
|
|
658
|
-
})
|
|
659
|
-
.attr('r', 4)
|
|
660
|
-
.attr('style', () => config.data[index].hide ? 'display: none' : null);
|
|
661
|
-
}
|
|
581
|
+
this.applyPreTransitionThresholdStyles(group.enter().append('rect'), config)
|
|
582
|
+
.attr('data-group-threshold-id', (_, i) => {
|
|
583
|
+
return i;
|
|
584
|
+
})
|
|
585
|
+
.attr('height', this.yScaleGrouped.bandwidth())
|
|
586
|
+
.on('mousemove', function (event, d, i, n) {
|
|
587
|
+
const target = event.target;
|
|
588
|
+
const index = Number(target.getAttribute("data-group-threshold-id"));
|
|
589
|
+
self.tooltipBuilder.showBarTooltip(event, config.thresholds[Number(this.parentElement.dataset['groupId'])].data[index], config.tickFormat || PcacFormatEnum.None);
|
|
590
|
+
})
|
|
591
|
+
.transition()
|
|
592
|
+
.duration(this.transitionService.getTransitionDuration())
|
|
593
|
+
.attr('y', (d) => {
|
|
594
|
+
return this.yScaleGrouped(d.key);
|
|
595
|
+
})
|
|
596
|
+
.attr('x', (d, i, n) => {
|
|
597
|
+
return this.xScale(config.thresholds[n[0].parentElement.dataset['groupId']].data[i].value);
|
|
598
|
+
});
|
|
662
599
|
}
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
600
|
+
applyPreTransitionThresholdStyles(elm, config) {
|
|
601
|
+
return elm.attr('class', 'pcac-threshold')
|
|
602
|
+
.style('fill', () => {
|
|
603
|
+
return this.colorService.getAlert();
|
|
604
|
+
})
|
|
605
|
+
.style('stroke', () => {
|
|
606
|
+
return this.colorService.getAlert();
|
|
607
|
+
})
|
|
608
|
+
.style('stroke-width', () => {
|
|
609
|
+
return 2;
|
|
610
|
+
})
|
|
611
|
+
.attr('width', '3px')
|
|
612
|
+
.on('mouseout', () => {
|
|
613
|
+
this.tooltipBuilder.hideTooltip();
|
|
614
|
+
});
|
|
673
615
|
}
|
|
674
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.
|
|
675
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.
|
|
616
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: BarHorizontalChartBuilder, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
|
617
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: BarHorizontalChartBuilder, providedIn: 'root' });
|
|
676
618
|
}
|
|
677
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.
|
|
619
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: BarHorizontalChartBuilder, decorators: [{
|
|
678
620
|
type: Injectable,
|
|
679
621
|
args: [{
|
|
680
622
|
providedIn: 'root',
|
|
681
623
|
}]
|
|
682
624
|
}] });
|
|
683
625
|
|
|
684
|
-
class
|
|
685
|
-
chartBuilder = inject(
|
|
626
|
+
class PcacBarHorizontalChartComponent {
|
|
627
|
+
chartBuilder = inject(BarHorizontalChartBuilder);
|
|
686
628
|
config = input.required(...(ngDevMode ? [{ debugName: "config" }] : []));
|
|
687
629
|
chartElm = viewChild.required('chart');
|
|
688
|
-
|
|
630
|
+
barClicked = output();
|
|
689
631
|
resizeWindowTimeout;
|
|
690
632
|
constructor() {
|
|
691
|
-
this.chartBuilder.
|
|
692
|
-
this.
|
|
633
|
+
this.chartBuilder.barClicked$.subscribe(data => {
|
|
634
|
+
this.barClicked.emit(data);
|
|
693
635
|
});
|
|
694
636
|
}
|
|
695
|
-
ngOnChanges(
|
|
696
|
-
|
|
697
|
-
this.buildChart();
|
|
698
|
-
}
|
|
637
|
+
ngOnChanges() {
|
|
638
|
+
this.buildChart();
|
|
699
639
|
}
|
|
700
640
|
buildChart() {
|
|
701
641
|
const config = this.config();
|
|
702
|
-
console.log('Building chart with config:', config);
|
|
703
642
|
if (config && config.data && config.data.length > 0) {
|
|
704
643
|
this.chartBuilder.buildChart(this.chartElm(), config);
|
|
705
644
|
}
|
|
@@ -714,209 +653,87 @@ class PcacLineAreaChartComponent {
|
|
|
714
653
|
self.buildChart();
|
|
715
654
|
}, 300);
|
|
716
655
|
}
|
|
717
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.
|
|
718
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "20.
|
|
656
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: PcacBarHorizontalChartComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
657
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "20.3.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 });
|
|
719
658
|
}
|
|
720
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.
|
|
659
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: PcacBarHorizontalChartComponent, decorators: [{
|
|
721
660
|
type: Component,
|
|
722
|
-
args: [{ selector: 'pcac-
|
|
661
|
+
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"] }]
|
|
723
662
|
}], ctorParameters: () => [], propDecorators: { onResize: [{
|
|
724
663
|
type: HostListener,
|
|
725
664
|
args: ['window:resize']
|
|
726
665
|
}] } });
|
|
727
666
|
|
|
728
|
-
class
|
|
729
|
-
|
|
730
|
-
enableEffects = true;
|
|
667
|
+
class PcacBarHorizontalChartConfig extends PcacChartConfig {
|
|
668
|
+
domainMax = 100;
|
|
731
669
|
numberOfTicks = 5;
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
xDomainMax;
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
class PieChartBuilder extends PcacChart {
|
|
743
|
-
radius;
|
|
744
|
-
arcShape;
|
|
745
|
-
arcOverShape;
|
|
746
|
-
pieAngles;
|
|
747
|
-
sliceClickedSource = new Subject();
|
|
748
|
-
sliceClicked$ = this.sliceClickedSource.asObservable();
|
|
749
|
-
buildChart(chartElm, config) {
|
|
750
|
-
this.initializeChartState(chartElm, config);
|
|
751
|
-
this.radius = Math.min(Math.min(this.height, this.width), Math.min(this.height, this.width)) / 2;
|
|
752
|
-
this.buildShapes(config);
|
|
753
|
-
this.drawChart(chartElm, config);
|
|
754
|
-
}
|
|
755
|
-
buildShapes(config) {
|
|
756
|
-
const radiusOffset = 10;
|
|
757
|
-
this.arcShape = arc()
|
|
758
|
-
.innerRadius(0)
|
|
759
|
-
.outerRadius(this.radius - radiusOffset);
|
|
760
|
-
this.arcOverShape = arc()
|
|
761
|
-
.innerRadius(0)
|
|
762
|
-
.outerRadius(this.radius - radiusOffset + radiusOffset);
|
|
763
|
-
this.pieAngles = pie()
|
|
764
|
-
.sort(null)
|
|
765
|
-
.value((d) => d.value); // TODO: Strongly type
|
|
766
|
-
}
|
|
767
|
-
drawChart(chartElm, config) {
|
|
768
|
-
this.buildContainer(chartElm, true);
|
|
769
|
-
const self = this;
|
|
770
|
-
this.svg.selectAll('.pcac-arc')
|
|
771
|
-
.data(this.pieAngles(config.data))
|
|
772
|
-
.enter().append('g')
|
|
773
|
-
.attr('class', 'pcac-arc')
|
|
774
|
-
.append('path')
|
|
775
|
-
.style('fill', (d, i) => {
|
|
776
|
-
return this.colors[i];
|
|
777
|
-
})
|
|
778
|
-
.on('mouseover', function (_, d) {
|
|
779
|
-
const t = transition().duration(self.transitionService.getTransitionDuration() / 3);
|
|
780
|
-
const c = color(self.colors[d.index]);
|
|
781
|
-
const ct = c ? c.darker(1).toString() : self.colors[d.index];
|
|
782
|
-
select$1(this).transition(t)
|
|
783
|
-
.attr('d', self.arcOverShape)
|
|
784
|
-
.style('fill', ct);
|
|
785
|
-
})
|
|
786
|
-
.on('mousemove', (event, d) => {
|
|
787
|
-
self.tooltipBuilder.showBarTooltip(event, d.data);
|
|
788
|
-
})
|
|
789
|
-
.on('mouseout', function (_, d) {
|
|
790
|
-
self.tooltipBuilder.hideTooltip();
|
|
791
|
-
select$1(this).transition(transition()
|
|
792
|
-
.duration(self.transitionService.getTransitionDuration() / 3))
|
|
793
|
-
.attr('d', self.arcShape)
|
|
794
|
-
.style('fill', self.colors[d.index]);
|
|
795
|
-
})
|
|
796
|
-
.on('click', (d, i) => {
|
|
797
|
-
this.sliceClickedSource.next(d.data);
|
|
798
|
-
})
|
|
799
|
-
.transition(transition()
|
|
800
|
-
.duration(this.transitionService.getTransitionDuration()))
|
|
801
|
-
.attrTween('d', (b) => {
|
|
802
|
-
return this.tweenChart(b);
|
|
803
|
-
});
|
|
804
|
-
}
|
|
805
|
-
tweenChart(b) {
|
|
806
|
-
b.innerRadius = 0;
|
|
807
|
-
const i = interpolate({ startAngle: 0, endAngle: 0 }, b);
|
|
808
|
-
return (t) => this.arcShape(i(t)); // TODO: Strongly type
|
|
809
|
-
}
|
|
810
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.7", ngImport: i0, type: PieChartBuilder, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
|
811
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.1.7", ngImport: i0, type: PieChartBuilder, providedIn: 'root' });
|
|
812
|
-
}
|
|
813
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.7", ngImport: i0, type: PieChartBuilder, decorators: [{
|
|
814
|
-
type: Injectable,
|
|
815
|
-
args: [{
|
|
816
|
-
providedIn: 'root',
|
|
817
|
-
}]
|
|
818
|
-
}] });
|
|
819
|
-
|
|
820
|
-
class PcacPieChartComponent {
|
|
821
|
-
chartBuilder = inject(PieChartBuilder);
|
|
822
|
-
config = input.required(...(ngDevMode ? [{ debugName: "config" }] : []));
|
|
823
|
-
chartElm = viewChild.required('chart');
|
|
824
|
-
sliceClicked = output();
|
|
825
|
-
resizeWindowTimeout;
|
|
826
|
-
constructor() {
|
|
827
|
-
this.chartBuilder.sliceClicked$.subscribe(data => {
|
|
828
|
-
this.sliceClicked.emit(data);
|
|
829
|
-
});
|
|
830
|
-
}
|
|
831
|
-
ngOnChanges() {
|
|
832
|
-
this.buildChart();
|
|
833
|
-
}
|
|
834
|
-
buildChart() {
|
|
835
|
-
const config = this.config();
|
|
836
|
-
if (config && config.data && config.data.length > 0) {
|
|
837
|
-
this.chartBuilder.buildChart(this.chartElm(), config);
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
/**
|
|
841
|
-
* Opting against fromEvent due to incompatibility with rxjs 5 => 6
|
|
842
|
-
*/
|
|
843
|
-
onResize() {
|
|
844
|
-
const self = this;
|
|
845
|
-
clearTimeout(this.resizeWindowTimeout);
|
|
846
|
-
this.resizeWindowTimeout = setTimeout(() => {
|
|
847
|
-
self.buildChart();
|
|
848
|
-
}, 300);
|
|
849
|
-
}
|
|
850
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.7", ngImport: i0, type: PcacPieChartComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
851
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "20.1.7", 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 });
|
|
670
|
+
isStacked = false;
|
|
671
|
+
thresholds = [];
|
|
672
|
+
tickFormat = PcacFormatEnum.None;
|
|
673
|
+
hideGrid = false;
|
|
674
|
+
hideAxis = false;
|
|
675
|
+
spreadColorsPerGroup = false;
|
|
676
|
+
colorOverride = new PcacBarHorizontalChartColorOverrideConfig();
|
|
852
677
|
}
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
args: [{ selector: 'pcac-pie-chart', encapsulation: ViewEncapsulation.None, standalone: true, 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"] }]
|
|
856
|
-
}], ctorParameters: () => [], propDecorators: { onResize: [{
|
|
857
|
-
type: HostListener,
|
|
858
|
-
args: ['window:resize']
|
|
859
|
-
}] } });
|
|
860
|
-
|
|
861
|
-
class PcacPieChartConfig extends PcacChartConfig {
|
|
862
|
-
numberOfTicks = 5;
|
|
678
|
+
class PcacBarHorizontalChartColorOverrideConfig {
|
|
679
|
+
colors = [];
|
|
863
680
|
}
|
|
864
681
|
|
|
865
|
-
class
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
682
|
+
class BarVerticalChartBuilder extends PcacChart {
|
|
683
|
+
xScaleStacked;
|
|
684
|
+
xScaleGrouped;
|
|
685
|
+
yScale;
|
|
869
686
|
barClickedSource = new Subject();
|
|
870
|
-
config;
|
|
871
|
-
cachedMargins;
|
|
872
687
|
barClicked$ = this.barClickedSource.asObservable();
|
|
873
688
|
buildChart(chartElm, config) {
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
689
|
+
if (config.colorOverride && config.colorOverride.colors) {
|
|
690
|
+
this.colors = config.colorOverride.colors;
|
|
691
|
+
}
|
|
692
|
+
if (config.hideAxis) {
|
|
693
|
+
this.adjustForHiddenAxis(config);
|
|
694
|
+
}
|
|
695
|
+
this.initializeChartState(chartElm, config);
|
|
696
|
+
if (this.width <= 0) {
|
|
697
|
+
return; // TODO: Figure out why this is happening on initial load sometimes
|
|
877
698
|
}
|
|
878
|
-
this.initializeChartState(chartElm, this.config);
|
|
879
699
|
if (config.colorOverride && config.colorOverride.colors) {
|
|
880
700
|
this.colors = config.colorOverride.colors.reverse();
|
|
881
701
|
}
|
|
882
|
-
this.buildScales(
|
|
883
|
-
this.drawChart(chartElm,
|
|
702
|
+
this.buildScales(config);
|
|
703
|
+
this.drawChart(chartElm, config);
|
|
884
704
|
}
|
|
885
|
-
adjustForHiddenAxis() {
|
|
886
|
-
|
|
887
|
-
|
|
705
|
+
adjustForHiddenAxis(config) {
|
|
706
|
+
const hasGroupLabel = this.hasGroupLabel(config);
|
|
707
|
+
config.height = config.height + this.margin.top;
|
|
708
|
+
if (!hasGroupLabel) {
|
|
709
|
+
config.height = config.height + this.margin.bottom;
|
|
888
710
|
}
|
|
889
|
-
this.margin = JSON.parse(JSON.stringify(this.cachedMargins));
|
|
890
|
-
this.config.height = this.config.height + this.margin.top + this.margin.bottom;
|
|
891
711
|
this.margin.top = 0;
|
|
892
|
-
this.margin.bottom = 0;
|
|
712
|
+
this.margin.bottom = hasGroupLabel ? this.margin.bottom : 0;
|
|
893
713
|
this.margin.left = 0;
|
|
894
714
|
this.margin.right = 0;
|
|
895
715
|
}
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
716
|
+
hasGroupLabel(config) {
|
|
717
|
+
let hasGroupLabel = false;
|
|
718
|
+
config.data.forEach(node => {
|
|
719
|
+
if (node.key) {
|
|
720
|
+
hasGroupLabel = true;
|
|
901
721
|
}
|
|
902
|
-
}
|
|
903
|
-
}
|
|
904
|
-
buildScales(chartElm, config) {
|
|
905
|
-
config.data[0].data.map((d) => {
|
|
906
|
-
return d.value;
|
|
907
722
|
});
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
723
|
+
return hasGroupLabel;
|
|
724
|
+
}
|
|
725
|
+
buildScales(config) {
|
|
726
|
+
this.yScale = scaleLinear()
|
|
727
|
+
.rangeRound([0, config.height])
|
|
728
|
+
.domain([config.domainMax, 0]);
|
|
729
|
+
this.xScaleStacked = scaleBand()
|
|
911
730
|
.domain(config.data.map((d) => d.key))
|
|
912
|
-
.
|
|
731
|
+
.rangeRound([0, this.width])
|
|
913
732
|
.padding(0.1);
|
|
914
|
-
this.
|
|
915
|
-
.padding(0.
|
|
916
|
-
.rangeRound([0, this.
|
|
733
|
+
this.xScaleGrouped = scaleBand()
|
|
734
|
+
.padding(0.2)
|
|
735
|
+
.rangeRound([0, this.xScaleStacked.bandwidth()])
|
|
917
736
|
.domain(config.data[0].data.map((d) => d.key));
|
|
918
|
-
this.setHorizontalMarginsBasedOnContent(chartElm, config.data, this.yScaleStacked);
|
|
919
|
-
this.xScale.range([0, this.width]);
|
|
920
737
|
}
|
|
921
738
|
drawChart(chartElm, config) {
|
|
922
739
|
this.buildContainer(chartElm);
|
|
@@ -924,19 +741,19 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
924
741
|
svg: this.svg,
|
|
925
742
|
numberOfTicks: config.numberOfTicks || 5,
|
|
926
743
|
height: this.height,
|
|
927
|
-
xScale: this.
|
|
928
|
-
yScale: this.
|
|
929
|
-
xFormat:
|
|
930
|
-
yFormat: PcacFormatEnum.None,
|
|
931
|
-
|
|
744
|
+
xScale: this.xScaleStacked,
|
|
745
|
+
yScale: this.yScale,
|
|
746
|
+
xFormat: PcacFormatEnum.None,
|
|
747
|
+
yFormat: config.tickFormat || PcacFormatEnum.None,
|
|
748
|
+
hideYAxis: config.hideAxis
|
|
932
749
|
});
|
|
933
750
|
if (!config.hideGrid) {
|
|
934
|
-
this.gridBuilder.
|
|
751
|
+
this.gridBuilder.drawHorizontalGrid({
|
|
935
752
|
svg: this.svg,
|
|
936
753
|
numberOfTicks: config.numberOfTicks || 5,
|
|
937
|
-
|
|
938
|
-
xScale: this.
|
|
939
|
-
yScale: this.
|
|
754
|
+
width: this.width,
|
|
755
|
+
xScale: this.xScaleStacked,
|
|
756
|
+
yScale: this.yScale
|
|
940
757
|
});
|
|
941
758
|
}
|
|
942
759
|
this.addGroups(config);
|
|
@@ -951,9 +768,11 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
951
768
|
.attr('data-group-id', (d, i) => {
|
|
952
769
|
return i;
|
|
953
770
|
})
|
|
954
|
-
.attr('transform', (d
|
|
771
|
+
.attr('transform', (d, i) => {
|
|
772
|
+
return 'translate(' + this.xScaleStacked(d.key) + ',0)';
|
|
773
|
+
});
|
|
955
774
|
const group = groupsContainer.selectAll('rect')
|
|
956
|
-
.data((d) => {
|
|
775
|
+
.data((d, i) => {
|
|
957
776
|
return d.data;
|
|
958
777
|
});
|
|
959
778
|
this.drawBarsPerGroup(group, config);
|
|
@@ -974,19 +793,17 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
974
793
|
this.drawThresholdsPerBarInGroup(group, config);
|
|
975
794
|
}
|
|
976
795
|
}
|
|
977
|
-
drawBarsPerGroup(
|
|
796
|
+
drawBarsPerGroup(group, config) {
|
|
978
797
|
const self = this;
|
|
979
|
-
|
|
798
|
+
group.enter().append('rect')
|
|
980
799
|
.attr('class', 'pcac-bar')
|
|
981
|
-
.attr('x',
|
|
982
|
-
.
|
|
983
|
-
let value = !config.isStacked ? this.yScaleGrouped(d.key) : this.yScaleStacked(d.key);
|
|
800
|
+
.attr('x', (d, i) => {
|
|
801
|
+
let value = !config.isStacked ? this.xScaleGrouped(d.key) : this.xScaleStacked(d.key);
|
|
984
802
|
return value ? value : 0;
|
|
985
803
|
})
|
|
986
804
|
.attr('data-group-bar-id', (_, i) => {
|
|
987
805
|
return i;
|
|
988
806
|
})
|
|
989
|
-
.attr('height', !config.isStacked ? this.yScaleGrouped.bandwidth() : this.yScaleStacked.bandwidth())
|
|
990
807
|
.style('fill', (d, i, n) => {
|
|
991
808
|
if (config.spreadColorsPerGroup) {
|
|
992
809
|
const groupIndex = parseInt(n[0].parentNode.getAttribute('data-group-id'), 10);
|
|
@@ -994,10 +811,14 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
994
811
|
}
|
|
995
812
|
return this.colors[i];
|
|
996
813
|
})
|
|
997
|
-
.attr('
|
|
814
|
+
.attr('y', () => {
|
|
815
|
+
return this.height;
|
|
816
|
+
})
|
|
817
|
+
.attr('height', 0)
|
|
998
818
|
.on('mouseover', function (event, d) {
|
|
999
|
-
select$1(this)
|
|
1000
|
-
.
|
|
819
|
+
select$1(this)
|
|
820
|
+
.transition()
|
|
821
|
+
.duration(self.transitionService.getTransitionDuration() / 5)
|
|
1001
822
|
.style('fill', () => {
|
|
1002
823
|
if (config.spreadColorsPerGroup) {
|
|
1003
824
|
const groupIndex = parseInt(this.parentNode.getAttribute('data-group-id'), 10);
|
|
@@ -1014,10 +835,11 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
1014
835
|
.on('mousemove', (event, d) => {
|
|
1015
836
|
self.tooltipBuilder.showBarTooltip(event, d, config.tickFormat || PcacFormatEnum.None);
|
|
1016
837
|
})
|
|
1017
|
-
.on('mouseout', function (
|
|
838
|
+
.on('mouseout', function (d) {
|
|
1018
839
|
self.tooltipBuilder.hideTooltip();
|
|
1019
|
-
select$1(this)
|
|
1020
|
-
.
|
|
840
|
+
select$1(this)
|
|
841
|
+
.transition()
|
|
842
|
+
.duration(self.transitionService.getTransitionDuration() / 5)
|
|
1021
843
|
.style('fill', () => {
|
|
1022
844
|
if (config.spreadColorsPerGroup) {
|
|
1023
845
|
const groupIndex = parseInt(this.parentNode.getAttribute('data-group-id'), 10);
|
|
@@ -1027,47 +849,54 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
1027
849
|
return self.colors[groupIndex];
|
|
1028
850
|
});
|
|
1029
851
|
})
|
|
1030
|
-
.on('click', (d) => {
|
|
852
|
+
.on('click', (_, d) => {
|
|
1031
853
|
this.barClickedSource.next(d);
|
|
1032
854
|
})
|
|
1033
|
-
.transition(
|
|
1034
|
-
.duration(this.transitionService.getTransitionDuration())
|
|
1035
|
-
.
|
|
1036
|
-
|
|
855
|
+
.transition()
|
|
856
|
+
.duration(this.transitionService.getTransitionDuration())
|
|
857
|
+
// .transition(
|
|
858
|
+
// transition().duration(this.transitionService.getTransitionDuration())
|
|
859
|
+
// )
|
|
860
|
+
.attr('width', !config.isStacked ? this.xScaleGrouped.bandwidth() : this.xScaleStacked.bandwidth())
|
|
861
|
+
.attr('y', (d) => {
|
|
862
|
+
return this.yScale(d.value);
|
|
863
|
+
})
|
|
864
|
+
.attr('height', (d) => {
|
|
865
|
+
return this.height - this.yScale(d.value);
|
|
1037
866
|
});
|
|
1038
867
|
}
|
|
1039
868
|
drawThresholdAcrossChart(config) {
|
|
1040
869
|
this.applyPreTransitionThresholdStyles(this.svg.select('.pcac-bars').append('rect'), config)
|
|
1041
|
-
.attr('
|
|
870
|
+
.attr('width', this.width)
|
|
1042
871
|
.attr('data-group-threshold-id', (_, i) => {
|
|
1043
872
|
return i;
|
|
1044
873
|
})
|
|
1045
|
-
.on('mousemove', (event,
|
|
874
|
+
.on('mousemove', (event, d, i) => {
|
|
1046
875
|
this.tooltipBuilder.showBarTooltip(event, config.thresholds[0], config.tickFormat || PcacFormatEnum.None);
|
|
1047
876
|
})
|
|
1048
|
-
.transition(
|
|
1049
|
-
.duration(this.transitionService.getTransitionDuration())
|
|
1050
|
-
.attr('
|
|
1051
|
-
return this.
|
|
1052
|
-
});
|
|
877
|
+
.transition()
|
|
878
|
+
.duration(this.transitionService.getTransitionDuration())
|
|
879
|
+
.attr('y', (d, i) => {
|
|
880
|
+
return this.yScale(config.thresholds[i].value);
|
|
881
|
+
});
|
|
1053
882
|
}
|
|
1054
883
|
drawThresholdsPerGroup(group, config) {
|
|
1055
884
|
const self = this;
|
|
1056
885
|
this.applyPreTransitionThresholdStyles(this.svg.selectAll('.pcac-bar-group').append('rect'), config)
|
|
1057
|
-
.attr('
|
|
886
|
+
.attr('width', this.xScaleStacked.bandwidth())
|
|
1058
887
|
.attr('data-group-threshold-id', (_, i) => {
|
|
1059
888
|
return i;
|
|
1060
889
|
})
|
|
1061
|
-
.on('mousemove', function (event
|
|
890
|
+
.on('mousemove', function (event) {
|
|
1062
891
|
const index = Number(this.parentElement.dataset['groupId']);
|
|
1063
892
|
self.tooltipBuilder.showBarTooltip(event, config.isStacked ?
|
|
1064
893
|
config.thresholds[index].data[0] :
|
|
1065
894
|
config.thresholds[index], config.tickFormat || PcacFormatEnum.None);
|
|
1066
895
|
})
|
|
1067
|
-
.transition(
|
|
1068
|
-
.duration(this.transitionService.getTransitionDuration())
|
|
1069
|
-
.attr('
|
|
1070
|
-
return this.
|
|
896
|
+
.transition()
|
|
897
|
+
.duration(this.transitionService.getTransitionDuration())
|
|
898
|
+
.attr('y', (d, i) => {
|
|
899
|
+
return this.yScale(config.isStacked ? config.thresholds[i].data[0].value : config.thresholds[i].value);
|
|
1071
900
|
});
|
|
1072
901
|
}
|
|
1073
902
|
drawThresholdsPerBarInGroup(group, config) {
|
|
@@ -1076,23 +905,27 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
1076
905
|
.attr('data-group-threshold-id', (_, i) => {
|
|
1077
906
|
return i;
|
|
1078
907
|
})
|
|
1079
|
-
.
|
|
1080
|
-
.on('mousemove', function (event, d, i, n) {
|
|
908
|
+
.on('mousemove', function (event, _) {
|
|
1081
909
|
const target = event.target;
|
|
1082
910
|
const index = Number(target.getAttribute("data-group-threshold-id"));
|
|
1083
911
|
self.tooltipBuilder.showBarTooltip(event, config.thresholds[Number(this.parentElement.dataset['groupId'])].data[index], config.tickFormat || PcacFormatEnum.None);
|
|
1084
912
|
})
|
|
1085
|
-
.
|
|
1086
|
-
.
|
|
1087
|
-
.
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
.attr('x', (d, i, n) => {
|
|
1091
|
-
return this.xScale(config.thresholds[n[0].parentElement.dataset['groupId']].data[i].value);
|
|
913
|
+
.attr('width', this.xScaleGrouped.bandwidth())
|
|
914
|
+
.transition()
|
|
915
|
+
.duration(this.transitionService.getTransitionDuration())
|
|
916
|
+
.attr('y', (d, i, n) => {
|
|
917
|
+
return this.yScale(config.thresholds[n[0].parentElement.dataset['groupId']].data[i].value);
|
|
1092
918
|
});
|
|
1093
919
|
}
|
|
1094
920
|
applyPreTransitionThresholdStyles(elm, config) {
|
|
1095
921
|
return elm.attr('class', 'pcac-threshold')
|
|
922
|
+
.attr('x', (d) => {
|
|
923
|
+
return this.xScaleGrouped(d ? d.key : '');
|
|
924
|
+
})
|
|
925
|
+
.attr('y', () => {
|
|
926
|
+
return this.height;
|
|
927
|
+
})
|
|
928
|
+
.attr('height', 0)
|
|
1096
929
|
.style('fill', () => {
|
|
1097
930
|
return this.colorService.getAlert();
|
|
1098
931
|
})
|
|
@@ -1102,23 +935,25 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
1102
935
|
.style('stroke-width', () => {
|
|
1103
936
|
return 2;
|
|
1104
937
|
})
|
|
1105
|
-
.attr('width', '3px')
|
|
1106
938
|
.on('mouseout', () => {
|
|
1107
939
|
this.tooltipBuilder.hideTooltip();
|
|
940
|
+
})
|
|
941
|
+
.attr('height', () => {
|
|
942
|
+
return '3px';
|
|
1108
943
|
});
|
|
1109
944
|
}
|
|
1110
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.
|
|
1111
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.
|
|
945
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: BarVerticalChartBuilder, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
|
946
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: BarVerticalChartBuilder, providedIn: 'root' });
|
|
1112
947
|
}
|
|
1113
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.
|
|
948
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: BarVerticalChartBuilder, decorators: [{
|
|
1114
949
|
type: Injectable,
|
|
1115
950
|
args: [{
|
|
1116
951
|
providedIn: 'root',
|
|
1117
952
|
}]
|
|
1118
953
|
}] });
|
|
1119
954
|
|
|
1120
|
-
class
|
|
1121
|
-
chartBuilder = inject(
|
|
955
|
+
class PcacBarVerticalChartComponent {
|
|
956
|
+
chartBuilder = inject(BarVerticalChartBuilder);
|
|
1122
957
|
config = input.required(...(ngDevMode ? [{ debugName: "config" }] : []));
|
|
1123
958
|
chartElm = viewChild.required('chart');
|
|
1124
959
|
barClicked = output();
|
|
@@ -1147,18 +982,18 @@ class PcacBarHorizontalChartComponent {
|
|
|
1147
982
|
self.buildChart();
|
|
1148
983
|
}, 300);
|
|
1149
984
|
}
|
|
1150
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.
|
|
1151
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "20.
|
|
985
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: PcacBarVerticalChartComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
986
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "20.3.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 });
|
|
1152
987
|
}
|
|
1153
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.
|
|
988
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: PcacBarVerticalChartComponent, decorators: [{
|
|
1154
989
|
type: Component,
|
|
1155
|
-
args: [{ selector: 'pcac-bar-
|
|
990
|
+
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"] }]
|
|
1156
991
|
}], ctorParameters: () => [], propDecorators: { onResize: [{
|
|
1157
992
|
type: HostListener,
|
|
1158
993
|
args: ['window:resize']
|
|
1159
994
|
}] } });
|
|
1160
995
|
|
|
1161
|
-
class
|
|
996
|
+
class PcacBarVerticalChartConfig extends PcacChartConfig {
|
|
1162
997
|
domainMax = 100;
|
|
1163
998
|
numberOfTicks = 5;
|
|
1164
999
|
isStacked = false;
|
|
@@ -1167,286 +1002,490 @@ class PcacBarHorizontalChartConfig extends PcacChartConfig {
|
|
|
1167
1002
|
hideGrid = false;
|
|
1168
1003
|
hideAxis = false;
|
|
1169
1004
|
spreadColorsPerGroup = false;
|
|
1170
|
-
colorOverride = new
|
|
1005
|
+
colorOverride = new PcacBarVerticalChartColorOverrideConfig();
|
|
1171
1006
|
}
|
|
1172
|
-
class
|
|
1007
|
+
class PcacBarVerticalChartColorOverrideConfig {
|
|
1173
1008
|
colors = [];
|
|
1174
1009
|
}
|
|
1175
1010
|
|
|
1176
|
-
class
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
this.adjustForHiddenAxis(config);
|
|
1188
|
-
}
|
|
1189
|
-
this.initializeChartState(chartElm, config);
|
|
1190
|
-
if (config.colorOverride && config.colorOverride.colors) {
|
|
1191
|
-
this.colors = config.colorOverride.colors.reverse();
|
|
1192
|
-
}
|
|
1193
|
-
this.buildScales(config);
|
|
1194
|
-
this.drawChart(chartElm, config);
|
|
1011
|
+
class LineAreaChartEffectsBuilder {
|
|
1012
|
+
config;
|
|
1013
|
+
lines = [];
|
|
1014
|
+
buildEffects(config) {
|
|
1015
|
+
this.config = config;
|
|
1016
|
+
this.lines = [];
|
|
1017
|
+
this.config.svg.selectAll('.line').each((d, i, n) => {
|
|
1018
|
+
this.lines.push(n[i]);
|
|
1019
|
+
});
|
|
1020
|
+
this.buildCollection();
|
|
1021
|
+
this.buildCanvas();
|
|
1195
1022
|
}
|
|
1196
|
-
|
|
1197
|
-
const
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1023
|
+
buildCollection() {
|
|
1024
|
+
const collection = this.config.svg.append('g')
|
|
1025
|
+
.attr('class', 'effects');
|
|
1026
|
+
collection.append('path')
|
|
1027
|
+
.attr('class', 'effect-line');
|
|
1028
|
+
const mousePerLine = collection.selectAll('.effect-group')
|
|
1029
|
+
.data(this.config.data.filter((elm) => {
|
|
1030
|
+
return elm.data.length > 0;
|
|
1031
|
+
}))
|
|
1032
|
+
.enter().append('g')
|
|
1033
|
+
.attr('class', 'effect-group')
|
|
1034
|
+
.attr('style', (d) => d.hide ? 'display: none' : null);
|
|
1035
|
+
mousePerLine.append('circle')
|
|
1036
|
+
.attr('r', 7)
|
|
1037
|
+
.attr('class', 'effect-circle')
|
|
1038
|
+
.style('stroke', (d, i) => {
|
|
1039
|
+
return this.config.colors[i];
|
|
1040
|
+
});
|
|
1041
|
+
mousePerLine.append('text')
|
|
1042
|
+
.attr('class', 'effect-text')
|
|
1043
|
+
.attr('y', 1.5)
|
|
1044
|
+
.attr('transform', 'translate(10,3)');
|
|
1206
1045
|
}
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1046
|
+
buildCanvas() {
|
|
1047
|
+
this.config.svg.append('rect')
|
|
1048
|
+
.attr('class', 'effects-canvas')
|
|
1049
|
+
.attr('width', this.config.width)
|
|
1050
|
+
.attr('height', this.config.height)
|
|
1051
|
+
.attr('pointer-events', 'all')
|
|
1052
|
+
.on('mouseout', () => {
|
|
1053
|
+
this.hideEffects();
|
|
1054
|
+
})
|
|
1055
|
+
.on('mouseover', () => {
|
|
1056
|
+
this.showEffects();
|
|
1057
|
+
})
|
|
1058
|
+
.on('mousemove', (event) => {
|
|
1059
|
+
const current = event.currentTarget;
|
|
1060
|
+
const parent = current.parentElement;
|
|
1061
|
+
const xForms = parent?.getAttribute('transform');
|
|
1062
|
+
if (!xForms)
|
|
1063
|
+
return this.onMouseMove([event.offsetX, event.offsetY]);
|
|
1064
|
+
const parts = /translate\(\s*([^\s,)]+)[ ,]([^\s,)]+)/.exec(xForms);
|
|
1065
|
+
if (!parts)
|
|
1066
|
+
return this.onMouseMove([event.offsetX, event.offsetY]);
|
|
1067
|
+
const x = Number(parts[1]);
|
|
1068
|
+
this.onMouseMove([event.offsetX - x, event.offsetY]);
|
|
1069
|
+
});
|
|
1070
|
+
}
|
|
1071
|
+
showEffects() {
|
|
1072
|
+
this.config.svg.select('.effect-line')
|
|
1073
|
+
.style('opacity', '1');
|
|
1074
|
+
this.config.svg.selectAll('.effect-group circle')
|
|
1075
|
+
.style('opacity', '1');
|
|
1076
|
+
this.config.svg.selectAll('.effect-group text')
|
|
1077
|
+
.style('opacity', '1');
|
|
1078
|
+
}
|
|
1079
|
+
hideEffects() {
|
|
1080
|
+
this.config.svg.select('.effect-line')
|
|
1081
|
+
.style('opacity', '0');
|
|
1082
|
+
this.config.svg.selectAll('.effect-group circle')
|
|
1083
|
+
.style('opacity', '0');
|
|
1084
|
+
this.config.svg.selectAll('.effect-group text')
|
|
1085
|
+
.style('opacity', '0');
|
|
1086
|
+
}
|
|
1087
|
+
onMouseMove(mousePos) {
|
|
1088
|
+
this.updateLine(mousePos);
|
|
1089
|
+
this.updateEffects(mousePos);
|
|
1090
|
+
}
|
|
1091
|
+
updateLine(mousePos) {
|
|
1092
|
+
this.config.svg.select('.effect-line')
|
|
1093
|
+
.attr('d', () => 'M' + mousePos[0] + ',' + this.config.height + ' ' + mousePos[0] + ',' + 0);
|
|
1094
|
+
}
|
|
1095
|
+
updateEffects(mousePos) {
|
|
1096
|
+
this.config.svg.selectAll('.effect-group')
|
|
1097
|
+
.attr('transform', (data, index, nodes) => {
|
|
1098
|
+
let beginning = 0;
|
|
1099
|
+
let end = this.lines[index].getTotalLength();
|
|
1100
|
+
let target = 0;
|
|
1101
|
+
let pos;
|
|
1102
|
+
while (true) {
|
|
1103
|
+
target = Math.floor((beginning + end) / 2);
|
|
1104
|
+
pos = this.lines[index].getPointAtLength(target);
|
|
1105
|
+
if ((target === end || target === beginning) && pos.x !== mousePos[0]) {
|
|
1106
|
+
break;
|
|
1107
|
+
}
|
|
1108
|
+
if (pos.x > mousePos[0]) {
|
|
1109
|
+
end = target;
|
|
1110
|
+
}
|
|
1111
|
+
else if (pos.x < mousePos[0]) {
|
|
1112
|
+
beginning = target;
|
|
1113
|
+
}
|
|
1114
|
+
else {
|
|
1115
|
+
break;
|
|
1116
|
+
}
|
|
1212
1117
|
}
|
|
1118
|
+
let textTarget = this.config.y.invert(pos.y);
|
|
1119
|
+
select$1(nodes[index]).select('text')
|
|
1120
|
+
.text(textTarget.toFixed(0));
|
|
1121
|
+
return 'translate(' + mousePos[0] + ',' + pos.y + ')';
|
|
1213
1122
|
});
|
|
1214
|
-
|
|
1123
|
+
}
|
|
1124
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: LineAreaChartEffectsBuilder, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1125
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: LineAreaChartEffectsBuilder, providedIn: 'root' });
|
|
1126
|
+
}
|
|
1127
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: LineAreaChartEffectsBuilder, decorators: [{
|
|
1128
|
+
type: Injectable,
|
|
1129
|
+
args: [{
|
|
1130
|
+
providedIn: 'root',
|
|
1131
|
+
}]
|
|
1132
|
+
}] });
|
|
1133
|
+
|
|
1134
|
+
class LineAreaChartBuilder extends PcacChart {
|
|
1135
|
+
line;
|
|
1136
|
+
area;
|
|
1137
|
+
xScale;
|
|
1138
|
+
yScale;
|
|
1139
|
+
dotClickedSource = new Subject();
|
|
1140
|
+
config;
|
|
1141
|
+
dotClicked$ = this.dotClickedSource.asObservable();
|
|
1142
|
+
buildChart(chartElm, config) {
|
|
1143
|
+
this.config = JSON.parse(JSON.stringify(config));
|
|
1144
|
+
this.startData = range(this.config.data[0].data.length).map((d) => {
|
|
1145
|
+
return {
|
|
1146
|
+
value: 0,
|
|
1147
|
+
key: ''
|
|
1148
|
+
};
|
|
1149
|
+
});
|
|
1150
|
+
if (this.config.hideAxis) {
|
|
1151
|
+
this.adjustForHiddenAxis();
|
|
1152
|
+
}
|
|
1153
|
+
this.initializeChartState(chartElm, this.config);
|
|
1154
|
+
this.buildScales(this.config);
|
|
1155
|
+
this.drawChart(chartElm, this.config);
|
|
1156
|
+
}
|
|
1157
|
+
adjustForHiddenAxis() {
|
|
1158
|
+
this.config.height = this.config.height + 12;
|
|
1159
|
+
this.margin.top = 8;
|
|
1160
|
+
this.margin.bottom = 8;
|
|
1161
|
+
this.margin.left = 8;
|
|
1162
|
+
this.margin.right = 8;
|
|
1215
1163
|
}
|
|
1216
1164
|
buildScales(config) {
|
|
1165
|
+
switch (config.xFormat) {
|
|
1166
|
+
case PcacFormatEnum.DateTime:
|
|
1167
|
+
this.xScale = scaleTime()
|
|
1168
|
+
.domain([new Date(config.xDomainMin), new Date(config.xDomainMax)])
|
|
1169
|
+
.range([0, this.width]);
|
|
1170
|
+
break;
|
|
1171
|
+
default:
|
|
1172
|
+
this.xScale = scaleLinear()
|
|
1173
|
+
.domain([0, config.data[0].data.length - 1])
|
|
1174
|
+
.range([0, this.width]);
|
|
1175
|
+
}
|
|
1217
1176
|
this.yScale = scaleLinear()
|
|
1218
|
-
.
|
|
1219
|
-
.
|
|
1220
|
-
this.
|
|
1221
|
-
.
|
|
1222
|
-
.
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
.
|
|
1226
|
-
|
|
1227
|
-
|
|
1177
|
+
.domain([config.yDomainMin || 0, config.yDomainMax || 100])
|
|
1178
|
+
.range([this.height, 0]);
|
|
1179
|
+
this.line = line()
|
|
1180
|
+
.x((d, i) => {
|
|
1181
|
+
return this.getXFormat(config.xFormat, d, i);
|
|
1182
|
+
})
|
|
1183
|
+
.y((d) => {
|
|
1184
|
+
return this.yScale(d.value);
|
|
1185
|
+
});
|
|
1186
|
+
this.area = area()
|
|
1187
|
+
.x((d, i) => {
|
|
1188
|
+
return this.getXFormat(config.xFormat, d, i);
|
|
1189
|
+
})
|
|
1190
|
+
.y0(this.height)
|
|
1191
|
+
.y1((d) => {
|
|
1192
|
+
return this.yScale(d.value);
|
|
1193
|
+
});
|
|
1228
1194
|
}
|
|
1229
1195
|
drawChart(chartElm, config) {
|
|
1230
1196
|
this.buildContainer(chartElm);
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
}
|
|
1197
|
+
if (!config.hideAxis) {
|
|
1198
|
+
this.axisBuilder.drawAxis({
|
|
1199
|
+
svg: this.svg,
|
|
1200
|
+
numberOfTicks: config.numberOfTicks || 5,
|
|
1201
|
+
height: this.height,
|
|
1202
|
+
xScale: this.xScale,
|
|
1203
|
+
yScale: this.yScale,
|
|
1204
|
+
yFormat: config.yFormat
|
|
1205
|
+
});
|
|
1206
|
+
}
|
|
1241
1207
|
if (!config.hideGrid) {
|
|
1242
1208
|
this.gridBuilder.drawHorizontalGrid({
|
|
1243
1209
|
svg: this.svg,
|
|
1244
1210
|
numberOfTicks: config.numberOfTicks || 5,
|
|
1245
1211
|
width: this.width,
|
|
1246
|
-
xScale: this.
|
|
1212
|
+
xScale: this.xScale,
|
|
1247
1213
|
yScale: this.yScale
|
|
1248
1214
|
});
|
|
1249
1215
|
}
|
|
1250
|
-
this.
|
|
1216
|
+
this.drawLineArea(config);
|
|
1217
|
+
if (config.enableEffects) {
|
|
1218
|
+
this.drawEffects(config);
|
|
1219
|
+
}
|
|
1220
|
+
this.drawDots(config);
|
|
1251
1221
|
}
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
.
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
.
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1222
|
+
drawLineArea(config) {
|
|
1223
|
+
for (let i = 0; i < config.data.length; i++) {
|
|
1224
|
+
if (config.isArea) {
|
|
1225
|
+
this.drawArea(config.data[i].data, i);
|
|
1226
|
+
}
|
|
1227
|
+
this.drawLine(config.data[i].data, i, config.data[i].hide);
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
drawLine(lineData, index, hide = false) {
|
|
1231
|
+
this.svg.append('g')
|
|
1232
|
+
.attr('class', 'lines')
|
|
1233
|
+
.append('path')
|
|
1234
|
+
.datum(lineData)
|
|
1235
|
+
.attr('class', 'line')
|
|
1236
|
+
.attr('d', this.line(this.startData))
|
|
1237
|
+
.transition()
|
|
1238
|
+
.duration(this.transitionService.getTransitionDuration())
|
|
1239
|
+
.attr('d', this.line) // TODO: strongly type
|
|
1240
|
+
.attr('stroke', () => {
|
|
1241
|
+
return this.colors[index];
|
|
1261
1242
|
})
|
|
1262
|
-
.attr('
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1243
|
+
.attr('fill', 'none')
|
|
1244
|
+
.attr('style', () => hide ? 'display: none' : null);
|
|
1245
|
+
}
|
|
1246
|
+
drawArea(lineData, index) {
|
|
1247
|
+
this.svg.append('g')
|
|
1248
|
+
.attr('class', 'areas')
|
|
1249
|
+
.append('path')
|
|
1250
|
+
.datum(lineData)
|
|
1251
|
+
.attr('class', 'area')
|
|
1252
|
+
.style('opacity', 0.5)
|
|
1253
|
+
.style('fill', () => {
|
|
1254
|
+
return this.colors[index]; // TODO: strongly type
|
|
1255
|
+
})
|
|
1256
|
+
.attr('d', this.line(this.startData))
|
|
1257
|
+
.transition()
|
|
1258
|
+
.duration(this.transitionService.getTransitionDuration())
|
|
1259
|
+
.attr('d', this.area); // TODO: strongly type
|
|
1260
|
+
}
|
|
1261
|
+
drawEffects(config) {
|
|
1262
|
+
if (config.enableEffects) {
|
|
1263
|
+
const effectsBuilder = new LineAreaChartEffectsBuilder();
|
|
1264
|
+
effectsBuilder.buildEffects({
|
|
1265
|
+
svg: this.svg,
|
|
1266
|
+
height: this.height,
|
|
1267
|
+
width: this.width,
|
|
1268
|
+
data: config.data,
|
|
1269
|
+
colors: this.colors,
|
|
1270
|
+
x: this.xScale,
|
|
1271
|
+
y: this.yScale
|
|
1272
|
+
});
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
drawDots(config) {
|
|
1276
|
+
const self = this;
|
|
1277
|
+
for (let index = 0; index < config.data.length; index++) {
|
|
1278
|
+
this.svg.append('g')
|
|
1279
|
+
.attr('class', 'dots')
|
|
1280
|
+
.selectAll('.dot')
|
|
1281
|
+
.data(config.data[index].data)
|
|
1282
|
+
.enter().append('circle')
|
|
1283
|
+
.attr('class', 'dot')
|
|
1284
|
+
.attr('stroke', (d) => {
|
|
1285
|
+
return this.colors[index];
|
|
1286
|
+
})
|
|
1287
|
+
.attr('cx', (d, i) => {
|
|
1288
|
+
return this.getXFormat(config.xFormat, d, i);
|
|
1289
|
+
})
|
|
1290
|
+
.attr('cy', (d) => {
|
|
1291
|
+
return this.yScale(0);
|
|
1292
|
+
})
|
|
1293
|
+
.attr('fill', '#fff')
|
|
1294
|
+
.on('mouseover', function (event, d) {
|
|
1295
|
+
self.tooltipBuilder.showBarTooltip(event, d, self.config.yFormat, self.config.xFormat);
|
|
1296
|
+
select$1(this)
|
|
1297
|
+
.transition()
|
|
1298
|
+
.duration(self.transitionService.getTransitionDuration() / 3)
|
|
1299
|
+
.attr('r', 6)
|
|
1300
|
+
.attr('fill', self.colors[index]);
|
|
1301
|
+
})
|
|
1302
|
+
.on('mouseout', function () {
|
|
1303
|
+
self.tooltipBuilder.hideTooltip();
|
|
1304
|
+
select$1(this)
|
|
1305
|
+
.transition()
|
|
1306
|
+
.duration(self.transitionService.getTransitionDuration() / 3)
|
|
1307
|
+
.attr('r', 4)
|
|
1308
|
+
.attr('fill', '#fff');
|
|
1309
|
+
})
|
|
1310
|
+
.on('click', (d, i) => {
|
|
1311
|
+
this.dotClickedSource.next(d);
|
|
1312
|
+
})
|
|
1313
|
+
.transition()
|
|
1314
|
+
.duration(this.transitionService.getTransitionDuration())
|
|
1315
|
+
.attr('cy', (d) => {
|
|
1316
|
+
return this.yScale(d.value);
|
|
1317
|
+
})
|
|
1318
|
+
.attr('r', 4)
|
|
1319
|
+
.attr('style', () => config.data[index].hide ? 'display: none' : null);
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
getXFormat(type, data, index) {
|
|
1323
|
+
switch (type) {
|
|
1324
|
+
case PcacFormatEnum.DateTime:
|
|
1325
|
+
if (data.key) {
|
|
1326
|
+
return this.xScale(new Date(data.key));
|
|
1327
|
+
}
|
|
1328
|
+
return 0;
|
|
1329
|
+
default:
|
|
1330
|
+
return this.xScale(index);
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: LineAreaChartBuilder, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
|
1334
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: LineAreaChartBuilder, providedIn: 'root' });
|
|
1335
|
+
}
|
|
1336
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: LineAreaChartBuilder, decorators: [{
|
|
1337
|
+
type: Injectable,
|
|
1338
|
+
args: [{
|
|
1339
|
+
providedIn: 'root',
|
|
1340
|
+
}]
|
|
1341
|
+
}] });
|
|
1342
|
+
|
|
1343
|
+
class PcacLineAreaChartComponent {
|
|
1344
|
+
chartBuilder = inject(LineAreaChartBuilder);
|
|
1345
|
+
config = input.required(...(ngDevMode ? [{ debugName: "config" }] : []));
|
|
1346
|
+
chartElm = viewChild.required('chart');
|
|
1347
|
+
dotClicked = output();
|
|
1348
|
+
resizeWindowTimeout;
|
|
1349
|
+
constructor() {
|
|
1350
|
+
this.chartBuilder.dotClicked$.subscribe(data => {
|
|
1351
|
+
this.dotClicked.emit(data);
|
|
1268
1352
|
});
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
if (
|
|
1272
|
-
|
|
1273
|
-
}
|
|
1274
|
-
// Draw threshold across entire chart
|
|
1275
|
-
if (config.thresholds.length === 1 && !config.thresholds[0].data) {
|
|
1276
|
-
this.drawThresholdAcrossChart(config);
|
|
1277
|
-
}
|
|
1278
|
-
// Draw threshold across each group
|
|
1279
|
-
if (config.thresholds.length > 1 && (!config.thresholds[0].data || config.isStacked)) {
|
|
1280
|
-
this.drawThresholdsPerGroup(group, config);
|
|
1353
|
+
}
|
|
1354
|
+
ngOnChanges(changes) {
|
|
1355
|
+
if (changes['config'].currentValue !== changes['config'].previousValue) {
|
|
1356
|
+
this.buildChart();
|
|
1281
1357
|
}
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1358
|
+
}
|
|
1359
|
+
buildChart() {
|
|
1360
|
+
const config = this.config();
|
|
1361
|
+
console.log('Building chart with config:', config);
|
|
1362
|
+
if (config && config.data && config.data.length > 0) {
|
|
1363
|
+
this.chartBuilder.buildChart(this.chartElm(), config);
|
|
1285
1364
|
}
|
|
1286
1365
|
}
|
|
1287
|
-
|
|
1366
|
+
/**
|
|
1367
|
+
* Opting against fromEvent due to incompatibility with rxjs 5 => 6
|
|
1368
|
+
*/
|
|
1369
|
+
onResize() {
|
|
1288
1370
|
const self = this;
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
.
|
|
1292
|
-
|
|
1293
|
-
return value ? value : 0;
|
|
1294
|
-
})
|
|
1295
|
-
.attr('data-group-bar-id', (_, i) => {
|
|
1296
|
-
return i;
|
|
1297
|
-
})
|
|
1298
|
-
.style('fill', (d, i, n) => {
|
|
1299
|
-
if (config.spreadColorsPerGroup) {
|
|
1300
|
-
const groupIndex = parseInt(n[0].parentNode.getAttribute('data-group-id'), 10);
|
|
1301
|
-
return this.colors[groupIndex];
|
|
1302
|
-
}
|
|
1303
|
-
return this.colors[i];
|
|
1304
|
-
})
|
|
1305
|
-
.attr('y', () => {
|
|
1306
|
-
return this.height;
|
|
1307
|
-
})
|
|
1308
|
-
.attr('height', 0)
|
|
1309
|
-
.on('mouseover', function (event, d) {
|
|
1310
|
-
select$1(this).transition(transition()
|
|
1311
|
-
.duration(self.transitionService.getTransitionDuration() / 5))
|
|
1312
|
-
.style('fill', () => {
|
|
1313
|
-
if (config.spreadColorsPerGroup) {
|
|
1314
|
-
const groupIndex = parseInt(this.parentNode.getAttribute('data-group-id'), 10);
|
|
1315
|
-
const c = color(self.colors[groupIndex]);
|
|
1316
|
-
const ct = c ? c.darker(1).toString() : self.colors[groupIndex];
|
|
1317
|
-
return ct;
|
|
1318
|
-
}
|
|
1319
|
-
const groupIndex = parseInt(this.getAttribute('data-group-bar-id'), 10);
|
|
1320
|
-
const c = color(self.colors[groupIndex]);
|
|
1321
|
-
const ct = c ? c.darker(1).toString() : self.colors[groupIndex];
|
|
1322
|
-
return ct;
|
|
1323
|
-
});
|
|
1324
|
-
})
|
|
1325
|
-
.on('mousemove', (event, d) => {
|
|
1326
|
-
self.tooltipBuilder.showBarTooltip(event, d, config.tickFormat || PcacFormatEnum.None);
|
|
1327
|
-
})
|
|
1328
|
-
.on('mouseout', function (d) {
|
|
1329
|
-
self.tooltipBuilder.hideTooltip();
|
|
1330
|
-
select$1(this).transition(transition()
|
|
1331
|
-
.duration(self.transitionService.getTransitionDuration() / 5))
|
|
1332
|
-
.style('fill', () => {
|
|
1333
|
-
if (config.spreadColorsPerGroup) {
|
|
1334
|
-
const groupIndex = parseInt(this.parentNode.getAttribute('data-group-id'), 10);
|
|
1335
|
-
return self.colors[groupIndex];
|
|
1336
|
-
}
|
|
1337
|
-
const groupIndex = parseInt(this.getAttribute('data-group-bar-id'), 10);
|
|
1338
|
-
return self.colors[groupIndex];
|
|
1339
|
-
});
|
|
1340
|
-
})
|
|
1341
|
-
.on('click', (_, d) => {
|
|
1342
|
-
this.barClickedSource.next(d);
|
|
1343
|
-
})
|
|
1344
|
-
.transition(transition()
|
|
1345
|
-
.duration(this.transitionService.getTransitionDuration()))
|
|
1346
|
-
.attr('width', !config.isStacked ? this.xScaleGrouped.bandwidth() : this.xScaleStacked.bandwidth())
|
|
1347
|
-
.attr('y', (d) => {
|
|
1348
|
-
return this.yScale(d.value);
|
|
1349
|
-
})
|
|
1350
|
-
.attr('height', (d) => {
|
|
1351
|
-
return this.height - this.yScale(d.value);
|
|
1352
|
-
});
|
|
1371
|
+
clearTimeout(this.resizeWindowTimeout);
|
|
1372
|
+
this.resizeWindowTimeout = setTimeout(() => {
|
|
1373
|
+
self.buildChart();
|
|
1374
|
+
}, 300);
|
|
1353
1375
|
}
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1376
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: PcacLineAreaChartComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1377
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "20.3.0", type: PcacLineAreaChartComponent, isStandalone: true, selector: "pcac-line-area-chart", inputs: { config: { classPropertyName: "config", publicName: "config", 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}\n"], encapsulation: i0.ViewEncapsulation.None });
|
|
1378
|
+
}
|
|
1379
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: PcacLineAreaChartComponent, decorators: [{
|
|
1380
|
+
type: Component,
|
|
1381
|
+
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}\n"] }]
|
|
1382
|
+
}], ctorParameters: () => [], propDecorators: { onResize: [{
|
|
1383
|
+
type: HostListener,
|
|
1384
|
+
args: ['window:resize']
|
|
1385
|
+
}] } });
|
|
1386
|
+
|
|
1387
|
+
class PcacLineAreaChartConfig extends PcacChartConfig {
|
|
1388
|
+
isArea = false;
|
|
1389
|
+
enableEffects = true;
|
|
1390
|
+
numberOfTicks = 5;
|
|
1391
|
+
hideGrid = false;
|
|
1392
|
+
hideAxis = false;
|
|
1393
|
+
yFormat = PcacFormatEnum.None;
|
|
1394
|
+
xFormat = PcacFormatEnum.None;
|
|
1395
|
+
yDomainMax;
|
|
1396
|
+
yDomainMin;
|
|
1397
|
+
xDomainMin;
|
|
1398
|
+
xDomainMax;
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
class PieChartBuilder extends PcacChart {
|
|
1402
|
+
radius;
|
|
1403
|
+
arcShape;
|
|
1404
|
+
arcOverShape;
|
|
1405
|
+
pieAngles;
|
|
1406
|
+
sliceClickedSource = new Subject();
|
|
1407
|
+
sliceClicked$ = this.sliceClickedSource.asObservable();
|
|
1408
|
+
buildChart(chartElm, config) {
|
|
1409
|
+
this.initializeChartState(chartElm, config);
|
|
1410
|
+
this.radius = Math.min(Math.min(this.height, this.width), Math.min(this.height, this.width)) / 2;
|
|
1411
|
+
this.buildShapes(config);
|
|
1412
|
+
this.drawChart(chartElm, config);
|
|
1368
1413
|
}
|
|
1369
|
-
|
|
1370
|
-
const
|
|
1371
|
-
this.
|
|
1372
|
-
.
|
|
1373
|
-
.
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
.
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
config.thresholds[index], config.tickFormat || PcacFormatEnum.None);
|
|
1381
|
-
})
|
|
1382
|
-
.transition(transition()
|
|
1383
|
-
.duration(this.transitionService.getTransitionDuration()))
|
|
1384
|
-
.attr('y', (d, i) => {
|
|
1385
|
-
return this.yScale(config.isStacked ? config.thresholds[i].data[0].value : config.thresholds[i].value);
|
|
1386
|
-
});
|
|
1414
|
+
buildShapes(config) {
|
|
1415
|
+
const radiusOffset = 10;
|
|
1416
|
+
this.arcShape = arc()
|
|
1417
|
+
.innerRadius(0)
|
|
1418
|
+
.outerRadius(this.radius - radiusOffset);
|
|
1419
|
+
this.arcOverShape = arc()
|
|
1420
|
+
.innerRadius(0)
|
|
1421
|
+
.outerRadius(this.radius - radiusOffset + radiusOffset);
|
|
1422
|
+
this.pieAngles = pie()
|
|
1423
|
+
.sort(null)
|
|
1424
|
+
.value((d) => d.value); // TODO: Strongly type
|
|
1387
1425
|
}
|
|
1388
|
-
|
|
1426
|
+
drawChart(chartElm, config) {
|
|
1427
|
+
this.buildContainer(chartElm, true);
|
|
1389
1428
|
const self = this;
|
|
1390
|
-
this.
|
|
1391
|
-
.
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
.
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
self.tooltipBuilder.showBarTooltip(event, config.thresholds[Number(this.parentElement.dataset['groupId'])].data[index], config.tickFormat || PcacFormatEnum.None);
|
|
1398
|
-
})
|
|
1399
|
-
.attr('width', this.xScaleGrouped.bandwidth())
|
|
1400
|
-
.transition(transition()
|
|
1401
|
-
.duration(this.transitionService.getTransitionDuration()))
|
|
1402
|
-
.attr('y', (d, i, n) => {
|
|
1403
|
-
return this.yScale(config.thresholds[n[0].parentElement.dataset['groupId']].data[i].value);
|
|
1404
|
-
});
|
|
1405
|
-
}
|
|
1406
|
-
applyPreTransitionThresholdStyles(elm, config) {
|
|
1407
|
-
return elm.attr('class', 'pcac-threshold')
|
|
1408
|
-
.attr('x', (d) => {
|
|
1409
|
-
return this.xScaleGrouped(d ? d.key : '');
|
|
1410
|
-
})
|
|
1411
|
-
.attr('y', () => {
|
|
1412
|
-
return this.height;
|
|
1429
|
+
this.svg.selectAll('.pcac-arc')
|
|
1430
|
+
.data(this.pieAngles(config.data))
|
|
1431
|
+
.enter().append('g')
|
|
1432
|
+
.attr('class', 'pcac-arc')
|
|
1433
|
+
.append('path')
|
|
1434
|
+
.style('fill', (d, i) => {
|
|
1435
|
+
return this.colors[i];
|
|
1413
1436
|
})
|
|
1414
|
-
.
|
|
1415
|
-
.
|
|
1416
|
-
|
|
1437
|
+
.on('mouseover', function (_, d) {
|
|
1438
|
+
const t = transition().duration(self.transitionService.getTransitionDuration() / 3);
|
|
1439
|
+
const c = color(self.colors[d.index]);
|
|
1440
|
+
const ct = c ? c.darker(1).toString() : self.colors[d.index];
|
|
1441
|
+
select$1(this).transition(t)
|
|
1442
|
+
.attr('d', self.arcOverShape)
|
|
1443
|
+
.style('fill', ct);
|
|
1417
1444
|
})
|
|
1418
|
-
.
|
|
1419
|
-
|
|
1445
|
+
.on('mousemove', (event, d) => {
|
|
1446
|
+
self.tooltipBuilder.showBarTooltip(event, d.data);
|
|
1420
1447
|
})
|
|
1421
|
-
.
|
|
1422
|
-
|
|
1448
|
+
.on('mouseout', function (_, d) {
|
|
1449
|
+
self.tooltipBuilder.hideTooltip();
|
|
1450
|
+
select$1(this)
|
|
1451
|
+
.transition()
|
|
1452
|
+
.duration(self.transitionService.getTransitionDuration() / 3)
|
|
1453
|
+
.attr('d', self.arcShape)
|
|
1454
|
+
.style('fill', self.colors[d.index]);
|
|
1423
1455
|
})
|
|
1424
|
-
.on('
|
|
1425
|
-
this.
|
|
1456
|
+
.on('click', (d, i) => {
|
|
1457
|
+
this.sliceClickedSource.next(d.data);
|
|
1426
1458
|
})
|
|
1427
|
-
.
|
|
1428
|
-
|
|
1459
|
+
.transition()
|
|
1460
|
+
.duration(this.transitionService.getTransitionDuration())
|
|
1461
|
+
.attrTween('d', (b) => {
|
|
1462
|
+
return this.tweenChart(b);
|
|
1429
1463
|
});
|
|
1430
1464
|
}
|
|
1431
|
-
|
|
1432
|
-
|
|
1465
|
+
tweenChart(b) {
|
|
1466
|
+
b.innerRadius = 0;
|
|
1467
|
+
const i = interpolate({ startAngle: 0, endAngle: 0 }, b);
|
|
1468
|
+
return (t) => this.arcShape(i(t)); // TODO: Strongly type
|
|
1469
|
+
}
|
|
1470
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: PieChartBuilder, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
|
1471
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: PieChartBuilder, providedIn: 'root' });
|
|
1433
1472
|
}
|
|
1434
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.
|
|
1473
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: PieChartBuilder, decorators: [{
|
|
1435
1474
|
type: Injectable,
|
|
1436
1475
|
args: [{
|
|
1437
1476
|
providedIn: 'root',
|
|
1438
1477
|
}]
|
|
1439
1478
|
}] });
|
|
1440
1479
|
|
|
1441
|
-
class
|
|
1442
|
-
chartBuilder = inject(
|
|
1480
|
+
class PcacPieChartComponent {
|
|
1481
|
+
chartBuilder = inject(PieChartBuilder);
|
|
1443
1482
|
config = input.required(...(ngDevMode ? [{ debugName: "config" }] : []));
|
|
1444
1483
|
chartElm = viewChild.required('chart');
|
|
1445
|
-
|
|
1484
|
+
sliceClicked = output();
|
|
1446
1485
|
resizeWindowTimeout;
|
|
1447
1486
|
constructor() {
|
|
1448
|
-
this.chartBuilder.
|
|
1449
|
-
this.
|
|
1487
|
+
this.chartBuilder.sliceClicked$.subscribe(data => {
|
|
1488
|
+
this.sliceClicked.emit(data);
|
|
1450
1489
|
});
|
|
1451
1490
|
}
|
|
1452
1491
|
ngOnChanges() {
|
|
@@ -1468,30 +1507,22 @@ class PcacBarVerticalChartComponent {
|
|
|
1468
1507
|
self.buildChart();
|
|
1469
1508
|
}, 300);
|
|
1470
1509
|
}
|
|
1471
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.
|
|
1472
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "20.
|
|
1510
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: PcacPieChartComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1511
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "20.3.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 });
|
|
1473
1512
|
}
|
|
1474
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.
|
|
1513
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: PcacPieChartComponent, decorators: [{
|
|
1475
1514
|
type: Component,
|
|
1476
|
-
args: [{ selector: 'pcac-
|
|
1515
|
+
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"] }]
|
|
1477
1516
|
}], ctorParameters: () => [], propDecorators: { onResize: [{
|
|
1478
1517
|
type: HostListener,
|
|
1479
1518
|
args: ['window:resize']
|
|
1480
1519
|
}] } });
|
|
1481
1520
|
|
|
1482
|
-
class
|
|
1483
|
-
domainMax = 100;
|
|
1521
|
+
class PcacPieChartConfig extends PcacChartConfig {
|
|
1484
1522
|
numberOfTicks = 5;
|
|
1485
|
-
isStacked = false;
|
|
1486
|
-
thresholds = [];
|
|
1487
|
-
tickFormat = PcacFormatEnum.None;
|
|
1488
|
-
hideGrid = false;
|
|
1489
|
-
hideAxis = false;
|
|
1490
|
-
spreadColorsPerGroup = false;
|
|
1491
|
-
colorOverride = new PcacBarVerticalChartColorOverrideConfig();
|
|
1492
1523
|
}
|
|
1493
|
-
|
|
1494
|
-
|
|
1524
|
+
|
|
1525
|
+
class PcacScatterPlotConfig extends PcacChartConfig {
|
|
1495
1526
|
}
|
|
1496
1527
|
|
|
1497
1528
|
/*
|
|
@@ -1502,5 +1533,5 @@ class PcacBarVerticalChartColorOverrideConfig {
|
|
|
1502
1533
|
* Generated bundle index. Do not edit.
|
|
1503
1534
|
*/
|
|
1504
1535
|
|
|
1505
|
-
export { BarHorizontalChartBuilder, BarVerticalChartBuilder, LineAreaChartBuilder, PcacAxisBuilder, PcacBarHorizontalChartColorOverrideConfig, PcacBarHorizontalChartComponent, PcacBarHorizontalChartConfig, PcacBarVerticalChartColorOverrideConfig, PcacBarVerticalChartComponent, PcacBarVerticalChartConfig, PcacChart, PcacChartConfig, PcacColorService, PcacData, PcacFormatEnum, PcacGridBuilder, PcacLineAreaChartComponent, PcacLineAreaChartConfig, PcacPieChartComponent, PcacPieChartConfig, PcacTooltipBuilder, PcacTransitionService, PieChartBuilder };
|
|
1536
|
+
export { BarHorizontalChartBuilder, BarVerticalChartBuilder, LineAreaChartBuilder, PcacAxisBuilder, PcacBarHorizontalChartColorOverrideConfig, PcacBarHorizontalChartComponent, PcacBarHorizontalChartConfig, PcacBarVerticalChartColorOverrideConfig, PcacBarVerticalChartComponent, PcacBarVerticalChartConfig, PcacChart, PcacChartConfig, PcacColorService, PcacData, PcacFormatEnum, PcacGridBuilder, PcacLineAreaChartComponent, PcacLineAreaChartConfig, PcacPieChartComponent, PcacPieChartConfig, PcacScatterPlotConfig, PcacTooltipBuilder, PcacTransitionService, PieChartBuilder };
|
|
1506
1537
|
//# sourceMappingURL=pioneer-code-pioneer-charts.mjs.map
|