Java Code Examples for org.jfree.chart.plot.XYPlot#indexOf()

The following examples show how to use org.jfree.chart.plot.XYPlot#indexOf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XYBlockPixelSizeRenderer.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws the block representing the specified item.
 *
 * @param g2 the graphics device.
 * @param state the state.
 * @param dataArea the data area.
 * @param info the plot rendering info.
 * @param plot the plot.
 * @param domainAxis the x-axis.
 * @param rangeAxis the y-axis.
 * @param dataset the dataset.
 * @param series the series index.
 * @param item the item index.
 * @param crosshairState the crosshair state.
 * @param pass the pass index.
 */
@Override
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea,
    PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis,
    XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) {

  double x = dataset.getXValue(series, item);
  double y = dataset.getYValue(series, item);
  double z = 0.0;
  if (dataset instanceof XYZDataset) {
    z = ((XYZDataset) dataset).getZValue(series, item);
  }

  Paint p = this.paintScale.getPaint(z);
  double xx0 = domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge());
  double yy0 = rangeAxis.valueToJava2D(y, dataArea, plot.getRangeAxisEdge());
  double xx1 = domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge());
  double yy1 = rangeAxis.valueToJava2D(y, dataArea, plot.getRangeAxisEdge());
  Rectangle2D block;
  PlotOrientation orientation = plot.getOrientation();
  if (orientation.equals(PlotOrientation.HORIZONTAL)) {
    block = new Rectangle2D.Double(Math.min(yy0, yy1), Math.min(xx0, xx1), blockWidthPixel,
        blockHeightPixel);
  } else {
    block = new Rectangle2D.Double(Math.min(xx0, xx1), Math.min(yy0, yy1), blockWidthPixel,
        blockHeightPixel);
  }
  g2.setPaint(p);
  g2.fill(block);
  g2.setStroke(new BasicStroke(1.0f));
  g2.draw(block);

  if (isItemLabelVisible(series, item)) {
    drawItemLabel(g2, orientation, dataset, series, item, block.getCenterX(), block.getCenterY(),
        y < 0.0);
  }

  int datasetIndex = plot.indexOf(dataset);
  double transX = domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge());
  double transY = rangeAxis.valueToJava2D(y, dataArea, plot.getRangeAxisEdge());
  updateCrosshairValues(crosshairState, x, y, datasetIndex, transX, transY, orientation);

  EntityCollection entities = state.getEntityCollection();
  if (entities != null) {
    addEntity(entities, block, dataset, series, item, block.getCenterX(), block.getCenterY());
  }

}
 
Example 2
Source File: XYBlockPixelSizeRenderer.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws the block representing the specified item.
 *
 * @param g2 the graphics device.
 * @param state the state.
 * @param dataArea the data area.
 * @param info the plot rendering info.
 * @param plot the plot.
 * @param domainAxis the x-axis.
 * @param rangeAxis the y-axis.
 * @param dataset the dataset.
 * @param series the series index.
 * @param item the item index.
 * @param crosshairState the crosshair state.
 * @param pass the pass index.
 */
@Override
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea,
    PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis,
    XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) {

  double x = dataset.getXValue(series, item);
  double y = dataset.getYValue(series, item);
  double z = 0.0;
  if (dataset instanceof XYZDataset) {
    z = ((XYZDataset) dataset).getZValue(series, item);
  }

  Paint p = this.paintScale.getPaint(z);
  double xx0 = domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge());
  double yy0 = rangeAxis.valueToJava2D(y, dataArea, plot.getRangeAxisEdge());
  double xx1 = domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge());
  double yy1 = rangeAxis.valueToJava2D(y, dataArea, plot.getRangeAxisEdge());
  Rectangle2D block;
  PlotOrientation orientation = plot.getOrientation();
  if (orientation.equals(PlotOrientation.HORIZONTAL)) {
    block = new Rectangle2D.Double(Math.min(yy0, yy1), Math.min(xx0, xx1), blockWidthPixel,
        blockHeightPixel);
  } else {
    block = new Rectangle2D.Double(Math.min(xx0, xx1), Math.min(yy0, yy1), blockWidthPixel,
        blockHeightPixel);
  }
  g2.setPaint(p);
  g2.fill(block);
  g2.setStroke(new BasicStroke(1.0f));
  g2.draw(block);

  if (isItemLabelVisible(series, item)) {
    drawItemLabel(g2, orientation, dataset, series, item, block.getCenterX(), block.getCenterY(),
        y < 0.0);
  }

  int datasetIndex = plot.indexOf(dataset);
  double transX = domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge());
  double transY = rangeAxis.valueToJava2D(y, dataArea, plot.getRangeAxisEdge());
  updateCrosshairValues(crosshairState, x, y, datasetIndex, transX, transY, orientation);

  EntityCollection entities = state.getEntityCollection();
  if (entities != null) {
    addEntity(entities, block, dataset, series, item, block.getCenterX(), block.getCenterY());
  }

}