var i,x,tr,td,th,value,winner_value,leftpos,tableID; var winner = ""; var tableCN = ""; var results = []; var base_colors = ["#EEE","#CCC","#AAA","#888","#666","#444","#222"]; var colors = ["#CC8A36","#CBB224","#C1C91E","#96CA1E","#27B288","#4AACC5"]; function stackedChart(scopeDivId) { var targetDiv = ''; var targetChildren = ''; var table = ''; var value = ''; var target = ''; var targetTable = ''; var answerRow = ''; targetChildren = plib.Dom.query(".chart-stacked", document.body); for(i=0;targetChildren.length>i;i++){ target = targetChildren[i]; if(plib.Dom.hasClass(target,"graphRendered")) { continue; } plib.Dom.addClass(target,"graphRendered"); targetTable = plib.Dom.query("table",targetChildren[i]); targetWidth = plib.Dom.width(target); thead = plib.Dom.query("thead",targetTable); thead[0].style.display = 'none'; caption = plib.Dom.query("caption", targetTable); caption[0].style.display = 'none'; leftpos = 0; chart_width = 0; value = 0; winner_value = 0; winner = ""; results = plib.Dom.query("tbody tr", targetTable); chart_colors = colors; switch(results.length){ case 5: chart_colors = [colors[0],colors[1],colors[2],colors[3],colors[5]]; break; case 4: chart_colors = [colors[0],colors[2],colors[3],colors[5]]; break; case 3: chart_colors = [colors[0],colors[2],colors[5]]; break; case 2: chart_colors = [colors[0],colors[5]]; break; } for(x=0;results.length>x;x++){ answerRow = results[x]; td = plib.Dom.query("td", answerRow); th = plib.Dom.query("th", answerRow); percentage = td[0].getElementsByTagName("a")[0].innerHTML.replace('%',''); //ensure that re-rendering kills the percentage and use for calculations try { value = percentage*1; if(value>winner_value){ winner = answerRow.className; winner_value = value; } if(plib.Dom.hasClass(targetChildren[i], "round")){ Math.round(percentage); } } catch(err) { winner_value = 0; } th[0].style.display = 'none'; th[0].style.position = 'absolute'; th[0].style.left = leftpos+'%'; td[0].style.position = 'absolute'; td[0].style.left = leftpos+'%'; td[0].style.width = Math.round(targetWidth*(value/100))+"px"; td[0].style.backgroundColor = chart_colors[x]; if(plib.Dom.hasClass(target,"label-winner")){ td[0].getElementsByTagName("a")[0].style.textIndent = '-937em'; } td[0].getElementsByTagName("a")[0].innerHTML = percentage+'%'; td[0].title = th[0].innerHTML + ': '+percentage + '%' chart_width += value; leftpos = leftpos + value; } chart_width = chart_width*(targetWidth/100); if(plib.Dom.hasClass(target,"label-winner")){ winnerTd = plib.Dom.query("tr."+winner+" td", target); winnerTh = plib.Dom.query("tr."+winner+" th", target); winnerWidth = plib.Dom.width(winnerTd[0]); winnerTh[0].style.display = 'block'; winnerTh[0].style.width = winnerWidth+"px"; graphDiv = plib.Dom.query(target); winnerTh = plib.Dom.query("tr."+winner+" th", target); graphDiv[0].style.paddingBottom = plib.Dom.height(winnerTh[0])+2+"px"; winnerAnchor = plib.Dom.query("tr."+winner+" td a", target); winnerAnchor[0].style.textIndent = 0; } } }