Skip to content

feat: replace echarts to ting-charts (#21) #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from

Conversation

hu-qi
Copy link
Contributor

@hu-qi hu-qi commented Apr 25, 2025

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: #21

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features

    • Integrated new chart components for histogram, waterfall, map, and ring charts using a dedicated chart library, providing a more seamless and interactive data visualization experience.
  • Refactor

    • Replaced manual chart initialization and updates with declarative, component-based chart integration for improved maintainability and responsiveness.
    • Simplified resize and localization handling for all chart components.
  • Chores

    • Updated dependencies to include the latest version of the chart library package.

Copy link

coderabbitai bot commented Apr 25, 2025

Walkthrough

This update migrates several Vue components from direct, imperative usage of the ECharts library to a declarative, component-based approach using the @opentiny/vue-huicharts library. The change involves updating the package.json to include the new dependency, removing manual ECharts instance management, and replacing it with wrapped chart components (tiny-chart-histogram, tiny-chart-waterfall, tiny-chart-map, tiny-chart-ring). Chart configurations are now handled via reactive props and refs, and resize and localization logic is adapted to interact with the new chart components.

Changes

File(s) Change Summary
package.json Added the @opentiny/vue-huicharts dependency.
template/tinyvue/src/App.vue Removed import and usage of Vue's provide and the echarts library; eliminated dependency injection of echarts.
template/tinyvue/src/views/board/home/components/curve.vue
.../falls.vue
.../region.vue
.../round.vue
Refactored each component to replace direct ECharts usage with corresponding @opentiny/vue-huicharts components (tiny-chart-histogram, tiny-chart-waterfall, tiny-chart-map, tiny-chart-ring). Chart configuration is now passed via reactive options and chartExtend props. Updated resize and localization logic to interact with the new chart component APIs.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant VueComponent
    participant HuichartsComponent

    User->>VueComponent: Mounts component
    VueComponent->>HuichartsComponent: Passes reactive options/props
    HuichartsComponent-->>VueComponent: Renders chart based on options
    User->>VueComponent: Triggers resize or locale change
    VueComponent->>HuichartsComponent: Calls resize() or updates props
    HuichartsComponent-->>VueComponent: Updates chart display
Loading

Poem

In the garden of charts, a new breeze blew,
Out with the old, in with something new!
Huicharts now paint with a hop and a swing,
No more manual brushes—just let the props sing.
With every resize and each locale tune,
The charts now dance to a simpler monsoon.
🐇✨ Hopping forward, code in bloom!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 520dae7 and 2a939e8.

📒 Files selected for processing (4)
  • template/tinyvue/src/views/board/home/components/curve.vue (3 hunks)
  • template/tinyvue/src/views/board/home/components/falls.vue (4 hunks)
  • template/tinyvue/src/views/board/home/components/region.vue (4 hunks)
  • template/tinyvue/src/views/board/home/components/round.vue (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • template/tinyvue/src/views/board/home/components/region.vue
  • template/tinyvue/src/views/board/home/components/falls.vue
  • template/tinyvue/src/views/board/home/components/round.vue
  • template/tinyvue/src/views/board/home/components/curve.vue

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the enhancement New feature or request label Apr 25, 2025
Copy link

@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: 0

🧹 Nitpick comments (5)
template/tinyvue/src/views/board/home/components/falls.vue (2)

12-15: Remove unused import.

The inject import from Vue is not used in this component after migrating to Ting-Charts. Consider removing it to keep the imports clean.

-import { onMounted, watch, inject, ref, nextTick } from 'vue';
+import { onMounted, watch, ref, nextTick } from 'vue';

70-111: Consider extracting hardcoded chart configurations as constants or computed properties.

The chart configuration contains numerous hardcoded values. For better maintainability, consider extracting these values into constants or computed properties, especially for values that might need to change based on themes or other application state.

template/tinyvue/src/views/board/home/components/curve.vue (3)

12-15: Remove unused import.

The inject import from Vue is not used in this component after migrating to Ting-Charts. Consider removing it to keep the imports clean.

-import { onMounted, watch, inject, ref, nextTick } from 'vue';
+import { onMounted, watch, ref, nextTick } from 'vue';

213-230: Consider using i18n directly in chart config for better maintainability.

While the current approach works well for locale handling, consider using the t function directly in the initial configuration to make the code more DRY and easier to maintain:

const getLegendData = () => [t('home.main.down'), t('home.curve.play'), t('home.curve.page')];

const chartExtend = ref({
  legend: {
    data: getLegendData(),
    // ...other config
  },
  // ...other config
  series: [
    {
      name: t('home.main.down'),
      // ...other config
    },
    // ...other series
  ]
});

// Then in the watch function, just call:
watch(currentLocale, () => {
  chartExtend.value.legend.data = getLegendData();
  chartExtend.value.series[0].name = t('home.main.down');
  // ...other updates
  chartRef.value.resize();
});

This would reduce duplication and automatically handle translations.


127-128: Translate Chinese comment to English for consistency.

There's a comment in Chinese. Consider translating it to English for consistency with the rest of the codebase.

-        // 区域填充样式
+        // Area fill style
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3528021 and 7402246.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (6)
  • package.json (1 hunks)
  • template/tinyvue/src/App.vue (1 hunks)
  • template/tinyvue/src/views/board/home/components/curve.vue (1 hunks)
  • template/tinyvue/src/views/board/home/components/falls.vue (1 hunks)
  • template/tinyvue/src/views/board/home/components/region.vue (1 hunks)
  • template/tinyvue/src/views/board/home/components/round.vue (1 hunks)
🔇 Additional comments (15)
package.json (1)

74-74: New dependency added for chart upgrade.

The addition of @opentiny/vue-huicharts at version ^3.22.0 supports the migration from ECharts to Ting-Charts, which matches the PR title "feat: replace echarts to ting-charts".

template/tinyvue/src/App.vue (1)

8-15: Global ECharts injection removed.

As part of migrating from direct ECharts usage to Ting-Charts components, the global echarts injection (provide('echarts', echarts)) has been correctly removed. This is consistent with moving away from imperative chart initialization to a component-based approach.

template/tinyvue/src/views/board/home/components/region.vue (4)

9-9: Successfully migrated to declarative chart components.

The code has been refactored to use <tiny-chart-map> component instead of manually initializing an ECharts instance, which simplifies the code and makes it more maintainable.


18-22: Clean dependency update.

The code correctly imports TinyHuichartsMap and aliases it to TinyChartMap for better readability, while removing the dependency on the injected echarts instance.


60-119: Well-structured configuration with reactive refs.

The chart configuration has been properly converted to a reactive ref object, which is the recommended approach for Vue 3. The options include all necessary properties from the previous ECharts configuration with additional improvements like selectedMode: false and proper markPoint configuration.


121-128: Updated resize handling.

The resize event handling has been properly adapted to work with the Ting-Charts component API, maintaining the same functionality but with the new implementation.

template/tinyvue/src/views/board/home/components/round.vue (5)

7-7: Successfully migrated pie chart to component-based approach.

The code has been refactored to use <tiny-chart-ring> component with properly bound props (options and extend) instead of manually initializing an ECharts instance.


17-21: Clean dependency update.

The code correctly imports TinyHuichartsRing and aliases it to TinyChartRing, while removing the dependency on the injected echarts instance.


25-77: Well-organized chart configuration split into data and styling.

The chart configuration has been cleanly separated into:

  1. options.data - containing just the data points
  2. chartExtend - containing styling, tooltips, legend configuration, and other visual aspects

This separation of concerns makes the code more maintainable and easier to understand.


79-86: Updated resize handling.

The resize event handling has been properly adapted to work with the Ting-Charts component API, maintaining the same functionality with the new implementation.


88-90: Simplified locale change handling.

The watch on currentLocale has been updated to use the component's resize method instead of completely reinitializing the chart, which is a more efficient approach.

template/tinyvue/src/views/board/home/components/falls.vue (2)

6-6: Great migration to the declarative chart approach.

The refactoring from imperative ECharts usage to a declarative component-based approach with tiny-chart-waterfall looks good. This approach simplifies chart integration and makes updates more reactive.


190-201: Good implementation of resize handling.

The resize logic is properly implemented, triggered on window resize, after component mount, and on locale changes.

template/tinyvue/src/views/board/home/components/curve.vue (2)

6-6: Great migration to the declarative chart approach.

The refactoring from imperative ECharts usage to a declarative component-based approach with tiny-chart-histogram looks good. This approach simplifies chart integration and makes updates more reactive.


20-28: Good use of dataZoom configuration for improved user interaction.

The dataZoom configuration is well-structured and provides good user interaction options with both inside (mouse wheel/pinch zoom) and slider controls.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant