コード例 #1
0
  /**
   * Draws the item (first pass). This method draws the lines connecting the items.
   *
   * @param g2 the graphics device.
   * @param state the renderer state.
   * @param dataArea the area within which the data is being drawn.
   * @param plot the plot (can be used to obtain standard color information etc).
   * @param domainAxis the domain axis.
   * @param rangeAxis the range axis.
   * @param dataset the dataset.
   * @param pass the pass.
   * @param series the series index (zero-based).
   * @param item the item index (zero-based).
   */
  protected void drawPrimaryLine(
      XYItemRendererState state,
      Graphics2D g2,
      XYPlot plot,
      XYDataset dataset,
      int pass,
      int series,
      int item,
      ValueAxis domainAxis,
      ValueAxis rangeAxis,
      Rectangle2D dataArea) {
    if (item == 0) {
      return;
    }

    // get the data point...
    double x1 = dataset.getXValue(series, item);
    double y1 = dataset.getYValue(series, item);
    if (Double.isNaN(y1) || Double.isNaN(x1)) {
      return;
    }

    double x0 = dataset.getXValue(series, item - 1);
    double y0 = dataset.getYValue(series, item - 1);
    if (Double.isNaN(y0) || Double.isNaN(x0)) {
      return;
    }

    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();

    double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
    double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation);

    double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
    double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);

    // only draw if we have good values
    if (Double.isNaN(transX0)
        || Double.isNaN(transY0)
        || Double.isNaN(transX1)
        || Double.isNaN(transY1)) {
      return;
    }

    PlotOrientation orientation = plot.getOrientation();
    boolean visible;
    if (orientation == PlotOrientation.HORIZONTAL) {
      state.workingLine.setLine(transY0, transX0, transY1, transX1);
    } else if (orientation == PlotOrientation.VERTICAL) {
      state.workingLine.setLine(transX0, transY0, transX1, transY1);
    }
    visible = LineUtilities.clipLine(state.workingLine, dataArea);
    if (visible) {
      drawFirstPassShape(g2, pass, series, item, state.workingLine);
    }
  }
コード例 #2
0
  /**
   * Draws the item (first pass). This method draws the lines connecting the items. Instead of
   * drawing separate lines, a GeneralPath is constructed and drawn at the end of the series
   * painting.
   *
   * @param g2 the graphics device.
   * @param state the renderer state.
   * @param plot the plot (can be used to obtain standard color information etc).
   * @param dataset the dataset.
   * @param pass the pass.
   * @param series the series index (zero-based).
   * @param item the item index (zero-based).
   * @param domainAxis the domain axis.
   * @param rangeAxis the range axis.
   * @param dataArea the area within which the data is being drawn.
   */
  protected void drawPrimaryLineAsPath(
      XYItemRendererState state,
      Graphics2D g2,
      XYPlot plot,
      XYDataset dataset,
      int pass,
      int series,
      int item,
      ValueAxis domainAxis,
      ValueAxis rangeAxis,
      Rectangle2D dataArea) {

    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();

    // get the data point...
    double x1 = dataset.getXValue(series, item);
    double y1 = dataset.getYValue(series, item);
    double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
    double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);

    State s = (State) state;
    // update path to reflect latest point
    if (!Double.isNaN(transX1) && !Double.isNaN(transY1)) {
      float x = (float) transX1;
      float y = (float) transY1;
      PlotOrientation orientation = plot.getOrientation();
      if (orientation == PlotOrientation.HORIZONTAL) {
        x = (float) transY1;
        y = (float) transX1;
      }
      if (s.isLastPointGood()) {
        s.seriesPath.lineTo(x, y);
      } else {
        s.seriesPath.moveTo(x, y);
      }
      s.setLastPointGood(true);
    } else {
      s.setLastPointGood(false);
    }
    // if this is the last item, draw the path ...
    if (item == s.getLastItemIndex()) {
      // draw path
      drawFirstPassShape(g2, pass, series, item, s.seriesPath);
    }
  }