List of usage examples for com.google.gwt.widgetideas.graphics.client GWTCanvas moveTo
public void moveTo(double x, double y)
From source file:com.google.caliper.cloud.client.BoxPlot.java
License:Apache License
public Widget create(int style, double max, MeasurementSet measurementSet, boolean useNanos) { /*/*from w ww.j a v a2 s .c o m*/ * Compute the five displayed values of the box plot from the measurements. * * a = minimum * b = lower quartile * c = median * d = upper quartile * e = maximum */ List<Double> measurements = useNanos ? measurementSet.getMeasurementsRaw() : measurementSet.getMeasurementUnits(); Collections.sort(measurements); int numMeasurements = measurements.size(); double unitsPerPixel = max / maxWidth; int quartile = numMeasurements / 4; double a = measurements.get(0) / unitsPerPixel; double b = measurements.get(quartile) / unitsPerPixel; double c = measurements.get(numMeasurements / 2) / unitsPerPixel; double d = measurements.get(numMeasurements - (quartile > 0 ? quartile : 1)) / unitsPerPixel; double e = measurements.get(numMeasurements - 1) / unitsPerPixel; Color[] colors = Colors.forStyle(style); Color dark = colors[0]; Color medium = colors[1]; Color light = colors[2]; GWTCanvas canvas = new GWTCanvas(maxWidth, maxHeight); if (numMeasurements > 3) { canvas.setFillStyle(dark); canvas.fillRect(0, 0, b, maxHeight); canvas.setFillStyle(medium); canvas.fillRect(b, 0, (c - b), maxHeight); canvas.setFillStyle(light); canvas.fillRect(c, 0, (d - c), maxHeight); } else { canvas.setFillStyle(dark); canvas.fillRect(0, 0, c, maxHeight); } if (numMeasurements > 1) { int quarterHeight = maxHeight / 4; int halfHeight = maxHeight / 2; canvas.setStrokeStyle(light); canvas.setLineWidth(1); // the |-- of the |--[ | ]---| if ((int) (a - b) != 0) { canvas.beginPath(); canvas.moveTo(a, quarterHeight); canvas.lineTo(a, maxHeight - quarterHeight); canvas.stroke(); canvas.beginPath(); canvas.moveTo(a, halfHeight); canvas.lineTo(b, halfHeight); canvas.stroke(); } // the ---| of the |--[ | ]---| if ((int) (e - d) != 0) { canvas.setStrokeStyle(dark); canvas.beginPath(); canvas.moveTo(d, halfHeight); canvas.lineTo(e, halfHeight); canvas.stroke(); canvas.beginPath(); canvas.moveTo(e, quarterHeight); canvas.lineTo(e, maxHeight - quarterHeight); canvas.stroke(); } } return canvas; }
From source file:org.utgenome.gwt.utgb.client.canvas.GWTGraphCanvas.java
License:Apache License
protected void drawWigGraph(GraphCanvas graphCanvas) { for (CompactWIGData data : graphCanvas.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])); }/*w ww . j a va2 s.co m*/ // draw graph GWTCanvas canvas = graphCanvas.canvas; canvas.saveContext(); canvas.setLineWidth(1.0f); canvas.setStrokeStyle(graphColor); //canvas.scale(viewWindow.convertToPixelLength(graphCanvas.window.getSequenceLength()) / (double) data.getPixelSize(), 1.0f); float y2 = getYPosition(0.0f); // draw data graph final boolean isReverse = graphCanvas.window.isReverseStrand(); final int pixelWidth = data.getData().length; float min = style.autoScale ? autoScaledMinValue : style.minValue; float max = style.autoScale ? autoScaledMaxValue : style.maxValue; 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 = 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(); } }