Public
Edited
Nov 17, 2022
1 fork
3 stars
Insert cell
Insert cell
Insert cell
Insert cell
canvas = {
var elem = d3.create("div")
elem.call(zoom)
elem
.on("click", reset)
.on("mousemove", mousemove)
elem.append(() => renderer.view)
sprites;
renderer.resize(width,height);
container.sortableChildren = true
renderer.render(container)
return elem.node()
}
Insert cell
url = "https://vikusviewer.fh-potsdam.de/smb/beide/data/beide-similarity-image-norm-bit-space.csv"
Insert cell
umap = d3.csv(url, ({id,x,y}) => ({id, x: +x, y: +y}))
Insert cell
margin = ({top: 20, right: 20, bottom: 20, left: 20})
Insert cell
height = Math.ceil(width * screen.height / screen.width)
Insert cell
x = d3.scaleLinear()
.domain(d3.extent(umap, d => d.x)).nice()
.range([margin.left, width - margin.right])
Insert cell
y = d3.scaleLinear()
.domain(d3.extent(umap, d => d.y)).nice()
.range([height - margin.bottom, margin.top])
Insert cell
Insert cell
projection = umap.map(d => ({
id: d.id,
x: x(d.x),
y: y(d.y),
scale
}))
Insert cell
zoom = d3.zoom()
.scaleExtent([1, 50])
.translateExtent([[0,0],[width,height]])
.clickDistance(2)
.on("zoom", zoomed);
Insert cell
Insert cell
Insert cell
Insert cell
resetProjection = () => {
projection.forEach((d,i) => {
const s = sprites.get(d.id)
s.position.x = d.x
s.position.y = d.y
s.alpha = 1
s.scale.set(scale)
})
renderer.render(container)
}
Insert cell
project = {
let lastSelected
return async function(selected, distance){
if(distance > 4) { lastSelected = null; resetProjection(); return }
if(lastSelected == selected) return
const similars = (await getImageDistancesForId(selected.id)).slice(0,topNum)
projection.forEach((d,i) => {
const s = sprites.get(d.id)
s.zIndex = 0
s.position.x = d.x
s.position.y = d.y
s.alpha = 0.2
s.scale.set(scale)
})
similars.forEach((d,i) => {
const s = sprites.get(d.id)
const active = selected.id == d.id
s.zIndex = active ? 2 : 1
s.scale.set(active ? scale * 3 : scale * 1.7)
s.alpha = 1
})
renderer.render(container)
lastSelected = selected
}
}
Insert cell
function mousemove() {
const m = d3.mouse(this)
const p = d3.zoomTransform(this).invert(m)
const q = quadtree.find(p[0], p[1])
const distance = Math.hypot(p[0] - q.x, p[1] - q.y)
project(q, distance)
}
Insert cell
import { renderer, container, PIXI } from "@cpietsch/pixi-renderer"
Insert cell
import { getTextureStream, sprites } with {loadDelay as delay } from "68b54e3f54ebd551"
Insert cell
import {getDistancesForId as getImageDistancesForId} from "@cpietsch/distance-between-logit-vectors-to-show-related-images"
Insert cell
d3 = require("d3@5")
Insert cell
loadDelay = 0
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more