Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnregisterBehaviour bug #475

Open
toczekmj opened this issue Sep 30, 2024 · 3 comments
Open

UnregisterBehaviour bug #475

toczekmj opened this issue Sep 30, 2024 · 3 comments

Comments

@toczekmj
Copy link

toczekmj commented Sep 30, 2024

Hi.
Today I've experienced weird bug related to overwriting existing selection behavior.
Our app seems to work fine while using default settings (example below)

Working.edited.-.Made.with.Clipchamp.mp4

But when we overwrite selection behaviour either with the default one, or with custom implementation, cards starts to behave unexpectedly. Namely in order to move a particular card we need to double click it, otherwise previously selected card is being moved. Example below:

Not.working.edited.-.Made.with.Clipchamp.mp4

This os our diagram configuration (working version, without overwriting default behavior)

var options = new BlazorDiagramOptions
        {
            LinksLayerOrder = 10,
            NodesLayerOrder = 10,
            AllowMultiSelection = true,
            Zoom =
            {
                Enabled = true,
                Minimum = 0.3,
            },
            Links =
            {
                DefaultRouter = new NormalRouter(),
                DefaultPathGenerator = new SmoothPathGenerator()
            },
        };

        var diagram = new BlazorDiagram(options);

And this is the overwriten version:

var options = new BlazorDiagramOptions
        {
            LinksLayerOrder = 10,
            NodesLayerOrder = 10,
            AllowMultiSelection = true,
            Zoom =
            {
                Enabled = true,
                Minimum = 0.3,
            },
            Links =
            {
                DefaultRouter = new NormalRouter(),
                DefaultPathGenerator = new SmoothPathGenerator()
            },
        };

        var diagram = new BlazorDiagram(options);
        diagram.UnregisterBehavior<SelectionBehavior>();
        diagram.RegisterBehavior(new SelectionBehavior(diagram));

It seems like some event is not being disposed while unregistering the behavior, but we really have no idea what is going on. Hope someone will help us.

@toczekmj
Copy link
Author

@FlaviusAugustus

@zHaytam
Copy link
Collaborator

zHaytam commented Dec 3, 2024

Hello, I will check this out!

@zHaytam
Copy link
Collaborator

zHaytam commented Dec 3, 2024

Hey, I found why this happens:

  • SelectionBehavior is the first behavior registered in the diagram by default
  • The others, such as DragMovablesBehavior come after
  • The drag movables one moves the selected node, but the selected node is decided by the selection behavior

When you add back the selection behavior last, its events are AFTER the drag movables on, which means that it will try to move the previously selected element and then select the newly clicked one.

To fix this, I have added a new parameter in the constructor of BlazorDiagram:

var diagram = new BlazorDiagram(options, registerDefaultBehaviors: false);
diagram.RegisterBehavior(new SelectionBehavior(diagram)); // or yours
diagram.RegisterBehavior(new DragMovablesBehavior(diagram));
diagram.RegisterBehavior(new DragNewLinkBehavior(diagram));
diagram.RegisterBehavior(new PanBehavior(diagram));
diagram.RegisterBehavior(new ZoomBehavior(diagram));
diagram.RegisterBehavior(new EventsBehavior(diagram));
diagram.RegisterBehavior(new KeyboardShortcutsBehavior(diagram));
diagram.RegisterBehavior(new ControlsBehavior(diagram));
diagram.RegisterBehavior(new VirtualizationBehavior(diagram));

For now this should unblock you, but I'm not very happy with the fact that users need to know all the default behaviors and their orders, I'll see if I can think of a better solution or maybe you guys have a suggestion!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants