src/js/widgets/sparklineWidget.js
branchpopcorn-port
changeset 600 4e669328ab6d
parent 532 5249bb0cd964
child 644 492d3c8d776a
equal deleted inserted replaced
599:a5a5e70d46a7 600:4e669328ab6d
    25   /* we suppose that a column is 5 pixels wide */
    25   /* we suppose that a column is 5 pixels wide */
    26   var num_columns = (this.selector.width()) / 10;
    26   var num_columns = (this.selector.width()) / 10;
    27   var duration = +this._serializer.currentMedia().meta["dc:duration"];
    27   var duration = +this._serializer.currentMedia().meta["dc:duration"];
    28   var time_step = duration / num_columns; /* the time interval between two columns */
    28   var time_step = duration / num_columns; /* the time interval between two columns */
    29   var results = [];
    29   var results = [];
    30   var i = 0; /* the index in the loop */
    30   var i = 0; /* the index in the loop */  
    31 
    31 
    32   /* this algorithm makes one assumption : that the array is sorted 
    32   /* this algorithm makes one assumption : that the array is sorted 
    33      (it's done for us by the JSONSerializer). We go through the array 
    33      (it's done for us by the JSONSerializer). We go through the array 
    34      and count how many comments fall within a peculiar time piece.
    34      and count how many comments fall within a peculiar time piece.
    35      As i is preserved between each iteration, it's O(n).
    35      As i is preserved between each iteration, it's O(n).
    36   */
    36   */
    37   for(var j = 0; j < num_columns; j++) {
    37   
       
    38   for(var j = 0; j < num_columns && i < this._serializer._data.annotations.length; j++) {    
    38     var count = 0;
    39     var count = 0;
    39     
       
    40     var annotation_begin = +(this._serializer._data.annotations[i].begin);
    40     var annotation_begin = +(this._serializer._data.annotations[i].begin);
    41     
    41     
    42     while(annotation_begin >= j * time_step && annotation_begin <= (j + 1) * time_step ) {
    42     while(annotation_begin >= j * time_step && annotation_begin <= (j + 1) * time_step ) {
    43       count++;
    43       count++;
    44       i++;
    44       i++;
    49       
    49       
    50     }
    50     }
    51     
    51     
    52     results.push(count);
    52     results.push(count);
    53   }
    53   }
       
    54 
    54   
    55   
    55   this.selector.append(templ);
    56   this.selector.append(templ);
    56   this.selector.find(".Ldt-sparkLine").css("background", "#c7c8cc");
    57   this.selector.find(".Ldt-sparkLine").css("background", "#c7c8cc");
    57   this.selector.find(".Ldt-sparkLine").sparkline(results, {lineColor: "#7492b4", fillColor: "#aeaeb8",
    58   this.selector.find(".Ldt-sparkLine").sparkline(results, {lineColor: "#7492b4", fillColor: "#aeaeb8",
    58                                                            spotColor: "#b70056",
    59                                                            spotColor: "#b70056",