New Ticket     Tickets     Wiki     Browse Source     Timeline     Roadmap     Ticket Reports     Search

Changeset 82156


Ignore:
Timestamp:
08/08/11 20:08:54 (4 years ago)
Author:
derek@…
Message:

Use gvis, removed all javascript, use helper methods

  • Call controller.set_chart_title to set title rather than building up a hash
  • Added a loop to set the type of all charts to PieChart
  • Use an array to define the order that charts will appear on the page
  • Display charts using gvis visualization call
  • Removed all javascript
  • Removed divs, they'll be generated by gvis
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/gsoc11-statistics/stats-server/app/views/os_statistics/index.html.erb

    r81855 r82156  
    1 <%# title: Title of the chart %> 
    2 <%# key: key into chartjson hash table %> 
    3 <%# div: div where chart should be drawn %> 
    4 <% charts = [] %> 
    5 <% charts << {:title => 'MacPorts Versions', :key => 'macports_version',  :div => 'macports_versions_div'} %> 
    6 <% charts << {:title => 'OSX Versions', :key => 'osx_version', :div => 'osx_versions_div'} %> 
    7 <% charts << {:title => 'OS Arch', :key => 'os_arch', :div => 'os_arch_div'} %> 
    8 <% charts << {:title => 'OS Platform', :key => 'os_platform', :div => 'os_platform_div'} %> 
    9 <% charts << {:title => 'Build Arch', :key => 'build_arch', :div => 'build_arch_div'} %> 
    10 <% charts << {:title => 'gcc Version', :key => 'gcc_version', :div => 'gcc_version_div'} %> 
    11 <% charts << {:title => 'XCode Version', :key => 'xcode_version', :div => 'xcode_version_div'} %> 
     1<%# Set titles for charts %> 
     2<% controller.set_chart_title :macports_version, "MacPorts Versions" %> 
     3<% controller.set_chart_title :osx_version, "OSX Versions" %> 
     4<% controller.set_chart_title :os_arch, "OS Arch" %> 
     5<% controller.set_chart_title :os_platform, "OS Platform" %> 
     6<% controller.set_chart_title :build_arch, "Build Arch" %> 
     7<% controller.set_chart_title :gcc_version, "gcc Versions" %> 
     8<% controller.set_chart_title :xcode_version, "XCode Versions" %> 
    129 
    13 <!--Load the AJAX API--> 
    14 <script type="text/javascript" src="https://www.google.com/jsapi"></script> 
     10<%# All these charts are pie charts - set :type to PieChart %> 
     11<% @charts.each do |chart_name, chartdata| %> 
     12  <% controller.set_chart_type chart_name, "PieChart" %> 
     13<% end %> 
    1514 
    16 <script type="text/javascript"> 
    17 // Load the Visualization API and the piechart package. 
    18 google.load('visualization', '1', {'packages':['corechart']}); 
    19        
    20 // Set a callback to run when the Google Visualization API is loaded. 
    21 google.setOnLoadCallback(drawAllCharts); 
     15<%# Order the charts %> 
     16<% ordered_charts = [:macports_version,  
     17                     :osx_version,  
     18                     :os_arch,  
     19                     :os_platform, 
     20                     :build_arch, 
     21                     :gcc_version, 
     22                     :xcode_version] %> 
    2223 
    23 function drawPieChart(json, title, div) { 
    24   var data  = new google.visualization.DataTable(json); 
    25   var chart = new google.visualization.PieChart(document.getElementById(div)); 
    26   chart.draw(data, {width: 450, height: 300, title: title}); 
    27 } 
    28  
    29 function drawAllCharts() { 
     24<% ordered_charts.each do |chart| %> 
     25  <% options = {:width => 600, :height => 400, :html => {:class => "graph_chart"}} %> 
     26  <% options[:title] = controller.chart_title chart %> 
     27  <% type = controller.chart_type chart %> 
    3028   
    31   <% charts.each do |hash|%> 
    32   json = <%= raw @chartjson[hash[:key]] %>; 
    33   drawPieChart(json, '<%= hash[:title] %>', '<%= hash[:div] %>'); 
     29  <% visualization chart, type, options do |visualization| %> 
     30    <% controller.populate_chart chart, visualization %> 
    3431  <% end %> 
    35 } 
    36 </script> 
    37   
    38 <div id="macports_versions_div"></div> 
    39 <div id="osx_versions_div"></div> 
    40 <div id="os_arch_div"></div> 
    41 <div id="os_platform_div"></div> 
    42 <div id="build_arch_div"></div> 
    43 <div id="gcc_version_div"></div> 
    44 <div id="xcode_version_div"></div> 
     32<% end %> 
    4533 
    4634<br /> 
Note: See TracChangeset for help on using the changeset viewer.