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