Java Code Examples for org.jfree.data.xy.XYDataset#getYValue()

The following examples show how to use org.jfree.data.xy.XYDataset#getYValue() . 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: AbstractXYItemLabelGenerator.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the array of items that can be passed to the 
 * {@link MessageFormat} class for creating labels.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param series  the series (zero-based index).
 * @param item  the item (zero-based index).
 *
 * @return An array of three items from the dataset formatted as
 *         <code>String</code> objects (never <code>null</code>).
 */
protected Object[] createItemArray(XYDataset dataset, int series, 
                                   int item) {
    Object[] result = new Object[3];
    result[0] = dataset.getSeriesKey(series).toString();
    
    double x = dataset.getXValue(series, item);
    if (Double.isNaN(x) && dataset.getX(series, item) == null) {
        result[1] = this.nullXString;
    }
    else {
        if (this.xDateFormat != null) {
            result[1] = this.xDateFormat.format(new Date((long) x));   
        }
        else {
            result[1] = this.xFormat.format(x);
        }
    }
    
    double y = dataset.getYValue(series, item);
    if (Double.isNaN(y) && dataset.getY(series, item) == null) {
        result[2] = this.nullYString;
    }
    else {
        if (this.yDateFormat != null) {
            result[2] = this.yDateFormat.format(new Date((long) y));   
        }
        else {
            result[2] = this.yFormat.format(y);
        }
    }
    return result;
}
 
Example 2
Source File: XYItemLabelGenerator.java    From openbd-core with GNU General Public License v3.0 5 votes vote down vote up
protected Object[] createItemArray(XYDataset dataset, int series, int item) {
	Object[] result = new Object[5];
	result[0] = dataset.getSeriesKey(series).toString();
	
	double x = dataset.getXValue(series, item);
	if (Double.isNaN(x) && dataset.getX(series, item) == null) {
		result[1] = "null";	//this.nullXString;
	}
	else {
		if (this.getXDateFormat() != null) {
			result[1] = this.getXDateFormat().format(new Date((long) x));   
		}
		else {
			result[1] = this.getXFormat().format(x);
		}
	}
	
	double y = dataset.getYValue(series, item);
	if (Double.isNaN(y) && dataset.getY(series, item) == null) {
		result[2] = "null";	//this.nullYString;
	}
	else {
		if (this.getYDateFormat() != null) {
			result[2] = this.getYDateFormat().format(new Date((long) y));   
		}
		else {
			result[2] = this.getYFormat().format(y);
		}
		double total = calculateYTotal(dataset, series);
		double percent = y / total;
		result[3] = NumberFormat.getPercentInstance().format(percent);
		if (this.getYFormat() != null) {
			result[4] = this.getYFormat().format(total);
		}
		else if (this.getYDateFormat() != null) {
			//result[4] = this.getDateFormat().format(total);
		}
	}
	return result;
}
 
Example 3
Source File: Cardumen_0082_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Selects the data items within the specified region.
 *
 * @param region  the region (in Java2D coordinates).
 * @param dataArea  the data area.
 * @param source  the rendering source.
 *
 * @since 1.2.0
 */
public void select(GeneralPath region, Rectangle2D dataArea,
        RenderingSource source) {
    // cycle through the datasets and change the selection state for the
    // items that fall within the specified region
    int datasetCount = this.datasets.size();
    for (int d = 0; d < datasetCount; d++) {
        XYDataset dataset = (XYDataset) this.datasets.get(d);
        if (dataset == null) {
            continue;
        }
        XYDatasetSelectionState state = findSelectionStateForDataset(
                dataset, source);
        if (state == null) {
            continue;
        }
        GeneralPath path = convertToDataSpace(region, dataArea, dataset);
        // now we have to iterate over all the dataset values and
        // convert each point to Java2D space and then check if it should
        // be selected.
        int seriesCount = dataset.getSeriesCount();
        for (int s = 0; s < seriesCount; s++) {
            int itemCount = dataset.getItemCount(s);
            for (int i = 0; i < itemCount; i++) {
                double x = dataset.getXValue(s, i);
                double y = dataset.getYValue(s, i);
                if (path.contains(x, y)) {
                    state.setSelected(s, i, true);
                    // FIXME:  we should fire just one dataset change event
                    // for the whole selection
                }
            }
        }
    }
}
 
