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

node click is not effective #272

Closed
ekoz opened this issue Dec 23, 2015 · 4 comments
Closed

node click is not effective #272

ekoz opened this issue Dec 23, 2015 · 4 comments
Labels
Type: Other Not an enhancement or a bug

Comments

@ekoz
Copy link

ekoz commented Dec 23, 2015

I defined a js function on page, and bind a click event to the node, but it is not effective, on the api guide, your demo is also not effect, but tooltip is ok.

<script type="text/javascripit">
    function onNodeClick(nodeId){
        alert(nodeId);
    }
</script>

the graph script is

graph LR;

A((start))-->B(step1);
B-->C[step2];
C-->D{step3};
D-->E[end];

classDef green fill:#9f6,stroke:#333,stroke-width:1px;
class A,B,C,D,E green;

click B onNodeClick "tooltip"

is there something wrong with my code?

@knsv
Copy link
Collaborator

knsv commented Dec 26, 2015

No I think not.

When I try you code it works fine. What version and browser are you one?

@ekoz
Copy link
Author

ekoz commented Dec 26, 2015

thank you for your reply. the mermaid version is 0.5.6 , I try the code on chrome (47.0.2526.106) and firefox both. my code is here.

      ...
       <script type="text/javascript">
            var callback = function(){
                alert('A callback was triggered');
            }
            mermaid.initialize({startOnLoad:false});

            $(function(){
                var html = mermaidAPI.render('panel', $('textarea').text());
                $('#penel').html(html);
            });
        </script>
    </head>
    <body>
        <div id="penel"></div>
        <textarea style="width:100%;height:300px;">
graph LR;

A((start))-->B(step1);
B-->C[step2];
C-->D{step3};
D-->E[end];

classDef green cursor:pointer,fill:#9f6,stroke:#333,stroke-width:1px;
class A,B,C,D,E green;

click B callback "tooltip"
        </textarea>
    </body>

by the way, if I click a node, could I get the parent node and children nodes, and the in-link, out-links?

@knsv
Copy link
Collaborator

knsv commented Dec 26, 2015

I see the problem now.

As you are using the render function you need to bind the event handlers to the svg code you recieved after ijnserting it in to the dom.

Look here for more info:
http://knsv.github.io/mermaid/#sample-of-api-usage-together-with-browserify

There are unfortunately no support currently for the parent/children arguments to the callback for the click.

@knsv knsv added Type: Other Not an enhancement or a bug Fixed labels Dec 27, 2015
@ekoz
Copy link
Author

ekoz commented Dec 28, 2015

thank you, I get it. I think there is some other way to bind click function, and also get the click node info.

                //get all nodes
                var nodes = $('g[class="nodes"] g[class="node"]');
                $(nodes).css({'cursor': 'pointer'});
                $(nodes).on('click', function(){
                    //get current node
                    var id = $(this).attr('id');
                    var text = $(this).find('foreignObject div').html();
                    alert('id is ' + id + ', text is ' + text);

                    //get sibling nodes

                    //get in link

                    //get parent node

                    //get out link

                    //get children nodes


                });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Other Not an enhancement or a bug
Projects
None yet
Development

No branches or pull requests

3 participants