Skip to content

Commit

Permalink
Add another chart.
Browse files Browse the repository at this point in the history
  • Loading branch information
boveus committed Aug 31, 2017
1 parent 810a2fe commit 4df8205
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
5 changes: 5 additions & 0 deletions app/controllers/chart_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ def shape_chart
setup_chart(shape_label, shape_data, 'Reported Shapes')
end

def country_chart
shape_label, shape_data = AlienSighting.count_by_country
setup_chart(shape_label, shape_data, 'Sightings by country')
end

def setup_chart(data_label, chart_data, chart_label)
{
labels: data_label,
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/main_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def index
end

def dashboard
@country_counts = AlienSighting.count_by_country
@country_chart = country_chart
@city_counts = AlienSighting.count_by_cities
@state_counts = AlienSighting.count_by_state
@shape_chart = shape_chart
Expand Down
2 changes: 2 additions & 0 deletions app/models/alien_sighting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ def self.shape_by_country(shape)
end

def self.count_by_country
format_for_chart(
group(:country)
.order("count(country) DESC")
.count
.first(5)
)
end

def self.count_by_cities(country = 'us', number = 10)
Expand Down
10 changes: 2 additions & 8 deletions app/views/main/dashboard.html.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
<h3> ITS A DASHBOARD </h3>

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

<ol>
Sightings by Country
<% @country_counts.each do |country, count| %>
<li> Country: <%= country %>, <%= count %> </li>
<% end %>
</ol>
<%= pie_chart @shape_chart, {:width => 50, :height => 100} %>
<%= bar_chart @country_chart %>

<ol>
Sightings by US city
Expand Down

0 comments on commit 4df8205

Please sign in to comment.