Example 4
Source File: AbstractXYItemLabelGenerator.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates the array of items that can be passed to the
 * {@link MessageFormat} class for creating labels.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param series  the series (zero-based index).
 * @param item  the item (zero-based index).
 *
 * @return An array of three items from the dataset formatted as
 *         <code>String</code> objects (never <code>null</code>).
 */
protected Object[] createItemArray(XYDataset dataset, int series,
                                   int item) {
    Object[] result = new Object[3];
    result[0] = dataset.getSeriesKey(series).toString();

    double x = dataset.getXValue(series, item);
    if (this.xDateFormat != null) {
        result[1] = this.xDateFormat.format(new Date((long) x));
    }
    else {
        result[1] = this.xFormat.format(x);
    }

    double y = dataset.getYValue(series, item);
    if (Double.isNaN(y) && dataset.getY(series, item) == null) {
        result[2] = this.nullYString;
    }
    else {
        if (this.yDateFormat != null) {
            result[2] = this.yDateFormat.format(new Date((long) y));
        }
        else {
            result[2] = this.yFormat.format(y);
        }
    }
    return result;
}
 
Example 5
Source File: SymbolicXYItemLabelGenerator.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Generates a tool tip text item for a particular item within a series.
 *
 * @param data  the dataset.
 * @param series  the series number (zero-based index).
 * @param item  the item number (zero-based index).
 *
 * @return The tool tip text (possibly <code>null</code>).
 */
@Override
public String generateToolTip(XYDataset data, int series, int item) {

    String xStr, yStr;
    if (data instanceof YisSymbolic) {
        yStr = ((YisSymbolic) data).getYSymbolicValue(series, item);
    }
    else {
        double y = data.getYValue(series, item);
        yStr = Double.toString(round(y, 2));
    }
    if (data instanceof XisSymbolic) {
        xStr = ((XisSymbolic) data).getXSymbolicValue(series, item);
    }
    else if (data instanceof TimeSeriesCollection) {
        RegularTimePeriod p
            = ((TimeSeriesCollection) data).getSeries(series)
                .getTimePeriod(item);
        xStr = p.toString();
    }
    else {
        double x = data.getXValue(series, item);
        xStr = Double.toString(round(x, 2));
    }
    return "X: " + xStr + ", Y: " + yStr;
}
 
Example 6
Source File: XYPlotToolTipGenerator.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String generateToolTip(XYDataset data, int series, int item) {
    final Comparable key = data.getSeriesKey(series);
    final double valueX = data.getXValue(series, item);
    final double valueY = data.getYValue(series, item);
    return String.format("%s: X = %6.2f, Y = %6.2f", key, valueX, valueY);
}
 
