Changeset 2455 for SMC


Ignore:
Timestamp:
01/12/13 12:11:16 (11 years ago)
Author:
vronk
Message:

changes in layout and detail rendering;
dirty version with try-out code before clean-up

File:
1 edited

Legend:

Unmodified
Added
Removed
  • SMC/trunk/SMC/src/web/scripts/js/cmd-dep-graph.js

    r2440 r2455  
    11
    22
     3var item_li = null;
    34
    45var svg  = null; // main svg-element
     
    910var detail_data = null; // global holder for detail-data (in html) 
    1011 
     12
     13var index_container_selector = "#index-container";
    1114var graph_container_selector = '#infovis';
    1215var navi_container_selector = '#navigate';
     16var detail_container_selector = "#detail-container";
     17var detail_info_holder_selector =  '#detail-info-holder';
     18
    1319var graph_container = null;
    1420var index_container = null;
     
    2329
    2430var opts = {"depth-before": {"value":2, "min":0, "max":10, "widget":"slider"},
    25             "depth-after":{"value":1, "min":0, "max":10, "widget":"slider"},
     31            "depth-after":{"value":2, "min":0, "max":10, "widget":"slider"},
    2632            "link-distance": {"value":30, "min":10, "max":200, "widget":"slider" },
    2733            "charge":{"value":400, "min":10, "max":1000, "widget":"slider" },
    28             "node-weight": {"value":"usage", "values":["1","usage"], "widget":"selectone" },
     34            "node-weight": {"value":"1", "values":["1","usage"], "widget":"selectone" },
    2935            "curve": {"value":"straight", "values":["straight","arc"], "widget":"selectone" },
    30             "layout": {"value":"dot", "values":["dot","force"], "widget":"selectone" },
     36            "layout": {"value":"horizontal-tree", "values":["vertical-tree", "horizontal-tree", "weak-tree","force","dot"], "widget":"selectone" },
    3137           
    3238            };
     
    4753function loadDetailInfo () {
    4854     
    49   $('#detail-info-holder').load(detail_file)
     55  $(detail_info_holder_selector).load(detail_file,function(data) {
     56     $(detail_container_selector).html(getDetailInfo("summary", "overall"));
     57  });
     58 
    5059 
    5160  /* $.get(detail_file, function(data) {
     
    5766
    5867function getDetailInfo(type, id) {
    59     notify("getDetailInfo: #" + type + "s-" + id );
    60     var d = $('#detail-info-holder').find("#" + type + "s-" + id );
     68    notify("getDetailInfo: #" + type + "-" + id );
     69    var d = $(detail_info_holder_selector).find("#" + type + "-" + id );
    6170    // notify(d);
    6271    return d.html();
     
    126135                                           });
    127136
    128                     renderIndex(data_all.nodes);
     137                    renderIndex_default();
    129138                    //renderGraph(data_all, graph_container);
    130139                });       
    131140}
    132141
     142/* there was a strange problem with overloading */
     143function renderIndex_default () {
     144    renderIndex (data_all.nodes, index_container_selector)
     145}
    133146
    134147/** generate the index lists
    135148    @param nodes - accepts an array of nodes (like in data.nodes)
    136149*/ 
    137 function renderIndex (nodes) {
     150function renderIndex (nodes, target_container_selector) {
     151
    138152    nest = d3.nest()
    139153    .key(function(d) { return d.type; })
     
    141155    .entries(nodes);
    142156 
    143     index_container = d3.select("#index-container");
    144         index_container.selectAll("div").remove();
    145       var group_divs = index_container.selectAll("div").data(nest)
     157    target_container = d3.select(target_container_selector);
     158        target_container.selectAll("div").remove();
     159       
     160        // rendering extra-information about the displayed data only in detail-index
     161        if (target_container_selector != index_container_selector) {
     162           target_container.append("span")
     163                .text("show nodes: " + data_show.nodes.length + "; "
     164                        + "show links: " + data_show.links.length);
     165           }
     166           
     167        var group_divs = target_container.selectAll("div").data(nest)
    146168                        .enter().append("div")
    147169                        .attr("id", function (d) { return "detail-" + d.key })
     
    149171                       
    150172      var group_headers = group_divs.append("div").classed("header", 1)
    151                         .text(function (d) { return d.key});
     173                        .text(function (d) { return d.key + " |" + d.values.length + "|"});
    152174                       
    153       var item_li = group_divs.append("div").classed("content",1)
    154                     .append("ul").selectAll(".node-item")       
     175      var list =  group_divs.append("div").classed("content",1)
     176                    .append("ul");
     177      var item_li = list.selectAll(".node-item")       
    155178                    .data(function(d) { return d.values; })
    156179                    .enter().append("li")
    157180                    .attr("class", "node-item")
    158                         .attr("id", function (d) { return "n-" + d.name })
    159                         .text(function (d) { return d.name})
    160                         .classed("highlight", function (d) { return d.selected })
    161                         .on("click", function(d) { d.selected= d.selected ? 0 : 1 ; updateSelected() });
     181                    .text(function (d) { return d.name})
     182                    .on("click", function(d) { d.selected= d.selected ? 0 : 1 ; updateSelected() });
     183         
     184                   
     185            /* slightly different behaviour for the main-index and rendering of the selected nodes in the detail-view */
     186          //  console.log("target_container:" + target_container_selector);
     187            if (target_container_selector == index_container_selector) {
     188                index_container = target_container;
     189                item_li.attr("id", function (d) { return "n-" + d.name });
     190                item_li.classed("highlight", function (d) { return d.selected });
     191               
     192              } else {
     193                 var item_detail = item_li.append("div")
     194                            .classed("node-detail", 1);
     195                           
     196                        item_detail.text(function (d) { return "links_in: " +  dataShowCount(d.key, "links_in") +  "; links_out: " +  dataShowCount(d.key, "links_out") ;
     197                                                       })
     198                                .append("a")
     199                      .attr("href",function (d) { if (d.type.toLowerCase()=='datcat') return d.id
     200                                                        else return comp_reg_url + d.id })
     201                      .text(function (d) { return d.id });
     202            item_detail.append("div").html(
     203                          function (d) { var detail_info_div = getDetailInfo(d.type.toLowerCase(), d.key);
     204                                            if (detail_info_div) {return detail_info_div } else
     205                                                { return  "<div>No detail</div>"; }
     206                          });
     207                           
     208         
     209                       
     210              }
    162211                        //.classed("detail", 1);
    163                        
    164   handleUIBlock($(".cmds-ui-block"));   
     212                        //console.log($(target_container_selector).find(".cmds-ui-block"));
     213   handleUIBlock($(target_container_selector).find(".cmds-ui-block"));
     214 
    165215}
    166216
    167217function filterIndex (search_string){
    168218    var filtered_index_nodes = data_all.nodes.filter(function(d, i) {
    169         console.log(d.name.indexOf(search_string));
    170         return d.name.indexOf(search_string) > -1;
     219     //   console.log(d.name.indexOf(search_string));
     220        return d.name.toLowerCase().indexOf(search_string) > -1;
    171221    });
    172222    console.log(filtered_index_nodes);
    173     renderIndex(filtered_index_nodes);
     223    renderIndex(filtered_index_nodes, index_container_selector);
    174224}
    175225
     
    190240       $(target_container).text("");
    191241     }
    192     var w = $(target_container).width(),
    193         h = $(target_container).height();
     242   
     243 
     244   var w = $(target_container).width(),
     245        h = $(target_container).height();
     246     
     247 
    194248        // console.log (w + '-' + h);
    195249     var force = d3.layout.force()
     
    197251            .links(data.links)
    198252            .size([w, h])
     253        //   .gravity(0)
    199254            .linkDistance(opt("link-distance"))
    200255            .charge(opt("charge") * -1)
    201256            .on("tick", tick)
    202257            .start();
    203                  
     258    console.log ("gravity: " + force.gravity() );             
    204259         // remove old render:
    205260          d3.select(graph_container_selector).selectAll("svg").remove();
     
    238293            .attr("r", function(d) { if (opt("node-weight")=="1"){ return min_circle }
    239294                                        else {return (Math.sqrt(d.count)>min_circle ? Math.sqrt(d.count) * 2 : min_circle); } })
    240             .attr("x", function(d) {return d.init_x;})
    241             .attr("y", function(d) {return d.init_y;})
     295          /*  .attr("x", function(d) {return d.x;})
     296            .attr("y", function(d) {return d.y;})*/
    242297            .call(force.drag);
    243298       
     
    249304            .classed("selected", function(d) { return d.selected; })
    250305          .on("click", function(d) {d.selected= d.selected ? 0 : 1; updateSelected() });
     306          .on("mouseover", function(d) {console.log(this)});
    251307       
    252308         
     
    273329            .text(function(d) { return d.name; });
    274330
    275  
     331
     332
    276333  /*
    277334  force.start();
     
    304361
    305362   function tick(e) {
     363    var link_distance = parseInt(opt("link-distance"));     
     364   var k =  10 * e.alpha;
     365          if (opt("layout")=='dot') {
     366            var link_distance_int = parseInt(opt("link-distance"));
     367            data.links.forEach(function(d, i) {
     368              d.source.x = (d.source.init_x / 150 * link_distance_int) ;
     369              d.target.x = (d.target.init_x / 150 * link_distance_int);
     370              //d.target.y  += (d.target.init_y / 300 ) * k;
     371  /*            d.source.x = (d.source.level * link_distance_int) + link_distance_int;
     372              d.target.x = (d.target.level * link_distance_int) + link_distance_int;*/
     373              /*d.source.x = d.source.level * 2 * opt("link-distance") + 50;
     374              d.target.x = d.target.level * 2 * opt("link-distance") + 50;*/
     375            });
     376          } else if (opt("layout")=='weak-tree') {
     377              data.links.forEach(function(d, i) {
     378              d.source.x -= k;
     379                d.target.x += k;
     380               
     381                //d.source.x -= k * d.source.level / (dataShowCount(d.source.key, "links_out") + 0.1);  // 0.1 to prevent div/0
     382                //d.target.x += k * d.target.level / (dataShowCount(d.target.key, "links_in") + 0.1);
     383                });
     384          } else if (opt("layout")=='vertical-tree') {
     385                   var ky= 1.4 * e.alpha, kx = .4 * e.alpha;
     386                   data.links.forEach(function(d, i) {
     387                     if (d.source.level==0) { d.source.y = 20 };
     388                     d.target.x += (d.source.x - d.target.x)  * kx;
     389                     d.target.y += (d.source.y - d.target.y + link_distance) * ky;
     390                    });
     391           } else if (opt("layout")=='horizontal-tree') {
     392                   var kx= 1.4 * e.alpha, ky = .4 * e.alpha;
     393                   data.links.forEach(function(d, i) {
     394                       if (d.source.level==0) { d.source.x = 20 };
     395                       d.target.y += (d.source.y - d.target.y)  * ky;
     396                       d.target.x += (d.source.x - d.target.x + link_distance  ) * kx;
     397                  });
     398            }
     399     
     400           /*  parent foci
     401                  var kx = 1.2 * e.alpha;
     402    data.links.forEach(function(d, i) {
     403      d.target.x += (d.target.level * link_distance  - d.target.x) * kx;
     404      });*/
     405     
     406      /*  obsoleted:
     407      /*data.links.forEach(function(d, i) {
     408                d.source.x -= (k * d.source.init_x  / (200 * Math.sqrt(d.source.count)) );
     409                d.target.x += (k * d.target.init_x / (50 * Math.sqrt(d.target.count)) );
     410                });*/
    306411         
    307    var k =  e.alpha;
    308           if (opt("layout")=='dot') {
    309           var link_distance_int = parseInt(opt("link-distance"));
    310           data.links.forEach(function(d, i) {
    311             d.source.x = (d.source.init_x / 150 * link_distance_int) ;
    312             d.target.x = (d.target.init_x / 150 * link_distance_int);
    313 /*            d.source.x = (d.source.level * link_distance_int) + link_distance_int;
    314             d.target.x = (d.target.level * link_distance_int) + link_distance_int;*/
    315             /*d.source.x = d.source.level * 2 * opt("link-distance") + 50;
    316             d.target.x = d.target.level * 2 * opt("link-distance") + 50;*/
    317           });
    318           }
    319          
    320412         /*d.source.y = d.source.init_y - d.source.y * k;
    321413           d.target.y = d.target.init_y + d.target.y * k;*/
     
    327419              //d.target.x += d.target.level * 0.2;
    328420         
    329                transform();
    330    }
     421       transform();
     422   } // end  tick()
    331423
    332424
     
    396488*/ 
    397489function renderDetail (nodes) {
     490   
     491    renderIndex (nodes, detail_container_selector);
     492}
     493
     494function renderDetail_old (nodes) {
    398495    /*
    399496    nest = d3.nest()
     
    463560    renderDetail(nodes_sel);
    464561   
    465     index_container.selectAll("li").classed("highlight", function (d) { return d.selected });   
    466 }
    467 
    468 
    469 
    470 /**  generates the subset of data to display (based on selected nodes + options) */
     562 //   index_container.selectAll("li").classed("highlight", function (d) { return d.selected });   
     563}
     564
     565
     566
     567/**  generates the subset of data to display (based on selected nodes + options)
     568fills global variable: data_show !
     569*/
    471570function dataToShow (nodes) {
    472571     data_show = {};
     
    484583     data_show.nodes = unique_nodes(nodes.concat(data_show_collect.nodes));
    485584     data_show.links = unique_links(data_show_collect.links);
    486              
     585     
     586     // extend the object, with some lookup hashes on neighbourhood
     587     hashes = gen_neighbours(data_show.links);
     588     data_show = $.extend(data_show, hashes);
    487589/* data_show.nodes.forEach; data_all.links;
    488590.filter(function(e) {*/
     
    495597    }
    496598
    497 
     599/** generate lookup hashes for neighbours;
     600*/
     601function gen_neighbours(links) {
     602
     603    var neighbours = {"links_index": {},
     604                      "nodes_in": {}, "nodes_out": {},
     605                      "links_in": {}, "links_out": {}};
     606   
     607        links.forEach(function(d) {
     608                            src_key = d.source.key;
     609                            trg_key = d.target.key;
     610                         // generate lookup hashes for neighbours;
     611                            neighbours.links_index[src_key + "," + trg_key] = d;
     612                            if (d.source) {
     613                                    if (! neighbours.nodes_in[trg_key]) {
     614                                        neighbours.nodes_in[trg_key] = [d.source];
     615                                        neighbours.links_in[trg_key] = [d];
     616                                     }  else {
     617                                        neighbours.nodes_in[trg_key].push(d.source);
     618                                        neighbours.links_in[trg_key].push(d);
     619                                     }
     620                             }
     621                            if (d.target) {
     622                                    if (! neighbours.nodes_out[src_key]) {
     623                                        neighbours.nodes_out[src_key] = [d.target];
     624                                        neighbours.links_out[src_key] = [d];
     625                                    } else {
     626                                        neighbours.nodes_out[src_key].push(d.target);
     627                                        neighbours.links_out[src_key].push(d) ;
     628                                    }
     629                             }
     630                       });
     631                       
     632return neighbours;
     633
     634}
     635
     636function dataShowCount(n_key, info_type) {
     637
     638    if (data_show[info_type][n_key]) {
     639        return data_show[info_type][n_key].length;
     640       } else {
     641        return 0
     642       }
     643}
    498644/** returns appropriate link
    499645*/
     
    636782         } else if (opts[key].widget =="selectone") {
    637783            [new_input,new_widget] = genCombo(key, opts[key].values);
    638              
     784            // set initial value
     785            $(new_input).val(opts[key].value);
    639786           
    640787        //     $(new_input).autocomplete({"source":opts[key].values});
Note: See TracChangeset for help on using the changeset viewer.