You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by sh...@apache.org on 2021/10/26 02:18:05 UTC
[echarts] 01/01: fix(line): fix smoothed line with duplicate points
failed to draw
This is an automated email from the ASF dual-hosted git repository.
shenyi pushed a commit to branch fix-line-draw
in repository https://gitbox.apache.org/repos/asf/echarts.git
commit 56bad39e08940f70dd7b6ed0e9471be7245cd723
Author: pissang <bm...@gmail.com>
AuthorDate: Mon Oct 25 18:58:44 2021 +0800
fix(line): fix smoothed line with duplicate points failed to draw
---
src/chart/line/poly.ts | 21 +++++++++---
test/line-case.html | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 108 insertions(+), 4 deletions(-)
diff --git a/src/chart/line/poly.ts b/src/chart/line/poly.ts
index a4b3cdd..ed38bed 100644
--- a/src/chart/line/poly.ts
+++ b/src/chart/line/poly.ts
@@ -56,8 +56,8 @@ function drawSegment(
let k = 0;
for (; k < segLen; k++) {
- const x = points[idx * 2];
- const y = points[idx * 2 + 1];
+ let x = points[idx * 2];
+ let y = points[idx * 2 + 1];
if (idx >= allLen || idx < 0) {
break;
@@ -76,8 +76,8 @@ function drawSegment(
cpy0 = y;
}
else {
- const dx = x - prevX;
- const dy = y - prevY;
+ let dx = x - prevX;
+ let dy = y - prevY;
// Ignore tiny segment.
if ((dx * dx + dy * dy) < 0.5) {
@@ -89,6 +89,19 @@ function drawSegment(
let nextIdx = idx + dir;
let nextX = points[nextIdx * 2];
let nextY = points[nextIdx * 2 + 1];
+ // Ignore duplicate point
+ while (nextX === x && nextY === y && k < segLen) {
+ k++;
+ nextIdx += dir;
+ idx += dir;
+ nextX = points[nextIdx * 2];
+ nextY = points[nextIdx * 2 + 1];
+ x = points[idx * 2];
+ y = points[idx * 2 + 1];
+ dx = x - prevX;
+ dy = y - prevY;
+ }
+
let tmpK = k + 1;
if (connectNulls) {
// Find next point not null
diff --git a/test/line-case.html b/test/line-case.html
index 4c2bbb8..300ca00 100644
--- a/test/line-case.html
+++ b/test/line-case.html
@@ -38,6 +38,8 @@ under the License.
<div id="main0"></div>
+ <div id="main1"></div>
+ <div id="main2"></div>
@@ -452,6 +454,95 @@ under the License.
</script>
+ <script>
+ require([
+ 'echarts',
+ 'ecStat'
+ ], function (echarts, ecStat) {
+ var data = [
+ [1, 5],
+ [4, 10],
+ [4,5],
+ [6, 5]
+ ];
+ echarts.registerTransform(ecStat.transform.regression);
+
+ var option = {
+ dataset: [{
+ source: data
+ }, {
+ transform: {
+ type: 'ecStat:regression',
+ config: { method: 'polynomial', order: 3 }
+ }
+ }],
+ tooltip: {
+ trigger: 'axis',
+ axisPointer: {
+ type: 'cross'
+ }
+ },
+ xAxis: {},
+ yAxis: {},
+ series: [{
+ name: 'scatter',
+ type: 'scatter'
+ }, {
+ name: 'line',
+ type: 'line',
+ datasetIndex: 1,
+ symbolSize: 0.1,
+ symbol: 'circle',
+ label: { show: true, fontSize: 16 },
+ smooth: true,
+ labelLayout: { dx: -20 },
+ encode: { label: 2, tooltip: 1 }
+ }]
+ };
+ var chart = testHelper.create(echarts, 'main1', {
+ title: [
+ 'Polyline with smooth should been displayed',
+ 'Test case from https://github.com/apache/echarts/issues/15371'
+ ],
+ option: option
+ });
+ });
+ </script>
+
+
+ <script>
+ require([
+ 'echarts'
+ ], function (echarts) {
+ var data = [
+ [0, 0],
+ [10, 10],
+ [10, 10],
+ [20, 0]
+ ];
+
+ var option = {
+ xAxis: {
+ type: 'value'
+ },
+ yAxis: {},
+ series: [{
+ name: 'line',
+ type: 'line',
+ data,
+ smooth: true
+ }]
+ };
+ var chart = testHelper.create(echarts, 'main2', {
+ title: [
+ 'Smoothed polyline should been displayed when having duplicat points.'
+ ],
+ option: option
+ });
+ });
+ </script>
+
+
</body>
</html>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org