Example 7
Source File: VectorRenderer.java    From buffer_bci with GNU General Public License v3.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 dx = 0.0;
    double dy = 0.0;
    if (dataset instanceof VectorXYDataset) {
        dx = ((VectorXYDataset) dataset).getVectorXValue(series, item);
        dy = ((VectorXYDataset) dataset).getVectorYValue(series, item);
    }
    double xx0 = domainAxis.valueToJava2D(x, dataArea,
            plot.getDomainAxisEdge());
    double yy0 = rangeAxis.valueToJava2D(y, dataArea,
            plot.getRangeAxisEdge());
    double xx1 = domainAxis.valueToJava2D(x + dx, dataArea,
            plot.getDomainAxisEdge());
    double yy1 = rangeAxis.valueToJava2D(y + dy, dataArea,
            plot.getRangeAxisEdge());
    Line2D line;
    PlotOrientation orientation = plot.getOrientation();
    if (orientation.equals(PlotOrientation.HORIZONTAL)) {
        line = new Line2D.Double(yy0, xx0, yy1, xx1);
    }
    else {
        line = new Line2D.Double(xx0, yy0, xx1, yy1);
    }
    g2.setPaint(getItemPaint(series, item));
    g2.setStroke(getItemStroke(series, item));
    g2.draw(line);

    // calculate the arrow head and draw it...
    double dxx = (xx1 - xx0);
    double dyy = (yy1 - yy0);
    double bx = xx0 + (1.0 - this.baseLength) * dxx;
    double by = yy0 + (1.0 - this.baseLength) * dyy;

    double cx = xx0 + (1.0 - this.headLength) * dxx;
    double cy = yy0 + (1.0 - this.headLength) * dyy;

    double angle = 0.0;
    if (dxx != 0.0) {
        angle = Math.PI / 2.0 - Math.atan(dyy / dxx);
    }
    double deltaX = 2.0 * Math.cos(angle);
    double deltaY = 2.0 * Math.sin(angle);

    double leftx = cx + deltaX;
    double lefty = cy - deltaY;
    double rightx = cx - deltaX;
    double righty = cy + deltaY;

    GeneralPath p = new GeneralPath();
    if (orientation == PlotOrientation.VERTICAL) {
        p.moveTo((float) xx1, (float) yy1);
        p.lineTo((float) rightx, (float) righty);
        p.lineTo((float) bx, (float) by);
        p.lineTo((float) leftx, (float) lefty);
    }
    else {  // orientation is HORIZONTAL
        p.moveTo((float) yy1, (float) xx1);
        p.lineTo((float) righty, (float) rightx);
        p.lineTo((float) by, (float) bx);
        p.lineTo((float) lefty, (float) leftx);
    }
    p.closePath();
    g2.draw(p);

    // setup for collecting optional entity info...
    EntityCollection entities;
    if (info != null) {
        entities = info.getOwner().getEntityCollection();
        if (entities != null) {
            addEntity(entities, line.getBounds(), dataset, series, item,
                    0.0, 0.0);
        }
    }

}
 
Example 8
Source File: SpectraDatabaseSearchLabelGenerator.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public String generateLabel(XYDataset dataset, int series, int item) {

  // X and Y values of current data point
  double originalX = dataset.getX(series, item).doubleValue();
  double originalY = dataset.getY(series, item).doubleValue();

  // Calculate data size of 1 screen pixel
  double xLength = plot.getXYPlot().getDomainAxis().getRange().getLength();
  double pixelX = xLength / plot.getWidth();

  // Size of data set
  int itemCount = dataset.getItemCount(series);

  // Search for data points higher than this one in the interval
  // from limitLeft to limitRight
  double limitLeft = originalX - ((POINTS_RESERVE_X / 2) * pixelX);
  double limitRight = originalX + ((POINTS_RESERVE_X / 2) * pixelX);

  // Iterate data points to the left and right
  for (int i = 1; (item - i > 0) || (item + i < itemCount); i++) {

    // If we get out of the limit we can stop searching
    if ((item - i > 0) && (dataset.getXValue(series, item - i) < limitLeft)
        && ((item + i >= itemCount) || (dataset.getXValue(series, item + i) > limitRight)))
      break;

    if ((item + i < itemCount) && (dataset.getXValue(series, item + i) > limitRight)
        && ((item - i <= 0) || (dataset.getXValue(series, item - i) < limitLeft)))
      break;

    // If we find higher data point, bail out
    if ((item - i > 0) && (originalY <= dataset.getYValue(series, item - i)))
      return null;

    if ((item + i < itemCount) && (originalY <= dataset.getYValue(series, item + i)))
      return null;

  }

  // Create label
  String label = null;
  if (dataset.getSeriesKey(1).equals("Detected compounds")) {
    if (item < annotations.length)
      label = annotations[item];
  }
  return label;
}
 
Example 9
Source File: DatasetUtilities.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the maximum range value for the specified dataset.  This is
 * easy if the dataset implements the {@link RangeInfo} interface (a good
 * idea if there is an efficient way to determine the maximum value).
 * Otherwise, it involves iterating over the entire data-set.  Returns
 * <code>null</code> if all the data values are <code>null</code>.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 *
 * @return The maximum value (possibly <code>null</code>).
 */
