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