<commit_before>export default function(d3) {
  return function(id) {
    var autozoom = true;
    var transitionDuration = 500; // ms
    var pi = Math.PI;
    var tau = 2 * pi;
    var radius = d3.scalePow()
        .domain([1, 10])
        .range([3, 15]);

    var strokeWidth = 0.5;

    var wrapper = d3.select(id);
    var width = parseInt(wrapper.style('width').replace('px', ''), 10);
    var height = parseInt(wrapper.style('height').replace('px', ''), 10);
    var size = [width, height];

    var tilesConfig = {
      url: 'https://maps.wikimedia.org/osm-intl/',
      extension: '.png',
      switchXY: false,
      factor: 256
    };

    var projection = d3.geoMercator()
        .scale(1 / tau)
        .translate([0, 0]);

    var path = d3.geoPath()
        .projection(projection);  

    var tile = d3.tile()
        .size(size);

    var zoom = d3.zoom()
        .scaleExtent([1 << 9, 1 << 14])
        .on('zoom', zoomed);

    var svg = wrapper.select('svg');
    
    if (svg.empty()) {
      svg = wrapper.append('svg')
          .classed('infovyz-map', true)
          .attr('width', width)
          .attr('height', height);
    }

    var raster = svg.append('g').classed('tiles', true);

    var vector = svg.append('g').classed('overlay', true);

    var previousTransform;
    function zoomed() {
      var transform = previousTransform = d3.event.transform;

      var tiles = tile
          .scale(transform.k)
          .translate([transform.x, transform.y])
          ();

      vector
        .attr('transform', transform);
      
      vector.selectAll('circle')
        .attr('transform', function(d) { return 'translate(' + projection(d.geometry.coordinates) + ')'; })
        .attr('r', function(d) {
          return radius(d.properties.value || 1) / transform.k;
        })
        .attr('stroke-width', strokeWidth / transform.k);

      var image = raster
        .attr('transform', stringify(tiles.scale, tiles.translate))
        .selectAll('image')
        .data(tiles, function(d) { return d; });

      image
        .exit().remove();

      image.enter().append('image')
          .attr('xlink:href', function(d) { return tilesConfig.url + d[2] + '/' + d[0] + '/' + d[1] + tilesConfig.extension; })
          .attr('x', function(d) { return d[0] * tilesConfig.factor; })
          .attr('y', function(d) { return d[1] * tilesConfig.factor; })
          .attr('width', tilesConfig.factor)
          .attr('height', tilesConfig.factor);
    }

    function stringify(scale, translate) {
      var k = scale / tilesConfig.factor;
      var r = scale % 1 ? Number : Math.round;
      return 'translate(' + r(translate[0] * scale) + ',' + r(translate[1] * scale) + ') scale(' + k + ')';
    }

    var transformData = function(d) {
      return {
        type: 'FeatureCollection',
        features: d.map(function(el) {
          return {
            type: 'Feature',
            id: el.id,
            properties: el,
            geometry: {type: 'Point', coordinates: [+el.longitude, +el.latitude]}
          };
        })
      };
    };

    var map = function(d) {
      var newWidth = parseInt(wrapper.style('width').replace('px', ''), 10);
      var newHeight = parseInt(wrapper.style('height').replace('px', ''), 10);
      var _transitionDuration = transitionDuration;

      if (width !== newWidth || height !== newHeight) {
        width = newWidth;
        height = newHeight;
        _transitionDuration = 0;
        svg
          .attr('width', width)
          .attr('height', height);
      }

      if (typeof vector.datum() === 'undefined') {
        _transitionDuration = 0;
      }
      var data = (typeof d !== 'undefined') ? transformData(d) : vector.datum();

      // Compute the projected center.
      var bounds  = path.bounds(data);
      var bx = bounds[1][0] - bounds[0][0];
      var by = bounds[1][1] - bounds[0][1];
      var tx = (bounds[0][0] + bounds[1][0]) / 2;
      var ty = (bounds[0][1] + bounds[1][1]) / 2;
      var scale = 0.8 * Math.min(width / bx, height / by);

      svg.call(zoom);

      if (!autozoom && typeof vector.datum() === 'undefined') {
        svg
          .call(
            zoom.transform,
            d3.zoomIdentity
              .translate(width / 2, height / 2)
              .scale(1 << 10)
              .translate(0, 0)
          );
      }

      if (autozoom) {
        svg
          .transition()
          .duration(_transitionDuration)
          .call(
            zoom.transform,
            d3.zoomIdentity
              .translate(width / 2, height / 2)
              .scale(scale)
              .translate(-tx, -ty)
          );
      }

      vector.datum(data);

      radius.domain(d3.extent(data.features.map(function(f) {
        return f.properties.value || 1;
      })));

      var bubble = vector
        .selectAll('circle')
        .data(data.features, function(d) { return d.id; });

      bubble
        .exit()
        .transition()
        .attr('r', 0)
        .attr('stroke-width', 0)
        .remove();

      scale = (previousTransform) ? previousTransform.k : scale;
      bubble.enter().append('circle')
        .attr('transform', function(d) { return 'translate(' + projection(d.geometry.coordinates) + ')'; })
        .attr('r', 0)
        .attr('stroke-width', 0)
        .transition()
        .attr('r', function(d) {<commit_msg>Fixes an issue with calling map() without providing any data.<commit_after>export default function(d3) {
  return function(id) {
    var autozoom = true;
    var transitionDuration = 500; // ms
    var pi = Math.PI;
    var tau = 2 * pi;
    var radius = d3.scalePow()
        .domain([1, 10])
        .range([3, 15]);

    var strokeWidth = 0.5;

    var wrapper = d3.select(id);
    var width = parseInt(wrapper.style('width').replace('px', ''), 10);
    var height = parseInt(wrapper.style('height').replace('px', ''), 10);
    var size = [width, height];

    var tilesConfig = {
      url: 'https://maps.wikimedia.org/osm-intl/',
      extension: '.png',
      switchXY: false,
      factor: 256
    };

    var projection = d3.geoMercator()
        .scale(1 / tau)
        .translate([0, 0]);

    var path = d3.geoPath()
        .projection(projection);  

    var tile = d3.tile()
        .size(size);

    var zoom = d3.zoom()
        .scaleExtent([1 << 9, 1 << 14])
        .on('zoom', zoomed);

    var svg = wrapper.select('svg');
    
    if (svg.empty()) {
      svg = wrapper.append('svg')
          .classed('infovyz-map', true)
          .attr('width', width)
          .attr('height', height);
    }

    var raster = svg.append('g').classed('tiles', true);

    var vector = svg.append('g').classed('overlay', true);

    var previousTransform;
    function zoomed() {
      var transform = previousTransform = d3.event.transform;

      var tiles = tile
          .scale(transform.k)
          .translate([transform.x, transform.y])
          ();

      vector
        .attr('transform', transform);
      
      vector.selectAll('circle')
        .attr('transform', function(d) { return 'translate(' + projection(d.geometry.coordinates) + ')'; })
        .attr('r', function(d) {
          return radius(d.properties.value || 1) / transform.k;
        })
        .attr('stroke-width', strokeWidth / transform.k);

      var image = raster
        .attr('transform', stringify(tiles.scale, tiles.translate))
        .selectAll('image')
        .data(tiles, function(d) { return d; });

      image
        .exit().remove();

      image.enter().append('image')
          .attr('xlink:href', function(d) { return tilesConfig.url + d[2] + '/' + d[0] + '/' + d[1] + tilesConfig.extension; })
          .attr('x', function(d) { return d[0] * tilesConfig.factor; })
          .attr('y', function(d) { return d[1] * tilesConfig.factor; })
          .attr('width', tilesConfig.factor)
          .attr('height', tilesConfig.factor);
    }

    function stringify(scale, translate) {
      var k = scale / tilesConfig.factor;
      var r = scale % 1 ? Number : Math.round;
      return 'translate(' + r(translate[0] * scale) + ',' + r(translate[1] * scale) + ') scale(' + k + ')';
    }

    var transformData = function(d) {
      return {
        type: 'FeatureCollection',
        features: d.map(function(el) {
          return {
            type: 'Feature',
            id: el.id,
            properties: el,
            geometry: {type: 'Point', coordinates: [+el.longitude, +el.latitude]}
          };
        })
      };
    };

    var map = function(d) {
      var newWidth = parseInt(wrapper.style('width').replace('px', ''), 10);
      var newHeight = parseInt(wrapper.style('height').replace('px', ''), 10);
      var _transitionDuration = transitionDuration;

      if (width !== newWidth || height !== newHeight) {
        width = newWidth;
        height = newHeight;
        _transitionDuration = 0;
        svg
          .attr('width', width)
          .attr('height', height);
      }

      if (typeof vector.datum() === 'undefined') {
        _transitionDuration = 0;
      }
      var data = (typeof d !== 'undefined') ? transformData(d) : vector.datum();

      // Compute the projected center.
      var bounds  = path.bounds(data);
      var bx = bounds[1][0] - bounds[0][0];
      var by = bounds[1][1] - bounds[0][1];
      var tx = (bounds[0][0] + bounds[1][0]) / 2;
      var ty = (bounds[0][1] + bounds[1][1]) / 2;
      var scale = 0.8 * Math.min(width / bx, height / by);

      svg.call(zoom);

      if (!autozoom && typeof vector.datum() === 'undefined') {
        svg
          .call(
            zoom.transform,
            d3.zoomIdentity
              .translate(width / 2, height / 2)
              .scale(1 << 10)
              .translate(0, 0)
          );
      }

      if (autozoom) {
        svg
          .transition()
          .duration(_transitionDuration)
          .call(
            zoom.transform,
            d3.zoomIdentity
              .translate(width / 2, height / 2)
              .scale(scale)
              .translate(-tx, -ty)
          );
      }

      vector.datum(data);

      var features = (typeof data !== 'undefined') ? data.features : [];

      radius.domain(d3.extent(features.map(function(f) {
        return f.properties.value || 1;
      })));

      var bubble = vector
        .selectAll('circle')
        .data(features, function(d) { return d.id; });

      bubble
        .exit()
        .transition()
        .attr('r', 0)
        .attr('stroke-width', 0)
        .remove();

      scale = (previousTransform) ? previousTransform.k : scale;
      bubble.enter().append('circle')
        .attr('transform', function(d) { return 'translate(' + projection(d.geometry.coordinates) + ')'; })
        .attr('r', 0)
        .attr('stroke-width', 0)
        .transition()
        .attr('r', function(d) {
{'fraction_non_alphanumeric': 0.1673105224429728, 'fraction_numerical': 0.016004415011037526, 'mean_word_length': 1.956226209896683, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '4248409', 'n_tokens_mistral': 3459, 'n_tokens_neox': 3301, 'n_words': 725}