I am complete beginer in SVG and React, I am working on a reactflow app to design a low-code tool to produce DAGs.
I have nodes with different colors for source and target handles and I used this medium article to produce custom edges with a linear gradient
Correct edge color gradient:

My problem is that when the source is moved below the target the linear gradient changes orientation and I get the following
Incorrect edge color gradient:

I'd like the linear gradient to be invariant with respect to the source and target position.
Any suggestion?
EDIT: the medium article provides a codesandbox example which illustrates my problem: moving node 5 above node 4 inverts the gradient
Question solved
I defined a function that checks the relative position of the nodes and adjust the gradient style correspondingly.
I added a call to this function into the
CustomEdge.jsscriptedgegradient1andedgegradient2being defined byand