From 810a2fea2ded20daf24c7dc58dc1082500401d69 Mon Sep 17 00:00:00 2001 From: Brandon Stewart Date: Wed, 30 Aug 2017 21:07:57 -0600 Subject: [PATCH] Refactor chart module --- .../{data_handler.rb => chart_handler.rb} | 13 ++++++++----- app/controllers/main_controller.rb | 2 +- app/views/main/dashboard.html.erb | 6 ++---- 3 files changed, 11 insertions(+), 10 deletions(-) rename app/controllers/{data_handler.rb => chart_handler.rb} (51%) diff --git a/app/controllers/data_handler.rb b/app/controllers/chart_handler.rb similarity index 51% rename from app/controllers/data_handler.rb rename to app/controllers/chart_handler.rb index 50bea99..5aff963 100644 --- a/app/controllers/data_handler.rb +++ b/app/controllers/chart_handler.rb @@ -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 }, ] } diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb index a5911f4..25b7839 100644 --- a/app/controllers/main_controller.rb +++ b/app/controllers/main_controller.rb @@ -1,5 +1,5 @@ class MainController < ApplicationController -include DataHandler +include ChartHandler def index end diff --git a/app/views/main/dashboard.html.erb b/app/views/main/dashboard.html.erb index 7dfcb19..9ee4883 100644 --- a/app/views/main/dashboard.html.erb +++ b/app/views/main/dashboard.html.erb @@ -1,6 +1,6 @@

ITS A DASHBOARD

-<% options = {:width => 100, :height => 100} %> -<%= pie_chart @shape_chart, options %> + +<%= pie_chart @shape_chart, {:width => 100, :height => 100} %>
    Sightings by Country @@ -23,8 +23,6 @@ <% end %>
-<%= line_chart @shape_data %> -
    Sightings by year <% @sightings_by_year.each do |date, count| %>