[82900] branches/gsoc11-statistics/stats-server/app/views/partials/ _chart_draw.html.erb

derek at macports.org derek at macports.org
Sun Aug 21 15:57:52 PDT 2011


Revision: 82900
          http://trac.macports.org/changeset/82900
Author:   derek at macports.org
Date:     2011-08-21 15:57:52 -0700 (Sun, 21 Aug 2011)
Log Message:
-----------
Added options

- Views can now pass in the following

- charts: collection of names of charts that should be drawn
Default: empty hash table

- chart_height, chart_width - width and height of charts.
defaults: height:400, width:600

- drawtables - draw a table along with each chart
default: true

Modified Paths:
--------------
    branches/gsoc11-statistics/stats-server/app/views/partials/_chart_draw.html.erb

Modified: branches/gsoc11-statistics/stats-server/app/views/partials/_chart_draw.html.erb
===================================================================
--- branches/gsoc11-statistics/stats-server/app/views/partials/_chart_draw.html.erb	2011-08-21 22:55:04 UTC (rev 82899)
+++ branches/gsoc11-statistics/stats-server/app/views/partials/_chart_draw.html.erb	2011-08-21 22:57:52 UTC (rev 82900)
@@ -1,15 +1,51 @@
+<%# Set Defaults %>
+<% drawtables_default = true %>
+<% chart_width_default = 600 %>
+<% chart_height_default = 400 %>
+
+<%# Check if locals have been passed to this partial %>
+<%# Use them if available, otherwise use defaults %>
+
+<%# Avoid nil objects  %>
+<% if (defined? charts).nil? %>  
+  <% charts = Hash.new %>
+<% end %>
+
+<%# Draw tables as well as visualizations? %>
+<% if (defined? drawtables).nil? %>
+  <% drawtables = drawtables_default %>
+<% end %>
+
+<%# Get chart width %>
+<% if (defined? chart_width).nil? %>
+  <% chart_width = chart_width_default %>
+<% end %>
+
+<%# Get chart height %>
+<% if (defined? chart_height).nil? %>
+  <% chart_height = chart_height_default %>
+<% end %>
+
+<%# Set visualization options %>
+<% vis_options = {:width => chart_width, 
+                  :height => chart_height, 
+                  :html => {:class => "graph_chart"}} 
+%>
+
+<%# Set table options %>
+<% table_options = {:width => 600, 
+                    :html => {:class => "graph_chart"}} 
+%>
+
+
 <%# Draw charts %>
 <% charts.each do |chart| %>
   <% title = controller.chart_title chart %>
-  <%# Set visualization options %>
-  <% vis_options = {:width => 600, :height => 400, :html => {:class => "graph_chart"}} %>
+  <% type = controller.chart_type chart %>
+
+  <%# Set titles %>
   <% vis_options[:title] = title %>
-
-  <%# Set table options %>
-  <% table_options = {:width => 600, :html => {:class => "graph_chart"}} %>
   <% table_options[:title] = title %>
-  
-  <% type = controller.chart_type chart %>
 
   <%# Anchor %>
   <a name=<%= chart %>> </a>
@@ -23,13 +59,15 @@
       <% controller.populate_chart chart, visualization %>
     <% end %>
     
-    <%# Draw table %>
-    <% table = chart.to_s + "_table" %>
-    <% visualization table, "Table", table_options do |visualization| %>
-      <% controller.populate_chart chart, visualization %>
+    <% if drawtables %>
+      <%# Draw table %>
+      <% table = chart.to_s + "_table" %>
+      <% visualization table, "Table", table_options do |visualization| %>
+        <% controller.populate_chart chart, visualization %>
+        <% end %>
     <% end %>
     
   <% else %>
     No data to display
   <% end %>  
-<% end %>
\ No newline at end of file
+<% end %>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20110821/187554aa/attachment.html>


More information about the macports-changes mailing list