From 11aa57d9b842e92fe9c8720ece5590425acc2ecb Mon Sep 17 00:00:00 2001 From: Christoph Marzell Date: Fri, 19 Dec 2025 08:47:41 +0100 Subject: [PATCH] add bar chart --- app/controllers/entries_controller.rb | 7 +++++++ app/javascript/application.js | 3 ++- app/views/entries/index.html.erb | 21 +++++++++++++++++++++ app/views/layouts/application.html.erb | 12 ++++++++++++ config/importmap.rb | 2 ++ 5 files changed, 44 insertions(+), 1 deletion(-) diff --git a/app/controllers/entries_controller.rb b/app/controllers/entries_controller.rb index 9c4d8e1..2be0481 100644 --- a/app/controllers/entries_controller.rb +++ b/app/controllers/entries_controller.rb @@ -35,6 +35,7 @@ class EntriesController < ApplicationController end @completion_percent_by_typ_art = {} + @progress_chart_data = {} User::PRAKTIKUMSTYPEN.product(User::ENTRY_ARTEN).each do |typ, art| total_required = current_user.required_hours_matrix.to_h.dig(typ, art).to_f @@ -47,12 +48,18 @@ class EntriesController < ApplicationController percent = (done_minutes / required_minutes.to_f * 100).round percent = 100 if percent > 100 @completion_percent_by_typ_art[[typ, art]] = percent + @progress_chart_data["#{typ.capitalize} – #{art}"] = percent else @completion_percent_by_typ_art[[typ, art]] = 0 + @progress_chart_data["#{typ.capitalize} – #{art}"] = 0 end end + + + + @total_kilometer_costs_by_year = Entry.total_kilometer_cost_by_year(current_user) @fortbildungskosten_by_year = Entry.total_fortbildungskosten_by_year(current_user) @selbstsupervision_by_year = Entry.total_supervision_by_year(current_user) diff --git a/app/javascript/application.js b/app/javascript/application.js index a65e1f7..2974b52 100644 --- a/app/javascript/application.js +++ b/app/javascript/application.js @@ -3,7 +3,8 @@ import { application } from "controllers/application" import $ from "jquery" import "bootstrap" - +import "chartkick" +import "Chart.bundle" window.$ = $ window.jQuery = $ diff --git a/app/views/entries/index.html.erb b/app/views/entries/index.html.erb index 4dceae7..3d8c8b2 100644 --- a/app/views/entries/index.html.erb +++ b/app/views/entries/index.html.erb @@ -1,5 +1,26 @@

Meine Einträge

+
📊 Fortschritt je Kombination
+ +
+ +<%= bar_chart @progress_chart_data, + donut: false, + height: "300px", + library: { + legend: { position: "bottom" }, + + tooltip: { + callbacks: { + label: %|function(context) { + return context.label + ": " + context.parsed + "%"; + }| + } + } + + } %> + +
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 8b0c284..87555ea 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -14,6 +14,14 @@ + + + + + + + + diff --git a/config/importmap.rb b/config/importmap.rb index 3dd260f..5218993 100644 --- a/config/importmap.rb +++ b/config/importmap.rb @@ -17,3 +17,5 @@ pin "bootstrap", to: "https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/boots # Chart.js + interne Abhängigkeit pin "chart.js", to: "https://ga.jspm.io/npm:chart.js@4.4.1/dist/chart.js" pin "@kurkle/color", to: "https://ga.jspm.io/npm:@kurkle/color@0.3.2/dist/color.esm.js" +pin "chartkick", to: "chartkick.js" +pin "Chart.bundle", to: "Chart.bundle.js" \ No newline at end of file