-
Notifications
You must be signed in to change notification settings - Fork 19.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: allow closing a curve on polar line series #17720
base: master
Are you sure you want to change the base?
Changes from 2 commits
9b306ba
ba21d32
2bb3988
f21cadf
ef5f29e
8bf567d
0c1fb9e
0653a08
175d8cd
9cf4c8c
60c8e93
8c2a932
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -657,6 +657,8 @@ class LineView extends ChartView { | |
|
||
const connectNulls = seriesModel.get('connectNulls'); | ||
|
||
const closed = isCoordSysPolar && seriesModel.get('closed'); | ||
|
||
const isIgnoreFunc = showSymbol && !isCoordSysPolar | ||
&& getIsIgnoreFunc(seriesModel, data, coordSys as Cartesian2D); | ||
|
||
|
@@ -725,10 +727,10 @@ class LineView extends ChartView { | |
} | ||
} | ||
|
||
polyline = this._newPolyline(points); | ||
polyline = this._newPolyline(points, closed); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a better idea to define |
||
if (isAreaChart) { | ||
polygon = this._newPolygon( | ||
points, stackedOnPoints | ||
points, stackedOnPoints, closed | ||
); | ||
}// If areaStyle is removed | ||
else if (polygon) { | ||
|
@@ -749,7 +751,7 @@ class LineView extends ChartView { | |
if (isAreaChart && !polygon) { | ||
// If areaStyle is added | ||
polygon = this._newPolygon( | ||
points, stackedOnPoints | ||
points, stackedOnPoints, closed | ||
); | ||
} | ||
else if (polygon && !isAreaChart) { | ||
|
@@ -1019,7 +1021,7 @@ class LineView extends ChartView { | |
polygon && setStatesFlag(polygon, toState); | ||
} | ||
|
||
_newPolyline(points: ArrayLike<number>) { | ||
_newPolyline(points: ArrayLike<number>, closed: boolean) { | ||
let polyline = this._polyline; | ||
// Remove previous created polyline | ||
if (polyline) { | ||
|
@@ -1028,7 +1030,8 @@ class LineView extends ChartView { | |
|
||
polyline = new ECPolyline({ | ||
shape: { | ||
points | ||
points, | ||
closed | ||
}, | ||
segmentIgnoreThreshold: 2, | ||
z2: 10 | ||
|
@@ -1041,7 +1044,7 @@ class LineView extends ChartView { | |
return polyline; | ||
} | ||
|
||
_newPolygon(points: ArrayLike<number>, stackedOnPoints: ArrayLike<number>) { | ||
_newPolygon(points: ArrayLike<number>, stackedOnPoints: ArrayLike<number>, closed: boolean) { | ||
let polygon = this._polygon; | ||
// Remove previous created polygon | ||
if (polygon) { | ||
|
@@ -1051,6 +1054,7 @@ class LineView extends ChartView { | |
polygon = new ECPolygon({ | ||
shape: { | ||
points, | ||
closed, | ||
stackedOnPoints: stackedOnPoints | ||
}, | ||
segmentIgnoreThreshold: 2 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -217,6 +217,7 @@ class ECPolylineShape { | |
smoothConstraint = true; | ||
smoothMonotone: 'x' | 'y' | 'none'; | ||
connectNulls: boolean; | ||
closed = false; | ||
} | ||
|
||
interface ECPolylineProps extends PathProps { | ||
|
@@ -245,7 +246,15 @@ export class ECPolyline extends Path<ECPolylineProps> { | |
} | ||
|
||
buildPath(ctx: PathProxy, shape: ECPolylineShape) { | ||
const points = shape.points; | ||
const points = shape.closed | ||
? [ | ||
shape.points[shape.points.length - 2], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We also need to consider the situation when some of the data is null and when |
||
shape.points[shape.points.length - 1], | ||
...shape.points as number[], | ||
shape.points[0], | ||
shape.points[1] | ||
] | ||
: shape.points; | ||
|
||
let i = 0; | ||
let len = points.length / 2; | ||
|
@@ -267,7 +276,7 @@ export class ECPolyline extends Path<ECPolylineProps> { | |
} | ||
while (i < len) { | ||
i += drawSegment( | ||
ctx, points, i, len, len, | ||
ctx, points, shape.closed ? i - 1 : i, len, shape.closed ? len - 1 : len, | ||
1, | ||
shape.smooth, | ||
shape.smoothMonotone, shape.connectNulls | ||
|
@@ -369,7 +378,15 @@ export class ECPolygon extends Path { | |
} | ||
|
||
buildPath(ctx: PathProxy, shape: ECPolygonShape) { | ||
const points = shape.points; | ||
const points = shape.closed | ||
? [ | ||
shape.points[shape.points.length - 2], | ||
shape.points[shape.points.length - 1], | ||
...shape.points as number[], | ||
shape.points[0], | ||
shape.points[1] | ||
] | ||
: shape.points; | ||
const stackedOnPoints = shape.stackedOnPoints; | ||
|
||
let i = 0; | ||
|
@@ -391,13 +408,14 @@ export class ECPolygon extends Path { | |
} | ||
while (i < len) { | ||
const k = drawSegment( | ||
ctx, points, i, len, len, | ||
ctx, points, | ||
shape.closed ? i - 1 : i, len, shape.closed ? len - 1 : len, | ||
1, | ||
shape.smooth, | ||
smoothMonotone, shape.connectNulls | ||
); | ||
drawSegment( | ||
ctx, stackedOnPoints, i + k - 1, k, len, | ||
ctx, stackedOnPoints, i + k - 1 - (shape.closed ? 1 : 0), k, shape.closed ? len - 1 : len, | ||
-1, | ||
shape.stackedOnSmooth, | ||
smoothMonotone, shape.connectNulls | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
loop
(inspired bygl.LINE_LOOP
of WebGL) may be a better name thanclosed
because it may not always be closed due to the existance of null data.