- Timestamp:
- 01/06/13 15:13:23 (11 years ago)
- 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 7 7 var data_show = null; // global holder for data to show closure over data_sel 8 8 var nest = {}; 9 var detail_data = null; // global holder for detail-data (in html) 9 10 10 11 var graph_container_selector = '#infovis'; … … 15 16 var input_prefix = "input-"; 16 17 var select_rect_min_size = 5; 18 var min_circle = 4; 17 19 var comp_reg_url = "http://catalog.clarin.eu/ds/ComponentRegistry/?item="; 18 20 /*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 }}; 21 var source_file = "file:/C:/Users/m/3/clarin/_repo/SMC/output/cmd-dep-graph.d3.js" 22 var detail_file = "file:/C:/Users/m/3/clarin/_repo/SMC/output/smc_stats_detail.html" 23 24 var 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 }; 24 33 25 34 /** for faster/simpler neighborhood lookup … … 31 40 var neighbours_out = {}; 32 41 var links_out = {}; 42 43 /** loads from separate file detail info about individual nodes (in html) 44 later used in renderDetail() 45 invoked during the (jquery-)initalization */ 46 47 function 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 58 function 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 33 65 34 66 /** gets the data for the graph and calls rendering of the lists … … 167 199 .linkDistance(opt("link-distance")) 168 200 .charge(opt("charge") * -1) 169 .on("tick", tick) 170 .start();201 .on("tick", tick) 202 .start(); 171 203 172 204 // remove old render: … … 192 224 var path = svg.append("svg:g").selectAll("path") 193 225 .data(force.links()) 194 195 .enter().append("svg:path") 226 .enter().append("svg:path") 196 227 .attr("class", function(d) { return "link uses"; }) 197 228 .attr("marker-end", function(d) { return "url(#uses)"; }); 198 229 /* .style("stroke-width", function(d) { return Math.sqrt(d.value); });*/ 230 231 232 199 233 var circle = svg.append("svg:g") 200 234 .selectAll("circle") 201 235 .data(force.nodes()) 202 236 .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); } }) 204 240 .attr("x", function(d) {return d.init_x;}) 205 241 .attr("y", function(d) {return d.init_y;}) 206 242 .call(force.drag); 207 243 244 circle.append("title") 245 .text(function(d) { return d.name; }); 246 208 247 svg.selectAll("circle") 209 248 .attr("class", function(d) { return "type-" + d.type.toLowerCase()}) … … 233 272 .attr("y", ".31em") 234 273 .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"); 285 for (var i = 0; i < n; ++i) force.tick(); 286 force.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) { 240 306 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;*/ 242 322 /*d.source.x -= k * d.target.sum_level ; 243 323 d.target.x += k * d.source.sum_level ;*/ … … 246 326 //d.source.x -= d.source.level * 0.2 ; 247 327 //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) { 260 351 return "translate(" + d.x + "," + d.y + ")"; 261 });262 263 352 });*/ 353 354 textgroup.attr("transform", function(d) { 264 355 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 } 277 358 278 359 // Highlight selected nodes using the quadtree. … … 339 420 .attr("id", function (d) { return "n-" + d.name }); 340 421 item_li.append("span") 341 .text(function (d) { return d. name})422 .text(function (d) { return d.type + ": " + d.name}) 342 423 .on("click", function(d) { d.selected= d.selected ? 0 : 1 ; updateSelected() }); 343 424 var item_detail = item_li.append("div") 344 .append("a") 425 .classed("node-detail", 1); 426 427 item_detail.append("a") 345 428 .attr("href",function (d) { if (d.type.toLowerCase()=='datcat') return d.id 346 429 else return comp_reg_url + d.id }) 347 430 .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 350 438 // handleUIBlock($(".cmds-ui-block")); 351 439 } … … 537 625 function fillOpts(trg_container) { 538 626 539 540 627 for ( var key in opts ) { 541 628 if ($('#' + input_prefix + key).length) { … … 543 630 } else if (trg_container) { 544 631 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 } 557 642 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 () { 569 645 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()); } 571 648 renderGraph(); 572 649 }); 573 650 574 $(trg_container).append(new_input_label, new_input, new_ slider);651 $(trg_container).append(new_input_label, new_input, new_widget); 575 652 576 653 } … … 590 667 } 591 668 669 /** generating my own comboboxes, because very annoying trying to use some of existing jquery plugins (easyui.combo, combobox, jquery-ui.autocomplete) */ 670 function 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 678 function 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 592 708 function 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 41 41 42 42 initGraph(); 43 loadDetailInfo (); 43 44 44 45 ////////////// CREATE UI-LAYOUT
Note: See TracChangeset
for help on using the changeset viewer.