Skip to content

fix(JadeJueChart): use the axisTick.customValues property to divide … #153

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 1 commit into
base: dev
Choose a base branch
from

Conversation

Guanmingjiang
Copy link
Contributor

@Guanmingjiang Guanmingjiang commented Feb 12, 2025

…the scale into 5 equal parts and hide any excess scale lines

Summary by CodeRabbit

  • New Features
    • Enhanced chart axis display with improved percentage formatting and dynamically computed tick divisions.
    • Updated chart configuration to display the angle axis in 5 evenly distributed segments for clearer visualization.

Copy link

coderabbitai bot commented Feb 12, 2025

Walkthrough

This pull request updates the axis label formatting logic for the JadeJueChart. In labelFormatter.js, the obsolete setAxisLabel function is removed and replaced by a new defaultFormatter that computes percentage values based on angleAxis.sum. The formatter selection has been streamlined and now includes custom tick value calculations using the angleAxis.splitNumber parameter. Additionally, for the JadeJueChart, the splitNumber property is explicitly set to 5 in the angleAxis configuration.

Changes

File Change Summary
src/.../JadeJueChart/labelFormatter.js Removed setAxisLabel; added defaultFormatter for percentage calculations; simplified logic for 'percent' and undefined formatter cases; computed customValues for axis ticks.
src/.../angleAxis/index.js Added angleAxisOpt.splitNumber = 5 to the configuration for JadeJueChart.

Sequence Diagram(s)

sequenceDiagram
    participant C as Chart Component
    participant H as handleLabelFormatter
    participant D as DefaultFormatter
    participant A as AngleAxis Config

    C->>H: Call handleLabelFormatter(options, baseOpt)
    alt Formatter is "percent" or undefined
        H->>D: Invoke defaultFormatter(value, angleAxis.sum)
    else Formatter is "number"
        H->>H: Use native number formatting
    end
    H->>A: Compute customValues using splitNumber
    A-->>H: Return updated angleAxis settings
    H-->>C: Return updated chart options
Loading

Possibly related PRs

Poem

I'm a swift little rabbit, hopping in code's delight,
Celebrating sleek changes that make our charts shine bright.
With functions refined and ticks in neat array,
Our axis now dances in a new, playful way.
Bound by logic and joy, I leap into the night.
🐇 Coding with heart, everything is just right!

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/components/JadeJueChart/labelFormatter.js

