<commit_before>'use strict';

angular.module('ngDependencyGraph')
  .directive('dgGraph', function($rootScope, $timeout, appDeps, dev, Component, Const, currentView) {

    return {
      link: function(scope, elm, attrs) {

        function update() {
          var currentGraph = currentView.graph;
          force.nodes(currentGraph.nodes)
            .links(currentGraph.links);

          links = svg.selectAll('.link')
            .data(force.links(), _.property('_id'));

          links.enter()
            .insert("line", ":first-child") // this needs to be rendered first -> prepend
            .attr('class', 'link')
            .attr('marker-end', 'url(#end)');
          links.exit().remove();

          nodes = svg.selectAll('.node')
            .data(force.nodes(), _.property('_id'));

          /**
           * Nodes enter
           */
          nodesEnter = nodes
            .enter()
            .append('g')
            .attr('class', _.property('type'))
            .classed('node', true)
            .on('mousedown', nodeClick)
            .call(force.drag);

          nodesEnter.append('circle');
            // .attr('r', 8);

          nodesEnter.append('text')
            .attr('x', 12)
            .attr('dy', '.35em')
            .text(function(d) {
              return d.name;
            });

          /**
           * Nodes update
           */
          nodes
            .classed('selected', function(d) {
              return d === currentView.selectedNode;
            });


          /**
           * Nodes remove
           */
          nodes.exit().remove();

          force
            .size([width, height])
            .linkDistance(80)
            .charge(-400)
            .on('tick', tick)
            .start();
        }


        function tick() {
          links
            .attr('x1', function(d) {
              return d.source.x;
            })
            .attr('y1', function(d) {
              return d.source.y;
            })
            .attr('x2', function(d) {
              return d.target.x;
            })
            .attr('y2', function(d) {
              return d.target.y;
            });

          nodes
            .attr('transform', function(d) {
              return 'translate(' + d.x + ',' + d.y + ')';
            });
        }

        function nodeClick(d) {
          $rootScope.$apply(function() {
            currentView.chooseNode(d);
          });
        }

        function zoomListener() {
          var tmp = svg;

          // add transtion if user is not panning (move) or zooming (wheel)
          if (!d3.event.sourceEvent || ['mousemove', 'wheel'].indexOf(d3.event.sourceEvent.type) === -1) {
            tmp = tmp.transition();
          }
          tmp.attr('transform',
            'translate(' + d3.event.translate + ')' +
            ' scale(' + d3.event.scale + ')');
        }   


        scope.$on('chooseNode', function(event, d) {
          if (force.nodes().indexOf(d) === -1) { // if d is not present, it's not visible
            return;
          }
          var x = (width/2 - d.x);
          var y = (height/2 - d.y);<commit_msg>fix zoom when scaled<commit_after>'use strict';

angular.module('ngDependencyGraph')
  .directive('dgGraph', function($rootScope, $timeout, appDeps, dev, Component, Const, currentView) {

    return {
      link: function(scope, elm, attrs) {

        function update() {
          var currentGraph = currentView.graph;
          force.nodes(currentGraph.nodes)
            .links(currentGraph.links);

          links = svg.selectAll('.link')
            .data(force.links(), _.property('_id'));

          links.enter()
            .insert("line", ":first-child") // this needs to be rendered first -> prepend
            .attr('class', 'link')
            .attr('marker-end', 'url(#end)');
          links.exit().remove();

          nodes = svg.selectAll('.node')
            .data(force.nodes(), _.property('_id'));

          /**
           * Nodes enter
           */
          nodesEnter = nodes
            .enter()
            .append('g')
            .attr('class', _.property('type'))
            .classed('node', true)
            .on('mousedown', nodeClick)
            .call(force.drag);

          nodesEnter.append('circle');
            // .attr('r', 8);

          nodesEnter.append('text')
            .attr('x', 12)
            .attr('dy', '.35em')
            .text(function(d) {
              return d.name;
            });

          /**
           * Nodes update
           */
          nodes
            .classed('selected', function(d) {
              return d === currentView.selectedNode;
            });


          /**
           * Nodes remove
           */
          nodes.exit().remove();

          force
            .size([width, height])
            .linkDistance(80)
            .charge(-400)
            .on('tick', tick)
            .start();
        }


        function tick() {
          links
            .attr('x1', function(d) {
              return d.source.x;
            })
            .attr('y1', function(d) {
              return d.source.y;
            })
            .attr('x2', function(d) {
              return d.target.x;
            })
            .attr('y2', function(d) {
              return d.target.y;
            });

          nodes
            .attr('transform', function(d) {
              return 'translate(' + d.x + ',' + d.y + ')';
            });
        }

        function nodeClick(d) {
          $rootScope.$apply(function() {
            currentView.chooseNode(d);
          });
        }

        function zoomListener() {
          var tmp = svg;

          // add transtion if user is not panning (move) or zooming (wheel)
          if (!d3.event.sourceEvent || ['mousemove', 'wheel'].indexOf(d3.event.sourceEvent.type) === -1) {
            tmp = tmp.transition();
          }
          tmp.attr('transform',
            'translate(' + d3.event.translate + ') ' +
            ' scale(' + d3.event.scale + ')');
        }   


        scope.$on('chooseNode', function(event, d) {
          if (force.nodes().indexOf(d) === -1) { // if d is not present, it's not visible
            return;
          }
          var scale = zoom.scale();

          var x = -(scale * d.x - width/2);
          var y = -(scale * d.y - height/2);
{'fraction_non_alphanumeric': 0.1579278853723823, 'fraction_numerical': 0.006928042827901118, 'mean_word_length': 1.2972875226039784, 'pattern_counts': {'":': 2, '<': 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': '4910536', 'n_tokens_mistral': 1811, 'n_tokens_neox': 1744, 'n_words': 347}