var width = 960, height = 500; var svg = d3.select("#d3_container") .append("svg") .attr("class", "network") .attr("width", width) .attr("height", height), g = svg.append("g"); var transform = d3.zoomIdentity, zoom = d3.zoom().scaleExtent([0.5, 8]).on("zoom", zoomed); var x = d3.scaleLinear().range([0, width]); var y = d3.scaleLinear().range([height, 0]); var line = d3.line(); // *********** Network Variable: Layout, Community, Nodes, Edges ********** // var layout = "YifanHu"; var size_mode = "overlap_num", color_mode = "link_community", plot_x_mode = "link_overlap_num", plot_y_mode = "performance"; var communities = []; var link_communities = []; var overlap_threshold = 1; var course_info; var nodes, overlapping_nodes, link_overlapping_nodes, links; var getCommunityColor = function(d){ for (var i=0; i overlap_threshold) return true; return false; // skip }).map(function(filtered_d){ return { 'index' : filtered_d.index, 'x' : filtered_d.x, 'y' : filtered_d.y, 'overlapping_num': +filtered_d.overlap_num, 'overlapping_communities': filtered_d.community.map(function(d){ return { "id": d, "value": 0, "overlap_num": +filtered_d.overlap_num } } ) } }); overlaps.forEach(function(node, index){ var from = _.pluck(_.where(links, {source: node.index}), "community"); var to = _.pluck(_.where(links, {target: node.index}), "community"); // var neighbors = _.union(from, to); // unique ver. var neighbors = Array.prototype.concat(from, to); console.log(neighbors); neighbors.forEach(function(nei){ var commu_index = _.indexOf(_.pluck(node.overlapping_communities, "id"), nei); if(commu_index !== -1) overlaps[index].overlapping_communities[commu_index].value++; }) }); console.log(overlaps); return overlaps; } function getOverlappingNodes_LC(){ var overlaps = []; overlaps = nodes.filter(function(d) { if(+d.link_overlap_num > overlap_threshold) return true; return false; // skip }).map(function(filtered_d){ return { 'index' : filtered_d.index, 'x' : filtered_d.x, 'y' : filtered_d.y, 'overlapping_num': +filtered_d.link_overlap_num, 'overlapping_communities': filtered_d.link_community.split("+").map( function(d){ return { "id": d, "value": 0, "overlap_num": +filtered_d.overlap_num, "link_overlap_num": +filtered_d.link_overlap_num, 'betweenness': +filtered_d.between, 'performance': +filtered_d.performance}; }) } }); overlaps.forEach(function(node, index){ var from = _.pluck(_.where(links, {source: node.index}), "link_community"); var to = _.pluck(_.where(links, {target: node.index}), "link_community"); var neighbors = _.union(from, to); // link community algorithms의 경우 link마다 community가 mapping되있음. neighbors.forEach(function(nei){ var commu_index = _.indexOf(_.pluck(node.overlapping_communities, "id"), nei); if(commu_index !== -1) overlaps[index].overlapping_communities[commu_index].value++; }) }); return overlaps; } function updatePieChart(mode){ // **************** Pie update ****************** // var pie_selector = d3.select(".overlapping_nodes." + mode); if(pie_selector.empty()){ d3.select("#overlapping_nodes").remove(); if(mode == "link_community") drawOverlappingPieChart(link_overlapping_nodes, "link_community"); else drawOverlappingPieChart(overlapping_nodes, "community"); } } function zoomed(){ // console.log(d3.event.transform) g.select("g.nodes").attr("transform", d3.event.transform); g.select("g.edges").attr("transform", d3.event.transform); g.select("g.communities").attr("transform", d3.event.transform); // g.select("g.overlapping_nodes").attr("transform", d3.event.transform); } function dragged(d){ d3.select(this).attr("cx", d.x = d3.event.x).attr("cy", d.y = d3.event.y); } function getNodeOpacity (node){ if(+node.overlap_num > overlap_threshold) return 0; else return 1; }