Skip to content

OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.

fix(dashboard): chart lines keep the latest values legible and cards show full numbers (#555)

Carl-Gerhard Lindesvärd331b0691db41
diff --git a/apps/start/src/components/charts/fade-edges.ts b/apps/start/src/components/charts/fade-edges.ts
index b78f32b26..db9206c00 100644
--- a/apps/start/src/components/charts/fade-edges.ts
+++ b/apps/start/src/components/charts/fade-edges.ts
@@ -1,8 +1,8 @@
/**
* Which side(s) of a series should fade to transparent at the chart edges.
- * - `true` → fade both edges (default for `<Line>`)
+ * - `true` → fade both edges
* - `false` → no fade (default for `<Area>`)
- * - `"left"` / `"right"` → fade only that side
+ * - `"left"` / `"right"` → fade only that side (`"left"` is the default for `<Line>`)
*/
export type FadeEdges = boolean | 'left' | 'right';
diff --git a/apps/start/src/components/charts/line.tsx b/apps/start/src/components/charts/line.tsx
index 7559b5767..7f6ae5d42 100644
--- a/apps/start/src/components/charts/line.tsx
+++ b/apps/start/src/components/charts/line.tsx
@@ -58,7 +58,7 @@ export interface LineProps {
* Fade the line stroke toward transparent at the chart edges.
* - `true` fades both edges, `false` disables the fade entirely.
* - `"left"` / `"right"` fades only that side.
- * Default: true
+ * Default: `"left"` — the right edge is usually "now" and must stay legible.
*/
fadeEdges?: FadeEdges;
/** Whether to show highlight segment on hover. Default: true */
@@ -213,7 +213,7 @@ export function Line({
strokeWidth = 2.5,
curve = curveNatural,
animate = true,
- fadeEdges = true,
+ fadeEdges = 'left',
showHighlight = true,
showMarkers = false,
markers,
diff --git a/apps/start/src/components/overview/overview-metric-card.tsx b/apps/start/src/components/overview/overview-metric-card.tsx
index 9f6693eb7..5d3c222f9 100644
--- a/apps/start/src/components/overview/overview-metric-card.tsx
+++ b/apps/start/src/components/overview/overview-metric-card.tsx
@@ -20,6 +20,8 @@ const METRIC_ERROR_LABEL = 'Could not load';
// A tall card's bars get the report bars' rounding; the 40px sparkline's thin bars only a hint of it.
const BAR_RADIUS = 4;
const SPARKLINE_BAR_RADIUS = 1;
+// Below this a count fits the card in full ("25,412"); above it we compact to "12M".
+const FULL_NUMBER_LIMIT = 10_000_000;
export type MetricUnit = '' | 'date' | 'timeAgo' | 'min' | '%' | 'currency';
@@ -203,9 +205,12 @@ function MetricValue({ value, unit }: { value: number; unit?: MetricUnit }) {
}
if (unit === 'currency') {
+ const amount = value / 100;
return (
<span className={VALUE_CLASS}>
- {number.currency(value / 100, { short: true })}
+ {number.currency(amount, {
+ short: Math.abs(amount) >= FULL_NUMBER_LIMIT,
+ })}
</span>
);
}
@@ -221,5 +226,10 @@ function MetricValue({ value, unit }: { value: number; unit?: MetricUnit }) {
);
}
- return <span className={VALUE_CLASS}>{number.short(value)}</span>;
+ const fitsInFull = Math.abs(value) < FULL_NUMBER_LIMIT;
+ return (
+ <span className={VALUE_CLASS}>
+ {fitsInFull ? number.format(value) : number.short(value)}
+ </span>
+ );
}
diff --git a/apps/start/src/components/overview/overview-metrics.tsx b/apps/start/src/components/overview/overview-metrics.tsx
index 5ba2ed5d3..61a74fff8 100644
--- a/apps/start/src/components/overview/overview-metrics.tsx
+++ b/apps/start/src/components/overview/overview-metrics.tsx
@@ -369,7 +369,6 @@ function Chart({
<Line
curve={curveMonotoneX}
dataKey={`prev_${activeMetric.key}`}
- fadeEdges
key={`prev-${activeMetric.key}`}
stroke={PREV_LINE_COLOR}
strokeWidth={2}
@@ -379,7 +378,6 @@ function Chart({
<Line
curve={curveMonotoneX}
dataKey="revenue_norm"
- fadeEdges
stroke={REVENUE_COLOR}
strokeWidth={1.5}
/>