<commit_before>var dg = (function(dg){ 

    dg.graph = {
        cache: d3.map(),
        cacheHistory: [],
        centerNodeKey: null,
        dimensions: [0, 0],
        isUpdating: false,
        json: null,
        linkMap: d3.map(),
        links: [],
        newNodeCoords: [0, 0],
        nodeMap: d3.map(),
        nodes: [],
        selectedNodeKey: null,
        maxDistance: 0,
        // selections
        svgSelection: null,
        haloSelection: null,
        nodeSelection: null,
        linkSelection: null,
        textSelection: null,
        // layers
        haloLayer: null,
        textLayer: null,
        nodeLayer: null,
        linkLayer: null,
    };

    /* GRAPH METHODS */

    dg.handleNewGraphData = function(error, json) {
        if (error) {
            console.warn("404", error);
            window.history.back();
            return;
        }
        var key = json.center;
        if (!dg.graph.cache.has(key)) {
            dg.graph.cache.set(key, JSON.parse(JSON.stringify(json)));
            dg.graph.cacheHistory.push(key);
            if (50 <= dg.graph.cache.size()) {
                dg.graph.cache.remove(dg.graph.cacheHistory.shift());
            }
        }
        var name = json.nodes.filter(function(d) { return d.key == key; })
        if (name.length) {
            document.title = "discograph: " + name[0].name;
        }
        $(document).attr("body").id = key;
        dg.graph.json = json;
        dg.updateForceLayout();
        dg.startForceLayout();
        setTimeout(function() {
            dg.graph.isUpdating = false;
        }, 2000);
        $("#page-loading")
            .removeClass("glyphicon-animate glyphicon-refresh")
            .addClass("glyphicon-random")
            ;
    }

    dg.navigateGraph = function(key) {
        dg.history.pushState(key);
        dg.updateGraph(key);
    }

    dg.selectNode = function(key) {
        dg.graph.selectedNodeKey = key;

        if (key !== null) {
            var haloOff = dg.graph.haloSelection.filter("*:not(.node-" + key + ")");
            var nodeOff = dg.graph.nodeSelection.filter("*:not(.node-" + key + ")");
            var nodeOn = dg.graph.nodeSelection.filter(".node-" + key);
            var linkKeys = nodeOn.data()[0].links;
            var linkOff = dg.graph.linkSelection.filter(function(d) { 
                return linkKeys.indexOf(d.key) == -1;
            });
        } else {
            var haloOff = dg.graph.haloSelection;
            var nodeOff = dg.graph.nodeSelection;
            var linkOff = dg.graph.linkSelection;
        }

        haloOff.select(".halo").style("fill-opacity", 0.);
        linkOff.style("opacity", 0.25);
        nodeOff.select(".more").style("fill", "#fff");
        nodeOff.style("stroke", "#fff");

        if (key === null) {
            return;
        }

        var haloOn = dg.graph.haloSelection.filter(".node-" + key);
        var linkOn = dg.graph.linkSelection.filter(function(d) { 
            return 0 <= linkKeys.indexOf(d.key);
        });
        var textOn = dg.graph.textSelection.filter(".node-" + key);

        haloOn.select(".halo").style("fill-opacity", 0.1);
        linkOn.style("opacity", 1);
        nodeOn.moveToFront();
        nodeOn.select(".more").style("fill", "#000");
        nodeOn.style("stroke", "#000")
        textOn.moveToFront();
    }

    function getOuterRadius(d) {
        if (0 < d.size) {
            return 12 + (Math.sqrt(d.size) * 2);
        }
        return 9 + (Math.sqrt(d.size) * 2);
    }

    function getInnerRadius(d) {
        return 9 + (Math.sqrt(d.size) * 2);
    }

    function onHaloEnter(haloEnter) {
        var haloEnter = haloEnter.append("g")
            .attr("class", function(d) { return "node node-" + d.key; })
        haloEnter.append("circle")<commit_msg>Added Discogs.com link to selected nodes.<commit_after>var dg = (function(dg){ 

    dg.graph = {
        cache: d3.map(),
        cacheHistory: [],
        centerNodeKey: null,
        dimensions: [0, 0],
        isUpdating: false,
        json: null,
        linkMap: d3.map(),
        links: [],
        newNodeCoords: [0, 0],
        nodeMap: d3.map(),
        nodes: [],
        selectedNodeKey: null,
        maxDistance: 0,
        // selections
        svgSelection: null,
        haloSelection: null,
        nodeSelection: null,
        linkSelection: null,
        textSelection: null,
        // layers
        haloLayer: null,
        textLayer: null,
        nodeLayer: null,
        linkLayer: null,
    };

    /* GRAPH METHODS */

    dg.handleNewGraphData = function(error, json) {
        if (error) {
            console.warn("404", error);
            window.history.back();
            return;
        }
        var key = json.center;
        if (!dg.graph.cache.has(key)) {
            dg.graph.cache.set(key, JSON.parse(JSON.stringify(json)));
            dg.graph.cacheHistory.push(key);
            if (50 <= dg.graph.cache.size()) {
                dg.graph.cache.remove(dg.graph.cacheHistory.shift());
            }
        }
        var name = json.nodes.filter(function(d) { return d.key == key; })
        if (name.length) {
            document.title = "discograph: " + name[0].name;
        }
        $(document).attr("body").id = key;
        dg.graph.json = json;
        dg.updateForceLayout();
        dg.startForceLayout();
        setTimeout(function() {
            dg.graph.isUpdating = false;
        }, 2000);
        $("#page-loading")
            .removeClass("glyphicon-animate glyphicon-refresh")
            .addClass("glyphicon-random")
            ;
    }

    dg.navigateGraph = function(key) {
        dg.history.pushState(key);
        dg.updateGraph(key);
    }

    dg.selectNode = function(key) {
        dg.graph.selectedNodeKey = key;

        if (key !== null) {
            var haloOff = dg.graph.haloSelection.filter("*:not(.node-" + key + ")");
            var nodeOff = dg.graph.nodeSelection.filter("*:not(.node-" + key + ")");
            var nodeOn = dg.graph.nodeSelection.filter(".node-" + key);
            var linkKeys = nodeOn.data()[0].links;
            var linkOff = dg.graph.linkSelection.filter(function(d) { 
                return linkKeys.indexOf(d.key) == -1;
            });
        } else {
            var haloOff = dg.graph.haloSelection;
            var nodeOff = dg.graph.nodeSelection;
            var linkOff = dg.graph.linkSelection;
        }

        haloOff.select(".halo").style("fill-opacity", 0.);
        linkOff.style("opacity", 0.25);
        nodeOff.select(".more").style("fill", "#fff");
        nodeOff.style("stroke", "#fff");
        nodeOff.select("text").remove();

        if (key === null) {
            return;
        }

        var haloOn = dg.graph.haloSelection.filter(".node-" + key);
        var linkOn = dg.graph.linkSelection.filter(function(d) { 
            return 0 <= linkKeys.indexOf(d.key);
        });
        var textOn = dg.graph.textSelection.filter(".node-" + key);

        haloOn.select(".halo").style("fill-opacity", 0.1);
        linkOn.style("opacity", 1);
        nodeOn.moveToFront();
        nodeOn.select(".more").style("fill", "#000");
        nodeOn.style("stroke", "#000")
        textOn.moveToFront();

        nodeOn.select('text').remove();
        var icon = nodeOn.append('text')
            //.attr('filter', 'url(#shadow)')
            .style('cursor', 'pointer')
            .style('fill', '#fff')
            .style('font-family', 'Glyphicons Halflings')
            .style('font-style', 'normal')
            .style('font-weight', 100)
            .style('font-size', '20px')
            .style('opacity', 0.5)
            .attr('dx', function(d) {
                return (-1 * d.radius) - 28;
            })
            .attr('dy', 10)
            .text('\ue164');
        icon.append('title').text(function(d) {
            return 'View ' + d.name + ' on Discogs.com'; 
        });
        icon.on('mouseover', function(d) {
            d3.select(this).transition().duration(0).style('opacity', '1');
        });
        icon.on('mouseout', function(d) {
            d3.select(this).transition().duration(100).style('opacity', '0.5');
        });
        icon.on('mousedown', function(d) {
            var url = 'http://discogs.com/' + d.type + '/' + d.id;
            window.open(url);
        });

    }

    function getOuterRadius(d) {
        if (0 < d.size) {
            return 12 + (Math.sqrt(d.size) * 2);
        }
        return 9 + (Math.sqrt(d.size) * 2);
    }

    function getInnerRadius(d) {
        return 9 + (Math.sqrt(d.size) * 2);
    }

    function onHaloEnter(haloEnter) {
        var haloEnter = haloEnter.append("g")
            .attr("class", function(d) { return "node node-" + d.key; })
        haloEnter.append("circle")
{'fraction_non_alphanumeric': 0.16224790392023566, 'fraction_numerical': 0.012236573759347382, 'mean_word_length': 1.7507011530071674, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3812775', 'n_tokens_mistral': 2847, 'n_tokens_neox': 2661, 'n_words': 469}