Example usage for org.jfree.data.xy XYDataset getXValue

List of usage examples for org.jfree.data.xy XYDataset getXValue

Introduction

In this page you can find the example usage for org.jfree.data.xy XYDataset getXValue.

Prototype

public double getXValue(int series, int item);

Source Link

Document

Returns the x-value for an item within a series.

Usage

From source file:net.sf.maltcms.chromaui.msviewer.ui.panel.MassSpectrumPanel.java

private void initChartComponents() {

    this.sc = new XYSeriesCollection();
    barDataset = new XYBarDataset(sc, barWidth);
    XYBarRenderer renderer = new XYBarRenderer(0.1d);
    StandardXYBarPainter sp = new StandardXYBarPainter();
    renderer.setBarPainter(sp);/*from   ww  w  .  j a  va  2s . c  o  m*/
    renderer.setShadowVisible(false);
    renderer.setDrawBarOutline(false);
    NumberAxis intensityAxis = new NumberAxis("intensity");
    intensityAxis.setNumberFormatOverride(defaultNumberFormat);
    intensityAxis.setUpperMargin(0.10d);
    NumberAxis mzAxis = new NumberAxis("m/z");
    mzAxis.setAutoRangeIncludesZero(false);
    this.plot = new XYPlot(barDataset, mzAxis, intensityAxis, renderer);
    this.plot.setForegroundAlpha(0.85f);

    plot.setDomainCrosshairLockedOnData(true);
    plot.setDomainCrosshairVisible(true);
    ((XYBarRenderer) plot.getRenderer()).setShadowVisible(false);
    ((XYBarRenderer) plot.getRenderer()).setDrawBarOutline(false);
    ((XYBarRenderer) plot.getRenderer()).setBaseFillPaint(Color.RED);
    ((XYBarRenderer) plot.getRenderer()).setBarPainter(new StandardXYBarPainter());
    plot.getRenderer().setBaseItemLabelsVisible(true);
    plot.getRenderer().setBaseToolTipGenerator(new XYToolTipGenerator() {
        @Override
        public String generateToolTip(XYDataset xyd, int i, int i1) {
            Comparable comp = xyd.getSeriesKey(i);
            double x = xyd.getXValue(i, i1);
            double y = xyd.getYValue(i, i1);
            StringBuilder sb = new StringBuilder();
            sb.append(comp);
            sb.append(": ");
            sb.append("x=");
            sb.append(String.format("%.4f", x));
            sb.append(" y=");
            sb.append(String.format("%.4f", y));
            return sb.toString();
        }
    });
    plot.setDomainPannable(true);
    plot.setRangePannable(true);
    sc.addChangeListener(plot);
    JFreeChart msChart = new JFreeChart(this.plot);
    msChart.addChangeListener(this.defaultNumberFormat);
    //      System.out.println("Creating ms chart 3");
    this.cp = new ContextAwareChartPanel(msChart, true, true, true, true, true);
    this.cp.setInitialDelay(1);
    this.cp.getChart().getLegend().setVisible(true);
    this.cp.setMouseWheelEnabled(true);
    this.clearActionPerformed(null);
    this.jPanel2.removeAll();
    this.jPanel2.add(cp);
    this.jPanel2.repaint();
    this.massLabelsSpinner.setValue(topK);
}

From source file:course_generator.param.frmEditCurve.java

/**
 * This method is called to initialize the form.
 */// ww w .  java  2  s  . c  om
private void initComponents() {
    int line = 0;

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    setTitle(bundle.getString("frmEditCurve.title"));
    setPreferredSize(new Dimension(1200, 600));
    setAlwaysOnTop(true);
    setResizable(false);
    setType(java.awt.Window.Type.UTILITY);
    addWindowListener(new java.awt.event.WindowAdapter() {
        public void windowClosing(java.awt.event.WindowEvent evt) {
            formWindowClosing(evt);
        }
    });

    // -- Layout
    // ------------------------------------------------------------
    Container paneGlobal = getContentPane();
    paneGlobal.setLayout(new GridBagLayout());

    //-- Curves list
    ListCurves = new javax.swing.JList<>();
    model = new ParamListModel();
    ListCurves.setModel(model);
    ListCurves.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
    ListCurves.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            SelectCurve();
        }
    });
    jScrollPaneCurves = new javax.swing.JScrollPane();
    jScrollPaneCurves.setViewportView(ListCurves);

    Utils.addComponent(paneGlobal, jScrollPaneCurves, 0, 0, 1, 4, 0.5, 1, 10, 10, 0, 0,
            GridBagConstraints.PAGE_START, GridBagConstraints.BOTH);

    //-- Curve management toolbar
    CreateCurvesToolbar();
    Utils.addComponent(paneGlobal, ToolBarAction, 1, 0, 1, 4, 0, 0, 10, 0, 0, 0,
            GridBagConstraints.BASELINE_LEADING, GridBagConstraints.BOTH);

    lbSelectedCurve = new javax.swing.JLabel();
    lbSelectedCurve.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    lbSelectedCurve.setText("Selected");
    lbSelectedCurve.setHorizontalAlignment(JLabel.LEFT);
    Utils.addComponent(paneGlobal, lbSelectedCurve, 2, 0, GridBagConstraints.REMAINDER, 1, 1, 0, 10, 0, 5, 10,
            GridBagConstraints.BASELINE_LEADING, GridBagConstraints.HORIZONTAL);

    //-- Curve name
    lbName = new javax.swing.JLabel();
    lbName.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    lbName.setText(" " + bundle.getString("frmEditCurve.lbName.text") + " ");
    Utils.addComponent(paneGlobal, lbName, 2, 1, 1, 1, 0, 0, 0, 0, 5, 0, GridBagConstraints.BASELINE_LEADING,
            GridBagConstraints.HORIZONTAL);

    lbNameVal = new javax.swing.JLabel();
    lbNameVal.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    Utils.addComponent(paneGlobal, lbNameVal, 3, 1, GridBagConstraints.REMAINDER, 1, 1, 0, 0, 5, 5, 10,
            GridBagConstraints.BASELINE_LEADING, GridBagConstraints.BOTH);

    //-- Curve comment
    lbComment = new javax.swing.JLabel();
    lbComment.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    lbComment.setText(" " + bundle.getString("frmEditCurve.lbComment.text") + " ");
    Utils.addComponent(paneGlobal, lbComment, 2, 2, 1, 1, 0, 0, 0, 0, 5, 0, GridBagConstraints.BASELINE_LEADING,
            GridBagConstraints.HORIZONTAL);

    tfComment = new JTextField();
    tfComment.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    Utils.addComponent(paneGlobal, tfComment, 3, 2, GridBagConstraints.REMAINDER, 1, 1, 0, 0, 5, 5, 10,
            GridBagConstraints.BASELINE_LEADING, GridBagConstraints.HORIZONTAL);

    //-- Point list
    TablePoints = new javax.swing.JTable();
    TablePoints.setModel(tablemodel);//new ParamPointsModel(param));
    TablePoints.getTableHeader().setReorderingAllowed(false);
    TablePoints.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            //            TableMainMouseClicked(evt);
        }
    });
    TablePoints.addKeyListener(new java.awt.event.KeyAdapter() {
        public void keyReleased(java.awt.event.KeyEvent evt) {
            //            TableMainKeyReleased(evt);
        }
    });

    jScrollPanePoint = new javax.swing.JScrollPane();
    jScrollPanePoint.setViewportView(TablePoints);
    Utils.addComponent(paneGlobal, jScrollPanePoint, 2, 3, 2, 1, 0.5, 0, 0, 0, 0, 0,
            GridBagConstraints.BASELINE_LEADING, GridBagConstraints.BOTH);

    //-- Edit toolbar
    CreateEditToolbar();
    Utils.addComponent(paneGlobal, ToolBarEdit, 4, 3, 1, 1, 0, 0, 0, 0, 0, 0,
            GridBagConstraints.BASELINE_LEADING, GridBagConstraints.BOTH);

    jPanelProfilChart = new ChartPanel(chart);
    Utils.addComponent(paneGlobal, jPanelProfilChart, 5, 3, 1, 1, 1, 0, 0, 0, 0, 10,
            GridBagConstraints.BASELINE_LEADING, GridBagConstraints.BOTH);
    CrosshairOverlay crosshairOverlay = new CrosshairOverlay();
    xCrosshair = new Crosshair(Double.NaN, Color.DARK_GRAY, new BasicStroke(0f));
    xCrosshair.setLabelVisible(true);
    xCrosshair.setLabelBackgroundPaint(Color.WHITE);

    yCrosshair = new Crosshair(Double.NaN, Color.DARK_GRAY, new BasicStroke(0f));
    yCrosshair.setLabelVisible(true);
    yCrosshair.setLabelBackgroundPaint(Color.WHITE);

    crosshairOverlay.addDomainCrosshair(xCrosshair);
    crosshairOverlay.addRangeCrosshair(yCrosshair);

    jPanelProfilChart.addOverlay(crosshairOverlay);
    jPanelProfilChart.setBackground(new java.awt.Color(255, 0, 51));
    jPanelProfilChart.addChartMouseListener(new ChartMouseListener() {
        @Override
        public void chartMouseClicked(ChartMouseEvent event) {

            ChartEntity chartentity = event.getEntity();
            if (chartentity instanceof XYItemEntity) {
                XYItemEntity e = (XYItemEntity) chartentity;
                XYDataset d = e.getDataset();
                int s = e.getSeriesIndex();
                int i = e.getItem();
                double x = d.getXValue(s, i);
                double y = d.getYValue(s, i);
                xCrosshair.setValue(x);
                yCrosshair.setValue(y);
            }
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent event) {
        }
    });

    // == Bottom button
    // ===========================================================
    btOk = new javax.swing.JButton();
    btOk.setText(bundle.getString("frmEditCurve.btOk.text"));
    btOk.setIcon(new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/valid.png")));
    btOk.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            RequestToClose();
        }
    });
    Utils.addComponent(paneGlobal, btOk, 0, 5, GridBagConstraints.REMAINDER, 1, 0, 0, 10, 0, 10, 0,
            GridBagConstraints.CENTER, GridBagConstraints.NONE);

    // --
    pack();

    //-- Refresh the curve list
    RefreshCurveList();

    //-- Center the windows
    setLocationRelativeTo(null);
}

