-
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
Open
yassilah
wants to merge
12
commits into
apache:master
Choose a base branch
from
yassilah:feat-closed-line-series-polar
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
9b306ba
feat: allow closing a curve on polar line series
yassilah ba21d32
chore: remove pnpm lockfile
yassilah 2bb3988
Merge branch 'apache:master' into feat-closed-line-series-polar
yassilah f21cadf
fix: change to
yassilah ef5f29e
test(line): add tests for loop option with various cases
yassilah 8bf567d
Merge branch 'apache:master' into feat-closed-line-series-polar
yassilah 0c1fb9e
Merge branch 'apache:master' into feat-closed-line-series-polar
yassilah 0653a08
fix: clean code and skip process if no loop required
yassilah 175d8cd
fix: remove unnecessary if statement
yassilah 9cf4c8c
refactor(poly): use ECPolygon when Polyline is looped
yassilah 60c8e93
refactor(poly): getLoopedPoints
yassilah 8c2a932
refactor(poly): getSmoothableLoopedPoints
yassilah File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -211,12 +211,33 @@ function drawSegment( | |
return k; | ||
} | ||
|
||
function getPoints(shape: ECPolygonShape|ECPolylineShape) { | ||
if (!shape.loop) { | ||
return shape.points; | ||
} | ||
|
||
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 +266,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 +287,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 +389,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 +411,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 | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.