public void setTrackWindow(TrackWindow window, int newPixelX) { TrackWindow prev = this.window; this.window = window; if (!prev.hasSameScaleWith(window)) { Style.scaleXwithAnimation( canvas, (double) window.getPixelWidth() / prev.getPixelWidth(), newPixelX, 0.5); } else { Style.scaleX(canvas, 1); } }
protected void update(TrackWindow newWindow, boolean forceReload) { current = newWindow; if (!forceReload && geneCanvas.hasCacheCovering(newWindow)) { if (!needUpdateForGraphicRefinement) { geneCanvas.setTrackWindow(newWindow, false); refresh(); return; } } geneCanvas.setTrackWindow(newWindow, true); // retrieve gene data from the API TrackWindow prefetchWindow = geneCanvas.getPrefetchWindow(); String chr = getTrackGroupProperty(UTGBProperty.TARGET); ReadQueryConfig queryConfig = new ReadQueryConfig( prefetchWindow.getPixelWidth(), BrowserInfo.isCanvasSupported(), Layout.valueOf(Layout.class, style.layout.toUpperCase()), style.numReadsMax, getWIGPath()); queryConfig.window = GraphWindow.valueOf( GraphWindow.class, getConfig().getString(CONFIG_GRAPH_WINDOW, "MEDIAN")); getFrame().setNowLoading(); getBrowserService() .getOnGenomeData( getGenomeDB(), new ChrLoc(chr, prefetchWindow.getStartOnGenome(), prefetchWindow.getEndOnGenome()), queryConfig, new AsyncCallback<List<GenomeRange>>() { public void onFailure(Throwable e) { GWT.log("failed to retrieve gene data", e); UTGBEntryPointBase.showErrorMessage( "read data retrieval failed: " + e.getMessage()); needUpdateForGraphicRefinement = true; getFrame().loadingDone(); } public void onSuccess(List<GenomeRange> dataSet) { if ("pileup".equals(style.layout) && dataSet.size() > 0 && DataChecker.isReadCoverage(dataSet.get(0))) { needUpdateForGraphicRefinement = true; // narrow down the prefetch range float prefetchFactor = geneCanvas.getPrefetchFactor(); prefetchFactor /= 2.0; geneCanvas.setPrefetchFactor(prefetchFactor); } else { float newPrefetchFactor = geneCanvas.getPrefetchFactor() * 2.0f; if (newPrefetchFactor > 1.0f) newPrefetchFactor = 1.0f; // broaden the prefetch range upon successful read data retrieval geneCanvas.setPrefetchFactor(newPrefetchFactor); needUpdateForGraphicRefinement = false; } geneCanvas.resetData(dataSet); refresh(); } }); }
public BarGraphCanvas(TrackWindow window, int windowHeight) { this.window = window; // Style.border(canvas, 1, "solid", "gray"); initWidget(canvas); setPixelSize(window.getPixelWidth(), windowHeight); }
public void draw(List<CompactWIGData> graphData, GraphStyle style) { for (CompactWIGData each : graphData) { if (each.getSpan() > span) { this.span = each.getSpan(); } } setPixelWidth(window.getPixelWidth(), style.windowHeight); scale.updateStyle(style); for (CompactWIGData data : graphData) { // get graph color Color graphColor = new Color(DEFAULT_COLOR); if (style.color.isDefined()) { graphColor = new Color(style.color.get()); } else if (data.getTrack().containsKey("color")) { String colorStr = data.getTrack().get("color"); String c[] = colorStr.split(","); if (c.length == 3) graphColor = new Color(Integer.valueOf(c[0]), Integer.valueOf(c[1]), Integer.valueOf(c[2])); } // draw graph canvas.saveContext(); canvas.setLineWidth(1.0f); canvas.setStrokeStyle(graphColor); min = scale.getMin(); max = scale.getMax(); float y2 = scale.getYPosition(0.0f); // draw data graph final boolean isReverse = window.isReverseStrand(); final int pixelWidth = data.getData().length; for (int i = 0; i < pixelWidth; ++i) { float value = data.getData()[i]; float y1; if (value == 0.0f) { if (!style.drawZeroValue) continue; else { y1 = y2 + ((min < max) ? -0.5f : 0.5f); } } else { y1 = scale.getYPosition(value); } int x = i; if (isReverse) { x = pixelWidth - x - 1; } canvas.saveContext(); canvas.beginPath(); canvas.translate(x + 0.5f, 0); canvas.moveTo(0, y1); canvas.lineTo(0, y2); canvas.stroke(); canvas.restoreContext(); } canvas.restoreContext(); } }