From 94baad61a5a6067c0a9f1ac3bf12ecc7e20690e3 Mon Sep 17 00:00:00 2001 From: Loki Date: Fri, 1 Mar 2013 14:17:57 -0500 Subject: [PATCH 1/2] Fixed iteration loop instead of enumeration Although the for..in is usually correct, it's actually an enumeration instead of a true iteration. The problem came about when using prototype and jQuery.noConflict(). Prototype by default adds a few extra methods to the Array, enumerating through the array, shows the array method, which the plugin tries to render as bars. This causes a lot of 'undefined' values to show up. Doing a proper iteration through the jQuery $.each() method makes it work as it should. --- jqBarGraph.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/jqBarGraph.js b/jqBarGraph.js index b07ef7f..293df17 100755 --- a/jqBarGraph.js +++ b/jqBarGraph.js @@ -114,7 +114,7 @@ max = max(data); colPosition = 0; // for printing colors on simple bar graph - for(var val in data){ + $.each(data, function(val, valData){ valueData = data[val][0]; if (valueData instanceof Array) @@ -203,12 +203,12 @@ $('#graphFieldBar'+unique).css({'height': fieldHeight}); } - } + }); //creating legend array from legends param - for(var l in arr.legends){ + $.each(arr.legends, function(l, lData){ leg.push([ arr.colors[l], arr.legends[l], el.id, l ]); - } + }); createLegend(leg); // create legend from array @@ -285,4 +285,4 @@ return 0; } -})(jQuery); \ No newline at end of file +})(jQuery); From a4b53ede15c22f65520023b2a682592d81dd6afc Mon Sep 17 00:00:00 2001 From: Loki Date: Mon, 4 Mar 2013 15:43:44 -0500 Subject: [PATCH 2/2] Fixed multi bar graph width for data diff size When multi-bar graph is used, the width between arrays can change. e.g.: if you have 6 values for 2007, 6 values for 2008, but only 3 values for 2009, the previous code would apply the width of 2009 bars to the 2008 and 2007 bars. This adds the width to the different bars generated and only does positioning for multi. --- jqBarGraph.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jqBarGraph.js b/jqBarGraph.js index 293df17..9b0b938 100755 --- a/jqBarGraph.js +++ b/jqBarGraph.js @@ -180,13 +180,13 @@ sv = arr.prefix+valueData[i]+arr.postfix; fs = 12; // font-size is 0 if showValues = false } - o = "
"+sv+"
"; + o = "
"+sv+"
"; $('#graphFieldBar'+unique).prepend(o); } } if(arr.type=='multi') - $('.subBars'+el.id).css({ 'width': wid, 'position': 'absolute', 'bottom': 0 }); + $('.subBars'+el.id).css({ 'position': 'absolute', 'bottom': 0 }); //position of bars if(arr.position == 'bottom') $('.graphField'+el.id).css('bottom',0); @@ -285,4 +285,4 @@ return 0; } -})(jQuery); +})(jQuery);