MCPcopy Create free account
hub / github.com/DFin/Neural-Network-Visualisation / setupTimelineSlider

Function setupTimelineSlider

assets/main.js:934–1043  ·  view source on GitHub ↗
(timelineSnapshots, options = {})

Source from the content-addressed store, hash-verified

932}
933
934function setupTimelineSlider(timelineSnapshots, options = {}) {
935 const overlay = document.getElementById("timelineOverlay");
936 const slider = document.getElementById("timelineSlider");
937 const summary = document.getElementById("timelineSummary");
938 const label = document.getElementById("timelineLabel");
939 const metricsElement = document.getElementById("timelineMetrics");
940
941 if (
942 !overlay ||
943 !slider ||
944 !summary ||
945 !label ||
946 !metricsElement ||
947 !Array.isArray(timelineSnapshots) ||
948 timelineSnapshots.length === 0
949 ) {
950 overlay?.classList.add("hidden");
951 if (slider) {
952 slider.disabled = true;
953 slider.value = "0";
954 }
955 if (summary) summary.textContent = "";
956 if (label) label.textContent = "";
957 if (metricsElement) metricsElement.textContent = "";
958 return null;
959 }
960
961 overlay.classList.remove("hidden");
962 slider.min = "0";
963 slider.max = String(Math.max(timelineSnapshots.length - 1, 0));
964 slider.step = "1";
965 slider.disabled = timelineSnapshots.length <= 1;
966
967 const state = {
968 activeIndex: null,
969 loading: false,
970 };
971
972 const setLoading = (value) => {
973 state.loading = Boolean(value);
974 if (state.loading) {
975 slider.disabled = true;
976 overlay.classList.add("timeline-overlay--loading");
977 } else {
978 slider.disabled = timelineSnapshots.length <= 1;
979 overlay.classList.remove("timeline-overlay--loading");
980 }
981 };
982
983 const applySnapshotChange = async (snapshot, safeIndex) => {
984 if (typeof options.onSnapshotChange !== "function") return;
985 setLoading(true);
986 try {
987 await options.onSnapshotChange(snapshot, safeIndex);
988 } finally {
989 setLoading(false);
990 }
991 };

Callers 1

initializeVisualizerFunction · 0.85

Calls 1

setActiveIndexFunction · 0.85

Tested by

no test coverage detected