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

The following examples show how to use org.jfree.data.xy.XYDataset#getXValue() . 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: SymbolicXYItemLabelGenerator.java    From opensim-gui with Apache License 2.0 6 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>).
 */
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 2
Source File: XYDifferenceRenderer.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Determines if the two (2) series are disjoint.
 * Disjoint series do not overlap in the domain space.
 *
 * @param x_dataset  the dataset.
 *
 * @return true if the dataset is degenerate.
 */
private boolean areSeriesDisjoint(XYDataset x_dataset) {

    int l_minuendItemCount = x_dataset.getItemCount(0);
    double l_minuendFirst  = x_dataset.getXValue(0, 0);
    double l_minuendLast   = x_dataset.getXValue(0, l_minuendItemCount - 1);

    int l_subtrahendItemCount = x_dataset.getItemCount(1);
    double l_subtrahendFirst  = x_dataset.getXValue(1, 0);
    double l_subtrahendLast   = x_dataset.getXValue(1,
            l_subtrahendItemCount - 1);

    return ((l_minuendLast < l_subtrahendFirst)
            || (l_subtrahendLast < l_minuendFirst));
}
 
Example 3
Source File: SymbolicXYItemLabelGenerator.java    From ECG-Viewer with GNU General Public License v2.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 4
Source File: AbstractXYItemLabelGenerator.java    From ccu-historian 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: DefaultPolarItemRenderer.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Plots the data for a given series.
 *
 * @param g2  the drawing surface.
 * @param dataArea  the data area.
 * @param info  collects plot rendering info.
 * @param plot  the plot.
 * @param dataset  the dataset.
 * @param seriesIndex  the series index.
 */
public void drawSeries(Graphics2D g2,
                       Rectangle2D dataArea,
                       PlotRenderingInfo info,
                       PolarPlot plot,
                       XYDataset dataset,
                       int seriesIndex) {

    Polygon poly = new Polygon();
    int numPoints = dataset.getItemCount(seriesIndex);
    for (int i = 0; i < numPoints; i++) {
        double theta = dataset.getXValue(seriesIndex, i);
        double radius = dataset.getYValue(seriesIndex, i);
        Point p = plot.translateValueThetaRadiusToJava2D(theta, radius,
                dataArea);
        poly.addPoint(p.x, p.y);
    }
    g2.setPaint(lookupSeriesPaint(seriesIndex));
    g2.setStroke(lookupSeriesStroke(seriesIndex));
    if (isSeriesFilled(seriesIndex)) {
        Composite savedComposite = g2.getComposite();
        g2.setComposite(AlphaComposite.getInstance(
                AlphaComposite.SRC_OVER, 0.5f));
        g2.fill(poly);
        g2.setComposite(savedComposite);
    }
    else {
        g2.draw(poly);
    }
}
 
Example 6
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 7
Source File: XYDifferenceRenderer.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Determines if the two (2) series are disjoint.
 * Disjoint series do not overlap in the domain space.
 *
 * @param x_dataset  the dataset.
 *
 * @return true if the dataset is degenerate.
 */
private boolean areSeriesDisjoint(XYDataset x_dataset) {

    int l_minuendItemCount = x_dataset.getItemCount(0);
    double l_minuendFirst  = x_dataset.getXValue(0, 0);
    double l_minuendLast   = x_dataset.getXValue(0, l_minuendItemCount - 1);

    int l_subtrahendItemCount = x_dataset.getItemCount(1);
    double l_subtrahendFirst  = x_dataset.getXValue(1, 0);
    double l_subtrahendLast   = x_dataset.getXValue(1,
            l_subtrahendItemCount - 1);

    return ((l_minuendLast < l_subtrahendFirst)
            || (l_subtrahendLast < l_minuendFirst));
}
 
Example 8
Source File: AbstractXYItemLabelGenerator.java    From ECG-Viewer with GNU General Public License v2.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 9
Source File: XYLineAndShapeRenderer.java    From buffer_bci 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.
 *
 * @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);
    }
}
 
