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 2020/10/14 08:07:09 UTC
[incubator-echarts] branch bugfixes updated: fix(line): use raw
points when calculating endLabel.
This is an automated email from the ASF dual-hosted git repository.
shenyi pushed a commit to branch bugfixes
in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git
The following commit(s) were added to refs/heads/bugfixes by this push:
new f7ac75e fix(line): use raw points when calculating endLabel.
f7ac75e is described below
commit f7ac75ec9da17c24dcce94ee39733b4fce022272
Author: pissang <bm...@gmail.com>
AuthorDate: Wed Oct 14 16:06:38 2020 +0800
fix(line): use raw points when calculating endLabel.
---
src/chart/line/LineView.ts | 72 ++++++++++++++++++++++++++++++++++++++++++----
src/chart/line/poly.ts | 50 --------------------------------
2 files changed, 66 insertions(+), 56 deletions(-)
diff --git a/src/chart/line/LineView.ts b/src/chart/line/LineView.ts
index 36c8e6b..4a8a48a 100644
--- a/src/chart/line/LineView.ts
+++ b/src/chart/line/LineView.ts
@@ -357,6 +357,59 @@ function canShowAllSymbolForCategory(
return true;
}
+
+function isPointNull(x: number, y: number) {
+ return isNaN(x) || isNaN(y);
+}
+
+function getLastIndexNotNull(points: ArrayLike<number>) {
+ let len = points.length / 2;
+ for (; len > 0; len--) {
+ if (!isPointNull(points[len * 2 - 2], points[len * 2 - 1])) {
+ break;
+ }
+ }
+
+ return len - 1;
+}
+
+function getPointAtIndex(points: ArrayLike<number>, idx: number) {
+ return [points[idx * 2], points[idx * 2 + 1]];
+}
+
+function getIndexRange(points: ArrayLike<number>, xOrY: number, dim: 'x' | 'y') {
+ const len = points.length / 2;
+
+ const dimIdx = dim === 'x' ? 0 : 1;
+ let a;
+ let b;
+ let prevIndex = 0;
+ let nextIndex = -1;
+ for (let i = 0; i < len; i++) {
+ b = points[i * 2 + dimIdx];
+ if (isNaN(b) || isNaN(points[i * 2 + 1 - dimIdx])) {
+ continue;
+ }
+ if (i === 0) {
+ a = b;
+ continue;
+ }
+ if (a <= xOrY && b >= xOrY || a >= xOrY && b <= xOrY) {
+ nextIndex = i;
+ break;
+ }
+
+ prevIndex = i;
+ a = b;
+ }
+
+ return {
+ range: [prevIndex, nextIndex],
+ t: (xOrY - a) / (b - a)
+ };
+}
+
+
interface EndLabelAnimationRecord {
lastFrameIndex: number
originalX?: number
@@ -393,8 +446,14 @@ function createLineClipPath(
const isHorizontal = coordSys.getBaseAxis().isHorizontal();
const clipPath = createGridClipPath(coordSys, hasAnimation, seriesModel, () => {
- if (lineView._endLabel && labelAnimationRecord.originalX != null) {
- lineView._endLabel.attr({x: labelAnimationRecord.originalX, y: labelAnimationRecord.originalY});
+ const endLabel = lineView._endLabel;
+ if (endLabel && hasAnimation) {
+ if (labelAnimationRecord.originalX != null) {
+ endLabel.attr({
+ x: labelAnimationRecord.originalX,
+ y: labelAnimationRecord.originalY
+ });
+ }
}
}, during);
// Expand clip shape to avoid clipping when line value exceeds axis
@@ -995,7 +1054,7 @@ class LineView extends ChartView {
}
// Find last non-NaN data to display data
- const dataIndex = this._polyline.getLastIndexNotNull();
+ const dataIndex = getLastIndexNotNull(data.getLayout('points'));
if (dataIndex >= 0) {
setLabelStyle(
endLabel,
@@ -1039,6 +1098,7 @@ class LineView extends ChartView {
animationRecord.originalY = endLabel.y;
}
+ const points = data.getLayout('points');
const seriesModel = data.hostModel as LineSeriesModel;
const connectNulls = seriesModel.get('connectNulls');
const precision = endLabelModel.get('precision');
@@ -1053,7 +1113,7 @@ class LineView extends ChartView {
: isHorizontal ? (clipShape.x + clipShape.width) : clipShape.y;
const dim = isHorizontal ? 'x' : 'y';
- const dataIndexRange = polyline.getIndexRange(xOrY, dim);
+ const dataIndexRange = getIndexRange(points, xOrY, dim);
const indices = dataIndexRange.range;
const diff = indices[1] - indices[0];
@@ -1061,7 +1121,7 @@ class LineView extends ChartView {
if (diff >= 1) {
// diff > 1 && connectNulls, which is on the null data.
if (diff > 1 && !connectNulls) {
- const pt = polyline.getPointAtIndex(indices[0]);
+ const pt = getPointAtIndex(points, indices[0]);
endLabel.attr({ x: pt[0], y: pt[1] });
valueAnimation && (value = seriesModel.getRawValue(indices[0]) as ParsedValue);
}
@@ -1081,7 +1141,7 @@ class LineView extends ChartView {
// If diff <= 0, which is the range is not found(Include NaN)
// Choose the first point or last point.
const idx = (percent === 1 || animationRecord.lastFrameIndex > 0) ? indices[0] : 0;
- const pt = polyline.getPointAtIndex(idx);
+ const pt = getPointAtIndex(points, idx);
valueAnimation && (value = seriesModel.getRawValue(idx) as ParsedValue);
endLabel.attr({ x: pt[0], y: pt[1] });
}
diff --git a/src/chart/line/poly.ts b/src/chart/line/poly.ts
index 6138121..a4b3cdd 100644
--- a/src/chart/line/poly.ts
+++ b/src/chart/line/poly.ts
@@ -260,56 +260,6 @@ export class ECPolyline extends Path<ECPolylineProps> {
}
}
- getLastIndexNotNull() {
- const points = this.shape.points;
- let len = points.length / 2;
- for (; len > 0; len--) {
- if (!isPointNull(points[len * 2 - 2], points[len * 2 - 1])) {
- break;
- }
- }
-
- return len - 1;
- }
-
- getPointAtIndex(idx: number) {
- const points = this.shape.points;
- return [points[idx * 2], points[idx * 2 + 1]];
- }
-
- getIndexRange(xOrY: number, dim: 'x' | 'y') {
- const points = this.shape.points;
- const len = points.length / 2;
-
- const dimIdx = dim === 'x' ? 0 : 1;
- let a;
- let b;
- let prevIndex = 0;
- let nextIndex = -1;
- for (let i = 0; i < len; i++) {
- b = points[i * 2 + dimIdx];
- if (isNaN(b) || isNaN(points[i * 2 + 1 - dimIdx])) {
- continue;
- }
- if (i === 0) {
- a = b;
- continue;
- }
- if (a <= xOrY && b >= xOrY || a >= xOrY && b <= xOrY) {
- nextIndex = i;
- break;
- }
-
- prevIndex = i;
- a = b;
- }
-
- return {
- range: [prevIndex, nextIndex],
- t: (xOrY - a) / (b - a)
- };
- }
-
getPointOn(xOrY: number, dim: 'x' | 'y'): number[] {
if (!this.path) {
this.createPathProxy();
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org