Skip to content

feat(echarts): add updateDate method for efficient data updates - #7129

Merged
jinmao88 merged 1 commit into
vbenjs:mainfrom
abcd0f:dev/sun-local
Jan 23, 2026
Merged

jinmao88 merged 1 commit into
vbenjs:mainfrom
abcd0f:dev/sun-local

Conversation

@abcd0f

@abcd0f abcd0f commented Jan 23, 2026 •

Copy link
Copy Markdown
Contributor

feat: Add updateDate method for efficient ECharts data updates

📝 Description

Add a new updateDate method to the useEcharts composable for updating chart data without full re-rendering, improving performance for dynamic data updates.

🎯 Motivation

Previously, updating chart data required calling renderEcharts with clear=true, which would:

  • Clear the entire chart instance
  • Re-render all components
  • Reset animations and transitions
  • Cause unnecessary performance overhead

The new updateDate method provides a more efficient way to update chart data while preserving animations and chart state.

✨ Changes

Added Method

const updateDate = (
  option: EChartsOption,
  notMerge = false,
  lazyUpdate = false,
): Promise<echarts.ECharts | null>

Parameters:

  • option: ECharts configuration to update
  • notMerge:
    • false (default): Merge with existing configuration, preserving animations
    • true: Completely replace configuration
  • lazyUpdate:
    • false (default): Update immediately
    • true: Defer redraw, useful for multiple rapid updates

Key Features

  • Automatic initialization: If chart instance doesn't exist, falls back to renderEcharts
  • Configuration merging: Automatically merges with global options (e.g., backgroundColor)
  • Promise-based: Returns chart instance for chaining operations
  • Performance optimized: Uses setOption directly without clearing the chart

📖 Usage Examples

Basic Update (Merge Mode)

const { renderEcharts, updateDate } = useEcharts(chartRef);

// Initial render
await renderEcharts(initialOptions);

// Update only series data (merged with existing config)
await updateDate({
series: [{
data: [10, 20, 30, 40, 50]
}]
});

Complete Replacement

// Replace entire configuration
await updateDate(newCompleteOptions, true);

Batch Updates (Lazy Mode)

// Multiple rapid updates - only redraw once at the end
await updateDate({ series: [{ data: data1 }] }, false, true);
await updateDate({ xAxis: { data: labels } }, false, true);
// Final update triggers redraw
await updateDate({ title: { text: 'Updated' } }, false, false);

Real-time Data Updates

// Live dashboard example
setInterval(async () => {
  const newData = await fetchLatestData();
  await updateDate({
    series: [{ data: newData }]
  });
}, 1000);

🔄 Comparison with renderEcharts

Method Use Case Performance Animation State
renderEcharts Initial render, theme change Lower Reset Cleared
updateDate Data updates Higher Preserved Maintained

📦 Export Changes

Updated exports from useEcharts:

return {
  renderEcharts,
  updateDate,      // ← New method
  resize,
  getChartInstance: () => chartInstance,
};

🎨 Future Enhancements (Optional)

The method signature includes a commented silent option:

// silent: true,  // Disable all events for maximum performance

Summary by CodeRabbit

  • New Features
    • Added a new method for dynamically updating chart options with support for merge behavior and lazy update configurations. Accepts chart configuration and returns a Promise that resolves to the chart instance or null. Automatically handles chart initialization when required.

✏️ Tip: You can customize this high-level summary in your review settings.

新增 updateDate 方法用于更新 echarts 图表选项,支持合并配置、
完全替换和延迟更新等模式。该方法会在组件未初始化时自动执
行首次渲染,并能够合并全局配置如 backgroundColor 等选项。
@changeset-bot

changeset-bot Bot commented Jan 23, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: d5d4a5c

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

coderabbitai Bot commented Jan 23, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

A new public updateDate method is added to the useEcharts hook. The method accepts chart options and flags, initializing the chart if needed, merging options with existing configuration, and returning a promise that resolves with the chart instance or null.

Changes

Cohort / File(s) Summary
useEcharts hook enhancement
packages/effects/plugins/src/echarts/use-echarts.ts
Added public updateDate method that accepts ECharts options with merge and lazy update flags. Initializes chart via renderEcharts if uninitialized, merges options with global config if already initialized, then calls setOption and returns chart instance promise.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • anncwb
  • vince292007

Poem

