Plot.plot({
color: {legend: true},
y: {
grid: true,
label: null,
tickSize: 0,
domain: topContributors
},
width: 1200,
marginLeft: 100,
marks: [
Plot.ruleY(alphaForumTable, Plot.groupY({x1: "min", x2: "max"}, {y:"author", x: "date"})),
Plot.dot(
alphaForumTable,
{x: "date", y: "author", r: 5, fill: 'forum', opacity: 0.3}),
Plot.tip(alphaForumTable, Plot.pointer({
x: "date",
y: "author",
title: (d) => `<b>${d.author}</b> – ${(new Date(d.date).toLocaleDateString())} <br><a href="${d.url}" target="_blank">${d.forum}/${d.topic}</a> <br><br> ${d.post}`,
render: (index, scales, values, dimensions, context, next) => {
const g = next(index, scales, values, dimensions, context);
const [i] = index;
if (i === undefined) return g;
const textElement = d3.select(g)
.select(`g[aria-label="tip"] text`);
const bbox = textElement.node().getBBox();
textElement.html("");
const foreignObject = d3.select(g)
.select(`g[aria-label="tip"] g`)
.html("")
.append("foreignObject")
.attr("width", 200)
.attr("height", 200)
.style("background-color", "white")
.style("padding-top", "5px")
.style("border", "1px solid black");
const innerG = d3.select(g).select('g');
const transformAttr = innerG.attr('transform');
const yTranslate = transformAttr.match(/translate\(\d+,\s*(\d+)\)/)[1];
if (yTranslate > (dimensions.height) / 2 + dimensions.marginBottom + dimensions.marginTop) {
foreignObject.style("y", "-200px")
}
const body = foreignObject.append("xhtml:body");
body.html(`${values.title[i]}`);
console.log(g);
return g;
}
}))
],
})