@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
@@ -101,6 +101,9 @@ const barChart = /*@__PURE__*/ proxyCustomElement(class barChart extends H {
101
101
  // States
102
102
  this._loading = false;
103
103
  this._placeholderTicks = ['0', '1', '2', '3', '4', '5', '6', '7'];
104
+ // 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;
105
+ this.dataWidth = 1;
106
+ this.barGap = 0;
104
107
  this._dims = {};
105
108
  this._margin = {
106
109
  bottom: 0,
@@ -118,6 +121,7 @@ const barChart = /*@__PURE__*/ proxyCustomElement(class barChart extends H {
118
121
  this.defaultDuration = 400;
119
122
  // Text and formats
120
123
  this.fontSize = '0.875rem';
124
+ 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'];
121
125
  // Observer for watching size changes when in line chart mode
122
126
  this.barChartObserver = new ResizeObserver((entries) => {
123
127
  entries.forEach(() => {
@@ -163,12 +167,8 @@ const barChart = /*@__PURE__*/ proxyCustomElement(class barChart extends H {
163
167
  this._dims.width - this._margin.right - this._margin.left
164
168
  ]);
165
169
  this._barSelection
166
- .attr('x', (d) => this.afVariation === BarChartVariation.Horizontal
167
- ? 2
168
- : this._xScale(d.key))
169
- .attr('width', (d) => this.afVariation === BarChartVariation.Horizontal
170
- ? this._xScale(d.value)
171
- : this._xScale.bandwidth());
170
+ .attr('x', this.xFunction)
171
+ .attr('width', this.widthFunction);
172
172
  this.setValueTicks();
173
173
  };
174
174
  // Adding click listener for tool tip text
@@ -257,7 +257,7 @@ const barChart = /*@__PURE__*/ proxyCustomElement(class barChart extends H {
257
257
  this.updateBars = (fromLoading) => {
258
258
  this._barChartContainer
259
259
  .selectAll('.barGroup')
260
- .data(this.reshapeData)
260
+ .data(this.mappedData)
261
261
  .join((enter) => {
262
262
  var _a, _b;
263
263
  const tempSelection = enter
@@ -288,17 +288,9 @@ const barChart = /*@__PURE__*/ proxyCustomElement(class barChart extends H {
288
288
  .transition()
289
289
  .duration(this.defaultDuration)
290
290
  .ease(polyInOut)
291
- .attr('width', (d) => this.afVariation === BarChartVariation.Horizontal
292
- ? this._xScale(d.value)
293
- : this._xScale.bandwidth())
294
- .attr('y', (d) => this.afVariation === BarChartVariation.Horizontal
295
- ? this._yScale(d.key)
296
- : this._yScale(d.value))
297
- .attr('height', (d) => this.afVariation === BarChartVariation.Horizontal
298
- ? this._yScale.bandwidth()
299
- : this._dims.height -
300
- this._margin.bottom -
301
- this._yScale(d.value))
291
+ .attr('width', this.widthFunction)
292
+ .attr('y', this.yFunction)
293
+ .attr('height', this.heightFunction)
302
294
  .attr('fill', '#00005a');
303
295
  if (!((_b = (_a = this._chartData) === null || _a === void 0 ? void 0 : _a.meta) === null || _b === void 0 ? void 0 : _b.valueLabels))
304
296
  return tempSelection;
@@ -370,15 +362,11 @@ const barChart = /*@__PURE__*/ proxyCustomElement(class barChart extends H {
370
362
  .on('mouseenter', this.hover)
371
363
  .on('mouseleave', this.hoverOut)
372
364
  .on('click', this.openTooltip)
373
- .attr('x', (d) => this.afVariation === BarChartVariation.Horizontal
374
- ? 2
375
- : this._xScale(d.key))
365
+ .attr('x', this.xFunction)
376
366
  .attr('y', (d) => this.afVariation === BarChartVariation.Horizontal
377
367
  ? this._yScale(d.key)
378
368
  : this._dims.height - this._margin.bottom)
379
- .attr('width', (d) => this.afVariation === BarChartVariation.Horizontal
380
- ? this._xScale(d.value)
381
- : this._xScale.bandwidth())
369
+ .attr('width', this.widthFunction)
382
370
  .attr('height', () => this.afVariation === BarChartVariation.Horizontal
383
371
  ? this._yScale.bandwidth()
384
372
  : 0)
@@ -386,14 +374,8 @@ const barChart = /*@__PURE__*/ proxyCustomElement(class barChart extends H {
386
374
  .transition()
387
375
  .duration(this.defaultDuration)
388
376
  .ease(polyInOut)
389
- .attr('y', (d) => this.afVariation === BarChartVariation.Horizontal
390
- ? this._yScale(d.key)
391
- : this._yScale(d.value))
392
- .attr('height', (d) => this.afVariation === BarChartVariation.Horizontal
393
- ? this._yScale.bandwidth()
394
- : this._dims.height -
395
- this._margin.bottom -
396
- this._yScale(d.value))
377
+ .attr('y', this.yFunction)
378
+ .attr('height', this.heightFunction)
397
379
  .on('end', () => this.barChartObserver.observe(this._chartDiv)); // Reset barchartObserver
398
380
  }
399
381
  else {
@@ -402,20 +384,10 @@ const barChart = /*@__PURE__*/ proxyCustomElement(class barChart extends H {
402
384
  .transition()
403
385
  .duration(this.defaultDuration)
404
386
  .ease(polyInOut)
405
- .attr('y', (d) => this.afVariation === BarChartVariation.Horizontal
406
- ? this._yScale(d.key)
407
- : this._yScale(d.value))
408
- .attr('x', (d) => this.afVariation === BarChartVariation.Horizontal
409
- ? 2
410
- : this._xScale(d.key))
411
- .attr('width', (d) => this.afVariation === BarChartVariation.Horizontal
412
- ? this._xScale(d.value)
413
- : this._xScale.bandwidth())
414
- .attr('height', (d) => this.afVariation === BarChartVariation.Horizontal
415
- ? this._yScale.bandwidth()
416
- : this._dims.height -
417
- this._margin.bottom -
418
- this._yScale(d.value))
387
+ .attr('x', this.xFunction)
388
+ .attr('y', this.yFunction)
389
+ .attr('width', this.widthFunction)
390
+ .attr('height', this.heightFunction)
419
391
  .attr('fill', '#00005a');
420
392
  }
421
393
  return update
@@ -506,37 +478,67 @@ const barChart = /*@__PURE__*/ proxyCustomElement(class barChart extends H {
506
478
  const toReturn = [];
507
479
  if (this._loading) {
508
480
  this._placeholderTicks.forEach((key) => {
509
- toReturn.push({
481
+ const tick = { key: key, series: [] };
482
+ tick.series.push({
510
483
  key: key,
484
+ serie: '',
511
485
  value: Math.floor(Math.random() * (9 - 2 + 1) + 2),
512
- len: '1'
486
+ len: 0
513
487
  });
488
+ toReturn.push(tick);
514
489
  });
515
490
  return toReturn;
516
491
  }
517
492
  this._chartData.data.xValueNames.forEach((key, index) => {
518
- toReturn.push({
519
- key: key,
520
- value: this._chartData.data.series[0].yValues[index],
521
- len: this.getTextSize(this._chartData.data.series[0].yValues[index].toLocaleString())
493
+ const tick = { key: key, series: [] };
494
+ this._chartData.data.series.forEach((serie) => {
495
+ if (serie.yValues[index]) {
496
+ tick.series.push({
497
+ key: key,
498
+ serie: serie.title,
499
+ value: serie.yValues[index],
500
+ len: serie.yValues[index] ? this.getTextSize(serie.yValues[index].toLocaleString()) : 0
501
+ });
502
+ }
522
503
  });
504
+ toReturn.push(tick);
523
505
  });
524
506
  return toReturn;
525
507
  };
526
508
  this.adjustBarSize = () => {
527
- this._barSelection
528
- .attr('y', (d) => this.afVariation === BarChartVariation.Horizontal
529
- ? this._yScale(d.key)
530
- : this._yScale(d.value))
531
- .attr('x', (d) => this.afVariation === BarChartVariation.Horizontal
532
- ? 2
533
- : this._xScale(d.key))
534
- .attr('width', (d) => this.afVariation === BarChartVariation.Horizontal
535
- ? this._xScale(d.value)
536
- : this._xScale.bandwidth())
537
- .attr('height', (d) => this.afVariation === BarChartVariation.Horizontal
538
- ? this._yScale.bandwidth()
539
- : this._dims.height - this._margin.bottom - this._yScale(d.value));
509
+ this._barSelection.selectAll('.bar')
510
+ .attr('x', this.xFunction)
511
+ .attr('y', this.yFunction)
512
+ .attr('width', this.widthFunction)
513
+ .attr('height', this.heightFunction);
514
+ };
515
+ // Handling x positioning of bars
516
+ this.xFunction = (d, i) => {
517
+ return this.afVariation === BarChartVariation.Horizontal
518
+ ? (d.value > 0 ? this._xScale(0) : this._xScale(d.value))
519
+ : this._xScale(d.key) + ((this._xScale.bandwidth() / this.dataWidth) * i + (this.barGap * i));
520
+ };
521
+ // Handling y positioning of bars
522
+ this.yFunction = (d, i) => {
523
+ if (!d.value)
524
+ return 0;
525
+ return this.afVariation === BarChartVariation.Horizontal
526
+ ? this._yScale(d.key) + ((this._yScale.bandwidth() / this.dataWidth) * i + (this.barGap * i))
527
+ : (d.value < 0 ? this._yScale(0) : this._yScale(d.value));
528
+ };
529
+ // Handling height for bars
530
+ this.heightFunction = (d) => {
531
+ if (!d.value)
532
+ return 0;
533
+ return this.afVariation === BarChartVariation.Horizontal
534
+ ? this._yScale.bandwidth() / this.dataWidth - (this.barGap)
535
+ : (d.value < 0 ? this._yScale(d.value) - this._yScale(0) : this._yScale(0) - this._yScale(d.value));
536
+ };
537
+ // Handling width for bars
538
+ this.widthFunction = (d) => {
539
+ return this.afVariation === BarChartVariation.Horizontal
540
+ ? Math.abs(this._xScale(0) - this._xScale(d.value))
541
+ : this._xScale.bandwidth() / this.dataWidth - (this.barGap);
540
542
  };
541
543
  // Resize table
542
544
  this.resizeTable = () => {
@@ -776,16 +778,16 @@ const barChart = /*@__PURE__*/ proxyCustomElement(class barChart extends H {
776
778
  select(event.target)
777
779
  .transition('hover')
778
780
  .duration(20)
779
- .attr('fill', event.target.tagName === 'rect'
780
- ? '#4C4C8B'
781
- : 'var(--digi--color--text--link-hover)');
781
+ .attr('fill', (d) => event.target.tagName === 'rect'
782
+ ? `hsl(from ${this.colorFunction(d.serie)} h s calc(l + 10))`
783
+ : 'var(--digi--color--background--interactive--hover--tertiary)');
782
784
  };
783
785
  // Removing highlight from bar
784
786
  this.hoverOut = (event) => {
785
787
  select(event.target)
786
788
  .transition('hover')
787
789
  .duration(this.defaultDuration)
788
- .attr('fill', event.target.tagName === 'rect' ? '#00005a' : '#333333');
790
+ .attr('fill', (d) => event.target.tagName === 'rect' ? this.colorFunction(d.serie) : '#333333');
789
791
  };
790
792
  this.openTooltip = (...[, d]) => {
791
793
  // If type is string, the user has clicked on a y-axis tick
@@ -854,7 +856,7 @@ const barChart = /*@__PURE__*/ proxyCustomElement(class barChart extends H {
854
856
  if (this.afVariation == BarChartVariation.Horizontal)
855
857
  this._tickWidth = this.getLargestText(this._xScale.ticks().map((tick) => tick.toLocaleString()));
856
858
  this.tickSizes();
857
- this._barChartContainer.selectAll('.barGroup').data(this.reshapeData);
859
+ this._barChartContainer.selectAll('.barGroup').data(this.mappedData);
858
860
  if ((_b = (_a = this._chartData) === null || _a === void 0 ? void 0 : _a.meta) === null || _b === void 0 ? void 0 : _b.valueLabels)
859
861
  this._textSelection.remove();
860
862
  this.initBarText();
@@ -925,6 +927,14 @@ const barChart = /*@__PURE__*/ proxyCustomElement(class barChart extends H {
925
927
  this._chartData = data;
926
928
  else
927
929
  this._chartData = JSON.parse(data);
930
+ this.mappedData = this.reshapeData();
931
+ // checking for width of each tick
932
+ this.mappedData.forEach((elem) => {
933
+ if (elem.series.length > this.dataWidth)
934
+ this.dataWidth = elem.series.length;
935
+ });
936
+ if (this.dataWidth > 1)
937
+ this.barGap = 1;
928
938
  }
929
939
  initSvg() {
930
940
  var _a, _b, _c, _d, _e, _f, _g;
@@ -1044,7 +1054,7 @@ const barChart = /*@__PURE__*/ proxyCustomElement(class barChart extends H {
1044
1054
  this._barChartContainer.selectAll('.barGroup').remove();
1045
1055
  this._barSelection = this._barChartContainer
1046
1056
  .selectAll('barGroup')
1047
- .data(this.reshapeData)
1057
+ .data(this.mappedData)
1048
1058
  .join('g')
1049
1059
  .attr('class', 'barGroup')
1050
1060
  .attr('id', (d) => 'barGroup' + d.key.replace(/[^A-Z0-9]+/gi, '_'))
@@ -1055,26 +1065,17 @@ const barChart = /*@__PURE__*/ proxyCustomElement(class barChart extends H {
1055
1065
  .attr('y', (d) => this.afVariation === BarChartVariation.Horizontal
1056
1066
  ? this._yScale(d.key)
1057
1067
  : this._dims.height - this._margin.bottom)
1058
- .attr('x', (d) => this.afVariation === BarChartVariation.Horizontal
1059
- ? 2
1060
- : this._xScale(d.key))
1068
+ .attr('x', this.xFunction)
1061
1069
  .attr('ry', 4)
1062
1070
  .attr('rx', 4)
1063
- .attr('width', (d) => this.afVariation === BarChartVariation.Horizontal
1064
- ? this._xScale(d.value)
1065
- : this._xScale.bandwidth())
1071
+ .attr('width', this.widthFunction)
1066
1072
  .attr('height', () => 0)
1067
- //.attr('height', (d: any) => this.afVariation === BarChartVariation.Horizontal ? this._yScale.bandwidth() : (this._dims.height - this._margin.bottom) - this._yScale(d.value))
1068
1073
  .attr('fill', 'gray')
1069
1074
  .transition()
1070
1075
  .duration(400)
1071
1076
  .delay((...[, i]) => i * 150)
1072
- .attr('y', (d) => this.afVariation === BarChartVariation.Horizontal
1073
- ? this._yScale(d.key)
1074
- : this._yScale(d.value))
1075
- .attr('height', (d) => this.afVariation === BarChartVariation.Horizontal
1076
- ? this._yScale.bandwidth()
1077
- : this._dims.height - this._margin.bottom - this._yScale(d.value));
1077
+ .attr('y', this.yFunction)
1078
+ .attr('height', this.heightFunction);
1078
1079
  this._barSelection
1079
1080
  .transition()
1080
1081
  .duration(400)
@@ -1164,7 +1165,7 @@ const barChart = /*@__PURE__*/ proxyCustomElement(class barChart extends H {
1164
1165
  if (this.afVariation === BarChartVariation.Horizontal) {
1165
1166
  this.setValueTicks();
1166
1167
  // Removing first tick, because it aligns with y-axis domain
1167
- this._xAxisHandle.select('.tick').select('line').remove();
1168
+ //this._xAxisHandle.select('.tick').select('line').remove();
1168
1169
  }
1169
1170
  else {
1170
1171
  if (!empty) {
@@ -1178,39 +1179,41 @@ const barChart = /*@__PURE__*/ proxyCustomElement(class barChart extends H {
1178
1179
  initBars() {
1179
1180
  this._barSelection = this._barChartContainer
1180
1181
  .selectAll('barGroup')
1181
- .data(this.reshapeData)
1182
+ .data(this.mappedData)
1182
1183
  .join('g')
1183
1184
  .attr('class', 'barGroup')
1184
- .attr('id', (d) => 'barGroup' + d.key.replace(/[^A-Z0-9]+/gi, '_'))
1185
- .append('rect')
1185
+ .attr('id', (d) => {
1186
+ return 'barGroup' + d.key.replace(/[^A-Z0-9]+/gi, '_');
1187
+ });
1188
+ this._barSelection.selectAll('.barGroup')
1189
+ .data((d) => {
1190
+ return d.series;
1191
+ })
1192
+ .join('rect')
1186
1193
  .attr('class', 'bar')
1187
- .style('cursor', 'pointer');
1188
- this._barSelection
1189
- .attr('y', (d) => this.afVariation === BarChartVariation.Horizontal
1190
- ? this._yScale(d.key)
1191
- : this._yScale(d.value))
1192
- .attr('x', (d) => this.afVariation === BarChartVariation.Horizontal
1193
- ? 2
1194
- : this._xScale(d.key))
1194
+ .style('cursor', 'pointer')
1195
+ .attr('x', this.xFunction)
1196
+ .attr('y', this.yFunction)
1195
1197
  .attr('ry', 4)
1196
1198
  .attr('rx', 4)
1197
- .attr('width', (d) => this.afVariation === BarChartVariation.Horizontal
1198
- ? this._xScale(d.value)
1199
- : this._xScale.bandwidth())
1200
- .attr('height', (d) => this.afVariation === BarChartVariation.Horizontal
1201
- ? this._yScale.bandwidth()
1202
- : this._dims.height - this._margin.bottom - this._yScale(d.value))
1203
- .attr('fill', '#00005a')
1199
+ .attr('width', this.widthFunction)
1200
+ .attr('height', this.heightFunction)
1201
+ .attr('fill', (d) => this.colorFunction(d.serie))
1204
1202
  .on('mouseenter', this.hover)
1205
1203
  .on('mouseleave', this.hoverOut)
1206
1204
  .on('click', this.openTooltip);
1207
1205
  }
1208
1206
  initBarText() {
1207
+ var _a, _b;
1208
+ if (!((_b = (_a = this._chartData) === null || _a === void 0 ? void 0 : _a.meta) === null || _b === void 0 ? void 0 : _b.valueLabels))
1209
+ return;
1209
1210
  this._textSelection = this._barChartContainer
1210
1211
  .selectAll('.barGroup')
1211
1212
  .append('text');
1212
1213
  this._textSelection
1213
- .text((d) => d.value.toLocaleString(undefined, this._numberFormat))
1214
+ .text((d) => {
1215
+ return d.value ? d.value.toLocaleString(undefined, this._numberFormat) : undefined;
1216
+ })
1214
1217
  .attr('class', 'barText')
1215
1218
  .attr('font-size', this.fontSize)
1216
1219
  .attr('font-weight', '600')
@@ -1348,6 +1351,18 @@ const barChart = /*@__PURE__*/ proxyCustomElement(class barChart extends H {
1348
1351
  }
1349
1352
  }
1350
1353
  }
1354
+ // Getting correct color given index or name of data serie
1355
+ colorFunction(input) {
1356
+ if (typeof input === 'number')
1357
+ return `var(${this.colorPalettes[input]})`;
1358
+ else {
1359
+ const index = this._chartData.data.series.findIndex((serie) => serie.title === input);
1360
+ if (index > 0)
1361
+ return `var(${this.colorPalettes[index]})`;
1362
+ else
1363
+ return `var(${this.colorPalettes[0]})`;
1364
+ }
1365
+ }
1351
1366
  // Resizing bar chart
1352
1367
  resize() {
1353
1368
  var _a;
@@ -1428,11 +1443,11 @@ const barChart = /*@__PURE__*/ proxyCustomElement(class barChart extends H {
1428
1443
  }
1429
1444
  // Not currently used
1430
1445
  /*get cssModifiers() {
1431
- return {
1432
- 'digi-bar-chart--vertical': this.afVariation == 'vertical',
1433
- 'digi-bar-chart--horizontal': this.afVariation == 'horizontal'
1434
- };
1435
- }*/
1446
+ return {
1447
+ 'digi-bar-chart--vertical': this.afVariation == 'vertical',
1448
+ 'digi-bar-chart--horizontal': this.afVariation == 'horizontal'
1449
+ };
1450
+ }*/
1436
1451
  // Returns pixelwidth of text given the current fontSize (costly function using .each)
1437
1452
  getTextSize(text) {
1438
1453
  const textWidth = [];
@@ -1502,7 +1517,7 @@ const barChart = /*@__PURE__*/ proxyCustomElement(class barChart extends H {
1502
1517
  <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>`;
1503
1518
  }
1504
1519
  }
1505
- 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) }, ' ')));
1520
+ 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) }, ' ')));
1506
1521
  }
1507
1522
  get hostElement() { return this; }
1508
1523
  static get watchers() { return {