Example #1
0
  public static Set<Bar> createGustGraph(
      SpotWindData spotDayData, int startX, int startY, int endX, int endY) {
    Set<Bar> path = new LinkedHashSet<Bar>();
    double xDiff = endX - startX;
    double yDiff = endY - startY;
    for (WindData windData : spotDayData.getWindDatas()) {
      double wind = windData.getWind();
      double gust = windData.getGust();
      if (wind > MAXWIND) wind = MAXWIND;
      if (gust > MAXWIND) gust = MAXWIND;
      double time2 = (double) windData.getEndHour() + (double) windData.getEndMinute() / 60;
      double time1 = (double) windData.getStartHour() + (double) windData.getStartMinute() / 60;
      double xProcent2 = time2 / 24;
      double yProcent2 = wind / MAXWIND;
      double yProcent1 = gust / MAXWIND;
      double xProcent1 = time1 / 24;
      double x1 = startX + xProcent1 * xDiff;
      double y1 = endY - yProcent1 * yDiff;
      double y2 = endY - yProcent2 * yDiff;
      double x2 = startX + xProcent2 * xDiff;
      if (x1 > x2) x1 = startX; // in case startTime was from the day before.

      Bar bar = new Bar();
      bar.setX1((int) x1);
      bar.setX2((int) x2);
      bar.setY1((int) y1);
      bar.setY2((int) y2);
      path.add(bar);
    }

    return path;
  }
Example #2
0
  private static void paintGraph(Canvas canvas, Set<Bar> windGraphPath, Set<Bar> gustGraphPath) {
    // paint wind
    Paint pathPaint = new Paint();
    pathPaint.setColor(Color.argb(50, 0, 100, 0));
    pathPaint.setStyle(Style.FILL);
    pathPaint.setStrokeWidth(1);
    for (Bar bar : windGraphPath) {
      canvas.drawRect(bar.getX1(), bar.getY1(), bar.getX2(), bar.getY2(), pathPaint);
    }

    // paint gust
    Paint pathGustPaint = new Paint();
    pathGustPaint.setColor(Color.argb(50, 100, 0, 0));
    pathGustPaint.setStyle(Style.FILL);
    pathGustPaint.setStrokeWidth(1);
    for (Bar bar : gustGraphPath) {
      canvas.drawRect(bar.getX1(), bar.getY1(), bar.getX2(), bar.getY2(), pathGustPaint);
    }
  }