From 5d2b7de30fa4549a3a6ac3d2e87edda09ff6d5c0 Mon Sep 17 00:00:00 2001 From: Uku Taht Date: Fri, 6 Sep 2019 17:44:43 +0100 Subject: [PATCH] Cut off graph in the future --- lib/plausible/stats/stats.ex | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/plausible/stats/stats.ex b/lib/plausible/stats/stats.ex index 9e5a0aebf..8719c0db7 100644 --- a/lib/plausible/stats/stats.ex +++ b/lib/plausible/stats/stats.ex @@ -31,9 +31,9 @@ defmodule Plausible.Stats do ) |> Enum.into(%{}) |> transform_keys(fn dt -> NaiveDateTime.to_date(dt) end) + present_index = Enum.find_index(steps, fn step -> step == Timex.now(site.timezone) |> Timex.to_date |> Timex.beginning_of_month end) plot = Enum.map(steps, fn step -> groups[step] || 0 end) labels = Enum.map(steps, fn step -> Timex.format!(step, "{ISOdate}") end) - present_index = Enum.find_index(steps, fn step -> step == Timex.now(site.timezone) |> Timex.to_date |> Timex.beginning_of_month end) {plot, labels, present_index} end @@ -49,9 +49,10 @@ defmodule Plausible.Stats do ) |> Enum.into(%{}) |> transform_keys(fn dt -> NaiveDateTime.to_date(dt) end) - plot = Enum.map(steps, fn step -> groups[step] || 0 end) - labels = Enum.map(steps, fn step -> Timex.format!(step, "{ISOdate}") end) present_index = Enum.find_index(steps, fn step -> step == Timex.now(site.timezone) |> Timex.to_date end) + steps_to_show = if present_index, do: present_index + 1, else: Enum.count(steps) + plot = Enum.map(steps, fn step -> groups[step] || 0 end) |> Enum.take(steps_to_show) + labels = Enum.map(steps, fn step -> Timex.format!(step, "{ISOdate}") end) {plot, labels, present_index} end @@ -75,9 +76,10 @@ defmodule Plausible.Stats do |> Enum.into(%{}) |> transform_keys(fn dt -> NaiveDateTime.truncate(dt, :second) end) - plot = Enum.map(steps, fn step -> groups[step] || 0 end) - labels = Enum.map(steps, fn step -> NaiveDateTime.to_iso8601(step) end) present_index = Enum.find_index(steps, fn step -> step == Timex.now(site.timezone) |> truncate_to_hour |> NaiveDateTime.truncate(:second) end) + steps_to_show = if present_index, do: present_index + 1, else: Enum.count(steps) + plot = Enum.map(steps, fn step -> groups[step] || 0 end) |> Enum.take(steps_to_show) + labels = Enum.map(steps, fn step -> NaiveDateTime.to_iso8601(step) end) {plot, labels, present_index} end