Example #1
0
  private void updatePointLists() {

    // find the number of points to draw
    int n;
    if (drawType == DrawType.STEP_GRAPH_CONTINUOUS || drawType == DrawType.STEP_GRAPH_JUMP) {
      n = 2 * algo.getIntervals() - 1;
    } else {
      n = algo.getIntervals();
    }

    // adjust the lists
    if (n > pts.size()) {
      // add
      for (int i = pts.size(); i < n; i++) {
        addPt();
      }
    } else if (n < pts.size()) {
      // remove
      // for (int i = n; n < pts.size(); i++) {
      // remove in reverse order!
      for (int i = pts.size() - 1; i >= n; i--) {
        pts.remove(i);
        drawPoints.remove(i);
      }
    }
  }
Example #2
0
  @Override
  public void update() {

    isVisible = geo.isEuclidianVisible();
    if (!isVisible) return;
    if (!geo.getDrawAlgorithm().equals(geo.getParentAlgorithm())) init();
    labelVisible = geo.isLabelVisible();
    updateStrokes(sum);

    // init gp
    gp = new GeneralPathClipped[algo.getIntervals()];
    for (int i = 0; i < gp.length; i++) {
      gp[i] = new GeneralPathClipped(view);
      gp[i].reset();
    }

    double[] xVal = algo.getLeftBorder();
    double[] yVal = algo.getValues();

    double width = algo.getWidth();
    int N = algo.getIntervals();

    if (algo.hasPoints()) {
      updatePointLists();
    }

    drawType = algo.getDrawType();
    pointType = algo.getPointType();
    int pointStyle;

    if (algo.hasPoints() && pointType != POINT_NONE) {

      if (pointType == POINT_LEFT || pointType == POINT_LEFT_OPEN_RIGHT) {
        pointStyle = EuclidianStyleConstants.POINT_STYLE_DOT;
      } else {
        pointStyle = EuclidianStyleConstants.POINT_STYLE_CIRCLE;
      }

      for (int i = 0; i < N; i++) {
        coords[0] = xVal[i];
        coords[1] = yVal[i];
        pts.get(i).setCoords(coords[0], coords[1], 1.0);
        pts.get(i).setObjColor(geo.getObjectColor());
        pts.get(i).setPointSize(2 + (geo.getLineThickness() + 1) / 3);
        pts.get(i).setPointStyle(pointStyle);
        if (pointType == POINT_RIGHT) {
          pts.get(i).setEuclidianVisible(false);
        }
        drawPoints.get(i).update();
      }

      if (drawType == DrawType.STEP_GRAPH_CONTINUOUS || drawType == DrawType.STEP_GRAPH_JUMP) {

        if (pointType == POINT_LEFT || pointType == POINT_LEFT_OPEN_RIGHT) {
          pointStyle = EuclidianStyleConstants.POINT_STYLE_CIRCLE;
        } else {
          pointStyle = EuclidianStyleConstants.POINT_STYLE_DOT;
        }

        // step graph right points
        for (int i = 0; i < N - 1; i++) {
          coords[0] = xVal[i + 1];
          coords[1] = yVal[i];
          pts.get(N + i).setCoords(coords[0], coords[1], 1.0);
          pts.get(N + i).setObjColor(geo.getObjectColor());
          pts.get(N + i).setPointSize(2 + (geo.getLineThickness() + 1) / 3);
          pts.get(N + i).setPointStyle(pointStyle);
          if (pointType == POINT_LEFT) {
            pts.get(N + i).setEuclidianVisible(false);
          }
          drawPoints.get(N + i).update();
        }
      }
    }

    double halfWidth = width / 2;

    switch (drawType) {
      case VERTICAL_BAR:
        if (width <= 0) {
          for (int i = 0; i < N; i++) {
            coords[0] = xVal[i];
            coords[1] = 0;
            view.toScreenCoords(coords);
            gp[i].moveTo(coords[0], coords[1]);

            coords[0] = xVal[i];
            coords[1] = yVal[i];
            view.toScreenCoords(coords);
            gp[i].lineTo(coords[0], coords[1]);
          }

        } else {
          for (int i = 0; i < N; i++) {
            coords[0] = xVal[i];
            coords[1] = 0;
            view.toScreenCoords(coords);
            gp[i].moveTo(coords[0], coords[1]);

            coords[0] = xVal[i];
            coords[1] = yVal[i];
            view.toScreenCoords(coords);
            gp[i].lineTo(coords[0], coords[1]);

            coords[0] = xVal[i] + width;
            coords[1] = yVal[i];
            view.toScreenCoords(coords);
            gp[i].lineTo(coords[0], coords[1]);

            coords[0] = xVal[i] + width;
            coords[1] = 0;
            view.toScreenCoords(coords);
            gp[i].lineTo(coords[0], coords[1]);

            coords[0] = xVal[i];
            coords[1] = 0;
            view.toScreenCoords(coords);
            gp[i].lineTo(coords[0], coords[1]);
          }
        }

        break;

      case HORIZONTAL_BAR:
        if (width <= 0) {
          for (int i = 0; i < N; i++) {
            coords[0] = 0;
            coords[1] = yVal[i];
            view.toScreenCoords(coords);
            gp[i].moveTo(coords[0], coords[1]);

            coords[0] = xVal[i];
            coords[1] = yVal[i];
            view.toScreenCoords(coords);
            gp[i].lineTo(coords[0], coords[1]);
          }

        } else {
          for (int i = 0; i < N; i++) {
            coords[0] = 0;
            coords[1] = yVal[i];
            view.toScreenCoords(coords);
            gp[i].moveTo(coords[0], coords[1]);

            coords[0] = xVal[i];
            coords[1] = yVal[i];
            view.toScreenCoords(coords);
            gp[i].lineTo(coords[0], coords[1]);

            coords[0] = xVal[i];
            coords[1] = yVal[i] + width;
            view.toScreenCoords(coords);
            gp[i].lineTo(coords[0], coords[1]);

            coords[0] = 0;
            coords[1] = yVal[i] + width;
            view.toScreenCoords(coords);
            gp[i].lineTo(coords[0], coords[1]);

            coords[0] = 0;
            coords[1] = yVal[i];
            view.toScreenCoords(coords);
            gp[i].lineTo(coords[0], coords[1]);
          }
        }
        break;

      case STEP_GRAPH_CONTINUOUS:
        for (int i = 0; i < N - 1; i++) {

          // move to start point
          coords[0] = xVal[i] + halfWidth;
          coords[1] = yVal[i];
          view.toScreenCoords(coords);
          gp[i].moveTo(coords[0], coords[1]);

          // across
          coords[0] = xVal[i + 1] + halfWidth;
          coords[1] = yVal[i];
          view.toScreenCoords(coords);
          gp[i].lineTo(coords[0], coords[1]);

          // up
          coords[0] = xVal[i + 1] + halfWidth;
          coords[1] = yVal[i + 1];
          view.toScreenCoords(coords);
          gp[i].lineTo(coords[0], coords[1]);
        }

        // up to last point
        coords[0] = xVal[N - 1] + halfWidth;
        coords[1] = yVal[N - 1];
        view.toScreenCoords(coords);
        gp[gp.length - 1].lineTo(coords[0], coords[1]);

        break;

      case STEP_GRAPH_JUMP:
        for (int i = 0; i < N - 1; i++) {

          // move to start point
          coords[0] = xVal[i] + halfWidth;
          coords[1] = yVal[i];
          view.toScreenCoords(coords);
          gp[i].moveTo(coords[0], coords[1]);

          // across
          coords[0] = xVal[i + 1] + halfWidth;
          coords[1] = yVal[i];
          view.toScreenCoords(coords);
          gp[i].lineTo(coords[0], coords[1]);
        }

        break;
    }

    // gp on screen?
    isVisible = false;
    // don't return here to make sure that getBounds() works for
    // off screen points too
    for (int i = 0; i < gp.length; i++) {
      if (gp[i].intersects(0, 0, view.getWidth(), view.getHeight())) {
        isVisible = true;
        break;
      }
    }
    // TODO: improve label position
    if (labelVisible) {
      xLabel = (int) coords[0];
      yLabel = (int) coords[1] - view.getFontSize();
      labelDesc = geo.getLabelDescription();
      addLabelOffset();
    }
  }