website: redesign part 14

This commit is contained in:
nym21
2026-06-07 01:05:04 +02:00
parent c68d1d1fda
commit 9fc45625ad
7 changed files with 34 additions and 23 deletions
+9 -9
View File
@@ -71,22 +71,22 @@ async function loadSeries(chart, timeframe) {
/** @param {Chart} chart */
function createLoadedSeriesCache(chart) {
/** @type {Map<TimeframeValue, Promise<LoadedSeries[]>>} */
const cache = new Map();
/** @type {TimeframeValue | undefined} */
let cachedTimeframe;
/** @type {Promise<LoadedSeries[]> | undefined} */
let cachedPromise;
/** @param {TimeframeValue} timeframe */
return function getLoadedSeries(timeframe) {
let promise = cache.get(timeframe);
if (!promise) {
promise = loadSeries(chart, timeframe).catch((error) => {
cache.delete(timeframe);
if (timeframe !== cachedTimeframe || !cachedPromise) {
cachedTimeframe = timeframe;
cachedPromise = loadSeries(chart, timeframe).catch((error) => {
if (timeframe === cachedTimeframe) cachedPromise = undefined;
throw error;
});
cache.set(timeframe, promise);
}
return promise;
return cachedPromise;
};
}
+2
View File
@@ -74,6 +74,8 @@ export function createScrubber(svg, readout, highlight) {
* @param {boolean} [scrubbing]
*/
function update(ratio, scrubbing = true) {
if (!series.length) return;
const nextRatio = clamp(ratio, 0, 1);
const points = series.map((item) => getPointAtRatio(item, nextRatio));
const x = points[0].x.toFixed(2);
+12 -8
View File
@@ -18,10 +18,18 @@ function scrollToTarget(target, behavior) {
target.scrollIntoView({ behavior, block: "start" });
}
/**
* @param {HTMLElement} main
* @param {ScrollBehavior} behavior
*/
function scrollToCurrentHash(main, behavior) {
const target = getHashTarget(main, window.location.hash);
if (target) scrollToTarget(target, behavior);
}
/** @param {HTMLElement} main */
export function initHashLinks(main) {
const initialHash = window.location.hash;
main.addEventListener("click", (event) => {
if (!isPlainLeftClick(event)) return;
@@ -45,12 +53,8 @@ export function initHashLinks(main) {
window.addEventListener("popstate", () => {
if (main.hidden) return;
const target = getHashTarget(main, window.location.hash);
if (target) scrollToTarget(target, "auto");
scrollToCurrentHash(main, "auto");
});
requestAnimationFrame(() => {
const target = getHashTarget(main, initialHash);
if (target) scrollToTarget(target, "auto");
});
main.addEventListener("pageactive", () => scrollToCurrentHash(main, "auto"));
}