<commit_before>/* global d3 */

function MapOrSectorController($scope, $compile, $location, storageService, locationsService, navigationService, isMobile) {

    var vm = this;
    vm.selectedLocation = null;
    var leftMargin = isMobile ? 70 : 150;
    var truncateAmount = isMobile ? 70 : 100;  // used in cropping the x-axis labels

    var location_id = $location.search().location_id;

    if (['null', 'undefined', ''].indexOf(location_id) === -1) {
        locationsService.getLocation(location_id).then(function (location) {
            vm.showChart = location.location_type === 'district';
        });
    }

    function wrapXAxisLabels() {
        //This wrap te text on the xAxis label if text length is longer than 100
        //Found on stackoverflow: https://stackoverflow.com/questions/16701522/how-to-linebreak-an-svg-text-within-javascript/28553412#28553412
        //Replace svg text element to:
        //<text><tspan></tspan><tspan></tspan>...<text>
        d3.selectAll(".nv-x.nv-axis .tick text").each(function () {
            var text = d3.select(this),
                words = text.text().split(/\s+/).reverse(),
                word, line = [],
                lineNumber = 0,
                lineHeight = 1.1, // ems
                y = 2.5 * parseInt(words.length),
                dy = parseFloat(text.attr("dy")),
                tspan = text.text(null).append("tspan").attr("x", -5).attr("y", -y).attr("dy", dy + "em");

            word = words.pop();
            while (word) {
                line.push(word);
                tspan.text(line.join(" "));
                if (tspan.node().getComputedTextLength() > truncateAmount) {
                    line.pop();
                    tspan.text(line.join(" "));
                    line = [word];
                    tspan = text.append("tspan").attr("x", -5).attr("y", -y).attr("dy", ++lineNumber * lineHeight + dy + "em").text(word);
                }
                word = words.pop();
            }
        });
    }
    vm.handleMobileDrilldown = function () {
        locationsService.tryToNavigateToLocation(vm.selectedLocation, location_id);
    };

    // reduce caption width to fit screen up to 900px on mobile view
    var captionWidth = (isMobile && window.innerWidth < 960) ? window.innerWidth - 60 : 900;

    function getChartTooltip(d) {
        return getTooltipHtml(d.value);
    }

    function getTooltipHtml(locName) {
        if (!vm.data.mapData.tooltips_data || !vm.data.mapData.tooltips_data[locName]) {
            return 'NA';
        }
        return vm.templatePopup({
            loc: {
                properties: {
                    name: locName,
                },
            },
            row: vm.data.mapData.tooltips_data[locName],
        });
    }

    vm.renderPopup = function (html, divId) {
        console.log('new popup');
        // todo: this is mostly duplicated from indie-map.renderPopup
        // only the div ID is changed
        var css = 'display: block; left: ' + event.layerX + 'px; top: ' + event.layerY + 'px;';
        var popup = d3.select('#' + divId);
        popup.classed("hidden", false);
        popup.attr('style', css).html(html);
        $compile(popup[0])($scope);<commit_msg>remove deprecated todo and logging statement<commit_after>/* global d3 */

function MapOrSectorController($scope, $compile, $location, storageService, locationsService, navigationService, isMobile) {

    var vm = this;
    vm.selectedLocation = null;
    var leftMargin = isMobile ? 70 : 150;
    var truncateAmount = isMobile ? 70 : 100;  // used in cropping the x-axis labels

    var location_id = $location.search().location_id;

    if (['null', 'undefined', ''].indexOf(location_id) === -1) {
        locationsService.getLocation(location_id).then(function (location) {
            vm.showChart = location.location_type === 'district';
        });
    }

    function wrapXAxisLabels() {
        //This wrap te text on the xAxis label if text length is longer than 100
        //Found on stackoverflow: https://stackoverflow.com/questions/16701522/how-to-linebreak-an-svg-text-within-javascript/28553412#28553412
        //Replace svg text element to:
        //<text><tspan></tspan><tspan></tspan>...<text>
        d3.selectAll(".nv-x.nv-axis .tick text").each(function () {
            var text = d3.select(this),
                words = text.text().split(/\s+/).reverse(),
                word, line = [],
                lineNumber = 0,
                lineHeight = 1.1, // ems
                y = 2.5 * parseInt(words.length),
                dy = parseFloat(text.attr("dy")),
                tspan = text.text(null).append("tspan").attr("x", -5).attr("y", -y).attr("dy", dy + "em");

            word = words.pop();
            while (word) {
                line.push(word);
                tspan.text(line.join(" "));
                if (tspan.node().getComputedTextLength() > truncateAmount) {
                    line.pop();
                    tspan.text(line.join(" "));
                    line = [word];
                    tspan = text.append("tspan").attr("x", -5).attr("y", -y).attr("dy", ++lineNumber * lineHeight + dy + "em").text(word);
                }
                word = words.pop();
            }
        });
    }
    vm.handleMobileDrilldown = function () {
        locationsService.tryToNavigateToLocation(vm.selectedLocation, location_id);
    };

    // reduce caption width to fit screen up to 900px on mobile view
    var captionWidth = (isMobile && window.innerWidth < 960) ? window.innerWidth - 60 : 900;

    function getChartTooltip(d) {
        return getTooltipHtml(d.value);
    }

    function getTooltipHtml(locName) {
        if (!vm.data.mapData.tooltips_data || !vm.data.mapData.tooltips_data[locName]) {
            return 'NA';
        }
        return vm.templatePopup({
            loc: {
                properties: {
                    name: locName,
                },
            },
            row: vm.data.mapData.tooltips_data[locName],
        });
    }

    vm.renderPopup = function (html, divId) {
        var css = 'display: block; left: ' + event.layerX + 'px; top: ' + event.layerY + 'px;';
        var popup = d3.select('#' + divId);
        popup.classed("hidden", false);
        popup.attr('style', css).html(html);
        $compile(popup[0])($scope);
{'fraction_non_alphanumeric': 0.14747918957122663, 'fraction_numerical': 0.019161300455473537, 'mean_word_length': 1.961860465116279, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 2, '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': '264034', 'n_tokens_mistral': 1992, 'n_tokens_neox': 1846, 'n_words': 393}