module RailsAdminCharts::ClassMethods
Public Instance Methods
chart_type()
click to toggle source
# File lib/rails_admin_charts.rb, line 40 def chart_type "" end
delta_records_since(since = 30.days.ago)
click to toggle source
# File lib/rails_admin_charts.rb, line 16 def delta_records_since(since = 30.days.ago) deltas = self.group('DATE(created_at)').count (since.to_date..Date.today).map { |date| deltas[date] || deltas[date.to_s] || 0 } end
graph_data(since=30.days.ago)
click to toggle source
# File lib/rails_admin_charts.rb, line 21 def graph_data(since=30.days.ago) [ { name: model_name.plural, pointInterval: 1.day * 1000, pointStart: since.to_i * 1000, data: self.total_records_since(since) } ] end
label_rotation()
click to toggle source
# File lib/rails_admin_charts.rb, line 36 def label_rotation "0" end
total_records_since(since = 30.days.ago)
click to toggle source
# File lib/rails_admin_charts.rb, line 10 def total_records_since(since = 30.days.ago) totals, before_count = self.group('DATE(created_at)').count, self.where('created_at < ?', since.to_date).count # TODO separate MySQL/Postgres approaches using ActiveRecord::Base.connection.adapter_name or check hash key is_a? String/Date (since.to_date..Date.today).each_with_object([]) { |day, a| a << (a.last || before_count) + (totals[day] || totals[day.to_s] || 0) } end
xaxis()
click to toggle source
# File lib/rails_admin_charts.rb, line 32 def xaxis "datetime" end