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

Trying to add link using 'click' to flowchart #188

Closed
barttt opened this issue Jul 17, 2015 · 15 comments
Closed

Trying to add link using 'click' to flowchart #188

barttt opened this issue Jul 17, 2015 · 15 comments

Comments

@barttt
Copy link

barttt commented Jul 17, 2015

I have tried everything that I can think of to get a click event to fire on a flowchart item, per the docs and the test case code, but I cannot figure out what I am doing wrong. I am using mermaid 0.5.1. Here is my code:

<!DOCTYPE html>
<html>
    <head>
        <title>ART Process work-flow</title>

        <link href="//fonts.googleapis.com/css?family=Lato:100" rel="stylesheet" type="text/css">
        <link href="/bower_components/mermaid/dist/mermaid.css" rel="stylesheet" type="text/css">
        <link href="/bower_components/mermaid/dist/mermaid.forest.css" rel="stylesheet" type="text/css">

        <style>

            .title 
            {
                font-size: 48px;
            }
        </style>
        <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
        <script type="text/javascript" src="/bower_components/mermaid/dist/mermaidAPI.js"></script>
        <script>
        mermaidAPI.initialize({startOnLoad:true});

        function myAction(id)
        {
            alert("click fired");
        }

        $(function()
        {
            var graphDefinition = 'graph TB\nProposal-->Contract\nContract-->Planning\nPlanning-->Design\nDesign-->Build\nBuild-->Verification\nVerification-->Delivery\nDelivery-->Support\nclick Design myAction\n';
            mermaidAPI.render('id1',graphDefinition);
        });
        </script>
        </head>
    <body>
                <div class="title">Process WorkFlow (static test)</div>
                  <div class="mermaid">
                    <div class="id1">   </div>
                  </div>
    </body>
</html>

@knsv
Copy link
Collaborator

knsv commented Jul 17, 2015

Sorry to hear that.

Will take a look.

@knsv
Copy link
Collaborator

knsv commented Jul 17, 2015

