<commit_before>App.directive('choropleth', function($http) {

  // Clone the loader
  var loader = $("#loader").clone();
  var hasLoader = loader.length > 0;

  // If loader is not present, do not hide the choropleth
  if (hasLoader) {
      var choropleth = $("#choropleth");
          choropleth.append(loader.show());
  }

  // Width and height of the SVG
  var width = 600,
      height = 600;

  // D3 Array Object where the data is stored as key : value
  var rateById = d3.map();

  // Projection for Map
  var projection = d3.geo.transverseMercator()
      .rotate([100 + 20 / 60, -29 - 40 / 60])
      .scale(3000)
      .translate([285, 380]);

  // Declare the path object
  var path = d3.geo.path()
        .projection(projection);

  return {
    restrict: "E",
    scope: true,
    link: function (scope, element, attrs) {
      var scale, svg, $svg, g;

      // D3 SVG Element added to the DOM
      svg = d3.select(element[0]).append("svg")
        .attr("width", width)
        .attr("height", height);

      // JQuery Object for manipulating the SVG's behavior
      $svg = $('svg');

      // Hide the loader only if the loader object exists
      hasLoader ? $svg.hide() : false;

      // Watch for change in the Entity selection
      scope.$watch('choropleth.selection.cartogram_entity', function(newVals, oldVals) {
          if (newVals !== oldVals) {
              var records = scope.dataset.records;
              records.forEach(function(record) {
                  if (newVals === record.cartogram_entity) {
                      scope.choropleth.selection = JSON.parse(JSON.stringify(record));
                  }
              });
          }
      });

      // Watch for changes in the Choropleth members items and in the selected Palette
      scope.$watchCollection('[choropleth.scale, choropleth.data_classes, palette.class_name]', function(newVals, oldVals) {
        setScale(newVals[0]);
        update(scope.dataset.records);
      });

      // Determines correct scale for the current ScaleID
      function setScale(scaleId) {
        var range = scope.choropleth.data_classes;

        switch(scaleId) {
          // Quantize
          case 0:
            if (scope.palette && scope.choropleth.data_classes) {
              var min = scope.dataset.domain.min,
                  max = scope.dataset.domain.max;

              scale = d3.scale.quantize()
                .domain([min, max])
                .range(d3.range(range).map(function(i) {
                  return colorbrewer[scope.palette.class_name][range][i];
                }));
            }
            break;

          // Non-Quantize
          case 1:
            if (scope.palette && range) {
              var palette = colorbrewer[scope.palette.class_name][range];

              var color1 = palette[0];
                  color2 = palette[palette.length -1];

              var min = scope.dataset.domain.non_zero_min,
                  max = scope.dataset.domain.non_zero_max;

              scale = d3.scale.log()
                .domain([min, max])
                .range([color1, color2])
                .clamp(true);
            }
            break;

          // No scale
          default:
            scale = function() {
              return "none";
            };
        }
        return scale;
      }

      //Updates the SVG/Path elements accordingly
      function update(data) {
        svg.select("#entities").selectAll("path")
          .attr('fill', function(d) {
            return fill(d);
          });
      }

      // Helper function to determine the fill color base on the dataset record value
      function fill(d) {
         value = rateById.get(d.properties.fips);
         if (value === null) {
           return 'none';
         }
         return scale(rateById.get(d.properties.fips));
      }

      // Performs the initial drawing operation for the Choropleth
      function ready(texas) {
        svg.append("g")
          .attr("id", "entities")
        .selectAll("path")
         .data(topojson.feature(texas, texas.objects.counties).features)
        .enter().append("path")
          .attr("id", function(d) { return d.properties.fips; })
          .attr("fill", function(d) { return fill(d); })
          .style('cursor', 'pointer')
          .on("click", function(d) {
            scope.choropleth.selection.cartogram_entity = d.properties.fips;
            scope.$apply();
          })
          .attr("d", path);

        // Show the loader if it exists
        if (hasLoader) {
            choropleth.find('#loader').fadeOut('slow', function() {
              this.remove();
              $('svg').fadeIn('slow');
            });
        }
      }

      // Wrapper function for ready()
      // Grabs the TopoJson file and draws the Choropleth if the
      // call is successful<commit_msg>Choropleth selection now triggered by mouseenter event.<commit_after>App.directive('choropleth', function($http) {

  // Clone the loader
  var loader = $("#loader").clone();
  var hasLoader = loader.length > 0;

  // If loader is not present, do not hide the choropleth
  if (hasLoader) {
      var choropleth = $("#choropleth");
          choropleth.append(loader.show());
  }

  // Width and height of the SVG
  var width = 600,
      height = 600;

  // D3 Array Object where the data is stored as key : value
  var rateById = d3.map();

  // Projection for Map
  var projection = d3.geo.transverseMercator()
      .rotate([100 + 20 / 60, -29 - 40 / 60])
      .scale(3000)
      .translate([285, 380]);

  // Declare the path object
  var path = d3.geo.path()
        .projection(projection);

  return {
    restrict: "E",
    scope: true,
    link: function (scope, element, attrs) {
      var scale, svg, $svg, g;

      // D3 SVG Element added to the DOM
      svg = d3.select(element[0]).append("svg")
        .attr("width", width)
        .attr("height", height);

      // JQuery Object for manipulating the SVG's behavior
      $svg = $('svg');

      // Hide the loader only if the loader object exists
      hasLoader ? $svg.hide() : false;

      // Watch for change in the Entity selection
      scope.$watch('choropleth.selection.cartogram_entity', function(newVals, oldVals) {
          if (newVals !== oldVals) {
              var records = scope.dataset.records;
              records.forEach(function(record) {
                  if (newVals === record.cartogram_entity) {
                      scope.choropleth.selection = JSON.parse(JSON.stringify(record));
                  }
              });
          }
      });

      // Watch for changes in the Choropleth members items and in the selected Palette
      scope.$watchCollection('[choropleth.scale, choropleth.data_classes, palette.class_name]', function(newVals, oldVals) {
        setScale(newVals[0]);
        update(scope.dataset.records);
      });

      // Determines correct scale for the current ScaleID
      function setScale(scaleId) {
        var range = scope.choropleth.data_classes;

        switch(scaleId) {
          // Quantize
          case 0:
            if (scope.palette && scope.choropleth.data_classes) {
              var min = scope.dataset.domain.min,
                  max = scope.dataset.domain.max;

              scale = d3.scale.quantize()
                .domain([min, max])
                .range(d3.range(range).map(function(i) {
                  return colorbrewer[scope.palette.class_name][range][i];
                }));
            }
            break;

          // Non-Quantize
          case 1:
            if (scope.palette && range) {
              var palette = colorbrewer[scope.palette.class_name][range];

              var color1 = palette[0];
                  color2 = palette[palette.length -1];

              var min = scope.dataset.domain.non_zero_min,
                  max = scope.dataset.domain.non_zero_max;

              scale = d3.scale.log()
                .domain([min, max])
                .range([color1, color2])
                .clamp(true);
            }
            break;

          // No scale
          default:
            scale = function() {
              return "none";
            };
        }
        return scale;
      }

      //Updates the SVG/Path elements accordingly
      function update(data) {
        svg.select("#entities").selectAll("path")
          .attr('fill', function(d) {
            return fill(d);
          });
      }

      // Helper function to determine the fill color base on the dataset record value
      function fill(d) {
         value = rateById.get(d.properties.fips);
         if (value === null) {
           return 'none';
         }
         return scale(rateById.get(d.properties.fips));
      }

      // Performs the initial drawing operation for the Choropleth
      function ready(texas) {
        svg.append("g")
          .attr("id", "entities")
        .selectAll("path")
         .data(topojson.feature(texas, texas.objects.counties).features)
        .enter().append("path")
          .attr("id", function(d) { return d.properties.fips; })
          .attr("fill", function(d) { return fill(d); })
          .style('cursor', 'pointer')
          .on("mouseenter", function(d) {
            scope.choropleth.selection.cartogram_entity = d.properties.fips;
            scope.$apply();
          })
          .on("mouseleave", function(d) {
            scope.choropleth.selection = {};
            scope.$apply();
          })
          .attr("d", path);

        // Show the loader if it exists
        if (hasLoader) {
            choropleth.find('#loader').fadeOut('slow', function() {
              this.remove();
              $('svg').fadeIn('slow');
            });
        }
      }

      // Wrapper function for ready()
      // Grabs the TopoJson file and draws the Choropleth if the
      // call is successful
{'fraction_non_alphanumeric': 0.12622635784363306, 'fraction_numerical': 0.009912005664003236, 'mean_word_length': 1.7345132743362832, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '194844', 'n_tokens_mistral': 2919, 'n_tokens_neox': 2750, 'n_words': 679}