Hide sparkline if no annotations
authorveltr
Fri, 27 Jan 2012 15:49:21 +0100
changeset 476 c8338a96f94c
parent 475 fb7d796d52a7
child 477 1c4894a4de72
Hide sparkline if no annotations
src/ldt/ldt/static/ldt/js/Ldt_front_sparkline.js
--- a/src/ldt/ldt/static/ldt/js/Ldt_front_sparkline.js	Fri Jan 27 15:40:10 2012 +0100
+++ b/src/ldt/ldt/static/ldt/js/Ldt_front_sparkline.js	Fri Jan 27 15:49:21 2012 +0100
@@ -6,32 +6,34 @@
             _height = $(this).height(),
             _max = _values.reduce(function(_a,_b) {
                 return Math.max(_a,_b);
-            }, 1),
-            _x = function(_p) {
-                return _p * _width / _nb;
-            },
-            _y = function(_p) {
-                return _height * ( 1 - _p / _max );
-            },
-            _d = _values.map(function(_v,_k) {
-                return ( _k == 0 ?
-                    "M" + _x(_k) + " " + _y(_v) :
-                    "C" + _x(_k-.5) + " " + _y(_values[_k - 1])
-                    + " " + + _x(_k-.5) + " " + _y(_v)
-                    + " " + + _x(_k) + " " + _y(_v)
-                    ) ;
-            }).join("") + "L" + _width + " " + _height + "L0 " + _height;
+            }, 0);
         this.innerHTML = '';
-        var _paper = new Raphael(this,_width,_height);
-        _paper.rect(0,0,_width,_height).attr({
-            "stroke" : "none",
-            "fill" : "#ffffff",
-            "opacity" : .8,
-        });
-        _paper.path(_d).attr({
-            "fill" : "#adadad",
-            "stroke" : "#808080"
-        });
+        if (_max) {
+            var _x = function(_p) {
+                    return _p * _width / _nb;
+                },
+                _y = function(_p) {
+                    return _height * ( 1 - _p / _max );
+                },
+                _d = _values.map(function(_v,_k) {
+                    return ( _k == 0 ?
+                        "M" + _x(_k) + " " + _y(_v) :
+                        "C" + _x(_k-.5) + " " + _y(_values[_k - 1])
+                        + " " + + _x(_k-.5) + " " + _y(_v)
+                        + " " + + _x(_k) + " " + _y(_v)
+                        ) ;
+                }).join("") + "L" + _width + " " + _height + "L0 " + _height;
+            var _paper = new Raphael(this,_width,_height);
+            _paper.rect(0,0,_width,_height).attr({
+                "stroke" : "none",
+                "fill" : "#ffffff",
+                "opacity" : .8,
+            });
+            _paper.path(_d).attr({
+                "fill" : "#adadad",
+                "stroke" : "#808080"
+            });
+        }
     });
 
     $(".polemics li").each(function(_i,_e) {