1 | @* HeuristicLab
|
---|
2 | * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
3 | *
|
---|
4 | * This file is part of HeuristicLab.
|
---|
5 | *
|
---|
6 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
7 | * it under the terms of the GNU General Public License as published by
|
---|
8 | * the Free Software Foundation, either version 3 of the License, or
|
---|
9 | * (at your option) any later version.
|
---|
10 | *
|
---|
11 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
14 | * GNU General Public License for more details.
|
---|
15 | *
|
---|
16 | * You should have received a copy of the GNU General Public License
|
---|
17 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
18 | *@
|
---|
19 |
|
---|
20 | @helper AjaxDataRenderer()
|
---|
21 | {
|
---|
22 | <script>
|
---|
23 | var ajaxDataRenderer = function (url, plot, options) {
|
---|
24 | var ret = null;
|
---|
25 | $.ajax({
|
---|
26 | async: false,
|
---|
27 | url: url,
|
---|
28 | dataType: "json",
|
---|
29 | success: function (data) {
|
---|
30 | ret = data;
|
---|
31 | }
|
---|
32 | });
|
---|
33 | return ret;
|
---|
34 | };
|
---|
35 | </script>
|
---|
36 | }
|
---|
37 |
|
---|
38 | @helper LineChartTime(string destinationTag, string url, string title = "", double? minY = null, double? maxY = null, string axisYFormat = null)
|
---|
39 | {
|
---|
40 | <script>
|
---|
41 | var @(destinationTag)Plot = $.jqplot("@destinationTag", "@url", {
|
---|
42 | title: "@title",
|
---|
43 | highlighter: {
|
---|
44 | show: true,
|
---|
45 | sizeAdjust: 7.5
|
---|
46 | },
|
---|
47 | seriesDefaults: {
|
---|
48 | markerOptions: { show: false }
|
---|
49 | },
|
---|
50 | dataRenderer: ajaxDataRenderer,
|
---|
51 | axes: {
|
---|
52 | xaxis: {
|
---|
53 | renderer: $.jqplot.DateAxisRenderer,
|
---|
54 | pad: 0
|
---|
55 | },
|
---|
56 | yaxis: {
|
---|
57 | @if (axisYFormat != null)
|
---|
58 | {<text>
|
---|
59 | tickOptions: {
|
---|
60 | formatString: "@axisYFormat",
|
---|
61 | },
|
---|
62 | </text>}
|
---|
63 | autoscale: true,
|
---|
64 | pad: 0,
|
---|
65 | @if (minY != null)
|
---|
66 | {
|
---|
67 | @:min: @minY,
|
---|
68 | }
|
---|
69 | @if (maxY != null)
|
---|
70 | {
|
---|
71 | @:max: @maxY,
|
---|
72 | }
|
---|
73 | },
|
---|
74 | },
|
---|
75 | gridPadding: { left: 50, right: 10 },
|
---|
76 | cursor: {
|
---|
77 | show: true,
|
---|
78 | showTooltip: false,
|
---|
79 | zoom: true,
|
---|
80 | clickReset: false,
|
---|
81 | dblClickReset: false,
|
---|
82 | constrainZoomTo: 'x'
|
---|
83 | }
|
---|
84 | });
|
---|
85 |
|
---|
86 | @(destinationTag)Plot.replot({ resetAxes: true });
|
---|
87 |
|
---|
88 | $('#@destinationTag').contextmenu(function() {
|
---|
89 | @(destinationTag)Plot.resetZoom();
|
---|
90 | @(destinationTag)Plot.replot({ resetAxes: true });
|
---|
91 | return false;
|
---|
92 | });
|
---|
93 |
|
---|
94 | $(window).resize(function() {
|
---|
95 | @(destinationTag)Plot.replot({ resetAxes: true });
|
---|
96 | });
|
---|
97 | </script>
|
---|
98 | }
|
---|
99 |
|
---|
100 | @helper RefreshChart(string destinationTag, string url, string startDateVar, string endDateVar)
|
---|
101 | {
|
---|
102 | <text>
|
---|
103 | $.ajax({url: "@(new HtmlString(url))?start=" + @startDateVar + "&end=" + @endDateVar, datatype: "json", success: function(result) {
|
---|
104 | for (var i = 0; i < result.length; i++) {
|
---|
105 | @(destinationTag)Plot.series[i].data = result[i];
|
---|
106 | }
|
---|
107 | @(destinationTag)Plot.replot({ resetAxes: true })
|
---|
108 | }});
|
---|
109 | </text>
|
---|
110 | }
|
---|
111 |
|
---|
112 | @helper TasksForUser(string container, string destinationTag, string url, string userName, string startDate = null, string endDate = null)
|
---|
113 | {
|
---|
114 | <text>
|
---|
115 | $.ajax({url: "@(new HtmlString(url))?userName=" + @(userName) + "&start=" + @startDate + "&end=" + @endDate, datatype: "json", success: function(result) {
|
---|
116 | $("#@container").html("");
|
---|
117 | if(result[0].length==0) {
|
---|
118 | $("#@container").append(
|
---|
119 | '<section class="chartContainer"><h1 class="title">' + @userName + ' has no tasks for the given time period!</h1></section>'
|
---|
120 | )
|
---|
121 | }
|
---|
122 | var waitTime;
|
---|
123 | var transferTime;
|
---|
124 | var runTime;
|
---|
125 | var seriesDescriptions = ["Time waiting","Time transferring","Time calculating"];
|
---|
126 |
|
---|
127 | //Globally accesible, for use when resizing, eliminates extra DB request
|
---|
128 | window["numberTasks"] = result[0].length;
|
---|
129 |
|
---|
130 | //For each result create a seperate collapsable section with a chart and info label
|
---|
131 | for(var i = 0; i < result[0].length; i++){
|
---|
132 | $("#" + "@container").append(
|
---|
133 | '<section class="chartContainer"><h1 class="title">Task ' + (i + 1) +
|
---|
134 | '</h1><button class="collapse" onclick="collapseSection(this)">-</button><div id="@(destinationTag)' + i +
|
---|
135 | '"></div><label id="@(destinationTag)' + i + 'Info"></label></section>'
|
---|
136 | )
|
---|
137 | waitTime = [result[0][i]];
|
---|
138 | transferTime = [result[1][i]];
|
---|
139 | runTime = [result[2][i]];
|
---|
140 | window["@(destinationTag)Plot" + i] = $.jqplot("@destinationTag" + i, [waitTime,transferTime,runTime], {
|
---|
141 | //stackSeries: true,
|
---|
142 | seriesDefaults:{
|
---|
143 | renderer:$.jqplot.BarRenderer,
|
---|
144 | shadowAngle: 135,
|
---|
145 | //rendererOptions: {
|
---|
146 | // barDirection: 'horizontal'
|
---|
147 | //},
|
---|
148 | pointLabels: {show: true, formatString: '%.3f'}
|
---|
149 | },
|
---|
150 | series:[
|
---|
151 | {label:'Waiting'},
|
---|
152 | {label:'Transferring'},
|
---|
153 | {label:'Calculating'}
|
---|
154 | ],
|
---|
155 | legend: {
|
---|
156 | show: true,
|
---|
157 | location: 'e',
|
---|
158 | placement: 'outside'
|
---|
159 | },
|
---|
160 | axes: {
|
---|
161 | xaxis: {
|
---|
162 | renderer: $.jqplot.CategoryAxisRenderer,
|
---|
163 | showLabel: false,
|
---|
164 | pad: 0
|
---|
165 | },
|
---|
166 | yaxis: {
|
---|
167 | pad: 0
|
---|
168 | }
|
---|
169 | },
|
---|
170 | cursor: {
|
---|
171 | showTooltip: false
|
---|
172 | }
|
---|
173 | });
|
---|
174 | /* Bind a datalistener to each chart and display details of clicked
|
---|
175 | upon data in the label below the chart */
|
---|
176 | $("#" + "@(destinationTag)" + i).bind('jqplotDataClick', function (ev, seriesIndex, pointIndex, data) {
|
---|
177 | $("#" + $(this).attr('id') + "Info").html(seriesDescriptions[seriesIndex] + ': ' + data[1]);
|
---|
178 | });
|
---|
179 | }
|
---|
180 | }});
|
---|
181 | </text>
|
---|
182 | }
|
---|
183 |
|
---|
184 | @helper ResizeTasks(string destinationTag)
|
---|
185 | {
|
---|
186 | <text>
|
---|
187 | $(window).resize(function() {
|
---|
188 | for(var i = 0; i < numberTasks; i++) {
|
---|
189 | window[ "@(destinationTag)Plot" + i].replot({ resetAxes: true });
|
---|
190 | }
|
---|
191 | });
|
---|
192 | </text>
|
---|
193 | }
|
---|
194 |
|
---|
195 | @* OLD SMOOTHIE CHART FUNCTIONS *@
|
---|
196 | @*@helper CreateSmoothieChart(string destinationTag, string stroke, string fill, string label)
|
---|
197 | {
|
---|
198 | <text>
|
---|
199 | var @(destinationTag)Smoothie = new SmoothieChart({
|
---|
200 | grid: {
|
---|
201 | strokeStyle: '@stroke', fillStyle: '@fill',
|
---|
202 | lineWidth: 1, millisPerLine: 450, verticalSections: 4,
|
---|
203 | },
|
---|
204 | labels: {
|
---|
205 | fillStyle: '@label'
|
---|
206 | }
|
---|
207 | });
|
---|
208 |
|
---|
209 | var @(destinationTag)TimeSeries = new Array()
|
---|
210 | </text>
|
---|
211 | }
|
---|
212 |
|
---|
213 | @helper SetSmoothieCanvas(string destinationTag, string delay)
|
---|
214 | {
|
---|
215 | <text>
|
---|
216 | @(destinationTag)Smoothie.streamTo(document.getElementById("@destinationTag"), @delay);
|
---|
217 | </text>
|
---|
218 | }
|
---|
219 |
|
---|
220 | @helper AssignTimeSeries(string seriesName, string destinationTag, string stroke, string fill)
|
---|
221 | {
|
---|
222 | <text>
|
---|
223 | var @(seriesName)TS = new TimeSeries();
|
---|
224 | @(destinationTag)Smoothie.addTimeSeries(@(seriesName)TS, { strokeStyle: '@stroke', fillStyle: '@fill', lineWidth: 3 });
|
---|
225 | @(destinationTag)TimeSeries.push(@(seriesName)TS);
|
---|
226 | </text>
|
---|
227 | }
|
---|
228 |
|
---|
229 | @helper UpdateChartData(string destinationTag, string url)
|
---|
230 | {
|
---|
231 | <text>
|
---|
232 | $.ajax({
|
---|
233 | url: '@(url)', datatype: "json", success: function (result) {
|
---|
234 | var i
|
---|
235 | for (i = 0; i < @(destinationTag)TimeSeries.length; i++) {
|
---|
236 | @(destinationTag)TimeSeries[i].append(new Date().getTime(), result[i]);
|
---|
237 | }
|
---|
238 | }
|
---|
239 | });
|
---|
240 | </text>
|
---|
241 | }*@
|
---|
242 |
|
---|
243 | @helper SetStreamingProperties(int refresh, int chartLength, int upperY) {
|
---|
244 | <text>
|
---|
245 | //Refresh time (in millisec)
|
---|
246 | var refreshRate = @(refresh);
|
---|
247 | //Number of data points on chart
|
---|
248 | var chartSize = @(chartLength);
|
---|
249 | //Amount to add to max Y value
|
---|
250 | var upperYBuffer = @(upperY);
|
---|
251 |
|
---|
252 | //Used to return a string containing the names of the series
|
---|
253 | //to be used in plot creation
|
---|
254 | function getSeries(numberData,dataName){
|
---|
255 | var result = "[";
|
---|
256 | for(i=0; i < numberData; i++) {
|
---|
257 | if(i < numberData -1) {
|
---|
258 | result += dataName + i + ",";
|
---|
259 | }
|
---|
260 | else {
|
---|
261 | result += dataName + i + "]";
|
---|
262 | }
|
---|
263 | }
|
---|
264 | return result;
|
---|
265 | }
|
---|
266 | </text>
|
---|
267 | }
|
---|
268 |
|
---|
269 | @helper CreateStreamChart(string dataName, string destinationTag, string url, string title, string format = null, double? maxY = null) {
|
---|
270 | <text>
|
---|
271 | //Get current time, used to create initial values
|
---|
272 | var @(dataName)CurrentDate = (new Date()).getTime();
|
---|
273 |
|
---|
274 | var @(dataName)Data = [];
|
---|
275 | var @(dataName)CurrentValue = [];
|
---|
276 |
|
---|
277 | //Get the most recent value(s) from the given URL
|
---|
278 | $.ajax({
|
---|
279 | async: false, url: '@(url)', datatype: "json", success: function (result) {
|
---|
280 | for(i = 0; i < result.length; i++) {
|
---|
281 | @(dataName)CurrentValue[i] = result[i];
|
---|
282 | }
|
---|
283 | }
|
---|
284 | });
|
---|
285 |
|
---|
286 | //Create a chartSize worth of data using CurrentDate and CurrentValue
|
---|
287 | //for each CurrentValue
|
---|
288 | for(i = 0; i < @(dataName)CurrentValue.length; i++) {
|
---|
289 | window["@(dataName)Data" + i] = [];
|
---|
290 | for (j = 0; j < chartSize; j++) {
|
---|
291 | window[ "@(dataName)Data" + i].push([@(dataName)CurrentDate - (chartSize - 1 - j) * refreshRate, @(dataName)CurrentValue[i]]);
|
---|
292 | }
|
---|
293 | }
|
---|
294 |
|
---|
295 | //Options for the chart to be created
|
---|
296 | var @(destinationTag)PlotOptions = {
|
---|
297 | title: "@title",
|
---|
298 | axes: {
|
---|
299 | xaxis: {
|
---|
300 | numberTicks: 4,
|
---|
301 | renderer: $.jqplot.DateAxisRenderer,
|
---|
302 | tickOptions: { formatString: '%H:%M:%S' },
|
---|
303 | min: window["@(dataName)Data" + 0][0][0],
|
---|
304 | max: window["@(dataName)Data" + 0][window["@(dataName)Data" + 0].length - 1][0]
|
---|
305 | },
|
---|
306 | yaxis: {
|
---|
307 | @if (format != null)
|
---|
308 | {<text>
|
---|
309 | tickOptions: {
|
---|
310 | formatString: "@format",
|
---|
311 | },
|
---|
312 | </text>}
|
---|
313 | min: 0,
|
---|
314 | @if (maxY != null) {
|
---|
315 | @:max: @maxY,
|
---|
316 | }
|
---|
317 | else{
|
---|
318 | @:max: window["@(dataName)Data" + 0][window["@(dataName)Data" + 0].length - 1][1] + upperYBuffer,
|
---|
319 | }
|
---|
320 | numberTicks: 6
|
---|
321 | }
|
---|
322 | },
|
---|
323 | seriesDefaults: {
|
---|
324 | rendererOptions: { smooth: true },
|
---|
325 | markerOptions: {
|
---|
326 | show: false
|
---|
327 | }
|
---|
328 | }
|
---|
329 | };
|
---|
330 |
|
---|
331 | //Declares the jqPlot variable, evals the string of series returned
|
---|
332 | //from getSeries which allows for any number of series
|
---|
333 | window[ "@(destinationTag)Plot"] = $.jqplot('@destinationTag', eval(getSeries(@(dataName)CurrentValue.length,"@(dataName)Data")), @(destinationTag)PlotOptions);
|
---|
334 | </text>
|
---|
335 | }
|
---|
336 |
|
---|
337 | @helper UpdateStreamChart(string dataName, string destinationTag, string url, string fixedY = null)
|
---|
338 | {
|
---|
339 | <text>
|
---|
340 | //If the data is beyond chartSize use shift to trim one off the end
|
---|
341 | for(i = 0; i < @(dataName)CurrentValue.length; i++) {
|
---|
342 | if (window["@(dataName)Data" + i].length > chartSize - 1) {
|
---|
343 | window["@(dataName)Data" + i].shift();
|
---|
344 | }
|
---|
345 | }
|
---|
346 |
|
---|
347 | //Get the up-to-date data, each result assigned to it's own array
|
---|
348 | $.ajax({
|
---|
349 | async: false, url: '@(url)', datatype: "json", success: function (result) {
|
---|
350 | for(i = 0; i < result.length; i++) {
|
---|
351 | window[ "@(dataName)Data" + i].push([(new Date()).getTime(), result[i]]);
|
---|
352 | }
|
---|
353 | }
|
---|
354 | });
|
---|
355 |
|
---|
356 | //If the plot exists currently destroy it
|
---|
357 | if ( @(destinationTag)Plot) {
|
---|
358 | @(destinationTag)Plot.destroy();
|
---|
359 | }
|
---|
360 |
|
---|
361 | //Assign series
|
---|
362 | for(i = 0; i < @(dataName)CurrentValue.length; i++) {
|
---|
363 | @(destinationTag)Plot.series[i].data = window["@(dataName)Data" + i];
|
---|
364 | }
|
---|
365 |
|
---|
366 | //Recalculate x and possibly y axis max and mins
|
---|
367 | @(destinationTag)PlotOptions.axes.xaxis.min = window["@(dataName)Data" + 0][0][0];
|
---|
368 | @(destinationTag)PlotOptions.axes.xaxis.max = window["@(dataName)Data" + 0][window["@(dataName)Data" + 0].length - 1][0];
|
---|
369 | @if (fixedY == null) {
|
---|
370 | @:@(destinationTag)PlotOptions.axes.yaxis.max = window["@(dataName)Data" + 0][window["@(dataName)Data" + 0].length - 1][1] + upperYBuffer;
|
---|
371 | }
|
---|
372 |
|
---|
373 | //Re-assigns the jqPlot variable, evals the string of series returned
|
---|
374 | //from getSeries which allows for any number of series
|
---|
375 | @(destinationTag)Plot = $.jqplot('@destinationTag', eval(getSeries(@(dataName)CurrentValue.length,"@(dataName)Data")), @(destinationTag)PlotOptions);
|
---|
376 | </text>
|
---|
377 | }
|
---|
378 |
|
---|
379 | @helper MakeCollapsable()
|
---|
380 | {
|
---|
381 | <text>
|
---|
382 | $(document).ready(function() {
|
---|
383 | $(".collapse").click(function () {
|
---|
384 | if ($(this).html() == "-") {
|
---|
385 | $(this).parent().children("canvas, div, fieldset, label").fadeOut();
|
---|
386 | $(this).html("+");
|
---|
387 | }
|
---|
388 | else {
|
---|
389 | $(this).parent().children("canvas, div, fieldset, label").fadeIn();
|
---|
390 | $(this).html("-");
|
---|
391 | }
|
---|
392 | });
|
---|
393 | });
|
---|
394 | </text>
|
---|
395 | } |
---|