I like a solution with a formula overall. Also, if we expect the user to write a formula anyway, the range
argument could be omitted and always be (0,1).
For the ‘bar’ mode, this will end up with:
STYLE($Orchid / ($Orchid + $Rose), mode="bar") // ✅
As for ‘blend’ mode, I am not sure that a nice looking color range can be obtained with just blending two colors. Recently I came across the colorcet project that claims to provide color ranges which make values most perceptually distinct. I took the green-white-red CET_D3 diverging color range as an example and got this:
import colorcet
import colorsys
palette = colorcet.diverging_gwr_55_95_c38
print(len(palette))
colors = [
palette[0],
palette[len(palette)//4+1],
[round((a + b) / 2, 6) for a, b in zip(palette[0], palette[len(palette)//2+1])],
palette[len(palette)//2+1],
]
print('\n# not linear in RGB')
print(*colors, sep='\n')
print('\n# not linear in HSV')
print(*([round(x, 6) for x in colorsys.rgb_to_hsv(*rgb)] for rgb in colors), sep='\n')
256
# not linear in RGB
[0.22157, 0.59107, 0.055073]
[0.61495, 0.77146, 0.52644]
[0.579235, 0.75428, 0.479422]
[0.9369, 0.91749, 0.90377]
# not linear in HSV
[0.281562, 0.906825, 0.59107]
[0.273127, 0.317606, 0.77146]
[0.272809, 0.364398, 0.75428]
[0.069021, 0.035361, 0.9369]
So I think a better idea would be to let the user pick one of predefined color ranges, and the column formula will then be
STYLE(($Amount + 1) / 2) // will have to map the value into (0, 1) range