Debian Codegraph @

resources/pgcluu.js

raw symbols SCIP
1
2 /* <![CDATA[ */
3
4 function create_download_button (buttonid, cssclass) {
5 document.writeln('<button type="button" id="download'+buttonid+'" class="btn btn-danger" data-toggle="modal" data-target="#pgcluuModal">Download</button>');
6 document.writeln('<button type="button" id="csv'+buttonid+'" class="btn btn-danger" >CSV export</button>');
7 document.writeln('<a id="acsv'+buttonid+'" href="#"></a>');
8 }
9
10 /* Disable disabled menus */
11 $(document).ready(function() {
12 $(".nav li.disabled a").click(function() {
13 return false;
14 });
15 });
16
17 function add_download_button_event (buttonid, divid, plot) {
18
19 jQuery('#download'+buttonid).click( function() {
20 $('#pgcluuModal img').attr('src', $('#'+divid).jqplotToImageStr({}));
21 });
22 jQuery('#csv'+buttonid).click( function() {
23 export_csv(plot, buttonid);
24 });
25
26 }
27
28 function create_linegraph (divid, charttitle, ylabel, arr_series, lineseries, y2label) {
29 return $.jqplot(divid, lineseries, {
30 seriesColors: ['#6e9dc9','#f4ab3a','#ac7fa8','#8dbd0f',"#958c12","#953579", "#4b5de4", "#d8b83f", "#ff5800", "#0085cc"],
31 seriesDefaults: { markerOptions: {show: false}, lineWidth:1 },
32 grid: { borderWidth: 1, background: '#ffffff'},
33 title: charttitle,
34 series: arr_series,
35 axes: {
36 xaxis: {
37 renderer:$.jqplot.DateAxisRenderer,
38 tickOptions:{ angle: -30, textColor: '#333' },
39 },
40 yaxis: {
41 label: ylabel,
42 renderer: $.jqplot.LogAxisRenderer,
43 labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
44 tickRenderer: $.jqplot.CanvasAxisTickRenderer,
45 tickOptions: {
46 textColor: '#333',
47 formatter: function(format, value) { return pretty_print_number(value, 0, ylabel); }
48 },
49 }
50 },
51 legend: {
52 show: true,
53 placement: 'outside',
54 location:'e'
55 },
56 cursor:{
57 show: true,
58 zoom: true,
59 showTooltip:false,
60 looseZoom: true,
61 followMouse: true,
62 },
63 highlighter: {
64 show: true,
65 tooltipContentEditor: function (str, seriesIndex, pointIndex, plot) {
66 var dateToDisplay = new Date(plot.data[seriesIndex][pointIndex][0]);
67 var textToShow = '<div>On '+dateToDisplay.toString().substring(0,33)+'<br>'+dateToDisplay.toString().substring(34);
68 for (var i=0; i<plot.data.length;i++) {
69 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>';
70 }
71 textToShow += '</div>';
72 return textToShow;
73 }
74 }
75 });
76 }
77
78 function create_piechart(divid, title, data) {
79 return $.jqplot(divid, [data],
80 {
81 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"],
82 grid: { borderWidth: 1, background: '#ffffff'},
83 title: title,
84 seriesDefaults: {
85 renderer: $.jqplot.PieRenderer,
86 rendererOptions: {
87 showDataLabels: true
88 }
89 },
90 legend: { show:true, location: 'e' },
91 highlighter: {
92 show: true,
93 tooltipLocation:'sw',
94 useAxesFormatters:false,
95 tooltipContentEditor: function (str, seriesIndex, pointIndex, plot) {
96 var textToShow = '<div>';
97 //textToShow += '<span class="mfigure">'+pretty_print_number(plot.data[0][pointIndex][1], 2)+' <small>'+plot.data[0][pointIndex][0]+'</small></span>';
98 textToShow += '<span class="mfigure">'+format_number(plot.data[0][pointIndex][1])+' <small>'+plot.data[0][pointIndex][0]+'</small></span>';
99 textToShow += '</div>';
100 return textToShow;
101 }
102 }
103 }
104 );
105 }
106
107 function create_bargraph (divid, title, ytitle, data, y2title) {
108 return $.jqplot(divid, data, {
109 grid: { borderWidth: 1, background: '#ffffff'},
110 title: title,
111 seriesDefaults: {
112 rendererOptions: {
113 barPadding: 4,
114 barMargin: 5,
115 }
116 },
117 seriesColors: ['#6e9dc9','#8dbd0f','#f4ab3a','#ac7fa8',"#958c12","#953579", "#4b5de4", "#d8b83f", "#ff5800", "#0085cc"],
118 series:[
119 { renderer:$.jqplot.BarRenderer, label: ytitle},
120 { yaxis:'y2axis', label: y2title, markerOptions: {show: false}, lineWidth:1 }
121 ],
122 axes: {
123 xaxis: {
124 renderer: $.jqplot.CategoryAxisRenderer,
125 drawMajorGridlines: false,
126 drawMajorTickMarks: false,
127 tickRenderer: $.jqplot.CanvasAxisTickRenderer,
128 tickOptions: {
129 angle: -30,
130 textColor: '#333',
131 formatString:'%H:%M',
132 fontFamily:'Helvetica',
133 fontSize: '8pt'
134 }
135 },
136 yaxis: {
137 autoscale:true,
138 labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
139 tickOptions:{ textColor: '#333' },
140 tickRenderer: $.jqplot.CanvasAxisTickRenderer,
141 tickOptions: {
142 textColor: '#333',
143 formatter: function(format, value) { return pretty_print_number(value, 0, ytitle); },
144 fontFamily:'Helvetica',
145 fontSize: '8pt'
146 },
147 label: ytitle
148 },
149 y2axis: {
150 autoscale:true,
151 labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
152 tickRenderer: $.jqplot.CanvasAxisTickRenderer,
153 tickOptions: {
154 textColor: '#8dbd0f',
155 formatter: function(format, value) { return pretty_print_number(value, 0, y2title); },
156 fontFamily:'Helvetica',
157 fontSize: '8pt'
158 },
159 rendererOptions: {
160 alignTicks: true,
161 },
162 label: y2title,
163
164 }
165 },
166 highlighter: {
167 show: true,
168 tooltipLocation:'ne',
169 useAxesFormatters:false,
170 tooltipContentEditor: function (str, seriesIndex, pointIndex, plot) {
171 var textToShow = '<div style="z-index: 99;">At '+plot.data[0][pointIndex][0];
172 for (var i=0; i<plot.data.length;i++) {
173 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>';
174 }
175 textToShow += '</div>';
176 return textToShow;
177 }
178 }
179 });
180 }
181
182 function pretty_print_number(val, scale, type)
183 {
184
185 if ( (scale == undefined) || ((scale == 0) && (val != 0)) ) {
186 scale = 1;
187 };
188
189 if (type != undefined) {
190 type = type.toLowerCase();
191
192 if (type.search('size') >= 0) {
193 if (Math.abs(val) >= 1125899906842624) {
194 val = (val / 1125899906842624);
195 return val.toFixed(scale) + " PiB";
196 } else if (Math.abs(val) >= 1099511627776) {
197 val = (val / 1099511627776);
198 return val.toFixed(scale) + " TiB";
199 } else if (Math.abs(val) >= 1073741824) {
200 val = (val / 1073741824);
201 return val.toFixed(scale) + " GiB";
202 } else if (Math.abs(val) >= 1048576) {
203 val = (val / 1048576);
204 return val.toFixed(scale) + " MiB";
205 } else if (Math.abs(val) >= 1024) {
206 val = (val / 1024);
207 return val.toFixed(scale) + " KiB";
208 } else {
209 return val.toFixed(scale) + " B";
210 }
211 } else if (type.search('duration') >= 0) {
212 if (Math.abs(val) >= 1000) {
213 val = (val / 1000);
214 return val.toFixed(scale) + " sec";
215 } else {
216 return val + " ms";
217 }
218 } else {
219 if (Math.abs(val) >= 1000000000000000) {
220 val = (val / 1000000000000000);
221 return val.toFixed(scale) + " P";
222 } else if (Math.abs(val) >= 1000000000000) {
223 val = (val / 1000000000000);
224 return val.toFixed(scale) + " T";
225 } else if (Math.abs(val) >= 1000000000) {
226 val = (val / 1000000000);
227 return val.toFixed(scale) + " G";
228 } else if (Math.abs(val) >= 1000000) {
229 val = (val / 1000000);
230 return val.toFixed(scale) + " M";
231 } else if (Math.abs(val) >= 1000) {
232 val = (val / 1000);
233 return val.toFixed(scale) + " K";
234 }
235 }
236 }
237
238 return val.toFixed(scale);
239 }
240
241 function format_number(val) {
242 var decimal = 2;
243 var msep = ',';
244 var deci = Math.round( Math.pow(10,decimal)*(Math.abs(val)-Math.floor(Math.abs(val)))) ;
245 val = Math.floor(Math.abs(val));
246 if ((decimal==0)||(deci==Math.pow(10,decimal))) {deci=0;}
247 var val_format=val+"";
248 var nb=val_format.length;
249 for (var i=1;i<4;i++) {
250 if (val>=Math.pow(10,(3*i))) {
251 val_format=val_format.substring(0,nb-(3*i))+msep+val_format.substring(nb-(3*i));
252 }
253 }
254 if (decimal>0) {
255 var decim="";
256 for (var j=0;j<(decimal-deci.toString().length);j++) {decim+="0";}
257 deci=decim+deci.toString();
258 if (deci > 0) {
259 val_format=val_format+"."+deci;
260 }
261 }
262 if (parseFloat(val)<0) {val_format="-"+val_format;}
263 return val_format;
264 }
265
266 function export_csv(plot, buttonid) {
267
268 if (jQuery('#acsv' + buttonid).attr('href') == '#') {
269 var csv = "data:text/csv;charset=utf-8,";
270
271 if (plot.seriesDefaults != null) {
272 csv += '"serie","epoch","value"\n';
273 } else {
274 csv += '"serie","value"\n';
275 }
276 _.each(plot.series[0]._plotValues.x, function(val,i) {
277 _.each(plot.series, function(s, j) {
278 if (plot.plugins.lineRenderer != null) {
279 csv += '"' + s.label + '",' + s._plotValues.x[i] + ',' + s._plotValues.y[i] + '\n';
280 }
281 else {
282 csv += '"' + s._plotValues.x[i] + '",' + s._plotValues.y[i] + '\n';
283 }
284 });
285 });
286
287 var encodedUri = encodeURI(csv);
288 jQuery('#acsv' + buttonid).attr('href', encodedUri).attr('download', 'data.csv');
289 }
290
291 document.getElementById('acsv' + buttonid).click();
292 }