gooroodev commented on PR #19919:
URL: https://github.com/apache/echarts/pull/19919#issuecomment-2131313930
### Summary of Changes
1. **Added Custom Tick/Label Positions:**
- Introduced `customValues` property to `AxisTickOption` and
`AxisLabelBaseOption` interfaces in `axisCommonTypes.ts`.
- Implemented logic to handle custom tick/label positions in
`axisTickLabelBuilder.ts` by adding `tickValuesToNumbers` function and
modifying `createAxisLabels` and `createAxisTicks` functions.
2. **Test Case:**
- Created a new HTML test file `axis-customTicks.html` to demonstrate and
verify the functionality of custom tick/label positions for different axis
types (value, category, time, log).
### Issues, Bugs, and Typos
1. **Comma at the End of Object Properties:**
- In TypeScript interfaces, trailing commas are inconsistent. For example:
```typescript
customValues?: (number | string | Date)[]
```
should be:
```typescript
customValues?: (number | string | Date)[];
```
2. **Sorting and Duplicating Ticks for Time Axis:**
- The logic to duplicate the first and last tick values for time axis
might be confusing without comments explaining why it's necessary. Consider
adding comments for clarity.
### Proposed Improvements
1. **Consistency in Trailing Commas:**
- Ensure all properties in interfaces end with a comma for consistency.
```typescript
interface AxisTickOption {
inside?: boolean;
length?: number;
lineStyle?: LineStyleOption;
customValues?: (number | string | Date)[];
}
```
2. **Enhanced Comments for Clarity:**
- Add comments to explain the purpose of duplicating first and last tick
values for time axis.
```typescript
function tickValuesToNumbers(axis: Axis, values: (number | string |
Date)[]) {
const nums = zrUtil.map(values, val => axis.scale.parse(val));
if (axis.type === 'time' && nums.length > 0) {
// Time axis needs duplicate first/last tick to ensure proper
rendering.
// The first and last tick/label don't get drawn.
nums.sort();
nums.unshift(nums[0]);
nums.push(nums[nums.length - 1]);
}
return nums;
}
```
### General Review of Code Quality and Style
1. **Modularity and Separation of Concerns:**
- The new functionality is well-integrated into existing functions
without disrupting existing logic, demonstrating good modularity and separation
of concerns.
2. **Code Readability:**
- The code is generally readable and follows good naming conventions.
However, adding more comments, especially for complex logic, would enhance
understanding.
3. **Test Coverage:**
- The new test file `axis-customTicks.html` provides comprehensive test
cases for value, category, time, and log axes, ensuring the new feature is
well-tested.
4. **Use of Utilities:**
- The use of `zrUtil.map` for mapping values is appropriate and leverages
existing utilities effectively.
### Summary
Overall, the pull request introduces a valuable feature for customizing axis
tick/label positions. The code is well-structured, and the changes are
integrated seamlessly. Minor improvements in consistency and comments would
further enhance the quality and maintainability of the code.
Yours, [Gooroo.dev](https://gooroo.dev). To receive reviews automatically,
[install Github App](https://github.com/apps/gooroo-dev)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]