MCPcopy Index your code
hub / github.com/tensorflow/tfjs-examples / createFoundCard

Function createFoundCard

electron/renderer.js:175–216  ·  view source on GitHub ↗

* Create and material-design card for a search match and add * it to the root div for search results.

(rootDiv, foundItem)

Source from the content-addressed store, hash-verified

173 * it to the root div for search results.
174 */
175function createFoundCard(rootDiv, foundItem) {
176 const cardDiv = document.createElement('div');
177 cardDiv.classList.add('mdl-card');
178 cardDiv.classList.add('mdl-shadow--2dp');
179 cardDiv.classList.add('search-result');
180
181 const titleDiv = document.createElement('div');
182 titleDiv.classList.add('mdl-card__title');
183 titleDiv.textContent = foundItem.matchWord;
184 cardDiv.appendChild(titleDiv);
185
186 const imgDiv = document.createElement('img');
187 imgDiv.classList.add('search-result-thumbnail');
188 imgDiv.src = `file://${foundItem.filePath}`;
189 cardDiv.appendChild(imgDiv);
190
191 const pathDiv = document.createElement('div');
192 pathDiv.classList.add('mdl-card--border');
193 pathDiv.classList.add('search-result-file-path');
194 pathDiv.textContent = limitStringToLength(foundItem.filePath);
195 cardDiv.appendChild(pathDiv);
196
197 const topKDiv = document.createElement('div');
198 topKDiv.classList.add('mdl-card--border');
199 topKDiv.classList.add('search-result-top-k');
200 const ul = document.createElement('ul');
201 for (const classNameAndProb of foundItem.topClasses) {
202 const li = document.createElement('li');
203 if (classNameAndProb.prob >= 0.001) {
204 li.textContent =
205 `${classNameAndProb.className}: ${classNameAndProb.prob.toFixed(3)}`;
206 ul.appendChild(li);
207 }
208 }
209 topKDiv.appendChild(ul);
210 cardDiv.appendChild(topKDiv);
211
212 rootDiv.insertBefore(cardDiv, rootDiv.firstChild);
213 cardDiv.scrollIntoView();
214
215 updateClearSearchResultsButtonStatus();
216}
217
218const clearSearchResultsButton =
219 document.getElementById('clear-search-results');

Callers 1

displaySearchResultsFunction · 0.85

Calls 2

limitStringToLengthFunction · 0.85

Tested by

no test coverage detected