reimandlab/Visualistion-Framework-for-Genome-Mutations

View on GitHub
website/static/venn.js

Summary

Maintainability
A
1 hr
Test Coverage
/**
 * Code in this file is based upon an example of usage of venn.js from official repository,
 * MIT licensed: https://github.com/benfred/venn.js/blob/master/LICENSE
 */
function add_venn_tooltip(div, name) {
    var tooltip = d3.select("body").append("div").attr("class", "tooltip venn-tooltip");
    div.selectAll("g")
        .on("mouseover", function (d, i) {
            // sort all the areas relative to the current item
            venn.sortAreas(div, d);

            // Display a tooltip with the current size
            tooltip.transition().duration(400).style("opacity", .9);
            tooltip.text(d.size + " " + name);

            // highlight the current path
            var selection = d3.select(this).transition("tooltip").duration(400);
            selection.select("path")
                .style("fill-opacity", d.sets.length == 1 ? .4 : .1)
                .style("stroke-opacity", 1);
        })

        .on("mousemove", function () {
            tooltip.style("left", (d3.event.pageX + 10) + "px")
                .style("top", (d3.event.pageY + 10) + "px");
        })

        .on("mouseout", function (d, i) {
            tooltip.transition().duration(400).style("opacity", 0);
            var selection = d3.select(this).transition("tooltip").duration(400);
            selection.select("path")
                .style("fill-opacity", d.sets.length == 1 ? .25 : .0)
                .style("stroke-opacity", 0);
        });
}