feat: UX Changes

This commit is contained in:
Brennan Wilkes 2026-02-11 10:31:47 -08:00
parent 6d737d7c22
commit f912ce1ccc

View file

@ -914,10 +914,7 @@ export async function renderItem($app, skuInput) {
// --- Compute marker values --- // --- Compute marker values ---
// Province medians: per-store mean over time, then median across stores (>=3 stores) // Province medians: per-store mean over time, then median across stores (>=3 stores)
const storeMeans = seriesSorted const storeMeans = seriesSorted
.map((s) => ({ .map((s) => ({ label: s.label, mean: weightedMeanByDuration(s.points, labels) }))
label: s.label,
mean: weightedMeanByDuration(s.points, labels), // duration-weighted
}))
.filter((x) => Number.isFinite(x.mean)); .filter((x) => Number.isFinite(x.mean));
const bcMeans = storeMeans.filter((x) => isBcStoreLabel(x.label)); const bcMeans = storeMeans.filter((x) => isBcStoreLabel(x.label));
@ -936,15 +933,24 @@ export async function renderItem($app, skuInput) {
} }
// Target price: pick 3 lowest per-store mins (distinct stores), then average (>=3 stores) // Target price: pick 3 lowest per-store mins (distinct stores), then average (>=3 stores)
// Only show if there are at least 6 total unique price points (finite) across the chart.
const uniquePricePoints = new Set(
allVals
.filter((v) => Number.isFinite(v))
.map((v) => Math.round(v * 100)) // cents to avoid float noise
);
const hasEnoughUniquePoints = uniquePricePoints.size >= 6;
const storeMins = seriesSorted const storeMins = seriesSorted
.map((s) => ({ label: s.label, min: minFinite(s.values) })) .map((s) => ({ label: s.label, min: minFinite(s.values) }))
.filter((x) => Number.isFinite(x.min)) .filter((x) => Number.isFinite(x.min))
.sort((a, b) => a.min - b.min); .sort((a, b) => a.min - b.min);
if (storeMins.length >= 3) { if (hasEnoughUniquePoints && storeMins.length >= 3) {
const t = (storeMins[0].min + storeMins[1].min + storeMins[2].min) / 3; const t = (storeMins[0].min + storeMins[1].min + storeMins[2].min) / 3;
if (Number.isFinite(t)) markers.push({ y: Math.round(t), text: "Target" }); if (Number.isFinite(t)) markers.push({ y: Math.round(t), text: "Target" });
} }
const markerYs = markers.map((m) => Number(m.y)).filter(Number.isFinite); const markerYs = markers.map((m) => Number(m.y)).filter(Number.isFinite);
// helper: approximate font px size from a CSS font string (Chart uses one) // helper: approximate font px size from a CSS font string (Chart uses one)