lib/flamegraph/flamegraph.html in flamegraph-0.1.0 vs lib/flamegraph/flamegraph.html in flamegraph-0.9.5

- old
+ new

@@ -246,10 +246,35 @@ $('.info').text(""); d3.selectAll(i.nodes) .attr('opacity',1); }; +// highlight the nodes of a gem +var gemSelect = function(e) { + var name = e.data.name; + d3.selectAll(getGemNodes(name)).attr('opacity',0.5); + return false; +}; + +// remove highlighting of the nodes of a gem +var gemDeSelect = function(e) { + var name = e.data.name; + d3.selectAll(getGemNodes(name)).attr('opacity',1); + return false; +}; + +// given the name of a gem, return all of its nodes +var getGemNodes = function(gem_name) { + var frames = gemStats[gem_name].frames; + var nodes = []; + $.each(frames, function(i,f) { + var i = info[f]; + nodes = nodes.concat(i.nodes); + }); + return nodes; +}; + var backtrace = function(frame){ for(var i=0; i<data.length; i++){ if(frame === data[i]){ break; } } @@ -273,20 +298,25 @@ $('#frameinfo-wrapper').click(function(d){ $(this).hide(); $('#frameinfo').hide(); }); +$(window).keyup(function(e) { + if (e.keyCode==27) + $('#frameinfo-wrapper,#frameinfo').hide(); +}); + var click = function(d){ var trace = backtrace(d); var link = function(path, dest){ return path.replace(/[^\/]+:\d+/, function(x){ return "<a target='_blank' href='"+ dest +"'>" + x + "</a>"}) }; var linkify = function(path){ var split = path.split("/")[0].split("-"); - if(["activerecord","actionpack","railties","activesupport", "rails"].indexOf(split[0]) > -1) { + if(["actionview","activerecord","actionpack","railties","activesupport", "rails"].indexOf(split[0]) > -1) { var github = "https://github.com/rails/rails/blob/"; var file = path.split(":")[0].split("/"); if(split[0] === "rails") { file.shift(); } else { @@ -486,13 +516,14 @@ // render the legend _.each(gemsSorted, function(gem){ var node = $("<div></div>") .css("background-color", gem.color) - .text(gem.name + " " + samplePercent(gem.samples.length)) ; + .text(gem.name + " " + samplePercent(gem.samples.length)) + .on("mouseover", {name: gem.name}, gemSelect) + .on("mouseout", {name: gem.name}, gemDeSelect); $('.legend').append(node); }); - </script> </body> </html>