# HG changeset patch # User veltr # Date 1326904814 -3600 # Node ID 82a5ebbedc830af9eb023693ed8807ac7609ee11 # Parent 5e10069c5c2112f8e1e5e1c8e7d5fe568956f20d Added a Tag Cloud Widget and corrected Stack Graph Widget diff -r 5e10069c5c21 -r 82a5ebbedc83 src/css/LdtPlayer.css --- a/src/css/LdtPlayer.css Wed Jan 18 11:35:18 2012 +0100 +++ b/src/css/LdtPlayer.css Wed Jan 18 17:40:14 2012 +0100 @@ -734,3 +734,13 @@ display: table-cell; width: 80%; } + +/* Tagcloud */ + +.Ldt-TagCloud ul { + list-style: none; padding: 0; margin: 5px; text-align: center; +} + +.Ldt-TagCloud li { + display: inline-block; margin: 2px; +} diff -r 5e10069c5c21 -r 82a5ebbedc83 src/js/widgets/stackGraphWidget.js --- a/src/js/widgets/stackGraphWidget.js Wed Jan 18 11:35:18 2012 +0100 +++ b/src/js/widgets/stackGraphWidget.js Wed Jan 18 17:40:14 2012 +0100 @@ -28,10 +28,10 @@ }, ], _defaultDefColor = "#585858"; - this.height = (this._config.height ? this._config.height : 50); + this.height = this._config.height || 50; this.width = this.selector.width(); - this.isStreamGraph = (this._config.streamgraph ? this._config.streamgraph : false); - this.sliceCount = (this._config.slices ? this._config.slices : ~~(this.width/(this.isStreamGraph ? 20 : 5))); + this.isStreamGraph = this._config.streamgraph || false; + this.sliceCount = this._config.slices || ~~(this.width/(this.isStreamGraph ? 20 : 5)); this.tagconf = (this._config.tags ? this._config.tags : _defaultTags); @@ -49,17 +49,19 @@ var _annotationType = this._serializer.getTweets(), _sliceDuration = ~~ ( this.duration / this.sliceCount), - _annotations = IriSP._(this._serializer._data.annotations).filter(function(_a) { - return ( _a.meta && _a.meta["id-ref"] && ( _a.meta["id-ref"] == _annotationType ) ); - }), - _groupedAnnotations = IriSP._(_annotations).groupBy(function(_a) { - return ~~ (_a.begin / _sliceDuration); + _annotations = this._serializer._data.annotations, + _groupedAnnotations = IriSP._.range(this.sliceCount).map(function(_i) { + return _annotations.filter(function(_a){ + return (_a.begin <= (1 + _i) * _sliceDuration) && (_a.end >= _i * _sliceDuration) + }); }), _max = IriSP._(_groupedAnnotations).max(function(_g) { return _g.length }).length, _scale = this.height / _max, - _width = this.width / this.sliceCount; + _width = this.width / this.sliceCount + _showTitle = !this._config.excludeTitle, + _showDescription = !this._config.excludeDescription; var _paths = this.tagconf.map(function() { @@ -74,7 +76,7 @@ return 0; }); for (var j = 0; j < _group.length; j++){ - var _txt = _group[j].content.description; + var _txt = (_showTitle ? _group[j].content.title : '') + ' ' + (_showDescription ? _group[j].content.description : '') var _tags = this.tagconf.map(function(_tag) { return (_txt.search(_tag.regexp) == -1 ? 0 : 1) }), diff -r 5e10069c5c21 -r 82a5ebbedc83 src/js/widgets/tagCloudWidget.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/js/widgets/tagCloudWidget.js Wed Jan 18 17:40:14 2012 +0100 @@ -0,0 +1,70 @@ +IriSP.TagCloudWidget = function(Popcorn, config, Serializer) { + IriSP.Widget.call(this, Popcorn, config, Serializer); +} + +IriSP.TagCloudWidget.prototype = new IriSP.Widget(); + +IriSP.TagCloudWidget.prototype.draw = function() { + + var _stopwords = [ + 'aussi', 'and', 'avec', 'aux', 'car', 'cette', 'comme', 'dans', 'donc', 'des', 'elle', 'est', + 'être', 'eux', 'fait', 'ici', 'ils', 'les', 'leur', 'leurs', 'mais', 'mes', 'même', 'mon', 'notre', + 'nos', 'nous', 'ont', 'par', 'pas', 'peu', 'pour', 'que', 'qui', 'ses' ,'son', 'sont', 'sur', + 'tes', 'très', 'the', 'ton', 'tous', 'tout', 'une', 'votre', 'vos', 'vous' + ], + _regexpword = /[^\s\.&;,'"!\?\d\(\)\+\[\]\\\…\-«»:\/]{3,}/g, + _words = {}, + _showTitle = !this._config.excludeTitle, + _showDescription = !this._config.excludeDescription, + _tagCount = this._config.tagCount || 30; + + IriSP._(this._serializer._data.annotations).each(function(_annotation) { + if (_annotation.content && _annotation.content.description) { + var _txt = (_showTitle ? _annotation.content.title : '') + ' ' + (_showDescription ? _annotation.content.description : '') + IriSP._(_txt.toLowerCase().match(_regexpword)).each(function(_mot) { + if (_stopwords.indexOf(_mot) == -1) { + _words[_mot] = 1 + (_words[_mot] || 0); + } + }) + } + }); + + _words = IriSP._(_words) + .chain() + .map(function(_v, _k) { + return { + "word" : _k, + "count" : _v, + } + }) + .filter(function(_v) { + return _v.count > 2; + }) + .sortBy(function(_v) { + return - _v.count; + }) + .first(_tagCount) + .value(); + var _max = _words[0].count, + _min = Math.min(_words[_words.length - 1].count, _max - 1), + _scale = 16 / Math.sqrt(_max - _min), + _html = ''; + this.selector + .addClass("Ldt-TagCloud") + .html(_html); + +}