Skip to content

Commit 2f3c9e6

Browse files
committed
Add alpha support for RangeSelector view.
Reset zoom when viewRegion is set.
1 parent 1a057db commit 2f3c9e6

File tree

1 file changed

+117
-8
lines changed

1 file changed

+117
-8
lines changed

src/at/gmi/nordborglab/widgets/geneviewer/client/GeneViewer.pde

100644100755
Lines changed: 117 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ void api_setChromosome(String chr)
6262
browser.chr = chr;
6363
}
6464

65+
void api_setShowRangeSelector(int showRangeSelector) {
66+
layout.setShowRangeSelector(showRangeSelector);
67+
}
68+
6569
int api_getLength()
6670
{
6771
return layout.getViewLength();
@@ -239,9 +243,15 @@ class Layout
239243
DrawArea area = null;
240244

241245
float pxPerBp=1;
246+
float absolutePxPerBp=1;
242247

243248
//where to display scale (0 = no display, 1 = bottom, 2 = top)
244249
int showScale = 1;
250+
251+
// where to display range selector (0 = no display, 1 = bottom, 2 = top)
252+
int showRangeSelector = 1;
253+
int rangeSelectorHeight=40;
254+
int rangeSelectorGridCount = 10;
245255

246256
// how many vertical grid lines should be drawn
247257
int gridLineCount = 5;
@@ -282,7 +292,7 @@ class Layout
282292
if (getZoomLength() <= maximumZoomToDrawFeatures)
283293
scale = 3;
284294
laneSize = cdsHeight*scale;
285-
laneCount = floor((this.area.height-laneMarginTop) / laneSize);
295+
laneCount = floor((this.area.height-getLaneMarginTop()) / laneSize);
286296
lanes = new int[laneCount];
287297
resetLanes();
288298
}
@@ -295,30 +305,42 @@ class Layout
295305
}
296306
}
297307

308+
void setShowRangeSelector(showRangeSelector) {
309+
this.showRangeSelector = showRangeSelector;
310+
initLanes();
311+
draw();
312+
}
313+
298314
void initArea()
299315
{
300316
this.area = new DrawArea(marginLeft,marginTop,(width - marginLeft - marginRight),(height - marginTop - marginBottom));
301317
}
302318

303319
void setViewRegion(int start, int end)
304320
{
305-
if (zoomStart == 0)
321+
/*if (zoomStart == 0)
306322
zoomStart = start;
307323
else if (zoomStart < start)
308324
zoomStart = start;
309325
if (zoomEnd == 0)
310326
zoomEnd = end;
311327
else if (zoomEnd > end)
312328
zoomEnd = end;
329+
*/
330+
zoomStart = start;
331+
zoomEnd = end;
313332
viewStart = start;
314333
viewEnd = end;
315334
initPxPerBb();
335+
fetchGenes();
316336
}
317337

318338
void initPxPerBb()
319339
{
320340
if (this.zoomEnd - this.zoomStart != 0)
321341
this.pxPerBp = (float)this.area.width / (this.zoomEnd - this.zoomStart);
342+
if (this.viewEnd - this.viewStart != 0)
343+
this.absolutePxPerBp = (float)this.area.width / (this.viewEnd - this.viewStart);
322344
}
323345

324346
void getFreeLane(x) {
@@ -343,6 +365,13 @@ class Layout
343365
return vector;
344366
}
345367

368+
int getLaneMarginTop() {
369+
int top = laneMarginTop;
370+
if (showRangeSelector != 0)
371+
top = top + rangeSelectorHeight;
372+
return top;
373+
}
374+
346375
int getLanePosY(int lane)
347376
{
348377
return area.y + laneMarginTop + (lane*laneSize);
@@ -425,6 +454,18 @@ class Layout
425454
{
426455
return (int)(zoomEnd - zoomStart)/gridLineCount;
427456
}
457+
458+
int getRangeSelectorGridLineBpSeperation()
459+
{
460+
return (int)(viewEnd - viewStart)/rangeSelectorGridCount;
461+
}
462+
463+
int getRangeSelectorHeight() {
464+
int currentHeight= 0;
465+
if (showRangeSelector != 0)
466+
currentHeight = rangeSelectorHeight;
467+
return currentHeight;
468+
}
428469

429470

430471
float pxToBp(float pixel)
@@ -437,6 +478,14 @@ class Layout
437478
return pxPerBp * bp;
438479
}
439480