Oops! Something went wrong! :(

ESLint: 8.56.0

ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and '/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
at file:///eslint.config.js?mtime=1739329734096:1:15
at ModuleJob.run (node:internal/modules/esm/module_job:262:25)
at async onImport.tracePromise.proto (node:internal/modules/esm/loader:483:26)
at async loadFlatConfigFile (/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/eslint/flat-eslint.js:299:21)
at async calculateConfigArray (/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/eslint/flat-eslint.js:378:28)
at async FlatESLint.lintFiles (/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/eslint/flat-eslint.js:741:25)
at async Object.execute (/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/cli.js:421:23)
at async main (/node_modules/.pnpm/[email protected]/node_modules/eslint/bin/eslint.js:152:22)

src/option/config/angleAxis/index.js

Oops! Something went wrong! :(

ESLint: 8.56.0

ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and '/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
at file:///eslint.config.js?mtime=1739329734096:1:15
at ModuleJob.run (node:internal/modules/esm/module_job:262:25)
at async onImport.tracePromise.proto (node:internal/modules/esm/loader:483:26)
at async loadFlatConfigFile (/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/eslint/flat-eslint.js:299:21)
at async calculateConfigArray (/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/eslint/flat-eslint.js:378:28)
at async FlatESLint.lintFiles (/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/eslint/flat-eslint.js:741:25)
at async Object.execute (/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/cli.js:421:23)
at async main (/node_modules/.pnpm/[email protected]/node_modules/eslint/bin/eslint.js:152:22)

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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. (Beta)
  • @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.

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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 73ba1fb and 16d4fe9.

📒 Files selected for processing (2)
  • src/components/JadeJueChart/labelFormatter.js (2 hunks)
  • src/option/config/angleAxis/index.js (1 hunks)
🔇 Additional comments (3)
src/option/config/angleAxis/index.js (1)

20-20: LGTM! Setting splitNumber for JadeJueChart.

The addition of splitNumber = 5 aligns with the PR objective to divide the scale into five equal parts. This value is correctly used by the new customValues calculation in labelFormatter.js.

src/components/JadeJueChart/labelFormatter.js (2)

114-114: LGTM! Clear and concise percentage formatter.

The defaultFormatter function correctly calculates percentage values based on angleAxis.sum.


117-117: LGTM! Simplified formatter selection logic.

The code now consistently uses defaultFormatter for both 'percent' and undefined cases, improving maintainability.

Also applies to: 123-123

Comment on lines +132 to +140
// 使用customValues属性(echarts5.5.1以上版本才支持)将刻度均分为5份。
const customValues = [0];
const interval = angleAxis.splitNumber || 5;
const averageVal = angleAxis.sum / interval;
for (let i = 0; i < interval; i++) {
customValues.push(customValues[customValues.length - 1] + averageVal);
}
angleAxis.axisTick.customValues = customValues;
angleAxis.axisLabel.customValues = customValues;
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify ECharts version compatibility and add input validation.

The implementation correctly divides the scale into equal parts using customValues. However, there are two considerations:

  1. The comment indicates this feature requires ECharts 5.5.1+, but there's no version check.
  2. The splitNumber value should be validated to prevent potential issues.

Consider adding version validation and input checks:

 // 使用customValues属性(echarts5.5.1以上版本才支持)将刻度均分为5份。
+const ECHARTS_MIN_VERSION = '5.5.1';
+const MIN_SPLIT_NUMBER = 2;
+const MAX_SPLIT_NUMBER = 10;
+
+// Ensure splitNumber is within reasonable bounds
+const validSplitNumber = Math.max(MIN_SPLIT_NUMBER, 
+  Math.min(MAX_SPLIT_NUMBER, angleAxis.splitNumber || 5));
+
 const customValues = [0];
-const interval = angleAxis.splitNumber || 5;
+const interval = validSplitNumber;
 const averageVal = angleAxis.sum / interval;

Please verify the ECharts version requirement:


🌐 Web query:

What is the minimum ECharts version that supports axisTick.customValues?

💡 Result:

The axisTick.customValues feature for specifying custom tick positions was introduced in Apache ECharts 5.0.0. This version marked a major upgrade with significant API improvements and new customization capabilities[5][9].

Key points:

  • Version 5.x introduced enhanced axis configuration options as part of its focus on flexibility and developer experience[5].
  • The customValues property allows explicit definition of tick locations instead of relying on automatic calculation[9].
  • Earlier versions (4.x and below) do not support this feature natively, requiring workarounds for custom tick positioning[10].

For implementation details:

yAxis: {
  type: 'value',
  axisTick: {
    customValues: [0, 25, 50, 75, 100] // Explicitly set tick positions
  }
}

Citations:


ECharts Version Mismatch—Update Version Check and Validate Input

The research shows that the axisTick.customValues feature was introduced in Apache ECharts 5.0.0, not 5.5.1 as indicated in the comment. The suggested validation for the splitNumber is still a good improvement, but the version requirement should be updated accordingly.

  • In file src/components/JadeJueChart/labelFormatter.js (lines 132-140), update the version constant (and comment) from 5.5.1 to 5.0.0.
  • Ensure that any added validation of angleAxis.splitNumber aligns with acceptable input ranges.

Committable suggestion skipped: line range outside the PR's diff.

…the scale into 5 equal parts and hide any excess scale lines
@lingdan33 lingdan33 changed the title fix(JadeJueChart): Use the axisTick.customValues property to divide … fix(JadeJueChart): use the axisTick.customValues property to divide … Apr 18, 2025
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.

1 participant