@opendata-ai/openchart-engine 6.27.0 → 6.27.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 +40 -10
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/axes.test.ts +101 -3
- package/src/annotations/__tests__/compute.test.ts +175 -0
- package/src/annotations/position.ts +37 -1
- package/src/annotations/resolve-range.ts +5 -5
- package/src/charts/bar/__tests__/compute.test.ts +102 -0
- package/src/charts/bar/compute.ts +1 -0
- package/src/layout/axes/ticks.ts +31 -4
- package/src/layout/axes.ts +9 -2
package/dist/index.js
CHANGED
|
@@ -3692,6 +3692,22 @@ function resolvePosition(value2, scale) {
|
|
|
3692
3692
|
}
|
|
3693
3693
|
return null;
|
|
3694
3694
|
}
|
|
3695
|
+
function resolvePositionEdge(value2, scale, edge) {
|
|
3696
|
+
const center2 = resolvePosition(value2, scale);
|
|
3697
|
+
if (center2 === null || !scale) return null;
|
|
3698
|
+
const type = scale.type;
|
|
3699
|
+
if (type === "point") {
|
|
3700
|
+
const s = scale.scale;
|
|
3701
|
+
const halfStep = (s.step?.() ?? 0) / 2;
|
|
3702
|
+
return edge === "start" ? center2 - halfStep : center2 + halfStep;
|
|
3703
|
+
}
|
|
3704
|
+
if (type === "band") {
|
|
3705
|
+
const s = scale.scale;
|
|
3706
|
+
const halfBw = (s.bandwidth?.() ?? 0) / 2;
|
|
3707
|
+
return edge === "start" ? center2 - halfBw : center2 + halfBw;
|
|
3708
|
+
}
|
|
3709
|
+
return center2;
|
|
3710
|
+
}
|
|
3695
3711
|
|
|
3696
3712
|
// src/annotations/collisions.ts
|
|
3697
3713
|
function generateNudgeCandidates(selfBounds, obstacles, padding) {
|
|
@@ -3924,15 +3940,15 @@ function resolveRangeAnnotation(annotation, scales, chartArea, isDark) {
|
|
|
3924
3940
|
let width = chartArea.width;
|
|
3925
3941
|
let height = chartArea.height;
|
|
3926
3942
|
if (annotation.x1 !== void 0 && annotation.x2 !== void 0) {
|
|
3927
|
-
const x1px =
|
|
3928
|
-
const x2px =
|
|
3943
|
+
const x1px = resolvePositionEdge(annotation.x1, scales.x, "start");
|
|
3944
|
+
const x2px = resolvePositionEdge(annotation.x2, scales.x, "end");
|
|
3929
3945
|
if (x1px === null || x2px === null) return null;
|
|
3930
3946
|
x2 = Math.min(x1px, x2px);
|
|
3931
3947
|
width = Math.abs(x2px - x1px);
|
|
3932
3948
|
}
|
|
3933
3949
|
if (annotation.y1 !== void 0 && annotation.y2 !== void 0) {
|
|
3934
|
-
const y1px =
|
|
3935
|
-
const y2px =
|
|
3950
|
+
const y1px = resolvePositionEdge(annotation.y1, scales.y, "end");
|
|
3951
|
+
const y2px = resolvePositionEdge(annotation.y2, scales.y, "start");
|
|
3936
3952
|
if (y1px === null || y2px === null) return null;
|
|
3937
3953
|
y2 = Math.min(y1px, y2px);
|
|
3938
3954
|
height = Math.abs(y2px - y1px);
|
|
@@ -8233,9 +8249,9 @@ import {
|
|
|
8233
8249
|
formatNumber as formatNumber2
|
|
8234
8250
|
} from "@opendata-ai/openchart-core";
|
|
8235
8251
|
var Y_PX_PER_TICK = {
|
|
8236
|
-
full:
|
|
8237
|
-
reduced:
|
|
8238
|
-
minimal:
|
|
8252
|
+
full: 40,
|
|
8253
|
+
reduced: 70,
|
|
8254
|
+
minimal: 120
|
|
8239
8255
|
};
|
|
8240
8256
|
var X_PX_PER_TICK = {
|
|
8241
8257
|
full: 110,
|
|
@@ -8313,7 +8329,21 @@ function buildContinuousTicks(resolvedScale, count) {
|
|
|
8313
8329
|
return continuousTicks(resolvedScale, "full");
|
|
8314
8330
|
}
|
|
8315
8331
|
const raw = scale.ticks(count);
|
|
8316
|
-
|
|
8332
|
+
let ticks2 = raw;
|
|
8333
|
+
if (resolvedScale.type === "log" && raw.length > count) {
|
|
8334
|
+
const base = resolvedScale.channel.scale?.base ?? 10;
|
|
8335
|
+
const logBase = Math.log(base);
|
|
8336
|
+
const powered = raw.filter((v) => {
|
|
8337
|
+
const n = v;
|
|
8338
|
+
if (n <= 0) return false;
|
|
8339
|
+
const exp = Math.log(n) / logBase;
|
|
8340
|
+
return Math.abs(exp - Math.round(exp)) < 1e-9;
|
|
8341
|
+
});
|
|
8342
|
+
if (powered.length >= 2) {
|
|
8343
|
+
ticks2 = powered;
|
|
8344
|
+
}
|
|
8345
|
+
}
|
|
8346
|
+
return ticks2.map((value2) => ({
|
|
8317
8347
|
value: value2,
|
|
8318
8348
|
position: scale(value2),
|
|
8319
8349
|
label: formatTickLabel(value2, resolvedScale)
|
|
@@ -8416,8 +8446,8 @@ function resolveExplicitTicks(values, resolvedScale) {
|
|
|
8416
8446
|
}
|
|
8417
8447
|
|
|
8418
8448
|
// src/layout/axes.ts
|
|
8419
|
-
var HEIGHT_MINIMAL_THRESHOLD =
|
|
8420
|
-
var HEIGHT_REDUCED_THRESHOLD =
|
|
8449
|
+
var HEIGHT_MINIMAL_THRESHOLD = 80;
|
|
8450
|
+
var HEIGHT_REDUCED_THRESHOLD = 100;
|
|
8421
8451
|
var WIDTH_MINIMAL_THRESHOLD = 150;
|
|
8422
8452
|
var WIDTH_REDUCED_THRESHOLD = 300;
|
|
8423
8453
|
var DENSITY_ORDER = ["full", "reduced", "minimal"];
|