Skip to content

Commit 78eb274

Browse files
committed
Bugfix: Zooming at the beginning or end fixed. clearing selected snps when re-drawing, addex labels for x and y axis. additional bugfixes
1 parent 0865658 commit 78eb274

File tree

1 file changed

+58
-34
lines changed

1 file changed

+58
-34
lines changed

src/main/java/at/gmi/nordborglab/widgets/gwasgeneviewer/client/GWASGeneViewer.java

Lines changed: 58 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
import java.util.ArrayList;
44
import java.util.List;
55

6+
import org.danvk.dygraphs.client.DygraphOptions;
67
import org.danvk.dygraphs.client.Dygraphs;
7-
import org.danvk.dygraphs.client.Dygraphs.Options;
8+
import org.danvk.dygraphs.client.DygraphsJS;
9+
import org.danvk.dygraphs.client.events.Canvas;
810
import org.danvk.dygraphs.client.events.HightlightHandler;
911
import org.danvk.dygraphs.client.events.SelectHandler;
1012
import org.danvk.dygraphs.client.events.UnderlayHandler;
@@ -19,6 +21,8 @@
1921
import at.gmi.nordborglab.widgets.geneviewer.client.event.ZoomResizeEvent;
2022
import at.gmi.nordborglab.widgets.geneviewer.client.event.ZoomResizeHandler;
2123

