jiawulin001 commented on PR #16895:
URL: https://github.com/apache/echarts/pull/16895#issuecomment-1100600365

   My apologies I didn't explain enough in the PR and comment. Let me show you 
the dataflow and then the strategy would be clear.
   First, we are zooming in to 'b' category and only 'b' at this chart:
   <img width="437" alt="before#16746" 
src="https://user-images.githubusercontent.com/14244944/163664209-7654625a-2349-41dd-9eea-9531553b9d92.png";>
   Then Echarts tries to determine the location of 'a', 'b' and 'c' column in 
the chart **AFTER ZOOMING**. So the `extent` here is `[1, 1]`:
   
https://github.com/apache/echarts/blob/a5257e38ad7776c766879c83854b1faa2771a454/src/coord/Axis.ts#L122-L133
   At line 125, we enter function `normalize` which returns the **relative 
location** (0~1) of the column according to their location **BEFORE ZOOMING** 
(which is 0, 1, 2 for 'a', 'b', 'c' respectively):
   
https://github.com/apache/echarts/blob/a5257e38ad7776c766879c83854b1faa2771a454/src/scale/helper.ts#L129-L132
   At this moment, remember that `extent` is `[1, 1]`, so no matter what `data` 
is, function `normalize` returns 0.5, which means all the three columns are 
located at the middle of the chart after zooming. 
   To solve this, I add a judgement: `if (val !== extent[0])` which checks 
whether the column is the one we are zooming in at. If it's not, then we return 
a correct relative location of the column. Here for 'a', 'b', 'c', they are 0, 
1, 2 before zooming and then -0.5, 0.5, 1.5 (locate at -50%, 50%, 150%) after 
zooming. 
   
![before#16746](https://user-images.githubusercontent.com/14244944/163665200-004e2945-c010-4332-a7fe-a22c8504951c.png)
   
   Also, another bug is preventing me to distinguish the three columns. At line 
132 we enters function `linearMap`, `subRange` is 0 because r0 = r1 = 320, 
which result in `return (val - d0) / subDomain * subRange + r0` equaling r0 no 
matter what `val` is. That means all three columns still locate at 320 (0.5 * 
640).
   
https://github.com/apache/echarts/blob/a5257e38ad7776c766879c83854b1faa2771a454/src/util/number.ts#L47-L100
   To solve this, I add a check whether `subRange` is 0 and if yes then just 
return `val * 2 * r0`. When `subRange` is 0, `r0` is exactly half length of the 
chart, 0.5*640 = 320. So `val * 2 * r0` = val * chartLength would be the 
absolute location of corresponding relative location.
   
   


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