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: Added option to display multiple Y-axes for Trends related line charts #28316

Merged
merged 4 commits into from
Feb 5, 2025

Conversation

Sriram-bk
Copy link
Contributor

@Sriram-bk Sriram-bk commented Feb 5, 2025

Problem

Currently a trend insight with two or more series is unreadable/not useful if one series contains significantly more events than the others.

This PR adds an option to assign a second (or multiple) Y-axis, so the trends of two or more series can be easily compared even if the volume of events is very different.

Closes #17898

Changes

Before

Screenshot 2025-02-04 at 10 24 46 PM

After

Screenshot 2025-02-04 at 10 25 38 PM

Options Selector

Screenshot 2025-02-04 at 10 26 19 PM

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

Does this work well for both Cloud and self-hosted?

How did you test this code?

Tested locally.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

Based on the provided files, I'll summarize the key changes for adding multiple Y-axes support to line graphs:

This PR adds the ability to display multiple Y-axes in trend line graphs, making it easier to compare series with significantly different scales. Here are the key changes:

  • Added new showMultipleYAxes boolean option in the trends filter schema with corresponding UI toggle in the Options menu
  • Implemented Y-axis generation logic in LineGraph.tsx that alternates between left/right positioning for multiple axes
  • Modified dataset processing to assign different Y-axis IDs to each series when multiple axes are enabled
  • Added support for maintaining individual axis scales, formatting, and goal lines across multiple Y-axes
  • Ensured compatibility with existing features like logarithmic scales and annotations while adding the new Y-axes functionality

The implementation provides a clean solution to the issue of comparing trends with vastly different event volumes by allowing each series to have its own appropriately scaled axis.

💡 (2/5) Greptile learns from your feedback when you react with 👍/👎!

15 file(s) reviewed, 6 comment(s)
Edit PR Review Bot Settings | Greptile

@@ -93,6 +93,7 @@ describe('queryNodeToFilter', () => {
showLabelsOnSeries: true,
showPercentStackView: true,
yAxisScaleType: 'log10',
showMultipleYAxes: false,
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: showMultipleYAxes is set in the input query but missing from the expected output filters (lines 107-131). This will cause the feature to fail silently.

@@ -57,6 +58,7 @@ export function InsightDisplayConfig(): JSX.Element {
supportsPercentStackView,
supportsResultCustomizationBy,
yAxisScaleType,
showMultipleYAxes,
Copy link
Contributor

Choose a reason for hiding this comment

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

style: showMultipleYAxes is destructured but not used in any conditional rendering logic beyond the options count. Consider if this should affect other display behaviors.

Comment on lines +9 to +10
const { showMultipleYAxes } = useValues(insightVizDataLogic(insightProps))
const { updateInsightFilter } = useActions(insightVizDataLogic(insightProps))
Copy link
Contributor

Choose a reason for hiding this comment

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

style: insightVizDataLogic is instantiated twice - consider storing the result in a variable to avoid potential duplicate instantiations

Suggested change
const { showMultipleYAxes } = useValues(insightVizDataLogic(insightProps))
const { updateInsightFilter } = useActions(insightVizDataLogic(insightProps))
const logic = insightVizDataLogic(insightProps)
const { showMultipleYAxes } = useValues(logic)
const { updateInsightFilter } = useActions(logic)

frontend/src/scenes/insights/views/LineGraph/LineGraph.tsx Outdated Show resolved Hide resolved
frontend/src/scenes/insights/views/LineGraph/LineGraph.tsx Outdated Show resolved Hide resolved
@Sriram-bk Sriram-bk changed the title Added option to display multiple Y-axes for Trends related line charts feat: Added option to display multiple Y-axes for Trends related line charts Feb 5, 2025
Copy link
Contributor

github-actions bot commented Feb 5, 2025

Size Change: +5 B (0%)

Total Size: 1.17 MB

ℹ️ View Unchanged
Filename Size Change
frontend/dist/toolbar.js 1.17 MB +5 B (0%)

compressed-size-action

@Sriram-bk Sriram-bk requested a review from a team February 5, 2025 08:55
Copy link
Contributor

@anirudhpillai anirudhpillai left a comment

Choose a reason for hiding this comment

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

This is such a useful (and long overdue) change, great work getting this out so quickly! Works so smoothly 🎉

  • Just from a UX perspective, maybe we disable grid lines when this is enabled as inconsistent grid line spacing is hard to comprehend?
image
  • Also should we limit to just 2 axes? (not a blocker) When there's more than 2 series, it adds multiple axes and with the grid lines it becomes hard to read the graph. Not sure if there's a better way to stack axes.
image

@Sriram-bk
Copy link
Contributor Author

@anirudhpillai Thanks for the call out on the grid lines! Updated to hide grid lines if we're displaying multiple Y-axes.

To your point about limiting to 2, I think we should leave this as is. I do agree that it get's really confusing, but I'd like to default to being more flexible. If we find that users are using this with more than 2 series, then we can also rely on their feedback to come up with a better way to stack and represent those use cases.

@Sriram-bk Sriram-bk force-pushed the sri/add-option-for-multiple-y-axes-to-line-graphs branch from 047b04f to 0a81744 Compare February 5, 2025 18:01
Copy link
Contributor

@aspicer aspicer left a comment

Choose a reason for hiding this comment

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

After talking to Sri in person, the plan is to ship this as is, which provides useful functionality to people who want to graph two graphs, or graph more than 2 graphs and care more about relative movements than absolute numbers.

We will then look into improving it as necessary based on people's requirements (grouping graphs, for example)

@Sriram-bk Sriram-bk merged commit e405fb1 into master Feb 5, 2025
103 checks passed
@Sriram-bk Sriram-bk deleted the sri/add-option-for-multiple-y-axes-to-line-graphs branch February 5, 2025 22:04
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.

Feature Request: Optional second Y-axis
3 participants