Skip to content

feat(a2ui): add piechart#2682

Merged
HuJean merged 1 commit into
mainfrom
p/a2ui-pie
May 21, 2026
Merged

feat(a2ui): add piechart#2682
HuJean merged 1 commit into
mainfrom
p/a2ui-pie

Conversation

@HuJean
Copy link
Copy Markdown
Collaborator

@HuJean HuJean commented May 20, 2026

Summary by CodeRabbit

  • New Features
    • Introduced PieChart component supporting pie and donut chart formats
    • Includes optional legend display with values and percentages
    • Configurable title, subtitle, and chart height
    • Built-in color palette with customization support for slice colors

Review Change Stack

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).
  • Changeset added, and when a BREAKING CHANGE occurs, it needs to be clearly marked (or not required).

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 20, 2026

⚠️ No Changeset found

Latest commit: a49d405

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 20, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 085808c9-08e2-4c44-98eb-8a42fc12a6d1

📥 Commits

Reviewing files that changed from the base of the PR and between eb369f1 and a49d405.

📒 Files selected for processing (12)
  • packages/genui/a2ui-playground/lynx-src/a2ui/App.tsx
  • packages/genui/a2ui-playground/src/catalog/a2ui.ts
  • packages/genui/a2ui-playground/src/demos.ts
  • packages/genui/a2ui-playground/src/mock/basic/pie-chart-china-ev-share.json
  • packages/genui/a2ui/package.json
  • packages/genui/a2ui/src/catalog/LineChart/index.tsx
  • packages/genui/a2ui/src/catalog/PieChart/index.tsx
  • packages/genui/a2ui/src/catalog/README.md
  • packages/genui/a2ui/src/catalog/index.ts
  • packages/genui/a2ui/src/catalog/utils/chart.ts
  • packages/genui/a2ui/src/index.ts
  • packages/genui/a2ui/styles/catalog/PieChart.css
✅ Files skipped from review due to trivial changes (2)
  • packages/genui/a2ui/src/catalog/README.md
  • packages/genui/a2ui-playground/src/mock/basic/pie-chart-china-ev-share.json

📝 Walkthrough

Walkthrough

This PR introduces a new PieChart catalog component with reusable chart utilities, refactors existing LineChart to use those utilities, and integrates PieChart into the playground with full documentation and example data.

Changes

PieChart Component and Shared Utilities

Layer / File(s) Summary
Shared chart utilities
packages/genui/a2ui/src/catalog/utils/chart.ts
Defines DEFAULT_CHART_COLORS palette, escapeXml for XML sanitization, and formatValue for number formatting with support for large and small magnitudes.
PieChart component and styling
packages/genui/a2ui/src/catalog/PieChart/index.tsx, packages/genui/a2ui/styles/catalog/PieChart.css
Introduces PieChartSlice and PieChartProps types; implements SVG geometry helpers that compute pie/donut paths with optional padding gaps; renders header, legend with values/percentages, and SVG chart using the shared utilities; stylesheet provides layout and typography rules.
LineChart refactoring
packages/genui/a2ui/src/catalog/LineChart/index.tsx
Updates to import and use shared DEFAULT_CHART_COLORS, escapeXml, and formatValue instead of local implementations; switches all palette and utility references to the shared module.
Package exports and re-exports
packages/genui/a2ui/package.json, packages/genui/a2ui/src/catalog/index.ts, packages/genui/a2ui/src/index.ts
Adds export entries for ./catalog/utils/chart and ./catalog/PieChart subpaths; re-exports PieChart and utility functions from catalog and main entry points for public consumption.
Playground app and catalog
packages/genui/a2ui-playground/lynx-src/a2ui/App.tsx, packages/genui/a2ui-playground/src/catalog/a2ui.ts, packages/genui/a2ui/src/catalog/README.md
Registers PieChart in ALL_BUILTINS; adds component catalog entry with props schema derived from manifest and A2UI usage examples (donut and flat variants); updates integration recipe documentation.
Demo data
packages/genui/a2ui-playground/src/demos.ts, packages/genui/a2ui-playground/src/mock/basic/pie-chart-china-ev-share.json
Registers new demo 'pie-chart-china-ev-share' in EXTENDED_STATIC_DEMOS; provides three-stage mock showing China EV brand share evolution with progressive data snapshots and donut chart visualizations.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

The PR introduces a substantial new component with 300+ lines of SVG rendering logic and geometry computation, plus refactoring of an existing component. However, the changes follow consistent patterns: shared utilities are straightforward helpers, PieChart implementation is self-contained, LineChart updates are mechanical replacements, and integration is standard wiring across consistent layers.


Possibly related PRs

  • lynx-family/lynx-stack#2680: The earlier PR introduced the LineChart component; this PR refactors it to use newly extracted shared chart utilities, creating a direct code-level dependency between the PRs.

Suggested labels

framework:React


