Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graph navigation hotkeys #223

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 68 additions & 2 deletions flamegraph.pl
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ sub flow {
<script type="text/ecmascript">
<![CDATA[
"use strict";
var details, searchbtn, unzoombtn, matchedtxt, svg, searching, currentSearchTerm, ignorecase, ignorecaseBtn;
var details, searchbtn, unzoombtn, matchedtxt, svg, searching, currentSearchTerm, ignorecase, ignorecaseBtn, back_list, forward_list, current;
function init(evt) {
details = document.getElementById("details").firstChild;
searchbtn = document.getElementById("search");
Expand All @@ -756,6 +756,25 @@ sub flow {
svg = document.getElementsByTagName("svg")[0];
searching = 0;
currentSearchTerm = null;
back_list = [];
forward_list = [];
current = null;
}

function push_back(target) {
if (target != current) back_list.push(current);
}

function push_forward(target) {
if (target != current) forward_list.push(current);
}

function push_unzoom_forward() {
push_forward(null);
}

function push_unzoom_back() {
push_back(null);
}

window.addEventListener("click", function(e) {
Expand All @@ -765,10 +784,16 @@ sub flow {
if (e.ctrlKey === false) return;
e.preventDefault();
}
// prune forward list when moving forward in another direction.
forward_list = [];
push_back(target);
if (target.classList.contains("parent")) unzoom();
zoom(target);
}
else if (e.target.id == "unzoom") unzoom();
else if (e.target.id == "unzoom") {
push_unzoom_back();
unzoom();
}
else if (e.target.id == "search") search_prompt();
else if (e.target.id == "ignorecase") toggle_ignorecase();
}, false)
Expand Down Expand Up @@ -802,6 +827,45 @@ sub flow {
}
}, false)

// ctrl-U for unzoom
window.addEventListener("keydown", function (e) {
if (e.ctrlKey && e.keyCode === 85) {
e.preventDefault();
push_unzoom_back();
unzoom();
}
}, false)

// ctrl-[ for back
window.addEventListener("keydown", function (e) {
if (e.ctrlKey && e.keyCode === 219) {
var back = back_list.pop();
if (back === null) {
push_unzoom_forward();
unzoom();
} else if (back) {
push_forward(back);
if (back.classList.contains("parent")) unzoom();
zoom(back);
}
}
}, false)

// ctrl-] for forward
window.addEventListener("keydown", function (e) {
if (e.ctrlKey && e.keyCode === 221) {
var forward = forward_list.pop();
if (forward === null) {
push_unzoom_back();
unzoom();
} else if (forward) {
push_back(forward);
if (forward.classList.contains("parent")) unzoom();
zoom(forward);
}
}
}, false)

// functions
function find_child(node, selector) {
var children = node.querySelectorAll(selector);
Expand Down Expand Up @@ -909,6 +973,7 @@ sub flow {
}
}
function zoom(node) {
current = node;
var attr = find_child(node, "rect").attributes;
var width = parseFloat(attr.width.value);
var xmin = parseFloat(attr.x.value);
Expand Down Expand Up @@ -960,6 +1025,7 @@ sub flow {
search();
}
function unzoom() {
current = null;
unzoombtn.classList.add("hide");
var el = document.getElementById("frames").children;
for(var i = 0; i < el.length; i++) {
Expand Down