Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/04/14 08:59:24 (10 years ago)
Author:
mroscoe
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HiveStatistics/sources/HeuristicLab.Services.Hive.Statistics/3.3/App_Code/ChartHelper.cshtml

    r11059 r11084  
    102102}
    103103
     104@helper ResizeCharts()
     105{
     106  <text>
     107  function resizeCharts(caller) {
     108    //If current plot is collapsed
     109    if($(caller).css("display") == "none") {
     110      //Display the contents of chartContainer
     111      ResizeOpenClose($(caller).siblings(".collapse"));
     112      //Reset barWidth for bar charts
     113      $.each(window[caller.id].series, function(index, series) {
     114        series.barWidth = undefined;
     115      });
     116      //Replot the chart with same name as element id
     117      window[caller.id].replot({ resetAxes: false });
     118      //Hide the contents of the current div
     119      ResizeOpenClose($(caller).siblings(".collapse"));
     120    }
     121    //Current plot is expanded
     122    else {
     123      //Reset barWidth for bar charts
     124      $.each(window[caller.id].series, function(index, series) {
     125        series.barWidth = undefined;
     126      });
     127      //Replot the chart with same name as element id
     128      window[caller.id].replot({ resetAxes: false });
     129    }
     130  }
     131
     132  $(window).resize(function() {
     133    $("div.jqplot-target",".chartContainer").each(function() {
     134      var potentialTab = $(this).parent().parent().parent();
     135      //If the section is tabular and currently hidden
     136      if(potentialTab.hasClass("tabSection") && potentialTab.css("display") == "none") {
     137        ResizeOpenCloseTabular(potentialTab);
     138        resizeCharts(this);
     139        ResizeOpenCloseTabular(potentialTab);
     140      }
     141      else {
     142        resizeCharts(this);
     143      }
     144    });
     145  });
     146  </text>
     147}
     148
    104149@helper NumberPages(string records, string limit, string container, string functionName, string currentPage = null)
    105150{
     
    134179}
    135180
    136 @helper TasksForUser(string container, string destinationTag, string url, string functionName, string userName, string limit, string startDate = null, string endDate = null, string jobId=null, string taskState=null, string pageNumber=null)
    137 {
    138   <text>
    139     var GetRequest = "?userName=" + @(userName) + "&limit=" + @(limit);
    140     @if(startDate!=null) {
     181@helper TasksForUser(string destinationTag, string url, string functionName, string userName, string limit, string startDate = null, string endDate = null, string jobId = null, string taskState = null, string pageNumber = null)
     182{
     183  <text>
     184    var GetRequest = "?userName=" + @(userName);
     185    @if (startDate != null)
     186    {
    141187      @:if(@(startDate)!=null) {
    142188        @:GetRequest += "&start=" + @startDate;
    143189      @:}
    144190    }
    145     @if(endDate!=null) {
     191    @if (endDate != null)
     192    {
    146193      @:if(@(endDate)!=null) {
    147194        @:GetRequest += "&end=" + @endDate;
    148195      @:}
    149196    }
    150     @if(jobId!=null) {
     197    @if (jobId != null)
     198    {
    151199      @:if(@(jobId)!=null) {
    152200        @:GetRequest += "&jobId=" + @jobId;
    153201      @:}
    154202    }
    155     @if(taskState!=null) {
     203    @if (taskState != null)
     204    {
    156205      @:if(@(taskState)!=null) {
    157206        @:GetRequest += "&taskState=" + @taskState;
     
    161210      async: false, url: "@(new HtmlString(url))" + GetRequest, datatype: "json", success: function(result) {
    162211      if(@(userName) == null) {
    163         $("#@container").append(
     212        $("#@(destinationTag)").append(
    164213          '<section class="chartContainer">' +
    165214            '<h1 class="title">Please select a user!</h1>' +
     
    168217      }
    169218      else if(result.length==0) {
    170         $("#@container").append(
     219        $("#@(destinationTag)").append(
    171220          '<section class="chartContainer">' +
    172221            '<h1 class="title">' + @userName + ' has no tasks for the specified filters!</h1>' +
     
    182231        //Checks if multipage display, if it is then trims results to
    183232        //the results for the page to be displayed
    184         @ChartHelper.NumberPages("result",limit,container,functionName,pageNumber)
     233        @ChartHelper.NumberPages("result", limit, destinationTag, functionName, pageNumber)
    185234
    186235        //Globally accesible, for use when resizing, eliminates extra DB request
     
    188237
    189238        //Set display of all errors to none, errors matching the tasks will be reset below
    190         $("#@(container)").find(".errorContainer, .errorTitle, .errorTask, .errorMessage").css('display','none');
     239        $("#@(destinationTag)").find(".errorContainer, .errorTitle, .errorTask, .errorMessage").css('display','none');
    191240
    192241        //For each result create a seperate collapsable section with a chart and info label
    193242        for(var i = 0; i < result.length; i++){
    194           $("#" + "@container").append(
     243          $("#" + "@(destinationTag)").append(
    195244            '<section class="chartContainer">' +
    196               '<h1 class="title" id="@(container)' + result[i].Key + '">Task ' + result[i].Key + '</h1>' +
     245              '<h1 class="title" id="@(destinationTag)' + result[i].Key + 'PlotTitle">Task ' + result[i].Key + '</h1>' +
    197246              '<button class="collapse" onclick="CollapseSection(this)">+</button>' +
    198247              '<div id="@(destinationTag)Plot' + i + '"></div>' +
     
    202251          //Re-enables the error display if any of the tasks on the page have Ids matching
    203252          //those of errors
    204           $(".errorTask","#" + "@(container)").each(function() {
     253          $(".errorTask","#" + "@(destinationTag)").each(function() {
    205254            if($(this).html()==result[i].Key) {
    206               $("#@(container)" + result[i].Key).css("color","red");
    207               $("#@(container)" + result[i].Key).append(" - ERROR");
    208               $(".errorContainer, .errorTitle, .underline").css('display','inline-block');
     255              $("#@(destinationTag)" + result[i].Key + "PlotTitle").css("color","red");
     256              $("#@(destinationTag)" + result[i].Key + "PlotTitle").append(" - ERROR");
     257              $(".errorContainer, .errorTitle, .underline","#@(destinationTag)").css('display','inline-block');
    209258              $(this).css('display','inline-block');
    210259              $(this).next().css('display','inline-block');
     
    250299          });
    251300
    252           CollapsedByDefault(document.getElementById("@(container)" + result[i].Key));
     301          CollapsedByDefault(document.getElementById("@(destinationTag)Plot" + i));
    253302        }
    254303      }
     
    257306}
    258307
    259 @helper ResizeTasks(string destinationTag)
    260 {
    261   <text>
    262   //Resize event, resets bar width for task charts and replots them
    263   $(window).resize(function() {
    264     if(typeof numberTasks !== 'undefined') {
    265       for(var i = 0; i < numberTasks; i++) {
    266         $.each(window[ "@(destinationTag)Plot" + i].series, function(index, series) {
    267           series.barWidth = undefined;
    268         });
    269         if($("#@(destinationTag)Plot" + i).css("display") == "none") {
    270           ResizeOpenClose($("#@(destinationTag)Plot" + i).siblings(".collapse"));
    271           window["@(destinationTag)Plot" + i].replot({ resetAxes: true });
    272           ResizeOpenClose($("#@(destinationTag)Plot" + i).siblings(".collapse"));
    273         }
    274         else {
    275           window["@(destinationTag)Plot" + i].replot({ resetAxes: true });
    276         }
    277       }
    278     }
    279   });
    280   </text>
    281 }
    282 
    283 @helper SetStreamingProperties(int refresh, int chartLength, int upperY) {
     308@helper SetStreamingProperties(int refresh, int chartLength, int upperY)
     309{
    284310  <text>
    285311  //Refresh time (in millisec)
     
    307333}
    308334
    309 @helper CreateStreamChart(string dataName, string destinationTag, string url, string title, string format = null, double? maxY = null) {
     335@helper CreateStreamChart(string dataName, string destinationTag, string url, string title, string format = null, double? maxY = null)
     336{
    310337  <text>
    311338  //Get current time, used to create initial values
     
    352379        </text>}
    353380        min: 0,
    354         @if (maxY != null) {
     381        @if (maxY != null)
     382        {
    355383          @:max: @maxY,
    356384        }
    357         else{
     385        else
     386        {
    358387          @:max: window["@(dataName)Data" + 0][window["@(dataName)Data" + 0].length - 1][1] + upperYBuffer,
    359388        }
     
    375404}
    376405
    377 @helper UpdateStreamChart(string dataName, string destinationTag, string url, string fixedY = null) {
     406@helper UpdateStreamChart(string dataName, string destinationTag, string url, string fixedY = null)
     407{
    378408  <text>
    379409  //If the data is beyond chartSize use shift to trim one off the end
     
    406436  @(destinationTag)PlotOptions.axes.xaxis.min = window["@(dataName)Data" + 0][0][0];
    407437  @(destinationTag)PlotOptions.axes.xaxis.max = window["@(dataName)Data" + 0][window["@(dataName)Data" + 0].length - 1][0];
    408   @if (fixedY == null) {
     438  @if (fixedY == null)
     439  {
    409440    @:@(destinationTag)PlotOptions.axes.yaxis.max = window["@(dataName)Data" + 0][window["@(dataName)Data" + 0].length - 1][1] + upperYBuffer;
    410441  }
     
    416447}
    417448
    418 @helper SlaveInfoChart(string destinationTag, string url, string limit, bool singleSlave, string startDate=null, string endDate=null, string userName=null, string functionName=null, string pageNumber=null, string slaveId=null) {
    419   <text>
    420   var GetRequest = "?limit=" + @(limit);
    421   @if(startDate!=null) {
     449@helper SlaveInfoChart(string destinationTag, string url, string limit, bool singleSlave, string startDate = null, string endDate = null, string userName = null, string functionName = null, string pageNumber = null, string slaveId = null)
     450{
     451  <text>
     452  var GetRequest = "";
     453  @if (startDate != null)
     454  {
    422455    @:if(@(startDate)!=null) {
    423       @:GetRequest += "&start=" + @startDate;
     456      @:if(GetRequest == "") {
     457        @:GetRequest += "?start=" + @startDate;
     458      @:}
     459      @:else {
     460        @:GetRequest += "&start=" + @startDate;
     461      @:}
    424462    @:}
    425463  }
    426   @if(endDate!=null) {
     464  @if (endDate != null)
     465  {
    427466    @:if(@(endDate)!=null) {
    428       @:GetRequest += "&end=" + @endDate;
     467      @:if(GetRequest == "") {
     468        @:GetRequest += "?end=" + @endDate;
     469      @:}
     470      @:else {
     471        @:GetRequest += "&end=" + @endDate;
     472      @:}
    429473    @:}
    430474  }
    431   @if (userName != null) {
     475  @if (userName != null)
     476  {
    432477    @:if(@(userName)!=null) {
    433       @:GetRequest += "&userName=" + @userName;
     478      @:if(GetRequest == "") {
     479        @:GetRequest += "?userName=" + @userName;
     480      @:}
     481      @:else {
     482        @:GetRequest += "&userName=" + @userName;
     483      @:}
    434484    @:}
    435485  }
    436   @if (slaveId != null) {
     486  @if (slaveId != null)
     487  {
    437488    @:if(@(slaveId)!=null) {
    438       @:GetRequest += "&slaveId=" + @slaveId;
     489      @:if(GetRequest == "") {
     490        @:GetRequest += "?slaveId=" + @slaveId;
     491      @:}
     492      @:else {
     493        @:GetRequest += "&slaveId=" + @slaveId;
     494      @:}
    439495    @:}
    440496  }
     
    452508
    453509    if(result.length == 0) {
     510      @if (!singleSlave) {
     511        @:$('#' + destTag).html("");
     512      }
    454513      $('#' + destTag).append(
    455514        '<section class="chartContainer">' +
     
    461520      var time = new Date();
    462521
    463       @if(!singleSlave) {
     522      @if (!singleSlave)
     523      {
    464524        @:$('#' + destTag).html("");
    465525
     
    468528        @ChartHelper.NumberPages("result", limit, destinationTag, functionName, pageNumber)
    469529      }
    470 
    471       //Globally accesible, for use when resizing, eliminates extra DB request
    472       window["numberSlaves"] = result.length;
    473530
    474531      for(i = 0; i < result.length; i++) {
     
    483540        $('#' + destTag).append(
    484541          '<section class="chartContainer">' +
    485             '<h1 class="title" id="' + result[i][0].SlaveID + '">Slave ' + result[i][0].SlaveID + '</h1>' +
     542            '<h1 class="title" id="' + destTag + result[i][0].SlaveID + 'PlotTitle">Slave ' + result[i][0].SlaveID + '</h1>' +
    486543            '<button class="collapse" onclick="CollapseSection(this)">+</button>' +
    487             '<div id="' + slaveChartNames[0] + 'Plot' + i + '"></div>' +
    488             '<div id="' + slaveChartNames[1] + 'Plot' + i + '"></div>' +
    489             '<div id="' + slaveChartNames[2] + 'Plot' + i + '"></div>' +
     544            '<div id="' + destTag + slaveChartNames[0] + 'Plot' + i + '"></div>' +
     545            '<div id="' + destTag + slaveChartNames[1] + 'Plot' + i + '"></div>' +
     546            '<div id="' + destTag + slaveChartNames[2] + 'Plot' + i + '"></div>' +
    490547          '</section>');
    491548        for(j = 0; j < result[i].length; j++) {
     
    498555        }
    499556        if(result[i].length > 1) {
    500           @ChartHelper.LineChartGivenSeries("slaveChartNames[0]","i","coreSeries","Total/Used Cores")
    501           @ChartHelper.LineChartGivenSeries("slaveChartNames[1]","i","memorySeries","Total/Used Memory",0)
    502           @ChartHelper.LineChartGivenSeries("slaveChartNames[2]","i","cpuSeries","CPU Utilization",0,100,"%.1f%%")
     557          @ChartHelper.LineChartGivenSeries("destTag + slaveChartNames[0]", "i", "coreSeries", "Total/Used Cores")
     558          @ChartHelper.LineChartGivenSeries("destTag + slaveChartNames[1]", "i", "memorySeries", "Total/Used Memory", 0)
     559          @ChartHelper.LineChartGivenSeries("destTag + slaveChartNames[2]", "i", "cpuSeries", "CPU Utilization", 0, 100, "%.1f%%")
    503560        }
    504561        else {
    505           @ChartHelper.BarChartGivenSeries("slaveChartNames[0]","i","coreSeries","Total/Used Cores")
    506           @ChartHelper.BarChartGivenSeries("slaveChartNames[1]","i","memorySeries","Total/Used Memory",0)
    507           @ChartHelper.BarChartGivenSeries("slaveChartNames[2]","i","cpuSeries","CPU Utilization",0,100,"%.1f%%")
     562          @ChartHelper.BarChartGivenSeries("destTag + slaveChartNames[0]", "i", "coreSeries", "Total/Used Cores")
     563          @ChartHelper.BarChartGivenSeries("destTag + slaveChartNames[1]", "i", "memorySeries", "Total/Used Memory", 0)
     564          @ChartHelper.BarChartGivenSeries("destTag + slaveChartNames[2]", "i", "cpuSeries", "CPU Utilization", 0, 100, "%.1f%%")
    508565        }
    509566        for(k = 0; k < slaveChartNames.length; k++) {
    510           CollapsedByDefault(document.getElementById(slaveChartNames[k] + "Plot" + i));
     567          CollapsedByDefault(document.getElementById(destTag + slaveChartNames[k] + "Plot" + i));
    511568        }
    512569      }
     
    516573}
    517574
    518 @helper ResizeSlaves() {
    519   <text>
    520   //Resize event, resets bar width for slave charts and replots them
    521   $(window).resize(function() {
    522     if(typeof numberSlaves !== 'undefined') {
    523 
    524       //Set chart names for use in creation below, must be set identically in
    525       //SlaveInfoChart
    526       var slaveChartNames = ["TotalUsedCores","TotalUsedMemory","CPUUtilization"];
    527 
    528       for(i = 0; i < numberSlaves; i++) {
    529         if($("#" + slaveChartNames[0] + "Plot" + i).css("display") == "none") {
    530           ResizeOpenClose($("#" + slaveChartNames[0] + "Plot" + i).siblings(".collapse"));
    531           for(j = 0; j < slaveChartNames.length; j++) {
    532             $.each(window[slaveChartNames[j] + "Plot" + i].series, function(index, series) {
    533               series.barWidth = undefined;
    534             });
    535             window[slaveChartNames[j] + "Plot" + i].replot({ resetAxes: true });
    536           }
    537           ResizeOpenClose($("#" + slaveChartNames[0] + "Plot" + i).siblings(".collapse"));
    538         }
    539         else {
    540           for(j = 0; j < slaveChartNames.length; j++) {
    541             $.each(window[slaveChartNames[j] + "Plot" + i].series, function(index, series) {
    542               series.barWidth = undefined;
    543             });
    544             window[slaveChartNames[j] + "Plot" + i].replot({ resetAxes: true });
    545           }
    546         }
    547       }
    548     }
    549   });
    550   </text>
    551 }
    552 
    553 @helper LineChartGivenSeries(string destinationTag, string chartId, string series, string title, double? minY = null, double? maxY = null, string axisYFormat = null) {
     575@helper LineChartGivenSeries(string destinationTag, string chartId, string series, string title, double? minY = null, double? maxY = null, string axisYFormat = null)
     576{
    554577  <text>
    555578  window[@(destinationTag) + "Plot" + @(chartId)] = $.jqplot(@(destinationTag) + "Plot" + @(chartId), @series, {
     
    562585      },
    563586      yaxis: {
    564         @if (axisYFormat != null) {
     587        @if (axisYFormat != null)
     588        {
    565589          <text>
    566590          tickOptions: {
     
    569593          </text>
    570594        }
    571         @if (minY != null) {
     595        pad: 0,
     596        @if (minY != null)
     597        {
    572598            @:min: @minY,
    573599        }
    574         @if (maxY != null) {
     600        @if (maxY != null)
     601        {
    575602            @:max: @maxY,
    576603        }
    577         pad: 0
    578604      }
    579605    },
     
    591617}
    592618
    593 @helper BarChartGivenSeries(string destinationTag, string chartId, string series, string title, double? minY = null, double? maxY = null, string axisYFormat = null) {
     619@helper BarChartGivenSeries(string destinationTag, string chartId, string series, string title, double? minY = null, double? maxY = null, string axisYFormat = null)
     620{
    594621  <text>
    595622  window[@(destinationTag) + "Plot" + @(chartId)] = $.jqplot(@(destinationTag) + "Plot" + @(chartId), @series, {
     
    607634      },
    608635      yaxis: {
    609         @if (axisYFormat != null) {
     636        @if (axisYFormat != null)
     637        {
    610638          <text>
    611639          tickOptions: {
     
    614642          </text>
    615643        }
    616         @if (minY != null) {
     644        pad: 0,
     645        @if (minY != null)
     646        {
    617647            @:min: @minY,
    618648        }
    619         @if (maxY != null) {
     649        @if (maxY != null)
     650        {
    620651            @:max: @maxY,
    621652        }
    622         pad: 0
    623653      }
    624654    },
Note: See TracChangeset for help on using the changeset viewer.