@opendata-ai/openchart-engine 7.9.3 → 7.10.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 +23 -19
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/axes.test.ts +165 -0
- package/src/layout/axes/ticks.ts +20 -5
- package/src/layout/axes.ts +40 -15
package/dist/index.js
CHANGED
|
@@ -10637,7 +10637,7 @@ var NUMERIC_SCALE_TYPES = /* @__PURE__ */ new Set([
|
|
|
10637
10637
|
"threshold"
|
|
10638
10638
|
]);
|
|
10639
10639
|
var TEMPORAL_SCALE_TYPES = /* @__PURE__ */ new Set(["time", "utc"]);
|
|
10640
|
-
function formatTickLabel(value2, resolvedScale) {
|
|
10640
|
+
function formatTickLabel(value2, resolvedScale, compact = false) {
|
|
10641
10641
|
const axisConfig = resolvedScale.channel.axis || void 0;
|
|
10642
10642
|
const formatStr = axisConfig?.format;
|
|
10643
10643
|
const suffix = axisConfig?.labelSuffix ?? "";
|
|
@@ -10645,7 +10645,7 @@ function formatTickLabel(value2, resolvedScale) {
|
|
|
10645
10645
|
const temporalFmt = buildTemporalFormatter(formatStr);
|
|
10646
10646
|
if (temporalFmt) return temporalFmt(value2) + suffix;
|
|
10647
10647
|
const useUtc = resolvedScale.type === "utc";
|
|
10648
|
-
return formatDate(value2, void 0, void 0, useUtc) + suffix;
|
|
10648
|
+
return formatDate(value2, void 0, void 0, useUtc, compact) + suffix;
|
|
10649
10649
|
}
|
|
10650
10650
|
if (NUMERIC_SCALE_TYPES.has(resolvedScale.type)) {
|
|
10651
10651
|
const num = value2;
|
|
@@ -10672,7 +10672,7 @@ function continuousTicks(resolvedScale, density, targetCount) {
|
|
|
10672
10672
|
const count = axCfg?.tickCount ?? targetCount ?? TICK_COUNTS[density];
|
|
10673
10673
|
return buildContinuousTicks(resolvedScale, count);
|
|
10674
10674
|
}
|
|
10675
|
-
function buildContinuousTicks(resolvedScale, count) {
|
|
10675
|
+
function buildContinuousTicks(resolvedScale, count, compact = false) {
|
|
10676
10676
|
const scale = resolvedScale.scale;
|
|
10677
10677
|
if (!("ticks" in scale) || typeof scale.ticks !== "function") {
|
|
10678
10678
|
return continuousTicks(resolvedScale, "full");
|
|
@@ -10695,7 +10695,7 @@ function buildContinuousTicks(resolvedScale, count) {
|
|
|
10695
10695
|
return ticks2.map((value2) => ({
|
|
10696
10696
|
value: value2,
|
|
10697
10697
|
position: scale(value2),
|
|
10698
|
-
label: formatTickLabel(value2, resolvedScale)
|
|
10698
|
+
label: formatTickLabel(value2, resolvedScale, compact)
|
|
10699
10699
|
}));
|
|
10700
10700
|
}
|
|
10701
10701
|
function scaleSupportsTickCount(resolvedScale) {
|
|
@@ -10810,12 +10810,12 @@ function effectiveDensity(baseDensity, axisLength, minimalThreshold, reducedThre
|
|
|
10810
10810
|
var CONTINUOUS_TICK_FLOOR = 4;
|
|
10811
10811
|
var OVERSHOOT_TOLERANCE = 1.5;
|
|
10812
10812
|
var MIN_QUANTITATIVE_TICKS = 2;
|
|
10813
|
-
function ensureMinContinuousTicks(scale, ticks2, requestedCount) {
|
|
10813
|
+
function ensureMinContinuousTicks(scale, ticks2, requestedCount, compact = false) {
|
|
10814
10814
|
if (ticks2.length >= MIN_QUANTITATIVE_TICKS) return ticks2;
|
|
10815
10815
|
if (!scale || !scaleSupportsTickCount(scale)) return ticks2;
|
|
10816
10816
|
let best = ticks2;
|
|
10817
10817
|
for (let n = Math.max(requestedCount, MIN_QUANTITATIVE_TICKS) + 1; n <= 10; n++) {
|
|
10818
|
-
const candidate = buildContinuousTicks(scale, n);
|
|
10818
|
+
const candidate = buildContinuousTicks(scale, n, compact);
|
|
10819
10819
|
if (candidate.length >= MIN_QUANTITATIVE_TICKS) return candidate;
|
|
10820
10820
|
if (candidate.length > best.length) best = candidate;
|
|
10821
10821
|
}
|
|
@@ -10828,26 +10828,30 @@ function fitContinuousTicks(scale, initialTicks, initialCount, fontSize, fontWei
|
|
|
10828
10828
|
const overshoots = flooredTicks.length > tolerance;
|
|
10829
10829
|
const overlaps = ticksOverlap(flooredTicks, fontSize, fontWeight, measureText, orientation);
|
|
10830
10830
|
if (!overshoots && !overlaps) return flooredTicks;
|
|
10831
|
+
const useCompact = (scale.type === "time" || scale.type === "utc") && orientation === "horizontal";
|
|
10832
|
+
const fitsCleanly = (candidate) => candidate.length <= tolerance && !ticksOverlap(candidate, fontSize, fontWeight, measureText, orientation);
|
|
10833
|
+
if (useCompact) {
|
|
10834
|
+
const compactAtInitial = buildContinuousTicks(scale, initialCount, true);
|
|
10835
|
+
if (fitsCleanly(compactAtInitial)) return compactAtInitial;
|
|
10836
|
+
}
|
|
10831
10837
|
const minThreshold = orientation === "vertical" ? HEIGHT_MINIMAL_THRESHOLD : WIDTH_MINIMAL_THRESHOLD;
|
|
10832
10838
|
const floor = axisLength >= minThreshold ? CONTINUOUS_TICK_FLOOR : 2;
|
|
10833
10839
|
let bestWithinFloor;
|
|
10840
|
+
let bestWithinFloorCount;
|
|
10834
10841
|
for (let n = initialCount - 1; n >= 2; n--) {
|
|
10835
10842
|
const candidate = buildContinuousTicks(scale, n);
|
|
10836
|
-
|
|
10837
|
-
|
|
10838
|
-
|
|
10839
|
-
|
|
10840
|
-
|
|
10841
|
-
|
|
10842
|
-
|
|
10843
|
-
|
|
10844
|
-
if (!candidateOvershoots && !candidateOverlaps) {
|
|
10845
|
-
return candidate;
|
|
10843
|
+
if (fitsCleanly(candidate)) return candidate;
|
|
10844
|
+
if (useCompact) {
|
|
10845
|
+
const compact = buildContinuousTicks(scale, n, true);
|
|
10846
|
+
if (fitsCleanly(compact)) return compact;
|
|
10847
|
+
}
|
|
10848
|
+
if (candidate.length >= floor) {
|
|
10849
|
+
bestWithinFloor = candidate;
|
|
10850
|
+
bestWithinFloorCount = n;
|
|
10846
10851
|
}
|
|
10847
|
-
if (candidate.length >= floor) bestWithinFloor = candidate;
|
|
10848
10852
|
}
|
|
10849
|
-
const rawFallback = bestWithinFloor ?? buildContinuousTicks(scale, floor);
|
|
10850
|
-
const fallback = ensureMinContinuousTicks(scale, rawFallback, floor);
|
|
10853
|
+
const rawFallback = useCompact ? buildContinuousTicks(scale, bestWithinFloorCount ?? floor, true) : bestWithinFloor ?? buildContinuousTicks(scale, floor);
|
|
10854
|
+
const fallback = ensureMinContinuousTicks(scale, rawFallback, floor, useCompact);
|
|
10851
10855
|
return thinTicksUntilFit(fallback, fontSize, fontWeight, measureText, orientation);
|
|
10852
10856
|
}
|
|
10853
10857
|
function applyBandLabelStride(ticks2, stride) {
|