37
37
38
38
import com .google .gwt .core .client .GWT ;
39
39
import com .google .gwt .core .client .JavaScriptObject ;
40
+ import com .google .gwt .core .client .Scheduler ;
41
+ import com .google .gwt .core .client .Scheduler .ScheduledCommand ;
40
42
import com .google .gwt .dom .client .SpanElement ;
43
+ import com .google .gwt .dom .client .Style .Unit ;
41
44
import com .google .gwt .event .dom .client .ClickEvent ;
42
45
import com .google .gwt .event .dom .client .ClickHandler ;
43
46
import com .google .gwt .event .logical .shared .ValueChangeEvent ;
@@ -91,7 +94,6 @@ interface GeneViewerUiBinder extends UiBinder<Widget, GeneViewer> {
91
94
public enum SHOW_RANGE_SELECTOR {None ,Bottom ,Top };
92
95
93
96
protected boolean fetchGenes = true ;
94
- protected boolean dynamicWidth = false ;
95
97
protected boolean showStatsBand = true ;
96
98
protected int viewStart = 0 ;
97
99
protected int viewEnd = 0 ;
@@ -109,10 +111,17 @@ public enum SHOW_RANGE_SELECTOR {None,Bottom,Top};
109
111
protected List <GenomeStat > currentGenomeStats ;
110
112
protected DataTable stackableGenomeStatsCache = null ;
111
113
protected HashMap <GenomeStat ,DataTable > nonstackableGenomeStatsCache = new HashMap <GenomeStat ,DataTable >();
112
-
113
-
114
114
protected Dygraphs .Options options = Dygraphs .Options .create ();
115
115
protected DataTable statisticsDataTable ;
116
+ protected int width_offset = 31 ;
117
+
118
+ private final ScheduledCommand layoutCmd = new ScheduledCommand () {
119
+ public void execute () {
120
+ layoutScheduled = false ;
121
+ forceLayout ();
122
+ }
123
+ };
124
+ private boolean layoutScheduled = false ;
116
125
117
126
@ UiField Processing <GeneViewerInstance > processing ;
118
127
@ UiField Dygraphs genomeStatChart ;
@@ -150,14 +159,17 @@ public void onValueChange(ValueChangeEvent<Boolean> event) {
150
159
}
151
160
152
161
162
+ public void setWidthOffset (int offset ) {
163
+ this .width_offset = offset ;
164
+ }
153
165
154
- public void setSize (Integer width ,Integer height )
166
+ /* public void setSize(Integer width,Integer height)
155
167
{
156
168
if (!dynamicWidth) {
157
169
this.width= width;
158
170
}
159
171
this.height = height - (showStatsBand ? statsBandHeight : 0);
160
- }
172
+ }*/
161
173
162
174
public void setDataSource (DataSource datasource ) {
163
175
this .datasource = datasource ;
@@ -409,24 +421,8 @@ public void onClickGene(ClickGeneEvent event) {
409
421
Window .open (geneInfoUrl .replace ("{0}" , event .getGene ().getName ()),"" ,"" );
410
422
}
411
423
412
- @ Override
413
- public void onResize () {
414
- if (!dynamicWidth )
415
- return ;
416
- width = getOffsetWidth ();
417
- if (processing .isLoaded ()) {
418
- processing .getInstance ().setLayoutSize (width -31 ,height );
419
- processing .getInstance ().redraw (false );
420
- genomeStatChart .onResize ();
421
- //if (showStatsBand)
422
- //genomeStatChart.redraw();
423
- }
424
-
425
- }
426
424
427
- public void setDynamicWidth (boolean flag ) {
428
- this .dynamicWidth = flag ;
429
- }
425
+
430
426
431
427
private void loadGenomeStats () {
432
428
if (datasource == null || !showStatsBand )
@@ -570,8 +566,6 @@ private List<GenomeStat> getMissingGenomeStats() {
570
566
protected void drawStatistics () {
571
567
DataView view = filterStatsToDisplay ();
572
568
if (view != null ) {
573
- genomeStatChart .setOptions (options );
574
- genomeStatChart .setData (view );
575
569
genomeStatChart .draw (view ,createOptions (currentGenomeStats .get (0 ).isStepPlot ()));
576
570
isGenomeStatsDrawn = true ;
577
571
}
@@ -615,8 +609,7 @@ private Dygraphs.Options createOptions(boolean stepPlot) {
615
609
options .setIncludeZero (true );
616
610
options .setWidth (width );
617
611
options .setHeight (statsBandHeight );
618
- options .setAxisLabelFontSize (12 );
619
- options .setxAxisLabelWidth (100 );
612
+ options .setAxisLabelFontSize (11 );
620
613
options .setyAxisLabelWidth (20 );
621
614
options .setMinimumDistanceForHighlight (10 );
622
615
options .setFillGraph (true );
@@ -628,6 +621,8 @@ private Dygraphs.Options createOptions(boolean stepPlot) {
628
621
}
629
622
630
623
private void initStatisticsChart () {
624
+ genomeStatChart .setWidth ("100%" );
625
+ genomeStatChart .setHeight (statsBandHeight +"px" );
631
626
genomeStatChart .addUnderlayHandler (new UnderlayHandler () {
632
627
633
628
@ Override
@@ -732,4 +727,33 @@ public void setVisible(boolean visible) {
732
727
}
733
728
734
729
730
+ @ Override
731
+ public void onResize () {
732
+ scheduledLayout ();
733
+ }
734
+
735
+ @ Override
736
+ public void onAttach () {
737
+ super .onAttach ();
738
+ scheduledLayout ();
739
+ }
740
+
741
+ public void forceLayout () {
742
+ if (!isAttached () || !isVisible ())
743
+ return ;
744
+ width = getElement ().getClientWidth () - width_offset ;
745
+ height = getElement ().getClientHeight () - (showStatsBand ? statsBandHeight : 0 ) - settings_btn .getElement ().getClientHeight ();
746
+ if (processing .isLoaded ()) {
747
+ processing .getInstance ().setLayoutSize (width , height );
748
+ processing .getInstance ().redraw (false );
749
+ genomeStatChart .onResize ();
750
+ }
751
+ }
752
+
753
+ private void scheduledLayout () {
754
+ if (isAttached () && !layoutScheduled ) {
755
+ layoutScheduled = true ;
756
+ Scheduler .get ().scheduleDeferred (layoutCmd );
757
+ }
758
+ }
735
759
}
0 commit comments