feat(graphic): optional template-based graphic slot API#969
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c24da8374b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
This PR adds an opt-in template-based #graphic slot API for Vue ECharts by introducing a vue-echarts/graphic subpath entry that registers a graphic extension and exports G* declarative components, plus comprehensive tests/demo/docs updates.
Changes:
- Add a global VChart extension registry and integrate extension patch/render hooks into
ECharts. - Introduce
vue-echarts/graphicentry with collector/build/mount logic andG*components for declarativeoption.graphic. - Add extensive test coverage, a new demo example, and README documentation for the new slot API.
Reviewed changes
Copilot reviewed 40 out of 40 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| tsdown.config.ts | Build config updated to emit a new graphic entry bundle. |
| package.json | Adds ./graphic export mapping for JS + types output. |
| src/extensions.ts | Introduces global extension registry + slot-type augmentation interface. |
| src/composables/slot.ts | Extends slot typing via VChartExtensionSlots and skips graphic in callback-slot processing. |
| src/ECharts.ts | Wires extension patch/render into core lifecycle; adds #graphic missing-entry warning and theme+graphic reapply behavior. |
| src/graphic/index.ts | New opt-in entry that registers the graphic extension and exports G* components. |
| src/graphic/extension.ts | New runtime extension bridging slot collection → option.graphic building → incremental event binding + update requests. |
| src/graphic/mount.ts | New mount component to collect vnode order and host the slot render tree off-DOM via Teleport. |
| src/graphic/collector.ts | New collector with pass-based registration/unregistration, coalesced flush, fingerprinting, and warn-once support. |
| src/graphic/build.ts | Builds stable ECharts graphic.elements from collected nodes and order. |
| src/graphic/build-helpers.ts | Helpers for style/shape/info construction and prop pruning by type. |
| src/graphic/components.ts | Declares G* components using the component factory. |
| src/graphic/component-factory.ts | Factory to register nodes into collector, extract handlers, provide group parenting, and warn on misuse. |
| src/graphic/context.ts | Injection keys for collector, parent id, and order map. |
| src/graphic/constants.ts | Shared prop/style/shape key lists and per-type shape keys. |
| src/graphic/marker.ts | Adds a symbol marker to identify graphic components reliably. |
| src/graphic/props-common.ts | Defines common prop surface for G* components. |
| src/graphic/props-shape.ts | Defines shape-related props for G* components. |
| src/graphic/slots.ts | Module augmentation to add optional graphic slot typing when entry is imported. |
| src/graphic/warn.ts | Centralizes warning codes and messages for the graphic feature. |
| tests/helpers/dom.ts | Adds async warn-capture helper for browser tests. |
| tests/helpers/graphic-slot.ts | Adds shared helpers for graphic slot test suites. |
| tests/echarts.browser.test.ts | Adds regression test for theme updates when chart ref is missing. |
| tests/graphic.node.test.ts | Adds node-only tests for build/collector behavior and edge cases. |
| tests/graphic-mount.node.test.ts | Adds SSR/node tests for mount behavior. |
| tests/graphic-extension.node.test.ts | Adds node tests for extension dedupe, binding sync, warnings, and side-effect registration. |
| tests/graphic-components.browser.test.ts | Adds browser tests for G* registration/unregistration, parent propagation, and warnings. |
| tests/graphic-slot-order.browser.test.ts | Adds browser tests for order stability across v-if/v-for and tree changes. |
| tests/graphic-slot-events.browser.test.ts | Adds browser tests for chart event binding and reactive handler updates. |
| tests/graphic-slot-manual.browser.test.ts | Adds browser tests for manual-update semantics with graphic slot. |
| tests/graphic-slot-edge.browser.test.ts | Adds browser tests for integration/edge behavior (missing entry, override, theme reapply, clear, batching, no-op). |
| tests/graphic-behavior.browser.test.ts | Adds real-echarts integration tests covering merge/remove behaviors. |
| demo/examples/GraphicOverlay.vue | New demo showcasing the declarative graphic overlay usage. |
| demo/Demo.vue | Registers and renders the new GraphicOverlay demo page. |
| demo/examples/graphic-overlay/types.ts | Demo-specific types for layout and tokens. |
| demo/examples/graphic-overlay/useGraphicOverlayData.ts | Demo data + interactions for overlay. |
| demo/examples/graphic-overlay/useGraphicOverlayLayout.ts | Demo layout algorithm for overlay positioning. |
| demo/examples/graphic-overlay/GraphicOverlayTokens.ts | Demo theme token resolution for light/dark. |
| README.md | Documents optional #graphic slot entry and usage in English. |
| README.zh-Hans.md | Documents optional #graphic slot entry and usage in Chinese. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #969 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 9 25 +16
Lines 331 853 +522
Branches 39 204 +165
==========================================
+ Hits 331 853 +522 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
commit: |
Background
Native ECharts
option.graphicis powerful but painful in Vue-heavy projects:v-if/v-for/ reactive bindings is awkward.This PR introduces an opt-in, template-based graphic API while preserving existing
VChartbehavior and compatibility.Design Overview
1) Optional entry, no default bundle inflation
vue-echarts/graphic#graphicsupport is enabled only after explicit import (import "vue-echarts/graphic"orG*component imports).vue-echartsstays lean.2) Explicit semantics with stable behavior
#graphicandoption.graphicare mutually exclusive in practice.manual-updatesemantics are preserved:chartRef.setOption(...).3) Clean internal boundaries with pragmatic coupling
src/graphic/*:Public API
Enable graphic slot support
#graphicslotG*componentsThe entry exports declarative components for common graphic primitives (e.g.
GGroup,GRect,GCircle,GText,GLine,GPolyline,GPolygon,GImage,GSector,GRing,GArc,GBezierCurve,GCompoundPath).Type behavior
graphic) is also opt-in and only active after importingvue-echarts/graphic.Changes to existing modules
Core / Runtime
src/extensions.tssrc/ECharts.ts#graphicslot.src/composables/slot.tsNew graphic runtime modules
src/graphic/extension.tssrc/graphic/collector.tssrc/graphic/build.ts+src/graphic/build-helpers.tssrc/graphic/mount.ts#graphicvnode trees.src/graphic/components.ts+component-factory.ts+ props/marker/context/warn helpersG*components.Demo
demo/examples/GraphicOverlay.vuedemo/examples/graphic-overlay/*Tests
Docs
README.mdandREADME.zh-Hans.mdwith:#graphicsemantics and caveatsCompatibility
vue-echarts/graphicare unaffected.Verification
Executed on this branch:
pnpm lintpnpm typecheckpnpm testpnpm test:coverage(100/100/100/100)pnpm build