@pioneer-code/pioneer-charts 1.0.8 → 1.0.10

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.
Files changed (23) hide show
  1. package/esm2022/lib/bar-chart/bar-horizontal-chart/bar-horizontal-chart.builder.mjs +8 -8
  2. package/esm2022/lib/bar-chart/bar-horizontal-chart/bar-horizontal-chart.model.mjs +1 -1
  3. package/esm2022/lib/bar-chart/bar-vertical-chart/bar-vertical-chart.builder.mjs +8 -8
  4. package/esm2022/lib/bar-chart/bar-vertical-chart/bar-vertical-chart.model.mjs +1 -1
  5. package/esm2022/lib/core/axis.builder.mjs +12 -7
  6. package/esm2022/lib/core/chart.model.mjs +9 -7
  7. package/esm2022/lib/core/tooltip.builder.mjs +26 -10
  8. package/esm2022/lib/line-area-chart/line-area-chart-effects.builders.mjs +3 -2
  9. package/esm2022/lib/line-area-chart/line-area-chart.builder.mjs +32 -10
  10. package/esm2022/lib/line-area-chart/line-area-chart.component.mjs +8 -2
  11. package/esm2022/lib/line-area-chart/line-area-chart.model.mjs +1 -1
  12. package/fesm2022/pioneer-code-pioneer-charts.mjs +94 -44
  13. package/fesm2022/pioneer-code-pioneer-charts.mjs.map +1 -1
  14. package/lib/bar-chart/bar-horizontal-chart/bar-horizontal-chart.model.d.ts +2 -2
  15. package/lib/bar-chart/bar-vertical-chart/bar-vertical-chart.model.d.ts +2 -2
  16. package/lib/core/axis.builder.d.ts +3 -3
  17. package/lib/core/chart.model.d.ts +4 -2
  18. package/lib/core/tooltip.builder.d.ts +2 -2
  19. package/lib/line-area-chart/line-area-chart-effects.builders.d.ts +3 -2
  20. package/lib/line-area-chart/line-area-chart.builder.d.ts +1 -0
  21. package/lib/line-area-chart/line-area-chart.component.d.ts +2 -1
  22. package/lib/line-area-chart/line-area-chart.model.d.ts +9 -5
  23. package/package.json +1 -1
@@ -2,7 +2,7 @@ import { axisLeft, axisBottom } from 'd3-axis';
2
2
  import { select as select$1 } from 'd3-selection';
3
3
  import * as i0 from '@angular/core';
4
4
  import { Injectable, EventEmitter, Component, ViewEncapsulation, Input, ViewChild, Output, HostListener, NgModule } from '@angular/core';
5
- import { select } from 'd3';
5
+ import { select, scaleTime } from 'd3';
6
6
  import { transition } from 'd3-transition';
7
7
  import { scaleLinear, scaleBand } from 'd3-scale';
8
8
  import { line, area, arc, pie } from 'd3-shape';
@@ -12,12 +12,14 @@ import { CommonModule } from '@angular/common';
12
12
  import { interpolate } from 'd3-interpolate';
13
13
  import { color } from 'd3-color';
14
14
 
15
- var PcacTickFormatEnum;
16
- (function (PcacTickFormatEnum) {
17
- PcacTickFormatEnum["None"] = "none";
18
- PcacTickFormatEnum["Percentage"] = "percentage";
19
- PcacTickFormatEnum["Minutes"] = "minutes";
20
- })(PcacTickFormatEnum || (PcacTickFormatEnum = {}));
15
+ var PcacFormatEnum;
16
+ (function (PcacFormatEnum) {
17
+ PcacFormatEnum["None"] = "none";
18
+ PcacFormatEnum["Percentage"] = "percentage";
19
+ PcacFormatEnum["Minutes"] = "minutes";
20
+ PcacFormatEnum["DateTime"] = "dateTime";
21
+ PcacFormatEnum["Fahrenheit"] = "fahrenheit";
22
+ })(PcacFormatEnum || (PcacFormatEnum = {}));
21
23
 
