Skip to content

Commit

Permalink
shoebox - store colorScale as json in session
Browse files Browse the repository at this point in the history
  • Loading branch information
jrobinso committed Oct 13, 2024
1 parent 585b88b commit 676ecdd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
11 changes: 11 additions & 0 deletions dev/shoebox/shoebox.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

<h1>Shoebox</h1>

<button id="log-state">Log Session</button>
<button id="bookmark">Bookmark</button>

<div id="igvDiv" style="padding-top: 50px;padding-bottom: 20px; height: auto"></div>

Expand Down Expand Up @@ -75,6 +77,15 @@ <h1>Shoebox</h1>
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)
})

})


Expand Down
19 changes: 15 additions & 4 deletions js/shoebox/shoeboxColorScale.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ class ShoeboxColorScale {
this.updateColor(scale.color || "rgb(0,0,255)")

}

updateColor(color) {
const comps = color.substring(4).replace(")", "").split(",")
if (comps.length === 3) {
this.r = Number.parseInt(comps[0].trim())
this.g = Number.parseInt(comps[1].trim())
this.b = Number.parseInt(comps[2].trim())
}
this.cache = []
}

setMinMax(min, max) {
Expand All @@ -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]}`
Expand Down
7 changes: 4 additions & 3 deletions js/shoebox/shoeboxTrack.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

}
Expand Down

0 comments on commit 676ecdd

Please sign in to comment.