<commit_before>(function() {
  'use strict';
  /* global hash  */
  /* global jQuery  */
  /* global chroma  */
  /* global Kartograph */
  var STROKE_WIDTH = 1.5;
  var RIVER_WIDTH = STROKE_WIDTH * 2;
  var WATER_COLOR = '#73c5ef';
  var ANIMATION_TIME_MS = 500;

  angular.module('blindMaps.map', [])

  .value('chroma', chroma)

  .value('$', jQuery)

  .value('$K', Kartograph)

  .value('colors', {
    'GOOD': '#0d0',
    'BAD': '#ff0000',
    'NEUTRAL': '#bbb',
    'BRIGHT_GRAY' : '#ddd'

  })

  .factory('getLayerConfig', function($log, chroma, colors, citySizeRatio) {
    var scale = chroma.scale([
        colors.BAD,
        '#ff4500',
        '#ffa500',
        '#ffff00',
        colors.GOOD
      ]);

    return function(config) {
      var layerConfig = {};
      layerConfig.bg = {
        'styles' : {
          'fill' : colors.BRIGHT_GRAY,
          'stroke-width' : STROKE_WIDTH,
          'transform' : ''
        }
      };

      layerConfig.states = {
        'styles' : {
          'fill' : function(d) {
            var state = config.states && config.states[d.name];
            return state ? scale(state.probability).brighten((1 - state.certainty) * 80).hex() : '#fff';
          },
          'stroke-width' : STROKE_WIDTH,
          'transform' : ''
        },
        'click' : function(data) {
          $log.log(data.name);
          if (config.click !== undefined) {
            config.click(data.name);
          }
        }
      };

      if (config.showTooltips) {
        layerConfig.states.tooltips = function(d) {
          var state = config.states && config.states[d.name];
          var name = ( state ?
            '<span class="label">' +
              '<i class="flag-' + d.name + '"></i> ' +
              state.name +
              '</span>' :
            '<br>Zatím neprocvičováno<br><br>');
          var description = (state ?
            '<div>' +
              '<i class="color-indicator" style="background-color :' +
              scale(state.probability).hex() + '"></i>' +
              ' Odhad znalosti : ' + Math.round(100 * state.probability) + '%</div>' :
            '');
          return [
            name + description,
            config.states[d.name] ? config.states[d.name].name : ''
          ];
        };
      }

      layerConfig.cities = angular.copy(layerConfig.states, {
        'mouseenter' : function(data, path) {
          path.toFront();
          var zoomRatio = 2.5 / citySizeRatio(data.population);
          var animAttrs = {
              'transform' : 's' + zoomRatio,
              'stroke-width' : zoomRatio * STROKE_WIDTH
            };
          path.animate(animAttrs, ANIMATION_TIME_MS / 2, '>');
        },
        'mouseleave' : function(data, path) {
          var animAttrs = {
              'transform' : '',
              'stroke-width' : STROKE_WIDTH
            };
          path.animate(animAttrs, ANIMATION_TIME_MS / 2, '>');
        }
      });

      layerConfig.rivers = angular.copy(layerConfig.states, {
        'styles' : {
          'stroke-width' : RIVER_WIDTH,
          'stroke' : WATER_COLOR,
          'transform' : ''
        },
        'mouseenter' : function(data, path) {
          var zoomRatio = 4;
          var animAttrs = { 'stroke-width' : zoomRatio * RIVER_WIDTH };
          path.animate(animAttrs, ANIMATION_TIME_MS / 2, '>');
        },
        'mouseleave' : function(data, path) {
          var animAttrs = { 'stroke-width' : RIVER_WIDTH };
          path.animate(animAttrs, ANIMATION_TIME_MS / 2, '>');
        }
      });
      layerConfig.lakes = angular.copy(layerConfig.cities, {});
      layerConfig.lakes.styles.fill = function(d) {
        var state = config.states && config.states[d.name];
        return state ? scale(state.probability).brighten((1 - state.certainty) * 80).hex() : WATER_COLOR;
      };
      return layerConfig;
    };
  })
  
  .factory('initLayers', function(getLayerConfig) {
    return function(map, config) {
      var layersConfig = getLayerConfig(config);
      var layersArray = [];
      for (var i in layersConfig) {
        map.addLayer(i, layersConfig[i]);
        var l = map.getLayer(i);
        if (l) {
          layersArray.push(l);
        }
      }
      var that = {
        hideLayer : function(layer) {
          var paths = layer ? layer.getPaths({}) : [];
          angular.forEach(paths, function(path) {
            path.svgPath.hide();
          });
        },
        showLayer : function(layer) {
          var paths = layer ? layer.getPaths({}) : [];
          angular.forEach(paths, function(path) {
            path.svgPath.show();
          });
        },
        getLayerBySlug: function(slug) {
          var ret;
          angular.forEach(layersArray, function(l) {
            var singularId = l.id.replace(/s$/, '').replace(/ie$/, 'y');
            if (singularId == slug) {
              ret = l;
            }
          });
          return ret
        },
        getAll : function(){
          return layersArray;
        },<commit_msg>Fix hiding/showing cities/states to work for provinces, regions, etc.<commit_after>(function() {
  'use strict';
  /* global hash  */
  /* global jQuery  */
  /* global chroma  */
  /* global Kartograph */
  var STROKE_WIDTH = 1.5;
  var RIVER_WIDTH = STROKE_WIDTH * 2;
  var WATER_COLOR = '#73c5ef';
  var ANIMATION_TIME_MS = 500;

  angular.module('blindMaps.map', [])

  .value('chroma', chroma)

  .value('$', jQuery)

  .value('$K', Kartograph)

  .value('colors', {
    'GOOD': '#0d0',
    'BAD': '#ff0000',
    'NEUTRAL': '#bbb',
    'BRIGHT_GRAY' : '#ddd'

  })

  .factory('getLayerConfig', function($log, chroma, colors, citySizeRatio) {
    var scale = chroma.scale([
        colors.BAD,
        '#ff4500',
        '#ffa500',
        '#ffff00',
        colors.GOOD
      ]);

    return function(config) {
      var layerConfig = {};
      layerConfig.bg = {
        'styles' : {
          'fill' : colors.BRIGHT_GRAY,
          'stroke-width' : STROKE_WIDTH,
          'transform' : ''
        }
      };

      layerConfig.states = {
        'styles' : {
          'fill' : function(d) {
            var state = config.states && config.states[d.name];
            return state ? scale(state.probability).brighten((1 - state.certainty) * 80).hex() : '#fff';
          },
          'stroke-width' : STROKE_WIDTH,
          'transform' : ''
        },
        'click' : function(data) {
          $log.log(data.name);
          if (config.click !== undefined) {
            config.click(data.name);
          }
        }
      };

      if (config.showTooltips) {
        layerConfig.states.tooltips = function(d) {
          var state = config.states && config.states[d.name];
          var name = ( state ?
            '<span class="label">' +
              '<i class="flag-' + d.name + '"></i> ' +
              state.name +
              '</span>' :
            '<br>Zatím neprocvičováno<br><br>');
          var description = (state ?
            '<div>' +
              '<i class="color-indicator" style="background-color :' +
              scale(state.probability).hex() + '"></i>' +
              ' Odhad znalosti : ' + Math.round(100 * state.probability) + '%</div>' :
            '');
          return [
            name + description,
            config.states[d.name] ? config.states[d.name].name : ''
          ];
        };
      }

      layerConfig.cities = angular.copy(layerConfig.states, {
        'mouseenter' : function(data, path) {
          path.toFront();
          var zoomRatio = 2.5 / citySizeRatio(data.population);
          var animAttrs = {
              'transform' : 's' + zoomRatio,
              'stroke-width' : zoomRatio * STROKE_WIDTH
            };
          path.animate(animAttrs, ANIMATION_TIME_MS / 2, '>');
        },
        'mouseleave' : function(data, path) {
          var animAttrs = {
              'transform' : '',
              'stroke-width' : STROKE_WIDTH
            };
          path.animate(animAttrs, ANIMATION_TIME_MS / 2, '>');
        }
      });

      layerConfig.rivers = angular.copy(layerConfig.states, {
        'styles' : {
          'stroke-width' : RIVER_WIDTH,
          'stroke' : WATER_COLOR,
          'transform' : ''
        },
        'mouseenter' : function(data, path) {
          var zoomRatio = 4;
          var animAttrs = { 'stroke-width' : zoomRatio * RIVER_WIDTH };
          path.animate(animAttrs, ANIMATION_TIME_MS / 2, '>');
        },
        'mouseleave' : function(data, path) {
          var animAttrs = { 'stroke-width' : RIVER_WIDTH };
          path.animate(animAttrs, ANIMATION_TIME_MS / 2, '>');
        }
      });
      layerConfig.lakes = angular.copy(layerConfig.cities, {});
      layerConfig.lakes.styles.fill = function(d) {
        var state = config.states && config.states[d.name];
        return state ? scale(state.probability).brighten((1 - state.certainty) * 80).hex() : WATER_COLOR;
      };
      return layerConfig;
    };
  })
  
  .factory('initLayers', function(getLayerConfig) {
    return function(map, config) {
      var layersConfig = getLayerConfig(config);
      var layersArray = [];
      for (var i in layersConfig) {
        map.addLayer(i, layersConfig[i]);
        var l = map.getLayer(i);
        if (l) {
          layersArray.push(l);
        }
      }
      var that = {
        hideLayer : function(layer) {
          var paths = layer ? layer.getPaths({}) : [];
          angular.forEach(paths, function(path) {
            path.svgPath.hide();
          });
        },
        showLayer : function(layer) {
          var paths = layer ? layer.getPaths({}) : [];
          angular.forEach(paths, function(path) {
            path.svgPath.show();
          });
        },
        getLayerBySlug: function(slug) {
          var slugToLayerId = {
            "city" : "cities",
            "river" : "rivers",
            "lake" : "lakes",
            "state" : "states",
            "region" : "states",
            "province" : "states",
            "region_cz" : "states",
            "region_it" : "states",
            "autonomous_comunity" : "states",
          }
          var ret;
          angular.forEach(layersArray, function(l) {
            if (l.id == slugToLayerId[slug]) {
              ret = l;
            }
          });
          return ret
        },
        getAll : function(){
          return layersArray;
        },
{'fraction_non_alphanumeric': 0.15361012561127624, 'fraction_numerical': 0.0076709176335219105, 'mean_word_length': 1.693698347107438, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 33, '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': '964991', 'n_tokens_mistral': 3307, 'n_tokens_neox': 3235, 'n_words': 569}