diff --git a/app/controllers/simulation_controller.rb b/app/controllers/simulation_controller.rb index d64f70d21af0d9537b68a9d52eaf7b53e17aa429..4ceb44e1821711b1a937c50a29c9d8273e9876e7 100644 --- a/app/controllers/simulation_controller.rb +++ b/app/controllers/simulation_controller.rb @@ -81,6 +81,39 @@ class SimulationController < ApplicationController end + def show + simulate + g = Gruff::Line.new + # Uncomment to use your own theme or font + # See http://colourlovers.com or http://www.firewheeldesign.com/widgets/ for color ideas +# g.theme = { +# :colors => ['#663366', '#cccc99', '#cc6633', '#cc9966', '#99cc99'], +# :marker_color => 'white', +# :background_colors => ['black', '#333333'] +# } +# g.font = File.expand_path('artwork/fonts/VeraBd.ttf', RAILS_ROOT) + + g.title = "Simulation" + + datapoints = [] + labels = {} + @actions.each { |data| + date = data[0] + amount = data[3] + + if date.day == 1 + labels[datapoints.size] = "#{date.year}-#{date.month}" + end + datapoints << amount + } + + g.data("Cash", datapoints) + + g.labels = labels + + send_data(g.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "gruff.png") + end + def time_to_date(t) Date.civil(t.year, t.month, t.day) end diff --git a/app/controllers/simulation_graph_controller.rb b/app/controllers/simulation_graph_controller.rb deleted file mode 100644 index c34b0424689b381fa442907c8ad3bbecb5efd75c..0000000000000000000000000000000000000000 --- a/app/controllers/simulation_graph_controller.rb +++ /dev/null @@ -1,32 +0,0 @@ -class SimulationGraphController < ApplicationController - - # To make caching easier, add a line like this to config/routes.rb: - # map.graph "graph/:action/:id/image.png", :controller => "graph" - # - # Then reference it with the named route: - # image_tag graph_url(:action => 'show', :id => 42) - - def show - g = Gruff::Line.new - # Uncomment to use your own theme or font - # See http://colourlovers.com or http://www.firewheeldesign.com/widgets/ for color ideas -# g.theme = { -# :colors => ['#663366', '#cccc99', '#cc6633', '#cc9966', '#99cc99'], -# :marker_color => 'white', -# :background_colors => ['black', '#333333'] -# } -# g.font = File.expand_path('artwork/fonts/VeraBd.ttf', RAILS_ROOT) - - g.title = "Gruff-o-Rama" - - g.data("Apples", [1, 2, 3, 4, 4, 3]) - g.data("Oranges", [4, 8, 7, 9, 8, 9]) - g.data("Watermelon", [2, 3, 1, 5, 6, 8]) - g.data("Peaches", [9, 9, 10, 8, 7, 9]) - - g.labels = {0 => '2004', 2 => '2005', 4 => '2006'} - - send_data(g.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "gruff.png") - end - -end diff --git a/app/views/simulation/simulate.rhtml b/app/views/simulation/simulate.rhtml index 00280f9397eaf2316a7a911f575d4bdcdcbb0c26..0da42c49d533d56282cef02fd8921e157d03237c 100644 --- a/app/views/simulation/simulate.rhtml +++ b/app/views/simulation/simulate.rhtml @@ -20,6 +20,9 @@ <% end %> </table> +<%= image_tag graph_url(:action => 'show', :enddate => @end_date) %> + + <p>Transactions:</p> <table border="1"> diff --git a/config/environment.rb b/config/environment.rb index 03e9560821839cbffa4b71b359ecc0a2c396272b..bc6d7c4e3216b7a851d3bbd3197e3ed899abc1fa 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -50,4 +50,5 @@ end # inflect.uncountable %w( fish sheep ) # end -# Include your application configuration below \ No newline at end of file +# Include your application configuration below +require 'gruff' diff --git a/config/routes.rb b/config/routes.rb index 27fcae80d40e4222ca7bceb9028bbecee9121c60..a9d3b97f60d1bd36de150148189a0ddb74ede1bf 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -17,6 +17,8 @@ ActionController::Routing::Routes.draw do |map| # instead of a file named 'wsdl' map.connect ':controller/service.wsdl', :action => 'wsdl' + map.graph "simulation/:action/:enddate/image.png", :controller => "simulation" + # Install the default route as the lowest priority. map.connect ':controller/:action/:id' end diff --git a/test/functional/simulation_graph_controller_test.rb b/test/functional/simulation_graph_controller_test.rb deleted file mode 100644 index 378adf7ffd647cacb5c192ebba331a60fb26d6ff..0000000000000000000000000000000000000000 --- a/test/functional/simulation_graph_controller_test.rb +++ /dev/null @@ -1,24 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' -require 'simulation_graph_controller' - -# Re-raise errors caught by the controller. -class SimulationGraphController; def rescue_action(e) raise e end; end - -class SimulationGraphControllerTest < Test::Unit::TestCase - - #fixtures :data - - def setup - @controller = SimulationGraphController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new - end - - # TODO Replace this with your actual tests - def test_show - get :show - assert_response :success - assert_equal 'image/png', @response.headers['Content-Type'] - end - -end