Skip to content

Commit

Permalink
Some updates
Browse files Browse the repository at this point in the history
* Reduced default console message level.
* Changed auto-scale in bigWig display.
* Fixed interaction-track-dom.
  • Loading branch information
Xiaoyi Cao committed Nov 30, 2017
1 parent 22824d0 commit b4dfb91
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,12 @@ var GIVe = (function (give) {
!!(navigator.userAgent.match(/Trident/) ||
navigator.userAgent.match(/rv 11/)))) {
// IE detected (should be IE 11), fix the json return issue
console.log('You are currently using IE 11 to visit this site. ' +
'Some part of the site may behave differently and if you encounter ' +
'any problems, please use the info on \'About us\' page to ' +
'contact us.')
give._verboseConsole(
'You are currently using IE 11 to visit this site. ' +
'Some part of the site may behave differently and if you encounter ' +
'any problems, please use the info on \'About us\' page to ' +
'contact us.', give.VERBOSE_MAJ_ERROR
)
responses = JSON.parse(responses)
}
responseFunc.call(thisVar, responses, xhr.status)
Expand Down Expand Up @@ -194,6 +196,22 @@ var GIVe = (function (give) {
}
}

give._findPercentile = function (dataArr, upperPercentile, lowerPercentile) {
function numberComp (a, b) {
return a - b
}
lowerPercentile = lowerPercentile || upperPercentile
var sortedArr = dataArr.sort(numberComp)
return {
upper: sortedArr[parseInt(sortedArr.length * (1 - upperPercentile))],
lower: sortedArr[parseInt(sortedArr.length * lowerPercentile)]
}
}

give._maxDecimalDigits = function (number, digits) {
return Number(Math.round(number + 'e' + digits) + 'e-' + digits)
}

