jsplumb / community-edition

The community edition of jsPlumb, versions 1.x - 6.x
https://jsplumbtoolkit.com
Other
191 stars 14 forks source link

Can I create a standalone `connector` ? #48

Open bq-hentai opened 6 years ago

bq-hentai commented 6 years ago

We can use instance.connect to connect two endpoints. But can we create a connector whose source/target is not exist?

P.S. I checked the connect function and found this.

        if (_p) {
                if (_p.source == null && _p.sourceEndpoint == null) {
                    _ju.log("Cannot establish connection - source does not exist");
                    return;
                }
                if (_p.target == null && _p.targetEndpoint == null) {
                    _ju.log("Cannot establish connection - target does not exist");
                    return;
                }
                _ensureContainer(_p.source);
                // create the connection.  it is not yet registered
                jpc = _newConnection(_p);
                // now add it the model, fire an event, and redraw
                _finaliseConnection(jpc, _p);
            }

So it seems that we can't do this now.

sporritt commented 6 years ago

Not at the moment, no, but this concept has been floated before and it's an interesting idea. Give me a few days to go back and look at the various places I've talked about this with people and I'll drop an update in here with some questions about how something like this could behave.

bq-hentai commented 6 years ago

@sporritt Sry for late reply.

I have some additional notes as for the concept. There is a real use case for me.

If a judge node has two following nodes. And when I create the judge node, I don't know the exact following node or the following node is already exist or will be created in the future. If I should remain the judge conditions, I must create the exact judge node and the connectors. After I create this, I can do anything I can do in the future. Maybe drag a node to the end of a connector, may create one and then connect them.

I guess if jsPlumb support this behaviour, the codebase will have a big change.

P.s you can see this flowchart tool. Hope you can understand the page.

By the way, I can't move the connector to another endpoint by drag it if I set maxConnections: -1 or any more than 1?

jwerre commented 6 years ago

You could just create an invisible target somewhere on the stage if the connection has been broken.

sporritt commented 6 years ago

as a workaround this could work, yes. you'd need to be mindful of the fact that jsPlumb uses offsetLeft and offsetTop properties to get the position of elements, so "invisible" would have to mean visibility:hidden, or a very small size, or opacity:0...not display:none.

this is in fact what jsPlumb will do when this gets implemented. well, one of those options anyway. or maybe a combination, who knows? the unknown future is so exciting. um. but there's definitely a place for this concept in the API.

bq-hentai commented 6 years ago

@jwerre Thanks for ur reply.

Of course, it is ok at first. But pls consider following situation. I need to create a standalone connector, i.e., I will drag a node t o the end of the connector. How can I control this.

Btw, as for presentation and interaction, svg elsments present via the order of the DOM. So When create a visible element(opacity: 0 or visibility:hidden or even small width), the order should Be thought about. As an enhancement, I think the sort api maight Be good.

Maybe, for additional target, the AdditionalTargetManager is necessary.

As for jsPlumb's design, maybe This way

bq-hentai commented 6 years ago

Sorry for My foolish operation. Today is Chinese Labor day:) And I am using my phone not pc.

As for jsPlumb's design, maybe add additional etarget is the easiest way.