23
23
import com .google .gwt .core .client .JsArray ;
24
24
import com .google .gwt .core .client .JsArrayInteger ;
25
25
import com .google .gwt .core .client .JsArrayMixed ;
26
+ import com .google .gwt .core .client .Scheduler ;
27
+ import com .google .gwt .core .client .Scheduler .ScheduledCommand ;
28
+ import com .google .gwt .dom .client .Style .Unit ;
26
29
import com .google .gwt .uibinder .client .UiBinder ;
27
30
import com .google .gwt .user .client .ui .Composite ;
28
31
import com .google .gwt .user .client .ui .HTMLPanel ;
@@ -45,6 +48,14 @@ interface ScatterGenomeChartUiBinder extends UiBinder<Widget, GWASGeneViewer> {
45
48
@ UiField Label chromosome_label ;
46
49
@ UiField GeneViewer geneViewer ;
47
50
51
+ private final ScheduledCommand layoutCmd = new ScheduledCommand () {
52
+ public void execute () {
53
+ layoutScheduled = false ;
54
+ forceLayout ();
55
+ }
56
+ };
57
+ private boolean layoutScheduled = false ;
58
+
48
59
//Scatterchart settings
49
60
private static int DYGRAPHOFFSET = 31 ;
50
61
protected double max_value ;
@@ -69,8 +80,8 @@ interface ScatterGenomeChartUiBinder extends UiBinder<Widget, GWASGeneViewer> {
69
80
70
81
//General settings
71
82
protected String chromosome ;
72
- protected int width = 1000 ;
73
- protected int geneViewerHeight = 300 ;
83
+ protected int width = 0 ;
84
+ protected int geneViewerHeight = 326 ;
74
85
protected DataSource datasource = null ;
75
86
protected int viewStart = 0 ;
76
87
protected int viewEnd = 0 ;
@@ -84,10 +95,25 @@ public GWASGeneViewer() {
84
95
initGenomeView ();
85
96
}
86
97
87
- public GWASGeneViewer (String chromosome ,String color ,String gene_marker_color ,int width ,DataSource datasource ) {
98
+ @ Override
99
+ public void setWidth (String width ) {
100
+ scatterChart .setWidth (width );
101
+ }
102
+
103
+ @ Override
104
+ public void setHeight (String height ) {
105
+ scatterChart .setHeight (height );
106
+ }
107
+
108
+ @ Override
109
+ public void setSize (String width ,String height ) {
110
+ scatterChart .setSize (width , height );
111
+ }
112
+
113
+ public GWASGeneViewer (String chromosome ,String color ,String gene_marker_color ,DataSource datasource ) {
88
114
this .chromosome = chromosome ;
89
115
this .color = color ;
90
- this .width =width ;
116
+ // this.width=width;
91
117
this .datasource = datasource ;
92
118
this .gene_marker_color = gene_marker_color ;
93
119
initWidget (uiBinder .createAndBindUi (this ));
@@ -113,8 +139,12 @@ private void initGenomeView()
113
139
{
114
140
try
115
141
{
142
+ scatterChart .setSize ("100%" , scatterChartHeight +"px" );
143
+ geneViewer .setWidthOffset (DYGRAPHOFFSET );
116
144
geneViewer .setViewRegion (viewStart , viewEnd );
117
- geneViewer .setSize (width - DYGRAPHOFFSET , geneViewerHeight );
145
+ geneViewer .setWidth ("100%" );
146
+ geneViewer .setHeight (geneViewerHeight +"px" );
147
+ //geneViewer.setSize(width - DYGRAPHOFFSET, geneViewerHeight);
118
148
geneViewer .load (new Runnable () {
119
149
@ Override
120
150
public void run () {
@@ -163,7 +193,7 @@ public void draw(DataTable dataTable,double max_value, int start,int end,double
163
193
geneViewer .setViewRegion (start ,end );
164
194
geneViewer .setChromosome (chromosome );
165
195
geneViewer .setDataSource (datasource );
166
- geneViewer .setSize (width - DYGRAPHOFFSET , geneViewerHeight );
196
+ // geneViewer.setSize(width - DYGRAPHOFFSET, geneViewerHeight);
167
197
this .drawScatterChart ();
168
198
if (minZoomLevelForGenomeView >= (viewEnd - viewStart )) {
169
199
toggleGenomeViewVisible (true );
@@ -293,11 +323,10 @@ protected Options setOptions(Dygraphs.Options options){
293
323
options .setDrawPoints (true );
294
324
options .setPointSize (pointSize );
295
325
options .setIncludeZero (true );
296
- options .setWidth (width );
297
- options .setHeight (scatterChartHeight );
298
- options .setAxisLabelFontSize (12 );
326
+ // options.setWidth(width);
327
+ // options.setHeight(scatterChartHeight);
328
+ options .setAxisLabelFontSize (11 );
299
329
options .setValueRange (0 ,(int )maxValue + 2 );
300
- options .setxAxisLabelWidth (100 );
301
330
options .setyAxisLabelWidth (20 );
302
331
options .setColors (new String [] {color });
303
332
options .setMinimumDistanceForHighlight (10 );
@@ -309,9 +338,11 @@ protected Options setOptions(Dygraphs.Options options){
309
338
310
339
public void toggleGenomeViewVisible (boolean visible ) {
311
340
//geneViewerContainer.setVisible(visible);
341
+ if (geneViewer .isVisible () == visible )
342
+ return ;
312
343
geneViewer .setVisible (visible );
313
344
if (visible ) {
314
- geneViewer .setSize (width - DYGRAPHOFFSET , geneViewerHeight );
345
+ // geneViewer.setSize(width - DYGRAPHOFFSET, geneViewerHeight);
315
346
geneViewer .onResize ();
316
347
}
317
348
}
@@ -414,7 +445,29 @@ public Selection getTopSNP() {
414
445
415
446
@ Override
416
447
public void onResize () {
448
+ scheduledLayout ();
449
+ }
450
+
451
+ @ Override
452
+ public void onAttach () {
453
+ super .onAttach ();
454
+ scheduledLayout ();
455
+ }
456
+
457
+
458
+ public void forceLayout () {
459
+ if (!isAttached ())
460
+ return ;
461
+ int width = getParent ().getParent ().getElement ().getClientWidth ();
462
+ getElement ().getStyle ().setWidth (width , Unit .PX );
417
463
geneViewer .onResize ();
418
464
scatterChart .onResize ();
419
465
}
466
+
467
+ private void scheduledLayout () {
468
+ if (isAttached () && !layoutScheduled ) {
469
+ layoutScheduled = true ;
470
+ Scheduler .get ().scheduleDeferred (layoutCmd );
471
+ }
472
+ }
420
473
}
0 commit comments