clusterDisplayInit = (node, svg, svgg) => {
const hull = svgg.insert("path", ":first-child");
var selCluster = null;
var isHover = true;
const mouseclick = (eve, dat) => {
eve.stopPropagation();
isHover = false;
const color = d3.schemeCategory10[dat.cluster % 10];
hull.attr("stroke", color)
.attr("fill", color)
.attr("d", getPath(getHull(officerClusters[dat.cluster])))
.attr("stroke-opacity", 0.5)
.attr("fill-opacity", 0.3);
selCluster = dat.cluster;
svg.dispatch("update-info");
}
const mouseclickSvg = (eve) => {
if (selCluster !== null
&& d3.polygonContains(getHull(officerClusters[selCluster]), [eve.x, eve.y]))
return;
isHover = true;
selCluster = null;
hull.attr("stroke-opacity", 0)
.attr("fill-opacity", 0);
svg.dispatch("update-info");
}
const mouseover = (eve, dat) => {
if (!isHover) return;
const color = d3.schemeCategory10[dat.cluster % 10];
hull.attr("stroke", color)
.attr("fill", color)
.attr("d", getPath(getHull(officerClusters[dat.cluster])))
.attr("stroke-opacity", 0)
.attr("fill-opacity", 0)
.transition()
.duration(500)
.attr("stroke-opacity", 0.5)
.attr("fill-opacity", 0.3);
selCluster = dat.cluster;
svg.dispatch("update-info");
}
const mouseout = (eve, dat) => {
if (!isHover) return;
selCluster = null;
svg.dispatch("update-info");
hull.transition()
.duration(500)
.attr("stroke-opacity", 0)
.attr("fill-opacity", 0);
}
const updater = () => {
if (selCluster === null) return;
hull.attr("d", getPath(getHull(officerClusters[selCluster])));
}
const clusterGetter = () => {
return selCluster;
}
node.on("mouseover", mouseover)
.on("mouseout", mouseout)
.on("click", mouseclick);
svg.on("click", mouseclickSvg);
return [updater, clusterGetter];
}