[F plot] make jquery plots accept a fourth column that specifies a date format for tooltips
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
Wed, 29 Jul 2009 12:46:09 +0200
changeset 2564 5f38f5eaff86
parent 2563 415179b608c5
child 2565 df34d3720ff5
child 2580 6e9453fd11ef
[F plot] make jquery plots accept a fourth column that specifies a date format for tooltips
web/data/cubicweb.flot.js
--- a/web/data/cubicweb.flot.js	Wed Jul 29 11:16:42 2009 +0200
+++ b/web/data/cubicweb.flot.js	Wed Jul 29 12:46:09 2009 +0200
@@ -1,32 +1,34 @@
 function showTooltip(x, y, contents) {
     $('<div id="tooltip">' + contents + '</div>').css( {
             position: 'absolute',
-	    display: 'none',
-	    top: y + 5,
+        display: 'none',
+        top: y + 5,
             left: x + 5,
             border: '1px solid #fdd',
             padding: '2px',
             'background-color': '#fee',
             opacity: 0.80
-		}).appendTo("body").fadeIn(200);
+        }).appendTo("body").fadeIn(200);
 }
 
 var previousPoint = null;
 function onPlotHover(event, pos, item) {
     if (item) {
         if (previousPoint != item.datapoint) {
-    	previousPoint = item.datapoint;
-    	
-    	$("#tooltip").remove();
-    	var x = item.datapoint[0].toFixed(2),
-    	    y = item.datapoint[1].toFixed(2);
-	if (item.datapoint.length == 3) {
-	    var x = new Date(item.datapoint[2]);
-	    x = x.toLocaleDateString() + ' ' + x.toLocaleTimeString();
-	}
-    	showTooltip(item.pageX, item.pageY,
-    		    item.series.label + ': (' + x + ' ; ' + y + ')');
+            previousPoint = item.datapoint;
+            $("#tooltip").remove();
+            var x = item.datapoint[0].toFixed(2),
+                y = item.datapoint[1].toFixed(2);
+            if (item.datapoint.length == 3) {
+                x = new Date(item.datapoint[2]);
+                x = x.toLocaleDateString() + ' ' + x.toLocaleTimeString();
+            } else if (item.datapoint.length == 4) {
+               x = new Date(item.datapoint[2]);
+               x = x.strftime(item.datapoint[3]);
             }
+            showTooltip(item.pageX, item.pageY,
+            item.series.label + ': (' + x + ' ; ' + y + ')');
+        }
     } else {
         $("#tooltip").remove();
         previousPoint = null;