Skip to content

Conversation

@vdekrijger
Copy link
Contributor

@vdekrijger vdekrijger commented Nov 20, 2025

Problem

During my recent clickthrough spree of our application, we noticed that the export > png function 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 exporter logic 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

  1. We pass the show legend display option to the backend through the export_context (similar to how we do this for some other models, example for heatmaps).
  2. The backend then fetches this field (if present) whilst building the details for the insight exports and passes it on to the export endpoint through a GET parameter.

How did you test this code?

  1. Run the Posthog application locally
  2. Create an insight (ensuring there is no legend)
  3. Run the png export and confirm that there is no legend in the export
  4. Adjust the display options, setting the Show Legend to true
  5. Run the png export and confirm that this time, there is a legend on the export
  6. Also ran an export of the dashboards to confirm it's all okay
  7. And finally ran an export of the shared page for an insight with / without the show legend option enabled.

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

Without the legend being set

Screenshot 2025-11-20 at 17 11 36 export-weekly-signups-png-no-legend-fix export-this-dashboard-contains-helpful-insights-for-our-product-at-a-glance(1) Screenshot 2025-11-21 at 10 02 04

With the legend being set

Screenshot 2025-11-20 at 17 12 51 export-weekly-signups-png-with-legend-fix export-this-dashboard-contains-helpful-insights-for-our-product-at-a-glance(2)

(this already worked on master, but it's here for completeness sake)

Screenshot 2025-11-21 at 10 01 43

Changelog: (features only) Is this feature complete?

@github-actions
Copy link
Contributor

github-actions bot commented Nov 20, 2025

Size Change: +65 B (0%)

Total Size: 3.43 MB

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

compressed-size-action

@vdekrijger vdekrijger changed the title chore: When exporting to PNG respect the show_legend display option fix: When exporting to PNG respect the show_legend display option Nov 21, 2025
@vdekrijger vdekrijger changed the title fix: When exporting to PNG respect the show_legend display option fix(insights): When exporting to PNG respect the show_legend display option Nov 21, 2025
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}")
Copy link
Contributor Author

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:

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
}
however that check appears to be responsible for whether or not to show the legend on the sidebar, thus having it being disabled there is a good thing to avoid either 2 legends showing up.

@vdekrijger vdekrijger marked this pull request as ready for review November 21, 2025 09:04
@posthog-bot posthog-bot requested a review from a team November 21, 2025 09:05
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.

4 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@vdekrijger vdekrijger merged commit 8852c18 into master Nov 21, 2025
199 checks passed
@vdekrijger vdekrijger deleted the vdekrijger-sync-legend-in-png-export branch November 21, 2025 11:52
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