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

Function setupMnistSampleButtons

assets/main.js:133–170  ·  view source on GitHub ↗
({ digitCanvas, onSampleApplied, manifestPath } = {})

Source from the content-addressed store, hash-verified

131}
132
133async function setupMnistSampleButtons({ digitCanvas, onSampleApplied, manifestPath } = {}) {
134 if (!digitCanvas || typeof digitCanvas.setPixels !== "function") return null;
135 const interactionRow =
136 typeof digitCanvas.getInteractionRow === "function" ? digitCanvas.getInteractionRow() : null;
137 const gridElement =
138 typeof digitCanvas.getGridElement === "function" ? digitCanvas.getGridElement() : null;
139 if (!interactionRow || !gridElement) return null;
140 let loader;
141 try {
142 loader = await loadMnistTestSamples(manifestPath ?? MNIST_SAMPLE_MANIFEST_URL);
143 } catch (error) {
144 console.warn("MNIST-Testdaten konnten nicht geladen werden:", error);
145 return null;
146 }
147 const column = document.createElement("div");
148 column.className = "digit-button-column";
149 for (let digit = 0; digit < 10; digit += 1) {
150 const button = document.createElement("button");
151 button.type = "button";
152 button.className = "digit-button";
153 button.textContent = String(digit);
154 button.setAttribute("aria-label", `Zufällige ${digit} laden`);
155 button.addEventListener("click", () => {
156 const sample = loader.getRandomSample(digit);
157 if (!sample) return;
158 digitCanvas.setPixels(sample.pixels);
159 if (typeof onSampleApplied === "function") {
160 onSampleApplied(sample);
161 }
162 });
163 column.appendChild(button);
164 }
165 interactionRow.appendChild(column);
166 return {
167 loader,
168 column,
169 };
170}
171
172async function initializeVisualizer() {
173 initializeInfoDialog();

Callers 1

initializeVisualizerFunction · 0.85

Calls 4

loadMnistTestSamplesFunction · 0.85
getInteractionRowMethod · 0.80
getGridElementMethod · 0.80
setPixelsMethod · 0.80

Tested by

no test coverage detected