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:
@@ -13,19 +13,19 @@ module Ahoy
|
|||||||
# chart
|
# chart
|
||||||
def add(name, collection)
|
def add(name, collection)
|
||||||
collections.push data: collection, name: name
|
collections.push data: collection, name: name
|
||||||
shared_keys.merge(collection.keys)
|
dates.merge(collection.keys)
|
||||||
end
|
end
|
||||||
|
|
||||||
def build
|
def build
|
||||||
data = { x: [] }
|
data = { x: [] }
|
||||||
shared_keys.each do |k|
|
dates.each do |date|
|
||||||
# Add the key with a valid date format
|
# 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
|
# Add the value for each column, or 0 if not present
|
||||||
collections.each do |col|
|
collections.each do |col|
|
||||||
data[col[:name]] ||= []
|
data[col[:name]] ||= []
|
||||||
count = col[:data][k] || 0
|
count = col[:data][date] || 0
|
||||||
data[col[:name]].push count
|
data[col[:name]].push count
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -39,8 +39,8 @@ module Ahoy
|
|||||||
@collections ||= []
|
@collections ||= []
|
||||||
end
|
end
|
||||||
|
|
||||||
def shared_keys
|
def dates
|
||||||
@shared_keys ||= Set.new
|
@dates ||= Set.new
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user