fix: more intuitive min_bound_range behavior (#1136)

Now if one bound is defined but a soft bound, and there is no other bound defined, it treats it as a bound.

If both are soft bounds then it doesn't care.

And if the other bound is a hard bound, the soft one is breached.
This commit is contained in:
Fabio Critone
2025-01-02 21:19:16 +01:00
committed by GitHub
parent 25e6aea952
commit 54d987568b

View File

@@ -830,10 +830,22 @@ class MiniGraphCard extends LitElement {
// Doesn't matter if minBoundRange is NaN because this will be false if so
if (diff > 0) {
boundary = [
boundary[0] - diff / 2,
boundary[1] + diff / 2,
const weights = [
min !== undefined && min[0] !== '~' || max === undefined ? 0 : 1,
max !== undefined && max[0] !== '~' || min === undefined ? 0 : 1,
];
const sum = weights[0] + weights[1];
if (sum > 0) {
boundary = [
boundary[0] - diff * weights[0] / sum,
boundary[1] + diff * weights[1] / sum,
];
} else {
boundary = [
boundary[0] - diff / 2,
boundary[1] + diff / 2,
];
}
}
}