<commit_before>angular.module('yds').directive('ydsAggregate', ['Data', 'CountrySelectionService', '$sce',
    function(Data, CountrySelectionService, $sce) {
        return {
            restrict: 'E',
            scope: {
                projectId: '@',     // Project ID of chart
                viewType: '@',      // View type of chart
                lang: '@',          // Language
                setOnInit: '@',     // If true, will set this aggregate's view type in CountrySelectionService on init
                extraParams: '='    // Extra parameters to send
            },
            templateUrl: ((typeof Drupal != 'undefined') ? Drupal.settings.basePath + Drupal.settings.yds_project.modulePath +'/' : '') + 'templates/aggregate.html',
            link: function (scope, element, attrs) {
                var projectId = scope.projectId;
                var viewType = scope.viewType;
                var lang = scope.lang;
                var extraParams = scope.extraParams;
                var setOnInit = scope.setOnInit;

                // If project attribute is undefined, set default value
                if (_.isUndefined(projectId) || projectId.trim() == "")
                    projectId = "none";

                // If view type is undefined, show error
                if (_.isUndefined(viewType) || viewType.trim() == "") {
                    console.error("View type not defined!");
                    return;
                }

                // If language is undefined, set default value
                if (_.isUndefined(lang) || lang.trim() == "")
                    lang = "en";

                // Get data for aggregate from API to set variables
                Data.getAggregate(projectId, viewType, lang, extraParams).then(function(response) {
                    // Get value and label
                    scope.label = $sce.trustAsHtml(response.data.label);
                    scope.value = response.data.value;

                    // Get icon class
                    scope.iconClass = _.first(response.view).icon;

                    // Get color and create panel and panel heading styles
                    var color = _.first(response.view).color;

                    scope.panelStyle = {
                        "border-color": color
                    };

                    scope.panelHeadingStyle = {
                        "background-color": color,
                        "border-color": color,
                        "color": "#FFFFFF"
                    };

                    if (setOnInit == "true") {
                        scope.setViewType();
                    }
                });

                /**
                 * Sets the view type to this aggregate component's view type in CountrySelectionService
                 */
                scope.setViewType = function() {
                    CountrySelectionService.setViewType({
                        type: viewType,
                        panelStyle: scope.panelStyle,
                        panelHeadingStyle: scope.panelHeadingStyle
                    });
                };
            }
        };
    }
]);
<commit_msg>Changing year range in Dashboard doesn't reset selected visualization<commit_after>angular.module('yds').directive('ydsAggregate', ['Data', 'CountrySelectionService', '$sce',
    function(Data, CountrySelectionService, $sce) {
        return {
            restrict: 'E',
            scope: {
                projectId: '@',     // Project ID of chart
                viewType: '@',      // View type of chart
                lang: '@',          // Language
                setOnInit: '@',     // If true, will set this aggregate's view type in CountrySelectionService on init
                extraParams: '='    // Extra parameters to send
            },
            templateUrl: ((typeof Drupal != 'undefined') ? Drupal.settings.basePath + Drupal.settings.yds_project.modulePath +'/' : '') + 'templates/aggregate.html',
            link: function (scope, element, attrs) {
                var projectId = scope.projectId;
                var viewType = scope.viewType;
                var lang = scope.lang;
                var extraParams = scope.extraParams;
                var setOnInit = scope.setOnInit;

                // If project attribute is undefined, set default value
                if (_.isUndefined(projectId) || projectId.trim() == "")
                    projectId = "none";

                // If view type is undefined, show error
                if (_.isUndefined(viewType) || viewType.trim() == "") {
                    console.error("View type not defined!");
                    return;
                }

                // If language is undefined, set default value
                if (_.isUndefined(lang) || lang.trim() == "")
                    lang = "en";

                // Get data for aggregate from API to set variables
                Data.getAggregate(projectId, viewType, lang, extraParams).then(function(response) {
                    // Get value and label
                    scope.label = $sce.trustAsHtml(response.data.label);
                    scope.value = response.data.value;

                    // Get icon class
                    scope.iconClass = _.first(response.view).icon;

                    // Get color and create panel and panel heading styles
                    var color = _.first(response.view).color;

                    scope.panelStyle = {
                        "border-color": color
                    };

                    scope.panelHeadingStyle = {
                        "background-color": color,
                        "border-color": color,
                        "color": "#FFFFFF"
                    };

                    if (setOnInit == "true" && _.isEmpty(CountrySelectionService.getViewType())) {
                        scope.setViewType();
                    }
                });

                /**
                 * Sets the view type to this aggregate component's view type in CountrySelectionService
                 */
                scope.setViewType = function() {
                    CountrySelectionService.setViewType({
                        type: viewType,
                        panelStyle: scope.panelStyle,
                        panelHeadingStyle: scope.panelHeadingStyle
                    });
                };
            }
        };
    }
]);

{'fraction_non_alphanumeric': 0.10093023255813953, 'fraction_numerical': 0.0, 'mean_word_length': 1.240708579367836, 'pattern_counts': {'":': 8, '<': 3, '<?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': '3806570', 'n_tokens_mistral': 1524, 'n_tokens_neox': 1407, 'n_words': 371}