# HG changeset patch # User hamidouk # Date 1325588746 -3600 # Node ID 098929cd2d6272ea6f807bd16e13eb6df9fcd680 # Parent 903435828e6c3940055fab2f576f70392539b495 made the polemicwidget adjust its size automatically and fixed a couple edgecases. diff -r 903435828e6c -r 098929cd2d62 src/js/serializers/JSONSerializer.js --- a/src/js/serializers/JSONSerializer.js Mon Jan 02 16:59:30 2012 +0100 +++ b/src/js/serializers/JSONSerializer.js Tue Jan 03 12:05:46 2012 +0100 @@ -261,6 +261,9 @@ /* first get the list containing the tweets */ var tweets = IriSP.underscore.filter(this._data.lists, function(entry) { return entry.id.indexOf("tweet") !== -1 }); + if (tweets.length === 0) + return []; + // FIXME: collect tweets from multiple sources ? tweetsId = IriSP.underscore.pluck(tweets[0].items, "id-ref"); diff -r 903435828e6c -r 098929cd2d62 src/js/widgets/polemicWidget.js --- a/src/js/widgets/polemicWidget.js Mon Jan 02 16:59:30 2012 +0100 +++ b/src/js/widgets/polemicWidget.js Tue Jan 03 12:05:46 2012 +0100 @@ -34,11 +34,10 @@ this.tweets = new Array(); this.svgElements = {}; + this.oldSearchMatches = []; // Make and define the Raphael area this.paper = Raphael(document.getElementById(this._id), config.width, config.height); - this.oldSearchMatches = []; - // event handlers this._Popcorn.listen("IriSP.search", IriSP.wrap(this, function(searchString) { this.searchHandler(searchString); })); this._Popcorn.listen("IriSP.search.closed", IriSP.wrap(this, this.searchFieldClosedHandler)); @@ -137,16 +136,23 @@ this._serializer.sync(function(data) { loaded_callback.call(self, data) }); function loaded_callback (json) { - - // get current view (the first ???) + + var view_type = this._serializer.getTweetIds()[0]; + if (typeof(view_type) === "undefined") { + // default to guessing if nothing else works. view = json.views[0]; - // the tweets are by definition of the second annotation type FIXME ? + // tweet_annot_type = null; - if(typeof(view.annotation_types) !== "undefined" && view.annotation_types.length > 1) { - tweet_annot_type = view.annotation_types[1]; - } - + if(typeof(view.annotation_types) !== "undefined") { + if (view.annotation_types.length >= 1) { + view_type = view.annotation_types[0]; + } else { + console.log("PolemicWidget: invalid file"); + } + } + } + for(var i = 0; i < json.annotations.length; i++) { var item = json.annotations[i]; var MyTime = Math.floor(item.begin/duration*lineSize); @@ -154,10 +160,13 @@ if (typeof(item.meta) !== "undefined" && typeof(item.meta["id-ref"]) !== "undefined" - && item.meta["id-ref"] === tweet_annot_type) { + && item.meta["id-ref"] === view_type) { - var MyTJson = JSON.parse(item.meta['dc:source']['content']); - + var MyTJson = {}; + if (typeof(item.meta['dc:source']) !== "undefined") { + var MyTJson = JSON.parse(item.meta['dc:source']['content']); + } + if (item.content['polemics'] != undefined && item.content['polemics'][0] != null) { @@ -256,7 +265,16 @@ var tweetDrawed = new Array(); var TweetHeight = 5; + var newHeight = TweetHeight * max + 10; + + if (newHeight > this.height) { + this.paper.setSize(this.width, newHeight); + this.height = newHeight; + console.log("resizeing"); + } + + // DRAW TWEETS ============================================ for(var i = 0; i < nbrframes; i++) { var addEheight = 5; @@ -270,7 +288,7 @@ if (frames[i].mytweetsID[k].qualification == j) { var x = i * frameSize; - var y = this.heightmax - addEheight; + var y = this.height - addEheight; if (this.yMax > y) { this.yMax = y; @@ -309,7 +327,7 @@ } // DRAW UI :: resize border and bgd - this.paperBackground = this.paper.rect(0, 0, this.width, this.heightmax).attr({fill:"#F8F8F8","stroke-width":0.1,opacity: 1}); + this.paperBackground = this.paper.rect(0, 0, this.width, this.height).attr({fill:"#F8F8F8","stroke-width":0.1,opacity: 1}); // outer borders this.outerBorders = []; @@ -325,10 +343,10 @@ - this.paperSlider = this.paper.rect(0, 0, 0, this.heightmax).attr({fill:"#D4D5D5", stroke: "none", opacity: 1}); + this.paperSlider = this.paper.rect(0, 0, 0, this.height).attr({fill:"#D4D5D5", stroke: "none", opacity: 1}); // the small white line displayed over the slider. - this.sliderTip = this.paper.rect(0, 0, 1, this.heightmax).attr({fill:"#fc00ff", stroke: "none", opacity: 1}); + this.sliderTip = this.paper.rect(0, 0, 1, this.height).attr({fill:"#fc00ff", stroke: "none", opacity: 1}); // decalage // tweetSelection = this.paper.rect(-100,-100,5,5).attr({fill:"#fff",stroke: "none",opacity: 1}); @@ -373,7 +391,8 @@ e.attr({fill: e.color, opacity: 0.4}); } - for (var id in matches) { + + for (var id in matches) { if (this.svgElements.hasOwnProperty(id)) { var e = this.svgElements[id]; this.svgElements[id].attr({fill: "#fc00ff", opacity: 1}); diff -r 903435828e6c -r 098929cd2d62 test/integration/polemic-jsonp.htm --- a/test/integration/polemic-jsonp.htm Mon Jan 02 16:59:30 2012 +0100 +++ b/test/integration/polemic-jsonp.htm Tue Jan 03 12:05:46 2012 +0100 @@ -28,23 +28,42 @@ container:'LdtPlayer', css:'../../src/css/LdtPlayer.css', widgets: [ + {type: "PolemicWidget", + width: 640, /* required for this widget */ + height: 50, + metadata:{ + format:'cinelab', + src:'http://www.iri.centrepompidou.fr/dev/ldt/ldtplatform/ldt/cljson/id/ae6827dc-1f29-11e1-a049-00145ea49a02', + type:'json'}, + + requires: [{ + type: "TooltipWidget", + width: 180, + heigh: 160, + metadata : { + format:'cinelab', + src:'http://www.iri.centrepompidou.fr/dev/ldt/ldtplatform/ldt/cljson/id/ae6827dc-1f29-11e1-a049-00145ea49a02', + type:'empty' + } + }], + }, {type: "SliderWidget", metadata:{ format:'cinelab', - src:"http://www.iri.centrepompidou.fr/dev/ldt/ldtplatform/ldt/cljson/id/f20906c6-2c82-11e1-872c-00145ea49a02", + src:"http://www.iri.centrepompidou.fr/dev/ldt/ldtplatform/ldt/cljson/id/ae6827dc-1f29-11e1-a049-00145ea49a02", type:'json'} }, {type: "PlayerWidget", // please note that type refers directly to the constructor of the widget. mode: "radio", metadata:{ format:'cinelab', - src:"http://www.iri.centrepompidou.fr/dev/ldt/ldtplatform/ldt/cljson/id/f20906c6-2c82-11e1-872c-00145ea49a02", + src:"http://www.iri.centrepompidou.fr/dev/ldt/ldtplatform/ldt/cljson/id/ae6827dc-1f29-11e1-a049-00145ea49a02", type:'json'} }, {type: "SegmentsWidget", metadata:{ format:'cinelab', - src:"http://www.iri.centrepompidou.fr/dev/ldt/ldtplatform/ldt/cljson/id/f20906c6-2c82-11e1-872c-00145ea49a02", + src:"http://www.iri.centrepompidou.fr/dev/ldt/ldtplatform/ldt/cljson/id/ae6827dc-1f29-11e1-a049-00145ea49a02", type:'json'}, requires: [{ type: "TooltipWidget", @@ -58,20 +77,20 @@ {type: "ArrowWidget", metadata:{ format:'cinelab', - src:"http://www.iri.centrepompidou.fr/dev/ldt/ldtplatform/ldt/cljson/id/f20906c6-2c82-11e1-872c-00145ea49a02", + src:"http://www.iri.centrepompidou.fr/dev/ldt/ldtplatform/ldt/cljson/id/ae6827dc-1f29-11e1-a049-00145ea49a02", type:'json'} }, {type: "AnnotationsWidget", metadata:{ format:'cinelab', - src:"http://www.iri.centrepompidou.fr/dev/ldt/ldtplatform/ldt/cljson/id/f20906c6-2c82-11e1-872c-00145ea49a02", + src:"http://www.iri.centrepompidou.fr/dev/ldt/ldtplatform/ldt/cljson/id/ae6827dc-1f29-11e1-a049-00145ea49a02", type:'json'} }, {type: "TweetsWidget", metadata:{ format:'cinelab', - src:"http://www.iri.centrepompidou.fr/dev/ldt/ldtplatform/ldt/cljson/id/f20906c6-2c82-11e1-872c-00145ea49a02", + src:"http://www.iri.centrepompidou.fr/dev/ldt/ldtplatform/ldt/cljson/id/ae6827dc-1f29-11e1-a049-00145ea49a02", type:'json'} } ] @@ -89,13 +108,13 @@ { type: "MediaFragment", metadata:{ format:'cinelab', - src:"http://www.iri.centrepompidou.fr/dev/ldt/ldtplatform/ldt/cljson/id/f20906c6-2c82-11e1-872c-00145ea49a02", + src:"http://www.iri.centrepompidou.fr/dev/ldt/ldtplatform/ldt/cljson/id/ae6827dc-1f29-11e1-a049-00145ea49a02", type:'json'} }] }; - IriSP.loadLibs(IriSP.lib, config, "http://www.iri.centrepompidou.fr/dev/ldt/ldtplatform/ldt/cljson/id/f20906c6-2c82-11e1-872c-00145ea49a02", + IriSP.loadLibs(IriSP.lib, config, "polemic_fr.json", function() { var layoutManager = new IriSP.LayoutManager(config.gui.container); var pop = IriSP.configurePopcorn(layoutManager, config.player); diff -r 903435828e6c -r 098929cd2d62 test/integration/polemic.htm --- a/test/integration/polemic.htm Mon Jan 02 16:59:30 2012 +0100 +++ b/test/integration/polemic.htm Tue Jan 03 12:05:46 2012 +0100 @@ -31,7 +31,6 @@ {type: "PolemicWidget", width: 640, /* required for this widget */ height: 50, - heightmax: 50, metadata:{ format:'cinelab', src:'polemic_fr.json',