From source file:gda.plots.SimpleXYItemRenderer.java

/**
 * Draws the visual representation of a single data item. This mostly reproduces the code of StandardXYItemRenderer
 * but using the line by line information stored in the SimpleXYSeries instead of the series indexed information
 * stored in the Renderer itself.//from  w  w w  . j a  va2 s  .  c om
 * 
 * @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) {
    SimpleXYSeries sxys = (SimpleXYSeries) ((SimpleXYSeriesCollection) dataset).getSeries(series);

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

    PlotOrientation orientation = plot.getOrientation();
    g2.setPaint(sxys.getPaint());
    g2.setStroke(sxys.getStroke());

    // get the data point
    double x1 = dataset.getXValue(series, item);
    double y1 = dataset.getYValue(series, item);

    // Test
    x1 = xValueTransformer.transformValue(x1);

    if (Double.isNaN(x1) || Double.isNaN(y1)) {
        return;
    }

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

    if (sxys.isDrawLines()) {
        if (item > 0) {
            // get the previous data point...
            double x0 = dataset.getXValue(series, item - 1);
            double y0 = dataset.getYValue(series, item - 1);

            // Test
            // System.out.print("tranformed " + x0);
            x0 = xValueTransformer.transformValue(x0);
            // Message.debug(" to " + x0);
            if (!Double.isNaN(x0) && !Double.isNaN(y0)) {
                boolean drawLine = true;
                if (getPlotDiscontinuous()) {
                    // only draw a line if the gap between the current and
                    // previous data
                    // point is within the threshold
                    int numX = dataset.getItemCount(series);
                    double minX = dataset.getXValue(series, 0);
                    double maxX = dataset.getXValue(series, numX - 1);
                    drawLine = (x1 - x0) <= ((maxX - minX) / numX * getGapThreshold());
                }
                if (drawLine) {
                    double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
                    double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation);

                    // only draw if we have good values
                    if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1)
                            || Double.isNaN(transY1)) {
                        return;
                    }

                    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)) {
                        g2.draw(state.workingLine);
                    }
                }
            }
        }
    }

    if (sxys.isDrawMarkers()) {

        Shape shape = sxys.getSymbol();
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1);
        } else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1);
        }
        if (shape.intersects(dataArea)) {
            g2.setPaint(sxys.getSymbolPaint());
            // Always use full stroke for drawing marker
            g2.setStroke(new BasicStroke());
            if (sxys.getFilled()) {
                g2.fill(shape);
            } else {
                g2.draw(shape);
            }
            g2.setPaint(sxys.getPaint());
            g2.setStroke(sxys.getStroke());
        }
        entityArea = shape;

    }

    if (getPlotImages()) {
        // use shape scale with transform??
        // double scale = getShapeScale(plot, series, item, transX1,
        // transY1);
        Image image = getImage(plot, series, item, transX1, transY1);
        if (image != null) {
            Point hotspot = getImageHotspot(plot, series, item, transX1, transY1, image);
            g2.drawImage(image, (int) (transX1 - hotspot.getX()), (int) (transY1 - hotspot.getY()), null);
            entityArea = new Rectangle2D.Double(transX1 - hotspot.getX(), transY1 - hotspot.getY(),
                    image.getWidth(null), image.getHeight(null));
        }

    }

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

    updateCrosshairValues(crosshairState, x1, y1, transX1, transY1, orientation);

    // add an entity for the item...
    if (entities != null) {
        addEntity(entities, entityArea, dataset, series, item, transX1, transY1);
    }

}

From source file:com.rapidminer.gui.plotter.charts.MultipleScatterPlotter.java

@Override
public void updatePlotter() {

    prepareData();/*from   ww  w . j av a 2  s . c o  m*/

    JFreeChart chart = ChartFactory.createScatterPlot(null, // chart title
            null, // domain axis label
            null, // range axis label
            dataSet, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips
            false // URLs
    );

    if (xAxis >= 0) {
        int size = dataSet.getSeriesCount();
        chart = ChartFactory.createScatterPlot(null, // chart title
                null, // domain axis label
                null, // range axis label
                dataSet, // data
                PlotOrientation.VERTICAL, // orientation
                true, // include legend
                true, // tooltips
                false // URLs
        );

        // renderer settings
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) chart.getXYPlot().getRenderer();
        renderer.setBaseOutlinePaint(Color.BLACK);
        renderer.setUseOutlinePaint(true);
        renderer.setDrawOutlines(true);

        for (int i = 0; i < size; i++) {
            renderer.setSeriesShapesVisible(i, this.showPoints[plotIndexToColumnIndexMap.get(i)]);
            renderer.setSeriesLinesVisible(i, this.showLines[plotIndexToColumnIndexMap.get(i)]);
        }

        renderer.setSeriesShape(0, new Ellipse2D.Double(-3, -3, 7, 7));

        // legend settings
        LegendTitle legend = chart.getLegend();
        if (legend != null) {
            legend.setPosition(RectangleEdge.TOP);
            legend.setFrame(BlockBorder.NONE);
            legend.setHorizontalAlignment(HorizontalAlignment.LEFT);
            legend.setItemFont(LABEL_FONT);
        }
    }

    // GENERAL CHART SETTINGS

    int size = dataSet.getSeriesCount();
    if (size <= 1) {
        chart.getXYPlot().getRenderer().setSeriesPaint(0, getColorProvider().getPointColor(1.0d));
    } else {
        for (int i = 0; i < dataSet.getSeriesCount(); i++) {
            chart.getXYPlot().getRenderer().setSeriesStroke(i,
                    new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
            chart.getXYPlot().getRenderer().setSeriesPaint(i,
                    getColorProvider().getPointColor(i / (double) (dataSet.getSeriesCount() - 1)));
        }
    }

    // set the background colors for the chart...
    chart.setBackgroundPaint(Color.WHITE);
    chart.getPlot().setBackgroundPaint(Color.WHITE);
    chart.setAntiAlias(false);

    // general plot settings
    XYPlot plot = chart.getXYPlot();
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);

    // domain axis
    if (xAxis >= 0) {
        if (dataTable.isNominal(xAxis)) {
            String[] values = new String[dataTable.getNumberOfValues(xAxis)];
            for (int i = 0; i < values.length; i++) {
                values[i] = dataTable.mapIndex(xAxis, i);
            }
            plot.setDomainAxis(new SymbolAxis(dataTable.getColumnName(xAxis), values));
        } else if ((dataTable.isDate(xAxis)) || (dataTable.isDateTime(xAxis))) {
            DateAxis domainAxis = new DateAxis(dataTable.getColumnName(xAxis));
            domainAxis.setTimeZone(Tools.getPreferredTimeZone());
            plot.setDomainAxis(domainAxis);
        } else {
            if (xLogScale) {
                LogAxis domainAxis = new LogAxis(dataTable.getColumnName(xAxis));
                domainAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits(Locale.US));
                plot.setDomainAxis(domainAxis);
            } else {
                NumberAxis domainAxis = new NumberAxis(dataTable.getColumnName(xAxis));
                domainAxis.setAutoRangeStickyZero(false);
                domainAxis.setAutoRangeIncludesZero(false);
                plot.setDomainAxis(domainAxis);
            }
        }
    }
    plot.getDomainAxis().setLabelFont(LABEL_FONT_BOLD);
    plot.getDomainAxis().setTickLabelFont(LABEL_FONT);

    // rotate labels
    if (isLabelRotating()) {
        plot.getDomainAxis().setTickLabelsVisible(true);
        plot.getDomainAxis().setVerticalTickLabels(true);
    }

    // range axis
    plot.getRangeAxis().setLabelFont(LABEL_FONT_BOLD);
    plot.getRangeAxis().setTickLabelFont(LABEL_FONT);

    // Chart Panel Settings
    if (panel instanceof AbstractChartPanel) {
        panel.setChart(chart);
    } else {
        panel = new AbstractChartPanel(chart, getWidth(), getHeight() - MARGIN);

        final ChartPanelShiftController controller = new ChartPanelShiftController(panel);
        panel.addMouseListener(controller);
        panel.addMouseMotionListener(controller);

        // react to mouse clicks
        // ATTENTION: ACTIVATING THIS WILL LEAD TO SEVERE MEMORY LEAKS!!! (see below)
        panel.addChartMouseListener(new ChartMouseListener() {

            @Override
            public void chartMouseClicked(ChartMouseEvent e) {
                if (e.getTrigger().getClickCount() > 1) {
                    XYItemEntity entity = (XYItemEntity) e.getEntity();
                    if (entity != null) {
                        String id = idMap.get(new SeriesAndItem(entity.getSeriesIndex(), entity.getItem()));
                        if (id != null) {
                            ObjectVisualizer visualizer = ObjectVisualizerService
                                    .getVisualizerForObject(dataTable);
                            visualizer.startVisualization(id);
                        }
                    }
                }
            }

            @Override
            public void chartMouseMoved(ChartMouseEvent e) {
            }
        });
    }

    // tooltips
    class CustomXYToolTipGenerator implements XYToolTipGenerator {

        public CustomXYToolTipGenerator() {
        }

        @Override
        public String generateToolTip(XYDataset dataset, int row, int column) {
            String id = idMap.get(new SeriesAndItem(row, column));
            if (id != null) {
                return "<html><b>Id: " + id + "</b> (" + dataset.getSeriesKey(row) + ", "
                        + Tools.formatIntegerIfPossible(dataset.getXValue(row, column)) + ", "
                        + Tools.formatIntegerIfPossible(dataset.getYValue(row, column)) + ")</html>";
            } else {
                return "<html>(" + dataset.getSeriesKey(row) + ", "
                        + Tools.formatIntegerIfPossible(dataset.getXValue(row, column)) + ", "
                        + Tools.formatIntegerIfPossible(dataset.getYValue(row, column)) + ")</html>";
            }
        }
    }

    for (int i = 0; i < dataSet.getSeriesCount(); i++) {
        plot.getRenderer().setSeriesToolTipGenerator(i, new CustomXYToolTipGenerator());
    }
}

