<commit_before>'use strict';

function AppCtrl($scope, $location, $rootScope, Place, GeoSearch, EscapingService) {
	
	$scope.q = null;
	$scope.type = "";
	$rootScope.pageTitle = "iDAI.gazetteer";
	$rootScope.title = "";
	$rootScope.subtitle = "";
	
	$rootScope.activePlaces = [];
	
	$rootScope.alerts = [];
	
	$rootScope.loading = 0;
	
	$rootScope.isFocused = false;
	
	$rootScope.bbox = [];
	$rootScope.zoom = 2;
	$rootScope.mapMode = "standard";
	$scope.highlight = null;
	
	$scope.searchSuggestions = [];
	$scope.selectedSuggestionIndex = -1;
	
	$scope.scrollPosition = 0;
	
	$scope.$watch("q", function() {				
		$scope.updateSuggestions();	
	});
	
	$scope.$watch("showMap", function() {
		if ($rootScope.showMap)
			$scope.mapContainerStyle = {};
		else
			$scope.mapContainerStyle = { 'position': 'absolute', 'left': '-10000px' };
	});
	
	$scope.$watch("geoSearch", function() {
		if ($rootScope.geoSearch)
			GeoSearch.activate($rootScope.map);
		else
			GeoSearch.deactivate();
	});
	
	$scope.updateSuggestions = function() {
		$scope.searchSuggestions = [];
		$scope.selectedSuggestionIndex = -1;
		
		if ($scope.q && $scope.q.length > 0) {
			Place.suggestions({ field: "prefName.title.suggest", text: $scope.q }, function(result) {
				$scope.searchSuggestions = result.suggestions;

				Place.suggestions({ field: "names.title.suggest", text: $scope.q }, function(result) {
					for (var newSuggestion in result.suggestions) {
						var sameAsPrefName = false;
						for (var prefNameSuggestion in $scope.searchSuggestions) {
							if ($scope.searchSuggestions[prefNameSuggestion].trim() == result.suggestions[newSuggestion].trim()) {
								sameAsPrefName = true;
								break;
							}
						}
						if (!sameAsPrefName && $scope.searchSuggestions.length < 7)
							$scope.searchSuggestions.push(result.suggestions[newSuggestion]);
					}
				});
			});
		}
	};
	
	$scope.selectPreviousSuggestion = function() {
		if ($scope.searchSuggestions.length > 0) {
			$scope.selectedSuggestionIndex -= 1;
			if ($scope.selectedSuggestionIndex < 0)
				$scope.selectedSuggestionIndex = $scope.searchSuggestions.length - 1;
		}
	};
	
	$scope.selectNextSuggestion = function() {
		if ($scope.searchSuggestions.length > 0) {
			$scope.selectedSuggestionIndex += 1;
			if ($scope.selectedSuggestionIndex >= $scope.searchSuggestions.length)
				$scope.selectedSuggestionIndex = 0;
		}
	};
	
	$scope.setSelectedSuggestionIndex = function(index) {
		$scope.selectedSuggestionIndex = index;
	};
	
	$scope.lostFocus = function() {
		$scope.searchSuggestions = [];
		$rootScope.isFocused = false;
	};
	
	$scope.submit = function() {
		if ($scope.selectedSuggestionIndex != -1)
			$scope.q = $scope.searchSuggestions[$scope.selectedSuggestionIndex];
		
		$scope.zoom = 2;
		$location.path('/search').search({q: EscapingService.escape($scope.q), type: $scope.type});
		$scope.q = null;
	};
	
	$rootScope.addAlert = function(body, head, type) {
		var alert = { body: body };
		if (head != null) alert.head = head;
		if (type != null) alert.alertClass = "alert-" + type;
		$rootScope.alerts.push(alert);
	};
	
	// remove alerts if location changes
	$scope.$watch(function(){ return $location.absUrl(); }, function() {
		if ($location.search().keepAlerts) return;
		$rootScope.alerts = [];
	});
	
	$scope.setHighlight = function(id) {
		$scope.highlight = id;
	};
	
}

