@pioneer-code/pioneer-charts 1.0.8 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm2022/lib/bar-chart/bar-horizontal-chart/bar-horizontal-chart.builder.mjs +8 -8
- package/esm2022/lib/bar-chart/bar-horizontal-chart/bar-horizontal-chart.model.mjs +1 -1
- package/esm2022/lib/bar-chart/bar-vertical-chart/bar-vertical-chart.builder.mjs +8 -8
- package/esm2022/lib/bar-chart/bar-vertical-chart/bar-vertical-chart.model.mjs +1 -1
- package/esm2022/lib/core/axis.builder.mjs +12 -7
- package/esm2022/lib/core/chart.model.mjs +9 -7
- package/esm2022/lib/core/tooltip.builder.mjs +26 -10
- package/esm2022/lib/line-area-chart/line-area-chart-effects.builders.mjs +3 -2
- package/esm2022/lib/line-area-chart/line-area-chart.builder.mjs +32 -10
- package/esm2022/lib/line-area-chart/line-area-chart.model.mjs +1 -1
- package/fesm2022/pioneer-code-pioneer-charts.mjs +87 -43
- package/fesm2022/pioneer-code-pioneer-charts.mjs.map +1 -1
- package/lib/bar-chart/bar-horizontal-chart/bar-horizontal-chart.model.d.ts +2 -2
- package/lib/bar-chart/bar-vertical-chart/bar-vertical-chart.model.d.ts +2 -2
- package/lib/core/axis.builder.d.ts +3 -3
- package/lib/core/chart.model.d.ts +4 -2
- package/lib/core/tooltip.builder.d.ts +2 -2
- package/lib/line-area-chart/line-area-chart-effects.builders.d.ts +3 -2
- package/lib/line-area-chart/line-area-chart.builder.d.ts +1 -0
- package/lib/line-area-chart/line-area-chart.model.d.ts +9 -5
- 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
|
|
16
|
-
(function (
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
|
36
|
-
// let f = format('.0%') No longer works
|
|
37
|
+
case PcacFormatEnum.Percentage:
|
|
37
38
|
yAxis.tickFormat(d => d + "%");
|
|
38
39
|
break;
|
|
39
|
-
case
|
|
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
|
|
56
|
+
case PcacFormatEnum.Percentage:
|
|
53
57
|
xAxis.tickFormat(d => d + "%");
|
|
54
58
|
break;
|
|
55
|
-
case
|
|
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,
|
|
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,
|
|
147
|
+
.html(this.getBarTipData(data, valueFormat, keyFormat));
|
|
141
148
|
}
|
|
142
149
|
hideTooltip() {
|
|
143
150
|
this.tooltip.style('display', 'none');
|
|
144
151
|
}
|
|
145
|
-
getBarTipData(data,
|
|
152
|
+
getBarTipData(data, valueFormat, keyFormat) {
|
|
146
153
|
let value = data.value;
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
|
160
|
+
case PcacFormatEnum.Fahrenheit:
|
|
161
|
+
value = `${value} F`;
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
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
|
+
});
|
|
153
176
|
break;
|
|
154
177
|
}
|
|
155
178
|
}
|
|
156
|
-
return
|
|
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(
|
|
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
|
-
|
|
478
|
-
|
|
479
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
}
|
|
@@ -909,8 +953,8 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
909
953
|
height: this.height,
|
|
910
954
|
xScale: this.xScale,
|
|
911
955
|
yScale: this.yScaleStacked,
|
|
912
|
-
xFormat: config.tickFormat ||
|
|
913
|
-
yFormat:
|
|
956
|
+
xFormat: config.tickFormat || PcacFormatEnum.None,
|
|
957
|
+
yFormat: PcacFormatEnum.None,
|
|
914
958
|
hideXAxis: config.hideAxis
|
|
915
959
|
});
|
|
916
960
|
if (!config.hideGrid) {
|
|
@@ -995,7 +1039,7 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
995
1039
|
});
|
|
996
1040
|
})
|
|
997
1041
|
.on('mousemove', (event, d) => {
|
|
998
|
-
self.tooltipBuilder.showBarTooltip(event, d, config.tickFormat ||
|
|
1042
|
+
self.tooltipBuilder.showBarTooltip(event, d, config.tickFormat || PcacFormatEnum.None);
|
|
999
1043
|
})
|
|
1000
1044
|
.on('mouseout', function (event, d) {
|
|
1001
1045
|
self.tooltipBuilder.hideTooltip();
|
|
@@ -1026,7 +1070,7 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
1026
1070
|
return i;
|
|
1027
1071
|
})
|
|
1028
1072
|
.on('mousemove', (event, _) => {
|
|
1029
|
-
this.tooltipBuilder.showBarTooltip(event, config.thresholds[0], config.tickFormat ||
|
|
1073
|
+
this.tooltipBuilder.showBarTooltip(event, config.thresholds[0], config.tickFormat || PcacFormatEnum.None);
|
|
1030
1074
|
})
|
|
1031
1075
|
.transition(transition()
|
|
1032
1076
|
.duration(this.transitionService.getTransitionDuration()))
|
|
@@ -1045,7 +1089,7 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
1045
1089
|
const index = Number(this.parentElement.dataset['groupId']);
|
|
1046
1090
|
self.tooltipBuilder.showBarTooltip(event, config.isStacked ?
|
|
1047
1091
|
config.thresholds[index].data[0] :
|
|
1048
|
-
config.thresholds[index], config.tickFormat ||
|
|
1092
|
+
config.thresholds[index], config.tickFormat || PcacFormatEnum.None);
|
|
1049
1093
|
})
|
|
1050
1094
|
.transition(transition()
|
|
1051
1095
|
.duration(this.transitionService.getTransitionDuration()))
|
|
@@ -1063,7 +1107,7 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
1063
1107
|
.on('mousemove', function (event, d, i, n) {
|
|
1064
1108
|
const target = event.target;
|
|
1065
1109
|
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 ||
|
|
1110
|
+
self.tooltipBuilder.showBarTooltip(event, config.thresholds[Number(this.parentElement.dataset['groupId'])].data[index], config.tickFormat || PcacFormatEnum.None);
|
|
1067
1111
|
})
|
|
1068
1112
|
.transition(transition()
|
|
1069
1113
|
.duration(this.transitionService.getTransitionDuration()))
|
|
@@ -1227,8 +1271,8 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
1227
1271
|
height: this.height,
|
|
1228
1272
|
xScale: this.xScaleStacked,
|
|
1229
1273
|
yScale: this.yScale,
|
|
1230
|
-
xFormat:
|
|
1231
|
-
yFormat: config.tickFormat ||
|
|
1274
|
+
xFormat: PcacFormatEnum.None,
|
|
1275
|
+
yFormat: config.tickFormat || PcacFormatEnum.None,
|
|
1232
1276
|
hideYAxis: config.hideAxis
|
|
1233
1277
|
});
|
|
1234
1278
|
if (!config.hideGrid) {
|
|
@@ -1316,7 +1360,7 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
1316
1360
|
});
|
|
1317
1361
|
})
|
|
1318
1362
|
.on('mousemove', (event, d) => {
|
|
1319
|
-
self.tooltipBuilder.showBarTooltip(event, d, config.tickFormat ||
|
|
1363
|
+
self.tooltipBuilder.showBarTooltip(event, d, config.tickFormat || PcacFormatEnum.None);
|
|
1320
1364
|
})
|
|
1321
1365
|
.on('mouseout', function (d) {
|
|
1322
1366
|
self.tooltipBuilder.hideTooltip();
|
|
@@ -1351,7 +1395,7 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
1351
1395
|
return i;
|
|
1352
1396
|
})
|
|
1353
1397
|
.on('mousemove', (event, d, i) => {
|
|
1354
|
-
this.tooltipBuilder.showBarTooltip(event, config.thresholds[0], config.tickFormat ||
|
|
1398
|
+
this.tooltipBuilder.showBarTooltip(event, config.thresholds[0], config.tickFormat || PcacFormatEnum.None);
|
|
1355
1399
|
})
|
|
1356
1400
|
.transition(transition()
|
|
1357
1401
|
.duration(this.transitionService.getTransitionDuration()))
|
|
@@ -1370,7 +1414,7 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
1370
1414
|
const index = Number(this.parentElement.dataset['groupId']);
|
|
1371
1415
|
self.tooltipBuilder.showBarTooltip(event, config.isStacked ?
|
|
1372
1416
|
config.thresholds[index].data[0] :
|
|
1373
|
-
config.thresholds[index], config.tickFormat ||
|
|
1417
|
+
config.thresholds[index], config.tickFormat || PcacFormatEnum.None);
|
|
1374
1418
|
})
|
|
1375
1419
|
.transition(transition()
|
|
1376
1420
|
.duration(this.transitionService.getTransitionDuration()))
|
|
@@ -1387,7 +1431,7 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
1387
1431
|
.on('mousemove', function (event, _) {
|
|
1388
1432
|
const target = event.target;
|
|
1389
1433
|
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 ||
|
|
1434
|
+
self.tooltipBuilder.showBarTooltip(event, config.thresholds[Number(this.parentElement.dataset['groupId'])].data[index], config.tickFormat || PcacFormatEnum.None);
|
|
1391
1435
|
})
|
|
1392
1436
|
.attr('width', this.xScaleGrouped.bandwidth())
|
|
1393
1437
|
.transition(transition()
|
|
@@ -1500,5 +1544,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.6", ngImpor
|
|
|
1500
1544
|
* Generated bundle index. Do not edit.
|
|
1501
1545
|
*/
|
|
1502
1546
|
|
|
1503
|
-
export { BarHorizontalChartBuilder, BarVerticalChartBuilder, LineAreaChartBuilder, PcacAxisBuilder, PcacBarChartHorizontalComponent, PcacBarHorizontalChartModule, PcacBarVerticalChartComponent, PcacBarVerticalChartModule, PcacChart, PcacColorService, PcacGridBuilder, PcacLineAreaChartComponent, PcacLineAreaChartModule, PcacPieChartComponent, PcacPieChartModule,
|
|
1547
|
+
export { BarHorizontalChartBuilder, BarVerticalChartBuilder, LineAreaChartBuilder, PcacAxisBuilder, PcacBarChartHorizontalComponent, PcacBarHorizontalChartModule, PcacBarVerticalChartComponent, PcacBarVerticalChartModule, PcacChart, PcacColorService, PcacFormatEnum, PcacGridBuilder, PcacLineAreaChartComponent, PcacLineAreaChartModule, PcacPieChartComponent, PcacPieChartModule, PcacTooltipBuilder, PcacTransitionService, PieChartBuilder };
|
|
1504
1548
|
//# sourceMappingURL=pioneer-code-pioneer-charts.mjs.map
|