-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fix(insights): When exporting to PNG respect the show_legend display option #41836
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
Conversation
|
Size Change: +65 B (0%) Total Size: 3.43 MB ℹ️ View Unchanged
|
| show_legend = exported_asset.export_context.get("show_legend", False) | ||
|
|
||
| legend_param = "&legend=true" if show_legend else "" | ||
| url_to_render = absolute_uri(f"/exporter?token={access_token}{legend_param}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The legend parameter originated from this commit: 16e62f1#diff-588e33fbae1f1b86bfbd786002306364c5c240840ac3f148e7ed7634c34efbbdR80.
Due to it not having a true / false value and it just being a name, Python will interpret it as a falsy value (in fact, I think most backend languages do this) and therefore the legend won't be shown.
We have another check here:
posthog/frontend/src/exporter/ExportedInsight/ExportedInsight.tsx
Lines 36 to 45 in 5992ae8
| if ( | |
| isInsightVizNode(insight.query) && | |
| isTrendsQuery(insight.query.source) && | |
| insight.query.source.trendsFilter && | |
| insight.query.source.trendsFilter.showLegend == true | |
| ) { | |
| // legend is always shown so don't show it alongside the insight | |
| insight.query.source.trendsFilter.showLegend = false | |
| } |
…in line with the rest
…ync-legend-in-png-export
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4 files reviewed, no comments
Problem
During my recent clickthrough spree of our application, we noticed that the
export > pngfunction does not include the legends (even if they have been enabled through the display option) for insights.Whilst I was working on the TF export for our hackathon at the offsite, I was going through our
exporterlogic and discovered the issue with the PNG exports not having the legends set. In order to catch 2 birds with one stone, I figured I would update that as well.Changes
show legenddisplay option to the backend through theexport_context(similar to how we do this for some other models, example for heatmaps).exportendpoint through aGETparameter.How did you test this code?
pngexport and confirm that there is no legend in the exportShow Legendto truepngexport and confirm that this time, there is a legend on the export👉 Stay up-to-date with PostHog coding conventions for a smoother review.
Without the legend being set
With the legend being set
(this already worked on master, but it's here for completeness sake)
Changelog: (features only) Is this feature complete?