22
24
  class PcacAxisBuilder {
23
25
  drawAxis(config) {
@@ -32,13 +34,15 @@ class PcacAxisBuilder {
32
34
  const yAxis = axisLeft(config.yScale).ticks(config.numberOfTicks);
33
35
  if (config.yFormat) {
34
36
  switch (config.yFormat.toLocaleLowerCase()) {
35
- case PcacTickFormatEnum.Percentage:
36
- // let f = format('.0%') No longer works
37
+ case PcacFormatEnum.Percentage:
37
38
  yAxis.tickFormat(d => d + "%");
38
39
  break;
39
- case PcacTickFormatEnum.Minutes:
40
+ case PcacFormatEnum.Minutes:
40
41
  yAxis.tickFormat((d) => d + 'm');
41
42
  break;
43
+ case PcacFormatEnum.Fahrenheit:
44
+ yAxis.tickFormat((d) => d + ' F');
45
+ break;
42
46
  }
43
47
  }
44
48
  config.svg.append('g')
@@ -49,12 +53,15 @@ class PcacAxisBuilder {
49
53
  const xAxis = axisBottom(config.xScale).ticks(config.numberOfTicks);
50
54
  if (config.xFormat) {
51
55
  switch (config.xFormat.toLocaleLowerCase()) {
52
- case PcacTickFormatEnum.Percentage:
56
+ case PcacFormatEnum.Percentage:
53
57
  xAxis.tickFormat(d => d + "%");
54
58
  break;
55
- case PcacTickFormatEnum.Minutes:
59
+ case PcacFormatEnum.Minutes:
56
60
  xAxis.tickFormat((d) => d + 'm');
57
61
  break;
62
+ case PcacFormatEnum.Fahrenheit:
63
+ xAxis.tickFormat((d) => d + 'f');
64
+ break;
58
65
  }
59
66
  }
60
67
  config.svg.append('g')
@@ -133,27 +140,43 @@ class PcacTooltipBuilder {
133
140
  .append('div')
134
141
  .attr('class', 'pcac-d3-tooltip'); // TODO: Strongly type
135
142
  }
136
- showBarTooltip(event, data, tickFormat) {
143
+ showBarTooltip(event, data, valueFormat, keyFormat) {
137
144
  this.tooltip.style('left', event.pageX - 60 + 'px')
138
145
  .style('top', event.pageY - 55 + 'px')
139
146
  .style('display', 'inline-block')
140
- .html(this.getBarTipData(data, tickFormat));
147
+ .html(this.getBarTipData(data, valueFormat, keyFormat));
141
148
  }
142
149
  hideTooltip() {
143
150
  this.tooltip.style('display', 'none');
144
151
  }
145
- getBarTipData(data, tickFormat) {
152
+ getBarTipData(data, valueFormat, keyFormat) {
146
153
  let value = data.value;
147
- if (tickFormat) {
148
- switch (tickFormat.toLocaleLowerCase()) {
149
- case PcacTickFormatEnum.Percentage:
154
+ let key = data.key;
155
+ if (valueFormat) {
156
+ switch (valueFormat) {
157
+ case PcacFormatEnum.Percentage:
150
158
  value = value * 100 + '%';
151
159
  break;
152
- case PcacTickFormatEnum.Minutes:
160
+ case PcacFormatEnum.Fahrenheit:
161
+ value = `${value} F`;
153
162
  break;
154
163
  }
155
164
  }
156
- return data.key ? data.key + '</br>' + value.toString() : value.toString();
165
+ if (keyFormat) {
166
+ switch (keyFormat) {
167
+ case PcacFormatEnum.DateTime:
168
+ key = new Date(key).toLocaleDateString('en-US', {
169
+ day: '2-digit',
170
+ month: '2-digit',
171
+ year: 'numeric',
172
+ hour: '2-digit',
173
+ minute: '2-digit',
174
+ second: '2-digit'
175
+ });
176
+ break;
177
+ }
178
+ }
179
+ return key ? key + '</br>' + value.toString() : value.toString();
157
180
  }
158
181
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacTooltipBuilder, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
159
182
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacTooltipBuilder, providedIn: 'root' }); }
@@ -425,8 +448,9 @@ class LineAreaChartEffectsBuilder {
425
448
  break;
426
449
  }
427
450
  }
451
+ let textTarget = this.config.y.invert(pos.y);
428
452
  select$1(nodes[index]).select('text')
429
- .text(this.config.y.invert(pos.y).toFixed(0));
453
+ .text(textTarget.toFixed(0));
430
454
  return 'translate(' + mousePos[0] + ',' + pos.y + ')';
431
455
  });
432
456
  }
@@ -474,22 +498,30 @@ class LineAreaChartBuilder extends PcacChart {
474
498
  this.margin.right = 8;
475
499
  }
476
500
  buildScales(config) {
477
- this.xScale = scaleLinear()
478
- .domain([0, config.data[0].data.length - 1])
479
- .range([0, this.width]);
501
+ switch (config.xFormat) {
502
+ case PcacFormatEnum.DateTime:
503
+ this.xScale = scaleTime()
504
+ .domain([new Date(config.xDomainMin), new Date(config.xDomainMax)])
505
+ .range([0, this.width]);
506
+ break;
507
+ default:
508
+ this.xScale = scaleLinear()
509
+ .domain([0, config.data[0].data.length - 1])
510
+ .range([0, this.width]);
511
+ }
480
512
  this.yScale = scaleLinear()
481
- .domain([config.domainMin, config.domainMax])
513
+ .domain([config.yDomainMin || 0, config.yDomainMax || 100])
482
514
  .range([this.height, 0]);
483
515
  this.line = line()
484
516
  .x((d, i) => {
485
- return this.xScale(i);
517
+ return this.getXFormat(config.xFormat, d, i);
486
518
  })
487
519
  .y((d) => {
488
520
  return this.yScale(d.value);
489
521
  });
490
522
  this.area = area()
491
523
  .x((d, i) => {
492
- return this.xScale(i);
524
+ return this.getXFormat(config.xFormat, d, i);
493
525
  })
494
526
  .y0(this.height)
495
527
  .y1((d) => {
@@ -504,7 +536,8 @@ class LineAreaChartBuilder extends PcacChart {
504
536
  numberOfTicks: config.numberOfTicks || 5,
505
537
  height: this.height,
506
538
  xScale: this.xScale,
507
- yScale: this.yScale
539
+ yScale: this.yScale,
540
+ yFormat: config.yFormat
508
541
  });
509
542
  }
510
543
  if (!config.hideGrid) {
@@ -587,14 +620,14 @@ class LineAreaChartBuilder extends PcacChart {
587
620
  return this.colors[index];
588
621
  })
589
622
  .attr('cx', (d, i) => {
590
- return this.xScale(i);
623
+ return this.getXFormat(config.xFormat, d, i);
591
624
  })
592
625
  .attr('cy', (d) => {
593
626
  return this.yScale(0);
594
627
  })
595
628
  .attr('fill', '#fff')
596
629
  .on('mouseover', function (event, d) {
597
- self.tooltipBuilder.showBarTooltip(event, d);
630
+ self.tooltipBuilder.showBarTooltip(event, d, self.config.yFormat, self.config.xFormat);
598
631
  select$1(this).transition(transition()
599
632
  .duration(self.transitionService.getTransitionDuration() / 3))
600
633
  .attr('r', 6)
@@ -618,6 +651,17 @@ class LineAreaChartBuilder extends PcacChart {
618
651
  .attr('r', 4);
619
652
  }
620
653
  }
654
+ getXFormat(type, data, index) {
655
+ switch (type) {
656
+ case PcacFormatEnum.DateTime:
657
+ if (data.key) {
658
+ return this.xScale(new Date(data.key));
659
+ }
660
+ return 0;
661
+ default:
662
+ return this.xScale(index);
663
+ }
664
+ }
621
665
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: LineAreaChartBuilder, deps: [{ token: PcacAxisBuilder }, { token: PcacGridBuilder }, { token: PcacTransitionService }, { token: PcacTooltipBuilder }, { token: PcacColorService }], target: i0.ɵɵFactoryTarget.Injectable }); }
622
666
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: LineAreaChartBuilder, providedIn: 'root' }); }
623
667
  }
@@ -643,6 +687,12 @@ class PcacLineAreaChartComponent {
643
687
  this.dotClicked.emit(data);
644
688
  });
645
689
  }
690
+ ngOnChanges(changes) {
691
+ if (changes['config'].currentValue !== changes['config'].previousValue) {
692
+ this.buildChart();
693
+ }
694
+ console.log(changes); // here you will get the data from parent once the input param is change
695
+ }
646
696
  buildChart() {
647
697
  if (this.config && this.config.data && this.config.data.length > 0) {
648
698
  this.chartBuilder.buildChart(this.chartElm, this.config);
@@ -659,7 +709,7 @@ class PcacLineAreaChartComponent {
659
709
  }, 300);
660
710
  }
661
711
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacLineAreaChartComponent, deps: [{ token: LineAreaChartBuilder }], target: i0.ɵɵFactoryTarget.Component }); }
662
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.1.6", type: PcacLineAreaChartComponent, selector: "pcac-line-area-chart", inputs: { config: "config" }, outputs: { dotClicked: "dotClicked" }, host: { listeners: { "window:resize": "onResize()" } }, viewQueries: [{ propertyName: "chartElm", first: true, predicate: ["chart"], descendants: true, static: 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;background-color:#fff}.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 }); }
712
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.1.6", type: PcacLineAreaChartComponent, selector: "pcac-line-area-chart", inputs: { config: "config" }, outputs: { dotClicked: "dotClicked" }, host: { listeners: { "window:resize": "onResize()" } }, viewQueries: [{ propertyName: "chartElm", first: true, predicate: ["chart"], descendants: true, static: 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;background-color:#fff}.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 }); }
663
713
  }
