-
Notifications
You must be signed in to change notification settings - Fork 312
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
add d3.trail() #168
base: main
Are you sure you want to change the base?
add d3.trail() #168
Conversation
Ah excellent! I was worried about this shape too https://observablehq.com/@fil/trail-marks ;-) Another bit that would need fixing in this shape is when the data has more than 2 points—currently it draws one "loop" for each pair, with the consequence that the stroke is not the outline, and the shape has superpositions. (You will also need to declare the function in src/index.js, show it in README.md and test it in tests/ for the PR to be complete.) |
Thank you for your suggestions, I will further improve this function with your suggestions. Actually, it's my first experience to contribute to open source libraries. So if i make some mistakes, please accept my most sincere apology. |
Wow this is beautiful! (The images will display only when the PR is merged (they link to the master branch).) |
Two small issues: Have you pushed all the code? To build this branch I had to add:
Secondly, the data from https://observablehq.com/@fil/trail-marks breaks it, because I've left a little 💣 with coincident points ( [300, 200, 0], [300, 200, 0.1] ). |
The third commit has solved some small issus in d3.trail(). Note that the point will be only drawed when its size is greater than 0. |
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.
Mostly style remarks to try and homogenize with the rest of the code base.
I'm wondering: it might be more performant if it did all the calls to x, y, size and defined only once, and saved the values in Float64Arrays. (Plus, you never know what accessors the user is going to call—or maybe someone is going to try size(random).)
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.
Looks good to me!
If you would follow D3's general style conventions more closely (with spaces between operators and arguments, before curly brackets etc.) it will help do a cleaner merge. See https://gist.github.com/Fil/faa610218d355d927b19cf8e99d8dcb6
Thank you for your reminder. I have followed D3's general style conventions in the fifth commit. |
It's my honor to contribute to D3. Thank you for your help again. |
It's great to see someone improving the trail mark in Vega and adapting it to d3! Thanks! I took a quick glance at the code, but didn't check the adapted logic for correctness. That said, I did notice some possible concerns:
|
Thank you for your suggestions! The sixth commit has taken the two concerns above. |
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.
Looks good! Added some minor nits.
I think the consensus is that the README should use let
and const
, while the implementation uses ES5.
README.md
Outdated
When a trail is [generated](#_trail), the x accessor will be invoked for each [defined](#trail_defined) element in the input data array, being passed the element `d`, the index `i`, and the array `data` as three arguments. The default x accessor assumes that the input data are three-element arrays of numbers. If your data are in a different format, or if you wish to transform the data before rendering, then you should specify a custom accessor. For example: | ||
|
||
```js | ||
var data = [ |
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.
var data = [ | |
const data = [ |
README.md
Outdated
… | ||
]; | ||
|
||
var trail = d3.trail() |
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.
var trail = d3.trail() | |
const trail = d3.trail() |
src/trail.js
Outdated
return false; | ||
} | ||
|
||
// straddle experiment. |
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.
If it's an experiment, do we want to add it? Maybe remove this comment?
// straddle experiment. | |
// straddle. |
src/trail.js
Outdated
|
||
// straddle experiment. | ||
if (cross(x1 - x4, y1 - y4, x3 - x4, y3 - y4) * cross(x2 - x4, y2 - y4, x3 - x4, y3 - y4) > 0 || | ||
cross(x3 - x2, y3 - y2, x1 - x2, y1 - y2) * cross(x4 - x2, y4 - y2, x1 - x2, y1 - y2) > 0) { |
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.
cross(x3 - x2, y3 - y2, x1 - x2, y1 - y2) * cross(x4 - x2, y4 - y2, x1 - x2, y1 - y2) > 0) { | |
cross(x3 - x2, y3 - y2, x1 - x2, y1 - y2) * cross(x4 - x2, y4 - y2, x1 - x2, y1 - y2) > 0) { |
Alignment reads well.
This is a lot for a single expression also. May be worth factoring out into variables.
src/trail.js
Outdated
x: x2, | ||
y: y2 | ||
}; | ||
} |
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.
} | |
} else { |
Seems odd to have else on a new line.
src/trail.js
Outdated
angle: alpha + beta - pi | ||
}; | ||
} | ||
else { |
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.
No need for this else
, as the if
returns. Can remove the brackets and un-indent here.
src/trail.js
Outdated
|
||
if (context == null) context = buffer = path(); | ||
|
||
var start, |
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.
Perhaps better to lift these declarations to the top, with the others.
Thank you for your suggestions! The lastest commit has refined the codes and docs in d3-shape. |
No description provided.