Module: Decidim::Demographics::PublishResponsesHelper
- Defined in:
- app/helpers/decidim/demographics/publish_responses_helper.rb
Instance Method Summary collapse
-
#chart_for_question(question_id) ⇒ Object
Renders the chart for the given question.
- #colors_list ⇒ Object
- #options_column_chart_wrapper(question) ⇒ Object
- #question_response_is_publicable(question_type) ⇒ Object
Instance Method Details
#chart_for_question(question_id) ⇒ Object
Renders the chart for the given question. Uses chartkick to render the chart.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/helpers/decidim/demographics/publish_responses_helper.rb', line 16 def chart_for_question(question_id) question = Decidim::Forms::Question.includes(responses: { choices: [:response_option, :matrix_row] }).find(question_id) Chartkick. = { library: { animation: { easing: "easeOutQuart" } }, colors: colors_list } case question.question_type when "single_option", "multiple_option" (question) when "matrix_single", "matrix_multiple" matrix_stack_chart_wrapper(question) when "sorting" sorting_stack_chart_wrapper(question) else "Unknown question type" end end |
#colors_list ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/helpers/decidim/demographics/publish_responses_helper.rb', line 42 def colors_list %w( #3366CC #DC3912 #FF9900 #109618 #3B3EAC #0099C6 #DD4477 #66AA00 #B82E2E #316395 ) end |
#options_column_chart_wrapper(question) ⇒ Object
36 37 38 39 40 |
# File 'app/helpers/decidim/demographics/publish_responses_helper.rb', line 36 def (question) tally = question.responses.map { |response| response.choices.map { |choice| translated_attribute(choice.response_option.body) } }.tally column_chart(tally, download: true) end |
#question_response_is_publicable(question_type) ⇒ Object
6 7 8 9 10 |
# File 'app/helpers/decidim/demographics/publish_responses_helper.rb', line 6 def question_response_is_publicable(question_type) ignored_question_types = %w(short_response long_response separator files).freeze ignored_question_types.exclude?(question_type) end |