mirror of
https://github.com/kalkih/mini-graph-card.git
synced 2025-12-20 00:35:56 +01:00
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:
18
src/main.js
18
src/main.js
@@ -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,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user