web/rsln-opendata/res/metadataplayer/test/chartTimeline4.html
changeset 66 8a382087127f
equal deleted inserted replaced
65:e93dd6da4c6d 66:8a382087127f
       
     1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
       
     2 <html xmlns="http://www.w3.org/1999/xhtml">
       
     3 <head>
       
     4 <title>Example raphael</title>
       
     5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
       
     6  <style type='text/css'> 
       
     7 	#tip{
       
     8 	 position : absolute;
       
     9 	 border : 1px solid gray;
       
    10 	 background-color : #efefef;
       
    11 	 padding : 3px;
       
    12 	 z-index: 1000000;
       
    13 	 /* set this to create word wrap */
       
    14 	 max-width: 200px;
       
    15 	}	
       
    16 </style>
       
    17 </head>
       
    18 <body>
       
    19 
       
    20 <div id="Ldt-output" name="Ldt-output" style="position:absolute;left:600px;" ></div>
       
    21 <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'></script>
       
    22 <script type="text/javascript" src="raphael-min.js"></script>
       
    23 
       
    24 <div>
       
    25 <!--
       
    26 
       
    27 -->
       
    28 
       
    29 
       
    30 
       
    31 <script type='text/javascript' src='http://www.iri.centrepompidou.fr/dev/ldt/static/ldt/js/LdtPlayer.min.js'></script>
       
    32   <div id="player_project_13b0aa52-336b-11e0-b233-00145ea49a02_embed" class="iri_player_embed"/>
       
    33   <script type="text/javascript">
       
    34 	var config = {
       
    35 			/*metadata:{
       
    36 				format:'cinelab',
       
    37 				src:'metadata.json',
       
    38 				load:'json'},*/
       
    39 			metadata:{
       
    40 				format:'cinelab',
       
    41 				src:'http://www.iri.centrepompidou.fr//dev/ldt/ldtplatform/ldt/cljson/id/13b0aa52-336b-11e0-b233-00145ea49a02',
       
    42 				load:'jsonp'},
       
    43 			gui:{
       
    44 				width:650,
       
    45 				height:480,
       
    46 				mode:'video',
       
    47 				container:'player_project_13b0aa52-336b-11e0-b233-00145ea49a02_embed',
       
    48 				debug:false,
       
    49 				css:'http://www.iri.centrepompidou.fr//dev/ldt/static/ldt/css/LdtPlayer.css'},
       
    50 			player:{
       
    51 				type:'jwplayer',
       
    52 				src:'http://www.iri.centrepompidou.fr//dev/ldt/static/ldt/swf/player.swf'}
       
    53 		};
       
    54 	__IriSP.init(config);     
       
    55 </script>
       
    56 <div id="charttimeline" style="position:relative;display:block;"></div>
       
    57 <div id="tip"></div>
       
    58 <script type="text/javascript"> 
       
    59 
       
    60 // CHART TIMELINE / VERSION PROTOTYPE  ::
       
    61 //		- config
       
    62 // 		- organisation classe
       
    63 // 		!!!- rollover !! 
       
    64 // 		!!!!- legend  !!
       
    65 //		- time cursor
       
    66 // 		- seek !!
       
    67 
       
    68 /*
       
    69 	1 | 1D973D > vert 	> ++ > OK
       
    70 	2 | C5A62D > orange	> ?? > Q
       
    71 	3 | CE0A15 > rouge  > -- > KO
       
    72 	4 | 036AAE > bleu   > == > REF
       
    73 	5 | 585858 > gris   > NQ > ""
       
    74 */
       
    75 	
       
    76 
       
    77 	// configuration 
       
    78 	var config = {
       
    79 					target:"charttimeline",
       
    80 					x:8,
       
    81 					y:418,
       
    82 					width:650,
       
    83 					height:70,
       
    84 					heightmax:70
       
    85 					}
       
    86 	// Make and define the Raphael area
       
    87 	//var paper = Raphael(document.getElementById(config.target),config.width, config.height);
       
    88 	
       
    89 	var over = false;
       
    90 	var tip = $("#tip").hide();
       
    91 	var tipText = "";
       
    92 	
       
    93 	function ChartTimeLine (){
       
    94 		
       
    95 		var paper = Raphael(config.x,config.y,config.width, config.height);
       
    96 		paper.rect(0,20,config.width,config.heightmax-20).attr({fill:"#fff","stroke-width":0.1,opacity: 0.1});	
       
    97 		paper.rect(0,20,config.width,1).attr({fill:"#fff",stroke: "none"});	
       
    98 		paper.rect(0,20,config.width,1).attr({fill:"#fff",stroke: "none"});	
       
    99 		paper.rect(0,20,1,1).attr({fill:"#fff",stroke: "none"});	
       
   100 		
       
   101 		// variable 
       
   102 		
       
   103 		var yCoef	  = 2; 					// coef for height of 1 tweet 
       
   104 		var frameSize = 5; 					// frame size 
       
   105 		var margin 	  = 1;					// marge between frame
       
   106 		var lineSize  = 650;				// timeline pixel width 
       
   107 		var nbrframes = lineSize/frameSize; // frame numbers
       
   108 		var numberOfTweet = 0;				// number of tweet overide later 
       
   109 		var duration  = 4299820 ;			// timescale width 
       
   110 		var frameLenght =lineSize/frameSize;// frame timescale	
       
   111 		var timeline;
       
   112 		var colors  = new Array("","#1D973D","#C5A62D","#CE0A15","#036AAE","#585858");
       
   113 		
       
   114 		// array 
       
   115 		var tweets  = new Array();
       
   116 		var element = new Array();
       
   117 		var cluster = new Array();
       
   118 		var frames  = new Array(frameLenght);
       
   119 		var slices  = new Array();
       
   120 		
       
   121 		
       
   122 		// Classes =======================================================================
       
   123 		var Frames = function(){
       
   124 			
       
   125 			var Myclusters;
       
   126 			var x;
       
   127 			var y;
       
   128 			var width;
       
   129 			var height;
       
   130 		};
       
   131 		Frames = function(json){
       
   132 			// make my clusters
       
   133 			// ou Frame vide 
       
   134 		};
       
   135 		Frames.prototype.draw = function(){
       
   136 		}
       
   137 		Frames.prototype.zoom = function(){
       
   138 		}
       
   139 		Frames.prototype.inside = function(){
       
   140 		}
       
   141 		var Clusters = function(){
       
   142 			var Object;
       
   143 			var yDist;
       
   144 			var x;
       
   145 			var y;
       
   146 			var width;
       
   147 			var height;
       
   148 		};
       
   149 		Clusters = function(json){
       
   150 			// make my object
       
   151 		};
       
   152 		var Tweet = function(){
       
   153 		}
       
   154 		// Classes =======================================================================
       
   155 		
       
   156 		
       
   157 
       
   158 
       
   159 		// trace function 
       
   160 		var traceNum = 0;
       
   161 		function trace(msg,value){
       
   162 			traceNum += 1;
       
   163 			$("<div>"+traceNum+" - "+msg+" : "+value+"</div>").appendTo("#Ldt-output");
       
   164 		}
       
   165 		
       
   166 		// Refactoring (parametere) ************************************************************
       
   167 		// color translastion
       
   168 		function colorTranslation(value){
       
   169 			if(value == "Q"){
       
   170 				return 2;
       
   171 			}else if(value =="REF"){
       
   172 				return 4;
       
   173 			}else if(value =="OK"){
       
   174 				return 1;
       
   175 			}else if(value =="KO"){
       
   176 				return 3;
       
   177 			}else if(value ==""){
       
   178 				return 5;
       
   179 			}
       
   180 		}
       
   181 		
       
   182 		
       
   183 		// Refactoring (parametere) ************************************************************
       
   184 		// load tweets send in parameters 
       
   185 		$.ajax({
       
   186 		  dataType: "json",
       
   187 		  url:"metadata.json",
       
   188 		  success : function(json){
       
   189 			trace("load","");
       
   190 				$.each(json.annotations, function(i,item) {
       
   191 					
       
   192 					var MyTime  = Math.floor(item.begin/duration*lineSize);
       
   193 					var Myframe = Math.floor(MyTime/lineSize*frameLenght);
       
   194 
       
   195 					if (item.content['polemics'] != undefined) {
       
   196 						if (item.content['polemics'][0] != null) {
       
   197 							
       
   198 								for(var j=0; j<item.content['polemics'].length; j++){
       
   199 
       
   200 										tweets[numberOfTweet] = {
       
   201 													id:i,
       
   202 													qualification:colorTranslation(item.content['polemics'][j]),
       
   203 													yIndicator:MyTime,
       
   204 													yframe:Myframe,
       
   205 													title:item.content['title'],
       
   206 													timeframe:item.begin
       
   207 													}
       
   208 										numberOfTweet+=1;
       
   209 								}
       
   210 						}else{
       
   211 							//trace("k = ",i);
       
   212 							tweets[numberOfTweet] = {
       
   213 										id:i,
       
   214 										qualification:colorTranslation(""),
       
   215 										yIndicator:MyTime,
       
   216 										yframe:Myframe,
       
   217 										title:item.content['title'],
       
   218 										timeframe:item.begin
       
   219 							}
       
   220 							numberOfTweet+=1;
       
   221 						}
       
   222 						
       
   223 					} else {
       
   224 						//trace("tweet qualification = ","null");
       
   225 					}
       
   226 				});	
       
   227 			trace("======= ",numberOfTweet);
       
   228 		   DrawTweets ();
       
   229 		   
       
   230 		  }
       
   231 		 });
       
   232 			
       
   233 		// tweet Drawing (in raphael) 
       
   234 		function DrawTweets (){
       
   235 			// Count nbr of cluster and tweet in a frame an save int in "frames"
       
   236 			numberOfTweet = tweets.length;
       
   237 			for(var i=0; i<nbrframes; i++) {	
       
   238 				for(var j=0; j<numberOfTweet; j++) {	
       
   239 					if (i==tweets[j].yframe){
       
   240 						
       
   241 						var k = tweets[j].qualification;
       
   242 						// make array for frame cluster
       
   243 						if(frames[i]==undefined){
       
   244 							frames[i] = new Array();
       
   245 						}
       
   246 						// count clusters
       
   247 						if(frames[i][k]==undefined){
       
   248 							frames[i][k]=1;
       
   249 						}else{
       
   250 							frames[i][k]+=1;
       
   251 						}
       
   252 					}
       
   253 				}
       
   254 			}
       
   255 			
       
   256 			// max of tweet by Frame 
       
   257 			var max 	= 0; 
       
   258 			for(var i=0; i<nbrframes; i++) {
       
   259 				var moy	= 0;
       
   260 				for (var j=1; j<6; j++){		
       
   261 					if (frames[i]!=undefined){
       
   262 						if (frames[i][j]!=undefined){
       
   263 							moy += frames[i][j]
       
   264 						}
       
   265 					}
       
   266 				}
       
   267 				//trace("frame "+i,moy);
       
   268 				if (moy>max){max=moy;}
       
   269 			}
       
   270 			
       
   271 			// Draw cluster of tweet by frame ...
       
   272 			for(var i=0; i<nbrframes; i++) {
       
   273 				var addEheight = 0;
       
   274 				slices[i] =  new Array();
       
   275 				if (frames[i]!=undefined){
       
   276 					for (var j=6; j>0; j--){
       
   277 						if (frames[i][j]!=undefined){
       
   278 							//trace(" x ",i+" "+j);
       
   279 							var Eheight  = frames[i][j]*5;
       
   280 							//				x			y									w					h
       
   281 							e = paper.rect(i*frameSize, config.heightmax-Eheight-addEheight, frameSize-margin, Eheight).attr({stroke:"#00","stroke-width":0.1,  fill: colors[j]});	
       
   282 							e.id = i;
       
   283 							e.state = 0; // 0 petit // 1 grand
       
   284 							e.heightStart = Eheight;
       
   285 							e.yStart = config.heightmax-Eheight-addEheight;
       
   286 							addEheight +=Eheight;
       
   287 							/*
       
   288 							e.mouseover(function () {
       
   289 								fisheye(this.id,1);
       
   290 							}).mouseout(function () {
       
   291 								fisheye(this.id,0);
       
   292 							});*/
       
   293 							slices[i].push(e);
       
   294 							//
       
   295 							$(e.node).attr('id', 't'+i);
       
   296 							$(e.node).attr('title', tweets[i].title);
       
   297 							addTip(e.node,  tweets[i].title);
       
   298 
       
   299 						}			
       
   300 					}
       
   301 				}
       
   302 			}
       
   303 		}
       
   304 
       
   305 		// AddTip  ******************************************************************************
       
   306 		function addTip(node, txt){
       
   307 			$(node).mouseenter(function(){
       
   308 			   tipText = txt;
       
   309 			   tip.fadeIn(0);
       
   310 			   over = true;
       
   311 			}).mouseleave(function(){
       
   312 			   tip.fadeOut(0);
       
   313 			   over = false;
       
   314 			});
       
   315 		}	
       
   316 	
       
   317 	}
       
   318 	
       
   319 	$(document).mousemove(function(e){
       
   320 		if (over){
       
   321 			tip.css("left", e.clientX+20).css("top", e.clientY+20);
       
   322 			tip.text(tipText);
       
   323 		}
       
   324 	});
       
   325 
       
   326 
       
   327 
       
   328 	ChartTimeLine();
       
   329 
       
   330 </script>
       
   331 
       
   332 
       
   333 </div>
       
   334 </body>
       
   335 </html>