Example 10
Source File: VectorRenderer.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) {

    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 11
Source File: DatasetUtilities.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns the maximum domain value for the specified dataset.  This is
 * easy if the dataset implements the {@link DomainInfo} 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 in the dataset are
 * <code>null</code>.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 *
 * @return The maximum value (possibly <code>null</code>).
 */
public static Number findMaximumDomainValue(XYDataset dataset) {
    ParamChecks.nullNotPermitted(dataset, "dataset");
    Number result;
    // if the dataset implements DomainInfo, life is easy
    if (dataset instanceof DomainInfo) {
        DomainInfo info = (DomainInfo) dataset;
        return new Double(info.getDomainUpperBound(true));
    }

    // hasn't implemented DomainInfo, so 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.getEndXValue(series, item);
                }
                else {
                    value = dataset.getXValue(series, item);
                }
                if (!Double.isNaN(value)) {
                    maximum = Math.max(maximum, value);
                }
            }
        }
        if (maximum == Double.NEGATIVE_INFINITY) {
            result = null;
        }
        else {
            result = new Double(maximum);
        }

    }

    return result;
}
 
Example 12
Source File: XYDotRenderer.java    From opensim-gui with Apache License 2.0 4 votes vote down vote up
/**
 * Draws the visual representation of a single data item.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the area within which the data is being drawn.
 * @param info  collects information about the drawing.
 * @param plot  the plot (can be used to obtain standard color 
 *              information etc).
 * @param domainAxis  the domain (horizontal) axis.
 * @param rangeAxis  the range (vertical) axis.
 * @param dataset  the dataset.
 * @param series  the series index (zero-based).
 * @param item  the item index (zero-based).
 * @param crosshairState  crosshair information for the plot 
 *                        (<code>null</code> permitted).
 * @param pass  the pass index.
 */
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) {

    // get the data point...
    double x = dataset.getXValue(series, item);
    double y = dataset.getYValue(series, item);
    double adjx = (this.dotWidth - 1) / 2.0;
    double adjy = (this.dotHeight - 1) / 2.0;
    if (!Double.isNaN(y)) {
        RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
        RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
        double transX = domainAxis.valueToJava2D(x, dataArea, 
                xAxisLocation) - adjx;
        double transY = rangeAxis.valueToJava2D(y, dataArea, yAxisLocation) 
                - adjy;

        g2.setPaint(getItemPaint(series, item));
        PlotOrientation orientation = plot.getOrientation();
        if (orientation == PlotOrientation.HORIZONTAL) {
            g2.fillRect((int) transY, (int) transX, this.dotHeight, 
                    this.dotWidth);
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            g2.fillRect((int) transX, (int) transY, this.dotWidth, 
                    this.dotHeight);
        }

        int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
        int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
        updateCrosshairValues(crosshairState, x, y, domainAxisIndex, 
                rangeAxisIndex, transX, transY, orientation);
    }

}
 
Example 13
Source File: Regression.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns the parameters 'a0', 'a1', 'a2', ..., 'an' for a polynomial 
 * function of order n, y = a0 + a1 * x + a2 * x^2 + ... + an * x^n,
 * fitted to the data using a polynomial regression equation.
 * The result is returned as an array with a length of n + 2,
 * where double[0] --&gt; a0, double[1] --&gt; a1, .., double[n] --&gt; an.
 * and double[n + 1] is the correlation coefficient R2
 * Reference: J. D. Faires, R. L. Burden, Numerische Methoden (german
 * edition), pp. 243ff and 327ff.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param series  the series to fit the regression line against (the series
 *         must have at least order + 1 non-NaN items).
 * @param order  the order of the function (&gt; 0).
 *
 * @return The parameters.
 *
 * @since 1.0.14
 */
