Add bar chart
This commit is contained in:
parent
582562dae0
commit
c4ebe12408
5 changed files with 26 additions and 7 deletions
1
Gemfile
1
Gemfile
|
|
@ -8,3 +8,4 @@ gem 'puma'
|
|||
gem 'sqlite3'
|
||||
gem 'bcrypt'
|
||||
gem 'gettext'
|
||||
gem 'chartkick'
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title><%= _("Vote") %></title>
|
||||
<script src="/chartkick.js"></script>
|
||||
<script src="/Chart.bundle.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<% if current_user %>
|
||||
|
|
|
|||
|
|
@ -46,6 +46,20 @@
|
|||
<% end %>
|
||||
</table>
|
||||
|
||||
<%
|
||||
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' %>
|
||||
|
||||
<h2><%= _("Organizers") %></h2>
|
||||
|
||||
<ul>
|
||||
|
|
|
|||
14
vote.rb
14
vote.rb
|
|
@ -3,6 +3,7 @@ require 'sinatra/activerecord'
|
|||
require 'bcrypt'
|
||||
require 'gettext'
|
||||
require 'securerandom'
|
||||
require 'chartkick'
|
||||
require_relative 'mj'
|
||||
|
||||
class Vote < ActiveRecord::Base
|
||||
|
|
@ -56,13 +57,12 @@ bindtextdomain('vote', 'locale')
|
|||
set_locale('ca')
|
||||
|
||||
enable :sessions
|
||||
set :values, [ { :id => 1, :label => _("Awful") },
|
||||
{ :id => 2, :label => _("Very bad") },
|
||||
{ :id => 3, :label => _("Bad") },
|
||||
{ :id => 4, :label => _("Mediocre") },
|
||||
{ :id => 5, :label => _("Good") },
|
||||
{ :id => 6, :label => _("Very good") },
|
||||
{ :id => 7, :label => _("Excellent") } ]
|
||||
set :values, [ { :id => 1, :label => _("Awful"), :color => '#ff4500' },
|
||||
{ :id => 2, :label => _("Very bad"), :color => '#ffa500' },
|
||||
{ :id => 3, :label => _("Bad"), :color => '#ffff00' },
|
||||
{ :id => 4, :label => _("Mediocre"), :color => '#9acd32' },
|
||||
{ :id => 5, :label => _("Good"), :color => '#228b22' },
|
||||
{ :id => 6, :label => _("Very good"), :color => '#006400' } ]
|
||||
MajorityJudgment.values = settings.values
|
||||
|
||||
get '/' do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue