From 34543f5c0d2f59f82cbc1f99407442b9b507f547 Mon Sep 17 00:00:00 2001 From: turner Date: Mon, 25 Nov 2024 16:16:29 -0500 Subject: [PATCH] track initial color wrangling --- js/trackBase.js | 3 +++ js/trackView.js | 32 +++++--------------------------- js/ui/menuUtils.js | 10 ++++++---- 3 files changed, 14 insertions(+), 31 deletions(-) diff --git a/js/trackBase.js b/js/trackBase.js index 35770d6c5..70632187f 100644 --- a/js/trackBase.js +++ b/js/trackBase.js @@ -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)) { diff --git a/js/trackView.js b/js/trackView.js index 7739ce1cd..1351f743d 100644 --- a/js/trackView.js +++ b/js/trackView.js @@ -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 = @@ -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() diff --git a/js/ui/menuUtils.js b/js/ui/menuUtils.js index faf232321..205809778 100644 --- a/js/ui/menuUtils.js +++ b/js/ui/menuUtils.js @@ -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(); } } } @@ -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(); } } }