From source file:gov.llnl.lc.infiniband.opensm.plugin.gui.chart.AdvancedXY_PlotPanel.java

@Override
public void chartProgress(ChartProgressEvent event) {
    if (event.getType() != ChartProgressEvent.DRAWING_FINISHED) {
        return;//  w  w  w .  j  a va  2  s.  c  o  m
    }

    // update the table model

    if (this.chartPanel != null) {
        JFreeChart c = this.getChart();
        if (c != null) {
            XYPlot plot = (XYPlot) c.getPlot();

            int ndex = this.getCrossHairDomainIndex();

            // update the table from the value at the crosshair

            for (int pnum = 0; pnum < NumDataSets; pnum++) {
                XYDataset dataset = plot.getDataset(pnum);
                String seriesName = "Unknown";
                if ((dataset != null) && (dataset.getSeriesKey(0) != null)) {
                    int ds_size = dataset.getItemCount(0);
                    if (dataset.getSeriesKey(0) instanceof String)
                        seriesName = (String) dataset.getSeriesKey(0);

                    // the name
                    this.model.setValueAt(seriesName, pnum, 0);

                    // the deltas are one smaller than the counters, so make sure the
                    // crosshair index is valid
                    if (ndex < ds_size) {
                        // the time
                        this.model.setValueAt(dataset.getXValue(0, ndex), pnum, 1);

                        // the value
                        this.model.setValueAt(dataset.getYValue(0, ndex), pnum, 2);
                    }

                    // the units (key off the series name)
                    PortCounterAxisLabel label = PortCounterAxisLabel.getByName(seriesName);
                    if (label != null)
                        this.model.setValueAt(label.getUnits(), pnum, 3);
                    else
                        this.model.setValueAt(PortCounterAxisLabel.DELTA.getUnits(), pnum, 3);
                }
            }
        } else
            System.err.println("Its NULL, Jim!");
    }
}

