<commit_before>'use strict';

angular.module('vleApp')
  .directive('vlPlot', function(vg, $timeout) {
    var counter = 0;

    return {
      templateUrl: 'components/vlplot/vlplot.html',
      restrict: 'E',
      scope: {
        'vgSpec':'=',
        'maxHeight':'='
      },
      replace: true,
      link: function(scope, element) {
        scope.visId = (counter++);
        scope.hoverAction = null;
        scope.mouseover = function() {
          scope.hoverAction = $timeout(function(){
            scope.hoverFocus = true;
          }, 500);
        };

        scope.mouseout = function() {
          $timeout.cancel(scope.hoverAction);
          scope.hoverFocus = scope.unlocked = false;
        };

        var view;
        scope.$watch('vgSpec',function(spec) {
          if (!spec) {
            if (view) {
              view.off('mouseover');
            }
            return;
          }
          var elem = element;
          if (elem) {
            vg.parse.spec(spec, function(chart) {
              view = null;
              view = chart({el: elem[0], renderer: 'canvas'});
              view.update();
              view.on('mouseover', function(event, item) {
                // TODO: Hanchuan please create tooltip from this
                console.log(item.datum.data);
              });
            });
          } else {
            console.error('can not find vis element');
          }
        });
      }
    };
  });<commit_msg>automatically determine renderer for vlplot<commit_after>'use strict';

angular.module('vleApp')
  .directive('vlPlot', function(vg, $timeout) {
    var counter = 0;
    var MAX_CANVAS_SIZE = 32767, MAX_CANVAS_AREA = 268435456;

    function getRenderer(spec) {
      // use canvas by default but use svg if the visualization is too big
      if (spec.width > MAX_CANVAS_SIZE || spec.height > MAX_CANVAS_SIZE || spec.width*spec.height > MAX_CANVAS_AREA) {
        return 'svg';
      }
      return 'canvas';
    }

    return {
      templateUrl: 'components/vlplot/vlplot.html',
      restrict: 'E',
      scope: {
        'vgSpec':'=',
        'maxHeight':'='
      },
      replace: true,
      link: function(scope, element) {
        scope.visId = (counter++);
        scope.hoverAction = null;
        scope.mouseover = function() {
          scope.hoverAction = $timeout(function(){
            scope.hoverFocus = true;
          }, 500);
        };

        scope.mouseout = function() {
          $timeout.cancel(scope.hoverAction);
          scope.hoverFocus = scope.unlocked = false;
        };

        var view;
        scope.$watch('vgSpec',function(spec) {
          if (!spec) {
            if (view) {
              view.off('mouseover');
            }
            return;
          }
          var elem = element;
          if (elem) {
            vg.parse.spec(spec, function(chart) {
              view = null;
              view = chart({el: elem[0], renderer: getRenderer(spec)});
              view.update();
              view.on('mouseover', function(event, item) {
                // TODO: Hanchuan please create tooltip from this
                console.log(item.datum.data);
              });
            });
          } else {
            console.error('can not find vis element');
          }
        });
      }
    };
  });
{'fraction_non_alphanumeric': 0.1341756919374248, 'fraction_numerical': 0.007220216606498195, 'mean_word_length': 1.5755228505034857, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '4099681', 'n_tokens_mistral': 978, 'n_tokens_neox': 936, 'n_words': 195}