Skip to content

Commit 22824d0

Browse files
author
Xiaoyi Cao
committed
Minor fix
* Turned on auto scaling for all bigWig tracks. * Fixed text collision detection in label displaying.
1 parent e203455 commit 22824d0

File tree

2 files changed

+26
-27
lines changed

2 files changed

+26
-27
lines changed

give/html/components/bower_components/genemo-visual-components/chart-area/track-doms/bigwig-track-dom.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
/**
7979
* Whether or not to automatically scale the window bounds according to the data displayed.
8080
*/
81-
this.autoScale = false
81+
this.autoScale = true
8282

8383
/**
8484
* The amount of points used around one point; an average value of the points is displayed rather than the actual value at any given point.

give/html/components/bower_components/genemo-visual-components/chart-area/track-doms/track-dom-behavior.html

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -782,35 +782,34 @@
782782
// then draw everything in results
783783
// get all text elements in the svg in case collision detection is needed
784784
var textList = Polymer.dom(svgToDraw).querySelectorAll('text')
785-
textArray = Array.prototype.slice.call(textList)
786-
var currY = y - ((results.length - 1) * vertParam + 1) * (this.lineGap + this.fullHeight) * this.textSize
787-
if (!avoidCollision || resultWidths.every(function (width, index) {
785+
var oldTextArray = Array.prototype.slice.call(textList)
786+
// then store all new labels in newTextArray for collision detection
787+
var newTextArray = []
788+
var currY = y - (results.length - 1) * vertParam *
789+
(this.lineGap + this.fullHeight) * this.textSize
790+
results.forEach(function (line, index) {
791+
newTextArray.push(this.drawText(
792+
x, currY, line, textAnchor, params, svgToDraw
793+
))
788794
currY += (this.lineGap + this.fullHeight) * this.textSize
789-
var left = x
790-
var right = x
791-
switch (textAnchor) {
792-
case 'start':
793-
right += width
794-
break
795-
case 'end':
796-
left -= width
797-
break
798-
case 'middle':
799-
right += width / 2
800-
left -= width / 2
801-
break
802-
}
803-
return textArray.every(function (text, indexT) {
804-
var rect = text.getBBox()
805-
return (rect.x >= right || (rect.x + rect.width) <= left ||
806-
rect.y > (currY + (this.lineGap + this.fullHeight) * this.textSize) ||
807-
(rect.y + rect.height) < currY)
795+
}, this)
796+
797+
// collision detection, if collision is detected, remove all new labels
798+
// because there should not be many text elements within the labeling
799+
// area, a brute-force approach should be enough
800+
if (avoidCollision && newTextArray.some(function (newNode) {
801+
var newBox = newNode.getBBox()
802+
return oldTextArray.some(function (oldNode) {
803+
var oldBox = oldNode.getBBox()
804+
return (newBox.x + newBox.width > oldBox.x) &&
805+
(oldBox.x + oldBox.width > newBox.x) &&
806+
(newBox.y + newBox.height > oldBox.y) &&
807+
(oldBox.y + oldBox.height > newBox.y)
808808
}, this)
809809
}, this)) {
810-
currY = y - (results.length - 1) * vertParam * (this.lineGap + this.fullHeight) * this.textSize
811-
results.forEach(function (line, index) {
812-
this.drawText(x, currY, line, textAnchor, params, svgToDraw)
813-
currY += (this.lineGap + this.fullHeight) * this.textSize
810+
// collision found, remove everything from the newTextArray
811+
newTextArray.forEach(function (textElem) {
812+
this.removeElement(textElem, svgToDraw)
814813
}, this)
815814
}
816815
},

0 commit comments

Comments
 (0)