From source file:de.saring.util.gui.jfreechart.StackedRenderer.java

/**
 * Draws the visual representation of a single data item.
 *
 * @param g2 the graphics device./*w w  w.j av  a2s.c om*/
 * @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 information about crosshairs on a plot.
 * @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) {

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

    TableXYDataset tdataset = (TableXYDataset) dataset;

    // get the data point...
    double x1 = dataset.getXValue(series, item);
    double y1 = dataset.getYValue(series, item);
    if (Double.isNaN(y1)) {
        y1 = 0.0;
    }
    double[] stack1 = getStackValues(tdataset, series, item);

    // get the previous point and the next point so we can calculate a 
    // "hot spot" for the area (used by the chart entity)...
    double x0 = dataset.getXValue(series, Math.max(item - 1, 0));
    double y0 = dataset.getYValue(series, Math.max(item - 1, 0));
    if (Double.isNaN(y0)) {
        y0 = 0.0;
    }
    double[] stack0 = getStackValues(tdataset, series, Math.max(item - 1, 0));

    int itemCount = dataset.getItemCount(series);
    double x2 = dataset.getXValue(series, Math.min(item + 1, itemCount - 1));
    double y2 = dataset.getYValue(series, Math.min(item + 1, itemCount - 1));
    if (Double.isNaN(y2)) {
        y2 = 0.0;
    }
    double[] stack2 = getStackValues(tdataset, series, Math.min(item + 1, itemCount - 1));

    double xleft = (x0 + x1) / 2.0;
    double xright = (x1 + x2) / 2.0;
    double[] stackLeft = averageStackValues(stack0, stack1);
    double[] stackRight = averageStackValues(stack1, stack2);
    double[] adjStackLeft = adjustedStackValues(stack0, stack1);
    double[] adjStackRight = adjustedStackValues(stack1, stack2);

    RectangleEdge edge0 = plot.getDomainAxisEdge();

    float transX1 = (float) domainAxis.valueToJava2D(x1, dataArea, edge0);
    float transXLeft = (float) domainAxis.valueToJava2D(xleft, dataArea, edge0);
    float transXRight = (float) domainAxis.valueToJava2D(xright, dataArea, edge0);

    if (this.roundXCoordinates) {
        transX1 = Math.round(transX1);
        transXLeft = Math.round(transXLeft);
        transXRight = Math.round(transXRight);
    }
    float transY1;

    RectangleEdge edge1 = plot.getRangeAxisEdge();

    GeneralPath left = new GeneralPath();
    GeneralPath right = new GeneralPath();
    if (y1 >= 0.0) { // handle positive value
        transY1 = (float) rangeAxis.valueToJava2D(y1 + stack1[1], dataArea, edge1);
        float transStack1 = (float) rangeAxis.valueToJava2D(stack1[1], dataArea, edge1);
        float transStackLeft = (float) rangeAxis.valueToJava2D(stackLeft[1], dataArea, edge1); // other than StackedXYAreaRenderer2!

        // LEFT POLYGON
        if (y0 >= 0.0) {
            double yleft = (y0 + y1) / 2.0 + stackLeft[1];
            float transYLeft = (float) rangeAxis.valueToJava2D(yleft, dataArea, edge1);
            left.moveTo(transX1, transY1);
            left.lineTo(transX1, transStack1);
            left.lineTo(transXLeft, transStackLeft);
            left.lineTo(transXLeft, transYLeft);
            left.closePath();
        } else {
            left.moveTo(transX1, transStack1);
            left.lineTo(transX1, transY1);
            left.lineTo(transXLeft, transStackLeft);
            left.closePath();
        }

        float transStackRight = (float) rangeAxis.valueToJava2D(stackRight[1], dataArea, edge1); // other than StackedXYAreaRenderer2!
        // RIGHT POLYGON
        if (y2 >= 0.0) {
            double yright = (y1 + y2) / 2.0 + stackRight[1];
            float transYRight = (float) rangeAxis.valueToJava2D(yright, dataArea, edge1);
            right.moveTo(transX1, transStack1);
            right.lineTo(transX1, transY1);
            right.lineTo(transXRight, transYRight);
            right.lineTo(transXRight, transStackRight);
            right.closePath();
        } else {
            right.moveTo(transX1, transStack1);
            right.lineTo(transX1, transY1);
            right.lineTo(transXRight, transStackRight);
            right.closePath();
        }
    } else { // handle negative value
        transY1 = (float) rangeAxis.valueToJava2D(y1 + stack1[0], dataArea, edge1);
        float transStack1 = (float) rangeAxis.valueToJava2D(stack1[0], dataArea, edge1);
        float transStackLeft = (float) rangeAxis.valueToJava2D(adjStackLeft[0], dataArea, edge1);

        // LEFT POLYGON
        if (y0 >= 0.0) {
            left.moveTo(transX1, transStack1);
            left.lineTo(transX1, transY1);
            left.lineTo(transXLeft, transStackLeft);
            left.clone();
        } else {
            double yleft = (y0 + y1) / 2.0 + stackLeft[0];
            float transYLeft = (float) rangeAxis.valueToJava2D(yleft, dataArea, edge1);
            left.moveTo(transX1, transY1);
            left.lineTo(transX1, transStack1);
            left.lineTo(transXLeft, transStackLeft);
            left.lineTo(transXLeft, transYLeft);
            left.closePath();
        }
        float transStackRight = (float) rangeAxis.valueToJava2D(adjStackRight[0], dataArea, edge1);

        // RIGHT POLYGON
        if (y2 >= 0.0) {
            right.moveTo(transX1, transStack1);
            right.lineTo(transX1, transY1);
            right.lineTo(transXRight, transStackRight);
            right.closePath();
        } else {
            double yright = (y1 + y2) / 2.0 + stackRight[0];
            float transYRight = (float) rangeAxis.valueToJava2D(yright, dataArea, edge1);
            right.moveTo(transX1, transStack1);
            right.lineTo(transX1, transY1);
            right.lineTo(transXRight, transYRight);
            right.lineTo(transXRight, transStackRight);
            right.closePath();
        }
    }

    //  Get series Paint and Stroke
    Paint itemPaint = getItemPaint(series, item);
    if (pass == 0) {
        g2.setPaint(itemPaint);
        g2.fill(left);
        g2.fill(right);
    } else if (pass == 1) {
        if (item == 0 || (y1 == 0.0 && y0 == 0.0)) {
            return;
        }

        // get the data point...
        if (Double.isNaN(y1) || Double.isNaN(x1)) {
            return;
        }

        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 + stack0[1], dataArea, yAxisLocation);

        // only draw if we have good values
        if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1) || Double.isNaN(transY1)) {
            return;
        }

        state.workingLine.setLine(transX0, transY0, transX1, transY1);

        if (state.workingLine.intersects(dataArea)) {
            g2.setStroke(getItemStroke(series, item));
            g2.setPaint(super.lookupSeriesPaint(series));
            g2.draw(state.workingLine);
        }

        return;
    }

    // add an entity for the item...
    if (entities != null) {
        GeneralPath gp = new GeneralPath(left);
        gp.append(right, false);
        entityArea = gp;
        addEntity(entities, entityArea, dataset, series, item, transX1, transY1);
    }

}

