File: pgbadger.js

package info (click to toggle)
pgbadger 13.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,960 kB
  • sloc: perl: 22,613; javascript: 22,274; sh: 4; makefile: 2
file content (269 lines) | stat: -rw-r--r-- 8,983 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269

/* <![CDATA[ */

function create_download_button (buttonid, cssclass) {
	if (cssclass == undefined) {
		cssclass ='btn btn-info';
	}
	document.writeln('<button type="button" id="download'+buttonid+'" class="'+cssclass+'">Download</button>');
}

function add_download_button_event (buttonid, divid) {

	jQuery('#download'+buttonid).click( function() {
		$('#pgbadgerModal img').attr('src', $('#'+divid).jqplotToImageStr({}));
		$('#pgbadgerModal').modal('toggle');
	});

}

function create_linegraph (divid, charttitle, ylabel, arr_series, lineseries) {
        return $.jqplot(divid, lineseries, { 
        seriesColors: ['#6e9dc9','#f4ab3a','#ac7fa8','#8dbd0f',"#958c12","#953579", "#4b5de4", "#d8b83f", "#ff5800", "#0085cc"],
        seriesDefaults: { markerOptions: {show: false}, lineWidth:1 },
        grid: { borderWidth: 1, background: '#ffffff'},
        title: charttitle,
        series: arr_series,
        axes: {
            xaxis: {
                renderer:$.jqplot.DateAxisRenderer,
                tickOptions:{ angle: -30, textColor: '#333' },
            },
            yaxis: {
                renderer: $.jqplot.LogAxisRenderer,
                labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
                tickRenderer: $.jqplot.CanvasAxisTickRenderer,
                tickOptions: {
                        textColor: '#333',
                        formatter: function(format, value) { return pretty_print_number(value, 0, ylabel); }
                },
            }
        },
        legend: {
            show: true,
            location: 'nw',
        },
        cursor:{
            show: true,
            zoom: true,
            showTooltip:false,
            looseZoom: true,
            followMouse: true,
        },
        highlighter: {
                show: true,
                tooltipContentEditor: function (str, seriesIndex, pointIndex, plot) {
                    var dateToDisplay = new Date(plot.data[seriesIndex][pointIndex][0]);
                    var textToShow = '<div>On '+dateToDisplay.toString();
                    for (var i=0; i<plot.data.length;i++) {
                            textToShow += '<br><span class="mfigure">'+pretty_print_number(plot.data[i][pointIndex][1], 2, plot.series[i].label)+' <small>'+plot.series[i].label+'</small></span>';
                    }
                    textToShow += '</div>';
                    return textToShow;
                }
        }
    });
}

function create_piechart(divid, title, data) {
	return $.jqplot(divid, [data], 
	{
		seriesColors: ['#6e9dc9','#f4ab3a','#ac7fa8','#8dbd0f',"#958c12","#953579", "#4b5de4", "#d8b83f", "#ff5800", "#0085cc","#4bb2c5", "#c5b47f", "#EAA228", "#579575", "#839557","#498991", "#C08840", "#9F9274", "#546D61", "#646C4A", "#6F6621","#6E3F5F", "#4F64B0", "#A89050", "#C45923", "#187399", "#945381","#959E5C", "#C7AF7B", "#478396", "#907294"],
		grid: { borderWidth: 1, background: '#ffffff'},
		title: title,
		seriesDefaults: {
			renderer: $.jqplot.PieRenderer,
			rendererOptions: {
				showDataLabels: true
			}
		}, 
		legend: { show:true, location: 'e' },
		highlighter: {
			show: true,
			tooltipLocation:'sw', 
			useAxesFormatters:false,
			tooltipContentEditor: function (str, seriesIndex, pointIndex, plot) {
			    var textToShow = '<div>';
			    //textToShow += '<span class="mfigure">'+pretty_print_number(plot.data[0][pointIndex][1], 2)+' <small>'+plot.data[0][pointIndex][0]+'</small></span>';
			    textToShow += '<span class="mfigure">'+format_number(plot.data[0][pointIndex][1])+' <small>'+plot.data[0][pointIndex][0]+'</small></span>';
			    textToShow += '</div>';
			    return textToShow;
			}
		}
	}
	);
}

