-
Notifications
You must be signed in to change notification settings - Fork 86
refactor(chart-advisor): refactor whole chart advisor module #260
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
base: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -0,0 +1,42 @@ | |||
export interface RuleResult { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
类型定义补充一下具体的注释
// 你可以根据实际数据结构补充 ChartData 类型 | ||
export interface ChartData { | ||
// 示例字段 | ||
bars?: any[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为什么要限制有 bars 这个字段,我们的数据可能是任意的二维表
name: 'dataRange', | ||
weight: config.weights.dataRange, | ||
check: (data: ChartData) => ({ | ||
passed: Array.isArray(data.bars) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
data.bars 是哪里来的?
|
||
it('should return full score for valid bar chart data', () => { | ||
const data = { | ||
bars: [{ value: 1 }, { value: 2 }, { value: 3 }, { value: 4 }, { value: 5 }], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[中文版模板 / 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