refactor(chart-advisor): refactor whole chart advisor module#260
Open
bingling-sama wants to merge 2 commits intoVisActor:developfrom
Open
refactor(chart-advisor): refactor whole chart advisor module#260bingling-sama wants to merge 2 commits intoVisActor:developfrom
bingling-sama wants to merge 2 commits intoVisActor:developfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the chart advisor module to improve modularity and testability by decomposing monolithic functions and organizing reusable utility and rule functions.
- Extracted utility functions for validation and calculation.
- Introduced dedicated scorers for pie, line, and bar charts that compose common and chart-specific rules.
- Modularized rule configurations and composed rule logic to streamline scoring workflows.
Reviewed Changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/chart-advisor/src/utils/validation.ts | Added basic validation functions for chart data. |
| packages/chart-advisor/src/utils/calculation.ts | Added statistical calculation functions. |
| packages/chart-advisor/src/types/index.ts | Defined types and interfaces for chart advisor. |
| packages/chart-advisor/src/scorers/*.ts | Created scorers for pie, line, and bar charts. |
| packages/chart-advisor/src/rules/config.ts | Introduced default scoring configurations. |
| packages/chart-advisor/src/rules/compose.ts | Implemented rule composition to aggregate scores. |
| packages/chart-advisor/src/rules/common.ts | Defined shared scoring rules including data range, dimension-metric checks, and others. |
| packages/chart-advisor/src/tests/scorers/*.test.ts | Added tests to validate scoring behavior. |
Comments suppressed due to low confidence (2)
packages/chart-advisor/src/rules/common.ts:18
- [nitpick] The rule is named 'dimensionMetric' while its related configuration key is 'dimensionCheck'; consider renaming for consistency, for example, to 'dimensionCheckRule'.
export const dimensionMetricRule = (config: ScoringConfig): Rule => ({
packages/chart-advisor/src/utils/validation.ts:3
- [nitpick] Consider adding more detailed JSDoc comments to document the input parameters and return values of the validation functions for improved clarity.
// 校验 bars 是否为有效数组且长度大于0
xile611
reviewed
Jun 11, 2025
| @@ -0,0 +1,42 @@ | |||
| export interface RuleResult { | |||
| // 你可以根据实际数据结构补充 ChartData 类型 | ||
| export interface ChartData { | ||
| // 示例字段 | ||
| bars?: any[]; |
Contributor
There was a problem hiding this comment.
为什么要限制有 bars 这个字段,我们的数据可能是任意的二维表
| name: 'dataRange', | ||
| weight: config.weights.dataRange, | ||
| check: (data: ChartData) => ({ | ||
| passed: Array.isArray(data.bars) |
xile611
reviewed
Jun 11, 2025
|
|
||
| it('should return full score for valid bar chart data', () => { | ||
| const data = { | ||
| bars: [{ value: 1 }, { value: 2 }, { value: 3 }, { value: 4 }, { value: 5 }], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

[中文版模板 / Chinese template]
🤔 This is a ...
🔗 Related issue link
implementing #241
🔗 Related PR link
🐞 Bugserver case id
💡 Background and solution
Problems:
Refactor Plan:
Break down large functions (e.g., scorer, baseBarScore) into smaller, single-responsibility functions.
Extract chart-type-specific logic into separate modules/files.
Move rule definitions and configurations out of inline objects into dedicated, reusable modules.
Create a registry or factory for chart scoring strategies.
Replace large, loosely-typed parameter objects with well-defined interfaces.
Pass only necessary data to each function to reduce implicit dependencies.
Inject utility functions and configuration instead of importing them directly.
Allow for easy mocking/stubbing in tests.
Expose internal logic and utility functions for direct testing.
Write unit tests for each isolated function and rule.
Add integration tests for high-level scoring flows.
Add clear JSDoc/type annotations for all public and internal APIs.
Document the expected input/output for each function.
📝 Changelog
☑️ Self-Check before Merge
🚀 Summary
copilot:summary
🔍 Walkthrough
copilot:walkthrough