Skip to content

Commit

Permalink
fix(trends): fix month labels when comparing against previous (fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
Aashw1n authored Nov 14, 2024
1 parent bc59a1e commit 07f44d8
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 18 deletions.
2 changes: 1 addition & 1 deletion frontend/src/scenes/trends/viz/ActionsLineGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function ActionsLineGraph({
const labels =
(indexedResults.length === 2 &&
indexedResults.every((x) => x.compare) &&
indexedResults.find((x) => x.compare_label === 'current')?.days) ||
indexedResults.find((x) => x.compare_label === 'current')?.labels) ||
(indexedResults[0] && indexedResults[0].labels) ||
[]

Expand Down
8 changes: 4 additions & 4 deletions posthog/hogql_queries/insights/trends/test/test_trends.py
Original file line number Diff line number Diff line change
Expand Up @@ -2141,9 +2141,9 @@ def test_trends_compare_day_interval_relative_range(self):
)

self.assertEqual(response[0]["label"], "sign up")
self.assertEqual(response[0]["labels"][4], "day 4")
self.assertEqual(response[0]["labels"][4], "1-Jan-2020")
self.assertEqual(response[0]["data"][4], 3.0)
self.assertEqual(response[0]["labels"][5], "day 5")
self.assertEqual(response[0]["labels"][5], "2-Jan-2020")
self.assertEqual(response[0]["data"][5], 1.0)
self.assertEqual(
response[0]["days"],
Expand Down Expand Up @@ -2173,9 +2173,9 @@ def test_trends_compare_day_interval_relative_range(self):
],
)
self.assertEqual(response[1]["label"], "sign up")
self.assertEqual(response[1]["labels"][3], "day 3")
self.assertEqual(response[1]["labels"][3], "24-Dec-2019")
self.assertEqual(response[1]["data"][3], 1.0)
self.assertEqual(response[1]["labels"][4], "day 4")
self.assertEqual(response[1]["labels"][4], "25-Dec-2019")
self.assertEqual(response[1]["data"][4], 0.0)

with freeze_time("2020-01-04T13:00:01Z"):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1044,8 +1044,15 @@ def test_trends_compare(self):
response.results[1]["days"],
)

self.assertEqual(["day 0", "day 1", "day 2", "day 3", "day 4"], response.results[0]["labels"])
self.assertEqual(["day 0", "day 1", "day 2", "day 3", "day 4"], response.results[1]["labels"])
self.assertEqual(
["15-Jan-2020", "16-Jan-2020", "17-Jan-2020", "18-Jan-2020", "19-Jan-2020"],
response.results[0]["labels"],
)

self.assertEqual(
["10-Jan-2020", "11-Jan-2020", "12-Jan-2020", "13-Jan-2020", "14-Jan-2020"],
response.results[1]["labels"],
)

def test_trends_compare_weeks(self):
self._create_test_events()
Expand Down Expand Up @@ -1096,10 +1103,31 @@ def test_trends_compare_weeks(self):
)

self.assertEqual(
["day 0", "day 1", "day 2", "day 3", "day 4", "day 5", "day 6", "day 7"], response.results[0]["labels"]
[
"17-Jan-2020",
"18-Jan-2020",
"19-Jan-2020",
"20-Jan-2020",
"21-Jan-2020",
"22-Jan-2020",
"23-Jan-2020",
"24-Jan-2020",
],
response.results[0]["labels"],
)

self.assertEqual(
["day 0", "day 1", "day 2", "day 3", "day 4", "day 5", "day 6", "day 7"], response.results[1]["labels"]
[
"10-Jan-2020",
"11-Jan-2020",
"12-Jan-2020",
"13-Jan-2020",
"14-Jan-2020",
"15-Jan-2020",
"16-Jan-2020",
"17-Jan-2020",
],
response.results[1]["labels"],
)

def test_trends_breakdowns(self):
Expand Down
9 changes: 0 additions & 9 deletions posthog/hogql_queries/insights/trends/trends_query_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,17 +524,8 @@ def get_value(name: str, val: Any):

# Modifications for when comparing to previous period
if self.query.compareFilter is not None and self.query.compareFilter.compare:
labels = [
"{} {}".format(
self.query.interval if self.query.interval is not None else "day",
i,
)
for i in range(len(series_object.get("labels", [])))
]

series_object["compare"] = True
series_object["compare_label"] = "previous" if series.is_previous_period_series else "current"
series_object["labels"] = labels

# Modifications for when breakdowns are active
if self.breakdown_enabled:
Expand Down

0 comments on commit 07f44d8

Please sign in to comment.