Skip to content

Commit

Permalink
Adding the position to the url as zoom events happen. Makes it easy t…
Browse files Browse the repository at this point in the history
…o share you current view with others.
  • Loading branch information
mrvollger committed Mar 11, 2022
1 parent b5fb06d commit 6d13edf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions SafFire.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ function miropeats_d3(data) {
var st = Math.max(0, Math.round(xz.domain()[0]));
var en = Math.min(aln_data[0].c1_len, Math.round(xz.domain()[1]));
var coords = `${t_name}:${d3.format(",")(st + 1)}-${d3.format(",")(en)}`;
set_url_hash_elm("pos", `${t_name}:${st}-${en}`, false);
d3.selectAll('.coordinates').remove();
// define the coordinate box
var coordinates = d3.select("body").append("div")
Expand Down
15 changes: 14 additions & 1 deletion lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ function get_url_elm(tag) {
return val;
}

function set_url_hash_elm(tag, val, trigger_event = true) {
const parsedHash = new URLSearchParams(
window.location.hash.substr(1) // skip the first char (#)
);
parsedHash.set(tag, val);
var newHash = parsedHash.toString();
if (trigger_event) {
window.location.hash = newHash;
} else {
history.replaceState(null, null, document.location.pathname + '#' + newHash);
}
}

function set_default_hash() {
if (window.location.hash == "") {
window.location.hash = "#dataset=default&ref=CHM13_v1.1&query=CHM1";
Expand All @@ -31,7 +44,7 @@ function set_default_hash() {
}

function set_user_hash() {
window.location.hash = "#ref=USER_REF&query=USER_QUERY";
window.location.hash = "#dataset=USER&ref=USER_REF&query=USER_QUERY";
}

function sleep(ms) {
Expand Down

0 comments on commit 6d13edf

Please sign in to comment.