transition = {
let lastSelected
let lastProjection = umapProjection
let timer
let similarsMap
let canvas
let animationFinished = false
let similars
return async function(selected, distance, that){
if(distance >= snappyDistance) selected = null
if(lastSelected === selected) return
if(!canvas) canvas = d3.select(that)
canvas.style("cursor", distance >= snappyDistance ? "default" : "pointer")
const alted = d3.event.altKey
canvas.on("click", () => {
console.log("click", selected)
if(selected){
const transform = d3.zoomTransform(that)
if(transform.k >= zoomBarrier){
console.log("animate!")
if(animationFinished) {
lastProjection = umapProjection
d3.selection()
.interrupt()
transitionIntoList(selected,similarsMap,similars, lastProjection, that)
mutable state = 2
}
} else {
canvas
.transition()
.duration(1000)
.call(zoom.scaleTo, zoomBarrier, transform.apply([selected.x, selected.y]))
}
} else {
canvas
.transition()
.duration(200)
.call(
zoom.transform,
d3.zoomIdentity
.translate(0,0)
.scale(1)
);
}
})
animationFinished = false
// create similar map
if(selected){
similars = await getImageDistancesForId(selected.id)
//console.log(similars)
similarsMap = new Map(similars.map(d => [d.id, d]))
}
if(selected && alted) {
lastProjection = umapProjection.map(d => {
const similar = similarsMap.get(d.id)
const alpha = similar.score > scoreCutoff ? 1 : 0.1
const active = selected.id == d.id
return { ...d, scale: active ? scale * 2 : scale, zIndex: active ? 1 : 0, alpha }
})
project(lastProjection)
return
}
const transform = d3.zoomTransform(that)
if(transform.k !== zoomBarrier){
return
}
d3.selection()
.interrupt()
.transition()
.duration(200)
//.ease(d3.easePolyInOut)
.tween("close", function() {
const newProjection = umapProjection.map(d => {
const active = selected ? selected.id == d.id : false
return { ...d, scale: active ? scale * 1.2 : d.scale }
})
const interpolate = d3.interpolate(lastProjection, newProjection)
return function(t) {
lastProjection = interpolate(t)
project(lastProjection)
};
})
.filter(() => distance < snappyDistance)
.transition()
//.delay(30)
.delay(100)
.duration(700)
.ease(d3.easeExpIn)
.tween("open", function() {
const newProjection = lastProjection.map(d => {
const active = selected.id == d.id
return { ...d, scale: active ? scale * 2 : scale, zIndex: active ? 1 : 0 }
})
const interpolate = d3.interpolate(lastProjection, newProjection)
return function(t) {
lastProjection = interpolate(t)
project(lastProjection)
};
})
.transition()
.duration(0)
.tween("appear", function() {
const newProjection = lastProjection.map(d => {
const similar = similarsMap.get(d.id)
const alpha = similar.score > scoreCutoff ? 1 : 0.1
return { ...d, alpha }
})
const interpolate = d3.interpolate(lastProjection, newProjection)
return function(t) {
lastProjection = interpolate(t)
project(lastProjection)
};
})
.on("end", () => { animationFinished = true })
renderer.render(container)
lastSelected = selected
}
//asdasasd
}