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

Link restriction functionality #33

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open

Conversation

rpallares
Copy link

Hi,

Here is the pull request for the link restrictions.
The parameter is optional and allow to add an array of restrictions.
Only the mapped links are allowed.
Restrictions are working on operator types.

@sdrdis
Copy link
Owner

sdrdis commented Feb 5, 2017

Hi,

Sorry again for my late answer. Your PR is interesting and includes a functionality that some people definitely need (me included).

However, I thought about it for a long time, and I have come to the conclusion that the feature must be included in a different way, for the following reasons:

  • First, the plugin is beginning to be very large, making it difficult to maintain.
  • Secondly, depending on the usage, there could exist many different ways of defining link restrictions. For instance, for my usage, I would need a tag system (only connectors with at least one common tag could be connected)

Therefore, I suggest we include your code in a different way. I added today events on the flowchart plugin that can be catched in order to add functionalities. We can integrate your functionality in a sub plugin that could be included when people need it. It would be the first of its kind (hoping that many will follow 😄), you would retain ownership and could easily add more features. I would of course list the sub plugin in the README file and the demo website.

I have a small proof of concept you can begin to work with. Of course, you would need to add some entries in the plugin to include all the features you have worked on. Here is the subplugin, in the form of a simple jquery plugin:

(function( $ ) {
 
    $.fn.flowchartRestrictions = function(restrictions) {
        this.on('linkCreate', function(el, linkId, linkData, returnHash) {
            var isLinkValid = false;
            var restriction;
            for (var i = 0; i < restrictions.length; i++) {
                restriction = restrictions[i];
                if (linkData.fromOperator == restriction.fromOperator &&
                    linkData.fromConnector == restriction.fromConnector &&
                    linkData.toOperator == restriction.toOperator &&
                    linkData.toConnector == restriction.toConnector) {
                    isLinkValid = true;
                    break;
                }
            }
            
            if (!isLinkValid) {
                returnHash.result = false;
            } else {
                if (typeof restriction.color != 'undefined') {
                    linkData.color = restriction.color;
                }
            }
        });
    };
 
}( jQuery ));

It could be called like that:

    $('#example_3').flowchartRestrictions(
      [
        {
          fromOperator: 'operator1',
          fromConnector: 'output_1',
          toOperator: 'operator2',
          toConnector: 'input_2',
          color: '#FF0000'
        }
      ]
    );

    // Apply the plugin on a standard, empty div...
    $('#example_3').flowchart({
      data: data
    });

A full example can be found in example 3 of the tmp_subplugin_demo branch of the demo repository (https://github.com/sdrdis/jquery.flowchart-demo/tree/tmp_subplugin_demo).

What is your opinion about it ?

Don't hesitate to ask any question or suggestion...

@rpallares
Copy link
Author

Hi,

Thanks for your analyse.
I'm sorry I don't have any more time to develop that feature.

I don't really care about the feature ownership, but that's very friendly to think about that. I developed it for my professional work, and normally I shouldn't request for pulling....
You can cite me into the readme for inspiration :)

You idea seems to be better and cleaner than mine, I'm not very skilled in JavaScript...
So do it as you want, I know that will be perfect.
Just be careful with link restrictions, In last version I use the operator type to compute restriction not the operator id as mentioned into your short example. The big advantage is to that not require to declare the restriction for each operator created.

Regards

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

Successfully merging this pull request may close these issues.

2 participants