From source file:net.sf.mzmine.modules.visualization.spectra.renderers.SpectraItemLabelGenerator.java

/**
 * @see org.jfree.chart.labels.XYItemLabelGenerator#generateLabel(org.jfree.data.xy.XYDataset,
 *      int, int)//  ww w .  j a  v  a2  s  . c o  m
 */
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;

}

From source file:net.sf.mzmine.modules.visualization.metamsecorrelate.visual.pseudospectra.PseudoSpectraItemLabelGenerator.java

/**
 * @see org.jfree.chart.labels.XYItemLabelGenerator#generateLabel(org.jfree.data.xy.XYDataset,
 *      int, int)/*from  www.  j ava2  s. c om*/
 */
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.getChart().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 PseudoSpectrumDataSet) {
        double mzValue = dataset.getXValue(series, item);
        label = mzFormat.format(mzValue);
        String ann = ((PseudoSpectrumDataSet) dataset).getAnnotation(item);
        if (ann != null)
            label = label + "\n" + ann;
        return label;
    }
    if (label == null) {
        double mzValue = dataset.getXValue(series, item);
        label = mzFormat.format(mzValue);
    }

    return label;

}

From source file:org.rdv.viz.chart.FastXYItemRenderer.java

@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) {

    boolean itemVisible = getItemVisible(series, item);

    // setup for collecting optional entity info...
    Shape entityArea = null;//from w w  w. j  a v  a  2s  .  c  om
    EntityCollection entities = null;
    if (info != null) {
        entities = info.getOwner().getEntityCollection();
    }

    PlotOrientation orientation = plot.getOrientation();
    Paint paint = getItemPaint(series, item);
    Stroke seriesStroke = getItemStroke(series, item);
    g2.setPaint(paint);
    g2.setStroke(seriesStroke);

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

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

    if (getPlotLines()) {
        if (item == 0) {
            previousDrawnItem = 1;
        }

        if (getDrawSeriesLineAsPath()) {
            State s = (State) state;
            if (s.getSeriesIndex() != series) {
                // we are starting a new series path
                s.seriesPath.reset();
                s.setLastPointGood(false);
                s.setSeriesIndex(series);
            }

            // update path to reflect latest point
            if (itemVisible && !Double.isNaN(transX1) && !Double.isNaN(transY1)) {
                float x = (float) transX1;
                float y = (float) transY1;
                if (orientation == PlotOrientation.HORIZONTAL) {
                    x = (float) transY1;
                    y = (float) transX1;
                }
                if (s.isLastPointGood()) {
                    // TODO: check threshold
                    s.seriesPath.lineTo(x, y);
                } else {
                    s.seriesPath.moveTo(x, y);
                }
                s.setLastPointGood(true);
            } else {
                s.setLastPointGood(false);
            }
            if (item == dataset.getItemCount(series) - 1) {
                if (s.getSeriesIndex() == series) {
                    // draw path
                    g2.setStroke(lookupSeriesStroke(series));
                    g2.setPaint(lookupSeriesPaint(series));
                    g2.draw(s.seriesPath);
                }
            }
        }

        else if (item != 0 && itemVisible) {
            // get the previous data point...
            double x0 = dataset.getXValue(series, item - previousDrawnItem);
            double y0 = dataset.getYValue(series, item - previousDrawnItem);
            if (!Double.isNaN(x0) && !Double.isNaN(y0)) {
                boolean drawLine = true;
                if (getPlotDiscontinuous()) {
                    // only draw a line if the gap between the current and
                    // previous data point is within the threshold
                    int numX = dataset.getItemCount(series);
                    double minX = dataset.getXValue(series, 0);
                    double maxX = dataset.getXValue(series, numX - 1);
                    if (getGapThresholdType() == UnitType.ABSOLUTE) {
                        drawLine = Math.abs(x1 - x0) <= getGapThreshold();
                    } else {
                        drawLine = Math.abs(x1 - x0) <= ((maxX - minX) / numX * getGapThreshold());
                    }
                }
                if (drawLine) {
                    double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
                    double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation);

                    // only draw if we have good values
                    if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1)
                            || Double.isNaN(transY1)) {
                        return;
                    }

                    // Only draw line if it is more than a pixel away from the
                    // previous one
                    if ((transX1 - transX0 > 2 || transX1 - transX0 < -2 || transY1 - transY0 > 2
                            || transY1 - transY0 < -2)) {
                        previousDrawnItem = 1;

                        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)) {
                            g2.draw(state.workingLine);
                        }
                    } else {
                        // Increase counter for the previous drawn item.
                        previousDrawnItem++;
                    }
                }
            }
        }
    }

    // we needed to get this far even for invisible items, to ensure that
    // seriesPath updates happened, but now there is nothing more we need
    // to do for non-visible items...
    if (!itemVisible) {
        return;
    }

    // add a cursor to indicate the position of the last data item
    if (getCursorVisible() && item == dataset.getItemCount(series) - 1) {
        Line2D cursorX = new Line2D.Double(transX1 - DEFAULT_CURSOR_SIZE, transY1,
                transX1 + DEFAULT_CURSOR_SIZE, transY1);
        g2.draw(cursorX);
        Line2D cursorY = new Line2D.Double(transX1, transY1 - DEFAULT_CURSOR_SIZE, transX1,
                transY1 + DEFAULT_CURSOR_SIZE);
        g2.draw(cursorY);
    }

    if (getBaseShapesVisible()) {

        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);
        }
        if (shape.intersects(dataArea)) {
            if (getItemShapeFilled(series, item)) {
                g2.fill(shape);
            } else {
                g2.draw(shape);
            }
        }
        entityArea = shape;

    }

    if (getPlotImages()) {
        Image image = getImage(plot, series, item, transX1, transY1);
        if (image != null) {
            Point hotspot = getImageHotspot(plot, series, item, transX1, transY1, image);
            g2.drawImage(image, (int) (transX1 - hotspot.getX()), (int) (transY1 - hotspot.getY()), null);
            entityArea = new Rectangle2D.Double(transX1 - hotspot.getX(), transY1 - hotspot.getY(),
                    image.getWidth(null), image.getHeight(null));
        }

    }

    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...
    if (entities != null && dataArea.contains(xx, yy)) {
        addEntity(entities, entityArea, dataset, series, item, xx, yy);
    }
}

