Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(insights): add % of total option to line, bar and area trend insights (fixes #13728, #11276) #16699

Merged
merged 21 commits into from
Jul 31, 2023

Conversation

Arun-chaitanya
Copy link
Contributor

@Arun-chaitanya Arun-chaitanya commented Jul 20, 2023

Problem

Allow 100% stacked area/bar chart (#13728)

Changes

Without Percent Stack View
Screenshot 2023-07-20 at 11 04 12 PM
With Percent Stack View
Screenshot 2023-07-20 at 11 04 20 PM

Bugs Noticed - Update (FIXED)
I can right away see one bug that if I switch on "Show value on series" at first it is showing percentages as values, but when I hover it is showing their original value.

Screen.Recording.2023-07-20.at.11.06.09.PM.mov

I am working on it. @pauldambra

👉 Stay up-to-date with PostHog coding conventions for a smoother review.

How did you test this code?

@Arun-chaitanya Arun-chaitanya changed the title [DRAFT] - Allow 100% stacked area/bar chart #13728 fix - [DRAFT] - Allow 100% stacked area/bar chart #13728 Jul 20, 2023
@Arun-chaitanya Arun-chaitanya changed the title fix - [DRAFT] - Allow 100% stacked area/bar chart #13728 fix(insights): [DRAFT] - Allow 100% stacked area/bar chart #13728 Jul 20, 2023
Copy link
Member

@pauldambra pauldambra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good so far to me...

@thmsobrmlr is way more familiar than me with insights these days 🥇 tagging him for visibility

@thmsobrmlr
Copy link
Contributor

Don't have time for a full review at the moment, but here are some fly-by comments:

  • Does the plugin work for other chart types as well? We've had customer requests for a line / area charts as well e.g. Feature Request - % of total Area chart #11276. I'd like to move forward with a solution that can work for these cases as well.
  • What do we think about naming? At the moment we have a mix of "percent stack view" and "100% stacked". Maybe something along the lines of "percentage of total"?
  • More a nit, but the axis is missing the percentage sign (we have an axis display option that would format the axis accordingly).

@Arun-chaitanya
Copy link
Contributor Author

@thmsobrmlr point 1 and 3 can be easily achievable. I will make the required changes and let you know. For point 2, you can suggest me the label name :)

@Arun-chaitanya
Copy link
Contributor Author

Hi @thmsobrmlr , I have done points 1 and 3 as suggested by you and added the percentStack option view for the area and line graph as well.

@Twixes Twixes requested a review from thmsobrmlr July 24, 2023 17:00
@pauldambra
Copy link
Member

I've not made time to run it yet but from a pass over the code this is looking really good @Arun-chaitanya 🙌

@Arun-chaitanya Arun-chaitanya changed the title fix(insights): [DRAFT] - Allow 100% stacked area/bar chart #13728 fix(insights): Allow 100% stacked area/bar chart #13728 Jul 26, 2023
Copy link
Contributor

@thmsobrmlr thmsobrmlr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had a more in-depth look and unfortunately I have quite a bunch of follow up comments code wise and I think I also found two bugs:

  1. When you go to e.g. a funnels insight, then go back to the the trends insight, the option for the percent stack isn't displayed initially and you need to reload the page to see the option

    2023-07-26 15 59 13

  2. For an insight with a breakdown it doesn't seem to aggregate the values correctly

    Screenshot 2023-07-26 at 15 59 51

Hope my comments are clear & you aren't discouraged by them. Let me know if you need clarification or assistance with anything.

frontend/src/lib/constants.tsx Show resolved Hide resolved
@@ -106,6 +106,22 @@ export const getShowValueOnSeries = (query: InsightQueryNode): boolean | undefin
}
}

export const getShowPercentStackView = (query: InsightQueryNode): boolean | undefined => {
if (PERCENT_STACK_VIEW_DISPLAY_TYPE.includes(getDisplay(query) as ChartDisplayType)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to split this function up into two parts:

  • one part that should stay in this function related to getting the show_percent_stack_view from the respective insight filter (this is what other functions in this file do as well)
  • the other part where we override the value with undefined for chart display types that don't support the percent stack view. this should go in a kea selector with display and showPercentStackView as input and the same output

I think there is also a bug since this only considers the case where the query has a display set, but not the default display.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also only trends insights support the percent stack view (see below how you implemented formatYAxisLabel)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved: Also only trends insights support the percent stack view (see below how you implemented formatYAxisLabel)
Resolved: I think there is also a bug since this only considers the case where the query has a display set, but not the default display.

About the above two points, I understood the first point, the second point was not that clear to me.

frontend/src/types.ts Outdated Show resolved Hide resolved
frontend/src/types.ts Outdated Show resolved Hide resolved
frontend/src/scenes/insights/views/LineGraph/LineGraph.tsx Outdated Show resolved Hide resolved
frontend/src/scenes/insights/aggregationAxisFormat.ts Outdated Show resolved Hide resolved
@Arun-chaitanya Arun-chaitanya force-pushed the master branch 2 times, most recently from 7471be0 to d60f811 Compare July 26, 2023 16:15
@Arun-chaitanya
Copy link
Contributor Author

@thmsobrmlr I have resolved most of the comments. And 1st of the 2 bugs is solved. I am not able to reproduce the 2nd bug as I don't have much data in my test env. Is there any way I can reproduce it? Also, can you comment on the above 1 doubt?

@Arun-chaitanya
Copy link
Contributor Author

Arun-chaitanya commented Jul 27, 2023

@thmsobrmlr I was also able to solve the second bug also. Pheew! Now I just have one doubt about your comment, but If I am right I am managing that thing by passing checked={!!showPercentStackView} to Checkbox, so I need not manage undefined case specially. But you can give the correct opinion.

@thmsobrmlr thmsobrmlr changed the title fix(insights): Allow 100% stacked area/bar chart #13728 fix(insights): Allow 100% stacked area/bar chart (fixes #13728, #11276) Jul 28, 2023
@thmsobrmlr thmsobrmlr changed the title fix(insights): Allow 100% stacked area/bar chart (fixes #13728, #11276) feat(insights): add % of total option to line, bar and area trend insights (fixes #13728, #11276) Jul 28, 2023
@thmsobrmlr thmsobrmlr self-requested a review July 29, 2023 14:54
Copy link
Contributor

@thmsobrmlr thmsobrmlr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you again for the PR @Arun-chaitanya, everything is looking good now & it's great to finally get this feature in. I'll merge the PR on Monday.

@thmsobrmlr thmsobrmlr merged commit 34f7a9d into PostHog:master Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants