-
Notifications
You must be signed in to change notification settings - Fork 15
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
split the input polyline into multiple polylines when there is Nan/Nu… #49
Conversation
…ll in the input. plotly need this behavior to correctly render scatter chart.
index.js
Outdated
if(!(state.count-1 in ids)) | ||
ids[state.count] = state.count-1 // make sure there is at least polygon | ||
|
||
let splits = Object.keys(ids).map(e => e|0).sort(function(a, b){return a - b}) |
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.
What's the purpose of map(e => e|0)
? Cast to number? Better .map(Number)
.
Why does sort need that default comparator?
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, the lambda is for casting, will replace it with map(Number)
The comparator for sort is to sort by number value rather than string order.
Sorry I am not very fluent in javascript.
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.
Please provide test case in test.js
.
index.js
Outdated
|
||
for (let i = 0; i < splits.length; i++) | ||
{ | ||
let triangles = triangulate(pos.slice(base*2, splits[i]*2), state.hole || []) |
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 am not sure I follow the logic here, but placing triangulate in a loop looks suspicious.
Could you please elaborate a bit what algorithmic changes are done here?
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.
The issue is when plotly send scatter segment to regl (which is seperated by null in plotly input), plotly close each segment and drop the nulls. When regl receive the segments, regl treat it as a single big plygon which end up drawing some extra triangles.
I submitted a PR (plotly/plotly.js#5355) to plotly to keep those nulls. However that itself is not enough since regl will replace the null with last valid point and still send a single polygon for triangulation. I don't see earcut.js supporting multiple polygon in a single input yet. So the proposed solution here is to call triangulation multiple time, each time only handle one segment (polygon).
New submit add tests. It also handles holes now. The idea is for each polygon we create a new temporary position buffer that contains a single polygon and all the wholes (earcut.js support multiple holes). And when the vertex index comes back from earcut.js we map it back to the original position buffer. Below are test output before and after the fix. |
make the index mapping of temporary clearer Co-authored-by: Mojtaba Samimi <[email protected]>
Lines 446 to 458 in e7ff2a4
Why here we store the input option to state? And is it true that when some field is missing in the input option, the stored value in state will be used instead? I ran into a issue during debugging notice that a path could pick up the "hole" of another path, which cause error. I don't know enough about this part of code so I did not touch it. But is this a bug? |
There can be multiple passes, ie. multiple lines to render, and each can have its own properties (like |
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.
when setting stroke to null, line2d will still trying to render miter join while the stroke vertex are not there. Using thickness = 0 solve (or get around) this. Not sure if this behavior is desired or not. But since it's not related to the issue of this PR, I will leave it there. |
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.
LGTM
Published [email protected] minor. |
…ll in the input. plotly need this behavior to correctly render scatter chart.
related to this plotly issue:
plotly/plotly.js#2291 (comment)