ketr.photos/clusters-pre
James Ketrenos 8bb980123e Improved output while clustering
Signed-off-by: James Ketrenos <james_gitlab@ketrenos.com>
2020-01-11 19:26:40 -08:00

100 lines
2.5 KiB
Plaintext

<html>
<script>'<base href="BASEPATH">';</script>
<script>
function loadMore(index) {
var clusterBlock = document.body.querySelector("[cluster-index='" + index + "']");
if (!clusterBlock) {
return;
}
var faces = clusterBlock.querySelectorAll("div.face").length, i
for (i = faces; i < clusters[index].length; i++) {
if (i - faces > 10) {
return;
}
var tuple = clusters[index][i],
face = createFace(tuple[0], tuple[1]);
clusterBlock.appendChild(face);
}
if (i == clusters[index].length) {
var span = clusterBlock.querySelector("span.more");
if (span) {
span.parentElement.removeChild(span);
}
}
}
function createFace(faceId, photoId) {
var div = document.createElement("div");
div.classList.add("face");
div.setAttribute("photo-id", photoId);
div.style.backgroundImage = "url(face-data/" + (faceId % 100) + "/" + faceId + "-original.png)";
div.addEventListener("click", (event) => {
let photoId = parseInt(event.currentTarget.getAttribute("photo-id"));
if (photoId) {
window.open("face-explorer.html?" + photoId, "photo-" + photoId);
} else {
alert("No photo id mapped to face.");
}
});
return div;
}
document.addEventListener("DOMContentLoaded", (event) => {
var div = document.createElement("div");
div.textContent = "There are " + clusters.length + " clusters.";
document.body.appendChild(div);
clusters.sort((a, b) => { return b.length - a.length });
clusters.forEach((cluster, clusterIndex) => {
var clusterBlock = document.createElement("div");
clusterBlock.setAttribute("cluster-index", clusterIndex);
document.body.appendChild(clusterBlock);
var div = document.createElement("div");
var html = "Cluster " + (clusterIndex + 1) + " has " + cluster.length + " neighbors.";
if (cluster.length > 10) {
html += " <span class='more' onClick='loadMore(" + clusterIndex + ")'>more</a>";
}
div.innerHTML = html;
clusterBlock.appendChild(div);
cluster.forEach((tuple, index) => {
if (index >= 10) {
return;
}
var face = createFace(tuple[0], tuple[1]);
clusterBlock.appendChild(face);
});
});
});
</script>
<style>
body {
margin: 0;
padding: 0;
}
.more {
cursor: pointer;
}
.more:hover {
text-decoration: underline;
}
.face {
width: 128px;
height: 128px;
background-size: contain;
background-position: center center;
display: inline-block;
border: 1px solid black;
margin: 0.5em;
cursor: pointer;
}
.face:hover {
box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.5);
}
</style>