public static double[] getPolynomialRegression(XYDataset dataset, 
        int series, int order) {
    ParamChecks.nullNotPermitted(dataset, "dataset");
    int itemCount = dataset.getItemCount(series);
    if (itemCount < order + 1) {
        throw new IllegalArgumentException("Not enough data.");
    }
    int validItems = 0;
    double[][] data = new double[2][itemCount];
    for(int item = 0; item < itemCount; item++){
        double x = dataset.getXValue(series, item);
        double y = dataset.getYValue(series, item);
        if (!Double.isNaN(x) && !Double.isNaN(y)){
            data[0][validItems] = x;
            data[1][validItems] = y;
            validItems++;
        }
    }
    if (validItems < order + 1) {
        throw new IllegalArgumentException("Not enough data.");
    }
    int equations = order + 1;
    int coefficients = order + 2;
    double[] result = new double[equations + 1];
    double[][] matrix = new double[equations][coefficients];
    double sumX = 0.0;
    double sumY = 0.0;

    for(int item = 0; item < validItems; item++){
        sumX += data[0][item];
        sumY += data[1][item];
        for(int eq = 0; eq < equations; eq++){
            for(int coe = 0; coe < coefficients - 1; coe++){
                matrix[eq][coe] += Math.pow(data[0][item],eq + coe);
            }
            matrix[eq][coefficients - 1] += data[1][item]
                    * Math.pow(data[0][item],eq);
        }
    }
    double[][] subMatrix = calculateSubMatrix(matrix);
    for (int eq = 1; eq < equations; eq++) {
        matrix[eq][0] = 0;
        for (int coe = 1; coe < coefficients; coe++) {
            matrix[eq][coe] = subMatrix[eq - 1][coe - 1];
        }
    }
    for (int eq = equations - 1; eq > -1; eq--) {
        double value = matrix[eq][coefficients - 1];
        for (int coe = eq; coe < coefficients -1; coe++) {
            value -= matrix[eq][coe] * result[coe];
        }
        result[eq] = value / matrix[eq][eq];
    }
    double meanY = sumY / validItems;
    double yObsSquare = 0.0;
    double yRegSquare = 0.0;
    for (int item = 0; item < validItems; item++) {
        double yCalc = 0;
        for (int eq = 0; eq < equations; eq++) {
            yCalc += result[eq] * Math.pow(data[0][item],eq);
        }
        yRegSquare += Math.pow(yCalc - meanY, 2);
        yObsSquare += Math.pow(data[1][item] - meanY, 2);
    }
    double rSquare = yRegSquare / yObsSquare;
    result[equations] = rSquare;
    return result;
}
 
Example 14
Source File: XYLineAndShapeRenderer.java    From SIMVA-SoS with Apache License 2.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: DatasetUtilities.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns the maximum domain value for the specified dataset.  This is
 * easy if the dataset implements the {@link DomainInfo} 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 in the dataset are
 * <code>null</code>.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 *
 * @return The maximum value (possibly <code>null</code>).
 */
public static Number findMaximumDomainValue(XYDataset dataset) {
    ParamChecks.nullNotPermitted(dataset, "dataset");
    Number result;
    // if the dataset implements DomainInfo, life is easy
    if (dataset instanceof DomainInfo) {
        DomainInfo info = (DomainInfo) dataset;
        return new Double(info.getDomainUpperBound(true));
    }

    // hasn't implemented DomainInfo, so 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.getEndXValue(series, item);
                }
                else {
                    value = dataset.getXValue(series, item);
                }
                if (!Double.isNaN(value)) {
                    maximum = Math.max(maximum, value);
                }
            }
        }
        if (maximum == Double.NEGATIVE_INFINITY) {
            result = null;
        }
        else {
            result = new Double(maximum);
        }

    }

    return result;
}
 
Example 16
Source File: SpectraItemLabelGenerator.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);
  }
  if (label == null) {
    double mzValue = dataset.getXValue(series, item);
    label = mzFormat.format(mzValue);
  }

  return label;

}
 
Example 17
Source File: XYLineAndShapeRenderer.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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();
    if (orientation == PlotOrientation.HORIZONTAL) {
        state.workingLine.setLine(transY0, transX0, transY1, transX1);
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        state.workingLine.setLine(transX0, transY0, transX1, transY1);
    }

    if (state.workingLine.intersects(dataArea)) {
        drawFirstPassShape(g2, pass, series, item, state.workingLine);
    }
}
 
Example 18
Source File: XYDifferenceRenderer.java    From opensim-gui with Apache License 2.0 4 votes vote down vote up
/**
 * Draws the visual representation of a single data item, first pass.
 *
 * @param g2  the graphics device.
 * @param dataArea  the area within which the data is being drawn.
 * @param info  collects information about the drawing.
 * @param plot  the plot (can be used to obtain standard color 
 *              information etc).
 * @param domainAxis  the domain (horizontal) axis.
 * @param rangeAxis  the range (vertical) axis.
 * @param dataset  the dataset.
 * @param series  the series index (zero-based).
 * @param item  the item index (zero-based).
 * @param crosshairState  crosshair information for the plot 
 *                        (<code>null</code> permitted).
 */
