function badgeCode(g, context, frameNumber) {
context.fillStyle = "#34495e";
context.fillRect(0, 0, width, height);
context.fillStyle = "#fff";
context.fill(clip);
var hex = new Path2D(hexbinner.hexagon());
bins.forEach(function(bin) {
context.translate(bin.x,bin.y);
var arrayvalues = Array.from(bin);
var sum = d3.sum(arrayvalues, i => i.count)
bin.PCTPOP = d3.sum(arrayvalues, i => i.SUMPOP)/sum;
bin.PCTSODA = d3.sum(arrayvalues, i => i.SUMSODA)/sum;
bin.PCTCOKE = d3.sum(arrayvalues, i => i.SUMCOKE)/sum;
bin.PCTOTHER = d3.sum(arrayvalues, i => i.SUMOTHER)/sum;
if (bin.PCTPOP == 0 && bin.PCTSODA == 0 && bin.PCTCOKE == 0 && bin.PCTOTHER == 0) {
context.fillStyle = "white";
} else {
var color = "white";
switch(frameNumber) {
case 1:
color = "rgb("
+ Math.round((1-bin.PCTSODA) * 100) + "%,"
+ Math.round((1) * 100) + "%,"
+ Math.round((1) * 100) + "%)";
break;
case 2:
color = "rgb("
+ Math.round((1-bin.PCTSODA) * 100) + "%,"
+ Math.round((1) * 100) + "%,"
+ Math.round((1-(0.3*bin.PCTPOP)) * 100) + "%)";
break;
case 3:
color = "rgb("
+ Math.round((1-(0.3*bin.PCTSODA)) * 100) + "%,"
+ Math.round((1) * 100) + "%,"
+ Math.round((1-bin.PCTPOP) * 100) + "%)";
break;
case 4:
color = "rgb("
+ Math.round((1) * 100) + "%,"
+ Math.round((1) * 100) + "%,"
+ Math.round((1-bin.PCTPOP) * 100) + "%)";
break;
case 5:
color = "rgb("
+ Math.round((1) * 100) + "%,"
+ Math.round((1-(0.3*bin.PCTCOKE)) * 100) + "%,"
+ Math.round((1-bin.PCTPOP) * 100) + "%)";
break;
case 6:
color = "rgb("
+ Math.round((1) * 100) + "%,"
+ Math.round((1-bin.PCTCOKE) * 100) + "%,"
+ Math.round((1-(0.3*bin.PCTPOP)) * 100) + "%)";
break;
case 7:
color = "rgb("
+ Math.round((1) * 100) + "%,"
+ Math.round((1-bin.PCTCOKE) * 100) + "%,"
+ Math.round((1) * 100) + "%)";
break;
case 8:
color = "rgb("
+ Math.round((1-(0.3*bin.PCTSODA)) * 100) + "%,"
+ Math.round((1-bin.PCTCOKE) * 100) + "%,"
+ Math.round((1) * 100) + "%)";
break;
case 9:
color = "rgb("
+ Math.round((1-bin.PCTSODA) * 100) + "%,"
+ Math.round((1-(0.3*bin.PCTCOKE)) * 100) + "%,"
+ Math.round((1) * 100) + "%)";
break;
case 10:
color = "rgb("
+ Math.round((1-bin.PCTSODA) * 100) + "%,"
+ Math.round((1) * 100) + "%,"
+ Math.round((1) * 100) + "%)";
break;
}
context.fillStyle = color;
}
context.fill(hex);
context.setTransform(1, 0, 0, 1, 0, 0);
});
context.stroke(clip);
}