Skip to content

Commit

Permalink
track initial color wrangling
Browse files Browse the repository at this point in the history
  • Loading branch information
turner committed Nov 25, 2024
1 parent 0e96bd3 commit 34543f5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 31 deletions.
3 changes: 3 additions & 0 deletions js/trackBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ class TrackBase {
}
}

this._initialColor = this.color || this.constructor.defaultColor
this._initialAltColor = this.altColor || this.constructor.defaultColor

if (config.name || config.label) {
this.name = config.name || config.label
} else if (FileUtils.isFile(config.url)) {
Expand Down
32 changes: 5 additions & 27 deletions js/trackView.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,38 +208,16 @@ class TrackView {

if (false === colorPickerExclusionTypes.has(this.track.type)) {

if (undefined === this.track.initialTrackColor) {
this.track.initialTrackColor = {}
}

const color = this.track.color || this.track.constructor.defaultColor
if (StringUtils.isString(color)) {

if (undefined === this.track.initialTrackColor['color']) {
this.track.initialTrackColor['color'] = color.startsWith("#") ? color : color.startsWith("rgb(") ? IGVColor.rgbToHex(color) : IGVColor.colorNameToHex(color)
}
let initialTrackColor

if (colorSelection === 'color') {
initialTrackColor = this.track._initialColor || this.track.constructor.defaultColor
} else {
console.warn(`track color is not a string!`)
}

if (this.track.altColor && StringUtils.isString(this.track.altColor)) {

if (undefined === this.track.initialTrackColor['altColor']) {
const c = this.track.altColor
this.track.initialTrackColor['altColor'] = c.startsWith("#") ? c : c.startsWith("rgb(") ? IGVColor.rgbToHex(c) : IGVColor.colorNameToHex(c)
}

} else {
console.warn(`track altColor is not a string!`)
initialTrackColor = this.track._initialAltColor || this.track.constructor.defaultColor
}

let colorHandlers

const initialTrackColor = 0 === Object.keys(this.track.initialTrackColor).length ? undefined : this.track.initialTrackColor[ colorSelection ]

const selected = this.browser.getSelectedTrackViews()

if (selected.length > 0 && new Set(selected).has(this)) {

colorHandlers =
Expand Down Expand Up @@ -271,7 +249,7 @@ class TrackView {
};
}

const moreColorsPresentationColor = 'color' === colorSelection ? (this.track.color || this.track.constructor.defaultColor) : this.track.altColor
const moreColorsPresentationColor = 'color' === colorSelection ? (this.track.color || this.track.constructor.defaultColor) : (this.track.altColor || this.track.constructor.defaultColor)
this.browser.genericColorPicker.configure(initialTrackColor, colorHandlers[colorSelection], moreColorsPresentationColor)
this.browser.genericColorPicker.show()

Expand Down
10 changes: 6 additions & 4 deletions js/ui/menuUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,9 @@ function unsetColorMenuItem({trackView, label}) {
return {
object,
click: () => {
trackView.track.color = trackView.track.initialTrackColor ? trackView.track.initialTrackColor['color'] : undefined
trackView.repaintViews()
// trackView.track.color = trackView.track.initialTrackColor ? trackView.track.initialTrackColor['color'] : undefined;
trackView.track.color = trackView.track._initialColor || trackView.track.constructor.defaultColor;
trackView.repaintViews();
}
}
}
Expand All @@ -250,8 +251,9 @@ function unsetAltColorMenuItem({trackView, label}) {
return {
object: $e,
click: () => {
trackView.track.altColor = trackView.track.initialTrackColor ? trackView.track.initialTrackColor['altColor'] : undefined
trackView.repaintViews()
// trackView.track.altColor = trackView.track.initialTrackColor ? trackView.track.initialTrackColor['altColor'] : undefined;
trackView.track.altColor = trackView.track._initialAltColor || trackView.track.constructor.defaultColor;
trackView.repaintViews();
}
}
}
Expand Down

0 comments on commit 34543f5

Please sign in to comment.