mirror of
https://github.com/samsonjs/spirit-tracker.git
synced 2026-04-27 15:07:43 +00:00
UX Improvements
This commit is contained in:
parent
ae1d98612a
commit
952a6c6aba
1 changed files with 19 additions and 11 deletions
|
|
@ -438,9 +438,8 @@ function computeSeriesFromRaw(raw, filter) {
|
||||||
|
|
||||||
/* ---------------- y-axis bounds ---------------- */
|
/* ---------------- y-axis bounds ---------------- */
|
||||||
|
|
||||||
function computeYBounds(seriesByStore, defaultAbs) {
|
function computeYBounds(seriesByStore, minSpan = 6, pad = 1) {
|
||||||
let mn = Infinity;
|
let mn = Infinity, mx = -Infinity;
|
||||||
let mx = -Infinity;
|
|
||||||
|
|
||||||
for (const arr of Object.values(seriesByStore || {})) {
|
for (const arr of Object.values(seriesByStore || {})) {
|
||||||
if (!Array.isArray(arr)) continue;
|
if (!Array.isArray(arr)) continue;
|
||||||
|
|
@ -451,13 +450,24 @@ function computeYBounds(seriesByStore, defaultAbs) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mn === Infinity) return { min: -defaultAbs, max: defaultAbs };
|
if (mn === Infinity) return { min: -minSpan / 2, max: minSpan / 2 };
|
||||||
|
|
||||||
const min = Math.min(-defaultAbs, Math.floor(mn));
|
// pad a bit so lines aren't glued to edges
|
||||||
const max = Math.max(defaultAbs, Math.ceil(mx));
|
mn = Math.floor(mn - pad);
|
||||||
return { min, max };
|
mx = Math.ceil(mx + pad);
|
||||||
|
|
||||||
|
// enforce a minimum visible range so it doesn't get *too* tight
|
||||||
|
const span = mx - mn;
|
||||||
|
if (span < minSpan) {
|
||||||
|
const mid = (mn + mx) / 2;
|
||||||
|
mn = Math.floor(mid - minSpan / 2);
|
||||||
|
mx = Math.ceil(mid + minSpan / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return { min: mn, max: mx };
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ---------------- prefs ---------------- */
|
/* ---------------- prefs ---------------- */
|
||||||
|
|
||||||
const LS_GROUP = "stviz:v1:stats:group";
|
const LS_GROUP = "stviz:v1:stats:group";
|
||||||
|
|
@ -842,8 +852,7 @@ export async function renderStats($app) {
|
||||||
maxPrice: selectedMaxPrice,
|
maxPrice: selectedMaxPrice,
|
||||||
});
|
});
|
||||||
|
|
||||||
const abs = group === "all" ? 12 : 8;
|
const yBounds = computeYBounds(series.seriesByStore, group === "all" ? 8 : 6, 1);
|
||||||
const yBounds = computeYBounds(series.seriesByStore, abs);
|
|
||||||
|
|
||||||
await drawOrUpdateChart(series, yBounds);
|
await drawOrUpdateChart(series, yBounds);
|
||||||
|
|
||||||
|
|
@ -878,8 +887,7 @@ export async function renderStats($app) {
|
||||||
maxPrice: selectedMaxPrice,
|
maxPrice: selectedMaxPrice,
|
||||||
});
|
});
|
||||||
|
|
||||||
const abs = group === "all" ? 12 : 8;
|
const yBounds = computeYBounds(series.seriesByStore, group === "all" ? 8 : 6, 1);
|
||||||
const yBounds = computeYBounds(series.seriesByStore, abs);
|
|
||||||
|
|
||||||
await drawOrUpdateChart(series, yBounds);
|
await drawOrUpdateChart(series, yBounds);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue