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

The following examples show how to use org.jfree.chart.plot.XYPlot#getRangeAxisEdge() . 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: FunctionPanel.java    From opensim-gui with Apache License 2.0 6 votes vote down vote up
private FunctionNode findNodeAt(int x, int y) {
   XYPlot xyPlot = getChart().getXYPlot();
   XYDataset xyDataset = xyPlot.getDataset();
   RectangleEdge xAxisLocation = xyPlot.getDomainAxisEdge();
   RectangleEdge yAxisLocation = xyPlot.getRangeAxisEdge();
   Rectangle2D dataArea = getScreenDataArea();
   // Loop through the nodes from last to first, so if the circles
   // for two or more nodes overlap, you get the one drawn on top.
   for (int i=xyDataset.getSeriesCount()-1; i>=0; i--) {
      if (renderer.getSeriesShapesVisible(i)) {
         for (int j=xyDataset.getItemCount(i)-1; j>=0; j--) {
            double sx = xyPlot.getDomainAxis().valueToJava2D(xyDataset.getXValue(i, j), dataArea, xAxisLocation);
            double sy = xyPlot.getRangeAxis().valueToJava2D(xyDataset.getYValue(i, j), dataArea, yAxisLocation);
            double distance = Math.sqrt((sx-x)*(sx-x) + (sy-y)*(sy-y));
            if (distance < 6.0) {
               return new FunctionNode(i, j);
            }
         }
      }
   }
   return null;
}
 
Example 2
Source File: FunctionPanel.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
protected int addNode(int series, int screenX, int screenY) {
   XYPlot xyPlot = getChart().getXYPlot();
   RectangleEdge xAxisLocation = xyPlot.getDomainAxisEdge();
   RectangleEdge yAxisLocation = xyPlot.getRangeAxisEdge();
   Rectangle2D dataArea = getScreenDataArea();
   double newNodeX = xyPlot.getDomainAxis().java2DToValue(screenX, dataArea, xAxisLocation);
   double newNodeY = xyPlot.getRangeAxis().java2DToValue(screenY, dataArea, yAxisLocation);

   // Notify all listeners about the change.
   Object[] listeners = this.functionPanelListeners.getListenerList();
   for (int i = listeners.length - 2; i >= 0; i -= 2) {
      if (listeners[i] == FunctionPanelListener.class) {
         ((FunctionPanelListener) listeners[i + 1]).addNode(series, newNodeX, newNodeY);
      }
   }

   // Now add the point to the series, first figuring out what its index will be.
   XYSeriesCollection seriesCollection = (XYSeriesCollection)xyPlot.getDataset();
   XYSeries dSeries = seriesCollection.getSeries(series);
   int index = dSeries.getItemCount();
   for (int i=0; i<dSeries.getItemCount(); i++) {
      if (dSeries.getDataItem(i).getX().doubleValue() > newNodeX) {
         index = i;
         break;
      }
   }
   dSeries.add(newNodeX, newNodeY);

   updateSelectedNodesAfterAddition(series, index);
   return index;
}
 
Example 3
Source File: FunctionRenderer.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
private void drawInteriorTitle(Graphics2D g2, XYPlot plot, ValueAxis domainAxis,
        ValueAxis rangeAxis, Rectangle2D dataArea) {
   RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
   RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
   
   if (this.interiorTitle != null) {
      g2.setFont(this.interiorTitleFont);
      g2.setPaint(this.interiorTitlePaint);
      double textX = domainAxis.valueToJava2D(domainAxis.getUpperBound(), dataArea, xAxisLocation) - 2;
      double textY = rangeAxis.valueToJava2D(rangeAxis.getUpperBound(), dataArea, yAxisLocation) + 2;
      TextUtilities.drawAlignedString(this.interiorTitle, g2, (float)textX, (float)textY, TextAnchor.TOP_RIGHT);
   }
}
 
Example 4
Source File: YIntervalRenderer.java    From SIMVA-SoS 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 plot 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 axis.
 * @param rangeAxis  the range 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 (ignored here).
 */
@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) {

    // setup for collecting optional entity info...
    EntityCollection entities = null;
    if (info != null) {
        entities = info.getOwner().getEntityCollection();
    }

    IntervalXYDataset intervalDataset = (IntervalXYDataset) dataset;

    double x = intervalDataset.getXValue(series, item);
    double yLow   = intervalDataset.getStartYValue(series, item);
    double yHigh  = intervalDataset.getEndYValue(series, item);

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

    double xx = domainAxis.valueToJava2D(x, dataArea, xAxisLocation);
    double yyLow = rangeAxis.valueToJava2D(yLow, dataArea, yAxisLocation);
    double yyHigh = rangeAxis.valueToJava2D(yHigh, dataArea, yAxisLocation);

    Paint p = getItemPaint(series, item);
    Stroke s = getItemStroke(series, item);

    Line2D line = null;
    Shape shape = getItemShape(series, item);
    Shape top = null;
    Shape bottom = null;
    PlotOrientation orientation = plot.getOrientation();
    if (orientation == PlotOrientation.HORIZONTAL) {
        line = new Line2D.Double(yyLow, xx, yyHigh, xx);
        top = ShapeUtilities.createTranslatedShape(shape, yyHigh, xx);
        bottom = ShapeUtilities.createTranslatedShape(shape, yyLow, xx);
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        line = new Line2D.Double(xx, yyLow, xx, yyHigh);
        top = ShapeUtilities.createTranslatedShape(shape, xx, yyHigh);
        bottom = ShapeUtilities.createTranslatedShape(shape, xx, yyLow);
    } else {
        throw new IllegalStateException();
    }
    g2.setPaint(p);
    g2.setStroke(s);
    g2.draw(line);

    g2.fill(top);
    g2.fill(bottom);

    // for item labels, we have a special case because there is the
    // possibility to draw (a) the regular item label near to just the
    // upper y-value, or (b) the regular item label near the upper y-value
    // PLUS an additional item label near the lower y-value.
    if (isItemLabelVisible(series, item)) {
        drawItemLabel(g2, orientation, dataset, series, item, xx, yyHigh,
                false);
        drawAdditionalItemLabel(g2, orientation, dataset, series, item,
                xx, yyLow);
    }

    // add an entity for the item...
    if (entities != null) {
        addEntity(entities, line.getBounds(), dataset, series, item, 0.0,
                0.0);
    }

}
 
Example 5
Source File: FunctionPanel.java    From opensim-gui with Apache License 2.0 4 votes vote down vote up
public void mousePressed(MouseEvent e) {
   this.requestFocusInWindow();
   updateCursorLocation(e);
   FunctionNode leftClickNode = null;
   int keyMods = e.getModifiers();
   if ((keyMods & InputEvent.BUTTON1_MASK) > 0) {
      leftClickNode = findNodeAt(e.getX(), e.getY());

      // Some code to handle double clicking on an object, but which does so in a way that the sequence
      // CTRL-Click and Click does not count as a double click.  This avoids
      // treating as double click the case where the user selects an object
      // (CTRL-Click) and quickly starts dragging (Click & Drag) 
      if (leftClickNode != null && picking == false) {
         if (e.getClickCount() == lastLeftButtonClickCount+1 && leftClickNode == lastLeftButtonClickNode) {
            //handleDoubleClick(leftClickNode);
            return; 
         } else {
            lastLeftButtonClickCount = e.getClickCount();
            lastLeftButtonClickNode = leftClickNode;
         } 
      } else {
         lastLeftButtonClickCount = -1;
         lastLeftButtonClickNode = null;
      }
   }

   if ((keyMods & InputEvent.BUTTON3_MASK) > 0) {
      rightClickNode = findNodeAt(e.getX(), e.getY());
      rightClickX = e.getX();
      rightClickY = e.getY();
   } else if (picking == true && (keyMods & InputEvent.BUTTON1_MASK) > 0) {
      if (leftClickNode == null) {
         // Picking mode is on, but the user clicked away from a control point.
         // So clear the selections (unless Shift is pressed) and prepare for a box select.
         if ((keyMods & InputEvent.SHIFT_MASK) <= 0)
            clearSelectedNodes();
         startBoxSelect(e);
      } else {
         if ((keyMods & InputEvent.SHIFT_MASK) > 0) {
            toggleSelectedNode(leftClickNode.series, leftClickNode.node);
         } else {
            replaceSelectedNode(leftClickNode.series, leftClickNode.node);
         }
      }
   } else if ((leftClickNode != null) && listContainsNode(leftClickNode, selectedNodes) == true) {
      XYPlot xyPlot = getChart().getXYPlot();
      dragNode = leftClickNode;
      dragScreenXOld = e.getX();
      dragScreenYOld = e.getY();
      RectangleEdge xAxisLocation = xyPlot.getDomainAxisEdge();
      RectangleEdge yAxisLocation = xyPlot.getRangeAxisEdge();
      Rectangle2D dataArea = getScreenDataArea();
      dragDataXOld = xyPlot.getDomainAxis().java2DToValue((double)e.getX(), dataArea, xAxisLocation);
      dragDataYOld = xyPlot.getRangeAxis().java2DToValue((double)e.getY(), dataArea, yAxisLocation);
      setDragging(true);
      // During dragging, the crosshairs lock onto the center of the dragNode
      double crosshairX = xyPlot.getDataset().getXValue(dragNode.series, dragNode.node);
      double crosshairY = xyPlot.getDataset().getYValue(dragNode.series, dragNode.node);
      double crosshairScreenX = xyPlot.getDomainAxis().valueToJava2D(crosshairX, dataArea, xAxisLocation);
      double crosshairScreenY = xyPlot.getRangeAxis().valueToJava2D(crosshairY, dataArea, yAxisLocation);
      updateCrosshairs((int)crosshairScreenX, (int)crosshairScreenY);
      picking = false;
   } else {
      super.mousePressed(e);
   }
}
 
Example 6
Source File: XYDotRenderer.java    From SIMVA-SoS 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.
 */
@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) {

    // do nothing if item is not visible
    if (!getItemVisible(series, item)) {
        return;
    }

    // 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 7
Source File: YIntervalRenderer.java    From astor with GNU General Public License v2.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 plot 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 series  the series index (zero-based).
 * @param item  the item index (zero-based).
 * @param selected  is the item selected?
 * @param pass  the pass index (ignored here).
 *
 * @since 1.2.0
 */
public void drawItem(Graphics2D g2, XYItemRendererState state,
        Rectangle2D dataArea, XYPlot plot, ValueAxis domainAxis,
        ValueAxis rangeAxis, XYDataset dataset, int series, int item,
        boolean selected, int pass) {

    // setup for collecting optional entity info...
    EntityCollection entities = null;
    if (state.getInfo() != null) {
        entities = state.getInfo().getOwner().getEntityCollection();
    }

    IntervalXYDataset intervalDataset = (IntervalXYDataset) dataset;

    double x = intervalDataset.getXValue(series, item);
    double yLow   = intervalDataset.getStartYValue(series, item);
    double yHigh  = intervalDataset.getEndYValue(series, item);

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

    double xx = domainAxis.valueToJava2D(x, dataArea, xAxisLocation);
    double yyLow = rangeAxis.valueToJava2D(yLow, dataArea, yAxisLocation);
    double yyHigh = rangeAxis.valueToJava2D(yHigh, dataArea, yAxisLocation);

    Paint p = getItemPaint(series, item, selected);
    Stroke s = getItemStroke(series, item, selected);

    Line2D line = null;
    Shape shape = getItemShape(series, item, selected);
    Shape top = null;
    Shape bottom = null;
    PlotOrientation orientation = plot.getOrientation();
    if (orientation == PlotOrientation.HORIZONTAL) {
        line = new Line2D.Double(yyLow, xx, yyHigh, xx);
        top = ShapeUtilities.createTranslatedShape(shape, yyHigh, xx);
        bottom = ShapeUtilities.createTranslatedShape(shape, yyLow, xx);
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        line = new Line2D.Double(xx, yyLow, xx, yyHigh);
        top = ShapeUtilities.createTranslatedShape(shape, xx, yyHigh);
        bottom = ShapeUtilities.createTranslatedShape(shape, xx, yyLow);
    }
    g2.setPaint(p);
    g2.setStroke(s);
    g2.draw(line);

    g2.fill(top);
    g2.fill(bottom);

    // for item labels, we have a special case because there is the
    // possibility to draw (a) the regular item label near to just the
    // upper y-value, or (b) the regular item label near the upper y-value
    // PLUS an additional item label near the lower y-value.
    if (isItemLabelVisible(series, item, selected)) {
        drawItemLabel(g2, orientation, dataset, series, item, selected, 
                xx, yyHigh, false);
        drawAdditionalItemLabel(g2, orientation, dataset, series, item,
                xx, yyLow);
    }

    // add an entity for the item...
    if (entities != null) {
        addEntity(entities, line.getBounds(), dataset, series, item, 
                selected, 0.0, 0.0);
    }

}
 
Example 8
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. 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 9
Source File: XYLineAndShapeRenderer.java    From astor 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 selected  is the data item selected?
 * @param crosshairState  the crosshair state.
 * @param entities the entity collection.
 */
protected void drawShape2(Graphics2D g2, Rectangle2D dataArea,
        XYPlot plot, XYDataset dataset, int pass, int series, int item,
        boolean selected, ValueAxis domainAxis, 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, selected);
        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, selected));
                }
                else {
                    g2.setPaint(getItemPaint(series, item, selected));
                }
                g2.fill(shape);
            }
            if (this.drawOutlines) {
                if (getUseOutlinePaint()) {
                    g2.setPaint(getItemOutlinePaint(series, item,
                            selected));
                }
                else {
                    g2.setPaint(getItemPaint(series, item, selected));
                }
                g2.setStroke(getItemOutlineStroke(series, item, selected));
                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, selected)) {
        drawItemLabel(g2, orientation, dataset, series, item, selected, 
                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 
            && ShapeUtilities.isPointInRect(xx, yy, dataArea)) {
        addEntity(entities, entityArea, dataset, series, item, selected,
                xx, yy);
    }
}
 
Example 10
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. 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 selected  is the data item selected?
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataArea  the area within which the data is being drawn.
 *
 * @since 1.2.0
 */
protected void drawPrimaryLineAsPath(XYItemRendererState state,
        Graphics2D g2, XYPlot plot, XYDataset dataset, int pass,
        int series, int item, boolean selected, 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
        drawShape1(g2, pass, series, item, selected, s.seriesPath);
    }
}
 
Example 11
Source File: WindItemRenderer.java    From ccu-historian with GNU General Public License v3.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 plotArea  the area within which the plot is being drawn.
 * @param info  optional information collection.
 * @param plot  the plot (can be used to obtain standard color
 *              information etc).
 * @param domainAxis  the horizontal axis.
 * @param rangeAxis  the 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.
 */
@Override
public void drawItem(Graphics2D g2, XYItemRendererState state,
        Rectangle2D plotArea, PlotRenderingInfo info, XYPlot plot,
        ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset,
        int series, int item, CrosshairState crosshairState, int pass) {

    WindDataset windData = (WindDataset) dataset;

    Paint seriesPaint = getItemPaint(series, item);
    Stroke seriesStroke = getItemStroke(series, item);
    g2.setPaint(seriesPaint);
    g2.setStroke(seriesStroke);

    // get the data point...

    Number x = windData.getX(series, item);
    Number windDir = windData.getWindDirection(series, item);
    Number wforce = windData.getWindForce(series, item);
    double windForce = wforce.doubleValue();

    double wdirt = Math.toRadians(windDir.doubleValue() * (-30.0) - 90.0);

    double ax1, ax2, ay1, ay2, rax2, ray2;

    RectangleEdge domainAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge();
    ax1 = domainAxis.valueToJava2D(x.doubleValue(), plotArea,
            domainAxisLocation);
    ay1 = rangeAxis.valueToJava2D(0.0, plotArea, rangeAxisLocation);

    rax2 = x.doubleValue() + (windForce * Math.cos(wdirt) * 8000000.0);
    ray2 = windForce * Math.sin(wdirt);

    ax2 = domainAxis.valueToJava2D(rax2, plotArea, domainAxisLocation);
    ay2 = rangeAxis.valueToJava2D(ray2, plotArea, rangeAxisLocation);

    int diri = windDir.intValue();
    int forcei = wforce.intValue();
    String dirforce = diri + "-" + forcei;
    Line2D line = new Line2D.Double(ax1, ay1, ax2, ay2);

    g2.draw(line);
    g2.setPaint(Color.blue);
    g2.setFont(new Font("Dialog", 1, 9));

    g2.drawString(dirforce, (float) ax1, (float) ay1);

    g2.setPaint(seriesPaint);
    g2.setStroke(seriesStroke);

    double alx2, aly2, arx2, ary2;
    double ralx2, raly2, rarx2, rary2;

    double aldir = Math.toRadians(windDir.doubleValue()
            * (-30.0) - 90.0 - 5.0);
    ralx2 = wforce.doubleValue() * Math.cos(aldir) * 8000000 * 0.8
    + x.doubleValue();
    raly2 = wforce.doubleValue() * Math.sin(aldir) * 0.8;

    alx2 = domainAxis.valueToJava2D(ralx2, plotArea, domainAxisLocation);
    aly2 = rangeAxis.valueToJava2D(raly2, plotArea, rangeAxisLocation);

    line = new Line2D.Double(alx2, aly2, ax2, ay2);
    g2.draw(line);

    double ardir = Math.toRadians(windDir.doubleValue()
            * (-30.0) - 90.0 + 5.0);
    rarx2 = wforce.doubleValue() * Math.cos(ardir) * 8000000 * 0.8
            + x.doubleValue();
    rary2 = wforce.doubleValue() * Math.sin(ardir) * 0.8;

    arx2 = domainAxis.valueToJava2D(rarx2, plotArea, domainAxisLocation);
    ary2 = rangeAxis.valueToJava2D(rary2, plotArea, rangeAxisLocation);

    line = new Line2D.Double(arx2, ary2, ax2, ay2);
    g2.draw(line);

}
 
Example 12
Source File: XYDotRenderer.java    From buffer_bci with GNU General Public License v3.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.
 */
@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) {

    // do nothing if item is not visible
    if (!getItemVisible(series, item)) {
        return;
    }

    // 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: XYLineAndShapeRenderer.java    From buffer_bci with GNU General Public License v3.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 14
Source File: XYLineAndShapeRenderer.java    From opensim-gui with Apache License 2.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 15
Source File: XYLineAndShapeRenderer.java    From ECG-Viewer 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. 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 16
Source File: WindItemRenderer.java    From openstock with GNU General Public License v3.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 plotArea  the area within which the plot is being drawn.
 * @param info  optional information collection.
 * @param plot  the plot (can be used to obtain standard color
 *              information etc).
 * @param domainAxis  the horizontal axis.
 * @param rangeAxis  the 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.
 */
@Override
public void drawItem(Graphics2D g2, XYItemRendererState state,
        Rectangle2D plotArea, PlotRenderingInfo info, XYPlot plot,
        ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset,
        int series, int item, CrosshairState crosshairState, int pass) {

    WindDataset windData = (WindDataset) dataset;

    Paint seriesPaint = getItemPaint(series, item);
    Stroke seriesStroke = getItemStroke(series, item);
    g2.setPaint(seriesPaint);
    g2.setStroke(seriesStroke);

    // get the data point...

    Number x = windData.getX(series, item);
    Number windDir = windData.getWindDirection(series, item);
    Number wforce = windData.getWindForce(series, item);
    double windForce = wforce.doubleValue();

    double wdirt = Math.toRadians(windDir.doubleValue() * (-30.0) - 90.0);

    double ax1, ax2, ay1, ay2, rax2, ray2;

    RectangleEdge domainAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge();
    ax1 = domainAxis.valueToJava2D(x.doubleValue(), plotArea,
            domainAxisLocation);
    ay1 = rangeAxis.valueToJava2D(0.0, plotArea, rangeAxisLocation);

    rax2 = x.doubleValue() + (windForce * Math.cos(wdirt) * 8000000.0);
    ray2 = windForce * Math.sin(wdirt);

    ax2 = domainAxis.valueToJava2D(rax2, plotArea, domainAxisLocation);
    ay2 = rangeAxis.valueToJava2D(ray2, plotArea, rangeAxisLocation);

    int diri = windDir.intValue();
    int forcei = wforce.intValue();
    String dirforce = diri + "-" + forcei;
    Line2D line = new Line2D.Double(ax1, ay1, ax2, ay2);

    g2.draw(line);
    g2.setPaint(Color.blue);
    g2.setFont(new Font("Dialog", 1, 9));

    g2.drawString(dirforce, (float) ax1, (float) ay1);

    g2.setPaint(seriesPaint);
    g2.setStroke(seriesStroke);

    double alx2, aly2, arx2, ary2;
    double ralx2, raly2, rarx2, rary2;

    double aldir = Math.toRadians(windDir.doubleValue()
            * (-30.0) - 90.0 - 5.0);
    ralx2 = wforce.doubleValue() * Math.cos(aldir) * 8000000 * 0.8
    + x.doubleValue();
    raly2 = wforce.doubleValue() * Math.sin(aldir) * 0.8;

    alx2 = domainAxis.valueToJava2D(ralx2, plotArea, domainAxisLocation);
    aly2 = rangeAxis.valueToJava2D(raly2, plotArea, rangeAxisLocation);

    line = new Line2D.Double(alx2, aly2, ax2, ay2);
    g2.draw(line);

    double ardir = Math.toRadians(windDir.doubleValue()
            * (-30.0) - 90.0 + 5.0);
    rarx2 = wforce.doubleValue() * Math.cos(ardir) * 8000000 * 0.8
            + x.doubleValue();
    rary2 = wforce.doubleValue() * Math.sin(ardir) * 0.8;

    arx2 = domainAxis.valueToJava2D(rarx2, plotArea, domainAxisLocation);
    ary2 = rangeAxis.valueToJava2D(rary2, plotArea, rangeAxisLocation);

    line = new Line2D.Double(arx2, ary2, ax2, ay2);
    g2.draw(line);

}
 
Example 17
Source File: YIntervalRenderer.java    From buffer_bci with GNU General Public License v3.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 plot 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 axis.
 * @param rangeAxis  the range 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 (ignored here).
 */
@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) {

    // setup for collecting optional entity info...
    EntityCollection entities = null;
    if (info != null) {
        entities = info.getOwner().getEntityCollection();
    }

    IntervalXYDataset intervalDataset = (IntervalXYDataset) dataset;

    double x = intervalDataset.getXValue(series, item);
    double yLow   = intervalDataset.getStartYValue(series, item);
    double yHigh  = intervalDataset.getEndYValue(series, item);

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

    double xx = domainAxis.valueToJava2D(x, dataArea, xAxisLocation);
    double yyLow = rangeAxis.valueToJava2D(yLow, dataArea, yAxisLocation);
    double yyHigh = rangeAxis.valueToJava2D(yHigh, dataArea, yAxisLocation);

    Paint p = getItemPaint(series, item);
    Stroke s = getItemStroke(series, item);

    Line2D line = null;
    Shape shape = getItemShape(series, item);
    Shape top = null;
    Shape bottom = null;
    PlotOrientation orientation = plot.getOrientation();
    if (orientation == PlotOrientation.HORIZONTAL) {
        line = new Line2D.Double(yyLow, xx, yyHigh, xx);
        top = ShapeUtilities.createTranslatedShape(shape, yyHigh, xx);
        bottom = ShapeUtilities.createTranslatedShape(shape, yyLow, xx);
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        line = new Line2D.Double(xx, yyLow, xx, yyHigh);
        top = ShapeUtilities.createTranslatedShape(shape, xx, yyHigh);
        bottom = ShapeUtilities.createTranslatedShape(shape, xx, yyLow);
    } else {
        throw new IllegalStateException();
    }
    g2.setPaint(p);
    g2.setStroke(s);
    g2.draw(line);

    g2.fill(top);
    g2.fill(bottom);

    // for item labels, we have a special case because there is the
    // possibility to draw (a) the regular item label near to just the
    // upper y-value, or (b) the regular item label near the upper y-value
    // PLUS an additional item label near the lower y-value.
    if (isItemLabelVisible(series, item)) {
        drawItemLabel(g2, orientation, dataset, series, item, xx, yyHigh,
                false);
        drawAdditionalItemLabel(g2, orientation, dataset, series, item,
                xx, yyLow);
    }

    // add an entity for the item...
    if (entities != null) {
        addEntity(entities, line.getBounds(), dataset, series, item, 0.0,
                0.0);
    }

}
 
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: SamplingXYLineRenderer.java    From ECG-Viewer with GNU General Public License v2.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 axis.
 * @param rangeAxis  the range 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.
 */
