diff -r 919e362b9db1 -r 3ab36f402b0c src/widgets/Sparkline.js --- a/src/widgets/Sparkline.js Thu Aug 30 14:45:23 2012 +0200 +++ b/src/widgets/Sparkline.js Thu Jan 02 16:40:25 2014 +0100 @@ -1,6 +1,5 @@ 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(); @@ -19,15 +18,22 @@ _duration = this.source.getDuration(), _max = 0, _list = this.getWidgetAnnotations(); - for (var _i = 0; _i < this.slice_count; _i++) { - 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); + 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); } if (!_max) { return; @@ -42,7 +48,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; @@ -68,18 +74,18 @@ this.$.click(function(_e) { var _x = _e.pageX - _this.$.offset().left; - _this.player.popcorn.currentTime(_this.source.getDuration().getSeconds() * _x / _this.width); + _this.media.setCurrentTime(_this.media.duration * _x / _this.width); }); - this.bindPopcorn("timeupdate","onTimeupdate"); -} + this.onMediaEvent("timeupdate","onTimeupdate"); +}; -IriSP.Widgets.Sparkline.prototype.onTimeupdate = function() { - var _x = Math.floor( this.width * this.player.popcorn.currentTime() / this.source.getDuration().getSeconds()); +IriSP.Widgets.Sparkline.prototype.onTimeupdate = function(_time) { + var _x = Math.floor( this.width * _time / this.media.duration); this.rectangleProgress.attr({ "width" : _x }); this.ligneProgress.attr({ "path" : "M" + _x + " 0L" + _x + " " + this.height }); -} +};