From source file:msi.gama.outputs.layers.charts.FastXYItemRenderer.java

/** {@inheritDoc} */
@Override/*from   w ww .  ja  v  a2  s . c  om*/
public void drawItem(final Graphics2D g2, final XYItemRendererState state, final Rectangle2D dataArea,
        final PlotRenderingInfo info, final XYPlot plot, final ValueAxis domainAxis, final ValueAxis rangeAxis,
        final XYDataset dataset, final int series, final int item, final CrosshairState crosshairState,
        final int pass) {

    if (!getItemVisible(series, item)) {
        return;
    }
    // setup for collecting optional entity info...
    boolean bAddEntity = false;
    Shape entityArea = null;
    EntityCollection entities = null;
    if (info != null) {
        entities = info.getOwner().getEntityCollection();
    }

    final PlotOrientation orientation = plot.getOrientation();
    final Paint paint = getItemPaint(series, item);
    final Stroke seriesStroke = getItemStroke(series, item);
    g2.setPaint(paint);
    g2.setStroke(seriesStroke);

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

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

    if (getPlotLines()) {
        if (item == 0) {
            if (this.drawSeriesLineAsPath) {
                final State s = (State) state;
                s.seriesPath.reset();
                s.lastPointGood = false;
            }
            previousDrawnItem = 0;
        }

        if (this.drawSeriesLineAsPath) {
            final 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;
                if (orientation == PlotOrientation.HORIZONTAL) {
                    x = (float) transY1;
                    y = (float) transX1;
                }
                if (s.isLastPointGood()) {
                    // TODO: check threshold
                    s.seriesPath.lineTo(x, y);
                } else {
                    s.seriesPath.moveTo(x, y);
                }
                s.setLastPointGood(true);
            } else {
                s.setLastPointGood(false);
            }
            if (item == dataset.getItemCount(series) - 1) {
                // draw path
                g2.setStroke(getSeriesStroke(series));
                g2.setPaint(getSeriesPaint(series));
                g2.draw(s.seriesPath);
            }
        }

        else if (item != 0) {
            // get the previous data point...
            final double x0 = dataset.getXValue(series, item - previousDrawnItem);
            final double y0 = dataset.getYValue(series, item - previousDrawnItem);
            if (!Double.isNaN(x0) && !Double.isNaN(y0)) {
                boolean drawLine = true;
                if (getPlotDiscontinuous()) {
                    // only draw a line if the gap between the current and
                    // previous data point is within the threshold
                    final int numX = dataset.getItemCount(series);
                    final double minX = dataset.getXValue(series, 0);
                    final double maxX = dataset.getXValue(series, numX - 1);
                    if (this.gapThresholdType == UnitType.ABSOLUTE) {
                        drawLine = Math.abs(x1 - x0) <= this.gapThreshold;
                    } else {
                        drawLine = Math.abs(x1 - x0) <= (maxX - minX) / numX * getGapThreshold();
                    }
                }
                if (drawLine) {
                    final double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
                    final double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation);

                    // only draw if we have good values
                    if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1)
                            || Double.isNaN(transY1)) {
                        return;
                    }

                    // Only draw line if it is more than a pixel away from the previous one
                    if (transX1 - transX0 > 2 || transX1 - transX0 < -2 || transY1 - transY0 > 2
                            || transY1 - transY0 < -2 || 0 == previousDrawnItem) {
                        previousDrawnItem = 1;

                        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)) {
                            g2.draw(state.workingLine);
                        }
                    } else {
                        // Increase counter for the previous drawn item.
                        previousDrawnItem++;
                        bAddEntity = false;
                    }
                }
            }
        }
    }

    if (getBaseShapesVisible()) {

        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);
        }
        if (shape.intersects(dataArea)) {
            bAddEntity = true;
            if (getItemShapeFilled(series, item)) {
                g2.fill(shape);
            } else {
                g2.draw(shape);
            }
        }
        entityArea = shape;

    }

    if (getPlotImages()) {
        final Image image = getImage(plot, series, item, transX1, transY1);
        if (image != null) {
            final Point hotspot = getImageHotspot(plot, series, item, transX1, transY1, image);
            g2.drawImage(image, (int) (transX1 - hotspot.getX()), (int) (transY1 - hotspot.getY()), null);
            entityArea = new Rectangle2D.Double(transX1 - hotspot.getX(), transY1 - hotspot.getY(),
                    image.getWidth(null), image.getHeight(null));
        }

    }

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

    updateCrosshairValues(crosshairState, x1, y1, transX1, transY1, orientation);

    // add an entity for the item...
    if (entities != null && bAddEntity) {
        addEntity(entities, entityArea, dataset, series, item, transX1, transY1);
    }
}