Skip to content
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

Legend boxes don't reflect the gradient #28

Closed
stockiNail opened this issue Mar 28, 2022 · 6 comments · Fixed by #29
Closed

Legend boxes don't reflect the gradient #28

stockiNail opened this issue Mar 28, 2022 · 6 comments · Fixed by #29

Comments

@stockiNail
Copy link
Contributor

stockiNail commented Mar 28, 2022

Feature Proposal

As I have seen in my lib, when you use gradients, the gradients are not reflected in the legend.

To be precise, the gradient is applied to the legend but due to the gradient size is limited to the scales, the legend are out side of the gradient and then the canvas use the color related to the position.

See example in codepen: https://codepen.io/stockinail/pen/xxpENVM

As you can see the legend is using the red color because is the color from the gradient for legend position.

The same is for polarArea (using the radial gradient) where all legend items are colored with the color of the gradient.

polarGradient

The proposal is to reflect on the legend the gradient.

Possible Implementation

I see only 1 option, creating a generateLabels callback in the plugin to set to the chart in order to create a specific gradient (with dimension of the legend box).

For polarArea, the generateLabels callback could return the color at the data index, calculating the last color for the data index. For this, I have got already a code (even if is written in Java) that it can be translated and used.

@stockiNail
Copy link
Contributor Author

Forgot to write that if the user set own generateLabels callback, the callback of the plugin should wrap it, invoking it and changes only the fillStyle and strokeStyle.

@kurkle
Copy link
Owner

kurkle commented Mar 28, 2022

It would be great if the legend plugin would resolve the colors with a different context, so a different gradient could be returned based on that. But it does not, so your suggestion might be the only option.

@stockiNail
Copy link
Contributor Author

But it does not, so your suggestion might be the only option.

yeah, at he moment it sounds so. I know in CHART.JS v4 there is the plan to re-write legend plugin... in version 4!

Just FYI, I'm creating a prototype. I'll show it to you soon.

@stockiNail
Copy link
Contributor Author

In advance, to do that I think we need to map more hooks of plugin (i.e. to set the callback) and also leverage on chart states map (as done in plugin annotation).

@stockiNail
Copy link
Contributor Author

stockiNail commented Mar 28, 2022

@kurkle FYI, generateLabels callback is not the right direction because, when invoked, the legendItems size is not calculated yet. I've found another way.

@stockiNail
Copy link
Contributor Author

Do you think the support to version 2.x is still needed also for this enhancement?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants