<p> /**
* @fileOverview Plots the distribution of number-of-supporting-snippets across all the questions
* and their (possible) impact on consensus
* i.e.
* - for all the questions
* - the total number of times consensus was achieved with X snippets
* - the total number of times no consensus was achieved with X snippets
*/
//contains the number-of-snippets and corresponding counts for consensus and non-consensus
var snippetDistNested = [];
//adds the left property to the buckets to set the offset for the stacked bar graph
function prepareBuckets(result) {
var left = 0;
for (var i = 1; i consensusThreshold) {
consensusVoteType = voteType;
}
}
return consensusVoteType;
}
//prepare the data to be plotted
function prepareData(data) {
//iterate over all completed questions in the queue
for (var q = 0; q 0){
for(var j=0; j 0){
for(var j=0; j max){
max = totalQuestionCount;
}
}
max = Math.round(max + (max/10));
var scale = Math.round(availableWidth/max);
return scale;
}
//plot
function visualize(data) {
var totalHeight = document.height;
var totalWidth = document.width;
var padding = 50;
var availableHeight = totalHeight - (3 * padding);
var availableWidth = totalWidth - (3 * padding);
var snippetRange = snippetDistNested.length;
var heightPerBar = (availableHeight/snippetRange);
var maxHeightPerBar = 70;
if(heightPerBar > maxHeightPerBar){
heightPerBar = maxHeightPerBar;
}
var horzScale = findHorzScale(availableWidth);
var vis = new pv.Panel()
.canvas('plot')
.width(availableWidth)
.height(availableHeight)
.left(padding)
.right(padding)
.top(-availableHeight/2 + padding)
.bottom(padding);
var panels = vis.add(pv.Panel)
.data(snippetDistNested)
.left(padding)
.top(function(d) {return heightPerBar * this.index});
panels.anchor('left')
.add(pv.Label)
.text(function(d) {return d.snippetCount})
.textAlign('right');
var bar = panels.add(pv.Bar)
.data(function(a) { return a.result; })
.height(heightPerBar/2)
.left(function(a) { return horzScale * a.left; })
.strokeStyle("#000")
.fillStyle(function(a) { return (a.type == "consensus") ? '#aac' : '#f44'; })
.width(function(a) { return horzScale * a.questionCount; });
bar.anchor("right").add(pv.Label)
.visible(function(d) { return d.questionCount; })
.textStyle("white")
.text(function(d) { return (d.questionCount > 2) ? d.questionCount: ""; })
.textAlign('right');
vis.render();
}
$(function() {
$.getJSON(
'/get_answers_with_judgments?queue_id=' + escape(queue_id) + '&callback=?',
null,
function(data) {
//console.log(data);
prepareData(data);
visualize(data);
},
'jsonp'
);
});
</p>