diff --git a/viz/app/item_page.js b/viz/app/item_page.js index b034c9d..486021f 100644 --- a/viz/app/item_page.js +++ b/viz/app/item_page.js @@ -67,18 +67,25 @@ function computeSuggestedY(values) { const nums = values.filter((v) => Number.isFinite(v)); if (!nums.length) return { suggestedMin: undefined, suggestedMax: undefined }; - let min = nums[0], - max = nums[0]; + let min = nums[0], max = nums[0]; for (const n of nums) { if (n < min) min = n; if (n > max) max = n; } - if (min === max) return { suggestedMin: min * 0.95, suggestedMax: max * 1.05 }; - const pad = (max - min) * 0.08; - return { suggestedMin: Math.max(0, min - pad), suggestedMax: max + pad }; + const range = max - min; + const pad = range === 0 ? Math.max(1, min * 0.05) : range * 0.08; + + const rawMin = Math.max(0, min - pad); + const rawMax = max + pad; + + const suggestedMin = Math.floor(rawMin / 10) * 10; + const suggestedMax = Math.ceil(rawMax / 10) * 10; + + return { suggestedMin, suggestedMax }; } + function cacheKeySeries(sku, dbFile, cacheBust) { return `stviz:v3:series:${cacheBust}:${sku}:${dbFile}`; } @@ -534,7 +541,13 @@ export async function renderItem($app, skuInput) { }, scales: { x: { ticks: { maxRotation: 0, autoSkip: true, maxTicksLimit: 12 }, grid: { display: false } }, - y: { ...ySug, ticks: { callback: (v) => `$${Number(v).toFixed(0)}` } }, + y: { + ...ySug, + ticks: { + stepSize: 10, + callback: (v) => `$${Number(v).toFixed(0)}`, + }, + }, }, }, }); diff --git a/viz/app/linker_page.js b/viz/app/linker_page.js index af7e6c9..1a2349d 100644 --- a/viz/app/linker_page.js +++ b/viz/app/linker_page.js @@ -22,6 +22,7 @@ import { addPendingIgnore, pendingCounts, movePendingToSubmitted, + clearPendingEdits, } from "./pending.js"; /* ---------------- Similarity helpers ---------------- */ @@ -51,7 +52,6 @@ function smwsKeyFromName(name) { return m ? m[1] : ""; } - function isNumberToken(t) { return /^\d+$/.test(String(t || "")); } @@ -131,10 +131,9 @@ function similarityScore(aName, bName) { const gate = firstMatch ? 1.0 : 0.12; const numGate = numberMismatchPenalty(aToks, bToks); - return numGate * ( - firstMatch * 3.0 + - overlapTail * 2.2 * gate + - levSim * (firstMatch ? 1.0 : 0.15) + return ( + numGate * + (firstMatch * 3.0 + overlapTail * 2.2 * gate + levSim * (firstMatch ? 1.0 : 0.15)) ); } @@ -198,7 +197,7 @@ function buildMappedSkuSet(links) { function isBCStoreLabel(label) { const s = String(label || "").toLowerCase(); - return s.includes("bcl") || s.includes("strath")|| s.includes("gull")|| s.includes("legacy"); + return s.includes("bcl") || s.includes("strath") || s.includes("gull") || s.includes("legacy"); } function skuIsBC(allRows, skuKey) { @@ -304,8 +303,7 @@ function topSuggestions(allAgg, limit, otherPinnedSku, mappedSkus) { } function recommendSimilar(allAgg, pinned, limit, otherPinnedSku, mappedSkus, isIgnoredPairFn) { - if (!pinned || !pinned.name) - return topSuggestions(allAgg, limit, otherPinnedSku, mappedSkus); + if (!pinned || !pinned.name) return topSuggestions(allAgg, limit, otherPinnedSku, mappedSkus); const base = String(pinned.name || ""); const pinnedSku = String(pinned.sku || ""); @@ -319,7 +317,10 @@ function recommendSimilar(allAgg, pinned, limit, otherPinnedSku, mappedSkus, isI if (otherPinnedSku && String(it.sku) === String(otherPinnedSku)) continue; if (storesOverlap(pinned, it)) continue; - if (typeof isIgnoredPairFn === "function" && isIgnoredPairFn(pinnedSku, String(it.sku || ""))) + if ( + typeof isIgnoredPairFn === "function" && + isIgnoredPairFn(pinnedSku, String(it.sku || "")) + ) continue; // SMWS exact NUM.NUM match => force to top (requires SMWS + code match) @@ -348,7 +349,6 @@ function recommendSimilar(allAgg, pinned, limit, otherPinnedSku, mappedSkus, isI return scored.slice(0, limit).map((x) => x.it); } - function computeInitialPairsFast(allAgg, mappedSkus, limitPairs, isIgnoredPairFn) { const itemsAll = allAgg.filter((it) => !!it); @@ -396,7 +396,10 @@ function computeInitialPairsFast(allAgg, mappedSkus, limitPairs, isIgnoredPairFn if (!arr0 || arr0.length < 2) continue; // Bound bucket size - const arr = arr0.slice().sort((a, b) => itemRank(b) - itemRank(a)).slice(0, 80); + const arr = arr0 + .slice() + .sort((a, b) => itemRank(b) - itemRank(a)) + .slice(0, 80); const mapped = []; const unmapped = []; @@ -407,8 +410,9 @@ function computeInitialPairsFast(allAgg, mappedSkus, limitPairs, isIgnoredPairFn } // Pick best anchor (prefer mapped if available) - const anchor = - (mapped.length ? mapped : unmapped).slice().sort((a, b) => itemRank(b) - itemRank(a))[0]; + const anchor = (mapped.length ? mapped : unmapped) + .slice() + .sort((a, b) => itemRank(b) - itemRank(a))[0]; if (!anchor) continue; @@ -479,7 +483,9 @@ function computeInitialPairsFast(allAgg, mappedSkus, limitPairs, isIgnoredPairFn const itemNormName = new Map(); for (const it of work) { - const toks = Array.from(new Set(tokenizeQuery(it.name || ""))).filter(Boolean).slice(0, 10); + const toks = Array.from(new Set(tokenizeQuery(it.name || ""))) + .filter(Boolean) + .slice(0, 10); itemTokens.set(it.sku, toks); itemNormName.set(it.sku, normSearchText(it.name || "")); for (const t of toks) { @@ -573,7 +579,6 @@ function computeInitialPairsFast(allAgg, mappedSkus, limitPairs, isIgnoredPairFn return out.slice(0, limitPairs); } - /* ---------------- Page ---------------- */ export async function renderSkuLinker($app) { @@ -585,6 +590,12 @@ export async function renderSkuLinker($app) {