664
714
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacLineAreaChartComponent, decorators: [{
665
715
  type: Component,
@@ -909,8 +959,8 @@ class BarHorizontalChartBuilder extends PcacChart {
909
959
  height: this.height,
910
960
  xScale: this.xScale,
911
961
  yScale: this.yScaleStacked,
912
- xFormat: config.tickFormat || PcacTickFormatEnum.None,
913
- yFormat: PcacTickFormatEnum.None,
962
+ xFormat: config.tickFormat || PcacFormatEnum.None,
963
+ yFormat: PcacFormatEnum.None,
914
964
  hideXAxis: config.hideAxis
915
965
  });
916
966
  if (!config.hideGrid) {
@@ -995,7 +1045,7 @@ class BarHorizontalChartBuilder extends PcacChart {
995
1045
  });
996
1046
  })
997
1047
  .on('mousemove', (event, d) => {
998
- self.tooltipBuilder.showBarTooltip(event, d, config.tickFormat || PcacTickFormatEnum.None);
1048
+ self.tooltipBuilder.showBarTooltip(event, d, config.tickFormat || PcacFormatEnum.None);
999
1049
  })
1000
1050
  .on('mouseout', function (event, d) {
1001
1051
  self.tooltipBuilder.hideTooltip();
@@ -1026,7 +1076,7 @@ class BarHorizontalChartBuilder extends PcacChart {
1026
1076
  return i;
1027
1077
  })
1028
1078
  .on('mousemove', (event, _) => {
1029
- this.tooltipBuilder.showBarTooltip(event, config.thresholds[0], config.tickFormat || PcacTickFormatEnum.None);
1079
+ this.tooltipBuilder.showBarTooltip(event, config.thresholds[0], config.tickFormat || PcacFormatEnum.None);
1030
1080
  })
1031
1081
  .transition(transition()
1032
1082
  .duration(this.transitionService.getTransitionDuration()))
@@ -1045,7 +1095,7 @@ class BarHorizontalChartBuilder extends PcacChart {
1045
1095
  const index = Number(this.parentElement.dataset['groupId']);
1046
1096
  self.tooltipBuilder.showBarTooltip(event, config.isStacked ?
1047
1097
  config.thresholds[index].data[0] :
1048
- config.thresholds[index], config.tickFormat || PcacTickFormatEnum.None);
1098
+ config.thresholds[index], config.tickFormat || PcacFormatEnum.None);
1049
1099
  })
1050
1100
  .transition(transition()
1051
1101
  .duration(this.transitionService.getTransitionDuration()))
@@ -1063,7 +1113,7 @@ class BarHorizontalChartBuilder extends PcacChart {
1063
1113
  .on('mousemove', function (event, d, i, n) {
1064
1114
  const target = event.target;
1065
1115
  const index = Number(target.getAttribute("data-group-threshold-id"));
1066
- self.tooltipBuilder.showBarTooltip(event, config.thresholds[Number(this.parentElement.dataset['groupId'])].data[index], config.tickFormat || PcacTickFormatEnum.None);
1116
+ self.tooltipBuilder.showBarTooltip(event, config.thresholds[Number(this.parentElement.dataset['groupId'])].data[index], config.tickFormat || PcacFormatEnum.None);
1067
1117
  })
1068
1118
  .transition(transition()
1069
1119
  .duration(this.transitionService.getTransitionDuration()))
@@ -1227,8 +1277,8 @@ class BarVerticalChartBuilder extends PcacChart {
1227
1277
  height: this.height,
1228
1278
  xScale: this.xScaleStacked,
1229
1279
  yScale: this.yScale,
1230
- xFormat: PcacTickFormatEnum.None,
1231
- yFormat: config.tickFormat || PcacTickFormatEnum.None,
1280
+ xFormat: PcacFormatEnum.None,
1281
+ yFormat: config.tickFormat || PcacFormatEnum.None,
1232
1282
  hideYAxis: config.hideAxis
1233
1283
  });
