Closed agarwalishan closed 3 years ago
You can add z-index: 1
to the svg
element inside react-diagrams
.
@renato-bohler Thank you very much it's working perfectly. But could you please explain how it worked, I don't understand the reason?
Sure. So this is how react-diagrams
looks in the DOM:
Where:
react-diagrams
containersvg
.div
.Both the link and node layer have position: absolute
but no z-index
. Because div
comes after svg
, the nodes are rendered above the links as default. When you set z-index
to 1
, you are telling the browser that all links should be rendered above the nodes.
@renato-bohler Thank you very much for explaining, I got it. Could you please tell me if there is any event that fires when we click on canvas?
Hmmm I think there isn't. Not sure why you need that, but you could maybe addEventListener('click')
on the canvas. If you need more information of where the click happened or anything like that, you'll probably need to implement a custom state which fires this event.
@renato-bohler Ok, Is there a way to deregister default registered state? Actually I want Undo/Redo on moving items and I saw your code of logossim for implementing where you have made a custom MoveItemsState. I also want to implement like this but the problem is I have not made a Custom Diagram Engine like yours rather I am using default engine that react-diagrams provides and which comes with some states already registered in it as mentioned here.
So how can I de-register existing MoveItemsState and register my new custom inplace of it?
You just need to call engine.getStateMachine().pushState()
with your custom State
class. Here's how I did it.
@renato-bohler Ok thanks, your logossim project helped me a lot
You can add
z-index: 1
to thesvg
element insidereact-diagrams
.
It seems like I can't link two ports now, as they are behind the link element. Any workaround for that?
You can add
z-index: 1
to thesvg
element insidereact-diagrams
.It seems like I can't link two ports now, as they are behind the link element. Any workaround for that?
Sorry but I am not using drag and drop feature for making link. I am connecting links programmatically. Aren't you even able to create atleast one link?
You can add
z-index: 1
to thesvg
element insidereact-diagrams
.It seems like I can't link two ports now, as they are behind the link element. Any workaround for that?
Hi @sinanyaman95 , did you find any workaround for this? I am getting the exact same issue. @renato-bohler Please help
Uhh crap... well, you could add z-index: 2
specifically on the ports, but that would make the browser render them on top of links.
I guess a hacky solution you could try is separating the port element into two: one visual and one invisible, making the invisible have the same size and position as the visible, but with z-index: 2
... not sure if that would introduce any other issues.
If that's not desirable, I think the only alternative is changing how react-diagrams
handles click with a custom state, trying to figure out what element the user is trying to click in (instead of using getModelForEvent
). That can be complex, tough...
@renato-bohler After setting svg z-index to 1, I have already tried to add z-index of higher number to the port, but it's not working, as the main(parent) div for that port is having z-index 0 by default. So we are not able to pull the link from that port. And if set main/parent port z-index higher than the arrows get hide due to same or lesser z-index of svg tag.
With Z-index value 0 for svg
With Z-index value 1 for svg So any better solution you are suggesting?
Also @renato-bohler, We are working on Nodes which can have multiple ports, so we have added scroll view inside our custom nodes. But when we have links between two ports of two different nodes or two ports of the same node. So while scrolling the ports inside node, links remains on the same position even if that port gets scrolled up.(See the attachment.)
Is there anything that you can suggest here to achieve this?
@renato-bohler After setting svg z-index to 1, I have already tried to add z-index of higher number to the port, but it's not working, as the main(parent) div for that port is having z-index 0 by default. So we are not able to pull the link from that port. And if set main/parent port z-index higher than the arrows get hide due to same or lesser z-index of svg tag.
Hmm yeah, that really shouldn't work because of how stacking context works :confused:
Other thing you could try is removing all layers using CanvasModel getLayers
and removeLayer
, and then adding them in reverse order using addLayer
, similarly to DiagramModel
:
Again, I'm not sure if that would work, since I never needed to do this. It would most likely just end up having the same problem.
Also @renato-bohler, We are working on Nodes which can have multiple ports, so we have added scroll view inside our custom nodes. But when we have links between two ports of two different nodes or two ports of the same node. So while scrolling the ports inside node, links remains on the same position even if that port gets scrolled up.(See the attachment.)
This one I have no clue on how to implement, honestly... it looks very complex, I never succeeded handling port position changing when I tried to make a generic node rotation feature for my project.
Hey, When we make links then they appear by default below node. Is there any way by which we can show them above nodes like in pic below?