src/js/widgets/sparklineWidget.js
branchpopcorn-port
changeset 820 7968346b9689
parent 790 9d2b6f31994d
child 834 573c7ca752e0
equal deleted inserted replaced
819:9b8e68803f6f 820:7968346b9689
    42     console.log("sparklinewidget : using stats embedded in the json");
    42     console.log("sparklinewidget : using stats embedded in the json");
    43     var results = stat_view.meta.stat.split(",");      
    43     var results = stat_view.meta.stat.split(",");      
    44   } else {
    44   } else {
    45     console.log("sparklinewidget : computing stats ourselves");
    45     console.log("sparklinewidget : computing stats ourselves");
    46     var num_columns = (this.selector.width()) / IriSP.widgetsDefaults["SparklineWidget"].column_width;
    46     var num_columns = (this.selector.width()) / IriSP.widgetsDefaults["SparklineWidget"].column_width;
    47     var duration = +this._serializer.currentMedia().meta["dc:duration"];
    47     var duration = this._serializer.getDuration();
    48     var time_step = duration / num_columns; /* the time interval between two columns */
    48     var time_step = duration / num_columns; /* the time interval between two columns */
    49     var results = [];
    49     var results = [];
    50     var i = 0; /* the index in the loop */  
    50     var i = 0; /* the index in the loop */  
    51 
    51 
    52     /* this algorithm makes one assumption : that the array is sorted 
    52     /* this algorithm makes one assumption : that the array is sorted 
    89 };
    89 };
    90 
    90 
    91 /** react to a timeupdate event */
    91 /** react to a timeupdate event */
    92 IriSP.SparklineWidget.prototype.timeUpdateHandler = function() {
    92 IriSP.SparklineWidget.prototype.timeUpdateHandler = function() {
    93   var currentTime = this._Popcorn.currentTime();  
    93   var currentTime = this._Popcorn.currentTime();  
    94   var duration = +this._serializer.currentMedia().meta["dc:duration"] / 1000;
    94   var duration = this._serializer.getDuration() / 1000;
    95   var proportion = ((currentTime / duration) * 100).toFixed(4);
    95   var proportion = ((currentTime / duration) * 100).toFixed(4);
    96   
    96   
    97   IriSP.jQuery(".Ldt-sparkLinePositionMarker").css("width", proportion + "%");                                    
    97   IriSP.jQuery(".Ldt-sparkLinePositionMarker").css("width", proportion + "%");                                    
    98 }
    98 }
    99 
    99 
   109 
   109 
   110   var parentOffset = this.selector.offset();
   110   var parentOffset = this.selector.offset();
   111   var width = this.selector.width();
   111   var width = this.selector.width();
   112   var relX = event.pageX - parentOffset.left;
   112   var relX = event.pageX - parentOffset.left;
   113 
   113 
   114   var duration = this._serializer.currentMedia().meta["dc:duration"] / 1000;
   114   var duration = this._serializer.getDuration() / 1000;
   115   var newTime = ((relX / width) * duration).toFixed(2);
   115   var newTime = ((relX / width) * duration).toFixed(2);
   116     
   116     
   117   this._Popcorn.trigger("IriSP.SparklineWidget.clicked", newTime);
   117   this._Popcorn.trigger("IriSP.SparklineWidget.clicked", newTime);
   118   this._Popcorn.currentTime(newTime);                                 
   118   this._Popcorn.currentTime(newTime);                                 
   119 };
   119 };
   120 
   120 
   121 /** react when a new annotation is added */
   121 /** react when a new annotation is added */
   122 IriSP.SparklineWidget.prototype.handleNewAnnotation = function(annotation) {
   122 IriSP.SparklineWidget.prototype.handleNewAnnotation = function(annotation) {
   123   var num_columns = this._results.length;
   123   var num_columns = this._results.length;
   124   var duration = +this._serializer.currentMedia().meta["dc:duration"];
   124   var duration = this._serializer.getDuration();
   125   var time_step = Math.round(duration / num_columns); /* the time interval between two columns */
   125   var time_step = Math.round(duration / num_columns); /* the time interval between two columns */
   126   var begin = +annotation.begin;
   126   var begin = +annotation.begin;
   127   var end = +annotation.end;
   127   var end = +annotation.end;
   128   
   128   
   129   /* increment all the values between the beginning and the end of the annotation */
   129   /* increment all the values between the beginning and the end of the annotation */