projectstorm / react-diagrams

a super simple, no-nonsense diagramming library written in react that just works
https://projectstorm.cloud/react-diagrams
MIT License
8.45k stars 1.16k forks source link

SVG Rendering Order #965

Closed johnegnatis closed 1 year ago

johnegnatis commented 1 year ago

Is there any way to enforce the order in which the repaintCanvas() paints the elements (links and nodes)? I am using two link factories, one is the default link factory and one I have extended. What I want to do it ensure that the extended link factory's elements are painted first, then the node factory's element, and finally the default link element. This way I can create a sudo-z-index, having the extended link elements painted under the nodes, and the default link elements painted over the nodes. What is the default behavior of repaint canvas?

Flowwl commented 1 year ago

@johnegnatis I succeeded to do this by creating a new layer and filtering the nodes in the right layer. You can do the same with link layers

image

Here what you can do :

CanvasWidget.tsx so you can call your own TransformLayerWidget

https://github.com/projectstorm/react-diagrams/blob/2a810ca2d3bc9e632ad52eeee6487006ac70ffd7/packages/react-canvas-core/src/entities/layer/TransformLayerWidget.tsx#L61-L65

And add the z-index depending on the layer.getType()

and that's it

Hope it helps

johnegnatis commented 1 year ago

This did work! Thank you so much for taking the time and figuring this out!