Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion frontend/src/queries/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { OnlineExportContext, QueryExportContext } from '~/types'

import {
HogQLQueryString,
getShowLegend,
isAsyncResponse,
isDataTableNode,
isDataVisualizationNode,
Expand All @@ -39,7 +40,13 @@ export function queryExportContext<N extends DataNode>(
if (isDataTableNode(query) || isDataVisualizationNode(query)) {
return queryExportContext(query.source, methodOptions, refresh)
} else if (isInsightQueryNode(query)) {
return { source: query }
let showLegend = getShowLegend(query)

return {
source: query,
// Include show_legend for PNG exports
show_legend: showLegend === true,
}
} else if (isPersonsNode(query)) {
return { path: getPersonsEndpoint(query) }
}
Expand Down
1 change: 1 addition & 0 deletions frontend/src/scenes/insights/InsightPageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ export function InsightPageHeader({ insightLogicProps }: { insightLogicProps: In
{
format: ExporterFormat.PNG,
insight: insight.id,
context: exportContext,
dataAttr: `${RESOURCE_TYPE}-export-png`,
},
{
Expand Down
1 change: 1 addition & 0 deletions frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4487,6 +4487,7 @@ export type OnlineExportContext = {
export type QueryExportContext = {
source: Record<string, any>
filename?: string
show_legend?: boolean
}

export interface ReplayExportContext {
Expand Down
7 changes: 6 additions & 1 deletion posthog/tasks/exports/image_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,12 @@ def _export_to_png(exported_asset: ExportedAsset, max_height_pixels: Optional[in
wait_for_css_selector: CSSSelector
screenshot_height: int = 600
if exported_asset.insight is not None:
url_to_render = absolute_uri(f"/exporter?token={access_token}&legend")
show_legend = False
if exported_asset.export_context:
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.

wait_for_css_selector = ".ExportedInsight"
screenshot_width = 800
elif exported_asset.dashboard is not None:
Expand Down
Loading