bramp / js-sequence-diagrams

Draws simple SVG sequence diagrams from textual representation of the diagram
https://bramp.github.io/js-sequence-diagrams/
BSD 2-Clause "Simplified" License
7.81k stars 1.08k forks source link

Is it possible to make parts of the sequence diagrams hyperlinkable? #154

Open pkanthi opened 8 years ago

pkanthi commented 8 years ago

Currently the Sequence diagram generated is pretty static and only good for rendering purposes. To make it interactive, it would be good to allow hyperlinks in the grammar.

gasparch commented 7 years ago

It is SVG, we can put JS handlers over it, no? It will require some classes on elements, tho

Chetabahana commented 6 years ago

We can do hyperlinked and coloring as well like this

function trydrawSVG(val) {
    try {
         ....
    }catch(err) {
         ....
     } finally {
     //to be executed regardless of the try / catch result
    checkReady();
 }

 function checkReady() {

    var svg = $('.diagram').find('svg')[0];
    if (!svg) {
        setTimeout(function(){ checkReady(); }, 300);
    } else { 

        var svgobj = svg.children;
        for (i = 0; i < svgobj.length; i++) {
        element = svgobj[i];
        element.style = "cursor: pointer;";

        $(element).mouseover(function(evt){
        $(this).hide(100).show(100)
        });

        $(element).click(function(evt){
            $(this).find('rect').css({ fill: 'yellow' });
          if($(this).attr("class") == "signal"){
             window.open('https://www.google.com/')
          }
        });

     }       
    }

  } 

You can check also how it runs hyperlinkable and color filled in jsFiddle https://jsfiddle.net/chetabahana/f7ejxhnk/35/