Skip to content

Commit

Permalink
Clean up default track color implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
turner committed Nov 21, 2024
1 parent 3737306 commit 45591c1
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 29 deletions.
7 changes: 3 additions & 4 deletions js/feature/featureTrack.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ import {isSecureContext, expandRegion} from "../util/igvUtils.js"
import {IGVColor} from "../../node_modules/igv-utils/src/index.js"
import {findFeatureAfterCenter} from "./featureUtils.js"

const DEFAULT_COLOR = 'rgb(0, 0, 150)'


class FeatureTrack extends TrackBase {

static defaultColor = 'rgb(0,0,150)'

static defaults = {
type: "annotation",
maxRows: 1000, // protects against pathological feature packing cases (# of rows of overlapping feaures)
Expand Down Expand Up @@ -509,7 +508,7 @@ class FeatureTrack extends TrackBase {

// If no explicit setting use the default
if (!color) {
color = DEFAULT_COLOR // Track default
color = FeatureTrack.defaultColor // Track default
}

if (feature.alpha && feature.alpha !== 1) {
Expand Down
7 changes: 3 additions & 4 deletions js/feature/wigTrack.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ import {createCheckbox} from "../igv-icons.js"
import {ColorScaleFactory} from "../util/colorScale.js"
import ColorScaleEditor from "../ui/components/colorScaleEditor.js"

const DEFAULT_COLOR = 'rgb(150, 150, 150)'


class WigTrack extends TrackBase {

static defaultColor = 'rgb(150, 150, 150)'

static defaults = {
height: 50,
flipAxis: false,
Expand Down Expand Up @@ -408,7 +407,7 @@ class WigTrack extends TrackBase {
*/

getColorForFeature(f) {
let c = (f.value < 0 && this.altColor) ? this.altColor : this.color || DEFAULT_COLOR
let c = (f.value < 0 && this.altColor) ? this.altColor : this.color || WigTrack.defaultColor
return (typeof c === "function") ? c(f.value) : c
}

Expand Down
3 changes: 0 additions & 3 deletions js/trackBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ import {FeatureUtils, FileUtils, StringUtils} from "../node_modules/igv-utils/sr
import $ from "./vendor/jquery-3.3.1.slim.js"
import {createCheckbox} from "./igv-icons.js"
import {findFeatureAfterCenter} from "./feature/featureUtils.js"
import ColorScaleEditor from "./ui/components/colorScaleEditor.js"

const DEFAULT_COLOR = 'rgb(150,150,150)'

const fixColor = (colorString) => {
if (StringUtils.isString(colorString)) {
Expand Down
3 changes: 2 additions & 1 deletion js/trackView.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ class TrackView {
};
}

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

}
Expand Down
24 changes: 9 additions & 15 deletions js/ui/components/genericColorPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class GenericColorPicker extends GenericContainer {

}

configure(initialTrackColor, previousTrackColors, colorHandler) {
configure(initialTrackColor, previousTrackColors, colorHandler, moreColorsPresentationColor) {

this.colorSwatchContainer.innerHTML = ''

Expand Down Expand Up @@ -61,7 +61,7 @@ class GenericColorPicker extends GenericContainer {
}

// Present MoreColors picker
this.decorateMoreColorsButton(this.moreColorsContainer, previousTrackColors, colorHandler)
this.decorateMoreColorsButton(this.moreColorsContainer, previousTrackColors, colorHandler, moreColorsPresentationColor)

}

Expand All @@ -81,13 +81,13 @@ class GenericColorPicker extends GenericContainer {

}

decorateMoreColorsButton(moreColorsContainer, previousTrackColors, colorHandler) {
decorateMoreColorsButton(moreColorsContainer, previousTrackColors, colorHandler, moreColorsPresentationColor) {

moreColorsContainer.innerText = 'More Colors ...'

moreColorsContainer.addEventListener('click', event => {
event.stopPropagation()
this.createAndPresentMoreColorsPicker(moreColorsContainer, previousTrackColors, hexColorString => {
this.createAndPresentMoreColorsPicker(moreColorsContainer, previousTrackColors, moreColorsPresentationColor, hexColorString => {
colorHandler(hexColorString)
})
})
Expand All @@ -105,7 +105,7 @@ class GenericColorPicker extends GenericContainer {
this.decorateSwatch(swatch, hexColorString, colorHandler)
}

createAndPresentMoreColorsPicker(moreColorsContainer, previousTrackColors, colorHandler) {
createAndPresentMoreColorsPicker(moreColorsContainer, previousTrackColors, moreColorsPresentationColor, colorHandler) {

let picker

Expand Down Expand Up @@ -133,21 +133,15 @@ class GenericColorPicker extends GenericContainer {
editor: false,
editorFormat: 'rgb',
alpha: false,
color: moreColorsContainer.style.backgroundColor,
// color: moreColorsContainer.style.backgroundColor,
color: moreColorsPresentationColor,
}

picker = new Picker(config)

picker.onChange = (color) => {
moreColorsContainer.style.backgroundColor = color.rgba
picker.onChange = color => moreColorsContainer.style.backgroundColor = color.rgba

// Remove alpha from hex color string
const hexColorString = color.hex.substring(0,7)

colorHandler(hexColorString)
};

picker.onDone = (color) => {
picker.onDone = color => {

// Remove alpha from hex color string
const hexColorString = color.hex.substring(0,7)
Expand Down
5 changes: 3 additions & 2 deletions js/variant/variantTrack.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ import {doSortByAttributes} from "../sample/sampleUtils.js"

const isString = StringUtils.isString

const DEFAULT_COLOR = "rgb(0,0,150)"
const DEFAULT_VISIBILITY_WINDOW = 1000000
const TOP_MARGIN = 10

class VariantTrack extends TrackBase {

static defaultColor = 'rgb(0,0,150)'

static defaults = {
displayMode: "EXPANDED",
sortDirection: "ASC",
Expand Down Expand Up @@ -175,7 +176,7 @@ class VariantTrack extends TrackBase {
}

get color() {
return this._color || DEFAULT_COLOR
return this._color || VariantTrack.defaultColor
}

set color(c) {
Expand Down

0 comments on commit 45591c1

Please sign in to comment.