Skip to content

Commit

Permalink
Implement zoom state
Browse files Browse the repository at this point in the history
Using history.replaceState[1], a zoom state can be accessed by using the
y and x frame attributes. history.pushState was explicitly not used
since it would bring a slew of new issues to resolve (browser back and
forward state).

1. https://developer.mozilla.org/en-US/docs/Web/API/History_API
  • Loading branch information
versable committed Mar 2, 2020
1 parent 1a0dc69 commit 3acba28
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion flamegraph.pl
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,14 @@ sub flow {
svg = document.getElementsByTagName("svg")[0];
searching = 0;
currentSearchTerm = null;
var params = {};
var paramsarr = window.location.search.substr(1).split('&');
for (var i = 0; i < paramsarr.length; ++i) {
var tmp = paramsarr[i].split("=");
params[tmp[0]] = tmp[1];
}
if (params.y && params.x)
zoom(find_group(document.querySelector('[y="' + params.y + '"][x="' + params.x + '"]')));
}
window.addEventListener("click", function(e) {
Expand All @@ -767,8 +775,21 @@ sub flow {
}
if (target.classList.contains("parent")) unzoom();
zoom(target);
var el = target.querySelector("rect");
if (el && el.attributes && el.attributes.y && el.attributes._orig_x) {
var params = {
"y": el.attributes.y.value,
"x": el.attributes._orig_x.value ?
el.attributes._orig_x.value :
el.attributes.x.value
};
history.replaceState(null, null, "?y=" + params.y + "&x=" + params.x);
}
}
else if (e.target.id == "unzoom") {
history.replaceState(null, null, "?");
unzoom();
}
else if (e.target.id == "unzoom") unzoom();
else if (e.target.id == "search") search_prompt();
else if (e.target.id == "ignorecase") toggle_ignorecase();
}, false)
Expand Down

0 comments on commit 3acba28

Please sign in to comment.