@opendata-ai/openchart-engine 2.12.1 → 2.13.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.
package/dist/index.js CHANGED
@@ -6100,7 +6100,7 @@ function thinTicksUntilFit(ticks2, fontSize, fontWeight, measureText) {
6100
6100
  }
6101
6101
  return current;
6102
6102
  }
6103
- function continuousTicks(resolvedScale, density, fontSize, fontWeight, measureText) {
6103
+ function continuousTicks(resolvedScale, density) {
6104
6104
  const scale = resolvedScale.scale;
6105
6105
  const explicitCount = resolvedScale.channel.axis?.tickCount;
6106
6106
  const count = explicitCount ?? TICK_COUNTS[density];
@@ -6110,10 +6110,9 @@ function continuousTicks(resolvedScale, density, fontSize, fontWeight, measureTe
6110
6110
  position: scale(value),
6111
6111
  label: formatTickLabel(value, resolvedScale)
6112
6112
  }));
6113
- if (explicitCount) return ticks2;
6114
- return thinTicksUntilFit(ticks2, fontSize, fontWeight, measureText);
6113
+ return ticks2;
6115
6114
  }
6116
- function categoricalTicks(resolvedScale, density, fontSize, fontWeight, measureText) {
6115
+ function categoricalTicks(resolvedScale, density) {
6117
6116
  const scale = resolvedScale.scale;
6118
6117
  const domain = scale.domain();
6119
6118
  const explicitTickCount = resolvedScale.channel.axis?.tickCount;
@@ -6132,9 +6131,6 @@ function categoricalTicks(resolvedScale, density, fontSize, fontWeight, measureT
6132
6131
  label: value
6133
6132
  };
6134
6133
  });
6135
- if (resolvedScale.type !== "band" && !explicitTickCount) {
6136
- return thinTicksUntilFit(ticks2, fontSize, fontWeight, measureText);
6137
- }
6138
6134
  return ticks2;
6139
6135
  }
6140
6136
  function formatTickLabel(value, resolvedScale) {
@@ -6187,11 +6183,13 @@ function computeAxes(scales, chartArea, strategy, theme, measureText) {
6187
6183
  const { fontSize } = tickLabelStyle;
6188
6184
  const { fontWeight } = tickLabelStyle;
6189
6185
  if (scales.x) {
6190
- const ticks2 = scales.x.type === "band" || scales.x.type === "point" || scales.x.type === "ordinal" ? categoricalTicks(scales.x, xDensity, fontSize, fontWeight, measureText) : continuousTicks(scales.x, xDensity, fontSize, fontWeight, measureText);
6191
- const gridlines = ticks2.map((t) => ({
6186
+ const allTicks = scales.x.type === "band" || scales.x.type === "point" || scales.x.type === "ordinal" ? categoricalTicks(scales.x, xDensity) : continuousTicks(scales.x, xDensity);
6187
+ const gridlines = allTicks.map((t) => ({
6192
6188
  position: t.position,
6193
6189
  major: true
6194
6190
  }));
6191
+ const shouldThin = scales.x.type !== "band" && !scales.x.channel.axis?.tickCount;
6192
+ const ticks2 = shouldThin ? thinTicksUntilFit(allTicks, fontSize, fontWeight, measureText) : allTicks;
6195
6193
  let tickAngle = scales.x.channel.axis?.tickAngle;
6196
6194
  if (tickAngle === void 0 && scales.x.type === "band" && ticks2.length > 1) {
6197
6195
  const bandwidth = scales.x.scale.bandwidth();
@@ -6216,11 +6214,13 @@ function computeAxes(scales, chartArea, strategy, theme, measureText) {
6216
6214
  };
6217
6215
  }
6218
6216
  if (scales.y) {
6219
- const ticks2 = scales.y.type === "band" || scales.y.type === "point" || scales.y.type === "ordinal" ? categoricalTicks(scales.y, yDensity, fontSize, fontWeight, measureText) : continuousTicks(scales.y, yDensity, fontSize, fontWeight, measureText);
6220
- const gridlines = ticks2.map((t) => ({
6217
+ const allTicks = scales.y.type === "band" || scales.y.type === "point" || scales.y.type === "ordinal" ? categoricalTicks(scales.y, yDensity) : continuousTicks(scales.y, yDensity);
6218
+ const gridlines = allTicks.map((t) => ({
6221
6219
  position: t.position,
6222
6220
  major: true
6223
6221
  }));
6222
+ const shouldThin = scales.y.type !== "band" && !scales.y.channel.axis?.tickCount;
6223
+ const ticks2 = shouldThin ? thinTicksUntilFit(allTicks, fontSize, fontWeight, measureText) : allTicks;
6224
6224
  result.y = {
6225
6225
  ticks: ticks2,
6226
6226
  // Y-axis gridlines are shown by default (standard editorial practice)