From 676ecdd5a522c61573a488b7bf8aee3e44b00072 Mon Sep 17 00:00:00 2001
From: jrobinso <933148+jrobinso@users.noreply.github.com>
Date: Sat, 12 Oct 2024 21:06:39 -0700
Subject: [PATCH] shoebox - store colorScale as json in session
---
dev/shoebox/shoebox.html | 11 +++++++++++
js/shoebox/shoeboxColorScale.js | 19 +++++++++++++++----
js/shoebox/shoeboxTrack.js | 7 ++++---
3 files changed, 30 insertions(+), 7 deletions(-)
diff --git a/dev/shoebox/shoebox.html b/dev/shoebox/shoebox.html
index 52d2eae8f..95b4bda57 100644
--- a/dev/shoebox/shoebox.html
+++ b/dev/shoebox/shoebox.html
@@ -10,6 +10,8 @@
Shoebox
+
+
@@ -75,6 +77,15 @@ Shoebox
igv.createBrowser(igvDiv, options)
.then(function (browser) {
console.log("Created IGV browser")
+ document.getElementById("log-state").addEventListener("click", () => console.log(browser.toJSON()))
+
+ document.getElementById('bookmark').addEventListener('click', () => {
+ const path = window.location.href.slice()
+ const idx = path.indexOf("?")
+ const url = (idx > 0 ? path.substring(0, idx) : path) + "?sessionURL=blob:" + browser.compressedSession()
+ window.history.pushState({}, "IGV", url)
+ })
+
})
diff --git a/js/shoebox/shoeboxColorScale.js b/js/shoebox/shoeboxColorScale.js
index 70b8dec72..0c6b831a1 100644
--- a/js/shoebox/shoeboxColorScale.js
+++ b/js/shoebox/shoeboxColorScale.js
@@ -38,6 +38,7 @@ class ShoeboxColorScale {
this.updateColor(scale.color || "rgb(0,0,255)")
}
+
updateColor(color) {
const comps = color.substring(4).replace(")", "").split(",")
if (comps.length === 3) {
@@ -45,6 +46,7 @@ class ShoeboxColorScale {
this.g = Number.parseInt(comps[1].trim())
this.b = Number.parseInt(comps[2].trim())
}
+ this.cache = []
}
setMinMax(min, max) {
@@ -66,15 +68,24 @@ class ShoeboxColorScale {
return this.cache[bin]
}
- stringify() {
- return "" + this.min + "," + this.max + ',' + `rgb(${this.r},${this.g},${this.b})`
+ /**
+ *
+ * @returns {{min: (*|number), color: string, max}}
+ */
+ toJson() {
+ return {
+ min: this.min,
+ max: this.max,
+ color: `rgb(${this.r},${this.g},${this.b})`
+ }
}
+ // For short-term backward compatibility
static parse(str) {
- const tokens = str.split(",")
+ const tokens = str.split(",")
- const cs = {
+ const cs = {
min: Number.parseFloat(tokens[0]),
max: Number.parseFloat(tokens[1]),
color: `${tokens[2]},${tokens[3]},${tokens[4]}`
diff --git a/js/shoebox/shoeboxTrack.js b/js/shoebox/shoeboxTrack.js
index 2135cfa96..d8f1e009b 100755
--- a/js/shoebox/shoeboxTrack.js
+++ b/js/shoebox/shoeboxTrack.js
@@ -50,8 +50,9 @@ class ShoeboxTrack extends TrackBase {
// Must do the following after setting track properties as they can be overriden via a track line
// Color settings
- if (this.config.colorScale) {
- this.colorScale = ShoeboxColorScale.parse(this.config.colorScale)
+ if (this.config.colorScale && this.config.colorScale.max && this.config.colorScale.color) { // Minimal validation
+ this.colorScale = new ShoeboxColorScale(this.config.colorScale)
+
} else {
const min = this.dataRange.min
const max = this.dataRange.max
@@ -240,7 +241,7 @@ class ShoeboxTrack extends TrackBase {
getState() {
const config = super.getState()
- config.colorScale = this.colorScale.stringify()
+ config.colorScale = this.colorScale.toJson()
return config
}