Make it more obvious that we're using dates in charts

The `shared_keys` and `k` variable names could mean anything, so it
wasn't clear what these variables contained.
This commit is contained in:
Javi Martín
2024-05-08 17:44:16 +02:00
parent d44cff630d
commit 86e131df26

View File

@@ -13,19 +13,19 @@ module Ahoy
# chart
def add(name, collection)
collections.push data: collection, name: name
shared_keys.merge(collection.keys)
dates.merge(collection.keys)
end
def build
data = { x: [] }
shared_keys.each do |k|
dates.each do |date|
# Add the key with a valid date format
data[:x].push k.strftime("%Y-%m-%d")
data[:x].push date.strftime("%Y-%m-%d")
# Add the value for each column, or 0 if not present
collections.each do |col|
data[col[:name]] ||= []
count = col[:data][k] || 0
count = col[:data][date] || 0
data[col[:name]].push count
end
end
@@ -39,8 +39,8 @@ module Ahoy
@collections ||= []
end
def shared_keys
@shared_keys ||= Set.new
def dates
@dates ||= Set.new
end
end
end