public static Number findMaximumRangeValue(XYDataset dataset) {

    if (dataset == null) {
        throw new IllegalArgumentException("Null 'dataset' argument.");
    }

    // work out the minimum value...
    if (dataset instanceof RangeInfo) {
        RangeInfo info = (RangeInfo) dataset;
        return new Double(info.getRangeUpperBound(true));
    }

    // hasn't implemented RangeInfo, so we'll have to iterate...
    else  {

        double maximum = Double.NEGATIVE_INFINITY;
        int seriesCount = dataset.getSeriesCount();
        for (int series = 0; series < seriesCount; series++) {
            int itemCount = dataset.getItemCount(series);
            for (int item = 0; item < itemCount; item++) {
                double value;
                if (dataset instanceof IntervalXYDataset) {
                    IntervalXYDataset intervalXYData
                        = (IntervalXYDataset) dataset;
                    value = intervalXYData.getEndYValue(series, item);
                }
                else if (dataset instanceof OHLCDataset) {
                    OHLCDataset highLowData = (OHLCDataset) dataset;
                    value = highLowData.getHighValue(series, item);
                }
                else {
                    value = dataset.getYValue(series, item);
                }
                if (!Double.isNaN(value)) {
                    maximum = Math.max(maximum, value);
                }
            }
        }
        if (maximum == Double.NEGATIVE_INFINITY) {
            return null;
        }
        else {
            return new Double(maximum);
        }

    }

}
 
Example 10
Source File: XYShapeRenderer.java    From ccu-historian with GNU General Public License v3.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) {

    Shape hotspot;
    EntityCollection entities = null;
    if (info != null) {
        entities = info.getOwner().getEntityCollection();
    }

    double x = dataset.getXValue(series, item);
    double y = dataset.getYValue(series, item);
    if (Double.isNaN(x) || Double.isNaN(y)) {
        // can't draw anything
        return;
    }

    double transX = domainAxis.valueToJava2D(x, dataArea,
            plot.getDomainAxisEdge());
    double transY = rangeAxis.valueToJava2D(y, dataArea,
            plot.getRangeAxisEdge());

    PlotOrientation orientation = plot.getOrientation();

    // draw optional guide lines
    if ((pass == 0) && this.guideLinesVisible) {
        g2.setStroke(this.guideLineStroke);
        g2.setPaint(this.guideLinePaint);
        if (orientation == PlotOrientation.HORIZONTAL) {
            g2.draw(new Line2D.Double(transY, dataArea.getMinY(), transY,
                    dataArea.getMaxY()));
            g2.draw(new Line2D.Double(dataArea.getMinX(), transX,
                    dataArea.getMaxX(), transX));
        }
        else {
            g2.draw(new Line2D.Double(transX, dataArea.getMinY(), transX,
                    dataArea.getMaxY()));
            g2.draw(new Line2D.Double(dataArea.getMinX(), transY,
                    dataArea.getMaxX(), transY));
        }
    }
    else if (pass == 1) {
        Shape shape = getItemShape(series, item);
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transY,
                    transX);
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transX,
                    transY);
        }
        hotspot = shape;
        if (shape.intersects(dataArea)) {
            //if (getItemShapeFilled(series, item)) {
                g2.setPaint(getPaint(dataset, series, item));
                g2.fill(shape);
           //}
            if (this.drawOutlines) {
                if (getUseOutlinePaint()) {
                    g2.setPaint(getItemOutlinePaint(series, item));
                }
                else {
                    g2.setPaint(getItemPaint(series, item));
                }
                g2.setStroke(getItemOutlineStroke(series, item));
                g2.draw(shape);
            }
        }

        // add an entity for the item...
        if (entities != null) {
            addEntity(entities, hotspot, dataset, series, item, transX,
                    transY);
        }
    }
}
 
Example 11
Source File: Chart_2_DatasetUtilities_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Returns the minimum range value for the specified dataset.  This is
 * easy if the dataset implements the {@link RangeInfo} interface (a good
 * idea if there is an efficient way to determine the minimum value).
 * Otherwise, it involves iterating over the entire data-set.  Returns
 * <code>null</code> if all the data values in the dataset are
 * <code>null</code>.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 *
 * @return The minimum value (possibly <code>null</code>).
 */
