-
Notifications
You must be signed in to change notification settings - Fork 19.8k
feat: allow closing a curve on polar line series #17720
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
base: master
Are you sure you want to change the base?
Changes from 6 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 |
|---|---|---|
|
|
@@ -211,12 +211,34 @@ function drawSegment( | |
| return k; | ||
| } | ||
|
|
||
| function getPoints(shape: ECPolygonShape|ECPolylineShape) { | ||
| let points = Array.from(shape.points); | ||
|
||
|
|
||
| if (shape.loop) { | ||
| if (shape.connectNulls) { | ||
| const nonNull: number[] = []; | ||
| for (let i = 0; i < points.length; i += 2) { | ||
| if (!isPointNull(points[i], points[i + 1])) { | ||
| nonNull.push(points[i], points[i + 1]); | ||
| } | ||
| } | ||
| points = [nonNull[nonNull.length - 2], nonNull[nonNull.length - 1], ...points, nonNull[0], nonNull[1]]; | ||
| } | ||
| else { | ||
| points = [points[points.length - 2], points[points.length - 1], ...points, points[0], points[1]]; | ||
| } | ||
| } | ||
|
|
||
| return points; | ||
| } | ||
|
|
||
| class ECPolylineShape { | ||
| points: ArrayLike<number>; | ||
| smooth = 0; | ||
| smoothConstraint = true; | ||
| smoothMonotone: 'x' | 'y' | 'none'; | ||
| connectNulls: boolean; | ||
| loop = false; | ||
| } | ||
|
|
||
| interface ECPolylineProps extends PathProps { | ||
|
|
@@ -245,8 +267,7 @@ export class ECPolyline extends Path<ECPolylineProps> { | |
| } | ||
|
|
||
| buildPath(ctx: PathProxy, shape: ECPolylineShape) { | ||
| const points = shape.points; | ||
|
|
||
| const points = getPoints(shape); | ||
| let i = 0; | ||
| let len = points.length / 2; | ||
|
|
||
|
|
@@ -267,7 +288,7 @@ export class ECPolyline extends Path<ECPolylineProps> { | |
| } | ||
| while (i < len) { | ||
| i += drawSegment( | ||
| ctx, points, i, len, len, | ||
| ctx, points, shape.loop ? i - 1 : i, len, shape.loop ? len - 1 : len, | ||
| 1, | ||
| shape.smooth, | ||
| shape.smoothMonotone, shape.connectNulls | ||
|
|
@@ -369,7 +390,7 @@ export class ECPolygon extends Path { | |
| } | ||
|
|
||
| buildPath(ctx: PathProxy, shape: ECPolygonShape) { | ||
| const points = shape.points; | ||
| const points = getPoints(shape); | ||
| const stackedOnPoints = shape.stackedOnPoints; | ||
|
|
||
| let i = 0; | ||
|
|
@@ -391,13 +412,14 @@ export class ECPolygon extends Path { | |
| } | ||
| while (i < len) { | ||
| const k = drawSegment( | ||
| ctx, points, i, len, len, | ||
| ctx, points, | ||
| shape.loop ? i - 1 : i, len, shape.loop ? len - 1 : len, | ||
| 1, | ||
| shape.smooth, | ||
| smoothMonotone, shape.connectNulls | ||
| ); | ||
| drawSegment( | ||
| ctx, stackedOnPoints, i + k - 1, k, len, | ||
| ctx, stackedOnPoints, i + k - 1 - (shape.loop ? 1 : 0), k, shape.loop ? 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.
Can
ECPolygonbe used ifloopis true? If so, you don't have to implement the loop logic.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.
Yes it can, what do you mean I don't have to implement it?
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.
Yes. I think if it passes the test, you can use
ECPolygonand remove getPoints.