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 'sqlite3'
|
||||||
gem 'bcrypt'
|
gem 'bcrypt'
|
||||||
gem 'gettext'
|
gem 'gettext'
|
||||||
|
gem 'chartkick'
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ GEM
|
||||||
bcrypt (3.1.20)
|
bcrypt (3.1.20)
|
||||||
benchmark (0.4.0)
|
benchmark (0.4.0)
|
||||||
bigdecimal (3.1.9)
|
bigdecimal (3.1.9)
|
||||||
|
chartkick (5.1.4)
|
||||||
concurrent-ruby (1.3.5)
|
concurrent-ruby (1.3.5)
|
||||||
connection_pool (2.5.0)
|
connection_pool (2.5.0)
|
||||||
drb (2.2.1)
|
drb (2.2.1)
|
||||||
|
|
@ -91,6 +92,7 @@ PLATFORMS
|
||||||
|
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
bcrypt
|
bcrypt
|
||||||
|
chartkick
|
||||||
gettext
|
gettext
|
||||||
puma
|
puma
|
||||||
rackup
|
rackup
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<title><%= _("Vote") %></title>
|
<title><%= _("Vote") %></title>
|
||||||
|
<script src="/chartkick.js"></script>
|
||||||
|
<script src="/Chart.bundle.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<% if current_user %>
|
<% if current_user %>
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,20 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
</table>
|
</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>
|
<h2><%= _("Organizers") %></h2>
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
|
|
|
||||||
14
vote.rb
14
vote.rb
|
|
@ -3,6 +3,7 @@ require 'sinatra/activerecord'
|
||||||
require 'bcrypt'
|
require 'bcrypt'
|
||||||
require 'gettext'
|
require 'gettext'
|
||||||
require 'securerandom'
|
require 'securerandom'
|
||||||
|
require 'chartkick'
|
||||||
require_relative 'mj'
|
require_relative 'mj'
|
||||||
|
|
||||||
class Vote < ActiveRecord::Base
|
class Vote < ActiveRecord::Base
|
||||||
|
|
@ -56,13 +57,12 @@ bindtextdomain('vote', 'locale')
|
||||||
set_locale('ca')
|
set_locale('ca')
|
||||||
|
|
||||||
enable :sessions
|
enable :sessions
|
||||||
set :values, [ { :id => 1, :label => _("Awful") },
|
set :values, [ { :id => 1, :label => _("Awful"), :color => '#ff4500' },
|
||||||
{ :id => 2, :label => _("Very bad") },
|
{ :id => 2, :label => _("Very bad"), :color => '#ffa500' },
|
||||||
{ :id => 3, :label => _("Bad") },
|
{ :id => 3, :label => _("Bad"), :color => '#ffff00' },
|
||||||
{ :id => 4, :label => _("Mediocre") },
|
{ :id => 4, :label => _("Mediocre"), :color => '#9acd32' },
|
||||||
{ :id => 5, :label => _("Good") },
|
{ :id => 5, :label => _("Good"), :color => '#228b22' },
|
||||||
{ :id => 6, :label => _("Very good") },
|
{ :id => 6, :label => _("Very good"), :color => '#006400' } ]
|
||||||
{ :id => 7, :label => _("Excellent") } ]
|
|
||||||
MajorityJudgment.values = settings.values
|
MajorityJudgment.values = settings.values
|
||||||
|
|
||||||
get '/' do
|
get '/' do
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue