i am really desperate because i try to achieve a certain effect since hours and i basically just do not succeed

I need to colorize a random shape with a rainbow color gradient. The tricky thing here is, that the color gradient itself should have a "wave like" appearance. To clarify my problem i made some simple drawings:
A) shows the straight forward thing. Its easy to set up a color gradients, add steps, adjust offset etc. but the thing i need is B)! I need to individually change the course of each color. E.g. i want the turquoise gradient to form such a curve. Consequently i need all the other colours behind also to form that curve leading to an harmonic overall picture. I tried to cut my shape in smaller columns and colorize each one individually (like pictured in C) but i never get a harmonic alignment to the colours of the neighboring columns


The final result should look a bit like that (stolen from the internet) heatmap. Irregular colored like i draw the gradients with the cursor. Of course way to blurry but is shows what i need.

In reality its not a rectangle that i need to colorize but a random shape. I hope that does not play a role for helping me.
Thank you so much
Mike