481+
float absolutebpToPx(int bp) {
482+
return absolutePxPerBp*bp;
483+
}
484+
485+
float absolutepxToBp(float pixel) {
486+
return (float) pixel / absolutePxPerBp;
487+
}
488+
440489
int getGenomePosition(int position_px )
441490
{
442491
return round(pxToBp(position_px-area.x) + zoomStart);
@@ -573,6 +622,7 @@ class GenomeBrowser
573622
void render()
574623
{
575624
renderControls();
625+
renderRangeSelector();
576626
if (genes != null)
577627
{
578628
for (int i = 0;i<genes.size();i++)
@@ -586,6 +636,8 @@ class GenomeBrowser
586636
}
587637

588638

639+
640+
589641
void renderZoomArea()
590642
{
591643
if(layout.mouseButtonPressed ==LEFT)
@@ -602,7 +654,7 @@ class GenomeBrowser
602654
endPosition = layout.area.x;
603655
else if (endPosition > layout.area.getEndPosX())
604656
endPosition = layout.area.getEndPosX();
605-
rect(startPosition,layout.area.y+10,endPosition,layout.area.getEndPosY()-layout.labelScaleSize);
657+
rect(startPosition,layout.area.y+10,endPosition,layout.area.getEndPosY()-layout.labelScaleSize - layout.getRangeSelectorHeight());
606658
fill(100);
607659
String Position = round(layout.pxToBp(startPosition-layout.area.x) + layout.zoomStart);
608660
String zoomWidth = layout.convertToReadableBp(Math.abs(round(layout.pxToBp(startPosition-layout.area.x) - layout.pxToBp(endPosition))));
@@ -611,7 +663,7 @@ class GenomeBrowser
611663
else
612664
textAlign(LEFT,BASELINE);
613665
text(Position,layout.mouseButtonPressedX,10);
614-
text(zoomWidth,startPosition + Math.abs((endPosition-startPosition)/2)+textWidth(zoomWidth)/2,layout.area.getEndPosY()-layout.labelScaleSize);
666+
text(zoomWidth,startPosition + Math.abs((endPosition-startPosition)/2)+textWidth(zoomWidth)/2,layout.area.getEndPosY()-layout.labelScaleSize - layout.getRangeSelectorHeight());
615667
}
616668
}
617669

@@ -626,7 +678,7 @@ class GenomeBrowser
626678
layout.mousePositionX = layout.area.getEndPosX();
627679

628680
stroke(layout.selectionLineColor);
629-
line(layout.mousePositionX+0.5,layout.area.y,layout.mousePositionX+0.5,layout.area.height);
681+
line(layout.mousePositionX+0.5,layout.area.y,layout.mousePositionX+0.5,layout.area.height-layout.labelScaleSize - layout.getRangeSelectorHeight());
630682
fill(layout.selectionLineColor);
631683
String Position = layout.getGenomePositionFromMouse();
632684
if ((layout.mousePositionX + textWidth(Position) < layout.area.getEndPosX()))
@@ -636,6 +688,62 @@ class GenomeBrowser
636688
text(Position,layout.mousePositionX+0.5,0);
637689
}
638690
}
691+
692+
void renderRangeSelector() {
693+
694+
if (layout.showRangeSelector != 0) {
695+
int scaleLineY = 0;
696+
int scaleTextY = 0;
697+
int gridLineSeperation = layout.getRangeSelectorGridLineBpSeperation();
698+
float gridLineSeperationPx = layout.absolutebpToPx(gridLineSeperation);
699+
if (layout.showRangeSelector == 1) {
700+
scaleTextY = layout.area.getEndPosY();
701+
scaleLineY = scaleTextY - layout.labelScaleSize;
702+
}
703+
else
704+
{
705+
scaleTextY = layout.area.getStartPosY();
706+
scaleLineY = scaleTextY + layout.labelScaleSize;
707+
}
708+
fill(0);
709+
stroke(150);
710+
textFont(layout.font,layout.labelScaleSize);
711+
textAlign(LEFT,BASELINE);
712+
713+
for (int i =0;i<=layout.rangeSelectorGridCount;i++)
714+
{
715+
int x = round(i*gridLineSeperationPx + layout.area.x)+0.5;
716+
line(x,scaleLineY,x,scaleLineY-2);
717+
text(round(layout.viewStart + i*gridLineSeperation),x,scaleTextY);
718+
}
719+
line(layout.area.x,scaleLineY+0.5,layout.area.getEndPosX(),scaleLineY+0.5);
720+
721+
fill(100,20);
722+
noStroke();
723+
rectMode(CORNERS);
724+
725+
int y_startPosition = scaleLineY -layout.getRangeSelectorHeight()+layout.labelScaleSize;
726+
int y_endPosition = scaleLineY;
727+
int l_startPosition = 0;
728+
int l_endPosition = layout.absolutebpToPx(layout.zoomStart);
729+
730+
731+
rect(l_startPosition,y_startPosition,l_endPosition,y_endPosition);
732+
int r_startPosition = layout.absolutebpToPx(layout.zoomEnd);
733+
int r_endPosition = layout.area.getEndPosX();
734+
rect(r_startPosition,y_startPosition,r_endPosition,y_endPosition);
735+
stroke(100);
736+
strokeWeight(2.2);
737+
line(l_startPosition,y_startPosition,
738+
l_endPosition,y_startPosition);
739+
line(r_startPosition,y_startPosition,
740+
r_endPosition,y_startPosition);
741+
line(l_endPosition,y_startPosition,l_endPosition,y_endPosition);
742+
line(r_startPosition,y_startPosition,r_startPosition,y_endPosition);
743+
line(l_endPosition,y_endPosition,r_startPosition,y_endPosition);
744+
strokeWeight(1);
745+
}
746+
}
639747

