@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
@@ -14,6 +14,12 @@ exports.CalendarDatepickerValidation = void 0;
14
14
  CalendarDatepickerValidation["NEUTRAL"] = "neutral";
15
15
  })(exports.CalendarDatepickerValidation || (exports.CalendarDatepickerValidation = {}));
16
16
 
17
+ exports.BarChartVariation = void 0;
18
+ (function (BarChartVariation) {
19
+ BarChartVariation["Vertical"] = "vertical";
20
+ BarChartVariation["Horizontal"] = "horizontal";
21
+ })(exports.BarChartVariation || (exports.BarChartVariation = {}));
22
+
17
23
  exports.CodeBlockLanguage = void 0;
18
24
  (function (CodeBlockLanguage) {
19
25
  CodeBlockLanguage["JSON"] = "json";
@@ -255,22 +261,6 @@ exports.FeedbackVariation = void 0;
255
261
  FeedbackVariation["SECONDARY"] = "secondary";
256
262
  })(exports.FeedbackVariation || (exports.FeedbackVariation = {}));
257
263
 
258
- exports.TypographyHeadingJumboLevel = void 0;
259
- (function (TypographyHeadingJumboLevel) {
260
- TypographyHeadingJumboLevel["H1"] = "h1";
261
- TypographyHeadingJumboLevel["H2"] = "h2";
262
- TypographyHeadingJumboLevel["H3"] = "h3";
263
- TypographyHeadingJumboLevel["H4"] = "h4";
264
- TypographyHeadingJumboLevel["H5"] = "h5";
265
- TypographyHeadingJumboLevel["H6"] = "h6";
266
- })(exports.TypographyHeadingJumboLevel || (exports.TypographyHeadingJumboLevel = {}));
267
-
268
- exports.TypographyHeadingJumboVariation = void 0;
269
- (function (TypographyHeadingJumboVariation) {
270
- TypographyHeadingJumboVariation["PRIMARY"] = "primary";
271
- TypographyHeadingJumboVariation["SECONDARY"] = "secondary";
272
- })(exports.TypographyHeadingJumboVariation || (exports.TypographyHeadingJumboVariation = {}));
273
-
274
264
  exports.TypographyVariation = void 0;