24+
import com.google.gwt.canvas.dom.client.Context2d;
25+
import com.google.gwt.canvas.dom.client.FillStrokeStyle;
2226
import com.google.gwt.core.client.GWT;
2327
import com.google.gwt.core.client.JsArray;
2428
import com.google.gwt.core.client.JsArrayInteger;
@@ -215,6 +219,13 @@ public void onZoom(ZoomEvent event) {
215219
}
216220
else
217221
{
222+
223+
//Bugfix for http://code.google.com/p/dygraphs/issues/detail?id=280&thanks=280&ts=1328714824
224+
if (event.minX < 0)
225+
scatterChart.setValueRangeX(0, event.maxX);
226+
else if (event.maxX > viewEnd)
227+
scatterChart.setValueRangeX(event.minX, viewEnd);
228+
218229
if (event.maxX - event.minX<= minZoomLevelForGenomeView)
219230
{
220231
toggleGenomeViewVisible(true);
@@ -246,56 +257,62 @@ public void onUnhighlight(UnhighlightEvent event) {
246257
protected void drawScatterChart()
247258
{
248259
chromosome_label.setText(chromosome);
249-
Dygraphs.Options options = Dygraphs.Options.create();
260+
DygraphOptions options = DygraphOptions.create();
250261
options = setOptions(options);
251262
scatterChart.addUnderlayHandler(new UnderlayHandler() {
252263

253264
@Override
254265
public void onUnderlay(UnderlayEvent event) {
266+
267+
Canvas ctx = event.canvas;
268+
DygraphsJS dygraphjs = event.dygraph;
255269
for (Gene gene:displayGenes) {
256270
if (gene.getChromosome().equals(chromosome) && (gene.getStart() >= viewStart || gene.getEnd() <= viewEnd))
257271
{
258-
double left = event.dygraph.toDomXCoord(gene.getStart());
259-
double right = event.dygraph.toDomXCoord(gene.getEnd());
272+
double left = dygraphjs.toDomXCoord(gene.getStart());
273+
double right = dygraphjs.toDomXCoord(gene.getEnd());
260274
double length = right - left;
261275
if (length < 1)
262276
{
263277
left = left -0.5;
264278
length = 1;
265279
}
266-
event.canvas.save();
267-
event.canvas.setFillStyle(gene_marker_color);
268-
event.canvas.fillRect(left, event.area.getY(), length, event.area.getH());
269-
event.canvas.restore();
280+
ctx.save();
281+
ctx.setFillStyle(gene_marker_color);
282+
ctx.setStrokeStyle("#000000");
283+
ctx.fillRect(left, event.area.getY(), length, event.area.getH());
284+
ctx.restore();
270285
}
271286
}
272287

273288
for (int i =0;i<selections.length();i++)
274289
{
275290
Selection selection = selections.get(i);
276291
if (selection != null) {
277-
double posX = event.dygraph.toDomXCoord(dataTable.getValueInt(selection.getRow(), 0));
278-
double posY = event.dygraph.toDomYCoord(dataTable.getValueDouble(selection.getRow(), 1), 0);
279-
event.canvas.save();
280-
event.canvas.beginPath();
281-
event.canvas.setFillStyle(gene_marker_color);
282-
event.canvas.fillRect(posX-0.5, posY, 1, event.area.getH());
283-
event.canvas.arc(posX, posY, 3, 0, 2*Math.PI, false);
284-
event.canvas.fill();
285-
event.canvas.restore();
292+
double posX = dygraphjs.toDomXCoord(dataTable.getValueInt(selection.getRow(), 0));
293+
double posY = dygraphjs.toDomYCoord(dataTable.getValueDouble(selection.getRow(), 1), 0);
294+
ctx.save();
295+
ctx.setFillStyle(gene_marker_color);
296+
ctx.setStrokeStyle("#000000");
297+
ctx.beginPath();
298+
ctx.arc(posX,posY,4,0,Math.PI*2,true);
299+
ctx.fillRect(posX-0.5, posY, 1, dygraphjs.getArea().getH());
300+
ctx.closePath();
301+
ctx.fill();
302+
ctx.restore();
286303
}
287304
}
288305

289306
if (bonferroniThreshold != -1) {
290307
double posY = (int)event.dygraph.toDomYCoord(bonferroniThreshold, 0)-0.5;
291-
int width = event.canvas.getCanvas().getWidth();
292-
event.canvas.save();
293-
event.canvas.beginPath();
294-
event.canvas.setStrokeStyle(gene_marker_color);
295-
event.canvas.dashedLine(0, posY, width, posY);
296-
event.canvas.closePath();
297-
event.canvas.stroke();
298-
event.canvas.restore();
308+
int width = ctx.getCanvas().getWidth();
309+
ctx.save();
310+
ctx.beginPath();
311+
ctx.setStrokeStyle(gene_marker_color);
312+
ctx.dashedLine(0, posY, width, posY);
313+
ctx.closePath();
314+
ctx.stroke();
315+
ctx.restore();
299316
}
300317
}
301318

@@ -312,23 +329,26 @@ public void onUnderlay(UnderlayEvent event) {
312329
selections.set(0, selection);
313330
}
314331
scatterChart.draw(dataTable,setOptions(options));
315-
if (selections.length() > 0)
316-
scatterChart.setSelections(selections);
332+
//if (selections.length() > 0)
333+
scatterChart.setSelections(selections);
317334

318335
//scatterChart.setSelections()
319336
isScatterChartLoaded = true;
320337
}
321338

322-
protected Options setOptions(Dygraphs.Options options){
339+
340+
protected DygraphOptions setOptions(DygraphOptions options){
323341
double maxValue = max_value;
324342
if (maxValue < bonferroniThreshold)
325343
maxValue = bonferroniThreshold;
326344
options.setStrokeWidth(0.000000001);
327345
options.setDrawPoints(true);
328346
options.setPointSize(pointSize);
329347
options.setIncludeZero(true);
330-
//options.setWidth(width);
331-
//options.setHeight(scatterChartHeight);
348+
options.setYlabel("-log10(p)");
349+
options.setYLabelWidth(13.0);
350+
options.setXLabelHeight(13.0);
351+
options.setXlabel("Position");
332352
options.setAxisLabelFontSize(11);
333353
options.setValueRange(0,(int)maxValue + 2);
334354
options.setyAxisLabelWidth(20);
@@ -396,9 +416,9 @@ public void addSelectionHandler(SelectHandler handler) {
396416
public void addClickGeneHandler(ClickGeneHandler handler) {
397417
if (isGeneViewerLoaded) {
398418
geneViewer.addClickGeneHandler(handler);
399-
}
400-
else
401-
this.clickGeneHandler = handler;
419+
}
420+
else
421+
this.clickGeneHandler = handler;
402422
}
403423

404424
public void setSnpPosX(int snpPosX) {
@@ -422,10 +442,14 @@ public static Selection getSelectionFromPos(DataTable data,int pos) {
422442

423443
public void addSelection(Selection selection) {
424444
if (selection != null) {
425-
selections.set(selections.length(), selection);
445+
selections.push(selection);
426446
}
427447
}
428448

449+
public void clearSelection() {
450+
selections = JsArray.createArray().cast();
451+
}
452+
429453
public static Selection getTopSNP(DataTable data) {
430454
Selection selection = null;
431455
double top_pValue = -1;

0 commit comments

Comments
 (0)