gooroodev commented on PR #19475:
URL: https://github.com/apache/echarts/pull/19475#issuecomment-2131318761

   ### 1. Summary of Changes
   The pull request modifies the behavior of the `dataZoom` feature to prevent 
movement when zooming. Specifically:
   - It changes the `scale` variable from `const` to `let` to allow for 
reassignment.
   - It adds a conditional check to determine if the `scale` should be set to 1 
based on the minimum and maximum span constraints.
   - It ensures that the range values are adjusted only if the conditions for 
the minimum and maximum span are not violated.
   
   ### 2. Issues, Bugs, or Typos in Code
   - **Issue:** The scale calculation logic could be more readable and 
maintainable.
   - **Improvement Proposal:** The conditional check and scale reassignment 
could be refactored for clarity.
   
   #### Improved Code (Refactoring for Readability):
   ```typescript
   let scale = Math.max(1 / e.scale, 0);
   
   // Restrict range.
   const minMaxSpan = 
this.dataZoomModel.findRepresentativeAxisProxy().getMinMaxSpan();
   
   const isZoomingIn = scale < 1;
   const isZoomingOut = scale > 1;
   const isMinSpanReached = range[1] <= minMaxSpan.minSpan + range[0];
   const isMaxSpanReached = range[1] >= minMaxSpan.maxSpan + range[0];
   
   if ((isMinSpanReached && isZoomingIn) || (isMaxSpanReached && isZoomingOut)) 
{
       scale = 1;
   }
   
   range[0] = (range[0] - percentPoint) * scale + percentPoint;
   range[1] = (range[1] - percentPoint) * scale + percentPoint;
   
   sliderMove(0, range, [0, 100], 0, minMaxSpan.minSpan, minMaxSpan.maxSpan);
   
   this.range = range;
   ```
   
   ### 3. General Review of Code Quality and Style
   - **Variable Declaration:** Changing `scale` from `const` to `let` is 
appropriate for reassignment.
   - **Conditional Logic:** The added conditional checks are necessary to 
ensure that the zooming behavior respects the minimum and maximum span 
constraints.
   - **Code Readability:** The refactored code improves readability by breaking 
down complex conditions into well-named boolean variables.
   - **Code Style:** The code follows a consistent style, but readability can 
be enhanced by using descriptive variable names for conditions.
   
   Overall, the changes are well-targeted and improve the functionality as 
intended. The proposed refactoring further enhances the clarity 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: commits-unsubscr...@echarts.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@echarts.apache.org
For additional commands, e-mail: commits-h...@echarts.apache.org

Reply via email to