protected void drawItemPass0(Graphics2D g2,
                             Rectangle2D dataArea,
                             PlotRenderingInfo info,
                             XYPlot plot,
                             ValueAxis domainAxis,
                             ValueAxis rangeAxis,
                             XYDataset dataset,
                             int series,
                             int item,
                             CrosshairState crosshairState) {

    if (series == 0) {

        PlotOrientation orientation = plot.getOrientation();
        RectangleEdge domainAxisLocation = plot.getDomainAxisEdge();
        RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge();
        
        double y0 = dataset.getYValue(0, item);
        double x1 = dataset.getXValue(1, item);
        double y1 = dataset.getYValue(1, item);

        double transY0 = rangeAxis.valueToJava2D(y0, dataArea, 
                rangeAxisLocation);
        double transX1 = domainAxis.valueToJava2D(x1, dataArea, 
                domainAxisLocation);
        if (this.roundXCoordinates) {
            transX1 = Math.rint(transX1);
        }
        double transY1 = rangeAxis.valueToJava2D(y1, dataArea, 
                rangeAxisLocation);

        if (item > 0) {
            double prevx0 = dataset.getXValue(0, item - 1);
            double prevy0 = dataset.getYValue(0, item - 1);
            double prevy1 = dataset.getYValue(1, item - 1);

            double prevtransX0 = domainAxis.valueToJava2D(prevx0, dataArea, 
                    domainAxisLocation);
            if (this.roundXCoordinates) {
                prevtransX0 = Math.rint(prevtransX0);
            }
            double prevtransY0 = rangeAxis.valueToJava2D(prevy0, dataArea, 
                    rangeAxisLocation);
            double prevtransY1 = rangeAxis.valueToJava2D(prevy1, dataArea, 
                    rangeAxisLocation);

            Shape positive = getPositiveArea((float) prevtransX0, 
                    (float) prevtransY0, (float) prevtransY1,
                    (float) transX1, (float) transY0, (float) transY1,
                    orientation);
            if (positive != null) {
                g2.setPaint(getPositivePaint());
                g2.fill(positive);
            }

            Shape negative = getNegativeArea((float) prevtransX0, 
                    (float) prevtransY0, (float) prevtransY1,
                    (float) transX1, (float) transY0, (float) transY1,
                    orientation);

            if (negative != null) {
                g2.setPaint(getNegativePaint());
                g2.fill(negative);
            }
        }
    }

}
 
Example 19
Source File: DatasetUtilities.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Finds the minimum domain (or X) value for the specified dataset.  This
 * is easy if the dataset implements the {@link DomainInfo} interface (a
 * good idea if there is an efficient way to determine the minimum value).
 * Otherwise, it involves iterating over the entire data-set.
 * <p>
 * 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 findMinimumDomainValue(XYDataset dataset) {
    if (dataset == null) {
        throw new IllegalArgumentException("Null 'dataset' argument.");
    }
    Number result = null;
    // if the dataset implements DomainInfo, life is easy
    if (dataset instanceof DomainInfo) {
        DomainInfo info = (DomainInfo) dataset;
        return new Double(info.getDomainLowerBound(true));
    }
    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.getStartXValue(series, item);
                }
                else {
                    value = dataset.getXValue(series, item);
                }
                if (!Double.isNaN(value)) {
                    minimum = Math.min(minimum, value);
                }

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

    return result;
}
 
Example 20
Source File: Cardumen_0079_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Returns the maximum domain value for the specified dataset.  This is 
 * easy if the dataset implements the {@link DomainInfo} 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 in the dataset are 
 * <code>null</code>.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 *
 * @return The maximum value (possibly <code>null</code>).
 */
public static Number findMaximumDomainValue(XYDataset dataset) {
    if (dataset == null) {
        throw new IllegalArgumentException("Null 'dataset' argument.");
    }
    Number result = null;
    // if the dataset implements DomainInfo, life is easy
    if (dataset instanceof DomainInfo) {
        DomainInfo info = (DomainInfo) dataset;
        return new Double(info.getDomainUpperBound(true));
    }

    // hasn't implemented DomainInfo, so 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.getEndXValue(series, item);
                }
                else {
                    value = dataset.getXValue(series, item);
                }
                if (!Double.isNaN(value)) {
                    maximum = Math.max(maximum, value);
                }
            }
        }
        if (maximum == Double.NEGATIVE_INFINITY) {
            result = null;
        }
        else {
            result = new Double(maximum);
        }

    }
    
    return result;
}