public static Number findMinimumRangeValue(XYDataset dataset) {

    if (dataset == null) {
        throw new IllegalArgumentException("Null 'dataset' argument.");
    }

    // work out the minimum value...
    if (dataset instanceof RangeInfo) {
        RangeInfo info = (RangeInfo) dataset;
        return new Double(info.getRangeLowerBound(true));
    }

    // hasn't implemented RangeInfo, so we'll have to iterate...
    else {
        double minimum = Double.POSITIVE_INFINITY;
        int seriesCount = dataset.getSeriesCount();
        for (int series = 0; series < seriesCount; series++) {
            int itemCount = dataset.getItemCount(series);
            for (int item = 0; item < itemCount; item++) {

                double value;
                if (dataset instanceof IntervalXYDataset) {
                    IntervalXYDataset intervalXYData
                            = (IntervalXYDataset) dataset;
                    value = intervalXYData.getStartYValue(series, item);
                }
                else if (dataset instanceof OHLCDataset) {
                    OHLCDataset highLowData = (OHLCDataset) dataset;
                    value = highLowData.getLowValue(series, item);
                }
                else {
                    value = dataset.getYValue(series, item);
                }
                if (!Double.isNaN(value)) {
                    minimum = Math.min(minimum, value);
                }

            }
        }
        if (minimum == Double.POSITIVE_INFINITY) {
            return null;
        }
        else {
            return new Double(minimum);
        }

    }

}
 
Example 12
Source File: JGenProg2017_0047_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Returns the minimum range value for the specified dataset.  This is 
 * easy if the dataset implements the {@link RangeInfo} interface (a good
 * idea if there is an efficient way to determine the minimum value).  
 * Otherwise, it involves iterating over the entire data-set.  Returns 
 * <code>null</code> if all the data values in the dataset are 
 * <code>null</code>.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 *
 * @return The minimum value (possibly <code>null</code>).
 */
public static Number findMinimumRangeValue(XYDataset dataset) {

    if (dataset == null) {
        throw new IllegalArgumentException("Null 'dataset' argument.");
    }

    // work out the minimum value...
    if (dataset instanceof RangeInfo) {
        RangeInfo info = (RangeInfo) dataset;
        return new Double(info.getRangeLowerBound(true));
    }

    // hasn't implemented RangeInfo, so we'll have to iterate...
    else {
        double minimum = Double.POSITIVE_INFINITY;
        int seriesCount = dataset.getSeriesCount();
        for (int series = 0; series < seriesCount; series++) {
            int itemCount = dataset.getItemCount(series);
            for (int item = 0; item < itemCount; item++) {

                double value;
                if (dataset instanceof IntervalXYDataset) {
                    IntervalXYDataset intervalXYData 
                        = (IntervalXYDataset) dataset;
                    value = intervalXYData.getStartYValue(series, item);
                }
                else if (dataset instanceof OHLCDataset) {
                    OHLCDataset highLowData = (OHLCDataset) dataset;
                    value = highLowData.getLowValue(series, item);
                }
                else {
                    value = dataset.getYValue(series, item);
                }
                if (!Double.isNaN(value)) {
                    minimum = Math.min(minimum, value);
                }

            }
        }
        if (minimum == Double.POSITIVE_INFINITY) {
            return null;
        }
        else {
            return new Double(minimum);
        }

    }

}
 
Example 13
Source File: XYBlockRenderer.java    From buffer_bci with GNU General Public License v3.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 + this.xOffset, dataArea,
            plot.getDomainAxisEdge());
    double yy0 = rangeAxis.valueToJava2D(y + this.yOffset, dataArea,
            plot.getRangeAxisEdge());
    double xx1 = domainAxis.valueToJava2D(x + this.blockWidth
            + this.xOffset, dataArea, plot.getDomainAxisEdge());
    double yy1 = rangeAxis.valueToJava2D(y + this.blockHeight
            + this.yOffset, 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), Math.abs(yy1 - yy0),
                Math.abs(xx0 - xx1));
    }
    else {
        block = new Rectangle2D.Double(Math.min(xx0, xx1),
                Math.min(yy0, yy1), Math.abs(xx1 - xx0),
                Math.abs(yy1 - yy0));
    }
    g2.setPaint(p);
    g2.fill(block);
    g2.setStroke(new BasicStroke(1.0f));
    g2.draw(block);

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

}
 
Example 14
Source File: XYLineAndShapeRenderer.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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);
    }
}
 
Example 15
Source File: IntelligentItemLabelGenerator.java    From old-mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @see org.jfree.chart.labels.XYItemLabelGenerator#generateLabel(org.jfree.data.xy.XYDataset,
 *      int, int)
 */
public String generateLabel(XYDataset currentDataset, int currentSeries, int currentItem) {

  XYPlot plot = chartNode.getChart().getXYPlot();

  // X and Y values of the current data point
  final double currentXValue = currentDataset.getXValue(currentSeries, currentItem);
  final double currentYValue = currentDataset.getYValue(currentSeries, currentItem);

  // Calculate X axis span of 1 screen pixel
  final double xLength = plot.getDomainAxis().getRange().getLength();
  final double pixelX = xLength / chartNode.getWidth();

  // Calculate the distance from the current point where labels might
  // overlap
  final double dangerZoneX = (reservedPixels / 2) * pixelX;

  // Range on X axis that we're going to check for higher data points. If
  // a higher data point is found, we don't place a label on this one.
  final Range<Double> dangerZoneRange =
      Range.closed(currentXValue - dangerZoneX, currentXValue + dangerZoneX);

  // Iterate through data sets
  for (int datasetIndex = 0; datasetIndex < plot.getDatasetCount(); datasetIndex++) {

    XYDataset dataset = plot.getDataset(datasetIndex);

    // Some data sets could have been removed
    if (dataset == null)
      continue;

    final int seriesCount = dataset.getSeriesCount();

    // Iterate through series
    for (int seriesIndex = 0; seriesIndex < seriesCount; seriesIndex++) {

      final int itemCount = dataset.getItemCount(seriesIndex);

      // Find the index of a data point that is closest to
      // currentXValue
      int closestValueIndex;
      if (dataset == currentDataset && seriesIndex == currentSeries) {
        closestValueIndex = currentItem;
      } else {
        closestValueIndex =
            findClosestXIndex(dataset, seriesIndex, currentXValue, 0, itemCount - 1);
      }

      // Search to the left of the closest data point
      for (int i = closestValueIndex; (i >= 0)
          && (dangerZoneRange.contains(dataset.getX(seriesIndex, i).doubleValue())); i--) {
        if (dataset.getYValue(seriesIndex, i) > currentYValue)
          return null;

        // In the case there are equal values, only place the label
        // on the leftmost value
        if (dataset.getYValue(seriesIndex, i) == currentYValue
            && (dataset.getXValue(seriesIndex, i) < currentXValue))
          return null;

      }

      // Search to the right of the closest data point
      for (int i = closestValueIndex + 1; (i < itemCount)
          && (dangerZoneRange.contains(dataset.getX(seriesIndex, i).doubleValue())); i++) {
        if (dataset.getYValue(seriesIndex, i) > currentYValue)
          return null;
      }

    }

  }

  // If no higher data point was found, create the label
  String label = underlyingGenerator.generateLabel(currentDataset, currentSeries, currentItem);

  return label;

}
 
Example 16
Source File: XYBlockRenderer.java    From buffer_bci with GNU General Public License v3.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 + this.xOffset, dataArea,
            plot.getDomainAxisEdge());
    double yy0 = rangeAxis.valueToJava2D(y + this.yOffset, dataArea,
            plot.getRangeAxisEdge());
    double xx1 = domainAxis.valueToJava2D(x + this.blockWidth
            + this.xOffset, dataArea, plot.getDomainAxisEdge());
    double yy1 = rangeAxis.valueToJava2D(y + this.blockHeight
            + this.yOffset, 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), Math.abs(yy1 - yy0),
                Math.abs(xx0 - xx1));
    }
    else {
        block = new Rectangle2D.Double(Math.min(xx0, xx1),
                Math.min(yy0, yy1), Math.abs(xx1 - xx0),
                Math.abs(yy1 - yy0));
    }
    g2.setPaint(p);
    g2.fill(block);
    g2.setStroke(new BasicStroke(1.0f));
    g2.draw(block);

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

}
 
Example 17
Source File: Chart_2_DatasetUtilities_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Returns the maximum range value for the specified dataset.  This is
 * easy if the dataset implements the {@link RangeInfo} interface (a good
 * idea if there is an efficient way to determine the maximum value).
 * Otherwise, it involves iterating over the entire data-set.  Returns
 * <code>null</code> if all the data values are <code>null</code>.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 *
 * @return The maximum value (possibly <code>null</code>).
 */
public static Number findMaximumRangeValue(XYDataset dataset) {

    if (dataset == null) {
        throw new IllegalArgumentException("Null 'dataset' argument.");
    }

    // work out the minimum value...
    if (dataset instanceof RangeInfo) {
        RangeInfo info = (RangeInfo) dataset;
        return new Double(info.getRangeUpperBound(true));
    }

    // hasn't implemented RangeInfo, so we'll have to iterate...
    else  {

        double maximum = Double.NEGATIVE_INFINITY;
        int seriesCount = dataset.getSeriesCount();
        for (int series = 0; series < seriesCount; series++) {
            int itemCount = dataset.getItemCount(series);
            for (int item = 0; item < itemCount; item++) {
                double value;
                if (dataset instanceof IntervalXYDataset) {
                    IntervalXYDataset intervalXYData
                        = (IntervalXYDataset) dataset;
                    value = intervalXYData.getEndYValue(series, item);
                }
                else if (dataset instanceof OHLCDataset) {
                    OHLCDataset highLowData = (OHLCDataset) dataset;
                    value = highLowData.getHighValue(series, item);
                }
                else {
                    value = dataset.getYValue(series, item);
                }
                if (!Double.isNaN(value)) {
                    maximum = Math.max(maximum, value);
                }
            }
        }
        if (maximum == Double.NEGATIVE_INFINITY) {
            return null;
        }
        else {
            return new Double(maximum);
        }

    }

}
 
Example 18
Source File: XYLineAndShapeRenderer.java    From ECG-Viewer with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws the item shapes and adds chart entities (second pass). This method
 * draws the shapes which mark the item positions. If <code>entities</code>
 * is not <code>null</code> it will be populated with entity information
 * for points that fall within the data area.
 *
 * @param g2  the graphics device.
 * @param plot  the plot (can be used to obtain standard color
 *              information etc).
 * @param domainAxis  the domain axis.
 * @param dataArea  the area within which the data is being drawn.
 * @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).
 * @param crosshairState  the crosshair state.
 * @param entities the entity collection.
 */
protected void drawSecondaryPass(Graphics2D g2, XYPlot plot, 
        XYDataset dataset, int pass, int series, int item,
        ValueAxis domainAxis, Rectangle2D dataArea, ValueAxis rangeAxis,
        CrosshairState crosshairState, EntityCollection entities) {

    Shape entityArea = null;

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

    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
    double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);

    if (getItemShapeVisible(series, item)) {
        Shape shape = getItemShape(series, item);
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transY1,
                    transX1);
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transX1,
                    transY1);
        }
        entityArea = shape;
        if (shape.intersects(dataArea)) {
            if (getItemShapeFilled(series, item)) {
                if (this.useFillPaint) {
                    g2.setPaint(getItemFillPaint(series, item));
                }
                else {
                    g2.setPaint(getItemPaint(series, item));
                }
                g2.fill(shape);
            }
            if (this.drawOutlines) {
                if (getUseOutlinePaint()) {
                    g2.setPaint(getItemOutlinePaint(series, item));
                }
                else {
                    g2.setPaint(getItemPaint(series, item));
                }
                g2.setStroke(getItemOutlineStroke(series, item));
                g2.draw(shape);
            }
        }
    }

    double xx = transX1;
    double yy = transY1;
    if (orientation == PlotOrientation.HORIZONTAL) {
        xx = transY1;
        yy = transX1;
    }

    // draw the item label if there is one...
    if (isItemLabelVisible(series, item)) {
        drawItemLabel(g2, orientation, dataset, series, item, xx, yy,
                (y1 < 0.0));
    }

    int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
    int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
    updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex,
            rangeAxisIndex, transX1, transY1, orientation);

    // add an entity for the item, but only if it falls within the data
    // area...
    if (entities != null && isPointInRect(dataArea, xx, yy)) {
        addEntity(entities, entityArea, dataset, series, item, xx, yy);
    }
}
 
Example 19
Source File: DatasetUtilities.java    From ECG-Viewer with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the maximum range value for the specified dataset.  This is
 * easy if the dataset implements the {@link RangeInfo} interface (a good
 * idea if there is an efficient way to determine the maximum value).
 * Otherwise, it involves iterating over the entire data-set.  Returns
 * <code>null</code> if all the data values are <code>null</code>.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 *
 * @return The maximum value (possibly <code>null</code>).
 */
public static Number findMaximumRangeValue(XYDataset dataset) {

    ParamChecks.nullNotPermitted(dataset, "dataset");

    // work out the minimum value...
    if (dataset instanceof RangeInfo) {
        RangeInfo info = (RangeInfo) dataset;
        return new Double(info.getRangeUpperBound(true));
    }

    // hasn't implemented RangeInfo, so we'll have to iterate...
    else  {

        double maximum = Double.NEGATIVE_INFINITY;
        int seriesCount = dataset.getSeriesCount();
        for (int series = 0; series < seriesCount; series++) {
            int itemCount = dataset.getItemCount(series);
            for (int item = 0; item < itemCount; item++) {
                double value;
                if (dataset instanceof IntervalXYDataset) {
                    IntervalXYDataset intervalXYData
                            = (IntervalXYDataset) dataset;
                    value = intervalXYData.getEndYValue(series, item);
                }
                else if (dataset instanceof OHLCDataset) {
                    OHLCDataset highLowData = (OHLCDataset) dataset;
                    value = highLowData.getHighValue(series, item);
                }
                else {
                    value = dataset.getYValue(series, item);
                }
                if (!Double.isNaN(value)) {
                    maximum = Math.max(maximum, value);
                }
            }
        }
        if (maximum == Double.NEGATIVE_INFINITY) {
            return null;
        }
        else {
            return new Double(maximum);
        }

    }

}
 
Example 20
Source File: DPPResultsLabelGenerator.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @see org.jfree.chart.labels.XYItemLabelGenerator#generateLabel(org.jfree.data.xy.XYDataset,
 *      int, int)
 */
public String generateLabel(XYDataset dataset, int series, int item) {

  // X and Y values of current data point
  double originalX = dataset.getX(series, item).doubleValue();
  double originalY = dataset.getY(series, item).doubleValue();

  // Calculate data size of 1 screen pixel
  double xLength = (double) plot.getXYPlot().getDomainAxis().getRange().getLength();
  double pixelX = xLength / plot.getWidth();

  // Size of data set
  int itemCount = dataset.getItemCount(series);

  // Search for data points higher than this one in the interval
  // from limitLeft to limitRight
  double limitLeft = originalX - ((POINTS_RESERVE_X / 2) * pixelX);
  double limitRight = originalX + ((POINTS_RESERVE_X / 2) * pixelX);

  // Iterate data points to the left and right
  for (int i = 1; (item - i > 0) || (item + i < itemCount); i++) {

    // If we get out of the limit we can stop searching
    if ((item - i > 0) && (dataset.getXValue(series, item - i) < limitLeft)
        && ((item + i >= itemCount) || (dataset.getXValue(series, item + i) > limitRight)))
      break;

    if ((item + i < itemCount) && (dataset.getXValue(series, item + i) > limitRight)
        && ((item - i <= 0) || (dataset.getXValue(series, item - i) < limitLeft)))
      break;

    // If we find higher data point, bail out
    if ((item - i > 0) && (originalY <= dataset.getYValue(series, item - i)))
      return null;

    if ((item + i < itemCount) && (originalY <= dataset.getYValue(series, item + i)))
      return null;

  }

  // Create label
  String label = null;
  if (dataset instanceof ScanDataSet) {
    label = ((ScanDataSet) dataset).getAnnotation(item);
  } else if (dataset instanceof DPPResultsDataSet) {
    DataPoint[] dps = ((DPPResultsDataSet) dataset).getDataPoints();
    if(dps[item] instanceof ProcessedDataPoint) {
      ProcessedDataPoint p = (ProcessedDataPoint) dps[item];
      label = createLabel(p);
    }
  }

  if (label == null || label.equals("")) {
    double mzValue = dataset.getXValue(series, item);
    label = mzFormat.format(mzValue);
  }

  return label;
}