Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(exports): export metric insights as wide 2:1 cards instead of squares (#72017)

Sam Penningtonc54d9fa7188a
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 716d124f20a3..91e95fddc3c8 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -2273,9 +2273,9 @@ snapshots:
exporter-other--sql-insight-no-results--light:
hash: v1.k794b7964.61d2bc9e86a0f575ed9653d7a8591219e402a06f6e53021eee8efcc7eb87d644._4TYA0cVTREdm7CEPknXXiutaQB4rZKngjK1MrAGE-Y
exporter-trends--trends-metric-insight--dark:
- hash: v1.k794b7964.5888bc8efe3994a6f6de72dc564dd209797d995747398bbe0f8cf489f4d72df2.WJEQf5G2g5LwsaQVobnxkbS2SiYJxDbaadzeIyamrlY
+ hash: v1.k794b7964.cf3fe4db037b81c1da572706946b49e6c92aa70951bce07ebba3d7d7dd4befb0.3brUeK-WhFsdEAxR7gWVWAsrkVwv3C7Me4MiX7CHHvM
exporter-trends--trends-metric-insight--light:
- hash: v1.k794b7964.12f7c6fa526a6c940fa5138db6ba1066ece183e5feb87f52f8a48d1470c4cd57.VWm4tXCvu-q1PRelHAug4e69-DB9Tt5fpKG_kbwJuS0
+ hash: v1.k794b7964.312a58724b4972bd2eb142ff2591025408edf13663b9c1d1fa77a14c68e7924a.F2Yl15jP_qWWs0Yamx5tPRz8ZLTzbMtn71HB2C0rxjU
exporter-trends--trends-pie-insight--dark:
hash: v1.k794b7964.e5e7c9e36ec62680c87794152b474fcd8ae0061bc7e8145416512ee745e05d21.uVeV9IUiset22yU0BtIEzyXgbkadZEoT1M-mMbalaVw
exporter-trends--trends-pie-insight--light:
diff --git a/frontend/src/exporter/ExportedInsight/ExportedInsight.scss b/frontend/src/exporter/ExportedInsight/ExportedInsight.scss
index cab249130274..99ce8906ad2a 100644
--- a/frontend/src/exporter/ExportedInsight/ExportedInsight.scss
+++ b/frontend/src/exporter/ExportedInsight/ExportedInsight.scss
@@ -32,22 +32,32 @@
border-radius: 0 0 var(--radius) var(--radius);
}
- // A metric card renders best as a square card — header plus chart, proportioned like a dashboard
- // tile on a 2x2 grid — rather than stretched to the full exporter height. The aspect-ratio derives
- // the card's height from the export width, and the content flex-fills the space under the header so
- // the filling sparkline hugs the bottom of the card.
+ // A metric card renders best as a wide 2:1 card — header plus chart, proportioned like a dashboard
+ // tile — rather than stretched to the full exporter height. The aspect-ratio derives the card's
+ // height from the export width, and the content flex-fills the space under the header so the
+ // filling sparkline hugs the bottom of the card.
&--metric {
flex: 0 0 auto;
height: auto;
- aspect-ratio: 1 / 1;
+ aspect-ratio: 2 / 1;
.ExportedInsight__content {
flex: 1 1 0;
// `min-height: 0` overrides the flex-item `auto` floor so the aspect-ratio governs the card's
- // height instead of the content's min-content height stretching it taller than a square.
+ // height instead of the content's min-content height stretching the card taller.
min-height: 0;
}
+
+ // The quill sparkline shifts itself down 6px (`top-[6px]`) so its zero-baseline — drawn 6px
+ // above the canvas bottom, inside the hover-ring margin — rests exactly on the card's bottom
+ // edge. But an ancestor clips at that edge, so the 2px baseline stroke straddles the clip line
+ // and can all but vanish depending on sub-pixel flex heights. Ease the shift by 2px so the
+ // whole stroke stays inside the card, still visually hugging the bottom. A transform (rather
+ // than overriding `top`) sidesteps the `!important` on the tailwind utility.
+ [data-attr='metric-sparkline'] {
+ transform: translateY(-2px);
+ }
}
.LemonTable {
diff --git a/frontend/src/exporter/Exporter.scss b/frontend/src/exporter/Exporter.scss
index 86d6f51ac5b3..213e43319daa 100644
--- a/frontend/src/exporter/Exporter.scss
+++ b/frontend/src/exporter/Exporter.scss
@@ -16,7 +16,7 @@ body.ExporterBody {
max-height: 100vh;
}
- // A metric export is a square card, not a full-page insight — drop the viewport-height floor so the
+ // A metric export is a compact card, not a full-page insight — drop the viewport-height floor so the
// exporter wraps the card tightly instead of padding it out to 100vh.
&--metric {
min-height: 0;
diff --git a/frontend/src/exporter/Exporter.tsx b/frontend/src/exporter/Exporter.tsx
index 87974a40040e..70068274b226 100644
--- a/frontend/src/exporter/Exporter.tsx
+++ b/frontend/src/exporter/Exporter.tsx
@@ -89,7 +89,7 @@ export function Exporter(props: ExportedData): JSX.Element {
const { whitelabel, showInspector = false } = exportOptions
const forcedTheme = useResolvedForcedTheme(exportOptions.theme)
- // A metric insight sizes to a square card rather than filling the viewport, so drop the 100vh floor
+ // A metric insight sizes to a compact card rather than filling the viewport, so drop the 100vh floor
// that would otherwise leave empty space below it (see Exporter.scss and ExportedInsight.scss).
const metric =
insight &&
diff --git a/frontend/src/exporter/stories/ExporterTrends.stories.tsx b/frontend/src/exporter/stories/ExporterTrends.stories.tsx
index bfb5e27dfd37..d3a1fce7d894 100644
--- a/frontend/src/exporter/stories/ExporterTrends.stories.tsx
+++ b/frontend/src/exporter/stories/ExporterTrends.stories.tsx
@@ -144,9 +144,13 @@ export const TrendsNumberInsight: Story = {
}
/** The Metric sparkline is SVG/canvas, so it captures cleanly and guards against the exported card
- * collapsing to a fixed-height sparkline that floats mid-card instead of filling and hugging the bottom. */
+ * collapsing to a fixed-height sparkline that floats mid-card instead of filling and hugging the bottom.
+ * The fixed-width wrapper mirrors the backend's 600px metric export viewport — the test runner's
+ * shrink-to-fit root would otherwise collapse the aspect-ratio card to its text width, leaving the
+ * filling sparkline no height at all. */
export const TrendsMetricInsight: Story = {
args: { insight: __trendsMetric as any },
+ decorators: [(StoryFn): JSX.Element => <div className="w-[600px]">{StoryFn()}</div>],
parameters: {
mockDate: '2022-04-01',
testOptions: {
diff --git a/products/exports/backend/tasks/image_exporter.py b/products/exports/backend/tasks/image_exporter.py
index fa7e51b1b4d2..9150b20109b9 100644
--- a/products/exports/backend/tasks/image_exporter.py
+++ b/products/exports/backend/tasks/image_exporter.py
@@ -195,10 +195,10 @@ def _export_to_png(
funnels_filter = source.get("funnelsFilter") or {}
funnel_layout = funnels_filter.get("layout")
is_left_to_right_funnel = is_funnel and (funnel_layout is None or funnel_layout == FunnelLayout.VERTICAL)
- # A metric renders as a square card whose height derives from the viewport width, so a
- # narrower viewport keeps it at dashboard-tile size instead of an 800px-tall square.
- # Mirrors the frontend's check (InsightVizNode wrapper required), which gates the square
- # metric CSS — a bare TrendsQuery gets neither, so it must keep the default viewport.
+ # A metric renders as a wide 2:1 card whose height derives from the viewport width, so a
+ # narrower viewport keeps it at dashboard-tile size instead of a 400px-tall banner.
+ # Mirrors the frontend's check (InsightVizNode wrapper required), which gates the
+ # metric card CSS — a bare TrendsQuery gets neither, so it must keep the default viewport.
trends_filter = source.get("trendsFilter") or {}
is_metric = (
query.get("kind") == NodeKind.INSIGHT_VIZ_NODE