@porscheinformatik/clr-addons 19.18.3 → 19.18.4

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.
@@ -12,6 +12,28 @@ export interface XYAxisOptions {
12
12
  /** Left margin already accounting for the Y-axis label offset. */
13
13
  effectiveLeft: number;
14
14
  }
15
+ /**
16
+ * Computes sensible tick values for a linear Y scale.
17
+ *
18
+ * When the domain contains enough integer values (≥ 3) the ticks are filtered
19
+ * to integers only (avoids fractional labels for count data). For small-range
20
+ * domains – e.g. 0–1 ratios / probabilities – the raw D3 ticks are returned
21
+ * unchanged so that decimal labels are still visible.
22
+ */
23
+ export declare function computeYTickValues(y: ScaleLinear<number, number>, count?: number): number[];
24
+ /**
25
+ * Returns a D3 tick-format function that matches the decision made in
26
+ * {@link computeYTickValues}:
27
+ *
28
+ * - **Integer / large-value domain** (≥ 3 integer ticks): SI prefix format
29
+ * (`~s`), e.g. `1k`, `200`.
30
+ * - **Small / decimal domain** (< 3 integer ticks, e.g. 0–1 ratios): plain
31
+ * fixed-point format (`.3~f`) – avoids the SI "milli" prefix (`m`) that
32
+ * D3 would otherwise apply to values < 1.
33
+ */
34
+ export declare function computeYTickFormat(y: ScaleLinear<number, number>, count?: number): (d: number | {
35
+ valueOf(): number;
36
+ }) => string;
15
37
  /**
16
38
  * Draws the X and Y axes (with integer-only Y ticks and grid lines) plus
17
39
  * optional description labels onto the given D3 group.
@@ -1083,6 +1083,36 @@ function renderDots(g, series, x, y, onClick) {
1083
1083
  * This software is released under MIT license.
1084
1084
  * The full license information can be found in LICENSE in the root directory of this project.
1085
1085
  */
1086
+ /**
1087
+ * Computes sensible tick values for a linear Y scale.
1088
+ *
1089
+ * When the domain contains enough integer values (≥ 3) the ticks are filtered
1090
+ * to integers only (avoids fractional labels for count data). For small-range
1091
+ * domains – e.g. 0–1 ratios / probabilities – the raw D3 ticks are returned
1092
+ * unchanged so that decimal labels are still visible.
1093
+ */
1094
+ function computeYTickValues(y, count = 5) {
1095
+ const raw = y.ticks(count);
1096
+ const integers = raw.filter(Number.isInteger);
1097
+ // Keep integer-only ticks only when there are at least 3 of them; otherwise
1098
+ // the domain is too small (e.g. 0–1) and we need the decimal ticks.
1099
+ return integers.length >= 3 ? integers : raw;
1100
+ }
1101
+ /**
1102
+ * Returns a D3 tick-format function that matches the decision made in
1103
+ * {@link computeYTickValues}:
1104
+ *
1105
+ * - **Integer / large-value domain** (≥ 3 integer ticks): SI prefix format
1106
+ * (`~s`), e.g. `1k`, `200`.
1107
+ * - **Small / decimal domain** (< 3 integer ticks, e.g. 0–1 ratios): plain
1108
+ * fixed-point format (`.3~f`) – avoids the SI "milli" prefix (`m`) that
1109
+ * D3 would otherwise apply to values < 1.
1110
+ */
1111
+ function computeYTickFormat(y, count = 5) {
1112
+ const raw = y.ticks(count);
1113
+ const integers = raw.filter(Number.isInteger);
1114
+ return integers.length >= 3 ? format('~s') : format('.3~f');
1115
+ }
1086
1116
  /**
1087
1117
  * Draws the X and Y axes (with integer-only Y ticks and grid lines) plus
1088
1118
  * optional description labels onto the given D3 group.
@@ -1102,9 +1132,10 @@ function drawXYAxes(g, x, y, opts) {
1102
1132
  .style('font-size', '11px')
1103
1133
  .style('fill', 'var(--clr-color-neutral-600, #666)');
1104
1134
  // Y axis
1105
- const tickValues = y.ticks(5).filter((t) => Number.isInteger(t));
1135
+ const tickValues = computeYTickValues(y);
1136
+ const tickFormat = computeYTickFormat(y);
1106
1137
  g.append('g')
1107
- .call(axisLeft(y).tickValues(tickValues).tickSize(-width).tickFormat(format('~s')))
1138
+ .call(axisLeft(y).tickValues(tickValues).tickSize(-width).tickFormat(tickFormat))
1108
1139
  .selectAll('text')
1109
1140
  .style('font-size', '11px')
1110
1141
  .style('fill', 'var(--clr-color-neutral-600, #666)');
@@ -1565,12 +1596,12 @@ class ComboChartComponent extends ChartBase {
1565
1596
  styleGridLines(g);
1566
1597
  // ── Right Y axis for line series ─────────────────────────────────────────
1567
1598
  if (hasLines) {
1568
- const lineTickValues = yLine.ticks(5).filter((t) => Number.isInteger(t));
1599
+ const lineTickValues = computeYTickValues(yLine);
1600
+ const lineTickFormat = computeYTickFormat(yLine);
1569
1601
  const rightAxisG = g
1570
1602
  .append('g')
1571
1603
  .attr('transform', `translate(${width},0)`)
1572
- .call(axisRight(yLine).tickValues(lineTickValues).tickFormat(format('~s')).tickSize(-width) // draw grid lines across the chart
1573
- );
1604
+ .call(axisRight(yLine).tickValues(lineTickValues).tickFormat(lineTickFormat).tickSize(-width));
1574
1605
  rightAxisG.selectAll('text').style('font-size', '11px').style('fill', 'var(--clr-color-neutral-600, #666)');
1575
1606
  // Style the line-axis grid lines with a distinct dashed color
1576
1607
  rightAxisG