src/js/widgets/stackGraphWidget.js
author cavaliet
Mon, 13 Feb 2012 12:49:02 +0100
branchpopcorn-port
changeset 798 56fd575cb447
parent 766 aa26ddaf2556
child 820 7968346b9689
permissions -rw-r--r--
little clean modif.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
661
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
     1
IriSP.StackGraphWidget = function(Popcorn, config, Serializer) {
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
     2
  IriSP.Widget.call(this, Popcorn, config, Serializer);
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
     3
}
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
     4
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
     5
IriSP.StackGraphWidget.prototype = new IriSP.Widget();
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
     6
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
     7
IriSP.StackGraphWidget.prototype.draw = function() {
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
     8
    var _defaultTags = [
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
     9
            {
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    10
                "keywords" : [ "++" ],
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    11
                "description" : "positif",
766
aa26ddaf2556 fixed raphael's files to remove trailing colon at the end of objects to make
hamidouk
parents: 694
diff changeset
    12
                "color" : "#1D973D"
661
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    13
            },
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    14
            {
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    15
                "keywords" : [ "--" ],
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    16
                "description" : "negatif",
766
aa26ddaf2556 fixed raphael's files to remove trailing colon at the end of objects to make
hamidouk
parents: 694
diff changeset
    17
                "color" : "#CE0A15"
661
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    18
            },
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    19
            {
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    20
                "keywords" : [ "==" ],
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    21
                "description" : "reference",
766
aa26ddaf2556 fixed raphael's files to remove trailing colon at the end of objects to make
hamidouk
parents: 694
diff changeset
    22
                "color" : "#C5A62D"  
661
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    23
            },
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    24
            {
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    25
                "keywords" : [ "??" ],
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    26
                "description" : "question",
766
aa26ddaf2556 fixed raphael's files to remove trailing colon at the end of objects to make
hamidouk
parents: 694
diff changeset
    27
                "color" : "#036AAE"
aa26ddaf2556 fixed raphael's files to remove trailing colon at the end of objects to make
hamidouk
parents: 694
diff changeset
    28
            }
661
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    29
        ],
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    30
        _defaultDefColor = "#585858";
675
82a5ebbedc83 Added a Tag Cloud Widget and corrected Stack Graph Widget
veltr
parents: 661
diff changeset
    31
    this.height =  this._config.height || 50;
661
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    32
    this.width = this.selector.width();
675
82a5ebbedc83 Added a Tag Cloud Widget and corrected Stack Graph Widget
veltr
parents: 661
diff changeset
    33
    this.isStreamGraph = this._config.streamgraph || false;
82a5ebbedc83 Added a Tag Cloud Widget and corrected Stack Graph Widget
veltr
parents: 661
diff changeset
    34
    this.sliceCount = this._config.slices || ~~(this.width/(this.isStreamGraph ? 20 : 5));
661
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    35
    this.tagconf = (this._config.tags
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    36
        ? this._config.tags
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    37
        : _defaultTags);
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    38
    IriSP._(this.tagconf).each(function(_a) {
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    39
        _a.regexp = new RegExp(_a.keywords.map(function(_k) {
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    40
            return _k.replace(/([\W])/gm,'\\$1');
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    41
        }).join("|"),"im")
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    42
    });
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    43
    this.defaultcolorconf = (this._config.defaultcolor
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    44
        ? this._config.defaultcolor
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    45
        : _defaultDefColor);
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    46
    this.paper = new Raphael(this.selector[0], this.width, this.height);
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    47
    this.groups = [];
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    48
    this.duration = this._serializer.currentMedia().meta["dc:duration"];
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    49
    
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    50
    var _annotationType = this._serializer.getTweets(),
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    51
        _sliceDuration = ~~ ( this.duration / this.sliceCount),
675
82a5ebbedc83 Added a Tag Cloud Widget and corrected Stack Graph Widget
veltr
parents: 661
diff changeset
    52
        _annotations = this._serializer._data.annotations,
82a5ebbedc83 Added a Tag Cloud Widget and corrected Stack Graph Widget
veltr
parents: 661
diff changeset
    53
        _groupedAnnotations = IriSP._.range(this.sliceCount).map(function(_i) {
82a5ebbedc83 Added a Tag Cloud Widget and corrected Stack Graph Widget
veltr
parents: 661
diff changeset
    54
            return _annotations.filter(function(_a){
82a5ebbedc83 Added a Tag Cloud Widget and corrected Stack Graph Widget
veltr
parents: 661
diff changeset
    55
                return (_a.begin <= (1 + _i) * _sliceDuration) && (_a.end >= _i * _sliceDuration)
82a5ebbedc83 Added a Tag Cloud Widget and corrected Stack Graph Widget
veltr
parents: 661
diff changeset
    56
            });
661
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    57
        }),
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    58
        _max = IriSP._(_groupedAnnotations).max(function(_g) {
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    59
            return _g.length
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    60
        }).length,
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    61
        _scale = this.height / _max,
675
82a5ebbedc83 Added a Tag Cloud Widget and corrected Stack Graph Widget
veltr
parents: 661
diff changeset
    62
        _width = this.width / this.sliceCount
82a5ebbedc83 Added a Tag Cloud Widget and corrected Stack Graph Widget
veltr
parents: 661
diff changeset
    63
        _showTitle = !this._config.excludeTitle,
82a5ebbedc83 Added a Tag Cloud Widget and corrected Stack Graph Widget
veltr
parents: 661
diff changeset
    64
        _showDescription = !this._config.excludeDescription;
661
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    65
    
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    66
    
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    67
    var _paths = this.tagconf.map(function() {
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    68
        return [];
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    69
    });
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    70
    _paths.push([]);
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    71
    
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    72
    for (var i = 0; i < this.sliceCount; i++) {
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    73
        var _group = _groupedAnnotations[i];
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    74
        if (_group) {
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    75
            var _vol = this.tagconf.map(function() {
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    76
                return 0;
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    77
            });
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    78
            for (var j = 0; j < _group.length; j++){
675
82a5ebbedc83 Added a Tag Cloud Widget and corrected Stack Graph Widget
veltr
parents: 661
diff changeset
    79
           var _txt = (_showTitle ? _group[j].content.title : '') + ' ' + (_showDescription ? _group[j].content.description : '')
661
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    80
                var _tags = this.tagconf.map(function(_tag) {
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    81
                        return (_txt.search(_tag.regexp) == -1 ? 0 : 1)
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    82
                    }),
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    83
                    _nbtags = _tags.reduce(function(_a,_b) {
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    84
                        return _a + _b;
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    85
                    }, 0);
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    86
                if (_nbtags) {
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    87
                    IriSP._(_tags).each(function(_v, _k) {
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    88
                        _vol[_k] += (_v / _nbtags);
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    89
                    });
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    90
                }
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    91
            }
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    92
            var _nbtags = _vol.reduce(function(_a,_b) {
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    93
                    return _a + _b;
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    94
                }, 0),
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    95
                _nbneutre = _group.length - _nbtags,
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    96
                _h = _nbneutre * _scale,
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    97
                _base = this.height - _h;
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    98
            if (!this.isStreamGraph) {
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
    99
                this.paper.rect(i * _width, _base, _width - 1, _h ).attr({
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   100
                    "stroke" : "none",
766
aa26ddaf2556 fixed raphael's files to remove trailing colon at the end of objects to make
hamidouk
parents: 694
diff changeset
   101
                    "fill" : this.defaultcolorconf
661
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   102
                });
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   103
            }
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   104
           _paths[0].push(_base);
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   105
            for (var j = 0; j < this.tagconf.length; j++) {
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   106
                _h = _vol[j] * _scale;
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   107
                _base = _base - _h;
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   108
                if (!this.isStreamGraph) {
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   109
                    this.paper.rect(i * _width, _base, _width - 1, _h ).attr({
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   110
                        "stroke" : "none",
766
aa26ddaf2556 fixed raphael's files to remove trailing colon at the end of objects to make
hamidouk
parents: 694
diff changeset
   111
                        "fill" : this.tagconf[j].color
661
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   112
                    });
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   113
                }
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   114
                _paths[j+1].push(_base);
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   115
            }
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   116
            this.groups.push(_vol.map(function(_v) {
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   117
                return _v / _group.length;
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   118
            }))
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   119
        } else {
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   120
            for (var j = 0; j < _paths.length; j++) {
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   121
                _paths[j].push(this.height);
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   122
            }
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   123
            this.groups.push(this.tagconf.map(function() {
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   124
                return 0;
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   125
            }));
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   126
        }
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   127
    }
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   128
    
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   129
    if (this.isStreamGraph) {
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   130
        for (var j = _paths.length - 1; j >= 0; j--) {
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   131
            var _d = _paths[j].reduce(function(_memo, _v, _k) {
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   132
               return _memo + ( _k
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   133
                   ? 'C' + (_k * _width) + ' ' + _paths[j][_k - 1] + ' ' + (_k * _width) + ' ' + _v + ' ' + ((_k + .5) * _width) + ' ' + _v
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   134
                   : 'M0 ' + _v + 'L' + (.5*_width) + ' ' + _v )
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   135
            },'') + 'L' + this.width + ' ' + _paths[j][_paths[j].length - 1] + 'L' + this.width + ' ' + this.height + 'L0 ' + this.height;
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   136
            this.paper.path(_d).attr({
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   137
                "stroke" : "none",
766
aa26ddaf2556 fixed raphael's files to remove trailing colon at the end of objects to make
hamidouk
parents: 694
diff changeset
   138
                "fill" : (j ? this.tagconf[j-1].color : this.defaultcolorconf)
661
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   139
            });
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   140
        }
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   141
    }
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   142
    this.rectangleFocus = this.paper.rect(0,0,_width,this.height)
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   143
        .attr({
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   144
            "stroke" : "none",
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   145
            "fill" : "#ff00ff",
766
aa26ddaf2556 fixed raphael's files to remove trailing colon at the end of objects to make
hamidouk
parents: 694
diff changeset
   146
            "opacity" : 0
661
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   147
        })
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   148
    this.rectangleProgress = this.paper.rect(0,0,0,this.height)
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   149
        .attr({
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   150
            "stroke" : "none",
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   151
            "fill" : "#808080",
766
aa26ddaf2556 fixed raphael's files to remove trailing colon at the end of objects to make
hamidouk
parents: 694
diff changeset
   152
            "opacity" : .3
661
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   153
        });
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   154
    this.ligneProgress = this.paper.path("M0 0L0 "+this.height).attr({"stroke":"#ff00ff", "line-width" : 2})
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   155
    
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   156
    this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.timeUpdateHandler));
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   157
    var _this = this;
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   158
    this.selector
