<commit_before>angular.module('dplaceMapDirective', [])
    .directive('dplaceMap', function() {
        function link(scope, element, attrs) {
            element.append("<div id='mapdiv' style='width:1140px; height:30rem;'></div>");
            scope.localRegions = [];
            scope.checkDirty = function() {
                return !(angular.equals(scope.localRegions, scope.selectedRegions));
            };
            scope.updatesEnabled = true;
            scope.map = $('#mapdiv').vectorMap({
                map: 'tdwg-level2',
                backgroundColor: 'white',
                regionStyle: {
                  initial: {
                    fill: '#428bca',
                    "fill-opacity": 1,
                    stroke: '#357ebd',
                    "stroke-width": 0,
                    "stroke-opacity": 1
                  },
                  hover: {
                    "fill-opacity": 0.8
                  },
                  selected: {
                    fill: '#113'
                  },
                  selectedHover: {
                  }
                },
                onRegionOver: function(e, code) {
                    if(attrs.region) {
                        scope.$apply(function () {
                            scope.region = code;
                        });
                    }
                },
                onRegionSelected: function(e, code, isSelected, selectedRegionCodes) {
                    if(scope.updatesEnabled && attrs.selectedRegions) {
                        scope.localRegions = selectedRegionCodes.map(function(code) {
                            return {
                                code: code,
                                name: scope.map.getRegionName(code)
                            };
                        });
                        var dirty = scope.checkDirty();
                        if(dirty) {
                            scope.$apply(function() {
                                scope.selectedRegions = angular.copy(scope.localRegions);
                            });
                        }
                    }
                },
                regionsSelectable: true
            }).vectorMap('get','mapObject');

            scope.addMarkers = function() {
                scope.map.removeAllMarkers();
                if(!scope.societies) {
                    return;
                }
                scope.societies.forEach(function(societyResult) {
                    var society = societyResult.society;
                    // Add a marker for each point
                    var marker = {latLng: society.location.coordinates.reverse(), name: society.name}
                    scope.map.addMarker(society.id, marker);
                });
            };

            if(attrs.societies) {
                // Update markers when societies change
                scope.$watchCollection('societies', function(oldvalue, newvalue) {
                    scope.addMarkers();
                });
            }

            if(attrs.selectedRegions) {
                scope.$watchCollection('selectedRegions', function(oldvalue, newvalue) {
                    var dirty = scope.checkDirty();<commit_msg>Color-coding of society markers<commit_after>angular.module('dplaceMapDirective', [])
    .directive('dplaceMap', function() {
        function link(scope, element, attrs) {
            element.append("<div id='mapdiv' style='width:1140px; height:30rem;'></div>");
            scope.localRegions = [];
            scope.checkDirty = function() {
                return !(angular.equals(scope.localRegions, scope.selectedRegions));
            };
            scope.updatesEnabled = true;
            scope.map = $('#mapdiv').vectorMap({
                map: 'tdwg-level2',
                backgroundColor: 'white',
                series: {
                    markers: [{
                        attribute: 'fill'
                    }]
                },
                regionStyle: {
                  initial: {
                    fill: '#428bca',
                    "fill-opacity": 1,
                    stroke: '#357ebd',
                    "stroke-width": 0,
                    "stroke-opacity": 1
                  },
                  hover: {
                    "fill-opacity": 0.8
                  },
                  selected: {
                    fill: '#113'
                  },
                  selectedHover: {
                  }
                },
                onRegionOver: function(e, code) {
                    if(attrs.region) {
                        scope.$apply(function () {
                            scope.region = code;
                        });
                    }
                },
                onRegionSelected: function(e, code, isSelected, selectedRegionCodes) {
                    if(scope.updatesEnabled && attrs.selectedRegions) {
                        scope.localRegions = selectedRegionCodes.map(function(code) {
                            return {
                                code: code,
                                name: scope.map.getRegionName(code)
                            };
                        });
                        var dirty = scope.checkDirty();
                        if(dirty) {
                            scope.$apply(function() {
                                scope.selectedRegions = angular.copy(scope.localRegions);
                            });
                        }
                    }
                },
                regionsSelectable: true
            }).vectorMap('get','mapObject');

            /** Move this into a service **/
            var getColorAtScalar = function (n, maxLength) {
                var n = n * 240 / (maxLength);
                return 'hsl(' + n + ',100%,50%)';
            };

            var generateColorMap = function(ids) {
                // Return a map of ids to colors
                var colors = {};
                for(var i=0;i<ids.length;i++) {
                    var color = getColorAtScalar(i, ids.length);
                    colors[ids[i]] = color;
                }
                return colors;
            };

            /** end color service **/

            scope.addMarkers = function() {
                scope.map.removeAllMarkers();
                if(!scope.societies) {
                    return;
                }

                // get the society IDs
                var societyIds = scope.societies.map(function(societyResult) {
                    return societyResult.society.id;
                });

                scope.societies.forEach(function(societyResult) {
                    var society = societyResult.society;
                    // Add a marker for each point
                    var marker = {latLng: society.location.coordinates.reverse(), name: society.name}
                    scope.map.addMarker(society.id, marker);
                });

                // Map IDs to colors
                var colorMap = generateColorMap(societyIds);
                scope.map.series.markers[0].setValues(colorMap);
            };

            if(attrs.societies) {
                // Update markers when societies change
                scope.$watchCollection('societies', function(oldvalue, newvalue) {
                    scope.addMarkers();
                });
            }

            if(attrs.selectedRegions) {
                scope.$watchCollection('selectedRegions', function(oldvalue, newvalue) {
                    var dirty = scope.checkDirty();
{'fraction_non_alphanumeric': 0.10382585751978891, 'fraction_numerical': 0.006860158311345646, 'mean_word_length': 1.0092764378478665, 'pattern_counts': {'":': 8, '<': 8, '<?xml version=': 0, '>': 7, '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': '4606467', 'n_tokens_mistral': 1837, 'n_tokens_neox': 1671, 'n_words': 297}