axidio-styleguide-library1-v2 0.6.79 → 0.6.80

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.
@@ -3743,7 +3743,7 @@ class GroupChartComponent extends ComponentUniqueId {
3743
3743
  this.renderMultiChartXAxis(svg, x, height, data, metaData);
3744
3744
  }
3745
3745
  if (this.chartConfiguration.xLabelsOnSameLine) {
3746
- this.renderXLabelsOnSameLine(svg, data, metaData);
3746
+ this.renderXLabelsOnSameLine(svg, data, metaData, x);
3747
3747
  }
3748
3748
  // Bottom x-axis
3749
3749
  const xAxis2 = svg
@@ -3794,34 +3794,42 @@ class GroupChartComponent extends ComponentUniqueId {
3794
3794
  }
3795
3795
  });
3796
3796
  }
3797
- renderXLabelsOnSameLine(svg, data, metaData) {
3798
- const short_tick_length_bg = 5;
3799
- const long_tick_length_bg = 30;
3800
- svg
3801
- .selectAll('g.x1.axis1 g.tick text')
3802
- .attr('class', 'lib-xaxis-labels-texts-drilldown')
3803
- .attr('y', short_tick_length_bg)
3804
- .text((d) => {
3805
- const isValueToBeIgnored = data.some((indiv) => indiv.name.toLowerCase() === d.trim().toLowerCase() &&
3797
+ renderXLabelsOnSameLine(svg, data, metaData, x) {
3798
+ const shortY = 8;
3799
+ const longY = 26;
3800
+ // Remove previously added split labels (important on resize)
3801
+ svg.selectAll('.lib-xaxis-split').remove();
3802
+ const ticks = svg.selectAll('g.x1.axis1 g.tick');
3803
+ ticks.each((d, i, nodes) => {
3804
+ const tick = d3.select(nodes[i]);
3805
+ const label = d.trim().toLowerCase();
3806
+ const ignore = data.some((indiv) => indiv.name.toLowerCase() === label &&
3806
3807
  indiv[metaData.keyList[0]] === -1);
3807
- if (isValueToBeIgnored)
3808
- return '';
3809
- if (d.trim().indexOf(' ') > -1) {
3810
- return d.trim().substring(0, d.indexOf(' ')).toLowerCase();
3808
+ if (ignore) {
3809
+ tick.select('text').text('');
3810
+ return;
3811
3811
  }
3812
- return d.toLowerCase();
3813
- });
3814
- svg
3815
- .selectAll('g.x1.axis1 g.tick')
3816
- .append('text')
3817
- .attr('class', 'lib-xaxis-labels-texts-drilldown')
3818
- .attr('y', long_tick_length_bg)
3819
- .attr('fill', 'currentColor')
3820
- .text((d) => {
3821
- if (d.trim().indexOf(' ') > -1) {
3822
- return d.trim().substring(d.indexOf(' ')).toLowerCase();
3812
+ const bandwidth = x?.bandwidth?.() || 60;
3813
+ const maxCharsPerLine = Math.floor(bandwidth / 7); // responsive
3814
+ const truncate = (text) => text.length > maxCharsPerLine
3815
+ ? text.slice(0, maxCharsPerLine - 1) + '…'
3816
+ : text;
3817
+ const parts = label.split(' ');
3818
+ // First line
3819
+ tick
3820
+ .select('text')
3821
+ .attr('class', 'lib-xaxis-labels-texts-drilldown lib-xaxis-split')
3822
+ .attr('y', shortY)
3823
+ .text(truncate(parts[0]));
3824
+ // Second line (only if exists)
3825
+ if (parts.length > 1 && bandwidth > 35) {
3826
+ tick
3827
+ .append('text')
3828
+ .attr('class', 'lib-xaxis-labels-texts-drilldown lib-xaxis-split')
3829
+ .attr('y', longY)
3830
+ .attr('text-anchor', 'middle')
3831
+ .text(truncate(parts.slice(1).join(' ')));
3823
3832
  }
3824
- return '';
3825
3833
  });
3826
3834
  }
3827
3835
  renderYAxis(svg, svgYAxisLeft, svgYAxisRight, y, dimensions) {
@@ -4032,6 +4040,24 @@ class GroupChartComponent extends ComponentUniqueId {
4032
4040
  }
4033
4041
  return xSubgroup.bandwidth();
4034
4042
  }
4043
+ truncateTextByWidth(text, maxWidth, fontSize = 12, fontFamily = 'sans-serif') {
4044
+ if (!text)
4045
+ return '';
4046
+ const canvas = document.createElement('canvas');
4047
+ const context = canvas.getContext('2d');
4048
+ if (!context)
4049
+ return text;
4050
+ context.font = `${fontSize}px ${fontFamily}`;
4051
+ if (context.measureText(text).width <= maxWidth) {
4052
+ return text;
4053
+ }
4054
+ let truncated = text;
4055
+ while (truncated.length > 0 &&
4056
+ context.measureText(truncated + '…').width > maxWidth) {
4057
+ truncated = truncated.slice(0, -1);
4058
+ }
4059
+ return truncated + '…';
4060
+ }
4035
4061
  getBarHeight(d, y, height) {
4036
4062
  if (d.value === -1)
4037
4063
  return height - y(0);
@@ -7814,7 +7840,7 @@ class HorizontalGroupedBarWithScrollZoomComponent extends ComponentUniqueId {
7814
7840
  // more than one subgroup so grouped bars don't get congested.
7815
7841
  // On desktop: enable scrolling when there are many groups or
7816
7842
  // multiple subgroups (keeps previous behavior).
7817
- if ((isMobile || isTablet) && subgroupsCount > 1) {
7843
+ if ((isMobile) && subgroupsCount > 1) {
7818
7844
  innerContainer.style('overflow-x', 'auto');
7819
7845
  innerContainer.classed('scroll-enabled', true);
7820
7846
  }
@@ -8025,6 +8051,7 @@ class HorizontalGroupedBarWithScrollZoomComponent extends ComponentUniqueId {
8025
8051
  // }
8026
8052
  // ✅ Tablet View — Rotate if text > 10 characters
8027
8053
  if (isTablet) {
8054
+ const isria = this.customChartConfiguration.isRia;
8028
8055
  const textNodes = svg.selectAll('g.x1.axis1 g.tick text');
8029
8056
  textNodes.each(function (d) {
8030
8057
  const text = d ? d.toString().trim() : '';
@@ -8034,8 +8061,10 @@ class HorizontalGroupedBarWithScrollZoomComponent extends ComponentUniqueId {
8034
8061
  if (!isDateString && text.length > 10) {
8035
8062
  const trimmed = text.slice(0, 9) + '…';
8036
8063
  textNodes
8037
- .style('font-size', '10px');
8038
- // .text(trimmed)
8064
+ .style('font-size', '9px');
8065
+ if (isria) {
8066
+ textNodes.text(trimmed);
8067
+ }
8039
8068
  }
8040
8069
  });
8041
8070
  }