integ/js/vs/_vs.flocculate.js
author Anthony Ly <anthonyly.com@gmail.com>
Fri, 12 Apr 2013 15:08:00 +0200
changeset 28 84719280c84d
child 53 88666afffe6b
permissions -rwxr-xr-x
import VS lib
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     1
(function ($) {
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     2
//console.log("flocullate loaded")
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     3
$.fn._vs.flocculate = {
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     4
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     5
    buffer:[], 
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     6
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     7
    init:function(_this){
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     8
      console.log("init flocculate",_this)
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     9
      // create one buffer by data model (categorys)
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    10
      for (var i =0; i<_this.settings.data.model.length; i++) {
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    11
        this.buffer[i] = []
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    12
        console.log(i)
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    13
      };
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    14
    },
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    15
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    16
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    17
    // OLD STUFF NOT USED  
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    18
    addtobuffer:function(_this,token){
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    19
      c = token.attr("category")
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    20
      bufferSize =_this.settings.sedimentation.flocculate.bufferSize
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    21
      this.buffer[c].push(token)
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    22
      _this.decay.tokens.splice(_this.decay.tokens.indexOf(token),1)
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    23
      //
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    24
      token.attr("callback","bufferFlocculation",token)
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    25
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    26
      if(this.buffer[c].length > bufferSize){
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    27
        //console.log("order")
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    28
        this.update(_this,c,bufferSize)
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    29
      }
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    30
    },
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    31
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    32
    destroyIt:function(_this,token){
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    33
      token.attr("callback","flocculation",token) // callback 
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    34
      token.attr("state",2)                       // flocullating state
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    35
      //token.myobj=null
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    36
     // console.log(token.attr('ID'))
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    37
      var del = _this.world.DestroyBody(token.myobj.GetBody());
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    38
      
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    39
      return del
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    40
    },
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    41
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    42
    update:function(_this,c,nbtokens) {
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    43
      if(_this.settings.sedimentation.flocculate.number==1){
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    44
       while(this.buffer[c].length > nbtokens) {
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    45
         var token = this.buffer[c].shift();
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    46
         this.destroyIt(_this,token)
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    47
       }
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    48
      }else {
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    49
        while(this.buffer[c].length > _this.settings.sedimentation.flocculate.number) {
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    50
           var token = this.buffer[c].shift();
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    51
           this.destroyIt(_this,token)
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    52
        }
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    53
      }
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    54
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    55
    },
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    56
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    57
    disapear:function(_this,token){
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    58
      ///draft doesn't work
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    59
       window.setInterval(
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    60
        function(){token.update(self);},
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    61
         self.settings.options.refresh/2
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    62
        );
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    63
    },
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    64
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    65
    all:function(_this) {
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    66
      // TODO destroy all 
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    67
      console.log(_this.settings.data)
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    68
      for (var i = _this.decay.tokens - 1; i >= 0; i--) {
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    69
        console.log(_this.decay.tokens)
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    70
        this.update(_this,i,_this.tokens.length);      
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    71
      };
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    72
    },
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    73
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    74
    strategy:function(){
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    75
       if(flocullateBuffer.length>0){
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    76
         if (chart.flocullate.strategy=="Size" 
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    77
           && flocullateBuffer.length>=chart.flocullate.bufferSize){
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    78
           console.log(flocullateBuffer.length);
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    79
           flocullateByArray(flocullateBuffer);
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    80
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    81
         }else if (chart.flocullate.strategy=="Time") {
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    82
  
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    83
         }else if (chart.flocullate.strategy=="Height") {
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    84
  
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    85
         };  
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    86
    }
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    87
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    88
}}    
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    89
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    90
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    91
84719280c84d import VS lib
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    92
})(jQuery);