@opendata-ai/openchart-engine 2.12.0 → 2.12.2
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 +12 -12
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/axes.test.ts +32 -0
- package/src/annotations/compute.ts +6 -3
- package/src/layout/axes.ts +27 -31
package/dist/index.js
CHANGED
|
@@ -238,7 +238,7 @@ function resolveRangeAnnotation(annotation, scales, chartArea, isDark) {
|
|
|
238
238
|
const rect = { x: x2, y: y2, width, height };
|
|
239
239
|
let label;
|
|
240
240
|
if (annotation.label) {
|
|
241
|
-
const anchor = annotation.labelAnchor ?? "
|
|
241
|
+
const anchor = annotation.labelAnchor ?? "top";
|
|
242
242
|
const centered = anchor === "top" || anchor === "bottom" || anchor === "auto";
|
|
243
243
|
const baseDx = centered ? 0 : anchor === "right" ? -4 : 4;
|
|
244
244
|
const baseDy = 14;
|
|
@@ -6100,7 +6100,7 @@ function thinTicksUntilFit(ticks2, fontSize, fontWeight, measureText) {
|
|
|
6100
6100
|
}
|
|
6101
6101
|
return current;
|
|
6102
6102
|
}
|
|
6103
|
-
function continuousTicks(resolvedScale, density
|
|
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
|
-
|
|
6114
|
-
return thinTicksUntilFit(ticks2, fontSize, fontWeight, measureText);
|
|
6113
|
+
return ticks2;
|
|
6115
6114
|
}
|
|
6116
|
-
function categoricalTicks(resolvedScale, density
|
|
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
|
|
6191
|
-
const gridlines =
|
|
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
|
|
6220
|
-
const gridlines =
|
|
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)
|