Changeset 3431


Ignore:
Timestamp:
08/20/13 11:15:33 (11 years ago)
Author:
vronk
Message:

added external links to profiles, enhance init steps, add function: selectNodeByKey

File:
1 edited

Legend:

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

    r2488 r3431  
    1414var input_prefix = "input-";
    1515var select_rect_min_size = 5;
     16var first_level_margin = 20;
    1617var min_circle = 4;
    17 var comp_reg_url = "http://catalog.clarin.eu/ds/ComponentRegistry/?item=";     
     18var max_circle = 50;
     19var comp_reg_url = "http://catalog.clarin.eu/ds/ComponentRegistry/?item=";
     20var mdrepo_url_search = "http://localhost:8680/exist/apps/cr-xq/mdrepo/index.html?operation=searchRetrieve&x-context=&query=";
     21/*http://localhost:8680/exist/apps/cr-xq/mdrepo/fcs?operation=scan&scanClause=cmd:CountryName&x-context=&x-format=htmlpage*/
     22var mdrepo_url_scan = "http://localhost:8680/exist/apps/cr-xq/mdrepo/fcs?operation=scan&x-context=&x-format=htmlpage&sort=size&scanClause=";
    1823/*var source_file = "../scripts/cmd-dep-graph-d3_all_svg.json"*/
    1924/*var source_file = "file:/C:/Users/m/3/clarin/_repo/SMC/output/cmd-dep-graph.d3.js"
    2025var detail_file = "file:/C:/Users/m/3/clarin/_repo/SMC/output/smc_stats_detail.html"
    2126*/
    22 var source_file = "/smc/cmd-dep-graph.d3.js";
    23 var detail_file = "/smc/smc_stats_detail.html";
    24 var userdocs_file = "/smc/userdocs.html";
    25  
     27/*
     28var source_file = "/smc/_structure-graph.json";
     29var source_file = "cmd-dep-graph.d3.js";
     30var detail_file = "smc_stats_detail.html";
     31var userdocs_file = "userdocs.html";
     32*/
     33var source_file = "/smc/cmd-dep-graph_profiles-datcats.json";
     34/*var source_file = "/smc/cmd-dep-graph.d3.js";*/
     35var detail_file = "smc_stats_detail.html";
     36var userdocs_file = "userdocs.html";
     37
    2638var opts = {"depth-before": {"value":2, "min":0, "max":10, "widget":"slider"},
    2739            "depth-after":{"value":2, "min":0, "max":10, "widget":"slider"},
    2840            "link-distance": {"value":120, "min":10, "max":300, "widget":"slider" },
    2941            "charge":{"value":250, "min":10, "max":1000, "widget":"slider" },
     42            "friction":{"value":75, "min":1, "max":100, "widget":"slider" },
    3043            "node-size": {"value":"4", "values":["1","4","8","16","usage"], "widget":"selectone" },
    31             "labels": {"value":"hide", "values":["show","hide"], "widget":"selectone" },                         
     44            "labels": {"value":"show", "values":["show","hide"], "widget":"selectone" },                         
    3245            "curve": {"value":"straight", "values":["straight","arc"], "widget":"selectone" },
    3346           "layout": {"value":"horizontal-tree", "values":["vertical-tree", "horizontal-tree", "weak-tree","force","dot", "freeze"], "widget":"selectone" },
    3447            "selected": {"widget":"hidden" },
    3548            "link": {"widget":"link", "label":""},
    36             "download": {"widget":"link", "label":""}
     49            "download": {"widget":"link", "label":""},
     50            "add_profile": {"widget":"link", "label":"Add profile", "widget":""}
    3751            };
    3852
     
    7387                 add_lookups(data_all);
    7488                 
     89                 // get min/max on some properties
    7590                 var init_x_arr = [];
    7691                    data_all.nodes.forEach(function(d,i){init_x_arr.push(d.init_x);})
    77                            
    7892                 data_all.init_x_min = d3.min(init_x_arr);
    7993                 data_all.init_x_max = d3.max(init_x_arr);
     94
     95                 var init_level = [];
     96                    data_all.nodes.forEach(function(d,i){init_level.push(+d.level);})
     97                    data_all.level_min = d3.min(init_level);
     98               
     99                 var init_count = [];
     100                    data_all.nodes.forEach(function(d,i){init_count.push(+d.count);})
     101                 
     102                 data_all.count_max = d3.max(init_count);
     103                 data_all.node_size_ratio = Math.sqrt(data_all.count_max) / max_circle;
     104
     105                notifyUser("count max: " + data_all.count_max + "; "
     106                        + "node_size_ratio: " + data_all.node_size_ratio);
    80107                 
    81108                 // should be delivered by the data directly
     
    87114                  // get selected nodes (if any) from param
    88115                  selected_ids = opt("selected").split(",");
    89                   var selected_match = 0;
     116                  selectNodeByKey(selected_ids);
     117                  /*var selected_match = 0;
    90118                    for (var i = 0; i < selected_ids.length; i++)
    91119                    {  if (data_all.nodes_index[selected_ids[i]]) {
     
    96124                  // if something was selected, update and render Graph and Detail
    97125                  if (selected_match) { updateSelected();}
    98                    
     126                  */ 
    99127              renderIndex();
    100128   
     
    148176                    .attr("class", "node-item");
    149177               item_li.append("span")
    150                     .text(function (d) { return d.name})
     178                    .text(function (d) { return d.name + ' |' + d.count + '|' })
    151179                    .on("click", function(d) { d.selected= d.selected ? 0 : 1 ; updateSelected() });
    152180         
     
    162190               
    163191              } else {
    164                  var item_detail = item_li.append("div")
    165                                           .classed("node-detail", 1);
     192                 var item_detail = item_li.append("div");
     193                                        /*  .classed("node-detail", 1);*/
    166194                           
    167195                 item_detail.append("a")
     
    169197                                                        else return comp_reg_url + d.id })
    170198                            .text(function (d) { return d.id });
    171                  item_detail.append("div").html(
     199               
     200                profile_item_detail = item_detail.filter(function(d, i) { return d.type.toLowerCase()=='profile' });
     201                profile_item_detail.append("a")
     202                            .attr("target",'_blank')
     203                            .attr("href",function (d) { return 'profiles/' + d.key + '.html' })
     204                            .text(' html-view ');
     205               
     206/*                profile_item_detail.append("a")*/
     207                item_detail.append("a")
     208                            .classed("scan", function (d) {  return !(d.type=='Profile') } )
     209                            .attr("target",'_blank')
     210                            .attr("href",function (d) { if (d.type=='Profile') { return mdrepo_url_search +  'cmd.profile=%22' + d.id + '%22'; }
     211                                                          else { return mdrepo_url_scan +  'cmd:' +  d.name; }   }  )
     212                            .text(' mdrepo-view ');
     213               
     214                 item_detail_detail = item_detail.append("div").html(
    172215                                 function (d) {
    173216                                    var detail_info_div = getDetailInfo(d.type.toLowerCase(), d.key);
     
    178221                                    }
    179222                          });
     223                         
     224                 item_detail_detail.classed("node-detail", 1);
    180225                           
    181226              }
     
    229274            .size([w, h])
    230275            //.gravity(0.3)
    231             .friction(0.7)
     276            .friction(parseInt(opt("friction")) / 100 )
    232277            .linkDistance(parseInt(opt("link-distance")))
    233278            .charge(parseInt(opt("charge")) * -1)
     
    281326                      .classed("selected", function(d) { return d.selected; })
    282327                      .call(force.drag);
    283          
     328                     
    284329          // dragging of all selected nodes on freeze layout
    285330          // this does not work yet
     
    319364                    .on("click", function(d) {d.selected= d.selected ? 0 : 1; updateSelected() })
    320365                      .on("mouseover", highlight()).on("mouseout", unhighlight())
    321             .attr("r", function(d) { if (opt("node-size")=="usage") {return (Math.sqrt(d.count)>min_circle ? Math.sqrt(d.count) * 2 : min_circle); }
     366            .attr("r", function(d) { if (opt("node-size")=="usage")
     367                                        {return (Math.sqrt(d.count)<=min_circle) ?  min_circle  : Math.sqrt(d.count) / data_all.node_size_ratio;                                       
     368                                        }
    322369                                        else { return node_size_int; }
    323370                                    })   
    324371           
    325372            gnodes.append("title")
    326                   .text(function(d) { return d.name; });
     373                .text(function (d) { return d.name + ' |' + d.count + '|' })
     374/*                  .text(function(d) { return d.name; });*/
     375                 
    327376                 
    328377     
     
    376425                   var ky= 1.4 * e.alpha, kx = .4 * e.alpha;
    377426                   data.links.forEach(function(d, i) {
    378                      if (d.source.level==0) { d.source.y = 20 };
     427                     if (d.source.level==data_all.level_min) { d.source.y = first_level_margin };
    379428                   //  d.target.x += (d.source.x - d.target.x)  * kx;
    380429                     d.target.y += (d.source.y - d.target.y + link_distance_int) * ky;
     
    383432                   var kx= 1.4 * e.alpha, ky = .4 * e.alpha;
    384433                   data.links.forEach(function(d, i) {
    385                        if (d.source.level==0) { d.source.x = 20 };
     434                       if (d.source.level==data_all.level_min) { d.source.x = first_level_margin };
    386435                       //d.target.y += (d.source.y - d.target.y)  * ky;
    387436                       d.target.x += (d.source.x - d.target.x + link_distance_int  ) * kx;
     
    466515     
    467516  $(detail_info_holder_selector).load(detail_file,function(data) {
    468      $(detail_container_selector).html(
     517     $(detail_container_selector).find("h3").after(
    469518     '<div id="detail-summary-overall" class="cmds-ui-block init-show" ><div class="header">Overview</div><div class="content">'
    470519     + getDetailInfo("summary", "overall") + '</div></div>');
     
    472521     handleUIBlock($(detail_container_selector).find(".cmds-ui-block"));
    473522     
     523     // only render detail for initially selected nodes, after the detail info has been loaded
     524     if (nodes_sel) { renderDetail(nodes_sel) };
     525     
    474526  });
    475  
    476   // loading userdocs as welcome info
    477   $(graph_container).load(userdocs_file + " div.document");
    478527 
    479528  // loading css to store in extra variable, for later use = injecting into exported SVG
     
    505554    var svg_h = svg.attr("height");
    506555    var bounds = graphBounds();
    507     var margin = 20;
     556    var margin = 30;
    508557    var link_dist = parseInt(opt("link-distance"));
    509558   
     
    511560    x = Math.floor(bounds["x-min"]) - margin
    512561    y = Math.floor(bounds["y-min"]) - margin
    513     w = (bounds["width"] > svg_w) ? bounds["width"] + 2 * margin + link_dist : svg_w; 
     562    // add extra space to the right, because of the possible labels
     563    w = (bounds["width"] > svg_w) ? bounds["width"] + 2 * margin + link_dist : svg_w + link_dist; 
    514564    h = (bounds["height"] > svg_h) ? bounds["height"] + 2 * margin : svg_h;
    515565       
     
    557607}
    558608
     609function selectNodeByKey(nodes_keys) {
     610
     611    // get selected nodes (if any) from param
     612      var selected_match = 0;
     613        for (var i = 0; i < nodes_keys.length; i++)
     614        {  if (data_all.nodes_index[nodes_keys[i]]) {
     615                 data_all.nodes_index[nodes_keys[i]].selected = 1;
     616                 selected_match ++;
     617           }
     618        }   
     619      // if something was selected, update and render Graph and Detail
     620      if (selected_match) { updateSelected();}
     621}
    559622
    560623function updateSelected () {
     
    574637    renderGraph();
    575638   
    576     // this is to early! the  graph is not positioned yet:
    577     //genDownload();
    578  
    579639 // just need to highlight the selected nodes
    580640    d3.select(index_container_selector).selectAll("li").classed("highlight", function (d) { return d.selected });
Note: See TracChangeset for help on using the changeset viewer.