Survey
HTML
<div id="canvas"></div>
JavaScript
var surveyOptions = {
fontFamily : "Times New Roman", //"Courier New",
fontSize : 12,
fontWeight: 'light',
textColor : "black",
paddings : [10,10,10,10],
bgColor : "white",
stroke : "black",
scretch : false,
rectColor : "aqua"
};
function elementExists(element)
{
while (element)
{
if (element == document)
return true;
element = element.parentNode;
}
return false;
}
function RESULT(name,vote,rectColor, textColor)
{
this.name = name;
this.vote = vote;
this.rectColor = ((typeof rectColor) !== 'undefined') ? rectColor : surveyOptions.rectColor;
this.textColor = ((typeof textColor) !== 'undefined') ? textColor : surveyOptions.textColor;
if(RESULT.votes == undefined)
RESULT.votes = vote;
else RESULT.votes += vote;
if (RESULT.maxVote == undefined) RESULT.maxVote = vote;
else if(RESULT.maxVote < vote ) RESULT.maxVote = vote;
}
function survey(results, div, width, height)
{
if(!(results[0] instanceof RESULT))
{
console.log("There is no proper result variable!");
return;
}
if(typeof div == 'undefined' || elementExists(document.getElementById('#' + div)) )
{
console.log("There is no div like " + div + " !");
return;
}
width = typeof width !== 'undefined' ? width : 300;
surveyOptions.scretch = typeof height == 'undefined' ? false : true;
var totalOptions = results.length,
heightMin = totalOptions * ( 8 * surveyOptions.fontSize / 3 ) + surveyOptions.paddings[0] + surveyOptions.paddings[2];
if( surveyOptions.scretch && heightMin > height)
{
console.log("there is not enough place in div ( height )!");
return;
}
else height = heightMin;
var paper = Raphael(div,width,height);
var border = paper.rect(0,0,paper.width,paper.height).attr({
fill: surveyOptions.bgColor,
stroke: surveyOptions.stroke
});
var startX = surveyOptions.paddings[3], startY = surveyOptions.paddings[0], optionHeight = ( height - surveyOptions.paddings[0] - surveyOptions.paddings[2] ) /...