@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) {

    // do nothing if item is not visible
    if (!getItemVisible(series, item)) {
        return;
    }
    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.lastPointGood) {
            if ((Math.abs(x - s.lastX) > s.dX)) {
                s.seriesPath.lineTo(x, y);
                if (s.lowY < s.highY) {
                    s.intervalPath.moveTo((float) s.lastX, (float) s.lowY);
                    s.intervalPath.lineTo((float) s.lastX, (float) s.highY);
                }
                s.lastX = x;
                s.openY = y;
                s.highY = y;
                s.lowY = y;
                s.closeY = y;
            }
            else {
                s.highY = Math.max(s.highY, y);
                s.lowY = Math.min(s.lowY, y);
                s.closeY = y;
            }
        }
        else {
            s.seriesPath.moveTo(x, y);
            s.lastX = x;
            s.openY = y;
            s.highY = y;
            s.lowY = y;
            s.closeY = y;
        }
        s.lastPointGood = true;
    }
    else {
        s.lastPointGood = false;
    }
    // if this is the last item, draw the path ...
    if (item == s.getLastItemIndex()) {
        // draw path
        PathIterator pi = s.seriesPath.getPathIterator(null);
        int count = 0;
        while (!pi.isDone()) {
            count++;
            pi.next();
        }
        g2.setStroke(getItemStroke(series, item));
        g2.setPaint(getItemPaint(series, item));
        g2.draw(s.seriesPath);
        g2.draw(s.intervalPath);
    }
}
 