1234
1284
  if (!config.hideGrid) {
@@ -1316,7 +1366,7 @@ class BarVerticalChartBuilder extends PcacChart {
1316
1366
  });
1317
1367
  })
1318
1368
  .on('mousemove', (event, d) => {
1319
- self.tooltipBuilder.showBarTooltip(event, d, config.tickFormat || PcacTickFormatEnum.None);
1369
+ self.tooltipBuilder.showBarTooltip(event, d, config.tickFormat || PcacFormatEnum.None);
1320
1370
  })
1321
1371
  .on('mouseout', function (d) {
1322
1372
  self.tooltipBuilder.hideTooltip();
@@ -1351,7 +1401,7 @@ class BarVerticalChartBuilder extends PcacChart {
1351
1401
  return i;
1352
1402
  })
1353
1403
  .on('mousemove', (event, d, i) => {
1354
- this.tooltipBuilder.showBarTooltip(event, config.thresholds[0], config.tickFormat || PcacTickFormatEnum.None);
1404
+ this.tooltipBuilder.showBarTooltip(event, config.thresholds[0], config.tickFormat || PcacFormatEnum.None);
1355
1405
  })
1356
1406
  .transition(transition()
1357
1407
  .duration(this.transitionService.getTransitionDuration()))
@@ -1370,7 +1420,7 @@ class BarVerticalChartBuilder extends PcacChart {
1370
1420
  const index = Number(this.parentElement.dataset['groupId']);
1371
1421
  self.tooltipBuilder.showBarTooltip(event, config.isStacked ?
1372
1422
  config.thresholds[index].data[0] :
1373
- config.thresholds[index], config.tickFormat || PcacTickFormatEnum.None);
1423
+ config.thresholds[index], config.tickFormat || PcacFormatEnum.None);
1374
1424
  })
1375
1425
  .transition(transition()
1376
1426
  .duration(this.transitionService.getTransitionDuration()))
@@ -1387,7 +1437,7 @@ class BarVerticalChartBuilder extends PcacChart {
1387
1437
  .on('mousemove', function (event, _) {
1388
1438
  const target = event.target;
1389
1439
  const index = Number(target.getAttribute("data-group-threshold-id"));
1390
- self.tooltipBuilder.showBarTooltip(event, config.thresholds[Number(this.parentElement.dataset['groupId'])].data[index], config.tickFormat || PcacTickFormatEnum.None);
1440
+ self.tooltipBuilder.showBarTooltip(event, config.thresholds[Number(this.parentElement.dataset['groupId'])].data[index], config.tickFormat || PcacFormatEnum.None);
1391
1441
  })
1392
1442
  .attr('width', this.xScaleGrouped.bandwidth())
1393
1443
  .transition(transition()
@@ -1500,5 +1550,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.6", ngImpor
1500
1550
  * Generated bundle index. Do not edit.
1501
1551
  */
1502
1552
 
1503
- export { BarHorizontalChartBuilder, BarVerticalChartBuilder, LineAreaChartBuilder, PcacAxisBuilder, PcacBarChartHorizontalComponent, PcacBarHorizontalChartModule, PcacBarVerticalChartComponent, PcacBarVerticalChartModule, PcacChart, PcacColorService, PcacGridBuilder, PcacLineAreaChartComponent, PcacLineAreaChartModule, PcacPieChartComponent, PcacPieChartModule, PcacTickFormatEnum, PcacTooltipBuilder, PcacTransitionService, PieChartBuilder };
1553
+ export { BarHorizontalChartBuilder, BarVerticalChartBuilder, LineAreaChartBuilder, PcacAxisBuilder, PcacBarChartHorizontalComponent, PcacBarHorizontalChartModule, PcacBarVerticalChartComponent, PcacBarVerticalChartModule, PcacChart, PcacColorService, PcacFormatEnum, PcacGridBuilder, PcacLineAreaChartComponent, PcacLineAreaChartModule, PcacPieChartComponent, PcacPieChartModule, PcacTooltipBuilder, PcacTransitionService, PieChartBuilder };
1504
1554
  //# sourceMappingURL=pioneer-code-pioneer-charts.mjs.map