Changeset 2440 for SMC


Ignore:
Timestamp:
01/06/13 15:13:23 (11 years ago)
Author:
vronk
Message:

added combo-box widget, detail-info from separate source, changeable layout (dot, force)

Location:
SMC/trunk/SMC/src/web/scripts/js
Files:
2 edited

Legend:

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

    r2438 r2440  
    77var data_show = null; // global holder for data to show  closure over data_sel
    88var nest = {};
     9var detail_data = null; // global holder for detail-data (in html) 
    910 
    1011var graph_container_selector = '#infovis';
     
    1516var input_prefix = "input-";
    1617var select_rect_min_size = 5;
     18var min_circle = 4;
    1719var comp_reg_url = "http://catalog.clarin.eu/ds/ComponentRegistry/?item=";     
    1820/*var source_file = "../scripts/cmd-dep-graph-d3_all_svg.json"*/
    19 var source_file = "file:/C:/Users/m/3/clarin/_repo/SMC/data2/cmd-dep-graph.d3.js"
    20 
    21 
    22 var opts = {"depth-before": {"value":2, "min":0, "max":10}, "depth-after":{"value":2, "min":0, "max":10},
    23             "link-distance": {"value":30, "min":10, "max":200 }, "charge":{"value":400, "min":10, "max":1000 }};
     21var source_file = "file:/C:/Users/m/3/clarin/_repo/SMC/output/cmd-dep-graph.d3.js"
     22var detail_file = "file:/C:/Users/m/3/clarin/_repo/SMC/output/smc_stats_detail.html"
     23
     24var opts = {"depth-before": {"value":2, "min":0, "max":10, "widget":"slider"},
     25            "depth-after":{"value":1, "min":0, "max":10, "widget":"slider"},
     26            "link-distance": {"value":30, "min":10, "max":200, "widget":"slider" },
     27            "charge":{"value":400, "min":10, "max":1000, "widget":"slider" },
     28            "node-weight": {"value":"usage", "values":["1","usage"], "widget":"selectone" },
     29            "curve": {"value":"straight", "values":["straight","arc"], "widget":"selectone" },
     30            "layout": {"value":"dot", "values":["dot","force"], "widget":"selectone" },
     31           
     32            };
    2433
    2534/** for faster/simpler neighborhood lookup
     
    3140var neighbours_out = {};
    3241var links_out = {};
     42
     43/** loads from separate file detail info about individual nodes (in html)
     44later used in renderDetail()
     45invoked during the (jquery-)initalization */
     46
     47function loadDetailInfo () {
     48     
     49  $('#detail-info-holder').load(detail_file)
     50 
     51  /* $.get(detail_file, function(data) {
     52    detail_data = data; 
     53    notify('Detail data loaded');
     54 
     55}); */
     56}
     57
     58function getDetailInfo(type, id) {
     59    notify("getDetailInfo: #" + type + "s-" + id );
     60    var d = $('#detail-info-holder').find("#" + type + "s-" + id );
     61    // notify(d);
     62    return d.html();
     63}
     64
    3365
    3466/**  gets the data for the graph and calls rendering of the lists
     
    167199            .linkDistance(opt("link-distance"))
    168200            .charge(opt("charge") * -1)
    169             .on("tick", tick)
    170            .start();
     201            .on("tick", tick) 
     202            .start();
    171203                 
    172204         // remove old render:
     
    192224        var path = svg.append("svg:g").selectAll("path")
    193225            .data(force.links())
    194            
    195           .enter().append("svg:path")
     226            .enter().append("svg:path")
    196227            .attr("class", function(d) { return "link uses"; })
    197228            .attr("marker-end", function(d) { return "url(#uses)"; });
    198        
     229/*            .style("stroke-width", function(d) { return Math.sqrt(d.value); });*/
     230
     231           
     232           
    199233        var circle = svg.append("svg:g")
    200234             .selectAll("circle")
    201235            .data(force.nodes())
    202236            .enter().append("svg:circle")
    203             .attr("r", 6)
     237/*            .attr("r", 6)*/
     238            .attr("r", function(d) { if (opt("node-weight")=="1"){ return min_circle }
     239                                        else {return (Math.sqrt(d.count)>min_circle ? Math.sqrt(d.count) * 2 : min_circle); } })
    204240            .attr("x", function(d) {return d.init_x;})
    205241            .attr("y", function(d) {return d.init_y;})
    206242            .call(force.drag);
    207243       
     244         circle.append("title")
     245            .text(function(d) { return d.name; });
     246       
    208247       svg.selectAll("circle")
    209248            .attr("class", function(d) { return "type-" + d.type.toLowerCase()})
     
    233272            .attr("y", ".31em")
    234273            .text(function(d) { return d.name; });
    235            
    236         // Use elliptical arc path segments to doubly-encode directionality.
    237        
    238         function tick(e) {
    239           var k = e.alpha;
     274
     275 
     276  /*
     277  force.start();
     278        force.tick();
     279        force.stop();
     280       
     281        force.on("tick",tick);
     282       force.start();   
     283           var n = 100;
     284           console.log("start ticking");
     285for (var i = 0; i < n; ++i) force.tick();
     286force.stop();
     287*/
     288        /*   
     289          data.links.forEach(function(d, i) {
     290            d.source.x -= d.source.init_x;
     291            d.target.x += d.target.init_x;
     292          });
     293*/
     294
     295   function statick(e) {
     296     
     297      data.nodes.forEach(function(d,i) {
     298        d.x = d.init_x;
     299        d.y = d.init_y;
     300      });
     301     
     302      transform();
     303   }
     304
     305   function tick(e) {
    240306         
    241           path.attr("d", function(d) {
     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         
     320         /*d.source.y = d.source.init_y - d.source.y * k;
     321           d.target.y = d.target.init_y + d.target.y * k;*/
    242322              /*d.source.x -= k * d.target.sum_level ;
    243323             d.target.x += k *  d.source.sum_level ;*/
     
    246326              //d.source.x -= d.source.level * 0.2 ;
    247327              //d.target.x += d.target.level * 0.2;
    248         //    console.log ("k: " + k + "; source.x:" + d.source.x + "; target.x:" + d.target.x);
    249             var dx = d.target.x - d.source.x,
    250                 dy = d.target.y - d.source.y,
    251                 dr = Math.sqrt(dx * dx + dy * dy);
    252    
    253             return "M" + d.source.x + "," + d.source.y + "A" + dr + "," + dr + " 0 0,1 " + d.target.x + "," + d.target.y;
    254            
    255            
    256                        
    257           });
    258        
    259           circle.attr("transform", function(d) {
     328         
     329               transform();
     330   }
     331
     332
     333    function transform () {
     334         
     335       path.attr("d", function(d) {
     336             // links as elliptical arc path segments
     337            if (opt("curve")=="arc")
     338            {   var dx = d.target.x - d.source.x,
     339                    dy = d.target.y - d.source.y,
     340                    dr = Math.sqrt(dx * dx + dy * dy);
     341                return "M" + d.source.x + "," + d.source.y + "A" + dr + "," + dr + " 0 0,1 " + d.target.x + "," + d.target.y;
     342            } else {
     343            // or straight
     344                return "M" + d.source.x + "," + d.source.y + "L" + d.target.x + "," + d.target.y;
     345            } 
     346       });
     347         
     348         circle.attr("cx", function(d) {return d.x;})
     349                .attr("cy", function(d) {return d.y;});
     350      /* circle.attr("transform", function(d) {
    260351            return "translate(" + d.x + "," + d.y + ")";
    261           });
    262        
    263           textgroup.attr("transform", function(d) {
     352       });*/
     353       
     354       textgroup.attr("transform", function(d) {
    264355            return "translate(" + d.x + "," + d.y + ")";
    265           });
    266          
    267           /*
    268               circle.attr("cx", function(d) { return d.x; })
    269                     .attr("cy", function(d) { return d.y; });
    270            
    271                 path.attr("x1", function(d) { return d.source.x; })
    272                     .attr("y1", function(d) { return d.source.y; })
    273                     .attr("x2", function(d) { return d.target.x; })
    274                     .attr("y2", function(d) { return d.target.y; });*/
    275         }
    276 
     356       });
     357    }
    277358       
    278359        // Highlight selected nodes using the quadtree.
     
    339420                    .attr("id", function (d) { return "n-" + d.name });
    340421               item_li.append("span")
    341                       .text(function (d) { return d.name})
     422                      .text(function (d) { return d.type + ": " + d.name})
    342423                      .on("click", function(d) { d.selected= d.selected ? 0 : 1 ; updateSelected() });
    343424         var item_detail = item_li.append("div")
    344                       .append("a")
     425                            .classed("node-detail", 1);
     426         
     427             item_detail.append("a")
    345428                      .attr("href",function (d) { if (d.type.toLowerCase()=='datcat') return d.id
    346429                                                        else return comp_reg_url + d.id })
    347430                      .text(function (d) { return d.id });
    348                         //.classed("detail", 1);
    349                        
     431            item_detail.append("div").html(
     432                          function (d) { var detail_info_div = getDetailInfo(d.type.toLowerCase(), d.key);
     433                                            if (detail_info_div) {return detail_info_div } else
     434                                                { return  "<div>No detail</div>"; }
     435                          });
     436                           
     437                         
    350438  // handleUIBlock($(".cmds-ui-block"));   
    351439}
     
    537625function fillOpts(trg_container) {
    538626
    539 
    540627  for ( var key in opts ) {
    541628    if ($('#' + input_prefix + key).length) {
     
    543630     } else if (trg_container)  {
    544631        var new_input_label = "<label>" + key + "</label>";
    545         var new_input = $("<input />");
    546         new_input.attr("id", input_prefix + key)
    547                  .val(opts[key].value)
    548                  .attr("type", "text")
    549                  .attr("size", 3);
    550                  
    551          var new_slider = $("<div class='slider'></div>");
    552          new_slider.attr("id", "slider-" + key);
    553          new_slider.slider( opts[key]);
    554          // set both-ways references between the input-field and its slider - necessary for updating
    555          new_slider.data("related-input-field",new_input);
    556          new_input.data("related-slider",new_slider);
     632        var new_input;
     633       
     634       if (opts[key].widget == "slider") {
     635            [new_input,new_widget] = genSlider(key, opts[key].values);
     636         } else if (opts[key].widget =="selectone") {
     637            [new_input,new_widget] = genCombo(key, opts[key].values);
     638             
     639           
     640        //     $(new_input).autocomplete({"source":opts[key].values});
     641         }
    557642         
    558 /* hook changing  options + redrawing the graph, when values in navigation changed */
    559          new_slider.bind( "slidechange", function(event, ui) {
    560           //   console.log(ui.value);
    561              $(this).data("related-input-field").val(ui.value);
    562              // update the opts-object, but based on the (updated) value of the related input-field
    563              setOpt($(this).data("related-input-field"));
    564              
    565               renderGraph();
    566            });
    567 
    568         new_input.change(function () {
     643    /* hook changing  options + redrawing the graph, when values in navigation changed */
     644         new_input.change(function () {
    569645               setOpt(this);
    570                $(this).data("related-slider").slider("option", "value", $(this).val());
     646               var related_widget = $(this).data("related-widget");
     647           if ( $(related_widget).hasClass("widget-slider")) {$(related_widget).slider("option", "value", $(this).val()); }
    571648               renderGraph();
    572649            });
    573650               
    574         $(trg_container).append(new_input_label, new_input, new_slider);
     651        $(trg_container).append(new_input_label, new_input, new_widget);
    575652       
    576653     }
     
    590667}
    591668
     669/** generating my own comboboxes, because very annoying trying to use some of existing jquery plugins (easyui.combo, combobox, jquery-ui.autocomplete) */
     670function genCombo (key, data) {
     671   
     672    var select = $("<select id='widget-" + key + "' />")
     673        select.attr("id", input_prefix + key)
     674    data.forEach(function(v) { $(select).append("<option value='" + v +"' >" + v + "</option>") });
     675    return [select, null];
     676}
     677
     678function genSlider (key, data) {
     679
     680    var new_input = $("<input />");
     681            new_input.attr("id", input_prefix + key)
     682                 .val(opts[key].value)
     683/*                 .attr("type", "text")*/
     684                 .attr("size", 3);
     685     
     686    var new_widget = $("<div class='widget-" + opts[key].widget + "'></div>");
     687        new_widget.attr("id", "widget-" + key);
     688        new_widget.slider( opts[key]);
     689           
     690        // set both-ways references between the input-field and its slider - necessary for updating
     691        new_widget.data("related-input-field",new_input);
     692        new_input.data("related-widget",new_widget);
     693     
     694//           console.log("widget:" + opts[key].widget);
     695       
     696        new_widget.bind( "slidechange", function(event, ui) {
     697            //   console.log(ui.value);
     698               $(this).data("related-input-field").val(ui.value);
     699               // update the opts-object, but based on the (updated) value of the related input-field
     700                setOpt($(this).data("related-input-field"));
     701               renderGraph();
     702         });
     703         
     704   return [new_input,new_widget];
     705}
     706
     707
    592708function notify (msg) {
    593   d3.select("#notify").html(msg);
    594 }
     709  $("#notify").append(msg);
     710}
  • SMC/trunk/SMC/src/web/scripts/js/mdservice/mdservice_ui.js

    r2438 r2440  
    4141               
    4242                initGraph();
     43                loadDetailInfo ();
    4344               
    4445                ////////////// CREATE  UI-LAYOUT
Note: See TracChangeset for help on using the changeset viewer.