{"size": 1639, "ext": "js", "max_stars_repo_path": "src/github-contributions.js", "max_stars_repo_name": "portokallidis/angular-github-contributions", "max_stars_repo_stars_event_min_datetime": "2016-07-15T14:01:39.000Z", "max_stars_repo_stars_event_max_datetime": "2016-07-15T14:01:39.000Z", "max_issues_repo_path": "src/github-contributions.js", "max_issues_repo_name": "portokallidis/angular-github-contributions", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/github-contributions.js", "max_forks_repo_name": "portokallidis/angular-github-contributions", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 29.8, "max_line_length": 96, "alphanum_fraction": 0.552776083}
'use strict';

angular.module('np.github-contributions', []).directive('githubContributions', function($http) {
  return {
    restrict: 'E',
    link: function(scope, ielem, attr) {

      var options = attr.options || {};
      var username = attr.username;
      var graphCssClass = "github-contributions-graph";
      if (!username) {
        console.error("No username supplied");
        return;
      }
      var proxy = options.proxy || function(url) {
        return "https://urlreq.appspot.com/req?method=GET&url=" + url;
      };
      $http.get(proxy("https://github.com/" + username), {
        cache: true
      }).then(function(res) {
        // remove text svg tags
        var removeText=new RegExp(/<text[\s\S]*(.*?)<\/text>/,"g");
        
        // match graph
        var matchGraph=new RegExp(/<div class=\"js-calendar-graph[\s\S]*(.*?)<\/div>/,"g");
        
        var graphtext = res.data.match(matchGraph);
        
        if (!graphtext) {
          console.debug("No graph found, check github");
          return;
        }
        var elem = document.createElement('div');
        elem.innerHTML = graphtext[0].toString().replace(removeText,"");
        
        // contributions graph - scalable!  
        var graph = elem.querySelector('svg');
        var gW = graph.getAttribute("width");
        var gH = graph.getAttribute("height");
        graph.setAttribute("width", "100%");
        graph.setAttribute("height", "100%");
        graph.setAttribute("viewBox", "14 8 " + gW + " " + gH);
        graph.setAttribute("class", graphCssClass);
        ielem.append(graph);

      });




    }
  };


});