@opendata-ai/openchart-engine 6.19.1 → 6.19.3

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.
package/dist/index.js CHANGED
@@ -7802,9 +7802,19 @@ function effectiveDensity(baseDensity, axisLength, minimalThreshold, reducedThre
7802
7802
  function measureLabel(text, fontSize, fontWeight, measureText) {
7803
7803
  return measureText ? measureText(text, fontSize, fontWeight).width : estimateTextWidth7(text, fontSize, fontWeight);
7804
7804
  }
7805
- function ticksOverlap(ticks2, fontSize, fontWeight, measureText) {
7805
+ function ticksOverlap(ticks2, fontSize, fontWeight, measureText, orientation = "horizontal") {
7806
7806
  if (ticks2.length < 2) return false;
7807
7807
  const minGap = fontSize * MIN_TICK_GAP_FACTOR;
7808
+ if (orientation === "vertical") {
7809
+ const sorted = [...ticks2].sort((a, b) => a.position - b.position);
7810
+ const labelHeight = fontSize * 1.2;
7811
+ for (let i = 0; i < sorted.length - 1; i++) {
7812
+ const aBottom = sorted[i].position + labelHeight / 2;
7813
+ const bTop = sorted[i + 1].position - labelHeight / 2;
7814
+ if (aBottom + minGap > bTop) return true;
7815
+ }
7816
+ return false;
7817
+ }
7808
7818
  for (let i = 0; i < ticks2.length - 1; i++) {
7809
7819
  const aWidth = measureLabel(ticks2[i].label, fontSize, fontWeight, measureText);
7810
7820
  const bWidth = measureLabel(ticks2[i + 1].label, fontSize, fontWeight, measureText);
@@ -7814,8 +7824,8 @@ function ticksOverlap(ticks2, fontSize, fontWeight, measureText) {
7814
7824
  }
7815
7825
  return false;
7816
7826
  }
7817
- function thinTicksUntilFit(ticks2, fontSize, fontWeight, measureText) {
7818
- if (!ticksOverlap(ticks2, fontSize, fontWeight, measureText)) return ticks2;
7827
+ function thinTicksUntilFit(ticks2, fontSize, fontWeight, measureText, orientation = "horizontal") {
7828
+ if (!ticksOverlap(ticks2, fontSize, fontWeight, measureText, orientation)) return ticks2;
7819
7829
  let current = ticks2;
7820
7830
  while (current.length > MIN_TICK_COUNT) {
7821
7831
  const thinned = [current[0]];
@@ -7824,7 +7834,7 @@ function thinTicksUntilFit(ticks2, fontSize, fontWeight, measureText) {
7824
7834
  }
7825
7835
  if (current.length > 1) thinned.push(current[current.length - 1]);
7826
7836
  current = thinned;
7827
- if (!ticksOverlap(current, fontSize, fontWeight, measureText)) break;
7837
+ if (!ticksOverlap(current, fontSize, fontWeight, measureText, orientation)) break;
7828
7838
  }
7829
7839
  return current;
7830
7840
  }
@@ -8011,7 +8021,7 @@ function computeAxes(scales, chartArea, strategy, theme, measureText) {
8011
8021
  allTicks = continuousTicks(scales.y, yDensity);
8012
8022
  }
8013
8023
  const shouldThin = scales.y.type !== "band" && !axisConfig?.tickCount && !axisConfig?.values;
8014
- const ticks2 = shouldThin ? thinTicksUntilFit(allTicks, fontSize, fontWeight, measureText) : allTicks;
8024
+ const ticks2 = shouldThin ? thinTicksUntilFit(allTicks, fontSize, fontWeight, measureText, "vertical") : allTicks;
8015
8025
  const gridlines = ticks2.map((t) => ({
8016
8026
  position: t.position,
8017
8027
  major: true