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 option to show active points on line and multi-lines charts #827
Add option to show active points on line and multi-lines charts #827
Conversation
Thanks for the patch! I will try to make some time to look at it tomorrow. |
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.
This is such a great PR @thomaschampagne! I had one small nit re: adding unneeded circles to the DOM I'm hoping can get fixed (something we'll have to correct elsewhere in the codebase) but it is otherwise a fantastic addition.
src/js/charts/line.js
Outdated
if (args.active_point_on_lines) { | ||
|
||
svg.selectAll('circle-' + line_id) | ||
.data(args.data[i]) |
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.
Is there a way we can actually subset args.data[i]
to produce only the data points we need? This d3 call will produce extra circles for every data point even if it is not visible, which will add a bunch of weight to the DOM that is probably not needed. We are already committing this sin in MG, so I'm hoping to keep us from bringing in an even heavier DOM down the line.
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.
You right. It's a bit dirty :/. I will try to fix that this weekend.
The use case is the same than my 2 other PRs => https://twitter.com/champagnethomas/status/972161893384228866
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.
Great - thanks @thomaschampagne!
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.
btw, really neat to see how you're using MG. Don't hesitate to send along more screenshots.
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.
@hamilton I can suggest that improvement:
if (args.active_point_on_lines) {
svg.selectAll('circle-' + line_id)
.data(args.data[i])
.enter()
.filter((d) => {
return d[args.active_point_accessor];
})
.append('circle')
.attr('class', 'mg-area' + (line_id) + '-color mg-shown-active-point')
.attr('cx', args.scalefns.xf)
.attr('cy', args.scalefns.yf)
.attr('r', (d) => {
console.warn(d)
return args.active_point_size;
});
}
I introduced a filter()
between enter()
and append('circle')
. With this code only active points will create 'circle' elements in the DOM . Tested and verified on my side.
Let me know if this solution is sufficient for you.
Sending more screenshot of my app :)? Or screenshots related to this PR?
Sorry for the delay on reviewing this. Everything looks good to me here, I will merge! |
This PR includes:
Screenshot of the added documentation (tab "data"):
Hope this helps!
Thomas