@pioneer-code/pioneer-charts 1.0.7 → 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 -8
- 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 -44
- 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 +2 -4
- package/lib/line-area-chart/line-area-chart.model.d.ts +9 -4
- 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,13 +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
|
|
53
|
-
// let f = format('.0%') No longer works
|
|
56
|
+
case PcacFormatEnum.Percentage:
|
|
54
57
|
xAxis.tickFormat(d => d + "%");
|
|
55
58
|
break;
|
|
56
|
-
case
|
|
59
|
+
case PcacFormatEnum.Minutes:
|
|
57
60
|
xAxis.tickFormat((d) => d + 'm');
|
|
58
61
|
break;
|
|
62
|
+
case PcacFormatEnum.Fahrenheit:
|
|
63
|
+
xAxis.tickFormat((d) => d + 'f');
|
|
64
|
+
break;
|
|
59
65
|
}
|
|
60
66
|
}
|
|
61
67
|
config.svg.append('g')
|
|
@@ -134,27 +140,43 @@ class PcacTooltipBuilder {
|
|
|
134
140
|
.append('div')
|
|
135
141
|
.attr('class', 'pcac-d3-tooltip'); // TODO: Strongly type
|
|
136
142
|
}
|
|
137
|
-
showBarTooltip(event, data,
|
|
143
|
+
showBarTooltip(event, data, valueFormat, keyFormat) {
|
|
138
144
|
this.tooltip.style('left', event.pageX - 60 + 'px')
|
|
139
145
|
.style('top', event.pageY - 55 + 'px')
|
|
140
146
|
.style('display', 'inline-block')
|
|
141
|
-
.html(this.getBarTipData(data,
|
|
147
|
+
.html(this.getBarTipData(data, valueFormat, keyFormat));
|
|
142
148
|
}
|
|
143
149
|
hideTooltip() {
|
|
144
150
|
this.tooltip.style('display', 'none');
|
|
145
151
|
}
|
|
146
|
-
getBarTipData(data,
|
|
152
|
+
getBarTipData(data, valueFormat, keyFormat) {
|
|
147
153
|
let value = data.value;
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
154
|
+
let key = data.key;
|
|
155
|
+
if (valueFormat) {
|
|
156
|
+
switch (valueFormat) {
|
|
157
|
+
case PcacFormatEnum.Percentage:
|
|
151
158
|
value = value * 100 + '%';
|
|
152
159
|
break;
|
|
153
|
-
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
|
+
});
|
|
154
176
|
break;
|
|
155
177
|
}
|
|
156
178
|
}
|
|
157
|
-
return
|
|
179
|
+
return key ? key + '</br>' + value.toString() : value.toString();
|
|
158
180
|
}
|
|
159
181
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacTooltipBuilder, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
160
182
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacTooltipBuilder, providedIn: 'root' }); }
|
|
@@ -426,8 +448,9 @@ class LineAreaChartEffectsBuilder {
|
|
|
426
448
|
break;
|
|
427
449
|
}
|
|
428
450
|
}
|
|
451
|
+
let textTarget = this.config.y.invert(pos.y);
|
|
429
452
|
select$1(nodes[index]).select('text')
|
|
430
|
-
.text(
|
|
453
|
+
.text(textTarget.toFixed(0));
|
|
431
454
|
return 'translate(' + mousePos[0] + ',' + pos.y + ')';
|
|
432
455
|
});
|
|
433
456
|
}
|
|
@@ -475,22 +498,30 @@ class LineAreaChartBuilder extends PcacChart {
|
|
|
475
498
|
this.margin.right = 8;
|
|
476
499
|
}
|
|
477
500
|
buildScales(config) {
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
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
|
+
}
|
|
481
512
|
this.yScale = scaleLinear()
|
|
482
|
-
.domain([0, config.
|
|
513
|
+
.domain([config.yDomainMin || 0, config.yDomainMax || 100])
|
|
483
514
|
.range([this.height, 0]);
|
|
484
515
|
this.line = line()
|
|
485
516
|
.x((d, i) => {
|
|
486
|
-
return this.
|
|
517
|
+
return this.getXFormat(config.xFormat, d, i);
|
|
487
518
|
})
|
|
488
519
|
.y((d) => {
|
|
489
520
|
return this.yScale(d.value);
|
|
490
521
|
});
|
|
491
522
|
this.area = area()
|
|
492
523
|
.x((d, i) => {
|
|
493
|
-
return this.
|
|
524
|
+
return this.getXFormat(config.xFormat, d, i);
|
|
494
525
|
})
|
|
495
526
|
.y0(this.height)
|
|
496
527
|
.y1((d) => {
|
|
@@ -505,7 +536,8 @@ class LineAreaChartBuilder extends PcacChart {
|
|
|
505
536
|
numberOfTicks: config.numberOfTicks || 5,
|
|
506
537
|
height: this.height,
|
|
507
538
|
xScale: this.xScale,
|
|
508
|
-
yScale: this.yScale
|
|
539
|
+
yScale: this.yScale,
|
|
540
|
+
yFormat: config.yFormat
|
|
509
541
|
});
|
|
510
542
|
}
|
|
511
543
|
if (!config.hideGrid) {
|
|
@@ -588,14 +620,14 @@ class LineAreaChartBuilder extends PcacChart {
|
|
|
588
620
|
return this.colors[index];
|
|
589
621
|
})
|
|
590
622
|
.attr('cx', (d, i) => {
|
|
591
|
-
return this.
|
|
623
|
+
return this.getXFormat(config.xFormat, d, i);
|
|
592
624
|
})
|
|
593
625
|
.attr('cy', (d) => {
|
|
594
626
|
return this.yScale(0);
|
|
595
627
|
})
|
|
596
628
|
.attr('fill', '#fff')
|
|
597
629
|
.on('mouseover', function (event, d) {
|
|
598
|
-
self.tooltipBuilder.showBarTooltip(event, d);
|
|
630
|
+
self.tooltipBuilder.showBarTooltip(event, d, self.config.yFormat, self.config.xFormat);
|
|
599
631
|
select$1(this).transition(transition()
|
|
600
632
|
.duration(self.transitionService.getTransitionDuration() / 3))
|
|
601
633
|
.attr('r', 6)
|
|
@@ -619,6 +651,17 @@ class LineAreaChartBuilder extends PcacChart {
|
|
|
619
651
|
.attr('r', 4);
|
|
620
652
|
}
|
|
621
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
|
+
}
|
|
622
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 }); }
|
|
623
666
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: LineAreaChartBuilder, providedIn: 'root' }); }
|
|
624
667
|
}
|
|
@@ -910,8 +953,8 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
910
953
|
height: this.height,
|
|
911
954
|
xScale: this.xScale,
|
|
912
955
|
yScale: this.yScaleStacked,
|
|
913
|
-
xFormat: config.tickFormat ||
|
|
914
|
-
yFormat:
|
|
956
|
+
xFormat: config.tickFormat || PcacFormatEnum.None,
|
|
957
|
+
yFormat: PcacFormatEnum.None,
|
|
915
958
|
hideXAxis: config.hideAxis
|
|
916
959
|
});
|
|
917
960
|
if (!config.hideGrid) {
|
|
@@ -996,7 +1039,7 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
996
1039
|
});
|
|
997
1040
|
})
|
|
998
1041
|
.on('mousemove', (event, d) => {
|
|
999
|
-
self.tooltipBuilder.showBarTooltip(event, d, config.tickFormat ||
|
|
1042
|
+
self.tooltipBuilder.showBarTooltip(event, d, config.tickFormat || PcacFormatEnum.None);
|
|
1000
1043
|
})
|
|
1001
1044
|
.on('mouseout', function (event, d) {
|
|
1002
1045
|
self.tooltipBuilder.hideTooltip();
|
|
@@ -1027,7 +1070,7 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
1027
1070
|
return i;
|
|
1028
1071
|
})
|
|
1029
1072
|
.on('mousemove', (event, _) => {
|
|
1030
|
-
this.tooltipBuilder.showBarTooltip(event, config.thresholds[0], config.tickFormat ||
|
|
1073
|
+
this.tooltipBuilder.showBarTooltip(event, config.thresholds[0], config.tickFormat || PcacFormatEnum.None);
|
|
1031
1074
|
})
|
|
1032
1075
|
.transition(transition()
|
|
1033
1076
|
.duration(this.transitionService.getTransitionDuration()))
|
|
@@ -1046,7 +1089,7 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
1046
1089
|
const index = Number(this.parentElement.dataset['groupId']);
|
|
1047
1090
|
self.tooltipBuilder.showBarTooltip(event, config.isStacked ?
|
|
1048
1091
|
config.thresholds[index].data[0] :
|
|
1049
|
-
config.thresholds[index], config.tickFormat ||
|
|
1092
|
+
config.thresholds[index], config.tickFormat || PcacFormatEnum.None);
|
|
1050
1093
|
})
|
|
1051
1094
|
.transition(transition()
|
|
1052
1095
|
.duration(this.transitionService.getTransitionDuration()))
|
|
@@ -1064,7 +1107,7 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
1064
1107
|
.on('mousemove', function (event, d, i, n) {
|
|
1065
1108
|
const target = event.target;
|
|
1066
1109
|
const index = Number(target.getAttribute("data-group-threshold-id"));
|
|
1067
|
-
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);
|
|
1068
1111
|
})
|
|
1069
1112
|
.transition(transition()
|
|
1070
1113
|
.duration(this.transitionService.getTransitionDuration()))
|
|
@@ -1228,8 +1271,8 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
1228
1271
|
height: this.height,
|
|
1229
1272
|
xScale: this.xScaleStacked,
|
|
1230
1273
|
yScale: this.yScale,
|
|
1231
|
-
xFormat:
|
|
1232
|
-
yFormat: config.tickFormat ||
|
|
1274
|
+
xFormat: PcacFormatEnum.None,
|
|
1275
|
+
yFormat: config.tickFormat || PcacFormatEnum.None,
|
|
1233
1276
|
hideYAxis: config.hideAxis
|
|
1234
1277
|
});
|
|
1235
1278
|
if (!config.hideGrid) {
|
|
@@ -1317,7 +1360,7 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
1317
1360
|
});
|
|
1318
1361
|
})
|
|
1319
1362
|
.on('mousemove', (event, d) => {
|
|
1320
|
-
self.tooltipBuilder.showBarTooltip(event, d, config.tickFormat ||
|
|
1363
|
+
self.tooltipBuilder.showBarTooltip(event, d, config.tickFormat || PcacFormatEnum.None);
|
|
1321
1364
|
})
|
|
1322
1365
|
.on('mouseout', function (d) {
|
|
1323
1366
|
self.tooltipBuilder.hideTooltip();
|
|
@@ -1352,7 +1395,7 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
1352
1395
|
return i;
|
|
1353
1396
|
})
|
|
1354
1397
|
.on('mousemove', (event, d, i) => {
|
|
1355
|
-
this.tooltipBuilder.showBarTooltip(event, config.thresholds[0], config.tickFormat ||
|
|
1398
|
+
this.tooltipBuilder.showBarTooltip(event, config.thresholds[0], config.tickFormat || PcacFormatEnum.None);
|
|
1356
1399
|
})
|
|
1357
1400
|
.transition(transition()
|
|
1358
1401
|
.duration(this.transitionService.getTransitionDuration()))
|
|
@@ -1371,7 +1414,7 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
1371
1414
|
const index = Number(this.parentElement.dataset['groupId']);
|
|
1372
1415
|
self.tooltipBuilder.showBarTooltip(event, config.isStacked ?
|
|
1373
1416
|
config.thresholds[index].data[0] :
|
|
1374
|
-
config.thresholds[index], config.tickFormat ||
|
|
1417
|
+
config.thresholds[index], config.tickFormat || PcacFormatEnum.None);
|
|
1375
1418
|
})
|
|
1376
1419
|
.transition(transition()
|
|
1377
1420
|
.duration(this.transitionService.getTransitionDuration()))
|
|
@@ -1388,7 +1431,7 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
1388
1431
|
.on('mousemove', function (event, _) {
|
|
1389
1432
|
const target = event.target;
|
|
1390
1433
|
const index = Number(target.getAttribute("data-group-threshold-id"));
|
|
1391
|
-
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);
|
|
1392
1435
|
})
|
|
1393
1436
|
.attr('width', this.xScaleGrouped.bandwidth())
|
|
1394
1437
|
.transition(transition()
|
|
@@ -1501,5 +1544,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.6", ngImpor
|
|
|
1501
1544
|
* Generated bundle index. Do not edit.
|
|
1502
1545
|
*/
|
|
1503
1546
|
|
|
1504
|
-
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 };
|
|
1505
1548
|
//# sourceMappingURL=pioneer-code-pioneer-charts.mjs.map
|