cardiomoon / webr

31 stars 18 forks source link

Definable color palette #15

Open SebastianHesse opened 1 year ago

SebastianHesse commented 1 year ago

It would be amazing if one could define the color palette for the plots. Any chance you will implement this in a new version?

Thanks a lot!

biga94 commented 10 months ago

I was able to correct the PieDonut() function in order to make it possible to define the color palette: First off, I decided to sideline the makeSubColor function. That part was initially there to create different shades for the donut's subgroups, but I figured since I wanted the pie (yeah, the inner circle) and the donut (the outer ring) to rock the same colors, there was no point in keeping different shades for the subgroups. Made sense to keep it simple.

Then, I went straight to simplifying how colors are handled for both the pie and donut sections. I've added the customColors parameter to directly set up the mainCol. This way, I'm applying the exact same custom color mapping to both parts of the chart, ensuring they're in sync, color-wise.

Finally, I tweaked the geom_arc_bar calls. I replaced the fill parameter from "no" – which was a bit of a placeholder and didn't do much – to actually use the grouping variable, which in my case is pies. This move made sure the colors I specified in customColors are now correctly showing up on both the pie and donut parts. Before this change, the donut part was showing up all gray because it wasn't getting the right instructions on what colors to display. Now, it's looking exactly how I wanted.

So you'll have to create a color mapping according to your grouping factor and then assign to customColors function parameter this mapping object.

biga94 commented 10 months ago

I've produce a pull request according to what written above. #22