--- a/src/widgets/Sparkline.js Tue Nov 06 10:59:57 2012 +0100
+++ b/src/widgets/Sparkline.js Fri Nov 09 14:33:03 2012 +0100
@@ -20,11 +20,20 @@
_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;
+ var _begin = (_i*_duration/this.slice_count),
+ _end = ((_i+1)*_duration/this.slice_count),
+ _annotations = _list.reduce(function(_m, _annotation) {
+ if (_annotation.begin < _end && _annotation.begin >= _begin) {
+ var _d = _annotation.getDuration().milliseconds;
+ if (!_d) {
+ return _m + 1;
+ } else {
+ return _m + (Math.min(_annotation.end, _end) - Math.max(_annotation.begin, _begin)) / _d;
+ }
+ } else {
+ return _m
+ }
+ },0);
_max = Math.max(_max, _annotations);
_slices.push(_annotations);
}