window.addEventListener('WebComponentsReady', function (e) {
give.fireCoreSignal('content-dom-ready', null)
give.fireSignal(give.TASKSCHEDULER_EVENT_NAME, {flag: 'web-component-ready'})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var GIVe = (function (give) {
give.VERBOSE_DEBUG = 4
give.VERBOSE_DEBUG_MORE = 5

give.verboseLvl = give.VERBOSE_DEBUG
give.verboseLvl = give.VERBOSE_MAJ_ERROR

give.Host = 'https://www.givengine.org'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ var GIVe = (function (give) {
function (revdepth, start, end, summaryCtor, nextNode, prevNode, bFactor, isroot) {
// start and length is for the corresponding region
if (isNaN(bFactor) || parseInt(bFactor) !== bFactor || bFactor <= 2) {
console.log('Default branching factor is chosen instead of ' + bFactor)
give._verboseConsole('Default branching factor is chosen instead of ' +
bFactor, give.VERBOSE_DEBUG)
bFactor = give.ChromBPlusTreeNode._DEFAULT_B_FACTOR
}
if (typeof revdepth !== 'number' || isNaN(revdepth)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,25 @@
give.TrackDOMBehavior
],
properties: {
upperPercentile: {
type: Number,
value: 0.01
},

lowerPercentile: {
type: Number,
value: 0.01
},

numOfDigits: {
type: Number,
value: 2
},

includeZero: {
type: Boolean,
value: true
}
},
created: function () {
this.MARGIN = 2
Expand Down Expand Up @@ -199,29 +218,30 @@
var vwindow = this.mainSvg.viewWindow

if (this.track.data.hasOwnProperty(vwindow.chr)) {
var updateExtreme = function (dataSegment) {
var yvalue = dataSegment.data.value
if (Math.ceil(yvalue) > this.windowMax) {
this.windowMax = Math.ceil(yvalue)
}
if (Math.floor(yvalue) < this.windowMin) {
this.windowMin = Math.floor(yvalue)
}
}.bind(this)
this.dataPoints = this._generateSmoothedPoints()

if (this.autoScale) {
this.windowMax = Number.NEGATIVE_INFINITY
this.windowMin = Number.POSITIVE_INFINITY
this.track.data[vwindow.chr].traverse(vwindow, updateExtreme, null,
this.getResolution(vwindow), this, false)
this.windowMin = this.includeZero ? 0 : Number.POSITIVE_INFINITY
try {
var extremities = give._findPercentile(this.dataPoints.map(
function (dataEntry) {
return dataEntry.data.value
}, this), this.upperPercentile, this.lowerPercentile)
if (this.windowMax < extremities.upper) {
this.windowMax = extremities.upper
}
if (this.windowMin > extremities.lower) {
this.windowMin = extremities.lower
}
} catch (e) {
}
if (this.windowMax === Number.NEGATIVE_INFINITY) {
this.windowMax = 1
this.windowMin = 0
}
}

this.dataPoints = this._generateSmoothedPoints()

if (mode === 0) {
this.drawPeak(this.dataPoints)
}
Expand Down Expand Up @@ -716,10 +736,12 @@

// then the text
this.drawText(this.textMargin - this.MARGIN - this.scaleTickLength - this.TEXT_MARGIN_GAP,
this.drawingBoundary.top + this.textSize * 0.4, this.windowMax.toString(),
this.drawingBoundary.top + this.textSize * 0.4,
give._maxDecimalDigits(this.windowMax, this.numOfDigits).toString(),
'end', null, this.textSvg)
this.drawText(this.textMargin - this.MARGIN - this.scaleTickLength - this.TEXT_MARGIN_GAP,
this.drawingBoundary.bottom - this.textSize * 0.4, this.windowMin.toString(),
this.drawingBoundary.bottom - this.textSize * 0.4,
give._maxDecimalDigits(this.windowMin, this.numOfDigits).toString(),
'end', null, this.textSvg)
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

subTrackGap: {
type: Number,
value: 4 // em
value: 6 // em
},

// data structure for interaction tracks:
Expand Down Expand Up @@ -89,6 +89,8 @@
this.numOfSubs = properties.numOfSubs
this.bufferWindow = []
this.percentiles = this.track.getSetting('thresholdPercentile')

this._pendingVWs = []
},

initSvgComponents: function () {
Expand Down Expand Up @@ -203,6 +205,66 @@
this.initSubSvgHolders()
},

drawDataFireWrapper: function (newVWindow) {
// fire track-ready event to its container (to calculate size and do other stuff)
this.changeViewWindow(newVWindow)
this.drawData()
this._setIsReady(true)
this.fire('track-ready', {ID: this.track.getID()})
if (this.callbackAfterDraw) {
this.callbackAfterDraw()
delete this.callbackAfterDraw
}
},

drawDataDebounceWrapper: function (newVWindow) {
// debounce wrapper for drawData()
this.debounce(this.updateJobName, this.drawDataFireWrapper.bind(
this, newVWindow), this._drawDebounceInt)
},

checkDataAndUpdate: function (newVWindow) {
// Steps:
// * run this.track.getData with drawData (debounced) as callback
// * whenever drawData (debounced) is done, run updateCache
// Meanwhile, run fetch data (debounced) without visible callback
// * Otherwise, run fetch data with drawData (debounced) as callback

newVWindow = newVWindow || this._pendingVWs

if (this.isDebouncerActive(this.cacheUpdateJobName)) {
this.cancelDebouncer(this.cacheUpdateJobName)
}

if (!Array.isArray(newVWindow)) {
newVWindow = [newVWindow]
}

// this is to set up cache loading functions as call back after draw
this.callbackAfterDraw = this.debounce.bind(
this, this.cacheUpdateJobName, this.track.getData.bind(
this.track,
newVWindow.map(function (range) {
return range.getExtension(
give.TrackDOMBehaviorImpl.CacheRangeSpanProportion,
null, true, this.track.ref
)
}, this), this.getResolution(newVWindow), null, this.id
), this._cacheDebounceInt)
this.track.getData(
newVWindow.map(function (range) {
return range.getExtension(
give.TrackDOMBehaviorImpl.DefaultRangeSpanProportion,
null, true, this.track.ref
)
}, this),
this.getResolution(newVWindow),
this.drawDataDebounceWrapper.bind(
this, newVWindow
), this.id
)
},

updateTracks: function (viewWindow, index, threshold) {
// viewWindow: give.ChromRegion object or an array of give.ChromRegion objects
// index: if viewWindow is a single give.ChromRegion Object, index will be the index
Expand All @@ -215,18 +277,18 @@
if (viewWindow) {
if (Array.isArray(viewWindow)) {
// then it must have enough elements
viewWindow.forEach(this.changeViewWindow, this)
this._pendingVWs = viewWindow
} else {
this.changeViewWindow(viewWindow, index)
this._pendingVWs[index] = viewWindow
}
}

if (this.subSvgs.every(function (subSvg) {
return subSvg.viewWindow
if (this._pendingVWs.every(function (pendingVWindow) {
return pendingVWindow
}, this)) {
// Get data clipped by viewWindow by calling getData()
// May also include data preparation
this.checkDataAndUpdate()
this.checkDataAndUpdate(this._pendingVWs)
// Update detailed content by calling drawData()
// Will be debounced to prevent lagging
}
Expand All @@ -245,10 +307,15 @@
},

changeViewWindow: function (viewWindow, index) {
if (typeof (viewWindow) === 'string') {
this.subSvgs[index].viewWindow = new give.ChromRegion(viewWindow, this.track.ref)
if (Array.isArray(viewWindow)) {
viewWindow.forEach(this.changeViewWindow, this)
} else {
this.subSvgs[index].viewWindow = viewWindow.clipRegion(this.track.ref).clone()
if (typeof (viewWindow) === 'string') {
this.subSvgs[index].viewWindow = new give.ChromRegion(viewWindow, this.track.ref)
} else {
this.subSvgs[index].viewWindow = viewWindow.clipRegion(this.track.ref).clone()
}
this._pendingVWs[index] = this.subSvgs[index].viewWindow
}
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -861,19 +861,25 @@
this.cancelDebouncer(this.cacheUpdateJobName)
}

var newVWArr = Array.isArray(newVWindow) ? newVWindow : [newVWindow]

// this is to set up cache loading functions as call back after draw
this.callbackAfterDraw = this.debounce.bind(
this, this.cacheUpdateJobName, this.track.getData.bind(
this.track, newVWindow.getExtension(
give.TrackDOMBehaviorImpl.CacheRangeSpanProportion,
null, true, this.track.ref
), this.getResolution(newVWindow), null, this.id
this.track, newVWArr.map(function (range) {
return range.getExtension(
give.TrackDOMBehaviorImpl.CacheRangeSpanProportion,
null, true, this.track.ref
)
}, this), this.getResolution(newVWindow), null, this.id
), this._cacheDebounceInt)
this.track.getData(
newVWindow.getExtension(
give.TrackDOMBehaviorImpl.DefaultRangeSpanProportion,
null, true, this.track.ref
), this.getResolution(newVWindow),
newVWArr.map(function (range) {
return range.getExtension(
give.TrackDOMBehaviorImpl.DefaultRangeSpanProportion,
null, true, this.track.ref
)
}, this), this.getResolution(newVWindow),
this.drawDataDebounceWrapper.bind(
this, newVWindow
), this.id)
Expand Down Expand Up @@ -946,7 +952,7 @@
if (typeof (viewWindow) === 'string') {
return new give.ChromRegion(viewWindow, this.track.ref)
} else {
return viewWindow.clipRegion(this.track.ref).clone()
return viewWindow.clone().clipRegion(this.track.ref)
}
// this.set('viewWindowString', newValue);
},
Expand Down

0 comments on commit b4dfb91

Please sign in to comment.