chart = {
const zoom = d3.zoom()
.scaleExtent([0.5, 32])
.on("zoom", zoomed);
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
const gGrid = svg.append("g");
const x = d3.scaleLinear()
.domain([extent_x[0]-3, extent_x[1]+3])
.range([0, width])
const y = d3.scaleLinear()
.domain([(extent_y[0] * k)-3, (extent_y[1] * k)+3])
.range([height, 0])
const z = d3.scaleOrdinal()
.domain(umap_embedding2.map(d => d[sel_col]))
.range(d3.schemeTableau10)
const yAxis = (g, y) => g
.call(d3.axisRight(y).ticks(12 * k))
.call(g => g.select(".domain").attr("display", "none"))
const xAxis = (g, x) => g
.attr("transform", `translate(0,${height})`)
const gDot = svg.append("g")
.attr("fill", "none")
.attr("class", "circles")
.attr("stroke-linecap", "round");
gDot.append("style").text(`
.circles {
stroke: transparent;
stroke-width: 0.1px;
}
.circles circle:hover {
stroke: black;
}
`);
gDot.selectAll("circle")
.data(umap_embedding2)
.join("circle")
.attr("cx", d => x(d.x))
.attr("cy", d => y(d.y))
.attr("fill", d => sel_field === "" ? z(d[sel_col]) : 'grey')
.attr("opacity", d => sel_field === "" ? 0.5 : 0.3)
.attr("r", 1.5)
.append("title")
.text(d => `${d.title} (${d.field})\n# citations: ${d.citationCount}\nYear: ${d.year}\ntopic: ${d.topic}`);;
const gDotF = svg.append("g")
.attr("fill", "none")
.attr("class", "circles")
.attr("stroke-linecap", "round");
gDotF.append("style").text(`
.circles {
stroke: transparent;
stroke-width: 0.1px;
}
.circles circle:hover {
stroke: black;
}
`);
if (sel_field !== '') {
gDotF.selectAll("circle")
.data(field_data)
.join("circle")
.attr("cx", d => x(d.x))
.attr("cy", d => y(d.y))
.attr("fill", d => sel_field === "" ? 'black' : 'red')
.attr("opacity", d => sel_field === "" ? 0 : 0.4)
.attr("r", 1.5)
.append("title")
.text(d => `${d.title} (${d.field})\n# citations: ${d.citationCount}\nYear: ${d.year}\ntopic: ${d.topic}`);
}
const gx = svg.append("g");
const gy = svg.append("g");
svg.call(zoom).call(zoom.transform, d3.zoomIdentity);
function zoomed({transform}) {
const zx = transform.rescaleX(x).interpolate(d3.interpolateRound);
const zy = transform.rescaleY(y).interpolate(d3.interpolateRound);
gDot.attr("transform", transform).attr("stroke-width", 2 / transform.k);
gDotF.attr("transform", transform).attr("stroke-width", 2 / transform.k);
gx.call(xAxis, zx);
gy.call(yAxis, zy);
gGrid.call(grid, zx, zy);
}
const tooltip = d3
.select("body")
.append("div")
.style("position", "absolute")
.style("visibility", "hidden")
.style("opacity", 0.9)
.style("background", "white");
// sel_field === '' ? gDot.call(Tooltips, tooltip) : gDotF.call(Tooltips, tooltip)
return Object.assign(svg.node(), {
reset() {
svg.transition()
.duration(750)
.call(zoom.transform, d3.zoomIdentity);
}
});
}