<commit_before>/******************************************************
*                  Composer                           *
*                                                     *
*  License:     MIT (see: ../LICENSE.txt)             *
*  Copyright:   2010 <NAME>                     *
*  Description: Visual data and flow control editor   *
******************************************************/
(function(window) {
  var lastId = 0;
  
  // Core composer factory
  var Composer = function(canvas, options, features) {
    
    // Require a canvas
    if (!canvas) {
      throw new Error("Composer requires a canvas element");
    }

    // sensible defaults for params
    features = features || [Renderer];

    var self = options = options || {},
        version = "0.0.1";

    // Augment self with new properties
    self.__defineGetter__("version", function() { return version; });
    self.__defineGetter__("canvas", function() { return canvas; });

    // Hang a reference to this instance on the target canvas
    canvas.composer = self;

    Composer.create = self.create = function(obj, options, parts) {
      var myId = lastId++;
      
      if (arguments.length === 2 && options && options.length) {
        parts = options;
      }
      parts = parts || [];
      var i   = 0,
          len = parts.length;

      obj.__defineGetter__("composer", function () { return self; });
      obj.__defineGetter__("id", function () { return myId; });

      // Based on the incomming parts array, build out self.
      for (i; i<len; i++) {
        parts[i](obj, options);
      }

      return obj;
    }
    
    return self.create(self, options, features);
  };
  
  Composer.key = {
    "control" : "ctrlKey",
    "shift"   : "shiftKey",
    "alt"     : "altKey",
    "meta"    : "metaKey"
  };

  // Base canvas renderer
  var Renderer = Composer.Renderer = function(obj, options) {
    var stack = [],
        self  = {fps: 30} || options,
        timer,
        context = obj.canvas.getContext("2d");

    // Add getters to the base object
    obj.__defineGetter__("renderer", function() { return self; });

    // Add getters to this object
    self.__defineGetter__("length", function() { return stack.length; });
    self.__defineGetter__("context", function() { return context; });

    self.sort = function(fn, save) {
      fn = fn || function(a, b) {
        if (a.z !== b.z) {
          return a.z - b.z;
        }
        return 0;
      };
      
      var sorted = stack.sort(fn);
      if (save) {
        stack = sorted;
      }
      return sorted;
    };

    self.add = function(renderable) {
      stack.push(renderable);
      //self.sort(false, true);
      renderable.renderer = self;
      return self;
    };

    self.remove = function(renderable) {
      var i=0; l=stack.length;

      for (i; i<l; i++) {
        if (stack[i] === renderable) {
          var start = stack.slice(0,i),
              rest  = stack.slice(i+1);
          start.push.apply(start, rest);
          stack = start;
          renderable.renderer = null;
        }
      }
      return self;
    };

    self.render = function(fn) {  
        context.fillStyle = "#000000";
        context.fillRect(0,0, obj.composer.canvas.width, obj.composer.canvas.height);

        if (fn) {
         fn();
        }
        
        var data = { relativeX: 0, relativeY: 0 };

        if (obj.hasOwnProperty("x") && obj.hasOwnProperty("y")) {
          data.relativeX = obj.x;
          data.relativeY = obj.y;
        }
        
        var i=0, l=stack.length;
        for (i; i<l; i++) {
          stack[i].render(data);
        }
    };

    self.start = function(fn) {
      timer = setInterval(function() {self.render(fn); }, 1000/self.fps);
    };
    
    self.stop = function() {
      clearInterval(timer);
      timer = false;
    };

    self.renderIndex = function(node) {
      var i=0, l=stack.length;
      for (i; i<l; i++) {
        if (stack[i].id === node.id) {
          return i;
        }
      }
      return -1;
    };

  };

  var Renderable = Composer.Renderable = function(obj, parts) {<commit_msg>added course grain frustnum culling of nodes<commit_after>/******************************************************
*                  Composer                           *
*                                                     *
*  License:     MIT (see: ../LICENSE.txt)             *
*  Copyright:   2010 <NAME>                     *
*  Description: Visual data and flow control editor   *
******************************************************/
(function(window) {
  var lastId = 0;
  
  // Core composer factory
  var Composer = function(canvas, options, features) {
    
    // Require a canvas
    if (!canvas) {
      throw new Error("Composer requires a canvas element");
    }

    // sensible defaults for params
    features = features || [Renderer];

    var self = options = options || {},
        version = "0.0.1";

    // Augment self with new properties
    self.__defineGetter__("version", function() { return version; });
    self.__defineGetter__("canvas", function() { return canvas; });

    // Hang a reference to this instance on the target canvas
    canvas.composer = self;

    Composer.create = self.create = function(obj, options, parts) {
      var myId = lastId++;
      
      if (arguments.length === 2 && options && options.length) {
        parts = options;
      }
      parts = parts || [];
      var i   = 0,
          len = parts.length;

      obj.__defineGetter__("composer", function () { return self; });
      obj.__defineGetter__("id", function () { return myId; });

      // Based on the incomming parts array, build out self.
      for (i; i<len; i++) {
        parts[i](obj, options);
      }

      return obj;
    }
    
    return self.create(self, options, features);
  };
  
  Composer.key = {
    "control" : "ctrlKey",
    "shift"   : "shiftKey",
    "alt"     : "altKey",
    "meta"    : "metaKey"
  };

  // Base canvas renderer
  var Renderer = Composer.Renderer = function(obj, options) {
    var stack = [], stackToRender = [],
        self  = {fps: 30} || options,
        timer,
        context = obj.canvas.getContext("2d");

    // Add getters to the base object
    obj.__defineGetter__("renderer", function() { return self; });

    // Add getters to this object
    self.__defineGetter__("length", function() { return stack.length; });
    self.__defineGetter__("context", function() { return context; });

    setInterval(function() {
      stackToRender = [];
      var i=0; l=stack.length;

    
      
      
      for (i; i<l; i++) {

        var ox = stack[i].x, oy = stack[i].y, size = stack[i].getSize(); 

        if (stack[i].composer.hasOwnProperty('x') && 
            stack[i].composer.hasOwnProperty('y') && 
            stack[i].composer  !== stack[i]) 
        {
          ox += stack[i].composer.x;
          oy += stack[i].composer.y;
        }        

        if (ox >= 0 && size.width + ox <= obj.canvas.width &&
            oy >= 0 && size.height + oy <= obj.canvas.height) {
          stackToRender.push(stack[i]);
        }
      }
    },100/self.fps);

    self.sort = function(fn, save) {
      fn = fn || function(a, b) {
        if (a.z !== b.z) {
          return a.z - b.z;
        }
        return 0;
      };
      
      var sorted = stack.sort(fn);
      if (save) {
        stack = sorted;
      }
      return sorted;
    };

    self.add = function(renderable) {
      stack.push(renderable);
      //self.sort(false, true);
      renderable.renderer = self;
      return self;
    };

    self.remove = function(renderable) {
      var i=0; l=stack.length;

      for (i; i<l; i++) {
        if (stack[i] === renderable) {
          var start = stack.slice(0,i),
              rest  = stack.slice(i+1);
          start.push.apply(start, rest);
          stack = start;
          renderable.renderer = null;
        }
      }
      return self;
    };

    self.render = function(fn) {  
        context.fillStyle = "#000000";
        context.fillRect(0,0, obj.composer.canvas.width, obj.composer.canvas.height);

        if (fn) {
         fn();
        }
        
        var data = { relativeX: 0, relativeY: 0 };

        if (obj.hasOwnProperty("x") && obj.hasOwnProperty("y")) {
          data.relativeX = obj.x;
          data.relativeY = obj.y;
        }
        
        var i=0, l=stackToRender.length;
        for (i; i<l; i++) {
          stackToRender[i].render(data);
        }
    };

    self.start = function(fn) {
      timer = setInterval(function() {self.render(fn); }, 1000/self.fps);
    };
    
    self.stop = function() {
      clearInterval(timer);
      timer = false;
    };

    self.renderIndex = function(node) {
      var i=0, l=stack.length;
      for (i; i<l; i++) {
        if (stack[i].id === node.id) {
          return i;
        }
      }
      return -1;
    };

  };

  var Renderable = Composer.Renderable = function(obj, parts) {
{'fraction_non_alphanumeric': 0.16600044414834556, 'fraction_numerical': 0.008216744392627137, 'mean_word_length': 1.8208581271531474, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '179090', 'n_tokens_mistral': 2776, 'n_tokens_neox': 2695, 'n_words': 643}