diff -r 3ab36f402b0c -r 198c2b79f5e1 src/widgets/Sparkline.js --- a/src/widgets/Sparkline.js Thu Jan 02 16:40:25 2014 +0100 +++ b/src/widgets/Sparkline.js Thu Jan 02 16:49:20 2014 +0100 @@ -1,5 +1,6 @@ IriSP.Widgets.Sparkline = function(player, config) { IriSP.Widgets.Widget.call(this, player, config); + //this.bindPopcorn("timeupdate", "onTimeupdate"); }; IriSP.Widgets.Sparkline.prototype = new IriSP.Widgets.Widget(); @@ -18,22 +19,15 @@ _duration = this.source.getDuration(), _max = 0, _list = this.getWidgetAnnotations(); + for (var _i = 0; _i < this.slice_count; _i++) { - var _begin = (_i*_duration/this.slice_count), - _end = ((_i+1)*_duration/this.slice_count), - _volume = 0; - _list.forEach(function(_annotation) { - if (_annotation.begin < _end && _annotation.end >= _begin) { - var _d = _annotation.getDuration().milliseconds; - if (!_d) { - _volume += 1; - } else { - _volume += (Math.min(_annotation.end, _end) - Math.max(_annotation.begin, _begin)) / _d; - } - } - }); - _max = Math.max(_max, _volume); - _slices.push(_volume); + var _begin = new IriSP.Model.Time(_i*_duration/this.slice_count), + _end = new IriSP.Model.Time((_i+1)*_duration/this.slice_count), + _annotations = _list.filter(function(_annotation) { + return _annotation.begin >= _begin && _annotation.end < _end; + }).length; + _max = Math.max(_max, _annotations); + _slices.push(_annotations); } if (!_max) { return; @@ -48,7 +42,7 @@ _d = IriSP._(_y).reduce(function(_memo, _v, _k) { return _memo + ( _k ? 'C' + (_k * _width) + ' ' + _y[_k - 1] + ' ' + (_k * _width) + ' ' + _v + ' ' + ((_k + .5) * _width) + ' ' + _v - : 'M0 ' + _v + 'L' + (.5*_width) + ' ' + _v ); + : 'M0 ' + _v + 'L' + (.5*_width) + ' ' + _v ) },'') + 'L' + this.width + ' ' + _y[_y.length - 1], _d2 = _d + 'L' + this.width + ' ' + this.height + 'L0 ' + this.height; @@ -74,18 +68,18 @@ this.$.click(function(_e) { var _x = _e.pageX - _this.$.offset().left; - _this.media.setCurrentTime(_this.media.duration * _x / _this.width); + _this.player.popcorn.currentTime(_this.source.getDuration().getSeconds() * _x / _this.width); }); - this.onMediaEvent("timeupdate","onTimeupdate"); -}; + this.bindPopcorn("timeupdate","onTimeupdate"); +} -IriSP.Widgets.Sparkline.prototype.onTimeupdate = function(_time) { - var _x = Math.floor( this.width * _time / this.media.duration); +IriSP.Widgets.Sparkline.prototype.onTimeupdate = function() { + var _x = Math.floor( this.width * this.player.popcorn.currentTime() / this.source.getDuration().getSeconds()); this.rectangleProgress.attr({ "width" : _x }); this.ligneProgress.attr({ "path" : "M" + _x + " 0L" + _x + " " + this.height }); -}; +}