/* */ function pandoraFlotPie(graph_id, values, labels, nseries, width, font_size, water_mark, separator) { var labels = labels.split(separator); var data = values.split(separator); for( var i = 0; i'+label+'
'+Math.round(series.percent)+'%'; }, background: { opacity: 0.5, color: '#000' } }; } var plot = $.plot($('#'+graph_id), data, { series: { pie: { show: true, radius: 3/4, label: label_conf //$label_str } }, legend: { show: true }, grid: { hoverable: true, clickable: true } }); var legends = $('#'+graph_id+' .legendLabel'); legends.each(function () { // fix the widths so they don't jump around $(this).css('width', $(this).width()+5); $(this).css('font-size', font_size+'pt'); }); // Events $('#'+graph_id).bind('plothover', pieHover); $('#'+graph_id).bind('plotclick', pieClick); $('#'+graph_id).bind('mouseout',resetInteractivity); function pieHover(event, pos, obj) { if (!obj) return; index = obj.seriesIndex; legends.css('font-weight', ''); legends.eq(index).css('font-weight', 'bold'); } // Reset styles function resetInteractivity() { legends.each(function () { // fix the widths so they don't jump around $(this).css('font-weight', ''); }); } if(water_mark) { set_watermark(graph_id, plot, $('#watermark_image_'+graph_id).attr('src')); } } function pandoraFlotHBars(graph_id, values, labels, water_mark, maxvalue, water_mark, separator, separator2) { values = values.split(separator2); var datas = new Array(); for(i=0;i'+v+''; } // Events $('#'+graph_id).bind('plothover', function (event, pos, item) { $('.values_'+graph_id).css('font-weight', ''); if(item != null) { index = item.dataIndex; $('#value_'+index+'_'+graph_id).css('font-weight', 'bold'); } }); if(water_mark) { set_watermark(graph_id, plot, $('#watermark_image_'+graph_id).attr('src')); } } function pandoraFlotVBars(graph_id, values, labels, labels_long, legend, colors, water_mark, maxvalue, water_mark, separator, separator2) { values = values.split(separator2); legend = legend.split(separator); labels_long = labels_long.split(separator); colors = colors.split(separator); var datas = new Array(); for(i=0;i'+v+''; } // Events //~ $('#'+graph_id).bind('plothover', function (event, pos, item) { //~ $('.values_'+graph_id).css('font-weight', ''); //~ if(item != null) { //~ index = item.dataIndex; //~ $('#value_'+index+'_'+graph_id).css('font-weight', 'bold'); //~ } //~ }); if(water_mark) { set_watermark(graph_id, plot, $('#watermark_image_'+graph_id).attr('src')); } } function pandoraFlotSlicebar(graph_id, values, datacolor, labels, legend, acumulate_data, intervaltick, water_mark, maxvalue, separator, separator2) { values = values.split(separator2); labels = labels.split(separator); legend = legend.split(separator); acumulate_data = acumulate_data.split(separator); datacolor = datacolor.split(separator); // Check possible adapt_keys on classes check_adaptions(graph_id); var datas = new Array(); for(i=0;i' + legend[i] + ''; } } return ''; } } function pandoraFlotArea(graph_id, values, labels, labels_long, legend, colors, type, serie_types, water_mark, width, max_x, homeurl, unit, font_size, menu, events, event_ids, legend_events, alerts, alert_ids, legend_alerts, yellow_threshold, red_threshold, force_integer, separator, separator2) { var threshold = true; var thresholded = false; values = values.split(separator2); serie_types = serie_types.split(separator); labels_long = labels_long.split(separator); labels = labels.split(separator); legend = legend.split(separator); events = events.split(separator); event_ids = event_ids.split(separator); if (alerts.length != 0) alerts = alerts.split(separator); else alerts = []; alert_ids = alert_ids.split(separator); colors = colors.split(separator); var eventsz = new Array(); $.each(events,function(i,v) { eventsz[event_ids[i]] = v; }); var alertsz = new Array(); $.each(alerts,function(i,v) { alertsz[alert_ids[i]] = v; }); switch(type) { case 'line_simple': stacked = null; filled = false; break; case 'line_stacked': stacked = 'stack'; filled = false; break; case 'area_simple': stacked = null; filled = true; break; case 'area_stacked': stacked = 'stack'; filled = true; break; } var datas = new Array(); var data_base = new Array(); // Prepared to turn series with a checkbox // var showed = new Array(); for(i=0;i axes.xaxis.max || pos.y < axes.yaxis.min || pos.y > axes.yaxis.max) { return; } var j, dataset = currentPlot.getData(); var i = 0; for (k = 0; k < dataset.length; k++) { // k is the real series counter // i is the series counter without thresholds var series = dataset[k]; if(series.label == null) { continue; } // find the nearest points, x-wise for (j = 0; j < series.data.length; ++j) if (series.data[j][0] > pos.x) { break; } var y = series.data[j][1]; if(currentRanges == null || (currentRanges.xaxis.from < j && j < currentRanges.xaxis.to)) { $('#timestamp_'+graph_id).show(); // If no legend, the timestamp labels are short and with value if(legends.length == 0) { $('#timestamp_'+graph_id).text(labels[j] + ' (' + parseFloat(y).toFixed(2) + ')'); } else { $('#timestamp_'+graph_id).text(labels_long[j]); } $('#timestamp_'+graph_id).css('top', plot.offset().top-$('#timestamp_'+graph_id).height()*1.5); var timesize = $('#timestamp_'+graph_id).width(); if(currentRanges != null) { dataset = plot.getData(); } var timenewpos = dataset[0].xaxis.p2c(pos.x)+plot.offset().left; var canvaslimit = plot.offset().left + plot.width(); if(timesize+timenewpos > canvaslimit) { $('#timestamp_'+graph_id).css('left', timenewpos - timesize); } else { $('#timestamp_'+graph_id).css('left', timenewpos); } } else { $('#timestamp_'+graph_id).hide(); } var label_aux = series.label + ' = '; if(serie_types[i] != 'points') { legends.eq(i).text(label_aux.replace(/=.*/, '= ' + parseFloat(y).toFixed(2) +' '+unit)); } legends.eq(i).css('font-size',font_size+'pt'); legends.eq(i).css('color','#000'); i++; } } // Events $('#'+graph_id).bind('plothover', function (event, pos, item) { overview.setCrosshair({ x: pos.x, y: 0 }); currentPlot = plot; latestPosition = pos; if (!updateLegendTimeout) { updateLegendTimeout = setTimeout(updateLegend, 50); } }); $('#'+graph_id).bind("plotclick", function (event, pos, item) { plot.unhighlight(); if (item && item.series.label != '' && (item.series.label == legend_events || item.series.label == legend_alerts)) { plot.unhighlight(); var canvaslimit = parseInt(plot.offset().left + plot.width()); var dataset = plot.getData(); var timenewpos = parseInt(dataset[0].xaxis.p2c(pos.x)+plot.offset().left); var extrasize = parseInt($('#extra_'+graph_id).css('width').split('px')[0]); var left_pos; if(extrasize+timenewpos > canvaslimit) { left_pos = timenewpos - extrasize - 20; } else { left_pos = timenewpos + 20; } var extra_info = 'No info to show'; var extra_show = false; $('#extra_'+graph_id).css('left',left_pos); $('#extra_'+graph_id).css('top',plot.offset().top + 25); switch(item.series.label) { case legend_alerts: extra_info = ''+legend_alerts+' - '+labels_long[item.dataIndex]+''+get_event_details(alertsz[item.dataIndex]); extra_show = true; break; case legend_events: extra_info = ''+legend_events+' - '+labels_long[item.dataIndex]+''+get_event_details(eventsz[item.dataIndex]); extra_show = true; break; default: return; break; } if(extra_show) { $('#extra_'+graph_id).html(extra_info); $('#extra_'+graph_id).css('display',''); } plot.highlight(item.series, item.datapoint); } else { $('#extra_'+graph_id).html(''); $('#extra_'+graph_id).css('display','none'); } }); $('#overview_'+graph_id).bind('plothover', function (event, pos, item) { plot.setCrosshair({ x: pos.x, y: 0 }); currentPlot = overview; latestPosition = pos; if (!updateLegendTimeout) { updateLegendTimeout = setTimeout(updateLegend, 50); } }); $('#'+graph_id).bind('mouseout',resetInteractivity); $('#overview_'+graph_id).bind('mouseout',resetInteractivity); // Reset interactivity styles function resetInteractivity() { $('#timestamp_'+graph_id).hide(); dataset = plot.getData(); for (i = 0; i < dataset.length; ++i) { legends.eq(i).text(legends.eq(i).text().replace(/=.*/, '')); } plot.clearCrosshair(); overview.clearCrosshair(); } // Format functions function xFormatter(v, axis) { if(labels[v] == undefined) { return ''; } return '
'+labels[v]+'
'; } function yFormatter(v, axis) { var formatted = number_format(v,force_integer,unit); return '
'+formatted+'
'; } function lFormatter(v, item) { return '
'+v+'
'; // Prepared to turn series with a checkbox //return '
'+v+'
'; } // Prepared to turn series with a checkbox //~ $('.check_serie_'+graph_id).click(function() { //~ // Format of the id is graph_3905jf93f03_serie_id //~ id_clicked = this.id.split('_')[3]; //~ // Update the serie clicked //~ showed[id_clicked] = this.checked; //~ }); if(menu) { var parent_height; $('#menu_overview_'+graph_id).click(function() { $('#overview_'+graph_id).toggle(); adjust_menu(graph_id, plot, parent_height); }); $('#menu_threshold_'+graph_id).click(function() { datas = new Array(); if(thresholded) { thresholded = false; } else { $.each(threshold_data, function() { datas.push(this); }); thresholded = true; } $.each(data_base, function() { // Prepared to turning series //if(showed[this.id.split('_')[1]]) { datas.push(this); //} }); plot = $.plot($('#'+graph_id), datas, options); plot.setSelection(currentRanges); }); $('#menu_cancelzoom_'+graph_id).click(function() { // cancel the zooming plot = $.plot($('#'+graph_id), data_base, $.extend(true, {}, options, { xaxis: { min: 0, max: max_x }, legend: { show: false } })); $('#menu_cancelzoom_'+graph_id).attr('src',homeurl+'/images/zoom_cross.disabled.png'); overview.clearSelection(); currentRanges = null; }); // Adjust the menu image on top of the plot $('#menu_overview_'+graph_id)[0].onload = function() { // If there is no legend we increase top-padding to make space to the menu if(legends.length == 0) { $('#menu_'+graph_id).parent().css('padding-top',$('#menu_'+graph_id).css('height')); } // Add bottom margin in the legend var menu_height = parseInt($('#menu_'+graph_id).css('height').split('px')[0]); var legend_margin_bottom = parseInt($('#legend_'+graph_id).css('margin-bottom').split('px')[0]); $('#legend_'+graph_id).css('margin-bottom', menu_height+legend_margin_bottom+'px'); parent_height = parseInt($('#menu_'+graph_id).parent().css('height').split('px')[0]); adjust_menu(graph_id, plot, parent_height); } } if(water_mark) { set_watermark(graph_id, plot, $('#watermark_image_'+graph_id).attr('src')); } } function adjust_menu(graph_id, plot, parent_height) { if($('#'+graph_id+' .xAxis .tickLabel').eq(0).css('width') != undefined) { left_ticks_width = $('#'+graph_id+' .xAxis .tickLabel').eq(0).css('width').split('px')[0]; } else { left_ticks_width = 0; } var parent_height_new = 0; var legend_height = parseInt($('#legend_'+graph_id).css('height').split('px')[0]) + parseInt($('#legend_'+graph_id).css('margin-top').split('px')[0]); if($('#overview_'+graph_id).css('display') == 'none') { overview_height = 0; } else { overview_height = parseInt($('#overview_'+graph_id).css('height').split('px')[0]) + parseInt($('#overview_'+graph_id).css('margin-top').split('px')[0]); } $('#menu_'+graph_id).css('top',(-parent_height+legend_height-overview_height-7)+'px'); $('#menu_'+graph_id).css('left',plot.width()-(left_ticks_width/2)); $('#menu_'+graph_id).show(); } function set_watermark(graph_id, plot, watermark_src) { var img = new Image(); img.src = watermark_src; var context = plot.getCanvas().getContext('2d'); // Once it's loaded draw the image on the canvas. img.addEventListener('load', function () { //~ // Now resize the image: x, y, w, h. var down_ticks_height = 0; if($('#'+graph_id+' .yAxis .tickLabel').eq(0).css('height') != undefined) { down_ticks_height = $('#'+graph_id+' .yAxis .tickLabel').eq(0).css('height').split('px')[0]; } var left_pos = parseInt(context.canvas.width - 3) - $('#watermark_image_'+graph_id)[0].width; var top_pos = parseInt(context.canvas.height - down_ticks_height - 20) - $('#watermark_image_'+graph_id)[0].height; context.drawImage(this, left_pos, top_pos); }, false); } function get_event_details (event_ids) { table = ''; if (typeof(event_ids) != "undefined") { var inputs = []; var table; inputs.push ("get_events_details=1"); inputs.push ("event_ids="+event_ids); inputs.push ("page=include/ajax/events"); jQuery.ajax ({ data: inputs.join ("&"), type: 'GET', url: action="../../ajax.php", timeout: 10000, dataType: 'html', async: false, success: function (data) { table = data; } }); } return table; } function adjust_left_width_canvas(adapter_id, adapted_id) { adapter_left_margin = $('#'+adapter_id+' .yAxis .tickLabel').css('width'); adapted_pix = $('#'+adapted_id).css('width').split('px'); new_adapted_width = parseInt(adapted_pix[0])-parseInt(adapter_left_margin); $('#'+adapted_id).css('width',new_adapted_width); $('#'+adapted_id).css('margin-left',adapter_left_margin); } function check_adaptions(graph_id) { var classes = $('#'+graph_id).attr('class').split(' '); $.each(classes, function(i,v) { // If has a class starting with adapted, we adapt it if(v.split('_')[0] == 'adapted') { var adapter_id = $('.adapter_'+v.split('_')[1]).attr('id'); adjust_left_width_canvas(adapter_id, graph_id); } }); } function number_format(number, force_integer, unit) { if(force_integer) { if(Math.round(number) != number) { return ''; } } else { var decimals = 2; var factor = 10 * decimals; number = Math.round(number*factor)/factor } var shorts = ["", "K", "M", "G", "T", "P", "E", "Z", "Y"]; var pos = 0; while(1){ if (number >= 1000) { //as long as the number can be divided by 1000 pos++; //Position in array starting with 0 number = number / 1000; } else { break; } } return number+' '+shorts[pos]+unit; }