kurkle / chartjs-plugin-gradient

Easy gradients for Chart.js
MIT License
37 stars 6 forks source link

When the scale is configure in reverse mode, the color sequence is not correct #10

Closed stockiNail closed 2 years ago

stockiNail commented 2 years ago

When you are configuring the scale with reverse: true, the color sequence of the gradient is not correct.

I have prepared a codepen for that: https://codepen.io/stockinail/pen/xxpENVM

I can check how to solve it and submit a PR for that.

kurkle commented 2 years ago

I believe the problem is here:

https://github.com/kurkle/chartjs-plugin-gradient/blob/bb2601b4bc9dc43c460d5d3b983a7d315d5469f8/src/index.js#L13

The getDecimalForPixel is reversed (and that would need to be countered):

https://github.com/chartjs/Chart.js/blob/9568a315d220e0eaed697d5245724f8d34ed05ba/src/core/core.scale.js#L926-L929

stockiNail commented 2 years ago

I have the feeling that it should be in the createLinearGradient. If reverse is set, bottom and top (and left and right) should be reversed.