@pioneer-code/pioneer-charts 1.0.2 → 1.0.3
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/README.md +27 -50
- package/esm2022/lib/bar-chart/bar-horizontal-chart/bar-horizontal-chart.builder.mjs +272 -0
- package/esm2022/lib/bar-chart/bar-horizontal-chart/bar-horizontal-chart.component.mjs +47 -0
- package/esm2022/lib/bar-chart/bar-horizontal-chart/bar-horizontal-chart.model.mjs +2 -0
- package/esm2022/lib/bar-chart/bar-horizontal-chart/bar-horizontal-chart.module.mjs +20 -0
- package/esm2022/lib/bar-chart/bar-horizontal-chart/public_api.mjs +5 -0
- package/esm2022/lib/bar-chart/bar-vertical-chart/bar-vertical-chart.builder.mjs +284 -0
- package/esm2022/lib/bar-chart/bar-vertical-chart/bar-vertical-chart.component.mjs +47 -0
- package/esm2022/lib/bar-chart/bar-vertical-chart/bar-vertical-chart.model.mjs +2 -0
- package/esm2022/lib/bar-chart/bar-vertical-chart/bar-vertical-chart.module.mjs +20 -0
- package/esm2022/lib/bar-chart/bar-vertical-chart/public_api.mjs +5 -0
- package/esm2022/lib/core/axis.builder.mjs +58 -0
- package/esm2022/lib/core/chart.mjs +90 -0
- package/esm2022/lib/core/chart.model.mjs +7 -0
- package/esm2022/lib/core/color.service.mjs +74 -0
- package/esm2022/lib/core/grid.builder.mjs +40 -0
- package/esm2022/lib/core/index.mjs +2 -0
- package/esm2022/lib/core/public_api.mjs +8 -0
- package/esm2022/lib/core/tooltip.builder.mjs +42 -0
- package/esm2022/lib/core/transition.service.mjs +19 -0
- package/esm2022/lib/line-area-chart/line-area-chart-effects.builders.mjs +117 -0
- package/esm2022/lib/line-area-chart/line-area-chart.builder.mjs +206 -0
- package/esm2022/lib/line-area-chart/line-area-chart.component.mjs +47 -0
- package/esm2022/lib/line-area-chart/line-area-chart.model.mjs +2 -0
- package/esm2022/lib/line-area-chart/line-area-chart.module.mjs +24 -0
- package/esm2022/lib/line-area-chart/public_api.mjs +5 -0
- package/esm2022/lib/pie-chart/pie-chart.builder.mjs +99 -0
- package/esm2022/lib/pie-chart/pie-chart.component.mjs +47 -0
- package/esm2022/lib/pie-chart/pie-chart.model.mjs +2 -0
- package/esm2022/lib/pie-chart/pie-chart.module.mjs +24 -0
- package/esm2022/lib/pie-chart/public_api.mjs +5 -0
- package/esm2022/pioneer-code-pioneer-charts.mjs +5 -0
- package/esm2022/public-api.mjs +9 -0
- package/fesm2022/pioneer-code-pioneer-charts.mjs +1493 -0
- package/fesm2022/pioneer-code-pioneer-charts.mjs.map +1 -0
- package/index.d.ts +5 -0
- package/lib/bar-chart/bar-horizontal-chart/bar-horizontal-chart.builder.d.ts +41 -39
- package/lib/bar-chart/bar-horizontal-chart/bar-horizontal-chart.component.d.ts +21 -18
- package/lib/bar-chart/bar-horizontal-chart/bar-horizontal-chart.model.d.ts +15 -15
- package/lib/bar-chart/bar-horizontal-chart/bar-horizontal-chart.module.d.ts +7 -2
- package/lib/bar-chart/bar-horizontal-chart/public_api.d.ts +4 -4
- package/lib/bar-chart/bar-vertical-chart/bar-vertical-chart.builder.d.ts +42 -40
- package/lib/bar-chart/bar-vertical-chart/bar-vertical-chart.component.d.ts +21 -18
- package/lib/bar-chart/bar-vertical-chart/bar-vertical-chart.model.d.ts +15 -15
- package/lib/bar-chart/bar-vertical-chart/bar-vertical-chart.module.d.ts +7 -2
- package/lib/bar-chart/bar-vertical-chart/public_api.d.ts +4 -4
- package/lib/core/axis.builder.d.ts +21 -18
- package/lib/core/chart.d.ts +55 -52
- package/lib/core/chart.model.d.ts +21 -21
- package/lib/core/color.service.d.ts +32 -29
- package/lib/core/grid.builder.d.ts +22 -19
- package/lib/core/index.d.ts +1 -1
- package/lib/core/public_api.d.ts +7 -8
- package/lib/core/tooltip.builder.d.ts +10 -11
- package/lib/core/transition.service.d.ts +7 -4
- package/lib/line-area-chart/line-area-chart-effects.builders.d.ts +27 -27
- package/lib/line-area-chart/line-area-chart.builder.d.ts +39 -38
- package/lib/line-area-chart/line-area-chart.component.d.ts +21 -18
- package/lib/line-area-chart/line-area-chart.model.d.ts +9 -9
- package/lib/line-area-chart/line-area-chart.module.d.ts +8 -2
- package/lib/line-area-chart/public_api.d.ts +4 -4
- package/lib/pie-chart/pie-chart.builder.d.ts +33 -34
- package/lib/pie-chart/pie-chart.component.d.ts +21 -18
- package/lib/pie-chart/pie-chart.model.d.ts +4 -4
- package/lib/pie-chart/pie-chart.module.d.ts +8 -2
- package/lib/pie-chart/public_api.d.ts +4 -4
- package/package.json +21 -19
- package/public-api.d.ts +5 -0
- package/scss/lib/bar-chart/bar-horizontal-chart/bar-horizontal-chart.component.scss +19 -0
- package/scss/lib/bar-chart/bar-vertical-chart/bar-vertical-chart.component.scss +8 -0
- package/scss/{core → lib/core}/theme/imports.scss +12 -12
- package/scss/lib/line-area-chart/line-area-chart.component.scss +35 -0
- package/scss/{pie-chart → lib/pie-chart}/pie-chart.component.scss +10 -10
- package/scss/{core/core.scss → lib/pioneer-charts.scss} +26 -13
- package/themes/pioneer-charts.css +22 -0
- package/themes/pioneer-charts.css.map +10 -0
- package/themes/pioneer-charts.min.css +3 -0
- package/themes/pioneer-charts.min.css.map +10 -0
- package/bundles/pioneer-code-pioneer-charts.umd.js +0 -3700
- package/bundles/pioneer-code-pioneer-charts.umd.js.map +0 -1
- package/bundles/pioneer-code-pioneer-charts.umd.min.js +0 -2
- package/bundles/pioneer-code-pioneer-charts.umd.min.js.map +0 -1
- package/esm2015/lib/bar-chart/bar-horizontal-chart/bar-horizontal-chart.builder.js +0 -486
- package/esm2015/lib/bar-chart/bar-horizontal-chart/bar-horizontal-chart.component.js +0 -89
- package/esm2015/lib/bar-chart/bar-horizontal-chart/bar-horizontal-chart.model.js +0 -37
- package/esm2015/lib/bar-chart/bar-horizontal-chart/bar-horizontal-chart.module.js +0 -19
- package/esm2015/lib/bar-chart/bar-horizontal-chart/index.js +0 -6
- package/esm2015/lib/bar-chart/bar-horizontal-chart/public_api.js +0 -9
- package/esm2015/lib/bar-chart/bar-vertical-chart/bar-vertical-chart.builder.js +0 -518
- package/esm2015/lib/bar-chart/bar-vertical-chart/bar-vertical-chart.component.js +0 -89
- package/esm2015/lib/bar-chart/bar-vertical-chart/bar-vertical-chart.model.js +0 -37
- package/esm2015/lib/bar-chart/bar-vertical-chart/bar-vertical-chart.module.js +0 -19
- package/esm2015/lib/bar-chart/bar-vertical-chart/index.js +0 -6
- package/esm2015/lib/bar-chart/bar-vertical-chart/public_api.js +0 -9
- package/esm2015/lib/core/axis.builder.js +0 -99
- package/esm2015/lib/core/chart.js +0 -144
- package/esm2015/lib/core/chart.model.js +0 -39
- package/esm2015/lib/core/color.service.js +0 -149
- package/esm2015/lib/core/core.module.js +0 -24
- package/esm2015/lib/core/grid.builder.js +0 -88
- package/esm2015/lib/core/index.js +0 -6
- package/esm2015/lib/core/public_api.js +0 -13
- package/esm2015/lib/core/tooltip.builder.js +0 -74
- package/esm2015/lib/core/transition.service.js +0 -23
- package/esm2015/lib/dialog/dialog.component.js +0 -50
- package/esm2015/lib/dialog/dialog.module.js +0 -23
- package/esm2015/lib/dialog/index.js +0 -6
- package/esm2015/lib/dialog/public_api.js +0 -7
- package/esm2015/lib/header/header.component.js +0 -21
- package/esm2015/lib/header/header.model.js +0 -13
- package/esm2015/lib/header/header.module.js +0 -19
- package/esm2015/lib/header/index.js +0 -6
- package/esm2015/lib/header/public_api.js +0 -8
- package/esm2015/lib/line-area-chart/index.js +0 -6
- package/esm2015/lib/line-area-chart/line-area-chart-effects.builders.js +0 -236
- package/esm2015/lib/line-area-chart/line-area-chart.builder.js +0 -386
- package/esm2015/lib/line-area-chart/line-area-chart.component.js +0 -89
- package/esm2015/lib/line-area-chart/line-area-chart.model.js +0 -23
- package/esm2015/lib/line-area-chart/line-area-chart.module.js +0 -19
- package/esm2015/lib/line-area-chart/public_api.js +0 -9
- package/esm2015/lib/pagination/index.js +0 -6
- package/esm2015/lib/pagination/pagination.component.js +0 -144
- package/esm2015/lib/pagination/pagination.model.js +0 -48
- package/esm2015/lib/pagination/pagination.module.js +0 -25
- package/esm2015/lib/pagination/public_api.js +0 -8
- package/esm2015/lib/pie-chart/index.js +0 -6
- package/esm2015/lib/pie-chart/pie-chart.builder.js +0 -221
- package/esm2015/lib/pie-chart/pie-chart.component.js +0 -89
- package/esm2015/lib/pie-chart/pie-chart.model.js +0 -13
- package/esm2015/lib/pie-chart/pie-chart.module.js +0 -19
- package/esm2015/lib/pie-chart/public_api.js +0 -9
- package/esm2015/lib/spinner/index.js +0 -6
- package/esm2015/lib/spinner/public_api.js +0 -7
- package/esm2015/lib/spinner/spinner.component.js +0 -28
- package/esm2015/lib/spinner/spinner.module.js +0 -23
- package/esm2015/lib/table/index.js +0 -6
- package/esm2015/lib/table/public_api.js +0 -8
- package/esm2015/lib/table/table-sort.service.js +0 -95
- package/esm2015/lib/table/table.component.js +0 -232
- package/esm2015/lib/table/table.model.js +0 -51
- package/esm2015/lib/table/table.module.js +0 -23
- package/esm2015/pioneer-code-pioneer-charts.js +0 -10
- package/esm2015/public_api.js +0 -18
- package/esm5/lib/bar-chart/bar-horizontal-chart/bar-horizontal-chart.builder.js +0 -550
- package/esm5/lib/bar-chart/bar-horizontal-chart/bar-horizontal-chart.component.js +0 -102
- package/esm5/lib/bar-chart/bar-horizontal-chart/bar-horizontal-chart.model.js +0 -37
- package/esm5/lib/bar-chart/bar-horizontal-chart/bar-horizontal-chart.module.js +0 -23
- package/esm5/lib/bar-chart/bar-horizontal-chart/index.js +0 -6
- package/esm5/lib/bar-chart/bar-horizontal-chart/public_api.js +0 -9
- package/esm5/lib/bar-chart/bar-vertical-chart/bar-vertical-chart.builder.js +0 -582
- package/esm5/lib/bar-chart/bar-vertical-chart/bar-vertical-chart.component.js +0 -102
- package/esm5/lib/bar-chart/bar-vertical-chart/bar-vertical-chart.model.js +0 -37
- package/esm5/lib/bar-chart/bar-vertical-chart/bar-vertical-chart.module.js +0 -23
- package/esm5/lib/bar-chart/bar-vertical-chart/index.js +0 -6
- package/esm5/lib/bar-chart/bar-vertical-chart/public_api.js +0 -9
- package/esm5/lib/core/axis.builder.js +0 -117
- package/esm5/lib/core/chart.js +0 -182
- package/esm5/lib/core/chart.model.js +0 -39
- package/esm5/lib/core/color.service.js +0 -199
- package/esm5/lib/core/core.module.js +0 -28
- package/esm5/lib/core/grid.builder.js +0 -100
- package/esm5/lib/core/index.js +0 -6
- package/esm5/lib/core/public_api.js +0 -13
- package/esm5/lib/core/tooltip.builder.js +0 -92
- package/esm5/lib/core/transition.service.js +0 -28
- package/esm5/lib/dialog/dialog.component.js +0 -58
- package/esm5/lib/dialog/dialog.module.js +0 -27
- package/esm5/lib/dialog/index.js +0 -6
- package/esm5/lib/dialog/public_api.js +0 -7
- package/esm5/lib/header/header.component.js +0 -25
- package/esm5/lib/header/header.model.js +0 -13
- package/esm5/lib/header/header.module.js +0 -23
- package/esm5/lib/header/index.js +0 -6
- package/esm5/lib/header/public_api.js +0 -8
- package/esm5/lib/line-area-chart/index.js +0 -6
- package/esm5/lib/line-area-chart/line-area-chart-effects.builders.js +0 -280
- package/esm5/lib/line-area-chart/line-area-chart.builder.js +0 -439
- package/esm5/lib/line-area-chart/line-area-chart.component.js +0 -102
- package/esm5/lib/line-area-chart/line-area-chart.model.js +0 -23
- package/esm5/lib/line-area-chart/line-area-chart.module.js +0 -23
- package/esm5/lib/line-area-chart/public_api.js +0 -9
- package/esm5/lib/pagination/index.js +0 -6
- package/esm5/lib/pagination/pagination.component.js +0 -182
- package/esm5/lib/pagination/pagination.model.js +0 -48
- package/esm5/lib/pagination/pagination.module.js +0 -29
- package/esm5/lib/pagination/public_api.js +0 -8
- package/esm5/lib/pie-chart/index.js +0 -6
- package/esm5/lib/pie-chart/pie-chart.builder.js +0 -242
- package/esm5/lib/pie-chart/pie-chart.component.js +0 -102
- package/esm5/lib/pie-chart/pie-chart.model.js +0 -13
- package/esm5/lib/pie-chart/pie-chart.module.js +0 -23
- package/esm5/lib/pie-chart/public_api.js +0 -9
- package/esm5/lib/spinner/index.js +0 -6
- package/esm5/lib/spinner/public_api.js +0 -7
- package/esm5/lib/spinner/spinner.component.js +0 -30
- package/esm5/lib/spinner/spinner.module.js +0 -27
- package/esm5/lib/table/index.js +0 -6
- package/esm5/lib/table/public_api.js +0 -8
- package/esm5/lib/table/table-sort.service.js +0 -119
- package/esm5/lib/table/table.component.js +0 -299
- package/esm5/lib/table/table.model.js +0 -51
- package/esm5/lib/table/table.module.js +0 -27
- package/esm5/pioneer-code-pioneer-charts.js +0 -10
- package/esm5/public_api.js +0 -18
- package/fesm2015/pioneer-code-pioneer-charts.js +0 -3077
- package/fesm2015/pioneer-code-pioneer-charts.js.map +0 -1
- package/fesm5/pioneer-code-pioneer-charts.js +0 -3665
- package/fesm5/pioneer-code-pioneer-charts.js.map +0 -1
- package/lib/bar-chart/bar-horizontal-chart/index.d.ts +0 -1
- package/lib/bar-chart/bar-vertical-chart/index.d.ts +0 -1
- package/lib/core/core.module.d.ts +0 -2
- package/lib/dialog/dialog.component.d.ts +0 -9
- package/lib/dialog/dialog.module.d.ts +0 -2
- package/lib/dialog/index.d.ts +0 -1
- package/lib/dialog/public_api.d.ts +0 -2
- package/lib/header/header.component.d.ts +0 -4
- package/lib/header/header.model.d.ts +0 -3
- package/lib/header/header.module.d.ts +0 -2
- package/lib/header/index.d.ts +0 -1
- package/lib/header/public_api.d.ts +0 -3
- package/lib/line-area-chart/index.d.ts +0 -1
- package/lib/pagination/index.d.ts +0 -1
- package/lib/pagination/pagination.component.d.ts +0 -20
- package/lib/pagination/pagination.model.d.ts +0 -28
- package/lib/pagination/pagination.module.d.ts +0 -2
- package/lib/pagination/public_api.d.ts +0 -3
- package/lib/pie-chart/index.d.ts +0 -1
- package/lib/spinner/index.d.ts +0 -1
- package/lib/spinner/public_api.d.ts +0 -2
- package/lib/spinner/spinner.component.d.ts +0 -4
- package/lib/spinner/spinner.module.d.ts +0 -2
- package/lib/table/index.d.ts +0 -1
- package/lib/table/public_api.d.ts +0 -3
- package/lib/table/table-sort.service.d.ts +0 -10
- package/lib/table/table.component.d.ts +0 -51
- package/lib/table/table.model.d.ts +0 -28
- package/lib/table/table.module.d.ts +0 -2
- package/pioneer-code-pioneer-charts.d.ts +0 -5
- package/pioneer-code-pioneer-charts.metadata.json +0 -1
- package/public_api.d.ts +0 -10
- package/scss/bar-chart/bar-horizontal-chart/bar-horizontal-chart.component.scss +0 -7
- package/scss/bar-chart/bar-vertical-chart/bar-vertical-chart.component.scss +0 -7
- package/scss/dialog/dialog.component.scss +0 -42
- package/scss/header/header.component.scss +0 -8
- package/scss/line-area-chart/line-area-chart.component.scss +0 -28
- package/scss/pagination/pagination.component.scss +0 -94
- package/scss/pcac.scss +0 -61
- package/scss/spinner/spinner.component.scss +0 -34
- package/scss/table/table.component.scss +0 -143
- package/themes/pcac.css +0 -291
- package/themes/pcac.css.map +0 -19
- package/themes/pcac.min.css +0 -3
- package/themes/pcac.min.css.map +0 -19
|
@@ -0,0 +1,1493 @@
|
|
|
1
|
+
import { axisLeft, axisBottom } from 'd3-axis';
|
|
2
|
+
import { select as select$1 } from 'd3-selection';
|
|
3
|
+
import * as i0 from '@angular/core';
|
|
4
|
+
import { Injectable, EventEmitter, Component, ViewEncapsulation, Input, ViewChild, Output, HostListener, NgModule } from '@angular/core';
|
|
5
|
+
import { select } from 'd3';
|
|
6
|
+
import { transition } from 'd3-transition';
|
|
7
|
+
import { scaleLinear, scaleBand } from 'd3-scale';
|
|
8
|
+
import { line, area, arc, pie } from 'd3-shape';
|
|
9
|
+
import { range } from 'd3-array';
|
|
10
|
+
import { Subject } from 'rxjs';
|
|
11
|
+
import { CommonModule } from '@angular/common';
|
|
12
|
+
import { interpolate } from 'd3-interpolate';
|
|
13
|
+
import { color } from 'd3-color';
|
|
14
|
+
|
|
15
|
+
var PcacTickFormatEnum;
|
|
16
|
+
(function (PcacTickFormatEnum) {
|
|
17
|
+
PcacTickFormatEnum["None"] = "none";
|
|
18
|
+
PcacTickFormatEnum["Percentage"] = "percentage";
|
|
19
|
+
PcacTickFormatEnum["Minutes"] = "minutes";
|
|
20
|
+
})(PcacTickFormatEnum || (PcacTickFormatEnum = {}));
|
|
21
|
+
|
|
22
|
+
class PcacAxisBuilder {
|
|
23
|
+
drawAxis(config) {
|
|
24
|
+
if (!config.hideXAxis) {
|
|
25
|
+
this.drawXAxis(config);
|
|
26
|
+
}
|
|
27
|
+
if (!config.hideYAxis) {
|
|
28
|
+
this.drawYAxis(config);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
drawYAxis(config) {
|
|
32
|
+
const yAxis = axisLeft(config.yScale).ticks(config.numberOfTicks);
|
|
33
|
+
if (config.yFormat) {
|
|
34
|
+
switch (config.yFormat.toLocaleLowerCase()) {
|
|
35
|
+
case PcacTickFormatEnum.Percentage:
|
|
36
|
+
// let f = format('.0%') No longer works
|
|
37
|
+
yAxis.tickFormat(d => d + "%");
|
|
38
|
+
break;
|
|
39
|
+
case PcacTickFormatEnum.Minutes:
|
|
40
|
+
yAxis.tickFormat((d) => d + 'm');
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
config.svg.append('g')
|
|
45
|
+
.attr('class', 'pcac-y-axis')
|
|
46
|
+
.call(yAxis);
|
|
47
|
+
}
|
|
48
|
+
drawXAxis(config) {
|
|
49
|
+
const xAxis = axisBottom(config.xScale).ticks(config.numberOfTicks);
|
|
50
|
+
if (config.xFormat) {
|
|
51
|
+
switch (config.xFormat.toLocaleLowerCase()) {
|
|
52
|
+
case PcacTickFormatEnum.Percentage:
|
|
53
|
+
// let f = format('.0%') No longer works
|
|
54
|
+
xAxis.tickFormat(d => d + "%");
|
|
55
|
+
break;
|
|
56
|
+
case PcacTickFormatEnum.Minutes:
|
|
57
|
+
xAxis.tickFormat((d) => d + 'm');
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
config.svg.append('g')
|
|
62
|
+
.attr('class', 'pcac-x-axis')
|
|
63
|
+
.attr('transform', 'translate(0,' + config.height + ')')
|
|
64
|
+
.call(xAxis);
|
|
65
|
+
}
|
|
66
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacAxisBuilder, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
67
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacAxisBuilder, providedIn: 'root' }); }
|
|
68
|
+
}
|
|
69
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacAxisBuilder, decorators: [{
|
|
70
|
+
type: Injectable,
|
|
71
|
+
args: [{
|
|
72
|
+
providedIn: 'root',
|
|
73
|
+
}]
|
|
74
|
+
}] });
|
|
75
|
+
|
|
76
|
+
class PcacGridBuilder {
|
|
77
|
+
drawVerticalGrid(config) {
|
|
78
|
+
config.svg.append('g')
|
|
79
|
+
.attr('class', 'pcac-grid')
|
|
80
|
+
.selectAll('g.rule')
|
|
81
|
+
.data(config.xScale.ticks(5))
|
|
82
|
+
.enter().append('svg:g')
|
|
83
|
+
.attr('class', 'pcac-grid-rule')
|
|
84
|
+
.attr('transform', (d) => (`translate(${config.xScale(d)}, 0)`))
|
|
85
|
+
.append('svg:line')
|
|
86
|
+
.attr('y1', 0)
|
|
87
|
+
.attr('y2', config.height)
|
|
88
|
+
.attr('class', (d, i) => (i === 0 ? 'pcac-grid-rule-last' : ''));
|
|
89
|
+
}
|
|
90
|
+
drawHorizontalGrid(config) {
|
|
91
|
+
config.svg.append('g')
|
|
92
|
+
.attr('class', 'pcac-grid')
|
|
93
|
+
.selectAll('g.pcac-grid-rule')
|
|
94
|
+
.data(config.yScale.ticks(config.numberOfTicks))
|
|
95
|
+
.enter().append('svg:g')
|
|
96
|
+
.attr('class', 'pcac-grid-rule')
|
|
97
|
+
.append('svg:line')
|
|
98
|
+
.attr('y1', (d) => config.yScale(d))
|
|
99
|
+
.attr('y2', (d) => config.yScale(d))
|
|
100
|
+
.attr('x1', 0)
|
|
101
|
+
.attr('x2', config.width)
|
|
102
|
+
.attr('class', (_, i) => (i === 0 ? 'pcac-grid-rule-last' : ''));
|
|
103
|
+
}
|
|
104
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacGridBuilder, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
105
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacGridBuilder, providedIn: 'root' }); }
|
|
106
|
+
}
|
|
107
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacGridBuilder, decorators: [{
|
|
108
|
+
type: Injectable,
|
|
109
|
+
args: [{
|
|
110
|
+
providedIn: 'root',
|
|
111
|
+
}]
|
|
112
|
+
}] });
|
|
113
|
+
|
|
114
|
+
class PcacTransitionService {
|
|
115
|
+
constructor() {
|
|
116
|
+
this.transitionDuration = 750;
|
|
117
|
+
}
|
|
118
|
+
getTransitionDuration() {
|
|
119
|
+
return this.transitionDuration;
|
|
120
|
+
}
|
|
121
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacTransitionService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
122
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacTransitionService, providedIn: 'root' }); }
|
|
123
|
+
}
|
|
124
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacTransitionService, decorators: [{
|
|
125
|
+
type: Injectable,
|
|
126
|
+
args: [{
|
|
127
|
+
providedIn: 'root',
|
|
128
|
+
}]
|
|
129
|
+
}] });
|
|
130
|
+
|
|
131
|
+
class PcacTooltipBuilder {
|
|
132
|
+
constructor() {
|
|
133
|
+
this.tooltip = select('body')
|
|
134
|
+
.append('div')
|
|
135
|
+
.attr('class', 'pcac-d3-tooltip'); // TODO: Strongly type
|
|
136
|
+
}
|
|
137
|
+
showBarTooltip(event, data, tickFormat) {
|
|
138
|
+
this.tooltip.style('left', event.pageX - 60 + 'px')
|
|
139
|
+
.style('top', event.pageY - 55 + 'px')
|
|
140
|
+
.style('display', 'inline-block')
|
|
141
|
+
.html(this.getBarTipData(data, tickFormat));
|
|
142
|
+
}
|
|
143
|
+
hideTooltip() {
|
|
144
|
+
this.tooltip.style('display', 'none');
|
|
145
|
+
}
|
|
146
|
+
getBarTipData(data, tickFormat) {
|
|
147
|
+
let value = data.value;
|
|
148
|
+
if (tickFormat) {
|
|
149
|
+
switch (tickFormat.toLocaleLowerCase()) {
|
|
150
|
+
case PcacTickFormatEnum.Percentage:
|
|
151
|
+
value = value * 100 + '%';
|
|
152
|
+
break;
|
|
153
|
+
case PcacTickFormatEnum.Minutes:
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return data.key ? data.key + '</br>' + value.toString() : value.toString();
|
|
158
|
+
}
|
|
159
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacTooltipBuilder, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
160
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacTooltipBuilder, providedIn: 'root' }); }
|
|
161
|
+
}
|
|
162
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacTooltipBuilder, decorators: [{
|
|
163
|
+
type: Injectable,
|
|
164
|
+
args: [{
|
|
165
|
+
providedIn: 'root',
|
|
166
|
+
}]
|
|
167
|
+
}] });
|
|
168
|
+
|
|
169
|
+
class PcacColorService {
|
|
170
|
+
constructor() {
|
|
171
|
+
this.primary = '#43425d';
|
|
172
|
+
this.primaryLight = '#a3a1fb';
|
|
173
|
+
this.success = '#5ee2a0';
|
|
174
|
+
this.danger = '#ff6565';
|
|
175
|
+
this.warning = '#fec163';
|
|
176
|
+
this.orange = '#ffa177';
|
|
177
|
+
this.blue = '#55d8fe';
|
|
178
|
+
this.scale = [
|
|
179
|
+
this.primaryLight,
|
|
180
|
+
this.success,
|
|
181
|
+
this.danger,
|
|
182
|
+
this.warning,
|
|
183
|
+
this.orange,
|
|
184
|
+
this.blue
|
|
185
|
+
];
|
|
186
|
+
this.alert = 'red';
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Get a scale of colors dynamically
|
|
190
|
+
* @param numberOfNodes Number of items in dynamically build collection of colors
|
|
191
|
+
*/
|
|
192
|
+
getColorScale(numberOfNodes) {
|
|
193
|
+
const pallette = [];
|
|
194
|
+
for (let i = 0; i < numberOfNodes; i++) {
|
|
195
|
+
const mark = i % this.scale.length;
|
|
196
|
+
pallette.push(this.scale[mark]);
|
|
197
|
+
}
|
|
198
|
+
return pallette;
|
|
199
|
+
}
|
|
200
|
+
getAlert() {
|
|
201
|
+
return this.alert;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Set the scale that charts use to set colors of data[x] on the UI.
|
|
205
|
+
* @param colors A collection of hex values
|
|
206
|
+
*/
|
|
207
|
+
setScale(colors) {
|
|
208
|
+
this.scale = colors;
|
|
209
|
+
}
|
|
210
|
+
setPrimary(color) {
|
|
211
|
+
this.primary = color;
|
|
212
|
+
}
|
|
213
|
+
setPrimaryLight(color) {
|
|
214
|
+
this.primaryLight = color;
|
|
215
|
+
}
|
|
216
|
+
setSuccess(color) {
|
|
217
|
+
this.success = color;
|
|
218
|
+
}
|
|
219
|
+
setDanger(color) {
|
|
220
|
+
this.danger = color;
|
|
221
|
+
}
|
|
222
|
+
setOrange(color) {
|
|
223
|
+
this.orange = color;
|
|
224
|
+
}
|
|
225
|
+
setBlue(color) {
|
|
226
|
+
this.blue = color;
|
|
227
|
+
}
|
|
228
|
+
setAlert() {
|
|
229
|
+
return this.alert;
|
|
230
|
+
}
|
|
231
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacColorService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
232
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacColorService, providedIn: 'root' }); }
|
|
233
|
+
}
|
|
234
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacColorService, decorators: [{
|
|
235
|
+
type: Injectable,
|
|
236
|
+
args: [{
|
|
237
|
+
providedIn: 'root',
|
|
238
|
+
}]
|
|
239
|
+
}] });
|
|
240
|
+
|
|
241
|
+
class PcacChart {
|
|
242
|
+
constructor(axisBuilder, gridBuilder, transitionService, tooltipBuilder, colorService) {
|
|
243
|
+
this.axisBuilder = axisBuilder;
|
|
244
|
+
this.gridBuilder = gridBuilder;
|
|
245
|
+
this.transitionService = transitionService;
|
|
246
|
+
this.tooltipBuilder = tooltipBuilder;
|
|
247
|
+
this.colorService = colorService;
|
|
248
|
+
this.margin = { top: 8, right: 16, bottom: 20, left: 40 };
|
|
249
|
+
this.width = 400;
|
|
250
|
+
this.height = 400;
|
|
251
|
+
this.colors = [];
|
|
252
|
+
this.startData = []; // TODO: Strongly type
|
|
253
|
+
this.endData = []; // TODO: Strongly type
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Prior to building a chart, we need to initialize the state of the chart
|
|
257
|
+
* @param chartElm Reference to SVG on dom
|
|
258
|
+
* @param config Chart specific configuration
|
|
259
|
+
*/
|
|
260
|
+
initializeChartState(chartElm, config) {
|
|
261
|
+
select$1(chartElm.nativeElement).select('g').remove();
|
|
262
|
+
this.width = chartElm.nativeElement.parentNode.clientWidth - this.margin.left - this.margin.right;
|
|
263
|
+
this.height = config.height;
|
|
264
|
+
this.colors = this.colorService.getColorScale(Math.max(config.data.length, config.data[0].data ? config.data[0].data.length : 0));
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* 1) Set the width and height of the SVG
|
|
268
|
+
* 2) Add a group and translate it to state of {{center}} option
|
|
269
|
+
* @param chartElm Reference to SVG on dom
|
|
270
|
+
* @param center Are we pinning x,y to the top,left, or are we centering our drawing group inside the SVG.
|
|
271
|
+
*/
|
|
272
|
+
buildContainer(chartElm, center = false) {
|
|
273
|
+
const combinedHeight = this.height + this.margin.top + this.margin.bottom;
|
|
274
|
+
const combinedWidth = this.width + this.margin.left + this.margin.right;
|
|
275
|
+
this.svg = select$1(chartElm.nativeElement)
|
|
276
|
+
.attr('width', combinedWidth)
|
|
277
|
+
.attr('height', combinedHeight);
|
|
278
|
+
if (center) {
|
|
279
|
+
this.svg = this.svg
|
|
280
|
+
.append('g')
|
|
281
|
+
.attr('transform', 'translate(' + combinedWidth / 2 + ',' + combinedHeight / 2 + ')');
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
this.svg = this.svg
|
|
285
|
+
.append('g')
|
|
286
|
+
.attr('transform', 'translate(' + this.margin.left + ',' + this.margin.top + ')');
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Most charts share a default margin(s) state.
|
|
290
|
+
* In some cases, that state needs to be calculated based on the content that resides in that margin.
|
|
291
|
+
* For example, labels on a horizontal bar chart are dynamic and such the margin needs to be calculated ahead of
|
|
292
|
+
* chart axis construction.
|
|
293
|
+
* @param chartElm Reference to SVG on dom
|
|
294
|
+
* @param data Generic multi-dimensional IPcacData structure
|
|
295
|
+
* @param yScale D3 scale transformation object (d3.ScaleBand)
|
|
296
|
+
*/
|
|
297
|
+
setHorizontalMarginsBasedOnContent(chartElm, data, yScale) {
|
|
298
|
+
const axisY = axisLeft(yScale).ticks(5);
|
|
299
|
+
let max = 0;
|
|
300
|
+
select$1(chartElm.nativeElement).append('g')
|
|
301
|
+
.call(axisY)
|
|
302
|
+
.each((d, i, n) => {
|
|
303
|
+
if (n[i].getBBox().width > max) {
|
|
304
|
+
max = n[i].getBBox().width;
|
|
305
|
+
}
|
|
306
|
+
})
|
|
307
|
+
.remove();
|
|
308
|
+
this.margin.left = max;
|
|
309
|
+
this.margin.bottom = this.margin.bottom;
|
|
310
|
+
this.width = this.width - this.margin.left;
|
|
311
|
+
}
|
|
312
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacChart, deps: [{ token: PcacAxisBuilder }, { token: PcacGridBuilder }, { token: PcacTransitionService }, { token: PcacTooltipBuilder }, { token: PcacColorService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
313
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacChart, providedIn: 'root' }); }
|
|
314
|
+
}
|
|
315
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacChart, decorators: [{
|
|
316
|
+
type: Injectable,
|
|
317
|
+
args: [{
|
|
318
|
+
providedIn: 'root',
|
|
319
|
+
}]
|
|
320
|
+
}], ctorParameters: function () { return [{ type: PcacAxisBuilder }, { type: PcacGridBuilder }, { type: PcacTransitionService }, { type: PcacTooltipBuilder }, { type: PcacColorService }]; } });
|
|
321
|
+
|
|
322
|
+
class LineAreaChartEffectsBuilder {
|
|
323
|
+
constructor() {
|
|
324
|
+
this.lines = [];
|
|
325
|
+
}
|
|
326
|
+
buildEffects(config) {
|
|
327
|
+
this.config = config;
|
|
328
|
+
this.lines = [];
|
|
329
|
+
this.config.svg.selectAll('.line').each((d, i, n) => {
|
|
330
|
+
this.lines.push(n[i]);
|
|
331
|
+
});
|
|
332
|
+
this.buildCollection();
|
|
333
|
+
this.buildCanvas();
|
|
334
|
+
}
|
|
335
|
+
buildCollection() {
|
|
336
|
+
const collection = this.config.svg.append('g')
|
|
337
|
+
.attr('class', 'effects');
|
|
338
|
+
collection.append('path')
|
|
339
|
+
.attr('class', 'effect-line');
|
|
340
|
+
const mousePerLine = collection.selectAll('.effect-group')
|
|
341
|
+
.data(this.config.data.filter((elm) => {
|
|
342
|
+
return elm.data.length > 0;
|
|
343
|
+
}))
|
|
344
|
+
.enter().append('g')
|
|
345
|
+
.attr('class', 'effect-group');
|
|
346
|
+
mousePerLine.append('circle')
|
|
347
|
+
.attr('r', 7)
|
|
348
|
+
.attr('class', 'effect-circle')
|
|
349
|
+
.style('stroke', (d, i) => {
|
|
350
|
+
return this.config.colors[i];
|
|
351
|
+
});
|
|
352
|
+
mousePerLine.append('text')
|
|
353
|
+
.attr('class', 'effect-text')
|
|
354
|
+
.attr('y', 1.5)
|
|
355
|
+
.attr('transform', 'translate(10,3)');
|
|
356
|
+
}
|
|
357
|
+
buildCanvas() {
|
|
358
|
+
this.config.svg.append('rect')
|
|
359
|
+
.attr('class', 'effects-canvas')
|
|
360
|
+
.attr('width', this.config.width)
|
|
361
|
+
.attr('height', this.config.height)
|
|
362
|
+
.attr('pointer-events', 'all')
|
|
363
|
+
.on('mouseout', () => {
|
|
364
|
+
this.hideEffects();
|
|
365
|
+
})
|
|
366
|
+
.on('mouseover', () => {
|
|
367
|
+
this.showEffects();
|
|
368
|
+
})
|
|
369
|
+
.on('mousemove', (event) => {
|
|
370
|
+
const magic_offset = 65; // TODO: wish I understood this
|
|
371
|
+
this.onMouseMove([event.clientX - magic_offset, event.clientY]);
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
showEffects() {
|
|
375
|
+
this.config.svg.select('.effect-line')
|
|
376
|
+
.style('opacity', '1');
|
|
377
|
+
this.config.svg.selectAll('.effect-group circle')
|
|
378
|
+
.style('opacity', '1');
|
|
379
|
+
this.config.svg.selectAll('.effect-group text')
|
|
380
|
+
.style('opacity', '1');
|
|
381
|
+
}
|
|
382
|
+
hideEffects() {
|
|
383
|
+
this.config.svg.select('.effect-line')
|
|
384
|
+
.style('opacity', '0');
|
|
385
|
+
this.config.svg.selectAll('.effect-group circle')
|
|
386
|
+
.style('opacity', '0');
|
|
387
|
+
this.config.svg.selectAll('.effect-group text')
|
|
388
|
+
.style('opacity', '0');
|
|
389
|
+
}
|
|
390
|
+
onMouseMove(mousePos) {
|
|
391
|
+
this.updateLine(mousePos);
|
|
392
|
+
this.updateEffects(mousePos);
|
|
393
|
+
}
|
|
394
|
+
updateLine(mousePos) {
|
|
395
|
+
this.config.svg.select('.effect-line')
|
|
396
|
+
.attr('d', () => 'M' + mousePos[0] + ',' + this.config.height + ' ' + mousePos[0] + ',' + 0);
|
|
397
|
+
}
|
|
398
|
+
updateEffects(mousePos) {
|
|
399
|
+
this.config.svg.selectAll('.effect-group')
|
|
400
|
+
.attr('transform', (data, index, nodes) => {
|
|
401
|
+
let beginning = 0;
|
|
402
|
+
let end = this.lines[index].getTotalLength();
|
|
403
|
+
let target = 0;
|
|
404
|
+
let pos;
|
|
405
|
+
while (true) {
|
|
406
|
+
target = Math.floor((beginning + end) / 2);
|
|
407
|
+
pos = this.lines[index].getPointAtLength(target);
|
|
408
|
+
if ((target === end || target === beginning) && pos.x !== mousePos[0]) {
|
|
409
|
+
break;
|
|
410
|
+
}
|
|
411
|
+
if (pos.x > mousePos[0]) {
|
|
412
|
+
end = target;
|
|
413
|
+
}
|
|
414
|
+
else if (pos.x < mousePos[0]) {
|
|
415
|
+
beginning = target;
|
|
416
|
+
}
|
|
417
|
+
else {
|
|
418
|
+
break;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
select$1(nodes[index]).select('text')
|
|
422
|
+
.text(this.config.y.invert(pos.y).toFixed(0));
|
|
423
|
+
return 'translate(' + mousePos[0] + ',' + pos.y + ')';
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: LineAreaChartEffectsBuilder, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
427
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: LineAreaChartEffectsBuilder, providedIn: 'root' }); }
|
|
428
|
+
}
|
|
429
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: LineAreaChartEffectsBuilder, decorators: [{
|
|
430
|
+
type: Injectable,
|
|
431
|
+
args: [{
|
|
432
|
+
providedIn: 'root',
|
|
433
|
+
}]
|
|
434
|
+
}] });
|
|
435
|
+
|
|
436
|
+
class LineAreaChartBuilder extends PcacChart {
|
|
437
|
+
constructor(axisBuilder, gridBuilder, transitionService, tooltipBuilder, colorService) {
|
|
438
|
+
super(axisBuilder, gridBuilder, transitionService, tooltipBuilder, colorService);
|
|
439
|
+
this.axisBuilder = axisBuilder;
|
|
440
|
+
this.gridBuilder = gridBuilder;
|
|
441
|
+
this.transitionService = transitionService;
|
|
442
|
+
this.tooltipBuilder = tooltipBuilder;
|
|
443
|
+
this.colorService = colorService;
|
|
444
|
+
this.dotClickedSource = new Subject();
|
|
445
|
+
this.dotClicked$ = this.dotClickedSource.asObservable();
|
|
446
|
+
}
|
|
447
|
+
buildChart(chartElm, config) {
|
|
448
|
+
this.config = JSON.parse(JSON.stringify(config));
|
|
449
|
+
this.startData = range(this.config.data[0].data.length).map((d) => {
|
|
450
|
+
return {
|
|
451
|
+
value: 0,
|
|
452
|
+
key: ''
|
|
453
|
+
};
|
|
454
|
+
});
|
|
455
|
+
if (this.config.hideAxis) {
|
|
456
|
+
this.adjustForHiddenAxis();
|
|
457
|
+
}
|
|
458
|
+
this.initializeChartState(chartElm, this.config);
|
|
459
|
+
this.buildScales(this.config);
|
|
460
|
+
this.drawChart(chartElm, this.config);
|
|
461
|
+
}
|
|
462
|
+
adjustForHiddenAxis() {
|
|
463
|
+
this.config.height = this.config.height + 12;
|
|
464
|
+
this.margin.top = 8;
|
|
465
|
+
this.margin.bottom = 8;
|
|
466
|
+
this.margin.left = 8;
|
|
467
|
+
this.margin.right = 8;
|
|
468
|
+
}
|
|
469
|
+
buildScales(config) {
|
|
470
|
+
this.xScale = scaleLinear()
|
|
471
|
+
.domain([0, config.data[0].data.length - 1])
|
|
472
|
+
.range([0, this.width]);
|
|
473
|
+
this.yScale = scaleLinear()
|
|
474
|
+
.domain([0, config.domainMax])
|
|
475
|
+
.range([this.height, 0]);
|
|
476
|
+
this.line = line()
|
|
477
|
+
.x((d, i) => {
|
|
478
|
+
return this.xScale(i);
|
|
479
|
+
})
|
|
480
|
+
.y((d) => {
|
|
481
|
+
return this.yScale(d.value);
|
|
482
|
+
});
|
|
483
|
+
this.area = area()
|
|
484
|
+
.x((d, i) => {
|
|
485
|
+
return this.xScale(i);
|
|
486
|
+
})
|
|
487
|
+
.y0(this.height)
|
|
488
|
+
.y1((d) => {
|
|
489
|
+
return this.yScale(d.value);
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
drawChart(chartElm, config) {
|
|
493
|
+
this.buildContainer(chartElm);
|
|
494
|
+
if (!config.hideAxis) {
|
|
495
|
+
this.axisBuilder.drawAxis({
|
|
496
|
+
svg: this.svg,
|
|
497
|
+
numberOfTicks: config.numberOfTicks || 5,
|
|
498
|
+
height: this.height,
|
|
499
|
+
xScale: this.xScale,
|
|
500
|
+
yScale: this.yScale
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
if (!config.hideGrid) {
|
|
504
|
+
this.gridBuilder.drawHorizontalGrid({
|
|
505
|
+
svg: this.svg,
|
|
506
|
+
numberOfTicks: config.numberOfTicks || 5,
|
|
507
|
+
width: this.width,
|
|
508
|
+
xScale: this.xScale,
|
|
509
|
+
yScale: this.yScale
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
this.drawLineArea(config);
|
|
513
|
+
if (config.enableEffects) {
|
|
514
|
+
this.drawEffects(config);
|
|
515
|
+
}
|
|
516
|
+
this.drawDots(config);
|
|
517
|
+
}
|
|
518
|
+
drawLineArea(config) {
|
|
519
|
+
for (let i = 0; i < config.data.length; i++) {
|
|
520
|
+
if (config.isArea) {
|
|
521
|
+
this.drawArea(config.data[i].data, i);
|
|
522
|
+
}
|
|
523
|
+
this.drawLine(config.data[i].data, i);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
drawLine(lineData, index) {
|
|
527
|
+
this.svg.append('g')
|
|
528
|
+
.attr('class', 'lines')
|
|
529
|
+
.append('path')
|
|
530
|
+
.datum(lineData)
|
|
531
|
+
.attr('class', 'line')
|
|
532
|
+
.attr('d', this.line(this.startData))
|
|
533
|
+
.transition(transition()
|
|
534
|
+
.duration(this.transitionService.getTransitionDuration()))
|
|
535
|
+
.attr('d', this.line) // TODO: strongly type
|
|
536
|
+
.attr('stroke', () => {
|
|
537
|
+
return this.colors[index];
|
|
538
|
+
})
|
|
539
|
+
.attr('fill', 'none');
|
|
540
|
+
}
|
|
541
|
+
drawArea(lineData, index) {
|
|
542
|
+
this.svg.append('g')
|
|
543
|
+
.attr('class', 'areas')
|
|
544
|
+
.append('path')
|
|
545
|
+
.datum(lineData)
|
|
546
|
+
.attr('class', 'area')
|
|
547
|
+
.style('opacity', 0.5)
|
|
548
|
+
.style('fill', () => {
|
|
549
|
+
return this.colors[index]; // TODO: strongly type
|
|
550
|
+
})
|
|
551
|
+
.attr('d', this.line(this.startData))
|
|
552
|
+
.transition(transition()
|
|
553
|
+
.duration(this.transitionService.getTransitionDuration()))
|
|
554
|
+
.attr('d', this.area); // TODO: strongly type
|
|
555
|
+
}
|
|
556
|
+
drawEffects(config) {
|
|
557
|
+
if (config.enableEffects) {
|
|
558
|
+
const effectsBuilder = new LineAreaChartEffectsBuilder();
|
|
559
|
+
effectsBuilder.buildEffects({
|
|
560
|
+
svg: this.svg,
|
|
561
|
+
height: this.height,
|
|
562
|
+
width: this.width,
|
|
563
|
+
data: config.data,
|
|
564
|
+
colors: this.colors,
|
|
565
|
+
x: this.xScale,
|
|
566
|
+
y: this.yScale
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
drawDots(config) {
|
|
571
|
+
const self = this;
|
|
572
|
+
for (let index = 0; index < config.data.length; index++) {
|
|
573
|
+
this.svg.append('g')
|
|
574
|
+
.attr('class', 'dots')
|
|
575
|
+
.selectAll('.dot')
|
|
576
|
+
.data(config.data[index].data)
|
|
577
|
+
.enter().append('circle')
|
|
578
|
+
.attr('class', 'dot')
|
|
579
|
+
.attr('stroke', (d) => {
|
|
580
|
+
return this.colors[index];
|
|
581
|
+
})
|
|
582
|
+
.attr('cx', (d, i) => {
|
|
583
|
+
return this.xScale(i);
|
|
584
|
+
})
|
|
585
|
+
.attr('cy', (d) => {
|
|
586
|
+
return this.yScale(0);
|
|
587
|
+
})
|
|
588
|
+
.attr('fill', '#fff')
|
|
589
|
+
.on('mouseover', function (event, d) {
|
|
590
|
+
self.tooltipBuilder.showBarTooltip(event, d);
|
|
591
|
+
select$1(this).transition(transition()
|
|
592
|
+
.duration(self.transitionService.getTransitionDuration() / 3))
|
|
593
|
+
.attr('r', 6)
|
|
594
|
+
.attr('fill', self.colors[index]);
|
|
595
|
+
})
|
|
596
|
+
.on('mouseout', function () {
|
|
597
|
+
self.tooltipBuilder.hideTooltip();
|
|
598
|
+
select$1(this).transition(transition()
|
|
599
|
+
.duration(self.transitionService.getTransitionDuration() / 3))
|
|
600
|
+
.attr('r', 4)
|
|
601
|
+
.attr('fill', '#fff');
|
|
602
|
+
})
|
|
603
|
+
.on('click', (d, i) => {
|
|
604
|
+
this.dotClickedSource.next(d);
|
|
605
|
+
})
|
|
606
|
+
.transition(transition()
|
|
607
|
+
.duration(this.transitionService.getTransitionDuration()))
|
|
608
|
+
.attr('cy', (d) => {
|
|
609
|
+
return this.yScale(d.value);
|
|
610
|
+
})
|
|
611
|
+
.attr('r', 4);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
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 }); }
|
|
615
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: LineAreaChartBuilder, providedIn: 'root' }); }
|
|
616
|
+
}
|
|
617
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: LineAreaChartBuilder, decorators: [{
|
|
618
|
+
type: Injectable,
|
|
619
|
+
args: [{
|
|
620
|
+
providedIn: 'root',
|
|
621
|
+
}]
|
|
622
|
+
}], ctorParameters: function () { return [{ type: PcacAxisBuilder }, { type: PcacGridBuilder }, { type: PcacTransitionService }, { type: PcacTooltipBuilder }, { type: PcacColorService }]; } });
|
|
623
|
+
|
|
624
|
+
class PcacLineAreaChartComponent {
|
|
625
|
+
constructor(chartBuilder) {
|
|
626
|
+
this.chartBuilder = chartBuilder;
|
|
627
|
+
this.dotClicked = new EventEmitter();
|
|
628
|
+
this.chartBuilder.dotClicked$.subscribe(data => {
|
|
629
|
+
this.dotClicked.emit(data);
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
ngOnChanges() {
|
|
633
|
+
this.buildChart();
|
|
634
|
+
}
|
|
635
|
+
buildChart() {
|
|
636
|
+
if (this.config && this.config.data && this.config.data.length > 0) {
|
|
637
|
+
this.chartBuilder.buildChart(this.chartElm, this.config);
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
* Opting against fromEvent due to incompatibility with rxjs 5 => 6
|
|
642
|
+
*/
|
|
643
|
+
onResize() {
|
|
644
|
+
const self = this;
|
|
645
|
+
clearTimeout(this.resizeWindowTimeout);
|
|
646
|
+
this.resizeWindowTimeout = setTimeout(() => {
|
|
647
|
+
self.buildChart();
|
|
648
|
+
}, 300);
|
|
649
|
+
}
|
|
650
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacLineAreaChartComponent, deps: [{ token: LineAreaChartBuilder }], target: i0.ɵɵFactoryTarget.Component }); }
|
|
651
|
+
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 }); }
|
|
652
|
+
}
|
|
653
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacLineAreaChartComponent, decorators: [{
|
|
654
|
+
type: Component,
|
|
655
|
+
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;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"] }]
|
|
656
|
+
}], ctorParameters: function () { return [{ type: LineAreaChartBuilder }]; }, propDecorators: { config: [{
|
|
657
|
+
type: Input
|
|
658
|
+
}], chartElm: [{
|
|
659
|
+
type: ViewChild,
|
|
660
|
+
args: ['chart', { static: true }]
|
|
661
|
+
}], dotClicked: [{
|
|
662
|
+
type: Output
|
|
663
|
+
}], onResize: [{
|
|
664
|
+
type: HostListener,
|
|
665
|
+
args: ['window:resize']
|
|
666
|
+
}] } });
|
|
667
|
+
|
|
668
|
+
class PcacLineAreaChartModule {
|
|
669
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacLineAreaChartModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
670
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.1.6", ngImport: i0, type: PcacLineAreaChartModule, declarations: [PcacLineAreaChartComponent], imports: [CommonModule], exports: [PcacLineAreaChartComponent] }); }
|
|
671
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacLineAreaChartModule, imports: [CommonModule] }); }
|
|
672
|
+
}
|
|
673
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacLineAreaChartModule, decorators: [{
|
|
674
|
+
type: NgModule,
|
|
675
|
+
args: [{
|
|
676
|
+
declarations: [
|
|
677
|
+
PcacLineAreaChartComponent
|
|
678
|
+
],
|
|
679
|
+
imports: [
|
|
680
|
+
CommonModule,
|
|
681
|
+
],
|
|
682
|
+
exports: [
|
|
683
|
+
PcacLineAreaChartComponent
|
|
684
|
+
]
|
|
685
|
+
}]
|
|
686
|
+
}] });
|
|
687
|
+
|
|
688
|
+
class PieChartBuilder extends PcacChart {
|
|
689
|
+
constructor(axisBuilder, gridBuilder, transitionService, tooltipBuilder, colorService) {
|
|
690
|
+
super(axisBuilder, gridBuilder, transitionService, tooltipBuilder, colorService);
|
|
691
|
+
this.axisBuilder = axisBuilder;
|
|
692
|
+
this.gridBuilder = gridBuilder;
|
|
693
|
+
this.transitionService = transitionService;
|
|
694
|
+
this.tooltipBuilder = tooltipBuilder;
|
|
695
|
+
this.colorService = colorService;
|
|
696
|
+
this.sliceClickedSource = new Subject();
|
|
697
|
+
this.sliceClicked$ = this.sliceClickedSource.asObservable();
|
|
698
|
+
}
|
|
699
|
+
buildChart(chartElm, config) {
|
|
700
|
+
this.initializeChartState(chartElm, config);
|
|
701
|
+
this.radius = Math.min(Math.min(this.height, this.width), Math.min(this.height, this.width)) / 2;
|
|
702
|
+
this.buildShapes(config);
|
|
703
|
+
this.drawChart(chartElm, config);
|
|
704
|
+
}
|
|
705
|
+
buildShapes(config) {
|
|
706
|
+
const radiusOffset = 10;
|
|
707
|
+
this.arcShape = arc()
|
|
708
|
+
.innerRadius(0)
|
|
709
|
+
.outerRadius(this.radius - radiusOffset);
|
|
710
|
+
this.arcOverShape = arc()
|
|
711
|
+
.innerRadius(0)
|
|
712
|
+
.outerRadius(this.radius - radiusOffset + radiusOffset);
|
|
713
|
+
this.pieAngles = pie()
|
|
714
|
+
.sort(null)
|
|
715
|
+
.value((d) => d.value); // TODO: Strongly type
|
|
716
|
+
}
|
|
717
|
+
drawChart(chartElm, config) {
|
|
718
|
+
this.buildContainer(chartElm, true);
|
|
719
|
+
const self = this;
|
|
720
|
+
this.svg.selectAll('.pcac-arc')
|
|
721
|
+
.data(this.pieAngles(config.data))
|
|
722
|
+
.enter().append('g')
|
|
723
|
+
.attr('class', 'pcac-arc')
|
|
724
|
+
.append('path')
|
|
725
|
+
.style('fill', (d, i) => {
|
|
726
|
+
return this.colors[i];
|
|
727
|
+
})
|
|
728
|
+
.on('mouseover', function (_, d) {
|
|
729
|
+
const t = transition().duration(self.transitionService.getTransitionDuration() / 3);
|
|
730
|
+
const c = color(self.colors[d.index]);
|
|
731
|
+
const ct = c ? c.darker(1).toString() : self.colors[d.index];
|
|
732
|
+
select$1(this).transition(t)
|
|
733
|
+
.attr('d', self.arcOverShape)
|
|
734
|
+
.style('fill', ct);
|
|
735
|
+
})
|
|
736
|
+
.on('mousemove', (event, d) => {
|
|
737
|
+
self.tooltipBuilder.showBarTooltip(event, d.data);
|
|
738
|
+
})
|
|
739
|
+
.on('mouseout', function (_, d) {
|
|
740
|
+
self.tooltipBuilder.hideTooltip();
|
|
741
|
+
select$1(this).transition(transition()
|
|
742
|
+
.duration(self.transitionService.getTransitionDuration() / 3))
|
|
743
|
+
.attr('d', self.arcShape)
|
|
744
|
+
.style('fill', self.colors[d.index]);
|
|
745
|
+
})
|
|
746
|
+
.on('click', (d, i) => {
|
|
747
|
+
this.sliceClickedSource.next(d.data);
|
|
748
|
+
})
|
|
749
|
+
.transition(transition()
|
|
750
|
+
.duration(this.transitionService.getTransitionDuration()))
|
|
751
|
+
.attrTween('d', (b) => {
|
|
752
|
+
return this.tweenChart(b);
|
|
753
|
+
});
|
|
754
|
+
}
|
|
755
|
+
tweenChart(b) {
|
|
756
|
+
b.innerRadius = 0;
|
|
757
|
+
const i = interpolate({ startAngle: 0, endAngle: 0 }, b);
|
|
758
|
+
return (t) => this.arcShape(i(t)); // TODO: Strongly type
|
|
759
|
+
}
|
|
760
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PieChartBuilder, deps: [{ token: PcacAxisBuilder }, { token: PcacGridBuilder }, { token: PcacTransitionService }, { token: PcacTooltipBuilder }, { token: PcacColorService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
761
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PieChartBuilder, providedIn: 'root' }); }
|
|
762
|
+
}
|
|
763
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PieChartBuilder, decorators: [{
|
|
764
|
+
type: Injectable,
|
|
765
|
+
args: [{
|
|
766
|
+
providedIn: 'root',
|
|
767
|
+
}]
|
|
768
|
+
}], ctorParameters: function () { return [{ type: PcacAxisBuilder }, { type: PcacGridBuilder }, { type: PcacTransitionService }, { type: PcacTooltipBuilder }, { type: PcacColorService }]; } });
|
|
769
|
+
|
|
770
|
+
class PcacPieChartComponent {
|
|
771
|
+
constructor(chartBuilder) {
|
|
772
|
+
this.chartBuilder = chartBuilder;
|
|
773
|
+
this.sliceClicked = new EventEmitter();
|
|
774
|
+
this.chartBuilder.sliceClicked$.subscribe(data => {
|
|
775
|
+
this.sliceClicked.emit(data);
|
|
776
|
+
});
|
|
777
|
+
}
|
|
778
|
+
ngOnChanges() {
|
|
779
|
+
this.buildChart();
|
|
780
|
+
}
|
|
781
|
+
buildChart() {
|
|
782
|
+
if (this.config && this.config.data && this.config.data.length > 0) {
|
|
783
|
+
this.chartBuilder.buildChart(this.chartElm, this.config);
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
/**
|
|
787
|
+
* Opting against fromEvent due to incompatibility with rxjs 5 => 6
|
|
788
|
+
*/
|
|
789
|
+
onResize() {
|
|
790
|
+
const self = this;
|
|
791
|
+
clearTimeout(this.resizeWindowTimeout);
|
|
792
|
+
this.resizeWindowTimeout = setTimeout(() => {
|
|
793
|
+
self.buildChart();
|
|
794
|
+
}, 300);
|
|
795
|
+
}
|
|
796
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacPieChartComponent, deps: [{ token: PieChartBuilder }], target: i0.ɵɵFactoryTarget.Component }); }
|
|
797
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.1.6", type: PcacPieChartComponent, selector: "pcac-pie-chart", inputs: { config: "config" }, outputs: { sliceClicked: "sliceClicked" }, host: { listeners: { "window:resize": "onResize()" } }, viewQueries: [{ propertyName: "chartElm", first: true, predicate: ["chart"], descendants: true, static: 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 }); }
|
|
798
|
+
}
|
|
799
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacPieChartComponent, decorators: [{
|
|
800
|
+
type: Component,
|
|
801
|
+
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"] }]
|
|
802
|
+
}], ctorParameters: function () { return [{ type: PieChartBuilder }]; }, propDecorators: { config: [{
|
|
803
|
+
type: Input
|
|
804
|
+
}], chartElm: [{
|
|
805
|
+
type: ViewChild,
|
|
806
|
+
args: ['chart', { static: true }]
|
|
807
|
+
}], sliceClicked: [{
|
|
808
|
+
type: Output
|
|
809
|
+
}], onResize: [{
|
|
810
|
+
type: HostListener,
|
|
811
|
+
args: ['window:resize']
|
|
812
|
+
}] } });
|
|
813
|
+
|
|
814
|
+
class PcacPieChartModule {
|
|
815
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacPieChartModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
816
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.1.6", ngImport: i0, type: PcacPieChartModule, declarations: [PcacPieChartComponent], imports: [CommonModule], exports: [PcacPieChartComponent] }); }
|
|
817
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacPieChartModule, imports: [CommonModule] }); }
|
|
818
|
+
}
|
|
819
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacPieChartModule, decorators: [{
|
|
820
|
+
type: NgModule,
|
|
821
|
+
args: [{
|
|
822
|
+
exports: [
|
|
823
|
+
PcacPieChartComponent
|
|
824
|
+
],
|
|
825
|
+
imports: [
|
|
826
|
+
CommonModule,
|
|
827
|
+
],
|
|
828
|
+
declarations: [
|
|
829
|
+
PcacPieChartComponent
|
|
830
|
+
]
|
|
831
|
+
}]
|
|
832
|
+
}] });
|
|
833
|
+
|
|
834
|
+
class BarHorizontalChartBuilder extends PcacChart {
|
|
835
|
+
constructor(axisBuilder, gridBuilder, transitionService, tooltipBuilder, colorService) {
|
|
836
|
+
super(axisBuilder, gridBuilder, transitionService, tooltipBuilder, colorService);
|
|
837
|
+
this.axisBuilder = axisBuilder;
|
|
838
|
+
this.gridBuilder = gridBuilder;
|
|
839
|
+
this.transitionService = transitionService;
|
|
840
|
+
this.tooltipBuilder = tooltipBuilder;
|
|
841
|
+
this.colorService = colorService;
|
|
842
|
+
this.barClickedSource = new Subject();
|
|
843
|
+
this.barClicked$ = this.barClickedSource.asObservable();
|
|
844
|
+
}
|
|
845
|
+
buildChart(chartElm, config) {
|
|
846
|
+
this.config = JSON.parse(JSON.stringify(config));
|
|
847
|
+
if (this.config.hideAxis) {
|
|
848
|
+
this.adjustForHiddenAxis();
|
|
849
|
+
}
|
|
850
|
+
this.initializeChartState(chartElm, this.config);
|
|
851
|
+
if (config.colorOverride && config.colorOverride.colors) {
|
|
852
|
+
this.colors = config.colorOverride.colors.reverse();
|
|
853
|
+
}
|
|
854
|
+
this.buildScales(chartElm, this.config);
|
|
855
|
+
this.drawChart(chartElm, this.config);
|
|
856
|
+
}
|
|
857
|
+
adjustForHiddenAxis() {
|
|
858
|
+
if (!this.cachedMargins) {
|
|
859
|
+
this.cachedMargins = JSON.parse(JSON.stringify(this.margin));
|
|
860
|
+
}
|
|
861
|
+
this.margin = JSON.parse(JSON.stringify(this.cachedMargins));
|
|
862
|
+
this.config.height = this.config.height + this.margin.top + this.margin.bottom;
|
|
863
|
+
this.margin.top = 0;
|
|
864
|
+
this.margin.bottom = 0;
|
|
865
|
+
this.margin.left = 0;
|
|
866
|
+
this.margin.right = 0;
|
|
867
|
+
}
|
|
868
|
+
setStartState(data) {
|
|
869
|
+
if (data && data.data) {
|
|
870
|
+
for (let i = 0, l = data.data.length; i < l; ++i) {
|
|
871
|
+
data.data[i].value = 0;
|
|
872
|
+
this.setStartState(data.data[i]);
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
buildScales(chartElm, config) {
|
|
877
|
+
config.data[0].data.map((d) => {
|
|
878
|
+
return d.value;
|
|
879
|
+
});
|
|
880
|
+
this.xScale = scaleLinear()
|
|
881
|
+
.domain([0, config.domainMax]);
|
|
882
|
+
this.yScaleStacked = scaleBand()
|
|
883
|
+
.domain(config.data.map((d) => d.key))
|
|
884
|
+
.range([this.height, 0])
|
|
885
|
+
.padding(0.1);
|
|
886
|
+
this.yScaleGrouped = scaleBand()
|
|
887
|
+
.padding(0.05)
|
|
888
|
+
.rangeRound([0, this.yScaleStacked.bandwidth()])
|
|
889
|
+
.domain(config.data[0].data.map((d) => d.key));
|
|
890
|
+
this.setHorizontalMarginsBasedOnContent(chartElm, config.data, this.yScaleStacked);
|
|
891
|
+
this.xScale.range([0, this.width]);
|
|
892
|
+
}
|
|
893
|
+
drawChart(chartElm, config) {
|
|
894
|
+
this.buildContainer(chartElm);
|
|
895
|
+
this.axisBuilder.drawAxis({
|
|
896
|
+
svg: this.svg,
|
|
897
|
+
numberOfTicks: config.numberOfTicks || 5,
|
|
898
|
+
height: this.height,
|
|
899
|
+
xScale: this.xScale,
|
|
900
|
+
yScale: this.yScaleStacked,
|
|
901
|
+
xFormat: config.tickFormat || PcacTickFormatEnum.None,
|
|
902
|
+
yFormat: PcacTickFormatEnum.None,
|
|
903
|
+
hideXAxis: config.hideAxis
|
|
904
|
+
});
|
|
905
|
+
if (!config.hideGrid) {
|
|
906
|
+
this.gridBuilder.drawVerticalGrid({
|
|
907
|
+
svg: this.svg,
|
|
908
|
+
numberOfTicks: config.numberOfTicks || 5,
|
|
909
|
+
height: this.height,
|
|
910
|
+
xScale: this.xScale,
|
|
911
|
+
yScale: this.yScaleStacked
|
|
912
|
+
});
|
|
913
|
+
}
|
|
914
|
+
this.addGroups(config);
|
|
915
|
+
}
|
|
916
|
+
addGroups(config) {
|
|
917
|
+
const groupsContainer = this.svg.append('g')
|
|
918
|
+
.attr('class', 'pcac-bars')
|
|
919
|
+
.selectAll('g')
|
|
920
|
+
.data(config.data)
|
|
921
|
+
.enter().append('g')
|
|
922
|
+
.attr('class', 'pcac-bar-group')
|
|
923
|
+
.attr('data-group-id', (d, i) => {
|
|
924
|
+
return i;
|
|
925
|
+
})
|
|
926
|
+
.attr('transform', (d) => 'translate(0,' + this.yScaleStacked(d.key) + ')');
|
|
927
|
+
const group = groupsContainer.selectAll('rect')
|
|
928
|
+
.data((d) => {
|
|
929
|
+
return d.data;
|
|
930
|
+
});
|
|
931
|
+
this.drawBarsPerGroup(group, config);
|
|
932
|
+
// We have no thresholds to draw
|
|
933
|
+
if (!config.thresholds) {
|
|
934
|
+
return;
|
|
935
|
+
}
|
|
936
|
+
// Draw threshold across entire chart
|
|
937
|
+
if (config.thresholds.length === 1 && !config.thresholds[0].data) {
|
|
938
|
+
this.drawThresholdAcrossChart(config);
|
|
939
|
+
}
|
|
940
|
+
// Draw threshold across each group
|
|
941
|
+
if (config.thresholds.length > 1 && (!config.thresholds[0].data || config.isStacked)) {
|
|
942
|
+
this.drawThresholdsPerGroup(group, config);
|
|
943
|
+
}
|
|
944
|
+
// Draw threshold across each bar in group
|
|
945
|
+
if (config.thresholds.length > 1 && config.thresholds[0].data && !config.isStacked) {
|
|
946
|
+
this.drawThresholdsPerBarInGroup(group, config);
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
drawBarsPerGroup(groups, config) {
|
|
950
|
+
const self = this;
|
|
951
|
+
groups.enter().append('rect')
|
|
952
|
+
.attr('class', 'pcac-bar')
|
|
953
|
+
.attr('x', 0)
|
|
954
|
+
.attr('y', (d) => {
|
|
955
|
+
let value = !config.isStacked ? this.yScaleGrouped(d.key) : this.yScaleStacked(d.key);
|
|
956
|
+
return value ? value : 0;
|
|
957
|
+
})
|
|
958
|
+
.attr('data-group-bar-id', (_, i) => {
|
|
959
|
+
return i;
|
|
960
|
+
})
|
|
961
|
+
.attr('height', !config.isStacked ? this.yScaleGrouped.bandwidth() : this.yScaleStacked.bandwidth())
|
|
962
|
+
.style('fill', (d, i, n) => {
|
|
963
|
+
if (config.spreadColorsPerGroup) {
|
|
964
|
+
const groupIndex = parseInt(n[0].parentNode.getAttribute('data-group-id'), 10);
|
|
965
|
+
return this.colors[groupIndex];
|
|
966
|
+
}
|
|
967
|
+
return this.colors[i];
|
|
968
|
+
})
|
|
969
|
+
.attr('width', 0)
|
|
970
|
+
.on('mouseover', function (event, d) {
|
|
971
|
+
select$1(this).transition(transition()
|
|
972
|
+
.duration(self.transitionService.getTransitionDuration() / 7.5))
|
|
973
|
+
.style('fill', () => {
|
|
974
|
+
if (config.spreadColorsPerGroup) {
|
|
975
|
+
const groupIndex = parseInt(this.parentNode.getAttribute('data-group-id'), 10);
|
|
976
|
+
const c = color(self.colors[groupIndex]);
|
|
977
|
+
const ct = c ? c.darker(1).toString() : self.colors[groupIndex];
|
|
978
|
+
return ct;
|
|
979
|
+
}
|
|
980
|
+
const groupIndex = parseInt(this.getAttribute('data-group-bar-id'), 10);
|
|
981
|
+
const c = color(self.colors[groupIndex]);
|
|
982
|
+
const ct = c ? c.darker(1).toString() : self.colors[groupIndex];
|
|
983
|
+
return ct;
|
|
984
|
+
});
|
|
985
|
+
})
|
|
986
|
+
.on('mousemove', (event, d) => {
|
|
987
|
+
self.tooltipBuilder.showBarTooltip(event, d, config.tickFormat || PcacTickFormatEnum.None);
|
|
988
|
+
})
|
|
989
|
+
.on('mouseout', function (event, d) {
|
|
990
|
+
self.tooltipBuilder.hideTooltip();
|
|
991
|
+
select$1(this).transition(transition()
|
|
992
|
+
.duration(self.transitionService.getTransitionDuration() / 5))
|
|
993
|
+
.style('fill', () => {
|
|
994
|
+
if (config.spreadColorsPerGroup) {
|
|
995
|
+
const groupIndex = parseInt(this.parentNode.getAttribute('data-group-id'), 10);
|
|
996
|
+
return self.colors[groupIndex];
|
|
997
|
+
}
|
|
998
|
+
const groupIndex = parseInt(this.getAttribute('data-group-bar-id'), 10);
|
|
999
|
+
return self.colors[groupIndex];
|
|
1000
|
+
});
|
|
1001
|
+
})
|
|
1002
|
+
.on('click', (d) => {
|
|
1003
|
+
this.barClickedSource.next(d);
|
|
1004
|
+
})
|
|
1005
|
+
.transition(transition()
|
|
1006
|
+
.duration(this.transitionService.getTransitionDuration()))
|
|
1007
|
+
.attr('width', (d) => {
|
|
1008
|
+
return this.xScale(d.value);
|
|
1009
|
+
});
|
|
1010
|
+
}
|
|
1011
|
+
drawThresholdAcrossChart(config) {
|
|
1012
|
+
this.applyPreTransitionThresholdStyles(this.svg.select('.pcac-bars').append('rect'), config)
|
|
1013
|
+
.attr('height', this.height)
|
|
1014
|
+
.attr('data-group-threshold-id', (_, i) => {
|
|
1015
|
+
return i;
|
|
1016
|
+
})
|
|
1017
|
+
.on('mousemove', (event, _) => {
|
|
1018
|
+
this.tooltipBuilder.showBarTooltip(event, config.thresholds[0], config.tickFormat || PcacTickFormatEnum.None);
|
|
1019
|
+
})
|
|
1020
|
+
.transition(transition()
|
|
1021
|
+
.duration(this.transitionService.getTransitionDuration()))
|
|
1022
|
+
.attr('x', (d, i) => {
|
|
1023
|
+
return this.xScale(config.thresholds[i].value);
|
|
1024
|
+
});
|
|
1025
|
+
}
|
|
1026
|
+
drawThresholdsPerGroup(group, config) {
|
|
1027
|
+
const self = this;
|
|
1028
|
+
this.applyPreTransitionThresholdStyles(this.svg.selectAll('.pcac-bar-group').append('rect'), config)
|
|
1029
|
+
.attr('height', this.yScaleStacked.bandwidth())
|
|
1030
|
+
.attr('data-group-threshold-id', (_, i) => {
|
|
1031
|
+
return i;
|
|
1032
|
+
})
|
|
1033
|
+
.on('mousemove', function (event, d, i) {
|
|
1034
|
+
const index = Number(this.parentElement.dataset['groupId']);
|
|
1035
|
+
self.tooltipBuilder.showBarTooltip(event, config.isStacked ?
|
|
1036
|
+
config.thresholds[index].data[0] :
|
|
1037
|
+
config.thresholds[index], config.tickFormat || PcacTickFormatEnum.None);
|
|
1038
|
+
})
|
|
1039
|
+
.transition(transition()
|
|
1040
|
+
.duration(this.transitionService.getTransitionDuration()))
|
|
1041
|
+
.attr('x', (_, i) => {
|
|
1042
|
+
return this.xScale(config.isStacked ? config.thresholds[i].data[0].value : config.thresholds[i].value);
|
|
1043
|
+
});
|
|
1044
|
+
}
|
|
1045
|
+
drawThresholdsPerBarInGroup(group, config) {
|
|
1046
|
+
const self = this;
|
|
1047
|
+
this.applyPreTransitionThresholdStyles(group.enter().append('rect'), config)
|
|
1048
|
+
.attr('data-group-threshold-id', (_, i) => {
|
|
1049
|
+
return i;
|
|
1050
|
+
})
|
|
1051
|
+
.attr('height', this.yScaleGrouped.bandwidth())
|
|
1052
|
+
.on('mousemove', function (event, d, i, n) {
|
|
1053
|
+
const target = event.target;
|
|
1054
|
+
const index = Number(target.getAttribute("data-group-threshold-id"));
|
|
1055
|
+
self.tooltipBuilder.showBarTooltip(event, config.thresholds[Number(this.parentElement.dataset['groupId'])].data[index], config.tickFormat || PcacTickFormatEnum.None);
|
|
1056
|
+
})
|
|
1057
|
+
.transition(transition()
|
|
1058
|
+
.duration(this.transitionService.getTransitionDuration()))
|
|
1059
|
+
.attr('y', (d) => {
|
|
1060
|
+
return this.yScaleGrouped(d.key);
|
|
1061
|
+
})
|
|
1062
|
+
.attr('x', (d, i, n) => {
|
|
1063
|
+
return this.xScale(config.thresholds[n[0].parentElement.dataset['groupId']].data[i].value);
|
|
1064
|
+
});
|
|
1065
|
+
}
|
|
1066
|
+
applyPreTransitionThresholdStyles(elm, config) {
|
|
1067
|
+
return elm.attr('class', 'pcac-threshold')
|
|
1068
|
+
.style('fill', () => {
|
|
1069
|
+
return this.colorService.getAlert();
|
|
1070
|
+
})
|
|
1071
|
+
.style('stroke', () => {
|
|
1072
|
+
return this.colorService.getAlert();
|
|
1073
|
+
})
|
|
1074
|
+
.style('stroke-width', () => {
|
|
1075
|
+
return 2;
|
|
1076
|
+
})
|
|
1077
|
+
.attr('width', '3px')
|
|
1078
|
+
.on('mouseout', () => {
|
|
1079
|
+
this.tooltipBuilder.hideTooltip();
|
|
1080
|
+
});
|
|
1081
|
+
}
|
|
1082
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: BarHorizontalChartBuilder, deps: [{ token: PcacAxisBuilder }, { token: PcacGridBuilder }, { token: PcacTransitionService }, { token: PcacTooltipBuilder }, { token: PcacColorService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
1083
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: BarHorizontalChartBuilder, providedIn: 'root' }); }
|
|
1084
|
+
}
|
|
1085
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: BarHorizontalChartBuilder, decorators: [{
|
|
1086
|
+
type: Injectable,
|
|
1087
|
+
args: [{
|
|
1088
|
+
providedIn: 'root',
|
|
1089
|
+
}]
|
|
1090
|
+
}], ctorParameters: function () { return [{ type: PcacAxisBuilder }, { type: PcacGridBuilder }, { type: PcacTransitionService }, { type: PcacTooltipBuilder }, { type: PcacColorService }]; } });
|
|
1091
|
+
|
|
1092
|
+
class PcacBarChartHorizontalComponent {
|
|
1093
|
+
constructor(chartBuilder) {
|
|
1094
|
+
this.chartBuilder = chartBuilder;
|
|
1095
|
+
this.barClicked = new EventEmitter();
|
|
1096
|
+
this.chartBuilder.barClicked$.subscribe(data => {
|
|
1097
|
+
this.barClicked.emit(data);
|
|
1098
|
+
});
|
|
1099
|
+
}
|
|
1100
|
+
ngOnChanges() {
|
|
1101
|
+
this.buildChart();
|
|
1102
|
+
}
|
|
1103
|
+
buildChart() {
|
|
1104
|
+
if (this.config && this.config.data && this.config.data.length > 0) {
|
|
1105
|
+
this.chartBuilder.buildChart(this.chartElm, this.config);
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
/**
|
|
1109
|
+
* Opting against fromEvent due to incompatibility with rxjs 5 => 6
|
|
1110
|
+
*/
|
|
1111
|
+
onResize() {
|
|
1112
|
+
const self = this;
|
|
1113
|
+
clearTimeout(this.resizeWindowTimeout);
|
|
1114
|
+
this.resizeWindowTimeout = setTimeout(() => {
|
|
1115
|
+
self.buildChart();
|
|
1116
|
+
}, 300);
|
|
1117
|
+
}
|
|
1118
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacBarChartHorizontalComponent, deps: [{ token: BarHorizontalChartBuilder }], target: i0.ɵɵFactoryTarget.Component }); }
|
|
1119
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.1.6", type: PcacBarChartHorizontalComponent, selector: "pcac-bar-horizontal-chart", inputs: { config: "config" }, outputs: { barClicked: "barClicked" }, host: { listeners: { "window:resize": "onResize()" } }, viewQueries: [{ propertyName: "chartElm", first: true, predicate: ["chart"], descendants: true, static: 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 }); }
|
|
1120
|
+
}
|
|
1121
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacBarChartHorizontalComponent, decorators: [{
|
|
1122
|
+
type: Component,
|
|
1123
|
+
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"] }]
|
|
1124
|
+
}], ctorParameters: function () { return [{ type: BarHorizontalChartBuilder }]; }, propDecorators: { config: [{
|
|
1125
|
+
type: Input
|
|
1126
|
+
}], chartElm: [{
|
|
1127
|
+
type: ViewChild,
|
|
1128
|
+
args: ['chart', { static: true }]
|
|
1129
|
+
}], barClicked: [{
|
|
1130
|
+
type: Output
|
|
1131
|
+
}], onResize: [{
|
|
1132
|
+
type: HostListener,
|
|
1133
|
+
args: ['window:resize']
|
|
1134
|
+
}] } });
|
|
1135
|
+
|
|
1136
|
+
class PcacBarHorizontalChartModule {
|
|
1137
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacBarHorizontalChartModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
1138
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.1.6", ngImport: i0, type: PcacBarHorizontalChartModule, declarations: [PcacBarChartHorizontalComponent], exports: [PcacBarChartHorizontalComponent] }); }
|
|
1139
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacBarHorizontalChartModule }); }
|
|
1140
|
+
}
|
|
1141
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacBarHorizontalChartModule, decorators: [{
|
|
1142
|
+
type: NgModule,
|
|
1143
|
+
args: [{
|
|
1144
|
+
exports: [
|
|
1145
|
+
PcacBarChartHorizontalComponent
|
|
1146
|
+
],
|
|
1147
|
+
declarations: [
|
|
1148
|
+
PcacBarChartHorizontalComponent
|
|
1149
|
+
]
|
|
1150
|
+
}]
|
|
1151
|
+
}] });
|
|
1152
|
+
|
|
1153
|
+
class BarVerticalChartBuilder extends PcacChart {
|
|
1154
|
+
constructor(axisBuilder, gridBuilder, transitionService, tooltipBuilder, colorService) {
|
|
1155
|
+
super(axisBuilder, gridBuilder, transitionService, tooltipBuilder, colorService);
|
|
1156
|
+
this.axisBuilder = axisBuilder;
|
|
1157
|
+
this.gridBuilder = gridBuilder;
|
|
1158
|
+
this.transitionService = transitionService;
|
|
1159
|
+
this.tooltipBuilder = tooltipBuilder;
|
|
1160
|
+
this.colorService = colorService;
|
|
1161
|
+
this.barClickedSource = new Subject();
|
|
1162
|
+
this.barClicked$ = this.barClickedSource.asObservable();
|
|
1163
|
+
}
|
|
1164
|
+
buildChart(chartElm, config) {
|
|
1165
|
+
if (config.colorOverride && config.colorOverride.colors) {
|
|
1166
|
+
this.colors = config.colorOverride.colors;
|
|
1167
|
+
}
|
|
1168
|
+
if (config.hideAxis) {
|
|
1169
|
+
this.adjustForHiddenAxis(config);
|
|
1170
|
+
}
|
|
1171
|
+
this.initializeChartState(chartElm, config);
|
|
1172
|
+
if (config.colorOverride && config.colorOverride.colors) {
|
|
1173
|
+
this.colors = config.colorOverride.colors.reverse();
|
|
1174
|
+
}
|
|
1175
|
+
this.buildScales(config);
|
|
1176
|
+
this.drawChart(chartElm, config);
|
|
1177
|
+
}
|
|
1178
|
+
adjustForHiddenAxis(config) {
|
|
1179
|
+
const hasGroupLabel = this.hasGroupLabel(config);
|
|
1180
|
+
config.height = config.height + this.margin.top;
|
|
1181
|
+
if (!hasGroupLabel) {
|
|
1182
|
+
config.height = config.height + this.margin.bottom;
|
|
1183
|
+
}
|
|
1184
|
+
this.margin.top = 0;
|
|
1185
|
+
this.margin.bottom = hasGroupLabel ? this.margin.bottom : 0;
|
|
1186
|
+
this.margin.left = 0;
|
|
1187
|
+
this.margin.right = 0;
|
|
1188
|
+
}
|
|
1189
|
+
hasGroupLabel(config) {
|
|
1190
|
+
let hasGroupLabel = false;
|
|
1191
|
+
config.data.forEach(node => {
|
|
1192
|
+
if (node.key) {
|
|
1193
|
+
hasGroupLabel = true;
|
|
1194
|
+
}
|
|
1195
|
+
});
|
|
1196
|
+
return hasGroupLabel;
|
|
1197
|
+
}
|
|
1198
|
+
buildScales(config) {
|
|
1199
|
+
this.yScale = scaleLinear()
|
|
1200
|
+
.rangeRound([0, config.height])
|
|
1201
|
+
.domain([config.domainMax, 0]);
|
|
1202
|
+
this.xScaleStacked = scaleBand()
|
|
1203
|
+
.domain(config.data.map((d) => d.key))
|
|
1204
|
+
.rangeRound([0, this.width])
|
|
1205
|
+
.padding(0.1);
|
|
1206
|
+
this.xScaleGrouped = scaleBand()
|
|
1207
|
+
.padding(0.2)
|
|
1208
|
+
.rangeRound([0, this.xScaleStacked.bandwidth()])
|
|
1209
|
+
.domain(config.data[0].data.map((d) => d.key));
|
|
1210
|
+
}
|
|
1211
|
+
drawChart(chartElm, config) {
|
|
1212
|
+
this.buildContainer(chartElm);
|
|
1213
|
+
this.axisBuilder.drawAxis({
|
|
1214
|
+
svg: this.svg,
|
|
1215
|
+
numberOfTicks: config.numberOfTicks || 5,
|
|
1216
|
+
height: this.height,
|
|
1217
|
+
xScale: this.xScaleStacked,
|
|
1218
|
+
yScale: this.yScale,
|
|
1219
|
+
xFormat: PcacTickFormatEnum.None,
|
|
1220
|
+
yFormat: config.tickFormat || PcacTickFormatEnum.None,
|
|
1221
|
+
hideYAxis: config.hideAxis
|
|
1222
|
+
});
|
|
1223
|
+
if (!config.hideGrid) {
|
|
1224
|
+
this.gridBuilder.drawHorizontalGrid({
|
|
1225
|
+
svg: this.svg,
|
|
1226
|
+
numberOfTicks: config.numberOfTicks || 5,
|
|
1227
|
+
width: this.width,
|
|
1228
|
+
xScale: this.xScaleStacked,
|
|
1229
|
+
yScale: this.yScale
|
|
1230
|
+
});
|
|
1231
|
+
}
|
|
1232
|
+
this.addGroups(config);
|
|
1233
|
+
}
|
|
1234
|
+
addGroups(config) {
|
|
1235
|
+
const groupsContainer = this.svg.append('g')
|
|
1236
|
+
.attr('class', 'pcac-bars')
|
|
1237
|
+
.selectAll('g')
|
|
1238
|
+
.data(config.data)
|
|
1239
|
+
.enter().append('g')
|
|
1240
|
+
.attr('class', 'pcac-bar-group')
|
|
1241
|
+
.attr('data-group-id', (d, i) => {
|
|
1242
|
+
return i;
|
|
1243
|
+
})
|
|
1244
|
+
.attr('transform', (d, i) => {
|
|
1245
|
+
return 'translate(' + this.xScaleStacked(d.key) + ',0)';
|
|
1246
|
+
});
|
|
1247
|
+
const group = groupsContainer.selectAll('rect')
|
|
1248
|
+
.data((d, i) => {
|
|
1249
|
+
return d.data;
|
|
1250
|
+
});
|
|
1251
|
+
this.drawBarsPerGroup(group, config);
|
|
1252
|
+
// We have no thresholds to draw
|
|
1253
|
+
if (!config.thresholds) {
|
|
1254
|
+
return;
|
|
1255
|
+
}
|
|
1256
|
+
// Draw threshold across entire chart
|
|
1257
|
+
if (config.thresholds.length === 1 && !config.thresholds[0].data) {
|
|
1258
|
+
this.drawThresholdAcrossChart(config);
|
|
1259
|
+
}
|
|
1260
|
+
// Draw threshold across each group
|
|
1261
|
+
if (config.thresholds.length > 1 && (!config.thresholds[0].data || config.isStacked)) {
|
|
1262
|
+
this.drawThresholdsPerGroup(group, config);
|
|
1263
|
+
}
|
|
1264
|
+
// Draw threshold across each bar in group
|
|
1265
|
+
if (config.thresholds.length > 1 && config.thresholds[0].data && !config.isStacked) {
|
|
1266
|
+
this.drawThresholdsPerBarInGroup(group, config);
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
drawBarsPerGroup(group, config) {
|
|
1270
|
+
const self = this;
|
|
1271
|
+
group.enter().append('rect')
|
|
1272
|
+
.attr('class', 'pcac-bar')
|
|
1273
|
+
.attr('x', (d, i) => {
|
|
1274
|
+
let value = !config.isStacked ? this.xScaleGrouped(d.key) : this.xScaleStacked(d.key);
|
|
1275
|
+
return value ? value : 0;
|
|
1276
|
+
})
|
|
1277
|
+
.attr('data-group-bar-id', (_, i) => {
|
|
1278
|
+
return i;
|
|
1279
|
+
})
|
|
1280
|
+
.style('fill', (d, i, n) => {
|
|
1281
|
+
if (config.spreadColorsPerGroup) {
|
|
1282
|
+
const groupIndex = parseInt(n[0].parentNode.getAttribute('data-group-id'), 10);
|
|
1283
|
+
return this.colors[groupIndex];
|
|
1284
|
+
}
|
|
1285
|
+
return this.colors[i];
|
|
1286
|
+
})
|
|
1287
|
+
.attr('y', () => {
|
|
1288
|
+
return this.height;
|
|
1289
|
+
})
|
|
1290
|
+
.attr('height', 0)
|
|
1291
|
+
.on('mouseover', function (event, d) {
|
|
1292
|
+
select$1(this).transition(transition()
|
|
1293
|
+
.duration(self.transitionService.getTransitionDuration() / 5))
|
|
1294
|
+
.style('fill', () => {
|
|
1295
|
+
if (config.spreadColorsPerGroup) {
|
|
1296
|
+
const groupIndex = parseInt(this.parentNode.getAttribute('data-group-id'), 10);
|
|
1297
|
+
const c = color(self.colors[groupIndex]);
|
|
1298
|
+
const ct = c ? c.darker(1).toString() : self.colors[groupIndex];
|
|
1299
|
+
return ct;
|
|
1300
|
+
}
|
|
1301
|
+
const groupIndex = parseInt(this.getAttribute('data-group-bar-id'), 10);
|
|
1302
|
+
const c = color(self.colors[groupIndex]);
|
|
1303
|
+
const ct = c ? c.darker(1).toString() : self.colors[groupIndex];
|
|
1304
|
+
return ct;
|
|
1305
|
+
});
|
|
1306
|
+
})
|
|
1307
|
+
.on('mousemove', (event, d) => {
|
|
1308
|
+
self.tooltipBuilder.showBarTooltip(event, d, config.tickFormat || PcacTickFormatEnum.None);
|
|
1309
|
+
})
|
|
1310
|
+
.on('mouseout', function (d) {
|
|
1311
|
+
self.tooltipBuilder.hideTooltip();
|
|
1312
|
+
select$1(this).transition(transition()
|
|
1313
|
+
.duration(self.transitionService.getTransitionDuration() / 5))
|
|
1314
|
+
.style('fill', () => {
|
|
1315
|
+
if (config.spreadColorsPerGroup) {
|
|
1316
|
+
const groupIndex = parseInt(this.parentNode.getAttribute('data-group-id'), 10);
|
|
1317
|
+
return self.colors[groupIndex];
|
|
1318
|
+
}
|
|
1319
|
+
const groupIndex = parseInt(this.getAttribute('data-group-bar-id'), 10);
|
|
1320
|
+
return self.colors[groupIndex];
|
|
1321
|
+
});
|
|
1322
|
+
})
|
|
1323
|
+
.on('click', (_, d) => {
|
|
1324
|
+
this.barClickedSource.next(d);
|
|
1325
|
+
})
|
|
1326
|
+
.transition(transition()
|
|
1327
|
+
.duration(this.transitionService.getTransitionDuration()))
|
|
1328
|
+
.attr('width', !config.isStacked ? this.xScaleGrouped.bandwidth() : this.xScaleStacked.bandwidth())
|
|
1329
|
+
.attr('y', (d) => {
|
|
1330
|
+
return this.yScale(d.value);
|
|
1331
|
+
})
|
|
1332
|
+
.attr('height', (d) => {
|
|
1333
|
+
return this.height - this.yScale(d.value);
|
|
1334
|
+
});
|
|
1335
|
+
}
|
|
1336
|
+
drawThresholdAcrossChart(config) {
|
|
1337
|
+
this.applyPreTransitionThresholdStyles(this.svg.select('.pcac-bars').append('rect'), config)
|
|
1338
|
+
.attr('width', this.width)
|
|
1339
|
+
.attr('data-group-threshold-id', (_, i) => {
|
|
1340
|
+
return i;
|
|
1341
|
+
})
|
|
1342
|
+
.on('mousemove', (event, d, i) => {
|
|
1343
|
+
this.tooltipBuilder.showBarTooltip(event, config.thresholds[0], config.tickFormat || PcacTickFormatEnum.None);
|
|
1344
|
+
})
|
|
1345
|
+
.transition(transition()
|
|
1346
|
+
.duration(this.transitionService.getTransitionDuration()))
|
|
1347
|
+
.attr('y', (d, i) => {
|
|
1348
|
+
return this.yScale(config.thresholds[i].value);
|
|
1349
|
+
});
|
|
1350
|
+
}
|
|
1351
|
+
drawThresholdsPerGroup(group, config) {
|
|
1352
|
+
const self = this;
|
|
1353
|
+
this.applyPreTransitionThresholdStyles(this.svg.selectAll('.pcac-bar-group').append('rect'), config)
|
|
1354
|
+
.attr('width', this.xScaleStacked.bandwidth())
|
|
1355
|
+
.attr('data-group-threshold-id', (_, i) => {
|
|
1356
|
+
return i;
|
|
1357
|
+
})
|
|
1358
|
+
.on('mousemove', function (event) {
|
|
1359
|
+
const index = Number(this.parentElement.dataset['groupId']);
|
|
1360
|
+
self.tooltipBuilder.showBarTooltip(event, config.isStacked ?
|
|
1361
|
+
config.thresholds[index].data[0] :
|
|
1362
|
+
config.thresholds[index], config.tickFormat || PcacTickFormatEnum.None);
|
|
1363
|
+
})
|
|
1364
|
+
.transition(transition()
|
|
1365
|
+
.duration(this.transitionService.getTransitionDuration()))
|
|
1366
|
+
.attr('y', (d, i) => {
|
|
1367
|
+
return this.yScale(config.isStacked ? config.thresholds[i].data[0].value : config.thresholds[i].value);
|
|
1368
|
+
});
|
|
1369
|
+
}
|
|
1370
|
+
drawThresholdsPerBarInGroup(group, config) {
|
|
1371
|
+
const self = this;
|
|
1372
|
+
this.applyPreTransitionThresholdStyles(group.enter().append('rect'), config)
|
|
1373
|
+
.attr('data-group-threshold-id', (_, i) => {
|
|
1374
|
+
return i;
|
|
1375
|
+
})
|
|
1376
|
+
.on('mousemove', function (event, _) {
|
|
1377
|
+
const target = event.target;
|
|
1378
|
+
const index = Number(target.getAttribute("data-group-threshold-id"));
|
|
1379
|
+
self.tooltipBuilder.showBarTooltip(event, config.thresholds[Number(this.parentElement.dataset['groupId'])].data[index], config.tickFormat || PcacTickFormatEnum.None);
|
|
1380
|
+
})
|
|
1381
|
+
.attr('width', this.xScaleGrouped.bandwidth())
|
|
1382
|
+
.transition(transition()
|
|
1383
|
+
.duration(this.transitionService.getTransitionDuration()))
|
|
1384
|
+
.attr('y', (d, i, n) => {
|
|
1385
|
+
return this.yScale(config.thresholds[n[0].parentElement.dataset['groupId']].data[i].value);
|
|
1386
|
+
});
|
|
1387
|
+
}
|
|
1388
|
+
applyPreTransitionThresholdStyles(elm, config) {
|
|
1389
|
+
return elm.attr('class', 'pcac-threshold')
|
|
1390
|
+
.attr('x', (d) => {
|
|
1391
|
+
return this.xScaleGrouped(d ? d.key : '');
|
|
1392
|
+
})
|
|
1393
|
+
.attr('y', () => {
|
|
1394
|
+
return this.height;
|
|
1395
|
+
})
|
|
1396
|
+
.attr('height', 0)
|
|
1397
|
+
.style('fill', () => {
|
|
1398
|
+
return this.colorService.getAlert();
|
|
1399
|
+
})
|
|
1400
|
+
.style('stroke', () => {
|
|
1401
|
+
return this.colorService.getAlert();
|
|
1402
|
+
})
|
|
1403
|
+
.style('stroke-width', () => {
|
|
1404
|
+
return 2;
|
|
1405
|
+
})
|
|
1406
|
+
.on('mouseout', () => {
|
|
1407
|
+
this.tooltipBuilder.hideTooltip();
|
|
1408
|
+
})
|
|
1409
|
+
.attr('height', () => {
|
|
1410
|
+
return '3px';
|
|
1411
|
+
});
|
|
1412
|
+
}
|
|
1413
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: BarVerticalChartBuilder, deps: [{ token: PcacAxisBuilder }, { token: PcacGridBuilder }, { token: PcacTransitionService }, { token: PcacTooltipBuilder }, { token: PcacColorService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
1414
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: BarVerticalChartBuilder, providedIn: 'root' }); }
|
|
1415
|
+
}
|
|
1416
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: BarVerticalChartBuilder, decorators: [{
|
|
1417
|
+
type: Injectable,
|
|
1418
|
+
args: [{
|
|
1419
|
+
providedIn: 'root',
|
|
1420
|
+
}]
|
|
1421
|
+
}], ctorParameters: function () { return [{ type: PcacAxisBuilder }, { type: PcacGridBuilder }, { type: PcacTransitionService }, { type: PcacTooltipBuilder }, { type: PcacColorService }]; } });
|
|
1422
|
+
|
|
1423
|
+
class PcacBarVerticalChartComponent {
|
|
1424
|
+
constructor(chartBuilder) {
|
|
1425
|
+
this.chartBuilder = chartBuilder;
|
|
1426
|
+
this.barClicked = new EventEmitter();
|
|
1427
|
+
this.chartBuilder.barClicked$.subscribe(data => {
|
|
1428
|
+
this.barClicked.emit(data);
|
|
1429
|
+
});
|
|
1430
|
+
}
|
|
1431
|
+
ngOnChanges() {
|
|
1432
|
+
this.buildChart();
|
|
1433
|
+
}
|
|
1434
|
+
buildChart() {
|
|
1435
|
+
if (this.config && this.config.data && this.config.data.length > 0) {
|
|
1436
|
+
this.chartBuilder.buildChart(this.chartElm, this.config);
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
/**
|
|
1440
|
+
* Opting against fromEvent due to incompatibility with rxjs 5 => 6
|
|
1441
|
+
*/
|
|
1442
|
+
onResize() {
|
|
1443
|
+
const self = this;
|
|
1444
|
+
clearTimeout(this.resizeWindowTimeout);
|
|
1445
|
+
this.resizeWindowTimeout = setTimeout(() => {
|
|
1446
|
+
self.buildChart();
|
|
1447
|
+
}, 300);
|
|
1448
|
+
}
|
|
1449
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacBarVerticalChartComponent, deps: [{ token: BarVerticalChartBuilder }], target: i0.ɵɵFactoryTarget.Component }); }
|
|
1450
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.1.6", type: PcacBarVerticalChartComponent, selector: "pcac-bar-vertical-chart", inputs: { config: "config" }, outputs: { barClicked: "barClicked" }, host: { listeners: { "window:resize": "onResize()" } }, viewQueries: [{ propertyName: "chartElm", first: true, predicate: ["chart"], descendants: true, static: 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 }); }
|
|
1451
|
+
}
|
|
1452
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacBarVerticalChartComponent, decorators: [{
|
|
1453
|
+
type: Component,
|
|
1454
|
+
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"] }]
|
|
1455
|
+
}], ctorParameters: function () { return [{ type: BarVerticalChartBuilder }]; }, propDecorators: { config: [{
|
|
1456
|
+
type: Input
|
|
1457
|
+
}], chartElm: [{
|
|
1458
|
+
type: ViewChild,
|
|
1459
|
+
args: ['chart', { static: true }]
|
|
1460
|
+
}], barClicked: [{
|
|
1461
|
+
type: Output
|
|
1462
|
+
}], onResize: [{
|
|
1463
|
+
type: HostListener,
|
|
1464
|
+
args: ['window:resize']
|
|
1465
|
+
}] } });
|
|
1466
|
+
|
|
1467
|
+
class PcacBarVerticalChartModule {
|
|
1468
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacBarVerticalChartModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
1469
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.1.6", ngImport: i0, type: PcacBarVerticalChartModule, declarations: [PcacBarVerticalChartComponent], exports: [PcacBarVerticalChartComponent] }); }
|
|
1470
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacBarVerticalChartModule }); }
|
|
1471
|
+
}
|
|
1472
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.6", ngImport: i0, type: PcacBarVerticalChartModule, decorators: [{
|
|
1473
|
+
type: NgModule,
|
|
1474
|
+
args: [{
|
|
1475
|
+
exports: [
|
|
1476
|
+
PcacBarVerticalChartComponent
|
|
1477
|
+
],
|
|
1478
|
+
declarations: [
|
|
1479
|
+
PcacBarVerticalChartComponent
|
|
1480
|
+
]
|
|
1481
|
+
}]
|
|
1482
|
+
}] });
|
|
1483
|
+
|
|
1484
|
+
/*
|
|
1485
|
+
* Public API Surface of pioneer-charts
|
|
1486
|
+
*/
|
|
1487
|
+
|
|
1488
|
+
/**
|
|
1489
|
+
* Generated bundle index. Do not edit.
|
|
1490
|
+
*/
|
|
1491
|
+
|
|
1492
|
+
export { BarHorizontalChartBuilder, BarVerticalChartBuilder, LineAreaChartBuilder, PcacAxisBuilder, PcacBarChartHorizontalComponent, PcacBarHorizontalChartModule, PcacBarVerticalChartComponent, PcacBarVerticalChartModule, PcacChart, PcacColorService, PcacGridBuilder, PcacLineAreaChartComponent, PcacLineAreaChartModule, PcacPieChartComponent, PcacPieChartModule, PcacTickFormatEnum, PcacTooltipBuilder, PcacTransitionService, PieChartBuilder };
|
|
1493
|
+
//# sourceMappingURL=pioneer-code-pioneer-charts.mjs.map
|