function create_bargraph (divid, title, ytitle, data, y2title) {
	return $.jqplot(divid, data, {
		grid: { borderWidth: 1, background: '#ffffff'},
		title: title,
		seriesDefaults: {
			rendererOptions: {
				barPadding: 4,
				barMargin: 5,
			}
		},
		seriesColors: ['#6e9dc9','#8dbd0f','#f4ab3a','#ac7fa8',"#958c12","#953579", "#4b5de4", "#d8b83f", "#ff5800", "#0085cc"],
		series:[
			{ renderer:$.jqplot.BarRenderer, label: ytitle},
			{ yaxis:'y2axis', label: y2title, markerOptions: {show: false}, lineWidth:1 }
		],
		axes: {
		    xaxis: {
			renderer: $.jqplot.CategoryAxisRenderer, 
			drawMajorGridlines: false,
			drawMajorTickMarks: false,
			tickRenderer: $.jqplot.CanvasAxisTickRenderer,
			tickOptions: {
			    angle: -30,
			    textColor: '#333',
			    formatString:'%H:%M',
			    fontFamily:'Helvetica',
			    fontSize: '8pt'
			}
		    },
		    yaxis: {
			autoscale:true,
			labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
			tickOptions:{ textColor: '#333' },
			tickRenderer: $.jqplot.CanvasAxisTickRenderer,
                        tickOptions: {
                            textColor: '#333',
                            formatter: function(format, value) { return pretty_print_number(value, 1, ytitle); },
			    fontFamily:'Helvetica',
			    fontSize: '8pt'
                        },
			label: ytitle
		    },
		    y2axis: {
			autoscale:true,
			labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
			tickRenderer: $.jqplot.CanvasAxisTickRenderer,
			tickOptions: {
			    textColor: '#8dbd0f',
			    formatter: function(format, value) { return pretty_print_number(value, 1, y2title); },
			    fontFamily:'Helvetica',
			    fontSize: '8pt'
			},
                        rendererOptions: {
                                alignTicks: true,
                        },
			label: y2title,
			
		    }
		},
		highlighter: {
			show: true,
			tooltipLocation:'ne', 
			useAxesFormatters:false,
			tooltipContentEditor: function (str, seriesIndex, pointIndex, plot) {
			    var textToShow = '<div style="z-index: 99;">At '+plot.data[0][pointIndex][0];
			    for (var i=0; i<plot.data.length;i++) {
				    textToShow += '<br><span class="mfigure">'+pretty_print_number(plot.data[i][pointIndex][1], 2, plot.series[i].label)+' <small>'+plot.series[i].label+'</small></span>';
			    }
			    textToShow += '</div>';
			    return textToShow;
			}
		}
	});
}

function pretty_print_number(val, scale, type) 
{

	if ( (scale == undefined) || ((scale == 0) && (val != 0)) ) {
		scale = 1;
	};

	if (type != undefined) {
		type = type.toLowerCase();

		if (type.search('size') >= 0) {
			if (Math.abs(val) >= 1125899906842624) {
				val = (val / 1125899906842624);
				return val.toFixed(scale) + " PiB";
			} else if (Math.abs(val) >= 1099511627776) {
				val = (val / 1099511627776);
				return val.toFixed(scale) + " TiB";
			} else if (Math.abs(val) >= 1073741824) {
				val = (val / 1073741824);
				return val.toFixed(scale) + " GiB";
			} else if (Math.abs(val) >= 1048576) {
				val = (val / 1048576);
				return val.toFixed(scale) + " MiB";
			} else if (Math.abs(val) >= 1024) {
				val = (val / 1024);
				return val.toFixed(scale) + " KiB";
			} else {
				return val + " B";
			}
		} else if (type.search('duration') >= 0) {
			if (Math.abs(val) >= 1000) {
				val = (val / 1000);
				return val.toFixed(scale) + " sec";
			} else {
				return val.toFixed(scale) + " ms";
			}
		} else {
			if (Math.abs(val) >= 1000000000000000) {
				val = (val / 1000000000000000);
				return val.toFixed(scale) + " P";
			} else if (Math.abs(val) >= 1000000000000) {
				val = (val / 1000000000000);
				return val.toFixed(scale) + " T";
			} else if (Math.abs(val) >= 1000000000) {
				val = (val / 1000000000);
				return val.toFixed(scale) + " G";
			} else if (Math.abs(val) >= 1000000) {
				val = (val / 1000000);
				return val.toFixed(scale) + " M";
			} else if (Math.abs(val) >= 1000) {
				val = (val / 1000);
				return val.toFixed(scale) + " K";
			}
		}
	}

	return val.toFixed(scale);
}

function format_number(val) {
        var decimal = 2;
        var msep = ',';
        var deci = Math.round( Math.pow(10,decimal)*(Math.abs(val)-Math.floor(Math.abs(val)))) ;     
        val = Math.floor(Math.abs(val));
        if ((decimal==0)||(deci==Math.pow(10,decimal))) {deci=0;}
        var val_format=val+""; 
        var nb=val_format.length;
        for (var i=1;i<4;i++) {
                if (val>=Math.pow(10,(3*i))) {
                        val_format=val_format.substring(0,nb-(3*i))+msep+val_format.substring(nb-(3*i));
                }       
        }       
        if (decimal>0) {
                var decim="";
                for (var j=0;j<(decimal-deci.toString().length);j++) {decim+="0";}
                deci=decim+deci.toString();
		if (deci > 0) {
			val_format=val_format+"."+deci;
		}
        }
        if (parseFloat(val)<0) {val_format="-"+val_format;}
        return val_format;
}


function draw_charts() {
	window.charts = $.grep(window.charts, function(chart) {
		var chart_copy = chart.slice();
		var type = chart_copy.shift();
		var divid = chart[1];
		if ($('#' + divid).is(':visible')) {
			window['create_' + type].apply(null, chart_copy);
			// chart loaded, don't keep it in the list
			return false;
		}
		return true;
	});
};