From 6d13edf314000ebd927de19b537ffc40a5bc5625 Mon Sep 17 00:00:00 2001 From: Mitchell Robert Vollger Date: Thu, 10 Mar 2022 19:01:38 -0800 Subject: [PATCH] Adding the position to the url as zoom events happen. Makes it easy to share you current view with others. --- SafFire.js | 1 + lib.js | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/SafFire.js b/SafFire.js index 6577d6c..6e7d199 100644 --- a/SafFire.js +++ b/SafFire.js @@ -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") diff --git a/lib.js b/lib.js index 21d10df..30477b1 100644 --- a/lib.js +++ b/lib.js @@ -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"; @@ -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) {