I know, I know
I can't help myself.
I'm not sure how I didn't pick up on you wanting to do this on an SVG. Somehow I missed it though. For completeness, it is possible, you just have to know what it's looking for.
For this, I added a blank SVG and chose to embed it, I then added a circle element to it with the following values:
I added two custom properties (state and baseColor). I modified the script to provide the proper structure and added the binding to a paint object in the Fill for the element. Binding was modified to account for custom property
Binding:
Script:
def getRadialGrad(state,baseColor):
grad = { 'off': [{'offset':0,'stopColor':baseColor},{'offset':1,'stopColor':baseColor}],
'on': [{'offset':0,'stopColor':'var(--white)'},{'offset':1,'stopColor':baseColor}],
'safe': [{'offset':0,'stopColor':baseColor},{'offset':0.5,'stopColor':baseColor},{'offset':1,'stopColor':'var(--Black)'}],
'disabled':[{'offset':0,'stopColor':'var(--white)'},{'offset':0.5,'stopColor':baseColor},{'offset':1,'stopColor':'var(--Black)'}]}
return {'type':'radial','cx':22,'cy':21.5,'r':16,'gradientUnits':'userSpaceOnUse','stops':grad[state]}
Result with the state set to 'safe' and a baseColor of #FF8F00
Hopefully, it's obvious, but the offsets will need to be changed to suit your purposes. Also, you don't have to use hexadecimal colors, any valid CSS that resolves to a color will work. The cx and cy points were selected based on what I have here, they are dependent upon how your SVG is configured.
Needless to say that this technique could also be applied to a linear gradient.