# HG changeset patch # User veltr # Date 1327675761 -3600 # Node ID c8338a96f94c856dca2e14862627d17231c967a1 # Parent fb7d796d52a7584c14aac8bacf4617082e798d57 Hide sparkline if no annotations diff -r fb7d796d52a7 -r c8338a96f94c 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) {