public/javascript/application.js in rubrowser-0.2.1 vs public/javascript/application.js in rubrowser-0.2.2

- old
+ new

@@ -1,8 +1,9 @@ d3.json("/data.json", function(error, data) { parseGraph(data); $('.loading').hide(); + $('.toolbox').show(); }); var parseGraph = function(data){ var svg = d3.select(".dependency_graph svg"), $svg = $('.dependency_graph svg'), @@ -10,12 +11,12 @@ height = $svg.height(), drag = d3.drag() .on("start", dragstarted) .on("drag", dragged) .on("end", dragended), - constants = _.uniqWith(data.definitions.map(function(d){ return {id: d.namespace, type: d.type }; }), _.isEqual), - namespaces = constants.map(function(d){ return d.id; }), + definitions = _.uniqWith(data.definitions.map(function(d){ return {id: d.namespace, type: d.type }; }), _.isEqual), + namespaces = definitions.map(function(d){ return d.id; }), relations = data.relations.map(function(d){ return {source: d.caller, target: d.resolved_namespace }; }); relations = relations.filter(function(d){ return namespaces.indexOf(d.source) >= 0 && namespaces.indexOf(d.target) >= 0; }); @@ -32,14 +33,14 @@ var container = svg.append('g'), simulation = d3.forceSimulation() .force("link", d3.forceLink().id(function(d) { return d.id; })) .force("charge", d3.forceManyBody()) .force("center", d3.forceCenter(width / 2, height / 2)) - .force("forceCollide", d3.forceCollide(function(){ return 80; })); + .force("forceCollide", d3.forceCollide(80)); simulation - .nodes(constants) + .nodes(definitions) .on("tick", ticked); simulation.force("link") .links(relations); @@ -51,11 +52,11 @@ .attr("class", 'link') .attr("marker-end", "url(#relation)"), node = container.append("g") .attr("class", "nodes") .selectAll("g") - .data(constants) + .data(definitions) .enter().append("g") .call(drag) .on("dblclick", dblclick), circle = node .append("circle") @@ -66,10 +67,11 @@ .attr("x", "-0.4em") .attr("y", "0.4em") .text(function(d) { return d.type[0]; }), text = node .append("text") + .attr("class", "namespace") .attr("x", 8) .attr("y", ".31em") .text(function(d) { return d.id; }); container.append("defs").selectAll("marker") @@ -124,31 +126,33 @@ } node.on('mouseover', function(d) { var relatives = []; - link.style('opacity', function(l) { + link.classed('downlighted', function(l) { if (d === l.source || d === l.target){ relatives.push(l.source); relatives.push(l.target); - return 1; + return false; }else{ - return 0.1; + return true; } }); - node.style('opacity', function(n) { - if( n == d || relatives.indexOf(n) > -1 ){ - return 1; - }else{ - return 0.1; - } + node.classed('downlighted', function(n) { + return !(n == d || relatives.indexOf(n) > -1); }); }); node.on('mouseout', function() { - link.style('opacity', 1); - node.style('opacity', 1); + link.classed('downlighted', false); + node.classed('downlighted', false); }); - return true; - + window.rubrowser = { + data: data, + definitions: definitions, + relations: relations, + simulation: simulation, + node: node, + link: link + }; };