Example 20
Source File: FunctionPanel.java    From opensim-gui with Apache License 2.0 4 votes vote down vote up
public void updateCrosshairs(int screenX, int screenY) {
   XYPlot xyPlot = getChart().getXYPlot();
   if (showCrosshairs == true) {
      RectangleEdge xAxisLocation = xyPlot.getDomainAxisEdge();
      RectangleEdge yAxisLocation = xyPlot.getRangeAxisEdge();
      Rectangle2D dataArea = getScreenDataArea();
      double crosshairX = xyPlot.getDomainAxis().java2DToValue((double)screenX, dataArea, xAxisLocation);
      double crosshairY = xyPlot.getRangeAxis().java2DToValue((double)screenY, dataArea, yAxisLocation);
      if (crosshairX < xyPlot.getDomainAxis().getLowerBound() ||
          crosshairX > xyPlot.getDomainAxis().getUpperBound() ||
          crosshairY < xyPlot.getRangeAxis().getLowerBound() ||
          crosshairY > xyPlot.getRangeAxis().getUpperBound()) {
         xyPlot.setDomainCrosshairVisible(false);
         xyPlot.setRangeCrosshairVisible(false);
         crosshairAnnotation.setText("");
      } else {
         xyPlot.setDomainCrosshairVisible(true);
         xyPlot.setRangeCrosshairVisible(true);
         /** The xyPlot's crosshairs are updated with the screen coordinates of the XY location.
          * The annotation's text and location is updated with the data coordinates.
          * The format used for displaying the XY data coordinates is taken from the
          * format used for the X and Y axis tick labels. This format is not normally
          * accessible here, but a method was added to NumberTickUnit to provide it.
          * If this turns out to be problematic, the format could always be changed
          * to use a fixed number of significant digits.
          */
         NumberAxis dna = (NumberAxis)xyPlot.getDomainAxis();
         NumberFormat dnf = (NumberFormat)dna.getTickUnit().getFormatter().clone();
         dnf.setMaximumFractionDigits(dnf.getMaximumFractionDigits()+3);
         String xString = dnf.format(crosshairX);
         NumberAxis rna = (NumberAxis)xyPlot.getRangeAxis();
         NumberFormat rnf = (NumberFormat)rna.getTickUnit().getFormatter().clone();
         rnf.setMaximumFractionDigits(rnf.getMaximumFractionDigits()+3);
         String yString = rnf.format(crosshairY);
         crosshairAnnotation.setText("(" + xString + ", " + yString + ")");
         crosshairAnnotation.setX(crosshairX);
         crosshairAnnotation.setY(crosshairY);
         xyPlot.setDomainCrosshairValue(crosshairX);
         xyPlot.setRangeCrosshairValue(crosshairY);
         // JPL 11/19/09: the chart's plotInfo does not appear to be updated when the
         // FunctionPanel is resized. So the following call to handleClick will pass in
         // the wrong plot area for calculating crosshair coordinates. So instead, set
         // the crosshair directly with the two lines above this comment.
         //xyPlot.handleClick(screenX, screenY, this.getChartRenderingInfo().getPlotInfo());
      }
   }
}