Logo Search packages:      
Sourcecode: libjfreechart-java version File versions  Download package

void org::jfree::experimental::chart::renderer::xy::XYSmoothLineAndShapeRenderer::drawPrimaryLine ( XYItemRendererState  state,
Graphics2D  g2,
XYPlot  plot,
XYDataset  dataset,
int  pass,
int  series,
int  item,
ValueAxis  domainAxis,
ValueAxis  rangeAxis,
Rectangle2D  dataArea 
) [inline, protected]

Draws the item (first pass). This method draws the lines connecting the items.

Parameters:
g2 the graphics device.
state the renderer state.
dataArea the area within which the data is being drawn.
plot the plot (can be used to obtain standard color information etc).
domainAxis the domain axis.
rangeAxis the range axis.
dataset the dataset.
pass the pass.
series the series index (zero-based).
item the item index (zero-based).

Reimplemented from org::jfree::chart::renderer::xy::XYLineAndShapeRenderer.

Definition at line 67 of file XYSmoothLineAndShapeRenderer.java.

References org::jfree::chart::renderer::xy::XYLineAndShapeRenderer::drawFirstPassShape(), getBezierCurve(), org::jfree::chart::plot::XYPlot::getDomainAxisEdge(), org::jfree::data::xy::XYDataset::getItemCount(), org::jfree::chart::plot::XYPlot::getOrientation(), org::jfree::chart::plot::XYPlot::getRangeAxisEdge(), org::jfree::data::xy::XYDataset::getXValue(), org::jfree::data::xy::XYDataset::getYValue(), org::jfree::chart::plot::PlotOrientation::HORIZONTAL, org::jfree::chart::axis::ValueAxis::valueToJava2D(), org::jfree::chart::plot::PlotOrientation::VERTICAL, and org::jfree::chart::renderer::xy::XYItemRendererState::workingLine.

                                                                             {
           
        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;
        }
             
        Point2D.Double point0 = new Point2D.Double();
        Point2D.Double point1 = new Point2D.Double();
        Point2D.Double point2 = new Point2D.Double();
        Point2D.Double point3 = new Point2D.Double();
           
        if (item == 1) {
            point0 = null;
        } 
        else {
            point0.x = domainAxis.valueToJava2D(dataset.getXValue(series, 
                    item - 2), dataArea, xAxisLocation);
            point0.y = rangeAxis.valueToJava2D(dataset.getYValue(series, 
                    item - 2), dataArea, yAxisLocation);
        }
           
        point1.x = transX0;
        point1.y = transY0;
           
        point2.x = transX1;
        point2.y = transY1;
           
        if ((item + 1) == dataset.getItemCount(series)) {
            point3 = null;
        } 
        else {
            point3.x = domainAxis.valueToJava2D(dataset.getXValue(series, 
                    item + 1), dataArea, xAxisLocation);
            point3.y = rangeAxis.valueToJava2D(dataset.getYValue(series, 
                    item + 1), dataArea, yAxisLocation);
        }

        int steps = ((int) ((point2.x - point1.x) / 0.2) < 30) 
                ? (int) ((point2.x - point1.x) / 0.2) : 30;
           
        Point2D.Double[] points = getBezierCurve(point0, point1, point2, 
                point3, 1, steps);
           
        for (int i = 1; i < points.length; i++) {
            transX0 = points[i - 1].x;
            transY0 = points[i - 1].y;
            transX1 = points[i].x;
            transY1 = points[i].y;
             
            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);
            }
        }
    }


Generated by  Doxygen 1.6.0   Back to index