🐰 A new method hops into view,
updateDate has work to do,
Charts now refresh with grace and might,
Options merge, the echarts ignite! ✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
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.
Description check ❓ Inconclusive The description is comprehensive with motivation, changes, usage examples, and implementation details, but the required template checklist sections are not completed. Complete the required template sections: explicitly select 'New feature', check all checklist items (documentation, tests, tests passing, code review, style compliance, comments, warnings, and dependent changes).
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change—adding an updateDate method to the echarts composable for efficient data updates.

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

✨ Finishing touches
  • 📝 Generate docstrings

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@packages/effects/plugins/src/echarts/use-echarts.ts`:
- Around line 112-118: When updateDate is called and chartInstance exists, the
function currently doesn't update the stored cacheOptions, so theme switches
(handled by watch(isDark, ...)) re-render with stale options; modify updateDate
to assign the incoming option into the module/state cacheOptions before calling
render or setOption (i.e., update the cacheOptions reference used by
renderEcharts and the watch handler), ensuring chartInstance path updates
cacheOptions as well as calling renderEcharts or chartInstance.setOption so
theme switching uses the latest options.
- Line 107: The function name updateDate is a typo and should be renamed to
updateData across the module: rename the function declaration updateDate(...) to
updateData(...), update all internal calls, references, and exports (e.g., where
updateDate is used to patch ECharts series/options and any callback/handler
registration), and also update the other occurrence mentioned in the PR (the
later reference currently pointing to updateDate) so both declaration and usages
consistently use updateData.
🧹 Nitpick comments (1)
packages/effects/plugins/src/echarts/use-echarts.ts (1)

111-111: Consider using Nullable for return type consistency.

renderEcharts uses Promise<Nullable<echarts.ECharts>> while this method uses Promise<echarts.ECharts | null>. Using the same pattern improves consistency.

Proposed fix
-  ): Promise<echarts.ECharts | null> => {
+  ): Promise<Nullable<echarts.ECharts>> => {

});
};

const updateDate = (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Typo in method name: updateDate should be updateData.

Based on the PR description mentioning "efficient ECharts data updates," the intended name appears to be updateData, not updateDate.

Proposed fix
-  const updateDate = (
+  const updateData = (

Also update line 172:

-    updateDate,
+    updateData,
🤖 Prompt for AI Agents
In `@packages/effects/plugins/src/echarts/use-echarts.ts` at line 107, The
function name updateDate is a typo and should be renamed to updateData across
the module: rename the function declaration updateDate(...) to updateData(...),
update all internal calls, references, and exports (e.g., where updateDate is
used to patch ECharts series/options and any callback/handler registration), and
also update the other occurrence mentioned in the PR (the later reference
currently pointing to updateDate) so both declaration and usages consistently
use updateData.

Comment on lines +112 to +118
return new Promise((resolve) => {
nextTick(() => {
if (!chartInstance) {
// 还没初始化 → 当作首次渲染
renderEcharts(option).then(resolve);
return;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Missing cacheOptions update breaks theme switching.

When updateDate is called and the chart instance exists, cacheOptions is not updated. This causes the watch(isDark, ...) handler (lines 156-163) to re-render with stale options when the user switches themes, losing all updates made via updateDate.

Proposed fix
      nextTick(() => {
        if (!chartInstance) {
          // 还没初始化 → 当作首次渲染
          renderEcharts(option).then(resolve);
          return;
        }

+       // Update cache so theme switching preserves current options
+       cacheOptions = option;
+
        // 合并你原有的全局配置(比如 backgroundColor)
        const finalOption = {
          ...option,
          ...getOptions.value,
        };
🤖 Prompt for AI Agents
In `@packages/effects/plugins/src/echarts/use-echarts.ts` around lines 112 - 118,
When updateDate is called and chartInstance exists, the function currently
doesn't update the stored cacheOptions, so theme switches (handled by
watch(isDark, ...)) re-render with stale options; modify updateDate to assign
the incoming option into the module/state cacheOptions before calling render or
setOption (i.e., update the cacheOptions reference used by renderEcharts and the
watch handler), ensuring chartInstance path updates cacheOptions as well as
calling renderEcharts or chartInstance.setOption so theme switching uses the
latest options.

@jinmao88
jinmao88 merged commit 613c311 into vbenjs:main Jan 23, 2026
5 checks passed
@codering

codering commented Feb 9, 2026

Copy link
Copy Markdown

bot 都发现有typo 错误了,居然没修复就直接合了? 🤣

@abcd0f

abcd0f commented Feb 10, 2026

Copy link
Copy Markdown
Contributor Author

bot 都发现有typo 错误了,居然没修复就直接合了? 🤣

7538

@github-actions github-actions Bot locked and limited conversation to collaborators Mar 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants