Esempio n. 1
0
  private void enableShadows(double thickness, PlotMode mode) {
    if (mode == PlotMode.LINE) {
      canvas.setShadow("#666", (int) thickness, 0, (int) Math.ceil(thickness / 2.0));

    } else if (mode == PlotMode.BAR) {
      canvas.setShadow("#666", 2, 2, 2);
    }
  }
Esempio n. 2
0
  /**
   * Plots the line caps on the graph
   *
   * @param xCoordinates The x-coordinates of the caps
   * @param yCoordinates The y-coordinates of the caps
   */
  private void plotLineCaps(
      List<Float> xCoordinates, List<Float> yCoordinates, double lineThickness) {
    canvas.setStrokeStyle(canvas.getBackgroundColor());

    canvas.setFillStyle(color);
    canvas.beginPath();
    Float x, y;
    for (int i = 1; i < xCoordinates.size(); i++) {
      x = xCoordinates.get(i);
      y = yCoordinates.get(i);
      canvas.moveTo(x, y);
      canvas.arc(x, y, lineThickness, 0, 2 * Math.PI, false);
    }

    canvas.closePath();
    canvas.stroke();
    canvas.fill();
  }
Esempio n. 3
0
  /**
   * Plots a scatter graph
   *
   * @param xCoordinates The x-coordinates
   * @param yCoordinates THe y-coordinates
   */
  private void plotScatterGraph(List<Float> xCoordinates, List<Float> yCoordinates) {

    canvas.setStrokeStyle(color);
    canvas.setFillStyle(fillColor);
    canvas.beginPath();

    float x = xCoordinates.get(0);
    float y = yCoordinates.get(0);

    canvas.moveTo(x, y);
    canvas.strokeRect(x, y, 2, 2);
    canvas.moveTo(x, y);

    for (int i = 1; i < xCoordinates.size(); i++) {
      x = xCoordinates.get(i);
      y = yCoordinates.get(i);

      canvas.moveTo(x, y);
      canvas.strokeRect(x, y, 2, 2);
      canvas.moveTo(x, y);
    }

    canvas.moveTo(x, zero);

    x = xCoordinates.get(0);
    canvas.moveTo(x, zero);

    canvas.closePath();
    canvas.stroke();
    canvas.fill();
  }
Esempio n. 4
0
 private void disableShadows() {
   canvas.setShadow(null, 0, 0, 0);
 }
Esempio n. 5
0
  /**
   * Plots a line graph
   *
   * @param xCoordinates The x-coordinates
   * @param yCoordinates The y-coordinates
   */
  private void plotLineGraph(
      List<Float> xCoordinates, List<Float> yCoordinates, boolean lineCaps, double lineThickness) {

    canvas.setLineWidth(lineThickness);
    canvas.setLineJoin("round");

    // First draw the filling
    canvas.setStrokeStyle("rgba(0,0,0,255)");
    canvas.setFillStyle(fillColor);
    canvas.beginPath();

    float x = xCoordinates.get(0);
    float y = yCoordinates.get(0);

    canvas.moveTo(x, zero);
    canvas.lineTo(x, y);

    for (int i = 1; i < xCoordinates.size(); i++) {
      x = xCoordinates.get(i);
      y = yCoordinates.get(i);
      canvas.lineTo(x, y);
    }

    canvas.lineTo(x, zero);

    x = xCoordinates.get(0);
    canvas.moveTo(x, zero);

    canvas.closePath();
    canvas.fill();

    if (useShadows) {
      enableShadows(lineThickness, PlotMode.LINE);
    }

    // Then draw the outline
    if (lineCaps) {
      canvas.setLineJoin(Canvas.BEVEL);
    }

    canvas.setStrokeStyle(color);
    canvas.beginPath();

    x = xCoordinates.get(0);
    y = yCoordinates.get(0);

    canvas.moveTo(x, zero);
    canvas.moveTo(x, y);

    for (int i = 1; i < xCoordinates.size(); i++) {
      x = xCoordinates.get(i);
      y = yCoordinates.get(i);
      canvas.lineTo(x, y);
    }

    if (BrowserInfo.get().isIE8() || BrowserInfo.get().isChrome()) {
      /*
       * In IE we have to draw a line down to zero so the path can get
       * closed. If we don't then then there will be a line through the
       * whole graph due to the VML implementation. After we move we also
       * have to draw a 1px line, else IE will not draw anything when
       * stroke width > 1.5px. IE 9-> uses canvas implementation where
       * this problem does not exist
       *
       * Apparently Chrome 18-> joined the club :(
       */
      canvas.moveTo(xCoordinates.get(0), yCoordinates.get(0));
      canvas.lineTo(xCoordinates.get(0) + 1, yCoordinates.get(0));

    } else {
      canvas.moveTo(xCoordinates.get(0), zero);
    }

    canvas.closePath();
    canvas.stroke();

    // Finally, if we have any linecaps then draw them
    if (lineCaps) {
      plotLineCaps(xCoordinates, yCoordinates, lineThickness);
    }
  }
Esempio n. 6
0
 /**
  * Constructor
  *
  * @param canvas The canvas to plot on
  */
 public VCanvasPlotter(Canvas canvas) {
   this.canvas = canvas;
   zero = (float) canvas.getHeight();
 }