Suggested reviewers

  • PupilTong
  • Sherry-hue
  • gaoachao
  • fzx2666-fz

🐰 A pie chart hops in with colors so bright,
SVG arcs rendered with mathematical might,
Shared utilities bloom where LineChart did dine,
Together they chart data in donut design,
A playground adorned with East Asian shine! 🥧✨

🚥 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(a2ui): add piechart' directly and clearly describes the main change: introducing a new PieChart component to the a2ui package, which is the primary focus of all modifications across 11 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch p/a2ui-pie

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.

Copy link
Copy Markdown
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: 2

🧹 Nitpick comments (1)
packages/genui/a2ui/src/catalog/utils/shared.ts (1)

5-29: ⚡ Quick win

Consolidate duplicated chart helpers into one source-of-truth.

shared.ts currently re-implements the same helpers as utils/chart.ts, which can drift over time. Re-export from the canonical file instead.

Proposed simplification
-export const DEFAULT_CHART_COLORS = [
-  '`#0057d9`',
-  '`#0a8f8f`',
-  '`#8a5cf6`',
-  '`#d92d20`',
-  '`#2d6a4f`',
-  '`#b26a00`',
-] as const;
-
-export function escapeXml(value: string): string {
-  return value
-    .replace(/&/g, '&')
-    .replace(/</g, '&lt;')
-    .replace(/>/g, '&gt;')
-    .replace(/"/g, '&quot;')
-    .replace(/'/g, '&apos;');
-}
-
-export function formatValue(value: number): string {
-  if (!Number.isFinite(value)) return '0';
-  const rounded = Math.abs(value) >= 1000
-    ? Math.round(value)
-    : Number(value.toFixed(1));
-  return String(rounded);
-}
+export {
+  DEFAULT_CHART_COLORS,
+  escapeXml,
+  formatValue,
+} from './chart.js';
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/genui/a2ui/src/catalog/utils/shared.ts` around lines 5 - 29, The
three helpers DEFAULT_CHART_COLORS, escapeXml, and formatValue are duplicates of
the canonical implementations in utils/chart.ts; remove their local
implementations from shared.ts and instead re-export them from the canonical
module (import then export DEFAULT_CHART_COLORS, escapeXml, formatValue from
utils/chart.ts) so there is a single source-of-truth and no behavior drift.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/genui/a2ui-playground/src/utils/renderUrl.ts`:
- Around line 35-46: The code currently always appends inline payloads via
url.searchParams.set for messages and actionMocks (using
encodeBase64Url(JSON.stringify(init.messages)) and
encodeBase64Url(JSON.stringify(init.actionMocks))), which makes ?demo=<id> URLs
large; change this so the inline fallback is only added when explicitly allowed
(e.g., when running in dev: process.env.NODE_ENV === 'development' or when a new
flag/param like allowInlineFallback is true) or when no demoId is present—wrap
the two url.searchParams.set blocks in that conditional and leave demoId-based
URLs short and unchanged otherwise.

In `@packages/genui/a2ui/src/catalog/PieChart/index.tsx`:
- Around line 155-159: sliceAngle can be exactly 360 for a single-slice pie
which makes arc start/end coincide and SVG fail; before computing
gapForSlice/startAngle/endAngle or before calling describeSlicePath, detect a
full-circle case (e.g., sliceAngle === 360 or value === total) and clamp
sliceAngle to just under 360 (subtract a tiny epsilon like 1e-6) so startAngle
and endAngle differ slightly; update the logic around sliceAngle, gapForSlice,
startAngle, endAngle and then call describeSlicePath with the adjusted angle to
ensure the arc renders.

---

Nitpick comments:
In `@packages/genui/a2ui/src/catalog/utils/shared.ts`:
- Around line 5-29: The three helpers DEFAULT_CHART_COLORS, escapeXml, and
formatValue are duplicates of the canonical implementations in utils/chart.ts;
remove their local implementations from shared.ts and instead re-export them
from the canonical module (import then export DEFAULT_CHART_COLORS, escapeXml,
formatValue from utils/chart.ts) so there is a single source-of-truth and no
behavior drift.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f20f6037-2096-4366-805d-4bd9d34fa810

📥 Commits

Reviewing files that changed from the base of the PR and between 4222846 and eb369f1.

📒 Files selected for processing (14)
  • packages/genui/a2ui-playground/lynx-src/a2ui/App.tsx
  • packages/genui/a2ui-playground/src/catalog/a2ui.ts
  • packages/genui/a2ui-playground/src/demos.ts
  • packages/genui/a2ui-playground/src/mock/basic/pie-chart-china-ev-share.json
  • packages/genui/a2ui-playground/src/utils/renderUrl.ts
  • packages/genui/a2ui/package.json
  • packages/genui/a2ui/src/catalog/LineChart/index.tsx
  • packages/genui/a2ui/src/catalog/PieChart/index.tsx
  • packages/genui/a2ui/src/catalog/README.md
  • packages/genui/a2ui/src/catalog/index.ts
  • packages/genui/a2ui/src/catalog/utils/chart.ts
  • packages/genui/a2ui/src/catalog/utils/shared.ts
  • packages/genui/a2ui/src/index.ts
  • packages/genui/a2ui/styles/catalog/PieChart.css

Comment thread packages/genui/a2ui-playground/src/utils/renderUrl.ts Outdated
Comment thread packages/genui/a2ui/src/catalog/PieChart/index.tsx
@codecov
Copy link
Copy Markdown

codecov Bot commented May 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 20, 2026

Merging this PR will not alter performance

✅ 81 untouched benchmarks
⏩ 26 skipped benchmarks1


Comparing p/a2ui-pie (a49d405) with main (4222846)

Open in CodSpeed

Footnotes

  1. 26 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@relativeci
Copy link
Copy Markdown

relativeci Bot commented May 20, 2026

React External

#1636 Bundle Size — 698.01KiB (0%).

a49d405(current) vs 4222846 main#1633(baseline)

Bundle metrics  no changes
                 Current
#1636
     Baseline
#1633
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
No change  Cache Invalidation 0% 0%
No change  Chunks 0 0
No change  Assets 3 3
No change  Modules 17 17
No change  Duplicate Modules 5 5
No change  Duplicate Code 8.59% 8.59%
No change  Packages 0 0
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#1636
     Baseline
#1633
No change  Other 698.01KiB 698.01KiB

Bundle analysis reportBranch p/a2ui-pieProject dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci Bot commented May 20, 2026

React MTF Example

#1654 Bundle Size — 208.75KiB (0%).

a49d405(current) vs 4222846 main#1651(baseline)

Bundle metrics  no changes
                 Current
#1654
     Baseline
#1651
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
No change  Cache Invalidation 0% 0%
No change  Chunks 0 0
No change  Assets 3 3
No change  Modules 195 195
No change  Duplicate Modules 77 77
No change  Duplicate Code 44.17% 44.17%
No change  Packages 2 2
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#1654
     Baseline
#1651
No change  IMG 111.23KiB 111.23KiB
No change  Other 97.52KiB 97.52KiB

Bundle analysis reportBranch p/a2ui-pieProject dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci Bot commented May 20, 2026

React Example with Element Template

#790 Bundle Size — 202.16KiB (0%).

a49d405(current) vs 4222846 main#787(baseline)

Bundle metrics  no changes
                 Current
#790
     Baseline
#787
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
No change  Cache Invalidation 0% 0%
No change  Chunks 0 0
No change  Assets 4 4
No change  Modules 100 100
No change  Duplicate Modules 30 30
No change  Duplicate Code 39.22% 39.22%
No change  Packages 2 2
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#790
     Baseline
#787
No change  IMG 145.76KiB 145.76KiB
No change  Other 56.41KiB 56.41KiB

Bundle analysis reportBranch p/a2ui-pieProject dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci Bot commented May 20, 2026

Web Explorer

#10095 Bundle Size — 903.53KiB (0%).

a49d405(current) vs 4222846 main#10092(baseline)

Bundle metrics  Change 2 changes
                 Current
#10095
     Baseline
#10092
No change  Initial JS 45.06KiB 45.06KiB
No change  Initial CSS 2.22KiB 2.22KiB
No change  Cache Invalidation 0% 0%
No change  Chunks 9 9
No change  Assets 11 11
Change  Modules 231(+0.43%) 230
No change  Duplicate Modules 11 11
Change  Duplicate Code 27.12%(-0.04%) 27.13%
No change  Packages 10 10
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#10095
     Baseline
#10092
No change  JS 499.15KiB 499.15KiB
No change  Other 402.16KiB 402.16KiB
No change  CSS 2.22KiB 2.22KiB

Bundle analysis reportBranch p/a2ui-pieProject dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci Bot commented May 20, 2026

React Example

#8521 Bundle Size — 237.81KiB (0%).

a49d405(current) vs 4222846 main#8518(baseline)

Bundle metrics  no changes
                 Current
#8521
     Baseline
#8518
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
No change  Cache Invalidation 0% 0%
No change  Chunks 0 0
No change  Assets 4 4
No change  Modules 200 200
No change  Duplicate Modules 80 80
No change  Duplicate Code 44.68% 44.68%
No change  Packages 2 2
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#8521
     Baseline
#8518
No change  IMG 145.76KiB 145.76KiB
No change  Other 92.05KiB 92.05KiB

Bundle analysis reportBranch p/a2ui-pieProject dashboard


Generated by RelativeCIDocumentationReport issue

@HuJean HuJean enabled auto-merge (squash) May 21, 2026 09:16
@HuJean HuJean merged commit 7e6ff74 into main May 21, 2026
55 checks passed
@HuJean HuJean deleted the p/a2ui-pie branch May 21, 2026 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants