You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by GitBox <gi...@apache.org> on 2022/01/26 10:32:03 UTC

[GitHub] [echarts] Gyyi opened a new pull request #16435: fix(line): 过滤空节点, 避免阶梯线条变为斜线

Gyyi opened a new pull request #16435:
URL: https://github.com/apache/echarts/pull/16435


   <!-- Please fill in the following information to help us review your PR more efficiently. -->
   
   ## Brief Information
   
   This pull request is in the type of:
   
   - [x] bug fixing
   - [ ] new feature
   - [ ] others
   
   
   ### What does this PR do?
   
   fix that connectNulls with stepLine fails when after a long number of null entries occur
   
   
   
   ### Fixed issues
   
   [<!--
   - #xxxx: ...
   -->](https://github.com/apache/echarts/issues/16424)
   
   
   ## Details
   
   ### Before: What was the problem?
   
   ![image](https://user-images.githubusercontent.com/16659067/151147226-e17b836f-8934-4b69-8300-66b0b602281d.png)
   
   
   
   ### After: How is it fixed in this PR?
   
   ![image](https://user-images.githubusercontent.com/16659067/151147369-307892bf-6aa9-4d6a-8298-6cbf877c5709.png)
   
   
   
   ## Misc
   
   [<!-- ADD RELATED ISSUE ID WHEN APPLICABLE -->](https://github.com/apache/echarts/issues/16424)
   
   - [ ] The API has been changed (apache/echarts-doc#xxx).
   - [ ] This PR depends on ZRender changes (ecomfe/zrender#xxx).
   
   ### Related test cases or examples to use the new APIs
   
   N.A.
   
   
   
   ## Others
   
   ### Merging options
   
   - [ ] Please squash the commits into a single one when merging.
   
   ### Other information
   


-- 
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-unsubscribe@echarts.apache.org

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



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


[GitHub] [echarts] pissang commented on a change in pull request #16435: fix(line): 过滤空节点, 避免阶梯线条变为斜线

Posted by GitBox <gi...@apache.org>.
pissang commented on a change in pull request #16435:
URL: https://github.com/apache/echarts/pull/16435#discussion_r806473153



##########
File path: src/chart/line/LineView.ts
##########
@@ -161,32 +161,35 @@ function turnPointsIntoStep(
     const pt: number[] = [];
     const nextPt: number[] = [];
     for (; i < points.length - 2; i += 2) {
-        nextPt[0] = points[i + 2];
-        nextPt[1] = points[i + 3];
-        pt[0] = points[i];
-        pt[1] = points[i + 1];
-        stepPoints.push(pt[0], pt[1]);
-
-        switch (stepTurnAt) {
-            case 'end':
-                stepPt[baseIndex] = nextPt[baseIndex];
-                stepPt[1 - baseIndex] = pt[1 - baseIndex];
-                stepPoints.push(stepPt[0], stepPt[1]);
-                break;
-            case 'middle':
-                const middle = (pt[baseIndex] + nextPt[baseIndex]) / 2;
-                const stepPt2 = [];
-                stepPt[baseIndex] = stepPt2[baseIndex] = middle;
-                stepPt[1 - baseIndex] = pt[1 - baseIndex];
-                stepPt2[1 - baseIndex] = nextPt[1 - baseIndex];
-                stepPoints.push(stepPt[0], stepPt[1]);
-                stepPoints.push(stepPt2[0], stepPt2[1]);
-                break;
-            default:
-                // default is start
-                stepPt[baseIndex] = pt[baseIndex];
-                stepPt[1 - baseIndex] = nextPt[1 - baseIndex];
-                stepPoints.push(stepPt[0], stepPt[1]);
+        if (!isNaN(points[i]) && !isNaN(points[i + 1])) {      
+            pt[0] = points[i];
+            pt[1] = points[i + 1];
+            stepPoints.push(pt[0], pt[1]);
+        }
+        if (!isNaN(points[i + 2]) && !isNaN(points[i + 3])) { 

Review comment:
       Seems it may not work when there are multiple consecutive NaN values. And handling these consecutive NaN values may be too complex and easy to bring bugs.
   
   Perhaps the original filter logic is simpler and more robust. Sorry for the wrong suggestion.
   
   But still the variable name `points_` should be renamed to some others without underline, like `newPoints`.




-- 
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-unsubscribe@echarts.apache.org

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



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


[GitHub] [echarts] Gyyi commented on a change in pull request #16435: fix(line): 过滤空节点, 避免阶梯线条变为斜线

Posted by GitBox <gi...@apache.org>.
Gyyi commented on a change in pull request #16435:
URL: https://github.com/apache/echarts/pull/16435#discussion_r806547011



##########
File path: src/chart/line/LineView.ts
##########
@@ -161,32 +161,35 @@ function turnPointsIntoStep(
     const pt: number[] = [];
     const nextPt: number[] = [];
     for (; i < points.length - 2; i += 2) {
-        nextPt[0] = points[i + 2];
-        nextPt[1] = points[i + 3];
-        pt[0] = points[i];
-        pt[1] = points[i + 1];
-        stepPoints.push(pt[0], pt[1]);
-
-        switch (stepTurnAt) {
-            case 'end':
-                stepPt[baseIndex] = nextPt[baseIndex];
-                stepPt[1 - baseIndex] = pt[1 - baseIndex];
-                stepPoints.push(stepPt[0], stepPt[1]);
-                break;
-            case 'middle':
-                const middle = (pt[baseIndex] + nextPt[baseIndex]) / 2;
-                const stepPt2 = [];
-                stepPt[baseIndex] = stepPt2[baseIndex] = middle;
-                stepPt[1 - baseIndex] = pt[1 - baseIndex];
-                stepPt2[1 - baseIndex] = nextPt[1 - baseIndex];
-                stepPoints.push(stepPt[0], stepPt[1]);
-                stepPoints.push(stepPt2[0], stepPt2[1]);
-                break;
-            default:
-                // default is start
-                stepPt[baseIndex] = pt[baseIndex];
-                stepPt[1 - baseIndex] = nextPt[1 - baseIndex];
-                stepPoints.push(stepPt[0], stepPt[1]);
+        if (!isNaN(points[i]) && !isNaN(points[i + 1])) {      
+            pt[0] = points[i];
+            pt[1] = points[i + 1];
+            stepPoints.push(pt[0], pt[1]);
+        }
+        if (!isNaN(points[i + 2]) && !isNaN(points[i + 3])) { 

Review comment:
       Haha, OK, I have fixed this problem. And I also make it filter null points only when using connectNull: true. 
   Please review the code again,Thanks~




-- 
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-unsubscribe@echarts.apache.org

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



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


[GitHub] [echarts] Gyyi commented on a change in pull request #16435: fix(line): 过滤空节点, 避免阶梯线条变为斜线

Posted by GitBox <gi...@apache.org>.
Gyyi commented on a change in pull request #16435:
URL: https://github.com/apache/echarts/pull/16435#discussion_r806547011



##########
File path: src/chart/line/LineView.ts
##########
@@ -161,32 +161,35 @@ function turnPointsIntoStep(
     const pt: number[] = [];
     const nextPt: number[] = [];
     for (; i < points.length - 2; i += 2) {
-        nextPt[0] = points[i + 2];
-        nextPt[1] = points[i + 3];
-        pt[0] = points[i];
-        pt[1] = points[i + 1];
-        stepPoints.push(pt[0], pt[1]);
-
-        switch (stepTurnAt) {
-            case 'end':
-                stepPt[baseIndex] = nextPt[baseIndex];
-                stepPt[1 - baseIndex] = pt[1 - baseIndex];
-                stepPoints.push(stepPt[0], stepPt[1]);
-                break;
-            case 'middle':
-                const middle = (pt[baseIndex] + nextPt[baseIndex]) / 2;
-                const stepPt2 = [];
-                stepPt[baseIndex] = stepPt2[baseIndex] = middle;
-                stepPt[1 - baseIndex] = pt[1 - baseIndex];
-                stepPt2[1 - baseIndex] = nextPt[1 - baseIndex];
-                stepPoints.push(stepPt[0], stepPt[1]);
-                stepPoints.push(stepPt2[0], stepPt2[1]);
-                break;
-            default:
-                // default is start
-                stepPt[baseIndex] = pt[baseIndex];
-                stepPt[1 - baseIndex] = nextPt[1 - baseIndex];
-                stepPoints.push(stepPt[0], stepPt[1]);
+        if (!isNaN(points[i]) && !isNaN(points[i + 1])) {      
+            pt[0] = points[i];
+            pt[1] = points[i + 1];
+            stepPoints.push(pt[0], pt[1]);
+        }
+        if (!isNaN(points[i + 2]) && !isNaN(points[i + 3])) { 

Review comment:
       Haha, OK, I have fixed this problem. And I also dealt with filtering nulls only when using connectNull: true. 
   Please review the code again,Thanks~




-- 
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-unsubscribe@echarts.apache.org

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



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


[GitHub] [echarts] pissang commented on a change in pull request #16435: fix(line): 过滤空节点, 避免阶梯线条变为斜线

Posted by GitBox <gi...@apache.org>.
pissang commented on a change in pull request #16435:
URL: https://github.com/apache/echarts/pull/16435#discussion_r803271225



##########
File path: src/chart/line/LineView.ts
##########
@@ -160,7 +160,14 @@ function turnPointsIntoStep(
     const stepPt: number[] = [];
     const pt: number[] = [];
     const nextPt: number[] = [];
-    for (; i < points.length - 2; i += 2) {
+    const points_ = [];
+    for (i = 0; i < points.length; i += 2) {
+        if (!isNaN(points[i]) && !isNaN(points[i + 1])) {
+            points_.push(points[i], points[i + 1]);
+        }
+    }
+    points = points_;
+    for (i = 0; i < points.length - 2; i += 2) {

Review comment:
       Filter `NaN` point can be done in this loop directly.




-- 
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-unsubscribe@echarts.apache.org

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



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


[GitHub] [echarts] pissang merged pull request #16435: fix(line): 过滤空节点, 避免阶梯线条变为斜线

Posted by GitBox <gi...@apache.org>.
pissang merged pull request #16435:
URL: https://github.com/apache/echarts/pull/16435


   


-- 
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-unsubscribe@echarts.apache.org

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



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


[GitHub] [echarts] echarts-bot[bot] commented on pull request #16435: fix(line): 过滤空节点, 避免阶梯线条变为斜线

Posted by GitBox <gi...@apache.org>.
echarts-bot[bot] commented on pull request #16435:
URL: https://github.com/apache/echarts/pull/16435#issuecomment-1043822198


   Congratulations! Your PR has been merged. Thanks for your contribution! 👍


-- 
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-unsubscribe@echarts.apache.org

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



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


[GitHub] [echarts] pissang commented on pull request #16435: fix(line): 过滤空节点, 避免阶梯线条变为斜线

Posted by GitBox <gi...@apache.org>.
pissang commented on pull request #16435:
URL: https://github.com/apache/echarts/pull/16435#issuecomment-1039811250


   The code looks good to me now. Could you add a test case `line-step` with `npm run mktest` command?


-- 
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-unsubscribe@echarts.apache.org

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



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


[GitHub] [echarts] Gyyi commented on a change in pull request #16435: fix(line): 过滤空节点, 避免阶梯线条变为斜线

Posted by GitBox <gi...@apache.org>.
Gyyi commented on a change in pull request #16435:
URL: https://github.com/apache/echarts/pull/16435#discussion_r806547011



##########
File path: src/chart/line/LineView.ts
##########
@@ -161,32 +161,35 @@ function turnPointsIntoStep(
     const pt: number[] = [];
     const nextPt: number[] = [];
     for (; i < points.length - 2; i += 2) {
-        nextPt[0] = points[i + 2];
-        nextPt[1] = points[i + 3];
-        pt[0] = points[i];
-        pt[1] = points[i + 1];
-        stepPoints.push(pt[0], pt[1]);
-
-        switch (stepTurnAt) {
-            case 'end':
-                stepPt[baseIndex] = nextPt[baseIndex];
-                stepPt[1 - baseIndex] = pt[1 - baseIndex];
-                stepPoints.push(stepPt[0], stepPt[1]);
-                break;
-            case 'middle':
-                const middle = (pt[baseIndex] + nextPt[baseIndex]) / 2;
-                const stepPt2 = [];
-                stepPt[baseIndex] = stepPt2[baseIndex] = middle;
-                stepPt[1 - baseIndex] = pt[1 - baseIndex];
-                stepPt2[1 - baseIndex] = nextPt[1 - baseIndex];
-                stepPoints.push(stepPt[0], stepPt[1]);
-                stepPoints.push(stepPt2[0], stepPt2[1]);
-                break;
-            default:
-                // default is start
-                stepPt[baseIndex] = pt[baseIndex];
-                stepPt[1 - baseIndex] = nextPt[1 - baseIndex];
-                stepPoints.push(stepPt[0], stepPt[1]);
+        if (!isNaN(points[i]) && !isNaN(points[i + 1])) {      
+            pt[0] = points[i];
+            pt[1] = points[i + 1];
+            stepPoints.push(pt[0], pt[1]);
+        }
+        if (!isNaN(points[i + 2]) && !isNaN(points[i + 3])) { 

Review comment:
       Haha, OK, I have fixed this problem. And I also dealt with filtering nulls only when using connectNull: true. 
   Please review the code again,Thanks~

##########
File path: src/chart/line/LineView.ts
##########
@@ -161,32 +161,35 @@ function turnPointsIntoStep(
     const pt: number[] = [];
     const nextPt: number[] = [];
     for (; i < points.length - 2; i += 2) {
-        nextPt[0] = points[i + 2];
-        nextPt[1] = points[i + 3];
-        pt[0] = points[i];
-        pt[1] = points[i + 1];
-        stepPoints.push(pt[0], pt[1]);
-
-        switch (stepTurnAt) {
-            case 'end':
-                stepPt[baseIndex] = nextPt[baseIndex];
-                stepPt[1 - baseIndex] = pt[1 - baseIndex];
-                stepPoints.push(stepPt[0], stepPt[1]);
-                break;
-            case 'middle':
-                const middle = (pt[baseIndex] + nextPt[baseIndex]) / 2;
-                const stepPt2 = [];
-                stepPt[baseIndex] = stepPt2[baseIndex] = middle;
-                stepPt[1 - baseIndex] = pt[1 - baseIndex];
-                stepPt2[1 - baseIndex] = nextPt[1 - baseIndex];
-                stepPoints.push(stepPt[0], stepPt[1]);
-                stepPoints.push(stepPt2[0], stepPt2[1]);
-                break;
-            default:
-                // default is start
-                stepPt[baseIndex] = pt[baseIndex];
-                stepPt[1 - baseIndex] = nextPt[1 - baseIndex];
-                stepPoints.push(stepPt[0], stepPt[1]);
+        if (!isNaN(points[i]) && !isNaN(points[i + 1])) {      
+            pt[0] = points[i];
+            pt[1] = points[i + 1];
+            stepPoints.push(pt[0], pt[1]);
+        }
+        if (!isNaN(points[i + 2]) && !isNaN(points[i + 3])) { 

Review comment:
       Haha, OK, I have fixed this problem. And I also make it filter null points only when using connectNull: true. 
   Please review the code again,Thanks~




-- 
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-unsubscribe@echarts.apache.org

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



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


[GitHub] [echarts] echarts-bot[bot] commented on pull request #16435: fix(line): 过滤空节点, 避免阶梯线条变为斜线

Posted by GitBox <gi...@apache.org>.
echarts-bot[bot] commented on pull request #16435:
URL: https://github.com/apache/echarts/pull/16435#issuecomment-1022069000


   Thanks for your contribution!
   The community will review it ASAP. In the meanwhile, please checkout [the coding standard](https://echarts.apache.org/en/coding-standard.html) and Wiki about [How to make a pull request](https://github.com/apache/echarts/wiki/How-to-make-a-pull-request).


-- 
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-unsubscribe@echarts.apache.org

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



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


[GitHub] [echarts] pissang commented on a change in pull request #16435: fix(line): 过滤空节点, 避免阶梯线条变为斜线

Posted by GitBox <gi...@apache.org>.
pissang commented on a change in pull request #16435:
URL: https://github.com/apache/echarts/pull/16435#discussion_r806473153



##########
File path: src/chart/line/LineView.ts
##########
@@ -161,32 +161,35 @@ function turnPointsIntoStep(
     const pt: number[] = [];
     const nextPt: number[] = [];
     for (; i < points.length - 2; i += 2) {
-        nextPt[0] = points[i + 2];
-        nextPt[1] = points[i + 3];
-        pt[0] = points[i];
-        pt[1] = points[i + 1];
-        stepPoints.push(pt[0], pt[1]);
-
-        switch (stepTurnAt) {
-            case 'end':
-                stepPt[baseIndex] = nextPt[baseIndex];
-                stepPt[1 - baseIndex] = pt[1 - baseIndex];
-                stepPoints.push(stepPt[0], stepPt[1]);
-                break;
-            case 'middle':
-                const middle = (pt[baseIndex] + nextPt[baseIndex]) / 2;
-                const stepPt2 = [];
-                stepPt[baseIndex] = stepPt2[baseIndex] = middle;
-                stepPt[1 - baseIndex] = pt[1 - baseIndex];
-                stepPt2[1 - baseIndex] = nextPt[1 - baseIndex];
-                stepPoints.push(stepPt[0], stepPt[1]);
-                stepPoints.push(stepPt2[0], stepPt2[1]);
-                break;
-            default:
-                // default is start
-                stepPt[baseIndex] = pt[baseIndex];
-                stepPt[1 - baseIndex] = nextPt[1 - baseIndex];
-                stepPoints.push(stepPt[0], stepPt[1]);
+        if (!isNaN(points[i]) && !isNaN(points[i + 1])) {      
+            pt[0] = points[i];
+            pt[1] = points[i + 1];
+            stepPoints.push(pt[0], pt[1]);
+        }
+        if (!isNaN(points[i + 2]) && !isNaN(points[i + 3])) { 

Review comment:
       Seems it may not work when there are multiple consecutive NaN values. And handling these consecutive NaN values may be too complex and easy to bring bugs.
   
   Perhaps the original filter logic is simpler and more robust. Sorry for the wrong suggestion.
   
   But still the variable name `points_` should be renamed to some others without underline, like `newPoints`.




-- 
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-unsubscribe@echarts.apache.org

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



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


[GitHub] [echarts] pissang commented on pull request #16435: fix(line): 过滤空节点, 避免阶梯线条变为斜线

Posted by GitBox <gi...@apache.org>.
pissang commented on pull request #16435:
URL: https://github.com/apache/echarts/pull/16435#issuecomment-1039811250


   The code looks good to me now. Could you add a test case `line-step` with `npm run mktest` command?


-- 
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-unsubscribe@echarts.apache.org

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



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