From 2055ef2c9c41dd4805e18e260502dbc98f351efe Mon Sep 17 00:00:00 2001 From: Ferran Rodenas Date: Sun, 11 Dec 2011 21:00:06 +0100 Subject: [PATCH] Show pie chart with types of apps at dashboard view --- app/assets/javascripts/dashboard.js.erb | 31 +++++++++++++++++++- app/controllers/dashboard_controller.rb | 12 ++++++++ app/views/dashboard/_apps_overview.html.haml | 9 ++++-- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/dashboard.js.erb b/app/assets/javascripts/dashboard.js.erb index 054559d..df74af5 100644 --- a/app/assets/javascripts/dashboard.js.erb +++ b/app/assets/javascripts/dashboard.js.erb @@ -28,9 +28,10 @@ $(function() { if (tab == '#apps') { $('tr.pieCharts').each(function() { var trwidth = parseInt($(this).width()) - 20; - var tdwidth = trwidth / 2; + var tdwidth = trwidth / 3; $('.apps_states').width(tdwidth+'px').height('250px'); $('.instances_states').width(tdwidth+'px').height('250px'); + $('.apps_types').width(tdwidth+'px').height('250px'); }); if (typeof apps_states != 'undefined' && apps_states.length > 0) { function apps_states_hover(event, pos, obj) { @@ -53,6 +54,8 @@ $(function() { 'grid': {'hoverable': true} }); $('.apps_states').bind('plothover', apps_states_hover); + } else { + $('.apps_states').text("No available data"); } if (typeof instances_states != 'undefined' && instances_states.length > 0) { function instances_states_hover(event, pos, obj) { @@ -75,6 +78,32 @@ $(function() { 'grid': {'hoverable': true} }); $('.instances_states').bind('plothover', instances_states_hover); + } else { + $('.instances_states').text("No available data"); + } + if (typeof apps_types != 'undefined' && apps_types.length > 0) { + function apps_types_hover(event, pos, obj) { + if (!obj) return; + $('.apps_types_hover').html(''+obj.series.data[0][1]+' '+obj.series.label+' Application'); + } + $.plot($('.apps_types'), apps_types, { + 'series': { + 'pie': { + 'show': true, + 'label': { + 'show': true, + 'formatter': function(label, series) { + return label+'
'+Math.round(series.percent)+'%'; + } + } + } + }, + 'legend': {'show': false}, + 'grid': {'hoverable': true} + }); + $('.apps_types').bind('plothover', apps_types_hover); + } else { + $('.apps_types').text("No available data"); } } }); diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index eb65343..1d2b03f 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -37,6 +37,18 @@ def index @instances_states += "{'label': '" + state_value[:label] + "', 'color': '" + state_value[:color] + "', 'data': " + state_value[:data].to_s + "}, " end @instances_states += "]" + + # Types of application + apps_types = {} + apps.each do |app_item| + app_type = app_item[:staging][:model] + apps_types[app_type] = apps_types[app_type] ? apps_types[app_type] + 1 : 1 + end + @apps_types = "[" + apps_types.each do |type_key, type_value| + @apps_types += "{'label': '" + type_key.capitalize + "', 'data': " + type_value.to_s + "}, " + end + @apps_types += "]" rescue Exception => ex flash[:alert] = ex.message end diff --git a/app/views/dashboard/_apps_overview.html.haml b/app/views/dashboard/_apps_overview.html.haml index aa73b87..db89274 100644 --- a/app/views/dashboard/_apps_overview.html.haml +++ b/app/views/dashboard/_apps_overview.html.haml @@ -2,19 +2,24 @@ %table %tbody %tr.pieCharts - %td + %td.tdptop .apps_states - %td + %td.tdptop .instances_states + %td.tdptop + .apps_types %tr %td.tdptop .apps_states_hover Application's States %td.tdptop .instances_states_hover Instance's States + %td.tdptop + .apps_types_hover Types of Application - content_for :javascripts do :javascript $(function() { apps_states = #{@apps_states}; instances_states = #{@instances_states}; + apps_types = #{@apps_types}; }); \ No newline at end of file