function drawGoogleBubbleChart(parentID, width, height, json) {
var bcd = JSON.parse(json);
var bubbles = bcd.Bubbles;
var bubbleSeriesData = bcd.BubbleSeriesList;
var keyframeData = bcd.Keyframes;
var minX = 0;
var minY = 0;
var maxX = 0;
var maxY = 0;
var keyframeIndex = 0;
var keyframes = [];
var data = [];
for (var k = 0; k < keyframeData.length; ++k) {
var frame = [];
frame.push(['Label', 'x', 'y', 'Type', 'Count']);
var colors = [];
for (var i = 0; i < bubbles.length; ++i) {
var row = [];
var index = bubbles[i].BubbleSeriesIndex;
if (bubbles[i].KeyframeIndex == k) {
maxX = bubbles[i].XValue > maxX ? bubbles[i].XValue : maxX;
maxY = bubbles[i].YValue > maxY ? bubbles[i].YValue : maxY;
row.push(bubbles[i].Label);
row.push(bubbles[i].XValue);
row.push(bubbles[i].YValue);
row.push(bubbleSeriesData[index].Title);
row.push(bubbles[i].Amount);
} else {
row.push("");
row.push(0);
row.push(0);
row.push("");
row.push(0);
}
colors.push(rgbToHex(bubbleSeriesData[index].Color.R, bubbleSeriesData[index].Color.G, bubbleSeriesData[index].Color.B));
frame.push(row);
}
keyframes.push({
Frame: frame,
Colors: colors
});
data.push(google.visualization.arrayToDataTable(frame));
}
var xTitle = bcd.XAxis != null ? bcd.XAxis.Title : "";
var yTitle = bcd.YAxis != null ? bcd.YAxis.Title : "";
var options = {
animation: {
duration: 500,
easing: 'out'
},
bubble: {
textStyle: {
color: 'none'
}
},
hAxis: {
title: xTitle,
minValue: minX,
maxValue: maxX + (maxX * .05)
},
vAxis: {
title: yTitle,
minValue: minY,
maxValue: maxY + (maxY * .05)
},
width: width,
height: height,
colors: keyframes[keyframeIndex].Colors
};
var chart = new google.visualization.BubbleChart(document.getElementById(parentID));
var button = document.getElementById('PlayBubbleButton');
chart.draw(data[keyframeIndex++], options);
button.onclick = function () {
if (keyframeIndex < keyframes.length) {
options.colors = keyframes[keyframeIndex].Colors;
chart.draw(data[keyframeIndex++], options);
}
}
}