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

Delete connection [x] button is displayed out of place on a smartphone #407

Open
gpack opened this issue May 2, 2022 · 8 comments
Open
Assignees
Labels
enhancement New feature or request

Comments

@gpack
Copy link

gpack commented May 2, 2022

I've updated the script so that the "drawflow-delete" icon shows up on a "click" event.
On a desktop (Chrome or Firefox) this is working well, and shows the "x" button on (or close by) the connection line once you click on the line, but on a smartphone (iPhone 13) when you tap the connection line, the button is being placed in weird places, very far away from the connection line.

I've attached a screenshot for reference of what it looks like on a smartphone (see below).

Is this an issue with the "touch" event or something else? Any guidance is appreciated.

delete-button-incorrect-position

thanks.

@jerosoler
Copy link
Owner

Does it happen on android too?
It may be a Safari issue.

To rule out it being a safari issue.

First try to leave-normal and see if it shows normal. (CSS, and Javascript)

If it shows ok! It is a problem of its implementation, if not safari or create a demo that we could check.

@jerosoler jerosoler self-assigned this May 3, 2022
@27pchrisl
Copy link
Contributor

Yes this is an issue with the touch event, Safari doesn't have Touch.client[XY] (https://developer.mozilla.org/en-US/docs/Web/API/Touch/clientX#browser_compatibility) so that value is undefined at

deletebox.style.top = e.clientY * ( this.precanvas.clientHeight / (this.precanvas.clientHeight * this.zoom)) - (this.precanvas.getBoundingClientRect().y * ( this.precanvas.clientHeight / (this.precanvas.clientHeight * this.zoom)) ) + "px";

Changing this to

deletebox.style.top = (e.clientY || e.pageY) * ( this.precanvas.clientHeight ......

appears to resolve the issue. There may be other issues on Safari touch devices where e.clientXY are used in the code.

@gpack
Copy link
Author

gpack commented May 4, 2022

@jerosoler I've only tested on Safari (iPhone) and Chrome (iPhone) and has that bug, but not tested on Android as I don't have an Android phone. I will try source one and test it.

@27pchrisl Thanks for the feedback. It seems like it is a Safari bug (touch event).

I'm running the "drawflow.min.js" and I can't see that line of code you've referenced so I can change it.
Am I running the wrong drawflow.js script (even though everything works fine with "drawflow.min.js" ?

@jerosoler
Copy link
Owner

@27pchrisl

Please try:

    const editor = new Drawflow(id);

    editor.contextmenu = function(e) {
        this.dispatch('contextmenu', e);
        if (e.type === "touchmove") {
            var e_pos_x = e.touches[0].clientX;
            var e_pos_y = e.touches[0].clientY;
        } else {
            var e_pos_x = e.clientX;
            var e_pos_y = e.clientY;
        }
        e.preventDefault();
        if(this.editor_mode === 'fixed' || this.editor_mode === 'view') {
        return false;
        }
        if(this.precanvas.getElementsByClassName("drawflow-delete").length) {
        this.precanvas.getElementsByClassName("drawflow-delete")[0].remove()
        };
        if(this.node_selected || this.connection_selected) {
        var deletebox = document.createElement('div');
        deletebox.classList.add("drawflow-delete");
        deletebox.innerHTML = "x";
        if(this.node_selected) {
            this.node_selected.appendChild(deletebox);

        }
            if(this.connection_selected) {
                deletebox.style.top = e_pos_y * ( this.precanvas.clientHeight / (this.precanvas.clientHeight * this.zoom)) - (this.precanvas.getBoundingClientRect().y *  ( this.precanvas.clientHeight / (this.precanvas.clientHeight * this.zoom)) ) + "px";
                deletebox.style.left = e_pos_x * ( this.precanvas.clientWidth / (this.precanvas.clientWidth * this.zoom)) - (this.precanvas.getBoundingClientRect().x *  ( this.precanvas.clientWidth / (this.precanvas.clientWidth * this.zoom)) ) + "px";
                this.precanvas.appendChild(deletebox);
            }
        }
    }
    
    editor.start();

Add function between new Drawflow.. and editor.start()

And test in Iphone.

@27pchrisl
Copy link
Contributor

This did not work as is - the event comes through as a touchstart. If I change touchmove to touchstart then it works.

@jerosoler
Copy link
Owner

Perfect! I'll upload it tomorrow! ;)

@gpack
Copy link
Author

gpack commented May 5, 2022

I can confirm the above function solved the issue on Safari/smartphone and it now shows the delete icon next to the line.

However there is another strange behaviour I noticed on the phone which could be related to the touch event:
So when you tap on a connection and then try move/pan the canvas around slightly, it throws the canvas way off to the side and out of view of the nodes or to some random coordinate (not smooth panning).
This happens on the live demo too (using smartphone).

How to replicate issue:
Load drawflow on the phone and try touch a connection line (or tap close to the connection line), and then try slightly move the canvas area a little bit, the canvas does a big jump to some random/weird coordinate (not smooth).

@jerosoler jerosoler added the enhancement New feature or request label May 27, 2022
@ArG97
Copy link

ArG97 commented Nov 2, 2022

hi, different length of connection line have different position for X
image
image
image

how to make it fixed even the length changes?

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

No branches or pull requests

4 participants