-
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 all 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,29 @@ function drawSegment( | |
return k; | ||
} | ||
|
||
function getSmoothableLoopedPoints(shape: ECPolygonShape) { | ||
let points = (shape.points as number[]); | ||
|
||
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; | ||
} | ||
|
||
return [points[points.length - 2], points[points.length - 1], ...points, points[0], points[1]]; | ||
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 |
||
} | ||
|
||
class ECPolylineShape { | ||
points: ArrayLike<number>; | ||
smooth = 0; | ||
smoothConstraint = true; | ||
smoothMonotone: 'x' | 'y' | 'none'; | ||
connectNulls: boolean; | ||
loop = false; | ||
} | ||
|
||
interface ECPolylineProps extends PathProps { | ||
|
@@ -245,8 +262,15 @@ export class ECPolyline extends Path<ECPolylineProps> { | |
} | ||
|
||
buildPath(ctx: PathProxy, shape: ECPolylineShape) { | ||
const points = shape.points; | ||
if (shape.loop) { | ||
return ECPolygon.prototype.buildPath.call(this, ctx, { | ||
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. I didn't mean implement loop inside Polyline by calling Polygon, because this will cause dependency on the later. Instead, we should decide to call Polygon or Polyline in LineView. |
||
...shape, | ||
stackedOnPoints: [], | ||
stackedOnSmooth: 0 | ||
}); | ||
} | ||
|
||
const points = shape.points; | ||
let i = 0; | ||
let len = points.length / 2; | ||
|
||
|
@@ -369,7 +393,8 @@ export class ECPolygon extends Path { | |
} | ||
|
||
buildPath(ctx: PathProxy, shape: ECPolygonShape) { | ||
const points = shape.points; | ||
const shouldSmoothLoopedPoints = shape.loop && shape.smooth; | ||
const points = shouldSmoothLoopedPoints ? getSmoothableLoopedPoints(shape) : shape.points; | ||
const stackedOnPoints = shape.stackedOnPoints; | ||
|
||
let i = 0; | ||
|
@@ -391,13 +416,14 @@ export class ECPolygon extends Path { | |
} | ||
while (i < len) { | ||
const k = drawSegment( | ||
ctx, points, i, len, len, | ||
ctx, points, | ||
shouldSmoothLoopedPoints ? i - 1 : i, len, shouldSmoothLoopedPoints ? len - 1 : len, | ||
1, | ||
shape.smooth, | ||
smoothMonotone, shape.connectNulls | ||
); | ||
drawSegment( | ||
ctx, stackedOnPoints, i + k - 1, k, len, | ||
ctx, stackedOnPoints, i + k - 1, k, shouldSmoothLoopedPoints ? len - 1 : len, | ||
-1, | ||
shape.stackedOnSmooth, | ||
smoothMonotone, shape.connectNulls | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
ECPolygon
be used ifloop
is 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
ECPolygon
and remove getPoints.