I see the issue. With the render method you get the svg code back. The bindings done during rendering is void as the whole svg is torned out from the DOM and returned.
:(

@barttt
Copy link
Author

barttt commented Jul 17, 2015

Hi Knut-
Thanks for your very quick reply.

So does this mean that using the render API call will not allow a link (via javascript)?
I really hoped this would work..

@knsv
Copy link
Collaborator

knsv commented Jul 17, 2015

It turns out that it is not hard to fix this so the callback for the render function not only get the svg code back but also a function that sets up the bindings. It would look something like this:

<!DOCTYPE html>
<html>
<head>
    <title>ART Process work-flow</title>
    <meta charset="UTF-8">
    <link href="http://fonts.googleapis.com/css?family=Lato:100" rel="stylesheet" type="text/css">
    <link href="../dist/mermaid.css" rel="stylesheet" type="text/css">
    <link href="../dist/mermaid.forest.css" rel="stylesheet" type="text/css">

    <style>

        .title
        {
            font-size: 48px;
        }
    </style>
    <script src="../dist/mermaidAPI.js"></script>
    <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>

    <script>
        mermaidAPI.initialize({startOnLoad:true});

        function myAction(id)
        {
            alert("click fired");
        }

        $(function()
        {
            var callback = function(code,bindEvents){
                bindEvents();
            }
            var graphDefinition = 'graph TB\nProposal-->Contract\nContract-->Planning\nPlanning-->Design\nDesign-->Build\nBuild-->Verification\nVerification-->Delivery\nDelivery-->Support\nclick Design myAction\n';
            mermaidAPI.render('id1',graphDefinition,callback);
        });
    </script>
</head>
<body>
<div class="title">Process WorkFlow (static test)</div>
    <div id="id2">
    </div>
</body>
</html>

Will commit this in a bit. Not released yet though so if you need this early you need to the latest build.

knsv added a commit that referenced this issue Jul 17, 2015
@barttt
Copy link
Author

barttt commented Jul 17, 2015

Hmm..
Not sure what is wrong, but that doesn't work for me.
What does the bindEvents call do?
And what is code refering to?

@knsv
Copy link
Collaborator

knsv commented Jul 17, 2015

bindEvents is a function that binds the click events as per the graph definition. This must be done after the svg code is in the DOM.

If you get undefined instead of a function it means that you not have the lastest mermaid.

knsv added a commit that referenced this issue Jul 17, 2015
@knsv
Copy link
Collaborator

knsv commented Jul 17, 2015

Something went wrong... Did a rebuild.

Have this code working:

<!DOCTYPE html>
<html>
<head>
    <title>ART Process work-flow</title>
    <meta charset="UTF-8">
    <link href="http://fonts.googleapis.com/css?family=Lato:100" rel="stylesheet" type="text/css">
    <link href="../dist/mermaid.css" rel="stylesheet" type="text/css">
    <link href="../dist/mermaid.forest.css" rel="stylesheet" type="text/css">

    <style>

        .title
        {
            font-size: 48px;
        }
    </style>
    <script src="../dist/mermaidAPI.js"></script>
    <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>

    <script>
        mermaidAPI.initialize({startOnLoad:true});

        function myAction(id)
        {
            alert("click fired");
        }

        $(function()
        {
            var callback = function(code,bindEvents){
                console.log(bindEvents);
                $("#div-id1").html(code);
                bindEvents();
            }
            var graphDefinition = 'graph TB\nProposal-->Contract\nContract-->Planning\nPlanning-->Design\nDesign-->Build\nBuild-->Verification\nVerification-->Delivery\nDelivery-->Support\nclick Design myAction\n';
            mermaidAPI.render('id1',graphDefinition,callback);
        });
    </script>
</head>
<body>
<div class="title">Process WorkFlow (static test)</div>
    <div id="div-id1">
    </div>
</body>
</html>

@barttt
Copy link
Author

barttt commented Jul 17, 2015

Sorry for being a pain..
I don't see what gets passed in for code and bindEvents.
I am using firefox build 39.0 with firebug, and do not see any console log output on startup or if the flow chart elements are clicked.
I do see
web

@barttt
Copy link
Author

barttt commented Jul 17, 2015

Hi Knut-
I tried this code in:
Chrome - renders fine & alert fires
IE9 - rendering is messed up but alert fires

Looks like some browser differences are entering the picture.

Thank you for your timely replies

@barttt
Copy link
Author

barttt commented Jul 17, 2015

I did not catch you mention of mermaid version earlier. I just ran thru the source that I have here. It is marked 0.5.1. Perhaps there is a newer version?

@knsv
Copy link
Collaborator

knsv commented Jul 18, 2015

Tested in Firefox and noticed the problem was again with the css rules.

Change the initalization call to:

mermaidAPI.initialize({startOnLoad:true,cloneCssStyles:false});

Then it works in firefox as well!

@barttt
Copy link
Author

barttt commented Jul 20, 2015

Thank you so much for your help!

@Daijobou
Copy link

This is like dot syntax. In dot you can add "URL" (and "tooltip") to a node. Is URL here not possible? I need each node with a URL. Click on node should open a new page. ;)

@knsv
Copy link
Collaborator

knsv commented Sep 30, 2015

Yes I'll add that. Good what of breaking up a large flowchart top smaller pieces. How should the syntax for the tooltip look?

@knsv
Copy link
Collaborator

knsv commented Sep 30, 2015

Will continue discussions about click/tooltip in add this in issue #34. Will close this issue, let me know any objections.

@knsv knsv closed this as completed Sep 30, 2015
mgenereu pushed a commit to mgenereu/mermaid that referenced this issue Jun 25, 2022
…yarn/develop/autoprefixer-10.2.6

Bump autoprefixer from 10.2.5 to 10.2.6
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

3 participants