Skip to content

Commit

Permalink
Add stack chart
Browse files Browse the repository at this point in the history
  • Loading branch information
tschaefer committed Jan 19, 2025
1 parent 99f8f96 commit b764070
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ gem 'yabeda-rails'

# Application requirements
gem 'addressable'
gem 'chartkick'
gem 'chronic_duration', '>= 0.10.6'
gem 'hashie', '>= 5.0.0'
gem 'shellwords', '>= 0.2.0'
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ GEM
racc
builder (3.3.0)
byebug (11.1.3)
chartkick (5.1.2)
childprocess (5.1.0)
logger (~> 1.5)
chronic_duration (0.10.6)
Expand Down Expand Up @@ -439,6 +440,7 @@ DEPENDENCIES
awesome_print
bootsnap
brakeman
chartkick
chronic_duration (>= 0.10.6)
factory_bot_rails
faker
Expand Down
3 changes: 3 additions & 0 deletions app/javascript/application.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails
import "@hotwired/turbo-rails"
import "controllers"

import "chartkick"
import "Chart.bundle"
5 changes: 5 additions & 0 deletions app/javascript/controllers/log_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ export default class extends Controller {
this.currentUuidValue = uuid;
Turbo.visit(`/dashboard?uuid=${uuid}`, { frame: logFrame.id });
}
const statisticsFrame = document.getElementById("statistics-frame");
if (statisticsFrame) {
this.currentUuidValue = uuid;
Turbo.visit(`/dashboard?uuid=${uuid}`, { frame: statisticsFrame.id });
}
}
}

13 changes: 12 additions & 1 deletion app/views/dashboard/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
</turbo-frame>
</div>
<div class="col col-lg-4">
<turbo-frame id="statistics-frame" data-turbo-permanent>
<% uuid = params[:uuid] || @stacks&.first&.uuid %>
<% if uuid %>
<% stack = Stack.find_by(uuid: uuid) %>
Expand All @@ -166,10 +167,20 @@
</div>
<div class="card-body">
<% if stack %>
<canvas id="stack-chart"></canvas>
<% log = stack.log(entries: 10) %>
<% actions = log.group_by { it['action'] }.map { |k, v| [k, v.count] } %>
<%=
pie_chart actions,
legend: 'left',
donut: true,
dataset: { borderWidth: 0, cutout: '75%' },
library: { plugins: { legend: { labels: { usePointStyle: true } } } }
%>
<% end %>
</div>
</div>
</turbo-frame>
</div>
</div>
<input type="hidden" id="selected-uuid"
data-log-target="selectedUuid"
Expand Down
3 changes: 3 additions & 0 deletions config/importmap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
pin '@hotwired/stimulus', to: 'stimulus.min.js'
pin '@hotwired/stimulus-loading', to: 'stimulus-loading.js'
pin_all_from 'app/javascript/controllers', under: 'controllers'

pin 'chartkick', to: 'chartkick.js'
pin 'Chart.bundle', to: 'Chart.bundle.js'

0 comments on commit b764070

Please sign in to comment.