Skip to content

fix: Add dynamic y axis width#4516

Open
Ryrahul wants to merge 2 commits intovendurehq:masterfrom
Ryrahul:fix/Insights-widget-chart-fix
Open

fix: Add dynamic y axis width#4516
Ryrahul wants to merge 2 commits intovendurehq:masterfrom
Ryrahul:fix/Insights-widget-chart-fix

Conversation

@Ryrahul
Copy link
Contributor

@Ryrahul Ryrahul commented Mar 16, 2026

Description

Fixes Y-axis label clipping in the Metrics widget chart. Currency codes like "NPR" (Nepalese Rupee) combined with large formatted values (e.g. "NPR 1,200,000") were getting truncated because the Recharts <YAxis> uses a default width of 60px.

A static margin={{ left: 15 }} on the <AreaChart> I initially tried this , but it does not scale properly. While it helped with shorter labels like "NPR 80000", longer labels such as "NPR 1,200,000" were still clipped.

The fix dynamically computes the <YAxis> width based on the character length of the longest formatted tick label (derived from the maximum data value). This ensures the axis width adapts correctly to any currency code length and value magnitude.

Fixes #4515


Breaking changes

None.


Checklist

  • I have set a clear title
  • My PR is small and contains a single feature
  • I have checked my own PR
  • I have added or updated test cases
  • I have updated the README if needed

@vercel
Copy link

vercel bot commented Mar 16, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
vendure-storybook Ready Ready Preview, Comment Mar 16, 2026 6:35pm

Request Review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 16, 2026

📝 Walkthrough

Walkthrough

The metrics widget chart was updated to compute a dynamic Y-axis width. A useMemo hook calculates yAxisWidth from the maximum value in chartData, formatting it via formatValue and clamping to a minimum of 60. The <YAxis> rendering now uses width={yAxisWidth} while retaining tickFormatter={formatValue}. No exported APIs or function signatures were changed.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix: Add dynamic y axis width' clearly and concisely summarizes the main change—implementing dynamic Y-axis width to resolve label clipping.
Linked Issues check ✅ Passed The code changes implement the fix described in issue #4515 by dynamically computing YAxis width based on formatted label length, directly addressing the root cause of clipped Y-axis labels.
Out of Scope Changes check ✅ Passed All changes are scoped to the specific file and feature: YAxis width calculation, import addition, and layout adjustments. No out-of-scope modifications detected.
Description check ✅ Passed The PR description is comprehensive and follows the template structure with clear sections for description, breaking changes, and checklist. All required information is present and well-documented.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

You can validate your CodeRabbit configuration file in your editor.

If your editor has YAML language server, you can enable auto-completion and validation by adding # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json at the top of your CodeRabbit configuration file.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@packages/dashboard/src/lib/framework/dashboard-widget/metrics-widget/chart.tsx`:
- Around line 16-20: yAxisWidth computation can produce NaN because formatValue
may return a number (for DATA_TYPES.OrderCount) and .length on a number is
undefined; update the logic in the yAxisWidth useMemo (which references
chartData and formatValue) to coerce the formatted result to a string before
measuring length (e.g., use String(formatted) or conditional typeof check) so
Math.max(60, formattedString.length * 7) always receives a numeric argument and
cannot become NaN.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c26df301-fe3a-46ec-9e15-ff5d54415ff4

📥 Commits

Reviewing files that changed from the base of the PR and between ff485a6 and a33b65d.

📒 Files selected for processing (1)
  • packages/dashboard/src/lib/framework/dashboard-widget/metrics-widget/chart.tsx

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/dashboard/src/lib/framework/dashboard-widget/metrics-widget/chart.tsx (1)

16-20: Add a small safety padding to the width estimate.

Line 19 uses a strict length * 7 estimate; this can still clip in edge cases. Add a fixed pixel buffer (e.g., +10–12px) to make the sizing more robust.

Suggested tweak
 const yAxisWidth = useMemo(() => {
     const maxValue = Math.max(0, ...chartData.map(d => d.sales));
     const formatted = String(formatValue(maxValue));
-    return Math.max(60, formatted.length * 7);
+    return Math.max(60, formatted.length * 7 + 12);
 }, [chartData, formatValue]);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@packages/dashboard/src/lib/framework/dashboard-widget/metrics-widget/chart.tsx`
around lines 16 - 20, The yAxis width calc in yAxisWidth currently uses
formatted.length * 7 which can under-estimate; update the calculation in the
useMemo for yAxisWidth to add a small fixed pixel buffer (e.g., +10 or +12) to
the computed width and keep the Math.max(60, ...) guard; refer to the yAxisWidth
variable and the formatValue/chartData usage so you change the return expression
to include the extra padding.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@packages/dashboard/src/lib/framework/dashboard-widget/metrics-widget/chart.tsx`:
- Around line 16-20: The yAxis width calc in yAxisWidth currently uses
formatted.length * 7 which can under-estimate; update the calculation in the
useMemo for yAxisWidth to add a small fixed pixel buffer (e.g., +10 or +12) to
the computed width and keep the Math.max(60, ...) guard; refer to the yAxisWidth
variable and the formatValue/chartData usage so you change the return expression
to include the extra padding.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 283d612a-1557-47c6-9938-37feec266cfc

📥 Commits

Reviewing files that changed from the base of the PR and between a33b65d and d56748e.

📒 Files selected for processing (1)
  • packages/dashboard/src/lib/framework/dashboard-widget/metrics-widget/chart.tsx

@BibiSebi BibiSebi self-requested a review March 20, 2026 16:22
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.

Bug: Y-axis Labels Clipped in Metrics Widget (Insights Dashboard)

1 participant