@designsystem-se/af 35.3.1 → 35.4.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/digi-bar-chart.js +126 -111
- package/components/digi-chart-line.js +1 -1
- package/components/digi-code-block.js +1 -1
- package/components/digi-code-example.js +1 -1
- package/components/digi-info-card.js +1 -1
- package/components/digi-link-button.js +3 -1
- package/components/p-472bc7d3.js +129 -0
- package/custom-elements.json +6 -2
- package/dist/cjs/digi-arbetsformedlingen.cjs.js +1 -1
- package/dist/cjs/{digi-button_24.cjs.entry.js → digi-bar-chart_27.cjs.entry.js} +1611 -47
- package/dist/cjs/digi-calendar-datepicker.cjs.entry.js +2 -2
- package/dist/cjs/digi-chart-line.cjs.entry.js +1 -1
- package/dist/cjs/digi-code-block_3.cjs.entry.js +3 -3
- package/dist/cjs/digi-dialog.cjs.entry.js +2 -2
- package/dist/cjs/digi-footer.cjs.entry.js +2 -2
- package/dist/cjs/digi-form-error-list.cjs.entry.js +2 -2
- package/dist/cjs/digi-form-receipt.cjs.entry.js +2 -2
- package/dist/cjs/digi-form-select-filter.cjs.entry.js +2 -2
- package/dist/cjs/digi-info-card.cjs.entry.js +1 -1
- package/dist/cjs/digi-link-button.cjs.entry.js +2 -1
- package/dist/cjs/digi-navigation-pagination.cjs.entry.js +2 -2
- package/dist/cjs/digi-notification-alert.cjs.entry.js +2 -2
- package/dist/cjs/digi-notification-error-page.cjs.entry.js +2 -2
- package/dist/cjs/digi-tools-feedback.cjs.entry.js +2 -2
- package/dist/cjs/digi-typography-heading-jumbo.cjs.entry.js +38 -0
- package/dist/cjs/digi-typography-preamble.cjs.entry.js +20 -0
- package/dist/cjs/index-7a477838.js +10 -14
- package/dist/cjs/index.cjs.js +20 -20
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/typography-heading-jumbo-variation.enum-8677e099.js +17 -0
- package/dist/cjs/{typography-variation.enum-9f56fd50.js → typography-variation.enum-8fd8bed4.js} +6 -16
- package/dist/collection/components/_chart/bar-chart/bar-chart.css +13 -19
- package/dist/collection/components/_chart/bar-chart/bar-chart.js +125 -110
- package/dist/collection/components/_chart/chart-line/chart-line.css +19 -23
- package/dist/collection/components/_code/code-block/code-block.css +2 -2
- package/dist/collection/components/_info-card/info-card/info-card.js +5 -5
- package/dist/collection/components/_link/link-button/link-button.js +24 -1
- package/dist/digi-arbetsformedlingen/digi-arbetsformedlingen.esm.js +1 -1
- package/dist/digi-arbetsformedlingen/index.esm.js +1 -1
- package/dist/digi-arbetsformedlingen/p-044b32d7.entry.js +1 -0
- package/dist/digi-arbetsformedlingen/{p-e2330d9c.entry.js → p-1241d74a.entry.js} +1 -1
- package/dist/digi-arbetsformedlingen/{p-e54f5b28.entry.js → p-222a2b41.entry.js} +1 -1
- package/dist/digi-arbetsformedlingen/p-37377041.entry.js +1 -0
- package/dist/digi-arbetsformedlingen/p-3ae60edc.entry.js +1 -0
- package/dist/digi-arbetsformedlingen/p-431baa4e.entry.js +1 -0
- package/dist/digi-arbetsformedlingen/{p-0d35dc92.entry.js → p-56ca6c5c.entry.js} +1 -1
- package/dist/digi-arbetsformedlingen/{p-6559910e.entry.js → p-58f76475.entry.js} +1 -1
- package/dist/digi-arbetsformedlingen/{p-092d0e3e.entry.js → p-5a08f170.entry.js} +1 -1
- package/dist/digi-arbetsformedlingen/p-5aae7437.entry.js +1 -0
- package/dist/digi-arbetsformedlingen/{p-c04b06a2.entry.js → p-5ac3d7a9.entry.js} +1 -1
- package/dist/digi-arbetsformedlingen/{p-e0db40e9.entry.js → p-69010d14.entry.js} +1 -1
- package/dist/digi-arbetsformedlingen/{p-f1a6524e.entry.js → p-83b3f053.entry.js} +1 -1
- package/dist/digi-arbetsformedlingen/p-86eddf30.js +1 -0
- package/dist/digi-arbetsformedlingen/p-9f03b573.entry.js +1 -0
- package/dist/digi-arbetsformedlingen/p-a884ccf8.entry.js +1 -0
- package/dist/digi-arbetsformedlingen/{p-01f5f243.entry.js → p-c4cf1215.entry.js} +1 -1
- package/dist/digi-arbetsformedlingen/p-d1886fff.js +1 -0
- package/dist/digi-arbetsformedlingen/{p-5c7acd45.entry.js → p-e3bdf65a.entry.js} +1 -1
- package/dist/esm/digi-arbetsformedlingen.js +1 -1
- package/dist/esm/{digi-button_24.entry.js → digi-bar-chart_27.entry.js} +1608 -47
- package/dist/esm/digi-calendar-datepicker.entry.js +2 -2
- package/dist/esm/digi-chart-line.entry.js +1 -1
- package/dist/esm/digi-code-block_3.entry.js +3 -3
- package/dist/esm/digi-dialog.entry.js +2 -2
- package/dist/esm/digi-footer.entry.js +2 -2
- package/dist/esm/digi-form-error-list.entry.js +2 -2
- package/dist/esm/digi-form-receipt.entry.js +2 -2
- package/dist/esm/digi-form-select-filter.entry.js +2 -2
- package/dist/esm/digi-info-card.entry.js +1 -1
- package/dist/esm/digi-link-button.entry.js +2 -1
- package/dist/esm/digi-navigation-pagination.entry.js +2 -2
- package/dist/esm/digi-notification-alert.entry.js +2 -2
- package/dist/esm/digi-notification-error-page.entry.js +2 -2
- package/dist/esm/digi-tools-feedback.entry.js +2 -2
- package/dist/esm/digi-typography-heading-jumbo.entry.js +34 -0
- package/dist/esm/digi-typography-preamble.entry.js +16 -0
- package/dist/esm/index-148a7577.js +10 -14
- package/dist/esm/index.js +2 -2
- package/dist/esm/loader.js +1 -1
- package/dist/esm/typography-heading-jumbo-variation.enum-eb737f1b.js +17 -0
- package/dist/esm/{typography-variation.enum-8ba40d15.js → typography-variation.enum-531cdf64.js} +7 -17
- package/dist/types/components/_chart/bar-chart/bar-chart.d.ts +9 -0
- package/dist/types/components/_info-card/info-card/info-card.d.ts +4 -4
- package/dist/types/components/_link/link-button/link-button.d.ts +5 -0
- package/dist/types/components.d.ts +18 -8
- package/hydrate/index.js +132 -115
- package/hydrate/index.mjs +132 -115
- package/package.json +1 -1
- package/components/p-2bc16106.js +0 -129
- package/dist/cjs/bar-chart-variation.enum-a4e866b6.js +0 -7
- package/dist/cjs/digi-bar-chart.cjs.entry.js +0 -1510
- package/dist/cjs/digi-icon-caret-down_2.cjs.entry.js +0 -53
- package/dist/cjs/digi-icon-chart_2.cjs.entry.js +0 -53
- package/dist/digi-arbetsformedlingen/p-0c271457.entry.js +0 -1
- package/dist/digi-arbetsformedlingen/p-2422b0d1.entry.js +0 -1
- package/dist/digi-arbetsformedlingen/p-54a797ed.entry.js +0 -1
- package/dist/digi-arbetsformedlingen/p-a5c6e42e.entry.js +0 -1
- package/dist/digi-arbetsformedlingen/p-b22f09f1.entry.js +0 -1
- package/dist/digi-arbetsformedlingen/p-bd6e0b22.entry.js +0 -1
- package/dist/digi-arbetsformedlingen/p-c1606b8a.entry.js +0 -1
- package/dist/digi-arbetsformedlingen/p-d2d0856f.js +0 -1
- package/dist/digi-arbetsformedlingen/p-d8b9b535.entry.js +0 -1
- package/dist/digi-arbetsformedlingen/p-dcdffb3c.js +0 -1
- package/dist/esm/bar-chart-variation.enum-97c0b47f.js +0 -7
- package/dist/esm/digi-bar-chart.entry.js +0 -1506
- package/dist/esm/digi-icon-caret-down_2.entry.js +0 -48
- package/dist/esm/digi-icon-chart_2.entry.js +0 -48
|
@@ -1,1506 +0,0 @@
|
|
|
1
|
-
import { r as registerInstance, h, H as Host, g as getElement } from './index-148a7577.js';
|
|
2
|
-
import { o as ordinal, i as initRange, r as range, s as select, a as axisLeft, l as linear, b as axisBottom, p as polyInOut, c as interpolate, m as max, d as min, e as linear$1 } from './linear-0246aaea.js';
|
|
3
|
-
import { _ as _t } from './text-26e02c8d.js';
|
|
4
|
-
import { r as randomIdGenerator } from './randomIdGenerator.util-56406f2e.js';
|
|
5
|
-
import { B as BarChartVariation } from './bar-chart-variation.enum-97c0b47f.js';
|
|
6
|
-
|
|
7
|
-
function band() {
|
|
8
|
-
var scale = ordinal().unknown(undefined),
|
|
9
|
-
domain = scale.domain,
|
|
10
|
-
ordinalRange = scale.range,
|
|
11
|
-
r0 = 0,
|
|
12
|
-
r1 = 1,
|
|
13
|
-
step,
|
|
14
|
-
bandwidth,
|
|
15
|
-
round = false,
|
|
16
|
-
paddingInner = 0,
|
|
17
|
-
paddingOuter = 0,
|
|
18
|
-
align = 0.5;
|
|
19
|
-
|
|
20
|
-
delete scale.unknown;
|
|
21
|
-
|
|
22
|
-
function rescale() {
|
|
23
|
-
var n = domain().length,
|
|
24
|
-
reverse = r1 < r0,
|
|
25
|
-
start = reverse ? r1 : r0,
|
|
26
|
-
stop = reverse ? r0 : r1;
|
|
27
|
-
step = (stop - start) / Math.max(1, n - paddingInner + paddingOuter * 2);
|
|
28
|
-
if (round) step = Math.floor(step);
|
|
29
|
-
start += (stop - start - step * (n - paddingInner)) * align;
|
|
30
|
-
bandwidth = step * (1 - paddingInner);
|
|
31
|
-
if (round) start = Math.round(start), bandwidth = Math.round(bandwidth);
|
|
32
|
-
var values = range(n).map(function(i) { return start + step * i; });
|
|
33
|
-
return ordinalRange(reverse ? values.reverse() : values);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
scale.domain = function(_) {
|
|
37
|
-
return arguments.length ? (domain(_), rescale()) : domain();
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
scale.range = function(_) {
|
|
41
|
-
return arguments.length ? ([r0, r1] = _, r0 = +r0, r1 = +r1, rescale()) : [r0, r1];
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
scale.rangeRound = function(_) {
|
|
45
|
-
return [r0, r1] = _, r0 = +r0, r1 = +r1, round = true, rescale();
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
scale.bandwidth = function() {
|
|
49
|
-
return bandwidth;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
scale.step = function() {
|
|
53
|
-
return step;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
scale.round = function(_) {
|
|
57
|
-
return arguments.length ? (round = !!_, rescale()) : round;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
scale.padding = function(_) {
|
|
61
|
-
return arguments.length ? (paddingInner = Math.min(1, paddingOuter = +_), rescale()) : paddingInner;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
scale.paddingInner = function(_) {
|
|
65
|
-
return arguments.length ? (paddingInner = Math.min(1, _), rescale()) : paddingInner;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
scale.paddingOuter = function(_) {
|
|
69
|
-
return arguments.length ? (paddingOuter = +_, rescale()) : paddingOuter;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
scale.align = function(_) {
|
|
73
|
-
return arguments.length ? (align = Math.max(0, Math.min(1, _)), rescale()) : align;
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
scale.copy = function() {
|
|
77
|
-
return band(domain(), [r0, r1])
|
|
78
|
-
.round(round)
|
|
79
|
-
.paddingInner(paddingInner)
|
|
80
|
-
.paddingOuter(paddingOuter)
|
|
81
|
-
.align(align);
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
return initRange.apply(rescale(), arguments);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const barChartCss = ".sc-digi-bar-chart-h .digi-bar-chart.sc-digi-bar-chart{font-family:var(--digi--global--typography--font-family--default)}.sc-digi-bar-chart-h .chartTitle.sc-digi-bar-chart{--digi--typography--h2--margin:0.5rem;--digi--typography--h3--margin:0.5rem;--digi--typography--h4--margin:0.5rem;--digi--typography--h5--margin:0.5rem;--digi--typography--h6--margin:0.5rem;display:flex;justify-content:flex-start;flex-direction:column;align-items:left;text-align:left;padding-bottom:1rem;margin-right:0.5rem;flex-grow:2}.sc-digi-bar-chart-h .buttonWrapper.sc-digi-bar-chart{--digi--button--padding--medium:4px 4px 0.8125rem 0}.sc-digi-bar-chart-h .chartTooltip.sc-digi-bar-chart{box-sizing:border-box;position:absolute;background-color:rgba(250, 250, 250, 0.98);color:black;padding:5px 10px;padding-right:5px;border-radius:4px;display:flex;flex-direction:row;align-items:flex-start;box-shadow:rgba(60, 64, 67, 0.4) 0px 1px 2px 0px, rgba(60, 64, 67, 0.2) 0px 2px 6px 2px;font-size:0.875rem;display:none}.sc-digi-bar-chart-h .close.sc-digi-bar-chart{--digi--icon--color:black;cursor:pointer;margin-top:-5px}.sc-digi-bar-chart-h .legend.sc-digi-bar-chart::-webkit-scrollbar,.sc-digi-bar-chart-h .table.sc-digi-bar-chart::-webkit-scrollbar{height:10px;width:10px}.sc-digi-bar-chart-h .legend.sc-digi-bar-chart::-webkit-scrollbar-track,.sc-digi-bar-chart-h .table.sc-digi-bar-chart::-webkit-scrollbar-track{background:whitesmoke;border-radius:4px}.sc-digi-bar-chart-h .legend.sc-digi-bar-chart::-webkit-scrollbar-thumb,.sc-digi-bar-chart-h .table.sc-digi-bar-chart::-webkit-scrollbar-thumb{background-color:lightgray;border-radius:4px;border:0}.sc-digi-bar-chart-h .scChartStatus.sc-digi-bar-chart{border:0;clip:rect(1px, 1px, 1px, 1px);clip-path:inset(50%);height:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;width:1px;white-space:nowrap}.sc-digi-bar-chart-h .table.sc-digi-bar-chart{display:none;overflow-y:scroll;height:fit-content;border-radius:4px;padding:0.25rem;background:linear-gradient(white 30%, rgba(255, 255, 255, 0)) center top, linear-gradient(rgba(255, 255, 255, 0), white 70%) center bottom, radial-gradient(farthest-side at 50% 0, rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0)) center top, radial-gradient(farthest-side at 50% 100%, rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0)) center bottom;background-repeat:no-repeat;background-size:100% 40px, 100% 40px, 100% 14px, 100% 14px;background-attachment:local, local, scroll, scroll}.sc-digi-bar-chart-h .topWrapper.sc-digi-bar-chart{display:flex;flex-direction:row;align-items:flex-end;justify-content:space-between;flex-wrap:wrap}";
|
|
88
|
-
const DigiBarChartStyle0 = barChartCss;
|
|
89
|
-
|
|
90
|
-
const barChart = class {
|
|
91
|
-
constructor(hostRef) {
|
|
92
|
-
registerInstance(this, hostRef);
|
|
93
|
-
// States
|
|
94
|
-
this._loading = false;
|
|
95
|
-
this._placeholderTicks = ['0', '1', '2', '3', '4', '5', '6', '7'];
|
|
96
|
-
this._dims = {};
|
|
97
|
-
this._margin = {
|
|
98
|
-
bottom: 0,
|
|
99
|
-
top: 6,
|
|
100
|
-
left: 5,
|
|
101
|
-
right: 15,
|
|
102
|
-
ellipsis: false
|
|
103
|
-
};
|
|
104
|
-
this.tickPadding = 8;
|
|
105
|
-
this.yTickSize = 0;
|
|
106
|
-
this.xTickSize = 5;
|
|
107
|
-
// Width of the largets X-tick-value
|
|
108
|
-
this._tickWidth = 1;
|
|
109
|
-
// Transition
|
|
110
|
-
this.defaultDuration = 400;
|
|
111
|
-
// Text and formats
|
|
112
|
-
this.fontSize = '0.875rem';
|
|
113
|
-
// Observer for watching size changes when in line chart mode
|
|
114
|
-
this.barChartObserver = new ResizeObserver((entries) => {
|
|
115
|
-
entries.forEach(() => {
|
|
116
|
-
if (this._loading)
|
|
117
|
-
return this.loadingResize();
|
|
118
|
-
this.resize();
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
// Observer for watching size changes when in table mode
|
|
122
|
-
this.tableObserver = new ResizeObserver((entries) => {
|
|
123
|
-
entries.forEach(() => {
|
|
124
|
-
select(this._legendDiv).style('width', this._dims.width + 'px');
|
|
125
|
-
this.resizeTable();
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
// Resizing chart while loading
|
|
129
|
-
this.loadingResize = () => {
|
|
130
|
-
const newHeight = this.setDims();
|
|
131
|
-
this.setMargins(true);
|
|
132
|
-
this._svg.attr('width', this._dims.width).attr('height', this._dims.height);
|
|
133
|
-
this._barChartContainer.attr('transform', `translate(${this._margin.left + this.tickPadding + this.yTickSize},0)`);
|
|
134
|
-
this._margin.right =
|
|
135
|
-
this.getTextSize(this._xScale.domain()[1].toLocaleString()) / 2 +
|
|
136
|
-
this.yTickSize +
|
|
137
|
-
this.tickPadding;
|
|
138
|
-
// If there is a new height
|
|
139
|
-
if (newHeight) {
|
|
140
|
-
// Update y-axis with potentially new height (might want to do a check here)
|
|
141
|
-
this.afVariation === BarChartVariation.Horizontal
|
|
142
|
-
? this._yScale.range([
|
|
143
|
-
this._margin.top,
|
|
144
|
-
this._dims.height - this._margin.bottom
|
|
145
|
-
])
|
|
146
|
-
: this._yScale.range([
|
|
147
|
-
this._dims.height - this._margin.bottom,
|
|
148
|
-
this._margin.top
|
|
149
|
-
]);
|
|
150
|
-
this._xAxisHandle.attr('transform', `translate(0,${this._dims.height - this._margin.bottom})`);
|
|
151
|
-
}
|
|
152
|
-
// Update x-axis with new width
|
|
153
|
-
this._xScale.range([
|
|
154
|
-
0,
|
|
155
|
-
this._dims.width - this._margin.right - this._margin.left
|
|
156
|
-
]);
|
|
157
|
-
this._barSelection
|
|
158
|
-
.attr('x', (d) => this.afVariation === BarChartVariation.Horizontal
|
|
159
|
-
? 2
|
|
160
|
-
: this._xScale(d.key))
|
|
161
|
-
.attr('width', (d) => this.afVariation === BarChartVariation.Horizontal
|
|
162
|
-
? this._xScale(d.value)
|
|
163
|
-
: this._xScale.bandwidth());
|
|
164
|
-
this.setValueTicks();
|
|
165
|
-
};
|
|
166
|
-
// Adding click listener for tool tip text
|
|
167
|
-
this.setTickInteraction = () => {
|
|
168
|
-
if (this.afVariation === BarChartVariation.Horizontal) {
|
|
169
|
-
this._yAxisHandle
|
|
170
|
-
.selectAll('text')
|
|
171
|
-
.style('cursor', 'pointer')
|
|
172
|
-
.on('click', this.openTooltip)
|
|
173
|
-
.on('mouseenter', this.hover)
|
|
174
|
-
.on('mouseleave', this.hoverOut);
|
|
175
|
-
}
|
|
176
|
-
else {
|
|
177
|
-
this._xAxisHandle
|
|
178
|
-
.selectAll('text')
|
|
179
|
-
.style('cursor', 'pointer')
|
|
180
|
-
.on('click', this.openTooltip)
|
|
181
|
-
.on('mouseenter', this.hover)
|
|
182
|
-
.on('mouseleave', this.hoverOut);
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
// Setting Y-scale
|
|
186
|
-
this.setYScale = (empty) => {
|
|
187
|
-
var _a, _b, _c;
|
|
188
|
-
if (this.afVariation == BarChartVariation.Horizontal) {
|
|
189
|
-
this._yScale = band(empty
|
|
190
|
-
? ['0', '1', '2', '3', '4', '5', '6', '7']
|
|
191
|
-
: this._chartData.data.xValueNames, [this._margin.top, this._dims.height - this._margin.bottom])
|
|
192
|
-
.paddingOuter(0.1)
|
|
193
|
-
.paddingInner(0.1);
|
|
194
|
-
this._yAxis = axisLeft(this._yScale);
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
197
|
-
this._yScale = linear()
|
|
198
|
-
.domain(empty ? [0, 10] : [this._minVal, this._maxVal])
|
|
199
|
-
.nice(((_b = (_a = this._chartData) === null || _a === void 0 ? void 0 : _a.meta) === null || _b === void 0 ? void 0 : _b.numberOfReferenceLines)
|
|
200
|
-
? (_c = this._chartData) === null || _c === void 0 ? void 0 : _c.meta.numberOfReferenceLines
|
|
201
|
-
: 3);
|
|
202
|
-
this._yScale.range([
|
|
203
|
-
this._dims.height - this._margin.bottom,
|
|
204
|
-
this._margin.top
|
|
205
|
-
]);
|
|
206
|
-
this._yAxis = axisLeft(this._yScale);
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
|
-
// Setting X-Scale
|
|
210
|
-
this.setXScale = (empty) => {
|
|
211
|
-
// Horizontal
|
|
212
|
-
if (this.afVariation == BarChartVariation.Horizontal) {
|
|
213
|
-
this._xScale = linear()
|
|
214
|
-
.domain(empty ? [0, 10] : [this._minVal, this._maxVal])
|
|
215
|
-
.nice(3);
|
|
216
|
-
this._margin.right =
|
|
217
|
-
this.getTextSize(this._xScale.domain()[1].toLocaleString()) / 2 +
|
|
218
|
-
this.yTickSize +
|
|
219
|
-
this.tickPadding;
|
|
220
|
-
this._xScale.range([
|
|
221
|
-
0,
|
|
222
|
-
this._dims.width - this._margin.right - this._margin.left
|
|
223
|
-
]);
|
|
224
|
-
// Initializing actual axis
|
|
225
|
-
this._xAxis = axisBottom(this._xScale);
|
|
226
|
-
this._tickWidth = this.getLargestText(this._xScale.ticks().map((tick) => tick.toLocaleString()));
|
|
227
|
-
}
|
|
228
|
-
else {
|
|
229
|
-
// Vertical
|
|
230
|
-
this._xScale = band()
|
|
231
|
-
.domain(empty ? this._placeholderTicks : this._chartData.data.xValueNames)
|
|
232
|
-
.range([0, this._dims.width - this._margin.right - this._margin.left])
|
|
233
|
-
.paddingOuter(0.1)
|
|
234
|
-
.paddingInner(0.1);
|
|
235
|
-
this._xAxis = axisBottom(this._xScale);
|
|
236
|
-
}
|
|
237
|
-
};
|
|
238
|
-
// Stores all tick text sizes in an indexable array
|
|
239
|
-
this.tickSizes = () => {
|
|
240
|
-
// Initializing tick size array
|
|
241
|
-
this._namedTickSizes = [];
|
|
242
|
-
this._ellipsisSize = this.getTextSize('...');
|
|
243
|
-
if (this._chartData && this._chartData.data) {
|
|
244
|
-
for (let i = 0; i < this._chartData.data.xValueNames.length; i++) {
|
|
245
|
-
this._namedTickSizes.push(Math.ceil(this.getTextSize(this._chartData.data.xValueNames[i])));
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
|
-
this.updateBars = (fromLoading) => {
|
|
250
|
-
this._barChartContainer
|
|
251
|
-
.selectAll('.barGroup')
|
|
252
|
-
.data(this.reshapeData)
|
|
253
|
-
.join((enter) => {
|
|
254
|
-
var _a, _b;
|
|
255
|
-
const tempSelection = enter
|
|
256
|
-
.append('g')
|
|
257
|
-
.attr('class', 'barGroup')
|
|
258
|
-
.attr('id', (d) => 'barGroup' + d.key.replace(/[^A-Z0-9]+/gi, '_'));
|
|
259
|
-
tempSelection
|
|
260
|
-
.append('rect')
|
|
261
|
-
.attr('class', 'bar')
|
|
262
|
-
.style('cursor', 'pointer')
|
|
263
|
-
.attr('ry', 4)
|
|
264
|
-
.attr('rx', 4)
|
|
265
|
-
.attr('y', (d) => this.afVariation === BarChartVariation.Horizontal
|
|
266
|
-
? this._yScale(d.key)
|
|
267
|
-
: this._dims.height - this._margin.bottom)
|
|
268
|
-
.attr('x', (d) => this.afVariation === BarChartVariation.Horizontal
|
|
269
|
-
? 2
|
|
270
|
-
: this._xScale(d.key))
|
|
271
|
-
.attr('width', () => this.afVariation === BarChartVariation.Horizontal
|
|
272
|
-
? 0
|
|
273
|
-
: this._xScale.bandwidth())
|
|
274
|
-
.attr('height', () => this.afVariation === BarChartVariation.Horizontal
|
|
275
|
-
? this._yScale.bandwidth()
|
|
276
|
-
: 0)
|
|
277
|
-
.on('mouseenter', this.hover)
|
|
278
|
-
.on('mouseleave', this.hoverOut)
|
|
279
|
-
.on('click', this.openTooltip)
|
|
280
|
-
.transition()
|
|
281
|
-
.duration(this.defaultDuration)
|
|
282
|
-
.ease(polyInOut)
|
|
283
|
-
.attr('width', (d) => this.afVariation === BarChartVariation.Horizontal
|
|
284
|
-
? this._xScale(d.value)
|
|
285
|
-
: this._xScale.bandwidth())
|
|
286
|
-
.attr('y', (d) => this.afVariation === BarChartVariation.Horizontal
|
|
287
|
-
? this._yScale(d.key)
|
|
288
|
-
: this._yScale(d.value))
|
|
289
|
-
.attr('height', (d) => this.afVariation === BarChartVariation.Horizontal
|
|
290
|
-
? this._yScale.bandwidth()
|
|
291
|
-
: this._dims.height -
|
|
292
|
-
this._margin.bottom -
|
|
293
|
-
this._yScale(d.value))
|
|
294
|
-
.attr('fill', '#00005a');
|
|
295
|
-
if (!((_b = (_a = this._chartData) === null || _a === void 0 ? void 0 : _a.meta) === null || _b === void 0 ? void 0 : _b.valueLabels))
|
|
296
|
-
return tempSelection;
|
|
297
|
-
tempSelection
|
|
298
|
-
.append('text')
|
|
299
|
-
.text((d) => d.value.toLocaleString())
|
|
300
|
-
.attr('class', 'barText')
|
|
301
|
-
.attr('font-size', this.fontSize)
|
|
302
|
-
.attr('font-weight', '600')
|
|
303
|
-
.attr('text-anchor', 'end')
|
|
304
|
-
.style('pointer-events', 'none')
|
|
305
|
-
.attr('y', (d) => this.afVariation === BarChartVariation.Horizontal
|
|
306
|
-
? this._yScale(d.key) + this._yScale.bandwidth() / 2
|
|
307
|
-
: this._dims.height - this._margin.bottom)
|
|
308
|
-
.attr('x', (d) => this.afVariation === BarChartVariation.Horizontal
|
|
309
|
-
? 2
|
|
310
|
-
: this._xScale(d.key) + this._xScale.bandwidth() / 2)
|
|
311
|
-
.transition()
|
|
312
|
-
.duration(this.defaultDuration)
|
|
313
|
-
.ease(polyInOut)
|
|
314
|
-
.attr('font-size', this.fontSize)
|
|
315
|
-
.attr('font-weight', '600')
|
|
316
|
-
.attr('x', (d) => this.afVariation === BarChartVariation.Horizontal
|
|
317
|
-
? this._xScale(d.value)
|
|
318
|
-
: this._xScale(d.key) + this._xScale.bandwidth() / 2)
|
|
319
|
-
.attr('y', (d) => this.afVariation === BarChartVariation.Horizontal
|
|
320
|
-
? this._yScale(d.key) + this._yScale.bandwidth() / 2
|
|
321
|
-
: this._yScale(d.value))
|
|
322
|
-
.attr('text-anchor', (d) => {
|
|
323
|
-
if (this.afVariation === BarChartVariation.Vertical)
|
|
324
|
-
return 'middle';
|
|
325
|
-
return this._xScale(d.value) < d.len + this.tickPadding * 2
|
|
326
|
-
? 'start'
|
|
327
|
-
: 'end';
|
|
328
|
-
})
|
|
329
|
-
.attr('dx', (d) => {
|
|
330
|
-
if (this.afVariation === BarChartVariation.Horizontal)
|
|
331
|
-
return this._xScale(d.value) < d.len + this.tickPadding * 2
|
|
332
|
-
? this.tickPadding
|
|
333
|
-
: -this.tickPadding;
|
|
334
|
-
return 0;
|
|
335
|
-
})
|
|
336
|
-
.attr('fill', (d) => {
|
|
337
|
-
if (this.afVariation === BarChartVariation.Vertical)
|
|
338
|
-
return 'black';
|
|
339
|
-
return this._xScale(d.value) < d.len + this.tickPadding * 2
|
|
340
|
-
? 'black'
|
|
341
|
-
: 'white';
|
|
342
|
-
})
|
|
343
|
-
.attr('dy', () => this.afVariation == BarChartVariation.Horizontal
|
|
344
|
-
? '0.35em'
|
|
345
|
-
: '-0.25em')
|
|
346
|
-
.style('pointer-events', 'none')
|
|
347
|
-
.attrTween('text', (d, i, nodelist) => {
|
|
348
|
-
const oldnum = parseFloat(nodelist[i].textContent.replace(/\s/g, ''))
|
|
349
|
-
? parseFloat(nodelist[i].textContent.replace(/\s/g, ''))
|
|
350
|
-
: 0;
|
|
351
|
-
const interpolatedValue = interpolate(oldnum, d.value);
|
|
352
|
-
return (t) => (nodelist[i].textContent = parseInt(interpolatedValue(t)).toLocaleString(undefined, this._numberFormat));
|
|
353
|
-
});
|
|
354
|
-
return tempSelection;
|
|
355
|
-
}, (update) => {
|
|
356
|
-
// Update ids to bars
|
|
357
|
-
update.attr('id', (d) => 'barGroup' + d.key.replace(/[^A-Z0-9]+/gi, '_'));
|
|
358
|
-
// Mouse interaction to updated loading bars
|
|
359
|
-
if (fromLoading) {
|
|
360
|
-
update
|
|
361
|
-
.select('rect')
|
|
362
|
-
.on('mouseenter', this.hover)
|
|
363
|
-
.on('mouseleave', this.hoverOut)
|
|
364
|
-
.on('click', this.openTooltip)
|
|
365
|
-
.attr('x', (d) => this.afVariation === BarChartVariation.Horizontal
|
|
366
|
-
? 2
|
|
367
|
-
: this._xScale(d.key))
|
|
368
|
-
.attr('y', (d) => this.afVariation === BarChartVariation.Horizontal
|
|
369
|
-
? this._yScale(d.key)
|
|
370
|
-
: this._dims.height - this._margin.bottom)
|
|
371
|
-
.attr('width', (d) => this.afVariation === BarChartVariation.Horizontal
|
|
372
|
-
? this._xScale(d.value)
|
|
373
|
-
: this._xScale.bandwidth())
|
|
374
|
-
.attr('height', () => this.afVariation === BarChartVariation.Horizontal
|
|
375
|
-
? this._yScale.bandwidth()
|
|
376
|
-
: 0)
|
|
377
|
-
.attr('fill', '#00005a')
|
|
378
|
-
.transition()
|
|
379
|
-
.duration(this.defaultDuration)
|
|
380
|
-
.ease(polyInOut)
|
|
381
|
-
.attr('y', (d) => this.afVariation === BarChartVariation.Horizontal
|
|
382
|
-
? this._yScale(d.key)
|
|
383
|
-
: this._yScale(d.value))
|
|
384
|
-
.attr('height', (d) => this.afVariation === BarChartVariation.Horizontal
|
|
385
|
-
? this._yScale.bandwidth()
|
|
386
|
-
: this._dims.height -
|
|
387
|
-
this._margin.bottom -
|
|
388
|
-
this._yScale(d.value))
|
|
389
|
-
.on('end', () => this.barChartObserver.observe(this._chartDiv)); // Reset barchartObserver
|
|
390
|
-
}
|
|
391
|
-
else {
|
|
392
|
-
update
|
|
393
|
-
.select('rect')
|
|
394
|
-
.transition()
|
|
395
|
-
.duration(this.defaultDuration)
|
|
396
|
-
.ease(polyInOut)
|
|
397
|
-
.attr('y', (d) => this.afVariation === BarChartVariation.Horizontal
|
|
398
|
-
? this._yScale(d.key)
|
|
399
|
-
: this._yScale(d.value))
|
|
400
|
-
.attr('x', (d) => this.afVariation === BarChartVariation.Horizontal
|
|
401
|
-
? 2
|
|
402
|
-
: this._xScale(d.key))
|
|
403
|
-
.attr('width', (d) => this.afVariation === BarChartVariation.Horizontal
|
|
404
|
-
? this._xScale(d.value)
|
|
405
|
-
: this._xScale.bandwidth())
|
|
406
|
-
.attr('height', (d) => this.afVariation === BarChartVariation.Horizontal
|
|
407
|
-
? this._yScale.bandwidth()
|
|
408
|
-
: this._dims.height -
|
|
409
|
-
this._margin.bottom -
|
|
410
|
-
this._yScale(d.value))
|
|
411
|
-
.attr('fill', '#00005a');
|
|
412
|
-
}
|
|
413
|
-
return update
|
|
414
|
-
.select('text')
|
|
415
|
-
.style('display', () => { var _a, _b; return ((_b = (_a = this._chartData) === null || _a === void 0 ? void 0 : _a.meta) === null || _b === void 0 ? void 0 : _b.valueLabels) ? null : 'none'; })
|
|
416
|
-
.transition()
|
|
417
|
-
.duration(this.defaultDuration)
|
|
418
|
-
.ease(polyInOut)
|
|
419
|
-
.attr('font-size', this.fontSize)
|
|
420
|
-
.attr('font-weight', '600')
|
|
421
|
-
.attr('y', (d) => this.afVariation === BarChartVariation.Horizontal
|
|
422
|
-
? this._yScale(d.key) + this._yScale.bandwidth() / 2
|
|
423
|
-
: this._yScale(d.value))
|
|
424
|
-
.attr('x', (d) => this.afVariation === BarChartVariation.Horizontal
|
|
425
|
-
? this._xScale(d.value)
|
|
426
|
-
: this._xScale(d.key) + this._xScale.bandwidth() / 2)
|
|
427
|
-
.attr('text-anchor', (d) => {
|
|
428
|
-
if (this.afVariation === BarChartVariation.Vertical)
|
|
429
|
-
return 'middle';
|
|
430
|
-
return this._xScale(d.value) < d.len + this.tickPadding * 2
|
|
431
|
-
? 'start'
|
|
432
|
-
: 'end';
|
|
433
|
-
})
|
|
434
|
-
.attr('dx', (d) => {
|
|
435
|
-
if (this.afVariation === BarChartVariation.Horizontal)
|
|
436
|
-
return this._xScale(d.value) < d.len + this.tickPadding * 2
|
|
437
|
-
? this.tickPadding
|
|
438
|
-
: -this.tickPadding;
|
|
439
|
-
return 0;
|
|
440
|
-
})
|
|
441
|
-
.attr('fill', (d) => {
|
|
442
|
-
if (this.afVariation === BarChartVariation.Vertical)
|
|
443
|
-
return 'black';
|
|
444
|
-
return this._xScale(d.value) < d.len + this.tickPadding * 2
|
|
445
|
-
? 'black'
|
|
446
|
-
: 'white';
|
|
447
|
-
})
|
|
448
|
-
.attr('dy', () => this.afVariation == BarChartVariation.Horizontal
|
|
449
|
-
? '0.35em'
|
|
450
|
-
: '-0.25em')
|
|
451
|
-
.style('pointer-events', 'none')
|
|
452
|
-
.attrTween('text', (d, i, nodelist) => {
|
|
453
|
-
const oldnum = parseFloat(nodelist[i].textContent.replace(/\s/g, ''))
|
|
454
|
-
? parseFloat(nodelist[i].textContent.replace(/\s/g, ''))
|
|
455
|
-
: 0;
|
|
456
|
-
const interpolatedValue = interpolate(oldnum, d.value);
|
|
457
|
-
return (t) => (nodelist[i].textContent = parseInt(interpolatedValue(t)).toLocaleString(undefined, this._numberFormat));
|
|
458
|
-
});
|
|
459
|
-
}, (exit) => exit.remove());
|
|
460
|
-
this._barSelection = this._barChartContainer.selectAll('rect');
|
|
461
|
-
this._textSelection = this._barChartContainer.selectAll('.barText');
|
|
462
|
-
};
|
|
463
|
-
// Setting position of text according to bar size
|
|
464
|
-
this.adjustBarText = () => {
|
|
465
|
-
var _a, _b;
|
|
466
|
-
if (!((_b = (_a = this._chartData) === null || _a === void 0 ? void 0 : _a.meta) === null || _b === void 0 ? void 0 : _b.valueLabels))
|
|
467
|
-
return;
|
|
468
|
-
this._textSelection
|
|
469
|
-
.attr('y', (d) => this.afVariation === BarChartVariation.Horizontal
|
|
470
|
-
? this._yScale(d.key) + this._yScale.bandwidth() / 2
|
|
471
|
-
: this._yScale(d.value))
|
|
472
|
-
.attr('x', (d) => this.afVariation === BarChartVariation.Horizontal
|
|
473
|
-
? this._xScale(d.value)
|
|
474
|
-
: this._xScale(d.key) + this._xScale.bandwidth() / 2)
|
|
475
|
-
.attr('dx', (d) => {
|
|
476
|
-
if (this.afVariation === BarChartVariation.Horizontal)
|
|
477
|
-
return this._xScale(d.value) < d.len + this.tickPadding * 2
|
|
478
|
-
? this.tickPadding
|
|
479
|
-
: -this.tickPadding;
|
|
480
|
-
return 0;
|
|
481
|
-
})
|
|
482
|
-
.attr('fill', (d) => {
|
|
483
|
-
if (this.afVariation === BarChartVariation.Vertical)
|
|
484
|
-
return 'black';
|
|
485
|
-
return this._xScale(d.value) < d.len + this.tickPadding * 2
|
|
486
|
-
? 'black'
|
|
487
|
-
: 'white';
|
|
488
|
-
})
|
|
489
|
-
.attr('text-anchor', (d) => {
|
|
490
|
-
if (this.afVariation === BarChartVariation.Vertical)
|
|
491
|
-
return 'middle';
|
|
492
|
-
return this._xScale(d.value) < d.len + this.tickPadding * 2
|
|
493
|
-
? 'start'
|
|
494
|
-
: 'end';
|
|
495
|
-
});
|
|
496
|
-
};
|
|
497
|
-
this.reshapeData = () => {
|
|
498
|
-
const toReturn = [];
|
|
499
|
-
if (this._loading) {
|
|
500
|
-
this._placeholderTicks.forEach((key) => {
|
|
501
|
-
toReturn.push({
|
|
502
|
-
key: key,
|
|
503
|
-
value: Math.floor(Math.random() * (9 - 2 + 1) + 2),
|
|
504
|
-
len: '1'
|
|
505
|
-
});
|
|
506
|
-
});
|
|
507
|
-
return toReturn;
|
|
508
|
-
}
|
|
509
|
-
this._chartData.data.xValueNames.forEach((key, index) => {
|
|
510
|
-
toReturn.push({
|
|
511
|
-
key: key,
|
|
512
|
-
value: this._chartData.data.series[0].yValues[index],
|
|
513
|
-
len: this.getTextSize(this._chartData.data.series[0].yValues[index].toLocaleString())
|
|
514
|
-
});
|
|
515
|
-
});
|
|
516
|
-
return toReturn;
|
|
517
|
-
};
|
|
518
|
-
this.adjustBarSize = () => {
|
|
519
|
-
this._barSelection
|
|
520
|
-
.attr('y', (d) => this.afVariation === BarChartVariation.Horizontal
|
|
521
|
-
? this._yScale(d.key)
|
|
522
|
-
: this._yScale(d.value))
|
|
523
|
-
.attr('x', (d) => this.afVariation === BarChartVariation.Horizontal
|
|
524
|
-
? 2
|
|
525
|
-
: this._xScale(d.key))
|
|
526
|
-
.attr('width', (d) => this.afVariation === BarChartVariation.Horizontal
|
|
527
|
-
? this._xScale(d.value)
|
|
528
|
-
: this._xScale.bandwidth())
|
|
529
|
-
.attr('height', (d) => this.afVariation === BarChartVariation.Horizontal
|
|
530
|
-
? this._yScale.bandwidth()
|
|
531
|
-
: this._dims.height - this._margin.bottom - this._yScale(d.value));
|
|
532
|
-
};
|
|
533
|
-
// Resize table
|
|
534
|
-
this.resizeTable = () => {
|
|
535
|
-
this.setDims();
|
|
536
|
-
this.setTableDimensions();
|
|
537
|
-
};
|
|
538
|
-
// Setting dimension variable
|
|
539
|
-
this.setDims = (onlyHeight = false) => {
|
|
540
|
-
// Get title dimensions
|
|
541
|
-
const tempTitle = select(this._titleDiv).node().getBoundingClientRect(), tempLegend = select(this._legendDiv).node().getBoundingClientRect();
|
|
542
|
-
const prevHeight = this._dims.height;
|
|
543
|
-
if (!onlyHeight)
|
|
544
|
-
this._dims = select(this._chartDiv).node().getBoundingClientRect();
|
|
545
|
-
this._dims.height =
|
|
546
|
-
this._maxHeight - tempLegend.height - tempTitle.height - 1.75 * this._rem;
|
|
547
|
-
return prevHeight != this._dims.height;
|
|
548
|
-
};
|
|
549
|
-
// Setting margins given text size
|
|
550
|
-
this.setMargins = (fromLoading) => {
|
|
551
|
-
var _a;
|
|
552
|
-
this._pixelSize =
|
|
553
|
-
Number(window
|
|
554
|
-
.getComputedStyle(document.body)
|
|
555
|
-
.getPropertyValue('font-size')
|
|
556
|
-
.match(/\d+/)[0]) * Number(this.fontSize.replace(/[^\d.]|\.(?=.*\.)/g, ''));
|
|
557
|
-
// Getting the longest word, assuming it will also be the widest in terms of pixels
|
|
558
|
-
if (this.afVariation === BarChartVariation.Horizontal) {
|
|
559
|
-
const left = ((_a = this._chartData) === null || _a === void 0 ? void 0 : _a.data) &&
|
|
560
|
-
this.getLargestText(this._chartData.data.xValueNames)
|
|
561
|
-
? this.getLargestText(this._chartData.data.xValueNames)
|
|
562
|
-
: 0;
|
|
563
|
-
this._margin.left = left;
|
|
564
|
-
}
|
|
565
|
-
else
|
|
566
|
-
this._margin.left = this.getLargestText(fromLoading
|
|
567
|
-
? ['0', '10']
|
|
568
|
-
: [
|
|
569
|
-
this._minVal ? this._tempScale[0].toLocaleString() : '0',
|
|
570
|
-
this._maxVal ? this._tempScale[1].toLocaleString() : '10'
|
|
571
|
-
]);
|
|
572
|
-
if (this._margin.left > this._dims.width / 4) {
|
|
573
|
-
this._margin.left = Math.floor(this._dims.width / 4);
|
|
574
|
-
this._margin.ellipsis = true;
|
|
575
|
-
}
|
|
576
|
-
else
|
|
577
|
-
this._margin.ellipsis = false;
|
|
578
|
-
this._margin.bottom = this._pixelSize + this.tickPadding + this.xTickSize;
|
|
579
|
-
};
|
|
580
|
-
// Adjusting y-ticks
|
|
581
|
-
this.setNamedTicks = (transition = false) => {
|
|
582
|
-
if (this.afVariation == BarChartVariation.Horizontal) {
|
|
583
|
-
if (!transition) {
|
|
584
|
-
this._yAxisHandle
|
|
585
|
-
.style('font-size', this.fontSize)
|
|
586
|
-
.style('font-family', 'Open Sans')
|
|
587
|
-
.call(this._yAxis
|
|
588
|
-
.tickPadding(this.tickPadding)
|
|
589
|
-
.tickSize(this.yTickSize)
|
|
590
|
-
.tickSizeOuter(0)
|
|
591
|
-
.tickFormat((d, i) => {
|
|
592
|
-
if (!this._margin.ellipsis)
|
|
593
|
-
return d.toLocaleString();
|
|
594
|
-
// Adding ellipsis to text
|
|
595
|
-
const size = this._namedTickSizes[i] + this.tickPadding + this.yTickSize;
|
|
596
|
-
const mSize = this._margin.left;
|
|
597
|
-
if (size < mSize)
|
|
598
|
-
return d.toLocaleString();
|
|
599
|
-
const newSize = this.getTextSize(d.slice(0, Math.max(Math.floor((mSize / (size + this._ellipsisSize)) * d.length), 3)) + '...');
|
|
600
|
-
let adjustment = 0;
|
|
601
|
-
if (newSize > mSize) {
|
|
602
|
-
adjustment = Math.ceil((newSize - mSize) / (size / d.length));
|
|
603
|
-
}
|
|
604
|
-
// Slicing the text up, saving atleast 3 characters
|
|
605
|
-
return (d
|
|
606
|
-
.slice(0, Math.max(Math.floor((mSize / (size + this._ellipsisSize)) * d.length) - adjustment, 3))
|
|
607
|
-
.trim() + '...');
|
|
608
|
-
}));
|
|
609
|
-
}
|
|
610
|
-
else {
|
|
611
|
-
this._yAxisHandle
|
|
612
|
-
.style('font-size', this.fontSize)
|
|
613
|
-
.style('font-family', 'Open Sans')
|
|
614
|
-
.transition()
|
|
615
|
-
.duration(this.defaultDuration)
|
|
616
|
-
.call(this._yAxis
|
|
617
|
-
.tickPadding(this.tickPadding)
|
|
618
|
-
.tickSize(this.yTickSize)
|
|
619
|
-
.tickSizeOuter(0)
|
|
620
|
-
.tickFormat((d, i) => {
|
|
621
|
-
if (!this._margin.ellipsis)
|
|
622
|
-
return d;
|
|
623
|
-
// Adding ellipsis to text
|
|
624
|
-
const size = this._namedTickSizes[i] + this.tickPadding + this.yTickSize;
|
|
625
|
-
const mSize = this._margin.left;
|
|
626
|
-
if (size < mSize)
|
|
627
|
-
return d;
|
|
628
|
-
const newSize = this.getTextSize(d
|
|
629
|
-
.slice(0, Math.max(Math.floor((mSize / (size + this._ellipsisSize)) * d.length), 3))
|
|
630
|
-
.trim() + '...');
|
|
631
|
-
let adjustment = 0;
|
|
632
|
-
if (newSize > mSize) {
|
|
633
|
-
adjustment = Math.ceil((newSize - mSize) / (size / d.length));
|
|
634
|
-
}
|
|
635
|
-
// Slicing the text up, saving atleast 3 characters
|
|
636
|
-
return (d
|
|
637
|
-
.slice(0, Math.max(Math.floor((mSize / (size + this._ellipsisSize)) * d.length) - adjustment, 3))
|
|
638
|
-
.trim() + '...');
|
|
639
|
-
}));
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
else {
|
|
643
|
-
//Calculating every n:th text to show
|
|
644
|
-
let nTh = Math.round(this._chartData.data.xValues.length /
|
|
645
|
-
((this._dims.width - this._margin.left - this._margin.right) / 90 - 1));
|
|
646
|
-
if (Math.floor(this._chartData.data.xValues.length / nTh) < 4) {
|
|
647
|
-
nTh = Math.round(this._chartData.data.xValues.length / 4);
|
|
648
|
-
}
|
|
649
|
-
const allowedWidth = (this._dims.width - this._margin.left - this._margin.right) /
|
|
650
|
-
Math.floor(this._chartData.data.xValues.length / nTh + 1);
|
|
651
|
-
if (!transition) {
|
|
652
|
-
this._xAxisHandle
|
|
653
|
-
.style('font-size', this.fontSize)
|
|
654
|
-
.style('font-family', 'Open Sans')
|
|
655
|
-
.call(this._xAxis
|
|
656
|
-
.tickValues(this._xScale.domain().filter((...[, i]) => {
|
|
657
|
-
if (i == 0)
|
|
658
|
-
return true;
|
|
659
|
-
else {
|
|
660
|
-
return i % nTh == 0;
|
|
661
|
-
}
|
|
662
|
-
}))
|
|
663
|
-
.tickPadding(this.tickPadding)
|
|
664
|
-
.tickSize(this.xTickSize)
|
|
665
|
-
.tickSizeOuter(0)
|
|
666
|
-
.tickFormat((d, i) => {
|
|
667
|
-
const index = i * nTh;
|
|
668
|
-
if (this._namedTickSizes[index] < allowedWidth)
|
|
669
|
-
return d;
|
|
670
|
-
return (d.slice(0, Math.max(Math.floor((allowedWidth /
|
|
671
|
-
(this._namedTickSizes[index] +
|
|
672
|
-
this._ellipsisSize +
|
|
673
|
-
5)) *
|
|
674
|
-
d.length), 3)) + '...');
|
|
675
|
-
}));
|
|
676
|
-
}
|
|
677
|
-
else {
|
|
678
|
-
this._xAxisHandle
|
|
679
|
-
.style('font-size', this.fontSize)
|
|
680
|
-
.style('font-family', 'Open Sans')
|
|
681
|
-
.transition()
|
|
682
|
-
.duration(this.defaultDuration)
|
|
683
|
-
.call(this._xAxis
|
|
684
|
-
.tickValues(this._xScale.domain().filter((...[, i]) => {
|
|
685
|
-
if (i == 0)
|
|
686
|
-
return true;
|
|
687
|
-
else {
|
|
688
|
-
return i % nTh == 0;
|
|
689
|
-
}
|
|
690
|
-
}))
|
|
691
|
-
.tickPadding(this.tickPadding)
|
|
692
|
-
.tickSize(this.xTickSize)
|
|
693
|
-
.tickSizeOuter(0)
|
|
694
|
-
.tickFormat((d, i) => {
|
|
695
|
-
const index = i * nTh;
|
|
696
|
-
if (this._namedTickSizes[index] < allowedWidth)
|
|
697
|
-
return d;
|
|
698
|
-
return (d.slice(0, Math.max(Math.floor((allowedWidth /
|
|
699
|
-
(this._namedTickSizes[index] +
|
|
700
|
-
this._ellipsisSize +
|
|
701
|
-
5)) *
|
|
702
|
-
d.length), 3)) + '...');
|
|
703
|
-
}));
|
|
704
|
-
}
|
|
705
|
-
}
|
|
706
|
-
};
|
|
707
|
-
// Positioning the ticks of the value bearing axis
|
|
708
|
-
this.setValueTicks = (transition = false) => {
|
|
709
|
-
var _a, _b;
|
|
710
|
-
if (((_a = this._chartData) === null || _a === void 0 ? void 0 : _a.meta) && ((_b = this._chartData) === null || _b === void 0 ? void 0 : _b.meta.hideXAxis)) {
|
|
711
|
-
this.afVariation === BarChartVariation.Horizontal
|
|
712
|
-
? this._xAxisHandle.attr('display', 'none')
|
|
713
|
-
: this._yAxisHandle.attr('display', 'none');
|
|
714
|
-
return;
|
|
715
|
-
}
|
|
716
|
-
let toCall, tickSize, handle;
|
|
717
|
-
if (this.afVariation === BarChartVariation.Horizontal) {
|
|
718
|
-
this._xAxisHandle.attr('display', null);
|
|
719
|
-
toCall = this._xAxis;
|
|
720
|
-
tickSize = -(this._dims.height - this._margin.top - this._margin.bottom);
|
|
721
|
-
handle = this._xAxisHandle;
|
|
722
|
-
}
|
|
723
|
-
else {
|
|
724
|
-
this._yAxisHandle.attr('display', null);
|
|
725
|
-
toCall = this._yAxis;
|
|
726
|
-
tickSize = -(this._dims.width - this._margin.left - this._margin.right);
|
|
727
|
-
handle = this._yAxisHandle;
|
|
728
|
-
}
|
|
729
|
-
// Computing the amount of ticks to show
|
|
730
|
-
const ticks = Math.min(Math.floor((this._dims.width - this._margin.left - this._margin.right) /
|
|
731
|
-
(this._tickWidth + this.xTickSize)) - 2, this.afVariation == BarChartVariation.Horizontal
|
|
732
|
-
? this._xScale.ticks().length
|
|
733
|
-
: this._yScale.ticks().length);
|
|
734
|
-
if (!transition) {
|
|
735
|
-
handle
|
|
736
|
-
.style('font-size', this.fontSize)
|
|
737
|
-
.style('font-family', 'Open Sans')
|
|
738
|
-
.call(toCall
|
|
739
|
-
.ticks(this.afVariation === BarChartVariation.Horizontal
|
|
740
|
-
? Math.max(2, Math.min(ticks, 9))
|
|
741
|
-
: 5) // Clamping value between 2 and 10
|
|
742
|
-
.tickPadding(this.tickPadding)
|
|
743
|
-
.tickSize(tickSize)
|
|
744
|
-
.tickSizeOuter(0)
|
|
745
|
-
.tickFormat((d) => d.toLocaleString()));
|
|
746
|
-
}
|
|
747
|
-
else {
|
|
748
|
-
handle
|
|
749
|
-
.style('font-size', this.fontSize)
|
|
750
|
-
.style('font-family', 'Open Sans')
|
|
751
|
-
.transition('newScale')
|
|
752
|
-
.duration(this.defaultDuration)
|
|
753
|
-
.call(toCall
|
|
754
|
-
.ticks(this.afVariation === BarChartVariation.Horizontal
|
|
755
|
-
? Math.max(2, Math.min(ticks, 9))
|
|
756
|
-
: 5) // Clamping value between 2 and 10
|
|
757
|
-
.tickPadding(this.tickPadding)
|
|
758
|
-
.tickSize(tickSize)
|
|
759
|
-
.tickSizeOuter(0)
|
|
760
|
-
.tickFormat((d) => d.toLocaleString()));
|
|
761
|
-
}
|
|
762
|
-
handle.selectAll('line').attr('stroke', 'lightgray');
|
|
763
|
-
if (this.afVariation === BarChartVariation.Vertical)
|
|
764
|
-
this._yAxisHandle.select('.domain').attr('display', 'none');
|
|
765
|
-
};
|
|
766
|
-
// Highlight bar
|
|
767
|
-
this.hover = (event) => {
|
|
768
|
-
select(event.target)
|
|
769
|
-
.transition('hover')
|
|
770
|
-
.duration(20)
|
|
771
|
-
.attr('fill', event.target.tagName === 'rect'
|
|
772
|
-
? '#4C4C8B'
|
|
773
|
-
: 'var(--digi--color--text--link-hover)');
|
|
774
|
-
};
|
|
775
|
-
// Removing highlight from bar
|
|
776
|
-
this.hoverOut = (event) => {
|
|
777
|
-
select(event.target)
|
|
778
|
-
.transition('hover')
|
|
779
|
-
.duration(this.defaultDuration)
|
|
780
|
-
.attr('fill', event.target.tagName === 'rect' ? '#00005a' : '#333333');
|
|
781
|
-
};
|
|
782
|
-
this.openTooltip = (...[, d]) => {
|
|
783
|
-
// If type is string, the user has clicked on a y-axis tick
|
|
784
|
-
if (typeof d === 'string') {
|
|
785
|
-
this._tooltipData = this._barChartContainer
|
|
786
|
-
.select(`#barGroup${d.replace(/[^A-Z0-9]+/gi, '_')}`)
|
|
787
|
-
.datum();
|
|
788
|
-
}
|
|
789
|
-
else
|
|
790
|
-
this._tooltipData = d;
|
|
791
|
-
const tooltipBody = this._tooltip.select('.tooltipBody');
|
|
792
|
-
tooltipBody
|
|
793
|
-
.select(this._tooltipHeading)
|
|
794
|
-
.style('margin', '0 0.75rem 0 0 ')
|
|
795
|
-
.style('font-weight', 500)
|
|
796
|
-
.html(this._tooltipData.key);
|
|
797
|
-
tooltipBody
|
|
798
|
-
.selectAll('div')
|
|
799
|
-
.data([this._tooltipData])
|
|
800
|
-
.join('div')
|
|
801
|
-
.style('display', 'flex')
|
|
802
|
-
.style('flex-direction', 'row')
|
|
803
|
-
.style('flex-wrap', 'nowrap')
|
|
804
|
-
.style('white-space', 'nowrap')
|
|
805
|
-
.style('justify-content', 'space-between')
|
|
806
|
-
.html((d) => d.value.toLocaleString());
|
|
807
|
-
this._tooltip.style('display', 'flex');
|
|
808
|
-
this.positionTooltip(this._tooltipData);
|
|
809
|
-
};
|
|
810
|
-
this.closeTooltip = () => {
|
|
811
|
-
this._tooltip.style('display', 'none');
|
|
812
|
-
};
|
|
813
|
-
// Positions tooltip in horizontal mode
|
|
814
|
-
this.positionTooltip = (data) => {
|
|
815
|
-
const width = this._tooltip.node().getBoundingClientRect().width;
|
|
816
|
-
const height = this._tooltip.node().getBoundingClientRect().height + 8;
|
|
817
|
-
const diff = this._xScale(data.value) / 2 - width / 2;
|
|
818
|
-
if (this.afVariation === BarChartVariation.Horizontal) {
|
|
819
|
-
this._tooltip
|
|
820
|
-
.style('transform', `translate(${this._margin.left + this.tickPadding + Math.max(diff, -4)}px, ${this._yScale(data.key) + this._yScale.bandwidth() + this._yScale.paddingInner() * this._yScale.bandwidth()}px )`)
|
|
821
|
-
.style('max-width', this._xScale.range()[1] + 'px');
|
|
822
|
-
this._tooltip
|
|
823
|
-
.select('digi-icon-caret-up')
|
|
824
|
-
.style('position', 'absolute')
|
|
825
|
-
.style('--digi--icon--color', 'white')
|
|
826
|
-
.style('top', '-11px')
|
|
827
|
-
.style('left', '0')
|
|
828
|
-
.style('transform', `translate(${diff > 0 ? width / 2 - 10 : this._xScale(data.value) / 2}px,0)`);
|
|
829
|
-
}
|
|
830
|
-
else {
|
|
831
|
-
this._tooltip
|
|
832
|
-
.style('transform', `translate(${this._margin.left + this.tickPadding + this._xScale(data.key) + this._xScale.bandwidth() / 2 - width / 2}px, ${this._yScale(data.value) - height}px )`)
|
|
833
|
-
.style('max-width', this._xScale.range()[1] + 'px');
|
|
834
|
-
this._tooltip
|
|
835
|
-
.select('digi-icon-caret-down')
|
|
836
|
-
.style('position', 'absolute')
|
|
837
|
-
.style('--digi--icon--color', 'white')
|
|
838
|
-
.style('left', '0')
|
|
839
|
-
.style('bottom', '-11px')
|
|
840
|
-
.style('transform', `translate(${width / 2 - 6}px,0)`);
|
|
841
|
-
}
|
|
842
|
-
};
|
|
843
|
-
// Once texts has fully loaded, we can recompute some sizes
|
|
844
|
-
this.recomputeTextSize = () => {
|
|
845
|
-
var _a, _b;
|
|
846
|
-
if (this.afVariation == BarChartVariation.Horizontal)
|
|
847
|
-
this._tickWidth = this.getLargestText(this._xScale.ticks().map((tick) => tick.toLocaleString()));
|
|
848
|
-
this.tickSizes();
|
|
849
|
-
this._barChartContainer.selectAll('.barGroup').data(this.reshapeData);
|
|
850
|
-
if ((_b = (_a = this._chartData) === null || _a === void 0 ? void 0 : _a.meta) === null || _b === void 0 ? void 0 : _b.valueLabels)
|
|
851
|
-
this._textSelection.remove();
|
|
852
|
-
this.initBarText();
|
|
853
|
-
};
|
|
854
|
-
// Removes resize observer for chart and inits table
|
|
855
|
-
this.activateTable = (event) => {
|
|
856
|
-
this.closeTooltip();
|
|
857
|
-
this.barChartObserver.disconnect();
|
|
858
|
-
this.tableObserver.observe(this._chartDiv);
|
|
859
|
-
this._status.innerHTML = '<p>Visas som tabell</p>';
|
|
860
|
-
select(this._host).select('.tableButton').style('display', 'none');
|
|
861
|
-
select(this._host).select('.chartButton').style('display', null);
|
|
862
|
-
event.target.nextSibling.lastChild.focus();
|
|
863
|
-
const duration = 150;
|
|
864
|
-
this._svg
|
|
865
|
-
.attr('opacity', 1)
|
|
866
|
-
.transition('fadeout')
|
|
867
|
-
.duration(duration)
|
|
868
|
-
.attr('opacity', 0)
|
|
869
|
-
.on('end', () => {
|
|
870
|
-
this._svg.remove();
|
|
871
|
-
this._legendDiv.style['display'] = 'none';
|
|
872
|
-
this._tableDiv.style['display'] = 'block';
|
|
873
|
-
this.setTableContent();
|
|
874
|
-
this.setTableDimensions();
|
|
875
|
-
select(this._tableDiv)
|
|
876
|
-
.style('opacity', 0)
|
|
877
|
-
.transition('fadein')
|
|
878
|
-
.duration(duration)
|
|
879
|
-
.style('opacity', 1);
|
|
880
|
-
});
|
|
881
|
-
select(this._legendDiv)
|
|
882
|
-
.style('opacity', 1)
|
|
883
|
-
.transition('fadeout')
|
|
884
|
-
.duration(duration)
|
|
885
|
-
.style('opacity', 0);
|
|
886
|
-
};
|
|
887
|
-
// Removes observer and calls init functions for line chart
|
|
888
|
-
this.reInitChart = (event) => {
|
|
889
|
-
this.tableObserver.disconnect();
|
|
890
|
-
this._status.innerHTML = '<p>Visas som diagram</p>';
|
|
891
|
-
select(this._host).select('.tableButton').style('display', null);
|
|
892
|
-
select(this._host).select('.chartButton').style('display', 'none');
|
|
893
|
-
event.target.previousSibling.lastChild.focus();
|
|
894
|
-
const table = select(this._tableDiv);
|
|
895
|
-
table
|
|
896
|
-
.style('opacity', 1)
|
|
897
|
-
.transition()
|
|
898
|
-
.duration(150)
|
|
899
|
-
.style('opacity', 0)
|
|
900
|
-
.on('end', () => {
|
|
901
|
-
table.style('display', 'none');
|
|
902
|
-
this.initChain();
|
|
903
|
-
this._svg
|
|
904
|
-
.attr('opacity', 0)
|
|
905
|
-
.transition()
|
|
906
|
-
.duration(150)
|
|
907
|
-
.attr('opacity', 1);
|
|
908
|
-
});
|
|
909
|
-
};
|
|
910
|
-
this.afVariation = BarChartVariation.Vertical;
|
|
911
|
-
this.afHeadingLevel = 'h3';
|
|
912
|
-
this.afId = randomIdGenerator('tooltip');
|
|
913
|
-
this.afChartData = undefined;
|
|
914
|
-
}
|
|
915
|
-
afChartDataUpdate(data) {
|
|
916
|
-
if (typeof data != 'string')
|
|
917
|
-
this._chartData = data;
|
|
918
|
-
else
|
|
919
|
-
this._chartData = JSON.parse(data);
|
|
920
|
-
}
|
|
921
|
-
initSvg() {
|
|
922
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
923
|
-
// Fetch number formatting
|
|
924
|
-
this._numberFormat = {
|
|
925
|
-
maximumSignificantDigits: (_c = (_b = (_a = this._chartData) === null || _a === void 0 ? void 0 : _a.meta) === null || _b === void 0 ? void 0 : _b.labelProperties) === null || _c === void 0 ? void 0 : _c.significantDigits,
|
|
926
|
-
notation: ((_f = (_e = (_d = this._chartData) === null || _d === void 0 ? void 0 : _d.meta) === null || _e === void 0 ? void 0 : _e.labelProperties) === null || _f === void 0 ? void 0 : _f.shortHand)
|
|
927
|
-
? 'compact'
|
|
928
|
-
: 'standard'
|
|
929
|
-
};
|
|
930
|
-
select(this._chartDiv).select('svg').remove();
|
|
931
|
-
this._maxHeight = (_g = select(this._host)
|
|
932
|
-
.node()
|
|
933
|
-
.parentNode) === null || _g === void 0 ? void 0 : _g.getBoundingClientRect().height;
|
|
934
|
-
this.barChartObserver.observe(this._chartDiv);
|
|
935
|
-
// Getting rem-size
|
|
936
|
-
this._rem = parseFloat(getComputedStyle(document.documentElement).fontSize);
|
|
937
|
-
this.setMinMax();
|
|
938
|
-
this.setDims();
|
|
939
|
-
this.setMargins();
|
|
940
|
-
// Appending svg
|
|
941
|
-
this._svg = select(this._chartDiv)
|
|
942
|
-
.append('svg')
|
|
943
|
-
.attr('aria-hidden', true)
|
|
944
|
-
.attr('role', 'img')
|
|
945
|
-
.attr('aria-label', this._chartData && this._chartData.title
|
|
946
|
-
? 'Stapeldiagram om ' + this._chartData.title.toLowerCase()
|
|
947
|
-
: 'Stapeldiagram');
|
|
948
|
-
this._svg.attr('width', this._dims.width).attr('height', this._dims.height);
|
|
949
|
-
}
|
|
950
|
-
initToolTip() {
|
|
951
|
-
// Getting handle for tooltip
|
|
952
|
-
this._tooltip = select('#' + this.afId);
|
|
953
|
-
this._tooltip.select('.close').on('click', this.closeTooltip);
|
|
954
|
-
this._tooltipHeading =
|
|
955
|
-
'h' + (parseInt(this.afHeadingLevel.replace(/\D/g, '')) + 1); // increment heading level by one
|
|
956
|
-
// Add heading placeholder for heading
|
|
957
|
-
this._tooltip
|
|
958
|
-
.selectAll('.tooltipBody')
|
|
959
|
-
.append(this._tooltipHeading)
|
|
960
|
-
.attr('class', 'tooltipHeading') // Adding class to try to dodge global css classes
|
|
961
|
-
.style('font-size', '1rem')
|
|
962
|
-
.style('margin', '0 0.75rem')
|
|
963
|
-
.style('font-weight', '500');
|
|
964
|
-
}
|
|
965
|
-
initEmpty() {
|
|
966
|
-
select(this._chartDiv).select('svg').remove();
|
|
967
|
-
this._maxHeight = select(this._host)
|
|
968
|
-
.node()
|
|
969
|
-
.parentNode.getBoundingClientRect().height;
|
|
970
|
-
this.barChartObserver.observe(this._chartDiv);
|
|
971
|
-
// Getting rem-size
|
|
972
|
-
this._rem = parseFloat(getComputedStyle(document.documentElement).fontSize);
|
|
973
|
-
//this.setMinMax();
|
|
974
|
-
this.setDims();
|
|
975
|
-
this.setMargins();
|
|
976
|
-
// Appending svg
|
|
977
|
-
this._svg = select(this._chartDiv)
|
|
978
|
-
.append('svg')
|
|
979
|
-
.attr('aria-hidden', true)
|
|
980
|
-
.attr('role', 'img')
|
|
981
|
-
.attr('aria-label', this._chartData && this._chartData.title
|
|
982
|
-
? 'Stapeldiagram om ' + this._chartData.title.toLowerCase()
|
|
983
|
-
: 'Stapeldiagram');
|
|
984
|
-
this._svg.attr('width', this._dims.width).attr('height', this._dims.height);
|
|
985
|
-
// Hide unusable components
|
|
986
|
-
select(this._titleDiv)
|
|
987
|
-
.select(this.afHeadingLevel)
|
|
988
|
-
.html(`${_t.loading}...`);
|
|
989
|
-
this.initYAxis(true);
|
|
990
|
-
this.initXAxis(true);
|
|
991
|
-
this.loadingState(true);
|
|
992
|
-
}
|
|
993
|
-
loadingState(empty) {
|
|
994
|
-
this._loading = true;
|
|
995
|
-
// close potentially open tooltip
|
|
996
|
-
if (this._tooltip)
|
|
997
|
-
this.closeTooltip();
|
|
998
|
-
select(this._host).select('.tableButton').style('display', 'none');
|
|
999
|
-
const newHeight = this.setDims();
|
|
1000
|
-
this.transitionTitle();
|
|
1001
|
-
this._xAxisHandle.selectAll('.tick').remove();
|
|
1002
|
-
this._xAxisHandle.select('path').remove();
|
|
1003
|
-
this._svg
|
|
1004
|
-
.transition()
|
|
1005
|
-
.duration(400)
|
|
1006
|
-
.attr('width', this._dims.width)
|
|
1007
|
-
.attr('height', this._dims.height)
|
|
1008
|
-
.attr('aria-label', this._chartData && this._chartData.title
|
|
1009
|
-
? 'Stapeldiagram om ' + this._chartData.title.toLowerCase()
|
|
1010
|
-
: 'Stapeldiagram');
|
|
1011
|
-
this.setMargins(true);
|
|
1012
|
-
select(this._titleDiv)
|
|
1013
|
-
.select(this.afHeadingLevel)
|
|
1014
|
-
.html(`${_t.loading}...`);
|
|
1015
|
-
// Waiting with observing for changes until transition to regular bars is complete
|
|
1016
|
-
this._barChartContainer
|
|
1017
|
-
.transition('position')
|
|
1018
|
-
.duration(this.defaultDuration)
|
|
1019
|
-
.ease(polyInOut)
|
|
1020
|
-
.attr('transform', `translate(${this._margin.left + this.tickPadding + this.yTickSize},0)`);
|
|
1021
|
-
// If there is a new height
|
|
1022
|
-
if (newHeight) {
|
|
1023
|
-
// Update y-axis with potentially new height (might want to do a check here)
|
|
1024
|
-
this.afVariation === BarChartVariation.Horizontal
|
|
1025
|
-
? this._yScale.range([
|
|
1026
|
-
this._margin.top,
|
|
1027
|
-
this._dims.height - this._margin.bottom
|
|
1028
|
-
])
|
|
1029
|
-
: this._yScale.range([
|
|
1030
|
-
this._dims.height - this._margin.bottom,
|
|
1031
|
-
this._margin.top
|
|
1032
|
-
]);
|
|
1033
|
-
this._xAxisHandle.attr('transform', `translate(0,${this._dims.height - this._margin.bottom})`);
|
|
1034
|
-
}
|
|
1035
|
-
const animateBars = () => {
|
|
1036
|
-
this._barChartContainer.selectAll('.barGroup').remove();
|
|
1037
|
-
this._barSelection = this._barChartContainer
|
|
1038
|
-
.selectAll('barGroup')
|
|
1039
|
-
.data(this.reshapeData)
|
|
1040
|
-
.join('g')
|
|
1041
|
-
.attr('class', 'barGroup')
|
|
1042
|
-
.attr('id', (d) => 'barGroup' + d.key.replace(/[^A-Z0-9]+/gi, '_'))
|
|
1043
|
-
.append('rect')
|
|
1044
|
-
.attr('class', 'bar')
|
|
1045
|
-
.style('cursor', 'pointer');
|
|
1046
|
-
this._barSelection
|
|
1047
|
-
.attr('y', (d) => this.afVariation === BarChartVariation.Horizontal
|
|
1048
|
-
? this._yScale(d.key)
|
|
1049
|
-
: this._dims.height - this._margin.bottom)
|
|
1050
|
-
.attr('x', (d) => this.afVariation === BarChartVariation.Horizontal
|
|
1051
|
-
? 2
|
|
1052
|
-
: this._xScale(d.key))
|
|
1053
|
-
.attr('ry', 4)
|
|
1054
|
-
.attr('rx', 4)
|
|
1055
|
-
.attr('width', (d) => this.afVariation === BarChartVariation.Horizontal
|
|
1056
|
-
? this._xScale(d.value)
|
|
1057
|
-
: this._xScale.bandwidth())
|
|
1058
|
-
.attr('height', () => 0)
|
|
1059
|
-
//.attr('height', (d: any) => this.afVariation === BarChartVariation.Horizontal ? this._yScale.bandwidth() : (this._dims.height - this._margin.bottom) - this._yScale(d.value))
|
|
1060
|
-
.attr('fill', 'gray')
|
|
1061
|
-
.transition()
|
|
1062
|
-
.duration(400)
|
|
1063
|
-
.delay((...[, i]) => i * 150)
|
|
1064
|
-
.attr('y', (d) => this.afVariation === BarChartVariation.Horizontal
|
|
1065
|
-
? this._yScale(d.key)
|
|
1066
|
-
: this._yScale(d.value))
|
|
1067
|
-
.attr('height', (d) => this.afVariation === BarChartVariation.Horizontal
|
|
1068
|
-
? this._yScale.bandwidth()
|
|
1069
|
-
: this._dims.height - this._margin.bottom - this._yScale(d.value));
|
|
1070
|
-
this._barSelection
|
|
1071
|
-
.transition()
|
|
1072
|
-
.duration(400)
|
|
1073
|
-
.ease(linear$1)
|
|
1074
|
-
.delay((...[, i]) => i * 150 + 400)
|
|
1075
|
-
.attr('y', (d) => this.afVariation === BarChartVariation.Horizontal
|
|
1076
|
-
? this._yScale(d.key)
|
|
1077
|
-
: this._dims.height - this._margin.bottom)
|
|
1078
|
-
.attr('height', () => 0)
|
|
1079
|
-
.on('end', (...[, i]) => {
|
|
1080
|
-
if (i === this._placeholderTicks.length - 1)
|
|
1081
|
-
animateBars();
|
|
1082
|
-
});
|
|
1083
|
-
};
|
|
1084
|
-
const flattenBars = () => {
|
|
1085
|
-
this._barChartContainer
|
|
1086
|
-
.selectAll('rect')
|
|
1087
|
-
.transition()
|
|
1088
|
-
.duration(200)
|
|
1089
|
-
.ease(linear$1)
|
|
1090
|
-
.attr('y', (d) => this.afVariation === BarChartVariation.Horizontal
|
|
1091
|
-
? this._yScale(d.key)
|
|
1092
|
-
: this._dims.height - this._margin.bottom)
|
|
1093
|
-
.attr('height', () => 0)
|
|
1094
|
-
.on('end', (...[, i]) => {
|
|
1095
|
-
if (i != 0)
|
|
1096
|
-
return;
|
|
1097
|
-
this.setYScale(true);
|
|
1098
|
-
this.setValueTicks();
|
|
1099
|
-
this.setXScale(true);
|
|
1100
|
-
this.barChartObserver.observe(this._chartDiv);
|
|
1101
|
-
animateBars();
|
|
1102
|
-
});
|
|
1103
|
-
};
|
|
1104
|
-
if (empty)
|
|
1105
|
-
animateBars();
|
|
1106
|
-
else
|
|
1107
|
-
flattenBars();
|
|
1108
|
-
}
|
|
1109
|
-
transitionTitle() {
|
|
1110
|
-
const height = select(this._titleDiv).style('height');
|
|
1111
|
-
select(this._titleDiv)
|
|
1112
|
-
.style('height', this._prevHeight)
|
|
1113
|
-
.transition('adjust')
|
|
1114
|
-
.duration(400)
|
|
1115
|
-
.style('height', height)
|
|
1116
|
-
.on('end', () => select(this._titleDiv).style('height', null));
|
|
1117
|
-
}
|
|
1118
|
-
initYAxis(empty) {
|
|
1119
|
-
this.setYScale(empty);
|
|
1120
|
-
this._barChartContainer = this._svg
|
|
1121
|
-
.append('g')
|
|
1122
|
-
.attr('transform', `translate(${this._margin.left + this.tickPadding + this.yTickSize},0)`);
|
|
1123
|
-
this._yAxisHandle = this._barChartContainer.append('g');
|
|
1124
|
-
if (this.afVariation === BarChartVariation.Horizontal) {
|
|
1125
|
-
this.tickSizes();
|
|
1126
|
-
this.setNamedTicks();
|
|
1127
|
-
this.setTickInteraction();
|
|
1128
|
-
}
|
|
1129
|
-
else
|
|
1130
|
-
this.setValueTicks();
|
|
1131
|
-
}
|
|
1132
|
-
// Sets the largest and smallest value from series 0, Should only be used when not loading
|
|
1133
|
-
setMinMax() {
|
|
1134
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
1135
|
-
const max$1 = max((_a = this._chartData) === null || _a === void 0 ? void 0 : _a.data.series[0].yValues)
|
|
1136
|
-
? max((_b = this._chartData) === null || _b === void 0 ? void 0 : _b.data.series[0].yValues)
|
|
1137
|
-
: 0;
|
|
1138
|
-
const min$1 = min([0, min((_c = this._chartData) === null || _c === void 0 ? void 0 : _c.data.series[0].yValues)])
|
|
1139
|
-
? min([0, min((_d = this._chartData) === null || _d === void 0 ? void 0 : _d.data.series[0].yValues)])
|
|
1140
|
-
: 0;
|
|
1141
|
-
this._maxVal = max$1;
|
|
1142
|
-
this._minVal = min$1;
|
|
1143
|
-
this._tempScale = linear()
|
|
1144
|
-
.domain([this._minVal, this._maxVal])
|
|
1145
|
-
.nice(((_f = (_e = this._chartData) === null || _e === void 0 ? void 0 : _e.meta) === null || _f === void 0 ? void 0 : _f.numberOfReferenceLines)
|
|
1146
|
-
? (_g = this._chartData) === null || _g === void 0 ? void 0 : _g.meta.numberOfReferenceLines
|
|
1147
|
-
: 3)
|
|
1148
|
-
.domain();
|
|
1149
|
-
}
|
|
1150
|
-
// Setting up x-axis, getting margin.right in this function
|
|
1151
|
-
initXAxis(empty) {
|
|
1152
|
-
this.setXScale(empty);
|
|
1153
|
-
this._xAxisHandle = this._barChartContainer
|
|
1154
|
-
.append('g')
|
|
1155
|
-
.attr('transform', `translate(0,${this._dims.height - this._margin.bottom})`);
|
|
1156
|
-
if (this.afVariation === BarChartVariation.Horizontal) {
|
|
1157
|
-
this.setValueTicks();
|
|
1158
|
-
// Removing first tick, because it aligns with y-axis domain
|
|
1159
|
-
this._xAxisHandle.select('.tick').select('line').remove();
|
|
1160
|
-
}
|
|
1161
|
-
else {
|
|
1162
|
-
if (!empty) {
|
|
1163
|
-
this.tickSizes();
|
|
1164
|
-
this.setNamedTicks();
|
|
1165
|
-
this.setTickInteraction();
|
|
1166
|
-
}
|
|
1167
|
-
}
|
|
1168
|
-
}
|
|
1169
|
-
// Initializing bars, can only handle one series of bars for now
|
|
1170
|
-
initBars() {
|
|
1171
|
-
this._barSelection = this._barChartContainer
|
|
1172
|
-
.selectAll('barGroup')
|
|
1173
|
-
.data(this.reshapeData)
|
|
1174
|
-
.join('g')
|
|
1175
|
-
.attr('class', 'barGroup')
|
|
1176
|
-
.attr('id', (d) => 'barGroup' + d.key.replace(/[^A-Z0-9]+/gi, '_'))
|
|
1177
|
-
.append('rect')
|
|
1178
|
-
.attr('class', 'bar')
|
|
1179
|
-
.style('cursor', 'pointer');
|
|
1180
|
-
this._barSelection
|
|
1181
|
-
.attr('y', (d) => this.afVariation === BarChartVariation.Horizontal
|
|
1182
|
-
? this._yScale(d.key)
|
|
1183
|
-
: this._yScale(d.value))
|
|
1184
|
-
.attr('x', (d) => this.afVariation === BarChartVariation.Horizontal
|
|
1185
|
-
? 2
|
|
1186
|
-
: this._xScale(d.key))
|
|
1187
|
-
.attr('ry', 4)
|
|
1188
|
-
.attr('rx', 4)
|
|
1189
|
-
.attr('width', (d) => this.afVariation === BarChartVariation.Horizontal
|
|
1190
|
-
? this._xScale(d.value)
|
|
1191
|
-
: this._xScale.bandwidth())
|
|
1192
|
-
.attr('height', (d) => this.afVariation === BarChartVariation.Horizontal
|
|
1193
|
-
? this._yScale.bandwidth()
|
|
1194
|
-
: this._dims.height - this._margin.bottom - this._yScale(d.value))
|
|
1195
|
-
.attr('fill', '#00005a')
|
|
1196
|
-
.on('mouseenter', this.hover)
|
|
1197
|
-
.on('mouseleave', this.hoverOut)
|
|
1198
|
-
.on('click', this.openTooltip);
|
|
1199
|
-
}
|
|
1200
|
-
initBarText() {
|
|
1201
|
-
this._textSelection = this._barChartContainer
|
|
1202
|
-
.selectAll('.barGroup')
|
|
1203
|
-
.append('text');
|
|
1204
|
-
this._textSelection
|
|
1205
|
-
.text((d) => d.value.toLocaleString(undefined, this._numberFormat))
|
|
1206
|
-
.attr('class', 'barText')
|
|
1207
|
-
.attr('font-size', this.fontSize)
|
|
1208
|
-
.attr('font-weight', '600')
|
|
1209
|
-
.attr('text-anchor', 'end')
|
|
1210
|
-
.attr('y', (d) => this.afVariation === BarChartVariation.Horizontal
|
|
1211
|
-
? this._yScale(d.key) + this._yScale.bandwidth() / 2
|
|
1212
|
-
: this._yScale(d.value))
|
|
1213
|
-
.attr('x', (d) => this.afVariation === BarChartVariation.Horizontal
|
|
1214
|
-
? this._xScale(d)
|
|
1215
|
-
: this._xScale(d.key) + this._xScale.bandwidth())
|
|
1216
|
-
.attr('dy', () => this.afVariation == BarChartVariation.Horizontal ? '0.35em' : '-0.25em')
|
|
1217
|
-
.style('pointer-events', 'none')
|
|
1218
|
-
.style('display', () => { var _a, _b; return ((_b = (_a = this._chartData) === null || _a === void 0 ? void 0 : _a.meta) === null || _b === void 0 ? void 0 : _b.valueLabels) ? null : 'none'; });
|
|
1219
|
-
this.adjustBarText();
|
|
1220
|
-
}
|
|
1221
|
-
initChain() {
|
|
1222
|
-
this.initSvg();
|
|
1223
|
-
this.initToolTip();
|
|
1224
|
-
this.initYAxis();
|
|
1225
|
-
this.initXAxis();
|
|
1226
|
-
this.initBars();
|
|
1227
|
-
this.initBarText();
|
|
1228
|
-
}
|
|
1229
|
-
async updateChain() {
|
|
1230
|
-
var _a, _b, _c, _d, _e, _f;
|
|
1231
|
-
// Fetch number formatting
|
|
1232
|
-
this._numberFormat = {
|
|
1233
|
-
maximumSignificantDigits: (_c = (_b = (_a = this._chartData) === null || _a === void 0 ? void 0 : _a.meta) === null || _b === void 0 ? void 0 : _b.labelProperties) === null || _c === void 0 ? void 0 : _c.significantDigits,
|
|
1234
|
-
notation: ((_f = (_e = (_d = this._chartData) === null || _d === void 0 ? void 0 : _d.meta) === null || _e === void 0 ? void 0 : _e.labelProperties) === null || _f === void 0 ? void 0 : _f.shortHand)
|
|
1235
|
-
? 'compact'
|
|
1236
|
-
: 'standard'
|
|
1237
|
-
};
|
|
1238
|
-
if (this._tooltip)
|
|
1239
|
-
this.closeTooltip();
|
|
1240
|
-
// Check whether we are in table mode or not
|
|
1241
|
-
if (this._tableDiv.style['display'] == 'block') {
|
|
1242
|
-
if (!this._chartData.title) {
|
|
1243
|
-
select(this._titleDiv)
|
|
1244
|
-
.select(this.afHeadingLevel)
|
|
1245
|
-
.html(`${_t.loading}...`);
|
|
1246
|
-
}
|
|
1247
|
-
else {
|
|
1248
|
-
this.setTableContent();
|
|
1249
|
-
this.setTableDimensions();
|
|
1250
|
-
}
|
|
1251
|
-
this.transitionTitle();
|
|
1252
|
-
}
|
|
1253
|
-
else {
|
|
1254
|
-
// displaying legend again
|
|
1255
|
-
if (this._loading) {
|
|
1256
|
-
select(this._host).select('.tableButton').style('display', null);
|
|
1257
|
-
select(this._legendDiv).style('display', null);
|
|
1258
|
-
this.initToolTip();
|
|
1259
|
-
}
|
|
1260
|
-
// Disconnect resize observer while adjusting things
|
|
1261
|
-
this.barChartObserver.disconnect();
|
|
1262
|
-
this.setMinMax();
|
|
1263
|
-
const newHeight = this.setDims();
|
|
1264
|
-
this.transitionTitle();
|
|
1265
|
-
this._svg
|
|
1266
|
-
.transition()
|
|
1267
|
-
.duration(400)
|
|
1268
|
-
.attr('width', this._dims.width)
|
|
1269
|
-
.attr('height', this._dims.height)
|
|
1270
|
-
.attr('aria-label', this._chartData && this._chartData.title
|
|
1271
|
-
? 'Stapeldiagram om ' + this._chartData.title.toLowerCase()
|
|
1272
|
-
: 'Stapeldiagram');
|
|
1273
|
-
this.setMargins();
|
|
1274
|
-
// Waiting with observing for changes until transition to regular bars is complete
|
|
1275
|
-
this._barChartContainer
|
|
1276
|
-
.transition('position')
|
|
1277
|
-
.duration(this.defaultDuration)
|
|
1278
|
-
.ease(polyInOut)
|
|
1279
|
-
.attr('transform', `translate(${this._margin.left + this.tickPadding + this.yTickSize},0)`);
|
|
1280
|
-
if (!this._loading)
|
|
1281
|
-
this._barChartContainer.on('end', () => this.barChartObserver.observe(this._chartDiv));
|
|
1282
|
-
// If there is a new height
|
|
1283
|
-
if (newHeight) {
|
|
1284
|
-
// Update y-axis with potentially new height (might want to do a check here)
|
|
1285
|
-
this.afVariation === BarChartVariation.Horizontal
|
|
1286
|
-
? this._yScale.range([
|
|
1287
|
-
this._margin.top,
|
|
1288
|
-
this._dims.height - this._margin.bottom
|
|
1289
|
-
])
|
|
1290
|
-
: this._yScale.range([
|
|
1291
|
-
this._dims.height - this._margin.bottom,
|
|
1292
|
-
this._margin.top
|
|
1293
|
-
]);
|
|
1294
|
-
this._xAxisHandle.attr('transform', `translate(0,${this._dims.height - this._margin.bottom})`);
|
|
1295
|
-
}
|
|
1296
|
-
this.tickSizes();
|
|
1297
|
-
this.setYScale();
|
|
1298
|
-
this.setXScale();
|
|
1299
|
-
this.setTickInteraction();
|
|
1300
|
-
this._tickWidth = this.getLargestText(this.afVariation == BarChartVariation.Horizontal
|
|
1301
|
-
? this._xScale.ticks().map((tick) => tick.toLocaleString())
|
|
1302
|
-
: this._yScale.ticks().map((tick) => tick.toLocaleString()));
|
|
1303
|
-
this.setValueTicks(true);
|
|
1304
|
-
if (this._loading) {
|
|
1305
|
-
select(this._legendDiv)
|
|
1306
|
-
.style('opacity', 0)
|
|
1307
|
-
.transition()
|
|
1308
|
-
.duration(400)
|
|
1309
|
-
.ease(polyInOut)
|
|
1310
|
-
.style('opacity', 1);
|
|
1311
|
-
this._margin.right =
|
|
1312
|
-
this.getTextSize(this._xScale.domain()[1].toLocaleString()) / 2 +
|
|
1313
|
-
this.yTickSize +
|
|
1314
|
-
this.tickPadding;
|
|
1315
|
-
// Update x-axis with new width
|
|
1316
|
-
this._xScale.range([
|
|
1317
|
-
0,
|
|
1318
|
-
this._dims.width - this._margin.right - this._margin.left
|
|
1319
|
-
]);
|
|
1320
|
-
this.setNamedTicks(true);
|
|
1321
|
-
// Stop animation
|
|
1322
|
-
this._barSelection.selectAll('.barGroup').on('end', null);
|
|
1323
|
-
this._loading = false;
|
|
1324
|
-
this._barSelection
|
|
1325
|
-
.transition()
|
|
1326
|
-
.duration(this.defaultDuration)
|
|
1327
|
-
.attr('y', (d) => this.afVariation === BarChartVariation.Horizontal
|
|
1328
|
-
? this._yScale(d.key)
|
|
1329
|
-
: this._dims.height - this._margin.bottom)
|
|
1330
|
-
.attr('height', () => 0)
|
|
1331
|
-
.on('end', (...[, i]) => i === this._placeholderTicks.length - 1
|
|
1332
|
-
? this.updateBars(true)
|
|
1333
|
-
: null);
|
|
1334
|
-
this.setTickInteraction();
|
|
1335
|
-
}
|
|
1336
|
-
else {
|
|
1337
|
-
this.setNamedTicks(true);
|
|
1338
|
-
// Removing first tick, because it aligns with y-axis domain
|
|
1339
|
-
this.updateBars();
|
|
1340
|
-
}
|
|
1341
|
-
}
|
|
1342
|
-
}
|
|
1343
|
-
// Resizing bar chart
|
|
1344
|
-
resize() {
|
|
1345
|
-
var _a;
|
|
1346
|
-
const newHeight = this.setDims();
|
|
1347
|
-
this.setMargins();
|
|
1348
|
-
(_a = this._svg) === null || _a === void 0 ? void 0 : _a.attr('width', this._dims.width).attr('height', this._dims.height);
|
|
1349
|
-
this._barChartContainer.attr('transform', `translate(${this._margin.left + this.tickPadding + this.yTickSize},0)`);
|
|
1350
|
-
this._margin.right =
|
|
1351
|
-
this.getTextSize(this._xScale.domain()[1].toLocaleString()) / 2 +
|
|
1352
|
-
this.yTickSize +
|
|
1353
|
-
this.tickPadding;
|
|
1354
|
-
// If there is a new height
|
|
1355
|
-
if (newHeight) {
|
|
1356
|
-
// Update y-axis with potentially new height (might want to do a check here)
|
|
1357
|
-
this.afVariation === BarChartVariation.Horizontal
|
|
1358
|
-
? this._yScale.range([
|
|
1359
|
-
this._margin.top,
|
|
1360
|
-
this._dims.height - this._margin.bottom
|
|
1361
|
-
])
|
|
1362
|
-
: this._yScale.range([
|
|
1363
|
-
this._dims.height - this._margin.bottom,
|
|
1364
|
-
this._margin.top
|
|
1365
|
-
]);
|
|
1366
|
-
this._xAxisHandle.attr('transform', `translate(0,${this._dims.height - this._margin.bottom})`);
|
|
1367
|
-
}
|
|
1368
|
-
// Update x-axis with new width
|
|
1369
|
-
this._xScale.range([
|
|
1370
|
-
0,
|
|
1371
|
-
this._dims.width - this._margin.right - this._margin.left
|
|
1372
|
-
]);
|
|
1373
|
-
this.setNamedTicks();
|
|
1374
|
-
this.setValueTicks();
|
|
1375
|
-
this.adjustBarSize();
|
|
1376
|
-
this.adjustBarText();
|
|
1377
|
-
if (this._tooltipData)
|
|
1378
|
-
this.positionTooltip(this._tooltipData);
|
|
1379
|
-
}
|
|
1380
|
-
// Returns the longest text from an array of strings
|
|
1381
|
-
getLargestText(array) {
|
|
1382
|
-
let width = 0;
|
|
1383
|
-
array.forEach((elem) => {
|
|
1384
|
-
const temp = this.getTextSize(elem);
|
|
1385
|
-
if (temp > width) {
|
|
1386
|
-
width = temp;
|
|
1387
|
-
}
|
|
1388
|
-
});
|
|
1389
|
-
return width;
|
|
1390
|
-
}
|
|
1391
|
-
componentWillLoad() {
|
|
1392
|
-
this.afChartDataUpdate(this.afChartData);
|
|
1393
|
-
}
|
|
1394
|
-
componentDidLoad() {
|
|
1395
|
-
if (!this._chartData || Object.keys(this._chartData).length === 0) {
|
|
1396
|
-
this._loading = true;
|
|
1397
|
-
return this.initEmpty();
|
|
1398
|
-
}
|
|
1399
|
-
this.initChain();
|
|
1400
|
-
document.fonts.ready.then(() => {
|
|
1401
|
-
this.recomputeTextSize();
|
|
1402
|
-
this.setNamedTicks();
|
|
1403
|
-
this._barChartContainer.attr('transform', `translate(${this._margin.left + this.tickPadding + this.yTickSize},0)`);
|
|
1404
|
-
});
|
|
1405
|
-
}
|
|
1406
|
-
disconnectedCallback() {
|
|
1407
|
-
this.barChartObserver.disconnect();
|
|
1408
|
-
}
|
|
1409
|
-
componentWillUpdate() {
|
|
1410
|
-
this._prevHeight = select(this._titleDiv).style('height');
|
|
1411
|
-
}
|
|
1412
|
-
componentDidUpdate() {
|
|
1413
|
-
if (this._tableDiv.style['display'] != 'block' &&
|
|
1414
|
-
Object.keys(this._chartData).length === 0) {
|
|
1415
|
-
// Disconnect old barchartobserver while doing resizing
|
|
1416
|
-
this.barChartObserver.disconnect();
|
|
1417
|
-
return this.loadingState();
|
|
1418
|
-
}
|
|
1419
|
-
this.updateChain();
|
|
1420
|
-
}
|
|
1421
|
-
// Not currently used
|
|
1422
|
-
/*get cssModifiers() {
|
|
1423
|
-
return {
|
|
1424
|
-
'digi-bar-chart--vertical': this.afVariation == 'vertical',
|
|
1425
|
-
'digi-bar-chart--horizontal': this.afVariation == 'horizontal'
|
|
1426
|
-
};
|
|
1427
|
-
}*/
|
|
1428
|
-
// Returns pixelwidth of text given the current fontSize (costly function using .each)
|
|
1429
|
-
getTextSize(text) {
|
|
1430
|
-
const textWidth = [];
|
|
1431
|
-
const svg = select(this._chartDiv).append('svg');
|
|
1432
|
-
svg
|
|
1433
|
-
.selectAll('dummyText')
|
|
1434
|
-
.data([text])
|
|
1435
|
-
.join('text')
|
|
1436
|
-
.attr('font-size', this.fontSize) // <- using 1rem here whereas default is 0.875rem
|
|
1437
|
-
.text((d) => d)
|
|
1438
|
-
.each((...[, i, nodelist]) => {
|
|
1439
|
-
const thisWidth = nodelist[i].getComputedTextLength();
|
|
1440
|
-
textWidth.push(thisWidth);
|
|
1441
|
-
nodelist[i].remove();
|
|
1442
|
-
});
|
|
1443
|
-
svg.remove().exit();
|
|
1444
|
-
return textWidth[0];
|
|
1445
|
-
}
|
|
1446
|
-
// Setting table content from this._chartData
|
|
1447
|
-
setTableContent() {
|
|
1448
|
-
this._tableDiv.innerHTML = `<digi-table af-size="small" af-variation="primary"> <table><caption>${this._chartData.title}</caption><thead><tr>${this.headings()}</tr></thead><tbody>${this.tableBody()}</tbody></table></digi-table>`;
|
|
1449
|
-
}
|
|
1450
|
-
setTableDimensions() {
|
|
1451
|
-
const table = select(this._tableDiv);
|
|
1452
|
-
table
|
|
1453
|
-
// The last value is for compensating the padding set on the table element, changing padding in css, will need change in these two lines
|
|
1454
|
-
.style('height', this._dims.height + 'px');
|
|
1455
|
-
table.style('width', this._dims.width - this._rem * 0.65 + 'px');
|
|
1456
|
-
}
|
|
1457
|
-
// Extracting all headings from data and returning a string with <th>-elements with headings
|
|
1458
|
-
headings() {
|
|
1459
|
-
let headingsString = `<th scope="col">${this._chartData.x}</th>`;
|
|
1460
|
-
this._chartData.data.series.forEach((elem) => {
|
|
1461
|
-
headingsString = headingsString.concat(`<th scope="col">${elem.title}</th>`);
|
|
1462
|
-
});
|
|
1463
|
-
return headingsString;
|
|
1464
|
-
}
|
|
1465
|
-
// Building the table body
|
|
1466
|
-
tableBody() {
|
|
1467
|
-
let body = '';
|
|
1468
|
-
if (this._chartData && this._chartData.data) {
|
|
1469
|
-
const loopable = this._chartData.data.xValueNames
|
|
1470
|
-
? this._chartData.data.xValueNames
|
|
1471
|
-
: this._chartData.data.xValues;
|
|
1472
|
-
loopable.forEach((elem, index) => {
|
|
1473
|
-
let cells = '';
|
|
1474
|
-
this._chartData.data.series.forEach((serie) => {
|
|
1475
|
-
cells = cells.concat(`<td>${serie.yValues[index] != null ? serie.yValues[index].toLocaleString() : '-'}</td>`);
|
|
1476
|
-
});
|
|
1477
|
-
body = body.concat(`<tr><th scope='row'>${elem}${cells}</th></tr>`);
|
|
1478
|
-
});
|
|
1479
|
-
}
|
|
1480
|
-
return body;
|
|
1481
|
-
}
|
|
1482
|
-
render() {
|
|
1483
|
-
var _a, _b, _c, _d, _e;
|
|
1484
|
-
// Setting header
|
|
1485
|
-
let heading = '';
|
|
1486
|
-
if (this._chartData) {
|
|
1487
|
-
if (!this._chartData.subTitle)
|
|
1488
|
-
heading = `<${this.afHeadingLevel}>${this._chartData.title}</${this.afHeadingLevel}>`;
|
|
1489
|
-
else {
|
|
1490
|
-
if (!this._chartData.infoText)
|
|
1491
|
-
heading = `<${this.afHeadingLevel}>${this._chartData.title}</${this.afHeadingLevel}><p>${this._chartData.subTitle}</p>`;
|
|
1492
|
-
else
|
|
1493
|
-
heading = `<${this.afHeadingLevel}>${this._chartData.title}</${this.afHeadingLevel}><p>${(_a = this._chartData) === null || _a === void 0 ? void 0 : _a.subTitle}
|
|
1494
|
-
<span style="display:block;margin-top:0.25rem;font-size:0.875rem;color:var(--digi--global--color--neutral--grayscale--darkest-3)">${this._chartData.infoText}</span></p>`;
|
|
1495
|
-
}
|
|
1496
|
-
}
|
|
1497
|
-
return (h(Host, { key: '7659fcc4817cdfb3f19f2bd11a41464c13b5e19e', ref: (el) => (this._host = el) }, h("div", { key: '063611cf8dbb2554904d972ed3fc1f89d714772e', class: "topWrapper", ref: (el) => (this._titleDiv = el) }, h("digi-typography", { key: 'ad58c43c2629e7b2b97e3ad1658646e5171b1531', class: "chartTitle", innerHTML: heading }), h("digi-button", { key: '2234460c0ffab8e7d251f099f4f2d38e1e5ebede', class: "buttonWrapper tableButton", "af-size": "medium", "af-variation": "function", "af-full-width": "false", onAfOnClick: this.activateTable, afAriaLabel: `Visa tabell ${((_b = this._chartData) === null || _b === void 0 ? void 0 : _b.title) ? (_c = this._chartData) === null || _c === void 0 ? void 0 : _c.title.toLowerCase() : ''}` }, h("digi-icon-table", { key: 'b82a89d578d997ab878d44a2928e5e31773bd34f', slot: "icon" }), "Visa tabell"), h("digi-button", { key: 'b5dc532f7655bd383d0dcf42f8851edbc81b448c', style: { display: 'none' }, class: "buttonWrapper chartButton", "af-size": "medium", "af-variation": "function", "af-full-width": "false", onAfOnClick: this.reInitChart, afAriaLabel: `Visa diagram ${((_d = this._chartData) === null || _d === void 0 ? void 0 : _d.title) ? (_e = this._chartData) === null || _e === void 0 ? void 0 : _e.title.toLowerCase() : ''}` }, h("digi-icon-chart", { key: 'f868d9fd2c37c247e8abdd59cf2b9342ad120fef', slot: "icon" }), "Visa diagram"), h("div", { key: '6a0f7838d86a43b46d9a036ad935f50ebb2b523f', class: "scChartStatus", role: "status", ref: (el) => (this._status = el) })), h("div", { key: '5f37b9eaf1030cd1d5b1b0360cdaaa61f953b624', class: "chartTooltip", id: this.afId }, h("div", { key: 'a89608cb64620456a165ba4fb57db823870d2231', class: "tooltipBody" }), h("digi-icon-x", { key: 'e842c2b42f6bc7d6dfdad1d1b8a7acb9f8df5a1a', class: "close" }), this.afVariation === BarChartVariation.Horizontal ? (h("digi-icon-caret-up", null)) : (h("digi-icon-caret-down", null))), h("div", { key: 'f07154ab370a948016aa30a2547c4c9b25fae03b', ref: (el) => (this._chartDiv = el) }, " "), h("div", { key: '385151df18d373779257040d298bf8c108184500', class: "legend", ref: (el) => (this._legendDiv = el) }), h("div", { key: 'd5f07fc01a628aa2035a96d86621b6bab1e73f01', class: "table", ref: (el) => (this._tableDiv = el) }, ' ')));
|
|
1498
|
-
}
|
|
1499
|
-
get hostElement() { return getElement(this); }
|
|
1500
|
-
static get watchers() { return {
|
|
1501
|
-
"afChartData": ["afChartDataUpdate"]
|
|
1502
|
-
}; }
|
|
1503
|
-
};
|
|
1504
|
-
barChart.style = DigiBarChartStyle0;
|
|
1505
|
-
|
|
1506
|
-
export { barChart as digi_bar_chart };
|