694
528626981afe corrected copy pasta code.
hamidouk
parents: 676
diff changeset
   159
        .click(IriSP.wrap(this, this.clickHandler))
528626981afe corrected copy pasta code.
hamidouk
parents: 676
diff changeset
   160
        .mousemove(function(event) {
528626981afe corrected copy pasta code.
hamidouk
parents: 676
diff changeset
   161
            _this.updateTooltip(event);
673
18318dd611c2 made the stackGraphWidget send a message when hovered.
hamidouk
parents: 663
diff changeset
   162
            
18318dd611c2 made the stackGraphWidget send a message when hovered.
hamidouk
parents: 663
diff changeset
   163
            // Also tell the world where the mouse is hovering.
694
528626981afe corrected copy pasta code.
hamidouk
parents: 676
diff changeset
   164
            var relX = event.pageX - _this.selector.offset().left;
528626981afe corrected copy pasta code.
hamidouk
parents: 676
diff changeset
   165
            var duration = _this._serializer.currentMedia().meta["dc:duration"];
673
18318dd611c2 made the stackGraphWidget send a message when hovered.
hamidouk
parents: 663
diff changeset
   166
            var Time = ((relX / _this.width) * duration).toFixed(2);
18318dd611c2 made the stackGraphWidget send a message when hovered.
hamidouk
parents: 663
diff changeset
   167
            _this._Popcorn.trigger("IriSP.StackGraphWidget.mouseOver", Time);
676
499d9693d066 Merge with 835f5f454595a1097dc0cef85b987541c3b707ac
veltr
parents: 675 673
diff changeset
   168
661
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   169
        })
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   170
        .mouseout(function() {
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   171
            _this.TooltipWidget.hide();
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   172
            _this.rectangleFocus.attr({
766
aa26ddaf2556 fixed raphael's files to remove trailing colon at the end of objects to make
hamidouk
parents: 694
diff changeset
   173
                "opacity" : 0
661
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   174
            })
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   175
        })
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   176
}
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   177
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   178
IriSP.StackGraphWidget.prototype.timeUpdateHandler = function() {
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   179
    var _currentTime = this._Popcorn.currentTime(),
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   180
        _x = (1000 * _currentTime / this.duration) * this.width;
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   181
    this.rectangleProgress.attr({
766
aa26ddaf2556 fixed raphael's files to remove trailing colon at the end of objects to make
hamidouk
parents: 694
diff changeset
   182
        "width" : _x
661
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   183
    });
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   184
    this.ligneProgress.attr({
766
aa26ddaf2556 fixed raphael's files to remove trailing colon at the end of objects to make
hamidouk
parents: 694
diff changeset
   185
        "path" : "M" + _x + " 0L" + _x + " " + this.height
661
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   186
    })
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   187
}
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   188
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   189
IriSP.StackGraphWidget.prototype.clickHandler = function(event) {
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   190
  /* Ctrl-C Ctrl-V'ed from another widget
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   191
  */
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   192
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   193
  var relX = event.pageX - this.selector.offset().left;
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   194
  var newTime = ((relX / this.width) * this.duration/1000).toFixed(2);
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   195
  this._Popcorn.trigger("IriSP.StackGraphWidget.clicked", newTime);
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   196
  this._Popcorn.currentTime(newTime);                                 
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   197
};
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   198
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   199
IriSP.StackGraphWidget.prototype.updateTooltip = function(event) {
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   200
    var _segment = ~~(this.sliceCount * (event.pageX - this.selector.offset().left)/this.width),
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   201
        _valeurs = this.groups[_segment],
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   202
        _width = this.width / this.sliceCount,
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   203
        _html = '<ul style="list-style: none; margin: 0; padding: 0;">' + this.tagconf.map(function(_tag, _i) {
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   204
            return '<li style="clear: both;"><span style="float: left; width: 10px; height: 10px; margin: 2px; background: '
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   205
                + _tag.color
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   206
                + ';"></span>'
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   207
                + ~~(100 * _valeurs[_i])
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   208
                + '% de '
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   209
                + _tag.description
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   210
                + '</li>';
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   211
        }).join('') + '</ul>';
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   212
    this.TooltipWidget._shown = false; // Vraiment, on ne peut pas ouvrir le widget s'il n'est pas encore ouvert ?
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   213
    this.TooltipWidget.show('','',event.pageX - 105, event.pageY - 160);
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   214
    this.TooltipWidget.selector.find(".tip").html(_html);
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   215
    this.rectangleFocus.attr({
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   216
        "x" : _segment * _width,
766
aa26ddaf2556 fixed raphael's files to remove trailing colon at the end of objects to make
hamidouk
parents: 694
diff changeset
   217
        "opacity" : .4
661
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   218
    })
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   219
}
48c1beea7b1c change line endings to unix.
hamidouk
parents: 657
diff changeset
   220