-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
Allow configuration of borderWidth as object #6047
Conversation
Also related is #5262 which implements the |
Could we use an array for specifying multiple borders instead? So instead of |
I can't remember the ticket(s) but I'm sure we already had this debate about I agree with @benmccann about not using a If we really want to enhance this option (instead of borderSkipped: false | null // instead of 'none'
borderSkipped: {
left: boolean,
right: boolean,
top: boolean,
bottom: boolean
} It's consistent with the other "per side" options (e.g. |
Updated per comments |
Do we still need to make |
I think we should probably just deprecate |
A little more cleanup and tests for different directions. |
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.
Just one minor comment
One thing that might arise from this, is the fact that top/bottom for vertical and left/right for horizontal are actually start/end. |
I think it's confusing to be able to set |
refactored quite heavily to make it simpler (imo), better or not? |
After talking a bit more with @kurkle, it seems that the following makes sense (at least for v2):
Thoughts? Here are some use cases:
borderSkipped: 'bottom', // e.q. origin
borderWidth: {top: 2, bottom: 2} // left/right implicitly 0
borderSkipped: false,
borderWidth: {top: 4, bottom: 2}
borderSkipped: false,
borderWidth: function(ctx) {
var neg = ctx.dataset.data[ctx.dataIndex] < 0;
return {top: neg ? 1 : 4, bottom: neg ? 1 : 4};
} The last use case (4) may not be common, so I don't think it's an issue to ask for a scriptable option. Also, the condition ( |
That all sounds reasonable to me |
- borderWidth not inverted - borderSkipped on top of borderWidth
Updated to comply #6047 (comment) |
Maybe we can fake the border using a path if the border widths are uneven. ctx.beginPath();
ctx.rect(/* outer rect */);
ctx.rect(/* inner rect */);
ctx.fill('evenodd'); |
Good catch, @nagix! I did not notice those. |
Issue found by @nagix was not that simple to fix. With no skipped border, rectangle approach works like a charm and is a really compact solution. It does not work with skipped borders however. I tried using a rectangle + path, but that same issue lets the fill leak in some cases. So here is a new solution. While at it, added This got way bigger than my intention originally was, but at least I have explored some options :) |
@kurkle What happens with the rectangle approach with skipped borders? Does zero-width border still remain visible? |
Firefox is fine, Chrome draws a faint line there. |
I see a problem when If we don't take the arc approach, another option would be to use a clip in the same way as the arc element (link). If you still see a faint line on the edge, you can shift that section of the border a little bit outward so that it is completely outside the clip area. ctx.save();
ctx.beginPath();
ctx.rect(/* outer rect */);
ctx.clip();
ctx.beginPath();
ctx.rect(/* outer rect minus half of the thickest border width but shift outward based on the width of each section*/);
ctx.lineWidth = /* thickest border width */;
ctx.stroke();
ctx.restore(); |
I'll do another PR using that approach later. |
Closing in favor of #6077 |
@nagix about the clipping approach, according the MDN:
We are already clipping the canvas to the chart area, so it may not work in this case. |
CanvasRenderingContext2D.save() and CanvasRenderingContext2D.restore() save/restore the current clipping region, so I think it should be no problem. |
The outer clip was introduced in #3658 to clip overshooting bars / lines. So this inner clipping will ignore that. I'll see if there is a easy workaround. |
Ah, right, the problem is the solution in my comment will ignore the outer clip... |
Allow object as
borderWidth
,false
/null
(etc) toborderSkipped
.Examples:
Pen (817970c)
Pen (66d84ec)
Pen (40b4327)
Pen (700ae2c)
Fixes: #5565
Fixes: #5071
Fixes: #5709
Fixes: #4681
Related: #5413
Related: #3293 (fixed in master already)