Changeset 3629 for SMC


Ignore:
Timestamp:
09/27/13 13:23:39 (11 years ago)
Author:
vronk
Message:

force-layout parameters dynamic; (supports edges with weight AND value); flag for arrows

File:
1 edited

Legend:

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

    r3628 r3629  
    1616var first_level_margin = 20;
    1717var min_circle = 4;
    18 var max_circle = 50;
     18var max_circle = 80;
    1919
    2020var show_count = 1;
     21var show_arrows = 0;
    2122
    2223var comp_reg_url = "http://catalog.clarin.eu/ds/ComponentRegistry/?item=";
     
    4041var userdocs_file = "userdocs.html";
    4142
    42 var opts = {"graph": {"value":"/smc/data/smc-graph-basic.js",
     43var opts = {"graph": {"value":"/smc/data/profiles.js",
    4344                    "values":[{value: "/smc/data/smc-graph-basic.js", label:"SMC graph basic"},
    4445                              {value: "/smc/data/smc-graph-all.js", label:"SMC graph all"},                             
    4546                              {value: "/smc/data/smc-graph-profiles-datcats.js", label:"only profiles + datcats"},
    46                               {value: "/smc/data/smc-graph-groups-profiles-datcats-rr.js", label:"profiles+datcats+groups+rr"}
     47                              {value: "/smc/data/smc-graph-groups-profiles-datcats-rr.js", label:"profiles+datcats+groups+rr"},
     48                              {value: "/smc/data/profiles.js", label:"just profiles"}                             
     49                             
    4750                              /*,
    4851                              {value: "/smc/data/smc-graph-mdrepo-stats.js", label:"instance data"}*/
     
    5457            "charge":{"value":250, "min":10, "max":1000, "widget":"slider" },
    5558            "friction":{"value":75, "min":1, "max":100, "widget":"slider" },
    56             "node-size": {"value":"4", "values":["1","4","8","16","usage"], "widget":"selectone" },
     59            "node-size": {"value":"count", "values":["1","4","8","16","count"], "widget":"selectone" },
    5760            "labels": {"value":"show", "values":["show","hide"], "widget":"selectone" },                         
    5861            "curve": {"value":"straight", "values":["straight","arc"], "widget":"selectone" },
    59            "layout": {"value":"horizontal-tree", "values":["vertical-tree", "horizontal-tree", "weak-tree","force","dot", "freeze"], "widget":"selectone" },
     62           "layout": {"value":"force", "values":["vertical-tree", "horizontal-tree", "weak-tree","force","dot", "freeze"], "widget":"selectone" },
    6063            "selected": {"widget":"hidden" },
    6164            "link": {"widget":"link", "label":""},
     
    289292     }
    290293 
    291   // compute the maximum number, but only if it will be needed (i.e. node-size=usage)
    292     if (opt("node-size")=="usage") {
     294  // compute the maximum number, but only if it will be needed (i.e. node-size=count)
     295    if (opt("node-size")=="count") {
    293296        var init_count = [];
    294297            data.nodes.forEach(function(d,i){init_count.push(+d.count);})
     
    311314     var ratio = w / (data_all.init_x_max - data_all.init_x_min);
    312315    var node_size_int = parseInt(opt("node-size"));
    313 
     316 var link_distance = parseInt(opt("link-distance"))
     317 
    314318        // console.log (w + '-' + h);
    315319     var force = d3.layout.force()
     
    317321            .links(data.links)
    318322            .size([w, h])
    319             //.gravity(0.3)
     323
    320324            .friction(parseInt(opt("friction")) / 100 )
    321325            .linkDistance(parseInt(opt("link-distance")))
     326            .gravity(0.5)
     327            /* Profiles:           
     328           
     329            .linkDistance(function(d){return link_distance / (d.weight * d.value) })
     330            .linkStrength(function(d){return d.weight})*/
    322331            //.charge(parseInt(opt("charge")) * -1)
    323             .charge(function(d) { if (opt("node-size")=="usage")
     332            .charge(function(d) { if (opt("node-size")=="count")
    324333                            {var node_charge = (Math.sqrt(d.count)<=min_circle) ?  min_circle  : Math.sqrt(d.count) / data.node_size_ratio;
    325334                            //console.log (node_charge + ':' + d.count);
     
    346355       
    347356        // Per-type markers, as they don't inherit styles.
     357      if (show_arrows)  {
    348358        svg.append("svg:defs").selectAll("marker")
    349359          .data(["uses"])
     
    358368          .append("svg:path")
    359369            .attr("d", "M0,-3L10,0L0,3");
     370       }
    360371       
    361372        var path = svg.append("svg:g").selectAll("path")
     
    366377            .classed("uses", 1)
    367378            .classed("highlight", function(d) { d.highlight } )
    368             .attr("marker-end", function(d) { return "url(#uses)"; });
    369 /*            .style("stroke-width", function(d) { return Math.sqrt(d.value); });*/
    370 
     379            .attr("marker-end", function(d) { return "url(#uses)"; })
     380            .style("stroke-width", function(d) { return Math.sqrt(d.value); });
     381/*             .style("stroke-width", function(d) { return d.value });*/
     382
     383           path.append("title").text(function(d){ return d.value });
    371384           
    372385         var gnodes = svg.append("svg:g")
     
    415428                    .on("click", function(d) {d.selected= d.selected ? 0 : 1; updateSelected() })
    416429                      .on("mouseover", highlight()).on("mouseout", unhighlight())
    417             .attr("r", function(d) { if (opt("node-size")=="usage")
     430            .attr("r", function(d) { if (opt("node-size")=="count")
    418431                                        {return (Math.sqrt(d.count)<=min_circle) ?  min_circle  : Math.sqrt(d.count) / data.node_size_ratio;                                       
    419432                                        }
Note: See TracChangeset for help on using the changeset viewer.