var path = ""
var data = null;
var sub_times = [];
var overall_times = [];
var chart_data = [];
var show_hide = {}
var options = { selection: { mode: "xy" },
legend: { backgroundOpacity: 0,
position: "sw",
show: true,
noColumns : 1,
labelFormatter :
function(label, series) {
if (show_hide[label] === undefined)
show_hide[label] = true;
var css = '';
if (!show_hide[label]) {
css = 'style="font-style: italic"';
}
var v = '
' + label + '
';
return v;}},
xaxes: [{min: null, max: null, label: 'push'}],
yaxes: [{min: null, max: null, label: "time"},
{position: "right"}],
grid: { clickable: true, hoverable : true }
};
function addCommas(nStr) {
var rgx = /(\d+)(\d{3})/;
while (rgx.test(nStr)) {
nStr = nStr.replace(rgx, '$1' + ',' + '$2');
}
return nStr;
}
// Number -> String
function format_ms(ms) {
return addCommas(String(ms)) + " ms"
}
// Number -> String
function format_time(ms) {
if (ms >= 300000)
return Number(ms/60000).toFixed(2) + " m " + "("+ format_ms(ms)+")";
if (ms >= 10000)
return Number(ms/1000).toFixed(2) + " s" + "("+ format_ms(ms)+")";
return format_ms(ms);
}
function legend_click(l) {
show_hide[l] = !show_hide[l];
show();
serialize_opts(options);
}
var placeholder = $("#_chart");
var previousPoint = null;
function showTooltip(x, y, contents) {
$('' + contents + '
').css( {
position: 'absolute',
display: 'none',
top: y + 5,
left: x + 5,
border: '1px solid #fdd',
padding: '2px',
'background-color': '#fee',
opacity: 0.80
}).appendTo("body").fadeIn(200);
}
function makeTooltip(item,path) {
var x = item.datapoint[0];
var y = item.datapoint[1].toFixed(2);
showTooltip(item.pageX, item.pageY,
item.series.label + ' at push ' + x + ": "
+ format_time(y));
}
placeholder.bind("plotselected", handle_selection);
// is the tooltip shown b/c of a click?
var tooltip_clicked = false;
function remove_tooltip() {
tooltip_clicked = false;
$("#tooltip").remove();
}
function hover(event,pos,item) {
if (tooltip_clicked) return;
if (item) {
// don't re-show the same tool-tip that's already shown
if (previousPoint != item.dataIndex) {
previousPoint = item.dataIndex;
remove_tooltip();
makeTooltip(item,path);
}
}
else {
remove_tooltip();
previousPoint = null;
}
}
function click(e,pos,item) {
if (tooltip_clicked) {
remove_tooltip();
return;
}
if (!item) return;
tooltip_clicked = true;
// if we've already got the tooltip, just keep it around
if (previousPoint != item.dataIndex) {
$("#tooltip").remove();
makeTooltip(item,path);
}
}
// sort chart data based on the order of a[0], b[0]
function sorter(a,b) {
if (a[0] < b[0]) return -1;
if (a[0] > b[0]) return 1;
return 0;
}
function load_data(d) {
chart_data = [];
overall_times = [];
sub_times = [];
pdata = []
data = d;
reset_chart();
pdata = data && JSON.parse(data);
var max_overall = 0;
var max_sub = 0;
// build the timing data arrays
for (var i = 0; i < pdata.length; i++) {
overall_times.push([pdata[i][0], pdata[i][1]]);
max_overall = Math.max(max_overall, pdata[i][1]);
if (pdata[i][2].length != 0) {
for (var j = 0; j < pdata[i][2].length; j++) {
sub_times[j] = sub_times[j] || [];
sub_times[j].push([pdata[i][0],pdata[i][2][j][0]]);
max_sub = Math.max(max_sub, pdata[i][2][j][0]);
}
}
};
// is there a significant difference between the overall times
// and the internal timings?
var ya = 1;
if ((max_overall > (5 * max_sub)) || ((max_overall * 5) < max_sub))
ya = 2;
// put the data into the chart format
chart_data.push({data: overall_times.sort(sorter), label: "Overall Time", color: "#804040"});
for(var i = 0; i < sub_times.length; i++) {
var n = (sub_times[i].length/overall_times.length);
chart_data.push({data: sub_times[i].sort(sorter), label: "Timer "+ (i+1),
lines: { show: (.9