Skip to content

Commit

Permalink
Refactor chart module
Browse files Browse the repository at this point in the history
  • Loading branch information
boveus committed Aug 31, 2017
1 parent f40306b commit 810a2fe
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
module DataHandler

module ChartHandler
def shape_chart
shape_label, shape_data = AlienSighting.count_by_shape
setup_chart(shape_label, shape_data, 'Reported Shapes')
end

def setup_chart(data_label, chart_data, chart_label)
{
labels: shape_label,
labels: data_label,
datasets: [
{
label: "Reported shapes",
label: chart_label,
backgroundColor: "rgba(220,220,220,0.2)",
borderColor: "rgba(220,220,220,1)",
data: shape_data
data: chart_data
},
]
}
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/main_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class MainController < ApplicationController
include DataHandler
include ChartHandler
def index
end

Expand Down
6 changes: 2 additions & 4 deletions app/views/main/dashboard.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h3> ITS A DASHBOARD </h3>
<% options = {:width => 100, :height => 100} %>
<%= pie_chart @shape_chart, options %>

<%= pie_chart @shape_chart, {:width => 100, :height => 100} %>

<ol>
Sightings by Country
Expand All @@ -23,8 +23,6 @@
<% end %>
</ol>

<%= line_chart @shape_data %>

<ol>
Sightings by year
<% @sightings_by_year.each do |date, count| %>
Expand Down

0 comments on commit 810a2fe

Please sign in to comment.