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