diff --git a/src/routes/graphs/+page.svelte b/src/routes/graphs/+page.svelte index 6d1aaea..4208fba 100644 --- a/src/routes/graphs/+page.svelte +++ b/src/routes/graphs/+page.svelte @@ -44,9 +44,22 @@ fetchData('pressure', from, to, size).then((resp) => (pressureData = resp?.data)); } - + function scrollSelectedButtonIntoView() { + const container = document.getElementsByClassName('button-wrapper')[0]; + const selected = document.getElementsByClassName('selected')[0] as HTMLElement; + const containerWidth = container.getBoundingClientRect().width; + const selectedWidth = selected.getBoundingClientRect().width; - reload(minutes)} /> + // if the container is in-view, return + if (containerWidth > selected.offsetLeft) { + return; + } + + container.scrollLeft = selected.offsetLeft - selectedWidth / 2; + } + + onMount(scrollSelectedButtonIntoView); +