Sort data by date when building graphs
This doesn't affect the end result because all collections used the same order, but it makes debugging easier.
This commit is contained in:
@@ -18,7 +18,7 @@ module Ahoy
|
|||||||
|
|
||||||
def build
|
def build
|
||||||
data = { x: [] }
|
data = { x: [] }
|
||||||
dates.each do |date|
|
dates.sort.each do |date|
|
||||||
# Add the key with a valid date format
|
# Add the key with a valid date format
|
||||||
data[:x].push date.strftime("%Y-%m-%d")
|
data[:x].push date.strftime("%Y-%m-%d")
|
||||||
|
|
||||||
|
|||||||
@@ -25,5 +25,15 @@ describe Ahoy::DataSource do
|
|||||||
"foo" => [2, 1, 0],
|
"foo" => [2, 1, 0],
|
||||||
"bar" => [1, 0, 2]
|
"bar" => [1, 0, 2]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "returns data ordered by dates" do
|
||||||
|
ds = Ahoy::DataSource.new
|
||||||
|
ds.add "foo", { january_third => 2, january_second => 1 }
|
||||||
|
ds.add "bar", { january_first => 2, january_second => 1 }
|
||||||
|
|
||||||
|
expect(ds.build).to eq :x => ["2015-01-01", "2015-01-02", "2015-01-03"],
|
||||||
|
"foo" => [0, 1, 2],
|
||||||
|
"bar" => [2, 1, 0]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user