275
265
  (function (TypographyVariation) {
276
266
  TypographyVariation["SMALL"] = "small";
@@ -15,6 +15,9 @@ export class barChart {
15
15
  // States
16
16
  this._loading = false;
17
17
  this._placeholderTicks = ['0', '1', '2', '3', '4', '5', '6', '7'];
18
+ // Width of data at each tick, if we have two data series that have values att same tick, this will be 2 for example. defaults to 1;
19
+ this.dataWidth = 1;
20
+ this.barGap = 0;
18
21
  this._dims = {};
19
22
  this._margin = {
20
23
  bottom: 0,
@@ -32,6 +35,7 @@ export class barChart {
32
35
  this.defaultDuration = 400;
33
36
  // Text and formats
34
37
  this.fontSize = '0.875rem';
38
+ this.colorPalettes = ['--digi--color--background--brand-primary', '--digi--color--infographic--brand--primary', '--digi--color--background--sentiment--beta--primary', '--digi--color--text--interactive--visited', '--digi--color--icon--validation--error'];
35
39
  // Observer for watching size changes when in line chart mode
36
40
  this.barChartObserver = new ResizeObserver((entries) => {
37
41
  entries.forEach(() => {
@@ -77,12 +81,8 @@ export class barChart {
77
81
  this._dims.width - this._margin.right - this._margin.left
78
82
  ]);
79
83
  this._barSelection
80
- .attr('x', (d) => this.afVariation === BarChartVariation.Horizontal
81
- ? 2
82
- : this._xScale(d.key))
83
- .attr('width', (d) => this.afVariation === BarChartVariation.Horizontal
84
- ? this._xScale(d.value)
85
- : this._xScale.bandwidth());
84
+ .attr('x', this.xFunction)
85
+ .attr('width', this.widthFunction);
86
86
  this.setValueTicks();
87
87
  };
88
88
  // Adding click listener for tool tip text
@@ -175,7 +175,7 @@ export class barChart {
175
175
  this.updateBars = (fromLoading) => {
176
176
  this._barChartContainer
177
177
  .selectAll('.barGroup')
178
- .data(this.reshapeData)
178
+ .data(this.mappedData)
179
179
  .join((enter) => {
180
180
  var _a, _b;
181
181
  const tempSelection = enter
@@ -206,17 +206,9 @@ export class barChart {
206
206
  .transition()
207
207
  .duration(this.defaultDuration)
208
208
  .ease(d3.easePolyInOut)
209
- .attr('width', (d) => this.afVariation === BarChartVariation.Horizontal
210
- ? this._xScale(d.value)
211
- : this._xScale.bandwidth())
212
- .attr('y', (d) => this.afVariation === BarChartVariation.Horizontal
213
- ? this._yScale(d.key)
214
- : this._yScale(d.value))
215
- .attr('height', (d) => this.afVariation === BarChartVariation.Horizontal
216
- ? this._yScale.bandwidth()
217
- : this._dims.height -
218
- this._margin.bottom -
219
- this._yScale(d.value))
209
+ .attr('width', this.widthFunction)
210
+ .attr('y', this.yFunction)
211
+ .attr('height', this.heightFunction)
220
212
  .attr('fill', '#00005a');
221
213
  if (!((_b = (_a = this._chartData) === null || _a === void 0 ? void 0 : _a.meta) === null || _b === void 0 ? void 0 : _b.valueLabels))
222
214
  return tempSelection;
@@ -288,15 +280,11 @@ export class barChart {
288
280
  .on('mouseenter', this.hover)
289
281
  .on('mouseleave', this.hoverOut)
290
282
  .on('click', this.openTooltip)
291
- .attr('x', (d) => this.afVariation === BarChartVariation.Horizontal
292
- ? 2
293
- : this._xScale(d.key))
283
+ .attr('x', this.xFunction)
294
284
  .attr('y', (d) => this.afVariation === BarChartVariation.Horizontal
295
285
  ? this._yScale(d.key)
296
286
  : this._dims.height - this._margin.bottom)
297
- .attr('width', (d) => this.afVariation === BarChartVariation.Horizontal
298
- ? this._xScale(d.value)
299
- : this._xScale.bandwidth())
287
+ .attr('width', this.widthFunction)
300
288
  .attr('height', () => this.afVariation === BarChartVariation.Horizontal
301
289
  ? this._yScale.bandwidth()
302
290
  : 0)
@@ -304,14 +292,8 @@ export class barChart {
304
292
  .transition()
305
293
  .duration(this.defaultDuration)
306
294
  .ease(d3.easePolyInOut)
307
- .attr('y', (d) => this.afVariation === BarChartVariation.Horizontal
308
- ? this._yScale(d.key)
309
- : this._yScale(d.value))
310
- .attr('height', (d) => this.afVariation === BarChartVariation.Horizontal
311
- ? this._yScale.bandwidth()
312
- : this._dims.height -
313
- this._margin.bottom -
314
- this._yScale(d.value))
295
+ .attr('y', this.yFunction)
296
+ .attr('height', this.heightFunction)
315
297
  .on('end', () => this.barChartObserver.observe(this._chartDiv)); // Reset barchartObserver
316
298
  }
317
299
  else {
@@ -320,20 +302,10 @@ export class barChart {
320
302
  .transition()
321
303
  .duration(this.defaultDuration)
322
304
  .ease(d3.easePolyInOut)
323
- .attr('y', (d) => this.afVariation === BarChartVariation.Horizontal
324
- ? this._yScale(d.key)
325
- : this._yScale(d.value))
326
- .attr('x', (d) => this.afVariation === BarChartVariation.Horizontal
327
- ? 2
328
- : this._xScale(d.key))
329
- .attr('width', (d) => this.afVariation === BarChartVariation.Horizontal
330
- ? this._xScale(d.value)
331
- : this._xScale.bandwidth())
332
- .attr('height', (d) => this.afVariation === BarChartVariation.Horizontal
333
- ? this._yScale.bandwidth()
334
- : this._dims.height -
335
- this._margin.bottom -
336
- this._yScale(d.value))
305
+ .attr('x', this.xFunction)
306
+ .attr('y', this.yFunction)
307
+ .attr('width', this.widthFunction)
308
+ .attr('height', this.heightFunction)
337
309
  .attr('fill', '#00005a');
338
310
  }
339
311
  return update
@@ -424,37 +396,67 @@ export class barChart {
424
396
  const toReturn = [];
425
397
  if (this._loading) {
426
398
  this._placeholderTicks.forEach((key) => {
427
- toReturn.push({
399
+ const tick = { key: key, series: [] };
400
+ tick.series.push({
428
401
  key: key,
402
+ serie: '',
429
403
  value: Math.floor(Math.random() * (9 - 2 + 1) + 2),
430
- len: '1'
404
+ len: 0
431
405
  });
406
+ toReturn.push(tick);
432
407
  });
433
408
  return toReturn;
434
409
  }
435
410
  this._chartData.data.xValueNames.forEach((key, index) => {
436
- toReturn.push({
437
- key: key,
438
- value: this._chartData.data.series[0].yValues[index],
439
- len: this.getTextSize(this._chartData.data.series[0].yValues[index].toLocaleString())
411
+ const tick = { key: key, series: [] };
412
+ this._chartData.data.series.forEach((serie) => {
413
+ if (serie.yValues[index]) {
414
+ tick.series.push({
415
+ key: key,
416
+ serie: serie.title,
417
+ value: serie.yValues[index],
418
+ len: serie.yValues[index] ? this.getTextSize(serie.yValues[index].toLocaleString()) : 0
419
+ });
420
+ }
440
421
  });
422
+ toReturn.push(tick);
441
423
  });
442
424
  return toReturn;
443
425
  };
444
426
  this.adjustBarSize = () => {
445
- this._barSelection
446
- .attr('y', (d) => this.afVariation === BarChartVariation.Horizontal
447
- ? this._yScale(d.key)
448
- : this._yScale(d.value))
449
- .attr('x', (d) => this.afVariation === BarChartVariation.Horizontal
450
- ? 2
451
- : this._xScale(d.key))
452
- .attr('width', (d) => this.afVariation === BarChartVariation.Horizontal
453
- ? this._xScale(d.value)
454
- : this._xScale.bandwidth())
455
- .attr('height', (d) => this.afVariation === BarChartVariation.Horizontal
456
- ? this._yScale.bandwidth()
457
- : this._dims.height - this._margin.bottom - this._yScale(d.value));
427
+ this._barSelection.selectAll('.bar')
428
+ .attr('x', this.xFunction)
429
+ .attr('y', this.yFunction)
430
+ .attr('width', this.widthFunction)
431
+ .attr('height', this.heightFunction);
432
+ };
433
+ // Handling x positioning of bars
434
+ this.xFunction = (d, i) => {
435
+ return this.afVariation === BarChartVariation.Horizontal
436
+ ? (d.value > 0 ? this._xScale(0) : this._xScale(d.value))
437
+ : this._xScale(d.key) + ((this._xScale.bandwidth() / this.dataWidth) * i + (this.barGap * i));
438
+ };
439
+ // Handling y positioning of bars
440
+ this.yFunction = (d, i) => {
441
+ if (!d.value)
442
+ return 0;
443
+ return this.afVariation === BarChartVariation.Horizontal
444
+ ? this._yScale(d.key) + ((this._yScale.bandwidth() / this.dataWidth) * i + (this.barGap * i))
445
+ : (d.value < 0 ? this._yScale(0) : this._yScale(d.value));
446
+ };
447
+ // Handling height for bars
448
+ this.heightFunction = (d) => {
449
+ if (!d.value)
450
+ return 0;
451
+ return this.afVariation === BarChartVariation.Horizontal
452
+ ? this._yScale.bandwidth() / this.dataWidth - (this.barGap)
453
+ : (d.value < 0 ? this._yScale(d.value) - this._yScale(0) : this._yScale(0) - this._yScale(d.value));
454
+ };
455
+ // Handling width for bars
456
+ this.widthFunction = (d) => {
457
+ return this.afVariation === BarChartVariation.Horizontal
458
+ ? Math.abs(this._xScale(0) - this._xScale(d.value))
459
+ : this._xScale.bandwidth() / this.dataWidth - (this.barGap);
458
460
  };
459
461
  // Resize table
460
462
  this.resizeTable = () => {
@@ -694,16 +696,16 @@ export class barChart {
694
696
  d3.select(event.target)
695
697
  .transition('hover')
696
698
  .duration(20)
697
- .attr('fill', event.target.tagName === 'rect'
698
- ? '#4C4C8B'
699
- : 'var(--digi--color--text--link-hover)');
699
+ .attr('fill', (d) => event.target.tagName === 'rect'
700
+ ? `hsl(from ${this.colorFunction(d.serie)} h s calc(l + 10))`
701
+ : 'var(--digi--color--background--interactive--hover--tertiary)');
700
702
  };
701
703
  // Removing highlight from bar
702
704
  this.hoverOut = (event) => {
703
705
  d3.select(event.target)
704
706
  .transition('hover')
705
707
  .duration(this.defaultDuration)
706
- .attr('fill', event.target.tagName === 'rect' ? '#00005a' : '#333333');
708
+ .attr('fill', (d) => event.target.tagName === 'rect' ? this.colorFunction(d.serie) : '#333333');
707
709
  };
708
710
  this.openTooltip = (...[, d]) => {
709
711
  // If type is string, the user has clicked on a y-axis tick
@@ -772,7 +774,7 @@ export class barChart {
772
774
  if (this.afVariation == BarChartVariation.Horizontal)
773
775
  this._tickWidth = this.getLargestText(this._xScale.ticks().map((tick) => tick.toLocaleString()));
774
776
  this.tickSizes();
775
- this._barChartContainer.selectAll('.barGroup').data(this.reshapeData);
777
+ this._barChartContainer.selectAll('.barGroup').data(this.mappedData);
776
778
  if ((_b = (_a = this._chartData) === null || _a === void 0 ? void 0 : _a.meta) === null || _b === void 0 ? void 0 : _b.valueLabels)
777
779
  this._textSelection.remove();
778
780
  this.initBarText();
@@ -843,6 +845,14 @@ export class barChart {
843
845
  this._chartData = data;
844
846
  else
845
847
  this._chartData = JSON.parse(data);
848
+ this.mappedData = this.reshapeData();
849
+ // checking for width of each tick
850
+ this.mappedData.forEach((elem) => {
851
+ if (elem.series.length > this.dataWidth)
852
+ this.dataWidth = elem.series.length;
853
+ });
854
+ if (this.dataWidth > 1)
855
+ this.barGap = 1;
846
856
  }
847
857
  initSvg() {
848
858
  var _a, _b, _c, _d, _e, _f, _g;
@@ -966,7 +976,7 @@ export class barChart {
966
976
  this._barChartContainer.selectAll('.barGroup').remove();
967
977
  this._barSelection = this._barChartContainer
968
978
  .selectAll('barGroup')
969
- .data(this.reshapeData)
979
+ .data(this.mappedData)
970
980
  .join('g')
971
981
  .attr('class', 'barGroup')
972
982
  .attr('id', (d) => 'barGroup' + d.key.replace(/[^A-Z0-9]+/gi, '_'))
@@ -977,26 +987,17 @@ export class barChart {
977
987
  .attr('y', (d) => this.afVariation === BarChartVariation.Horizontal
978
988
  ? this._yScale(d.key)
979
989
  : this._dims.height - this._margin.bottom)
980
- .attr('x', (d) => this.afVariation === BarChartVariation.Horizontal
981
- ? 2
982
- : this._xScale(d.key))
990
+ .attr('x', this.xFunction)
983
991
  .attr('ry', 4)
984
992
  .attr('rx', 4)
985
- .attr('width', (d) => this.afVariation === BarChartVariation.Horizontal
986
- ? this._xScale(d.value)
987
- : this._xScale.bandwidth())
993
+ .attr('width', this.widthFunction)
988
994
  .attr('height', () => 0)
989
- //.attr('height', (d: any) => this.afVariation === BarChartVariation.Horizontal ? this._yScale.bandwidth() : (this._dims.height - this._margin.bottom) - this._yScale(d.value))
990
995
  .attr('fill', 'gray')
991
996
  .transition()
992
997
  .duration(400)
993
998
  .delay((...[, i]) => i * 150)
994
- .attr('y', (d) => this.afVariation === BarChartVariation.Horizontal
995
- ? this._yScale(d.key)
996
- : this._yScale(d.value))
997
- .attr('height', (d) => this.afVariation === BarChartVariation.Horizontal
998
- ? this._yScale.bandwidth()
999
- : this._dims.height - this._margin.bottom - this._yScale(d.value));
999
+ .attr('y', this.yFunction)
1000
+ .attr('height', this.heightFunction);
1000
1001
  this._barSelection
1001
1002
  .transition()
1002
1003
  .duration(400)
@@ -1087,7 +1088,7 @@ export class barChart {
1087
1088
  if (this.afVariation === BarChartVariation.Horizontal) {
1088
1089
  this.setValueTicks();
1089
1090
  // Removing first tick, because it aligns with y-axis domain
1090
- this._xAxisHandle.select('.tick').select('line').remove();
1091
+ //this._xAxisHandle.select('.tick').select('line').remove();
1091
1092
  }
1092
1093
  else {
1093
1094
  if (!empty) {
@@ -1101,39 +1102,41 @@ export class barChart {
1101
1102
  initBars() {
1102
1103
  this._barSelection = this._barChartContainer
1103
1104
  .selectAll('barGroup')
1104
- .data(this.reshapeData)
1105
+ .data(this.mappedData)
1105
1106
  .join('g')
1106
1107
  .attr('class', 'barGroup')
1107
- .attr('id', (d) => 'barGroup' + d.key.replace(/[^A-Z0-9]+/gi, '_'))
1108
- .append('rect')
1108
+ .attr('id', (d) => {
1109
+ return 'barGroup' + d.key.replace(/[^A-Z0-9]+/gi, '_');
1110
+ });
1111
+ this._barSelection.selectAll('.barGroup')
1112
+ .data((d) => {
1113
+ return d.series;
1114
+ })
1115
+ .join('rect')
1109
1116
  .attr('class', 'bar')
1110
- .style('cursor', 'pointer');
1111
- this._barSelection
1112
- .attr('y', (d) => this.afVariation === BarChartVariation.Horizontal
1113
- ? this._yScale(d.key)
1114
- : this._yScale(d.value))
1115
- .attr('x', (d) => this.afVariation === BarChartVariation.Horizontal
1116
- ? 2
1117
- : this._xScale(d.key))
1117
+ .style('cursor', 'pointer')
1118
+ .attr('x', this.xFunction)
1119
+ .attr('y', this.yFunction)
1118
1120
  .attr('ry', 4)
1119
1121
  .attr('rx', 4)
1120
- .attr('width', (d) => this.afVariation === BarChartVariation.Horizontal
1121
- ? this._xScale(d.value)
1122
- : this._xScale.bandwidth())
1123
- .attr('height', (d) => this.afVariation === BarChartVariation.Horizontal
1124
- ? this._yScale.bandwidth()
1125
- : this._dims.height - this._margin.bottom - this._yScale(d.value))
1126
- .attr('fill', '#00005a')
1122
+ .attr('width', this.widthFunction)
1123
+ .attr('height', this.heightFunction)
1124
+ .attr('fill', (d) => this.colorFunction(d.serie))
1127
1125
  .on('mouseenter', this.hover)
1128
1126
  .on('mouseleave', this.hoverOut)
1129
1127
  .on('click', this.openTooltip);
1130
1128
  }
1131
1129
  initBarText() {
1130
+ var _a, _b;
1131
+ if (!((_b = (_a = this._chartData) === null || _a === void 0 ? void 0 : _a.meta) === null || _b === void 0 ? void 0 : _b.valueLabels))
1132
+ return;
1132
1133
  this._textSelection = this._barChartContainer
1133
1134
  .selectAll('.barGroup')
1134
1135
  .append('text');
1135
1136
  this._textSelection
1136
- .text((d) => d.value.toLocaleString(undefined, this._numberFormat))
1137
+ .text((d) => {
1138
+ return d.value ? d.value.toLocaleString(undefined, this._numberFormat) : undefined;
1139
+ })
1137
1140
  .attr('class', 'barText')
1138
1141
  .attr('font-size', this.fontSize)
1139
1142
  .attr('font-weight', '600')
@@ -1271,6 +1274,18 @@ export class barChart {
1271
1274
  }
1272
1275
  }
1273
1276
  }
1277
+ // Getting correct color given index or name of data serie
1278
+ colorFunction(input) {
1279
+ if (typeof input === 'number')
1280
+ return `var(${this.colorPalettes[input]})`;
1281
+ else {
1282
+ const index = this._chartData.data.series.findIndex((serie) => serie.title === input);
1283
+ if (index > 0)
1284
+ return `var(${this.colorPalettes[index]})`;
1285
+ else
1286
+ return `var(${this.colorPalettes[0]})`;
1287
+ }
1288
+ }
1274
1289
  // Resizing bar chart
1275
1290
  resize() {
1276
1291
  var _a;
@@ -1351,11 +1366,11 @@ export class barChart {
1351
1366
  }
1352
1367
  // Not currently used
1353
1368
  /*get cssModifiers() {
1354
- return {
1355
- 'digi-bar-chart--vertical': this.afVariation == 'vertical',
1356
- 'digi-bar-chart--horizontal': this.afVariation == 'horizontal'
1357
- };
1358
- }*/
1369
+ return {
1370
+ 'digi-bar-chart--vertical': this.afVariation == 'vertical',
1371
+ 'digi-bar-chart--horizontal': this.afVariation == 'horizontal'
1372
+ };
1373
+ }*/
1359
1374
  // Returns pixelwidth of text given the current fontSize (costly function using .each)
1360
1375
  getTextSize(text) {
1361
1376
  const textWidth = [];
@@ -1425,7 +1440,7 @@ export class barChart {
1425
1440
  <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>`;
1426
1441
  }
1427
1442
  }
1428
- 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) }, ' ')));
1443
+ return (h(Host, { key: 'a1e4aaa788766d54c691e95b7e70932b0e7d2b05', ref: (el) => (this._host = el) }, h("div", { key: '2fac926d196acaa20ab5f438968e3c98c08dd104', class: "topWrapper", ref: (el) => (this._titleDiv = el) }, h("digi-typography", { key: '16d8cbd0f03a2a2d24d3366ab1b3eaed797dd361', class: "chartTitle", innerHTML: heading }), h("digi-button", { key: '22a93add4a7f1ea3965ce496f2b5cbf488b01314', 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: '152938d206dc00e2fb88b52d332960cbeda2c045', slot: "icon" }), "Visa tabell"), h("digi-button", { key: '66db213ee1c4cb169c7c257853a15a468bf2a83e', 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: 'ac4b8adad6ace97f50591cd39b8b0082d067f069', slot: "icon" }), "Visa diagram"), h("div", { key: 'b28e00a40b5c1a2919146ec4815f23a14fdfac50', class: "scChartStatus", role: "status", ref: (el) => (this._status = el) })), h("div", { key: '63f80744faa1d4b3d7d62bece3b5c446eda3ae7b', class: "chartTooltip", id: this.afId }, h("div", { key: '8c9fa9388b9bfc071c4a594275159eb36a8ec43b', class: "tooltipBody" }), h("digi-icon-x", { key: '252d12a937e5276381fa40ec3bb4e77c259da9c1', class: "close" }), this.afVariation === BarChartVariation.Horizontal ? (h("digi-icon-caret-up", null)) : (h("digi-icon-caret-down", null))), h("div", { key: '9b70433c310882bd0a06784ca1fa21c5b2dd9e52', ref: (el) => (this._chartDiv = el) }, " "), h("div", { key: '459e38448e29eea1fa7a10de7f3f1f06b6404eab', class: "legend", ref: (el) => (this._legendDiv = el) }), h("div", { key: 'cc655054cb3c3688c75060ebbdf6c3f8ea4ad712', class: "table", ref: (el) => (this._tableDiv = el) }, ' ')));
1429
1444
  }
1430
1445
  static get is() { return "digi-bar-chart"; }
1431
1446
  static get encapsulation() { return "scoped"; }