function HomeCtrl($scope, $location, $rootScope, Place, EscapingService) {
	$scope.q = null;
	$scope.type = "";
	$rootScope.showMap = false;
	$rootScope.showHeader = false;
	$rootScope.showNavbarSearch = false;
	$rootScope.viewClass = "";
	$rootScope.pageTitle = "iDAI.gazetteer";
	$rootScope.title = "";
	$rootScope.subtitle = "";
	$rootScope.isFocused = false;
	$rootScope.geoSearch = false;
	
	$scope.homeSearchSuggestions = [];
	$scope.selectedSuggestionIndex = -1;
	
	var map_canvas = document.getElementById('home_map_canvas');
	
	$scope.homeMap = new google.maps.Map(map_canvas, {
		center: new google.maps.LatLng(20,0),
		zoom: 2,
		disableDefaultUI: true,
		mapTypeId: google.maps.MapTypeId.ROADMAP,
		zoomControlOptions: {
			style: google.maps.ZoomControlStyle.SMALL
		},
		styles: [
        	{
       	    "featureType": "administrative",
       	    "stylers": [
       	      { "visibility": "off" }
       	    ]
       	  },{
       	    "featureType": "landscape",
       	    "stylers": [
       	      { "visibility": "simplified" },
       	      { "saturation": -100 },
       	      { "lightness": -31 }
       	    ]
       	  },{
       	    "featureType": "water",
       	    "stylers": [
       	      { "saturation": -100 },
       	      { "lightness": 32 }
       	    ]
       	  },{
       	    "featureType": "road",
       	    "stylers": [
       	      { "visibility": "off" }
       	    ]
       	  },{
       	    "featureType": "poi",
       	    "stylers": [
       	      { "visibility": "off" }
       	    ]
       	  },{
       	    "elementType": "labels"  }
       	]
	});
	
	Place.heatmapCoordinates({}, function(result) {
		var coordinates = result.coordinates;
		var heatmapData = [];
		for (var i = 0; i < coordinates.length - 1; i+= 2) {
			heatmapData.push(new google.maps.LatLng(coordinates[i], coordinates[i+1]));		
		}
		
		var heatmap = new google.maps.visualization.HeatmapLayer({
	        data: heatmapData,
	        opacity: 0.8,
	        maxIntensity: 10,
	        radius: 3,
			gradient: ['transparent', '#5283d2', '#ffffff']
	   	});
		heatmap.setMap($scope.homeMap);		
	});
	
	$scope.$watch("searchFieldInput", function() {
		$scope.updateSuggestions();		
		$scope.selectedSuggestionIndex = -1;
	});
	
	$scope.updateSuggestions = function() {
		$scope.homeSearchSuggestions = [];
		
		if ($scope.searchFieldInput && $scope.searchFieldInput.length > 0) {
			Place.suggestions({ field: "prefName.title.suggest", text: $scope.searchFieldInput }, function(result) {
				$scope.homeSearchSuggestions = result.suggestions;

				Place.suggestions({ field: "names.title.suggest", text: $scope.searchFieldInput }, function(result) {
					for (var newSuggestion in result.suggestions) {
						var sameAsPrefName = false;
						for (var prefNameSuggestion in $scope.homeSearchSuggestions) {
							if ($scope.homeSearchSuggestions[prefNameSuggestion].trim() == result.suggestions[newSuggestion].trim()) {
								sameAsPrefName = true;
								break;
							}
						} 
						if (!sameAsPrefName && $scope.homeSearchSuggestions.length < 7)
							$scope.homeSearchSuggestions.push(result.suggestions[newSuggestion]);
					}
				});
			});<commit_msg>try to fix map size bug<commit_after>'use strict';

function AppCtrl($scope, $location, $rootScope, Place, GeoSearch, EscapingService) {
	
	$scope.q = null;
	$scope.type = "";
	$rootScope.pageTitle = "iDAI.gazetteer";
	$rootScope.title = "";
	$rootScope.subtitle = "";
	
	$rootScope.activePlaces = [];
	
	$rootScope.alerts = [];
	
	$rootScope.loading = 0;
	
	$rootScope.isFocused = false;
	
	$rootScope.bbox = [];
	$rootScope.zoom = 2;
	$rootScope.mapMode = "standard";
	$scope.highlight = null;
	
	$scope.searchSuggestions = [];
	$scope.selectedSuggestionIndex = -1;
	
	$scope.scrollPosition = 0;
	
	$scope.$watch("q", function() {				
		$scope.updateSuggestions();	
	});
	
	$scope.$watch("showMap", function() {
		if ($rootScope.showMap) {
			$scope.mapContainerStyle = {};
			google.maps.event.trigger($rootScope.map, 'resize');
		}
		else
			$scope.mapContainerStyle = { 'position': 'absolute', 'left': '-10000px' };
	});
	
	$scope.$watch("geoSearch", function() {
		if ($rootScope.geoSearch)
			GeoSearch.activate($rootScope.map);
		else
			GeoSearch.deactivate();
	});
	
	$scope.updateSuggestions = function() {
		$scope.searchSuggestions = [];
		$scope.selectedSuggestionIndex = -1;
		
		if ($scope.q && $scope.q.length > 0) {
			Place.suggestions({ field: "prefName.title.suggest", text: $scope.q }, function(result) {
				$scope.searchSuggestions = result.suggestions;

				Place.suggestions({ field: "names.title.suggest", text: $scope.q }, function(result) {
					for (var newSuggestion in result.suggestions) {
						var sameAsPrefName = false;
						for (var prefNameSuggestion in $scope.searchSuggestions) {
							if ($scope.searchSuggestions[prefNameSuggestion].trim() == result.suggestions[newSuggestion].trim()) {
								sameAsPrefName = true;
								break;
							}
						}
						if (!sameAsPrefName && $scope.searchSuggestions.length < 7)
							$scope.searchSuggestions.push(result.suggestions[newSuggestion]);
					}
				});
			});
		}
	};
	
	$scope.selectPreviousSuggestion = function() {
		if ($scope.searchSuggestions.length > 0) {
			$scope.selectedSuggestionIndex -= 1;
			if ($scope.selectedSuggestionIndex < 0)
				$scope.selectedSuggestionIndex = $scope.searchSuggestions.length - 1;
		}
	};
	
	$scope.selectNextSuggestion = function() {
		if ($scope.searchSuggestions.length > 0) {
			$scope.selectedSuggestionIndex += 1;
			if ($scope.selectedSuggestionIndex >= $scope.searchSuggestions.length)
				$scope.selectedSuggestionIndex = 0;
		}
	};
	
	$scope.setSelectedSuggestionIndex = function(index) {
		$scope.selectedSuggestionIndex = index;
	};
	
	$scope.lostFocus = function() {
		$scope.searchSuggestions = [];
		$rootScope.isFocused = false;
	};
	
	$scope.submit = function() {
		if ($scope.selectedSuggestionIndex != -1)
			$scope.q = $scope.searchSuggestions[$scope.selectedSuggestionIndex];
		
		$scope.zoom = 2;
		$location.path('/search').search({q: EscapingService.escape($scope.q), type: $scope.type});
		$scope.q = null;
	};
	
	$rootScope.addAlert = function(body, head, type) {
		var alert = { body: body };
		if (head != null) alert.head = head;
		if (type != null) alert.alertClass = "alert-" + type;
		$rootScope.alerts.push(alert);
	};
	
	// remove alerts if location changes
	$scope.$watch(function(){ return $location.absUrl(); }, function() {
		if ($location.search().keepAlerts) return;
		$rootScope.alerts = [];
	});
	
	$scope.setHighlight = function(id) {
		$scope.highlight = id;
	};
	
}

function HomeCtrl($scope, $location, $rootScope, Place, EscapingService) {
	$scope.q = null;
	$scope.type = "";
	$rootScope.showMap = false;
	$rootScope.showHeader = false;
	$rootScope.showNavbarSearch = false;
	$rootScope.viewClass = "";
	$rootScope.pageTitle = "iDAI.gazetteer";
	$rootScope.title = "";
	$rootScope.subtitle = "";
	$rootScope.isFocused = false;
	$rootScope.geoSearch = false;
	
	$scope.homeSearchSuggestions = [];
	$scope.selectedSuggestionIndex = -1;
	
	var map_canvas = document.getElementById('home_map_canvas');
	
	Place.heatmapCoordinates({}, function(result) {
		$scope.homeMap = new google.maps.Map(map_canvas, {
			center: new google.maps.LatLng(20,0),
			zoom: 2,
			disableDefaultUI: true,
			mapTypeId: google.maps.MapTypeId.ROADMAP,
			zoomControlOptions: {
				style: google.maps.ZoomControlStyle.SMALL
			},
			styles: [
	        	{
	       	    "featureType": "administrative",
	       	    "stylers": [
	       	      { "visibility": "off" }
	       	    ]
	       	  },{
	       	    "featureType": "landscape",
	       	    "stylers": [
	       	      { "visibility": "simplified" },
	       	      { "saturation": -100 },
	       	      { "lightness": -31 }
	       	    ]
	       	  },{
	       	    "featureType": "water",
	       	    "stylers": [
	       	      { "saturation": -100 },
	       	      { "lightness": 32 }
	       	    ]
	       	  },{
	       	    "featureType": "road",
	       	    "stylers": [
	       	      { "visibility": "off" }
	       	    ]
	       	  },{
	       	    "featureType": "poi",
	       	    "stylers": [
	       	      { "visibility": "off" }
	       	    ]
	       	  },{
	       	    "elementType": "labels"  }
	       	]
		});
		
		var coordinates = result.coordinates;
		var heatmapData = [];
		for (var i = 0; i < coordinates.length - 1; i+= 2) {
			heatmapData.push(new google.maps.LatLng(coordinates[i], coordinates[i+1]));		
		}
		
		var heatmap = new google.maps.visualization.HeatmapLayer({
	        data: heatmapData,
	        opacity: 0.8,
	        maxIntensity: 10,
	        radius: 3,
			gradient: ['transparent', '#5283d2', '#ffffff']
	   	});
		heatmap.setMap($scope.homeMap);
	});
	
	$scope.$watch("searchFieldInput", function() {
		$scope.updateSuggestions();		
		$scope.selectedSuggestionIndex = -1;
	});
	
	$scope.updateSuggestions = function() {
		$scope.homeSearchSuggestions = [];
		
		if ($scope.searchFieldInput && $scope.searchFieldInput.length > 0) {
			Place.suggestions({ field: "prefName.title.suggest", text: $scope.searchFieldInput }, function(result) {
				$scope.homeSearchSuggestions = result.suggestions;

				Place.suggestions({ field: "names.title.suggest", text: $scope.searchFieldInput }, function(result) {
					for (var newSuggestion in result.suggestions) {
						var sameAsPrefName = false;
						for (var prefNameSuggestion in $scope.homeSearchSuggestions) {
							if ($scope.homeSearchSuggestions[prefNameSuggestion].trim() == result.suggestions[newSuggestion].trim()) {
								sameAsPrefName = true;
								break;
							}
						} 
						if (!sameAsPrefName && $scope.homeSearchSuggestions.length < 7)
							$scope.homeSearchSuggestions.push(result.suggestions[newSuggestion]);
					}
				});
			});
{'fraction_non_alphanumeric': 0.15730252227760158, 'fraction_numerical': 0.008004833106781453, 'mean_word_length': 3.00695915279879, 'pattern_counts': {'":': 38, '<': 11, '<?xml version=': 0, '>': 13, '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': '4929010', 'n_tokens_mistral': 5201, 'n_tokens_neox': 4314, 'n_words': 713}