From c4ebe12408c1836df53081903aece066ad16adb7 Mon Sep 17 00:00:00 2001 From: ricola Date: Sun, 6 Apr 2025 17:04:31 -0600 Subject: [PATCH] Add bar chart --- Gemfile | 1 + Gemfile.lock | 2 ++ views/layout.erb | 2 ++ views/votes_show_closed.erb | 14 ++++++++++++++ vote.rb | 14 +++++++------- 5 files changed, 26 insertions(+), 7 deletions(-) diff --git a/Gemfile b/Gemfile index 1884105..912bcb4 100644 --- a/Gemfile +++ b/Gemfile @@ -8,3 +8,4 @@ gem 'puma' gem 'sqlite3' gem 'bcrypt' gem 'gettext' +gem 'chartkick' diff --git a/Gemfile.lock b/Gemfile.lock index ca3398b..995a623 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -23,6 +23,7 @@ GEM bcrypt (3.1.20) benchmark (0.4.0) bigdecimal (3.1.9) + chartkick (5.1.4) concurrent-ruby (1.3.5) connection_pool (2.5.0) drb (2.2.1) @@ -91,6 +92,7 @@ PLATFORMS DEPENDENCIES bcrypt + chartkick gettext puma rackup diff --git a/views/layout.erb b/views/layout.erb index defbed5..8f974f6 100644 --- a/views/layout.erb +++ b/views/layout.erb @@ -3,6 +3,8 @@ <%= _("Vote") %> + + <% if current_user %> diff --git a/views/votes_show_closed.erb b/views/votes_show_closed.erb index f75958f..4ca8b71 100644 --- a/views/votes_show_closed.erb +++ b/views/votes_show_closed.erb @@ -46,6 +46,20 @@ <% end %> +<% +data = [] +colors = [] +settings.values.reverse.each do |v| + d = { name: v[:label], data: [] } + @vote.candidates.each do |c| + d[:data] << [c.name, c.mj.count[v[:id]]] + end + data << d + colors << v[:color] +end +%> +<%= bar_chart data, colors: colors, stacked: true, legend: 'bottom' %> +

<%= _("Organizers") %>