Skip to content

Commit 7845bec

Browse files
committed
Proper layout handling. Size will be automatically calculated from the container
1 parent e339f81 commit 7845bec

File tree

1 file changed

+50
-26
lines changed

1 file changed

+50
-26
lines changed

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

Lines changed: 50 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@
3737

3838
import com.google.gwt.core.client.GWT;
3939
import com.google.gwt.core.client.JavaScriptObject;
40+
import com.google.gwt.core.client.Scheduler;
41+
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
4042
import com.google.gwt.dom.client.SpanElement;
43+
import com.google.gwt.dom.client.Style.Unit;
4144
import com.google.gwt.event.dom.client.ClickEvent;
4245
import com.google.gwt.event.dom.client.ClickHandler;
4346
import com.google.gwt.event.logical.shared.ValueChangeEvent;
@@ -91,7 +94,6 @@ interface GeneViewerUiBinder extends UiBinder<Widget, GeneViewer> {
9194
public enum SHOW_RANGE_SELECTOR {None,Bottom,Top};
9295

9396
protected boolean fetchGenes = true;
94-
protected boolean dynamicWidth = false;
9597
protected boolean showStatsBand = true;
9698
protected int viewStart = 0;
9799
protected int viewEnd = 0;
@@ -109,10 +111,17 @@ public enum SHOW_RANGE_SELECTOR {None,Bottom,Top};
109111
protected List<GenomeStat> currentGenomeStats;
110112
protected DataTable stackableGenomeStatsCache = null;
111113
protected HashMap<GenomeStat,DataTable> nonstackableGenomeStatsCache = new HashMap<GenomeStat,DataTable>();
112-
113-
114114
protected Dygraphs.Options options = Dygraphs.Options.create();
115115
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;
116125

117126
@UiField Processing<GeneViewerInstance> processing;
118127
@UiField Dygraphs genomeStatChart;
@@ -150,14 +159,17 @@ public void onValueChange(ValueChangeEvent<Boolean> event) {
150159
}
151160

152161

162+
public void setWidthOffset(int offset) {
163+
this.width_offset = offset;
164+
}
153165

154-
public void setSize(Integer width,Integer height)
166+
/*public void setSize(Integer width,Integer height)
155167
{
156168
if (!dynamicWidth) {
157169
this.width= width;
158170
}
159171
this.height = height - (showStatsBand ? statsBandHeight : 0);
160-
}
172+
}*/
161173

162174
public void setDataSource(DataSource datasource) {
163175
this.datasource = datasource;
@@ -409,24 +421,8 @@ public void onClickGene(ClickGeneEvent event) {
409421
Window.open(geneInfoUrl.replace("{0}", event.getGene().getName()),"","");
410422
}
411423

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-
}
426424

427-
public void setDynamicWidth(boolean flag) {
428-
this.dynamicWidth = flag;
429-
}
425+
430426

431427
private void loadGenomeStats() {
432428
if (datasource == null || !showStatsBand)
@@ -570,8 +566,6 @@ private List<GenomeStat> getMissingGenomeStats() {
570566
protected void drawStatistics() {
571567
DataView view = filterStatsToDisplay();
572568
if (view != null) {
573-
genomeStatChart.setOptions(options);
574-
genomeStatChart.setData(view);
575569
genomeStatChart.draw(view,createOptions(currentGenomeStats.get(0).isStepPlot()));
576570
isGenomeStatsDrawn = true;
577571
}
@@ -615,8 +609,7 @@ private Dygraphs.Options createOptions(boolean stepPlot) {
615609
options.setIncludeZero(true);
616610
options.setWidth(width);
617611
options.setHeight(statsBandHeight);
618-
options.setAxisLabelFontSize(12);
619-
options.setxAxisLabelWidth(100);
612+
options.setAxisLabelFontSize(11);
620613
options.setyAxisLabelWidth(20);
621614
options.setMinimumDistanceForHighlight(10);
622615
options.setFillGraph(true);
@@ -628,6 +621,8 @@ private Dygraphs.Options createOptions(boolean stepPlot) {
628621
}
629622

630623
private void initStatisticsChart() {
624+
genomeStatChart.setWidth("100%");
625+
genomeStatChart.setHeight(statsBandHeight+"px");
631626
genomeStatChart.addUnderlayHandler(new UnderlayHandler() {
632627

633628
@Override
@@ -732,4 +727,33 @@ public void setVisible(boolean visible) {
732727
}
733728

734729

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+
}
735759
}

0 commit comments

Comments
 (0)