640748
void renderControls()
641749
{
@@ -646,13 +754,13 @@ class GenomeBrowser
646754
float gridLineSeperationPx = layout.bpToPx(gridLineSeperation);
647755
if (layout.showScale == 1)
648756
{
649-
scaleTextY = layout.area.getEndPosY();
757+
scaleTextY = layout.area.getEndPosY() - layout.getRangeSelectorHeight();
650758
scaleLineY = scaleTextY - layout.labelScaleSize;
651759

652760
}
653761
else
654762
{
655-
scaleTextY = layout.area.getEndPosY();
763+
scaleTextY = layout.area.getEndPosY() - layout.getRangeSelectorHeight();
656764
scaleLineY = scaleTextY + layout.labelScaleSize;
657765
}
658766
fill(0);
@@ -663,7 +771,7 @@ class GenomeBrowser
663771
for (int i =0;i<=layout.gridLineCount;i++)
664772
{
665773
int x = round(i*gridLineSeperationPx + layout.area.x)+0.5;
666-
line(x,0,x,layout.height);
774+
line(x,0,x,(layout.height- layout.getRangeSelectorHeight()));
667775
text(round(layout.zoomStart + i*gridLineSeperation),x,scaleTextY);
668776
}
669777
line(layout.area.x,scaleLineY+0.5,layout.area.getEndPosX(),scaleLineY+0.5);
@@ -699,6 +807,7 @@ class GenomeBrowser
699807
}
700808

701809

810+
702811
class Gene
703812
{
704813
String strand;

0 commit comments

Comments
 (0)