Last active
August 29, 2015 14:23
-
-
Save zamith/489eea929f1ce0dd637c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def index | |
@plans = Plan.all | |
@graph = Graph.new(@plans) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Graph | |
GRAPHS = { | |
roi: ReturnInvestment, | |
extra_pay: ExtraPay, | |
profit: Profit | |
} | |
private_constant :GRAPHS | |
def initialize(plans) | |
@plans = plans | |
end | |
def data_for(graph_identifier = :roi) | |
GRAPHS[graph_identifier].new.data(@plans) | |
end | |
end | |
class ReturnInvestiment | |
def data(plans) | |
plans.each_with_object({}) do |plan, graph_data| | |
graph_data[plan.name] = plan.return_of_investiment.round(2) | |
end | |
end | |
end | |
class ExtraPay | |
def data(plans) | |
plans.each_with_object({}) do |plan, graph_data| | |
graph_data[plan.name] = plan.extra_pay_total.round(2) | |
end | |
end | |
end | |
class Profit | |
def data(plans) | |
plans.each_with_object({}) do |plan, graph_data| | |
graph_data[plan.name] = plan.profit.round(2) | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= javascript_include_tag "http://www.google.com/jsapi", "chartkick" %> | |
<div class="container"> | |
<div class="row"> | |
<div class="col-md-offset-2 col-md-8"> | |
<div class="page-header"> | |
<h3>Financials</h3> | |
</div> | |
<% if @plans.empty? %> | |
<div> | |
No plans available. | |
</div> | |
<% else %> | |
<%= pie_chart @graph.data_for(:profit) %> | |
<p class="chart-label">Profit by plan chart<p> | |
<%= column_chart @graph.data_for(:roi) %> | |
<p class="chart-label">Return of investiment chart<p> | |
<%= column_chart @graph.data_for(:extra_pay) %> | |
<p class="chart-label">Extra pay by plan chart<p> | |
<% end %> | |
</div> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment