Example usage for org.jfree.chart.plot XYPlot getDomainAxisEdge

List of usage examples for org.jfree.chart.plot XYPlot getDomainAxisEdge

Introduction

In this page you can find the example usage for org.jfree.chart.plot XYPlot getDomainAxisEdge.

Prototype

public RectangleEdge getDomainAxisEdge() 

Source Link

Document

Returns the edge for the primary domain axis (taking into account the plot's orientation).

Usage

From source file:net.sf.maltcms.chromaui.annotations.PeakAnnotationRenderer.java

private void drawOutline(Shape entity, Graphics2D g2, Color fill, Color stroke, ChartPanel chartPanel,
        boolean scale, float alpha) {
    if (entity != null) {
        //System.out.println("Drawing entity with bbox: "+entity.getBounds2D());
        Shape savedClip = g2.getClip();
        Rectangle2D dataArea = chartPanel.getScreenDataArea();
        Color c = g2.getColor();/*from   w  ww. ja va 2 s .co  m*/
        Composite comp = g2.getComposite();
        g2.clip(dataArea);
        g2.setColor(fill);
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        JFreeChart chart = chartPanel.getChart();
        XYPlot plot = (XYPlot) chart.getPlot();
        ValueAxis xAxis = plot.getDomainAxis();
        ValueAxis yAxis = plot.getRangeAxis();
        RectangleEdge xAxisEdge = plot.getDomainAxisEdge();
        RectangleEdge yAxisEdge = plot.getRangeAxisEdge();
        Rectangle2D entityBounds = entity.getBounds2D();
        double viewX = xAxis.valueToJava2D(entityBounds.getCenterX(), dataArea, xAxisEdge);
        double viewY = yAxis.valueToJava2D(entityBounds.getCenterY(), dataArea, yAxisEdge);
        double viewW = xAxis.lengthToJava2D(entityBounds.getWidth(), dataArea, xAxisEdge);
        double viewH = yAxis.lengthToJava2D(entityBounds.getHeight(), dataArea, yAxisEdge);
        PlotOrientation orientation = plot.getOrientation();

        //transform model to origin (0,0) in model coordinates
        AffineTransform toOrigin = AffineTransform.getTranslateInstance(-entityBounds.getCenterX(),
                -entityBounds.getCenterY());
        //transform from origin (0,0) to model location
        AffineTransform toModelLocation = AffineTransform.getTranslateInstance(entityBounds.getCenterX(),
                entityBounds.getCenterY());
        //transform from model scale to view scale
        double scaleX = viewW / entityBounds.getWidth();
        double scaleY = viewH / entityBounds.getHeight();
        Logger.getLogger(getClass().getName()).log(Level.FINE, "Scale x: {0} Scale y: {1}",
                new Object[] { scaleX, scaleY });
        AffineTransform toViewScale = AffineTransform.getScaleInstance(scaleX, scaleY);
        AffineTransform toViewLocation = AffineTransform.getTranslateInstance(viewX, viewY);
        AffineTransform flipTransform = AffineTransform.getScaleInstance(1.0f, -1.0f);
        AffineTransform modelToView = new AffineTransform(toOrigin);
        modelToView.preConcatenate(flipTransform);
        modelToView.preConcatenate(toViewScale);
        modelToView.preConcatenate(toViewLocation);
        //
        //            if (orientation == PlotOrientation.HORIZONTAL) {
        //                entity = ShapeUtilities.createTranslatedShape(entity, viewY,
        //                        viewX);
        //            } else if (orientation == PlotOrientation.VERTICAL) {
        //                entity = ShapeUtilities.createTranslatedShape(entity, viewX,
        //                        viewY);
        //            }
        FlatteningPathIterator iter = new FlatteningPathIterator(modelToView.createTransformedShape(entity)
                .getPathIterator(AffineTransform.getTranslateInstance(0, 0)), 5);
        Path2D.Float path = new Path2D.Float();
        path.append(iter, false);

        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
        g2.fill(path);
        if (stroke != null) {
            g2.setColor(stroke);
            g2.draw(path);
        }
        g2.setComposite(comp);
        g2.setColor(c);
        g2.setClip(savedClip);
    } else {
        Logger.getLogger(getClass().getName()).info("Entity is null!");
    }
}

From source file:org.griphyn.vdl.karajan.monitor.monitors.swing.GraphPanel.java

private double valueFromPosition(ChartMouseEvent e) {
    Rectangle2D chartArea = cp.getScreenDataArea();
    XYPlot plot = chart.getXYPlot();
    return plot.getDomainAxis().java2DToValue(e.getTrigger().getX(), chartArea, plot.getDomainAxisEdge());
}

From source file:com.vgi.mafscaling.LogPlay.java

private void createPlayer(JPanel panel) {
    playerPanel = new JPanel();
    GridBagLayout gbl_playerPanel = new GridBagLayout();
    gbl_playerPanel.columnWidths = new int[] { 0, 0, 0, 0, 0, 0, 0, 0 };
    gbl_playerPanel.rowHeights = new int[] { 0, 0, 0, 0 };
    gbl_playerPanel.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 };
    gbl_playerPanel.rowWeights = new double[] { 0.0, 0.0 };
    playerPanel.setLayout(gbl_playerPanel);

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.insets = insets0;/*from   ww w.  ja va 2 s  .  co m*/
    gbc.anchor = GridBagConstraints.PAGE_START;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.gridx = 0;
    gbc.gridy = 0;

    progressBar = new JSlider(0, 0, 0);
    progressBar.setMinimum(0);
    progressBar.setMaximum(lastRow);
    setProgressBar(logDataTable.getSelectedRow());
    progressBar.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            int row = progressBar.getValue();
            if (playing) {
                if (row == lastRow || (endPlay >= 0 && endPlay < row)) {
                    stop();
                    return;
                }
                if (showMarker) {
                    Rectangle2D dataArea = logView.getChartPanel().getChartRenderingInfo().getPlotInfo()
                            .getDataArea();
                    XYPlot plot = (XYPlot) logView.getChartPanel().getChart().getPlot();
                    double x = plot.getDomainAxis().valueToJava2D(row, dataArea, plot.getDomainAxisEdge());
                    boolean isLeft = (x < (dataArea.getMaxX() - dataArea.getMinX()) / 2) ? true : false;
                    logView.setMarkers(row, isLeft);
                }
            }
            logDataTable.getTable().setRowSelectionInterval(row, row);
            logDataTable.getTable().changeSelection(row, logDataTable.getSelectedColumn(), false, false);
            double x, y, z;
            int origXCol, origYCol, origZCol;
            synchronized (lock) {
                for (TableHolder tableHolder : tables) {
                    try {
                        origXCol = logDataTable.getCurrentIndexForOriginalColumn(tableHolder.xColIdx);
                        origYCol = logDataTable.getCurrentIndexForOriginalColumn(tableHolder.yColIdx);
                        origZCol = logDataTable.getCurrentIndexForOriginalColumn(tableHolder.zColIdx);
                        x = Double.valueOf(logDataTable.getValueAt(row, origXCol).toString());
                        y = Double.valueOf(logDataTable.getValueAt(row, origYCol).toString());
                        if (origZCol > 0)
                            z = Double.valueOf(logDataTable.getValueAt(row, origZCol).toString());
                        else
                            z = Double.NaN;
                        tableHolder.table.setCurrentPoint(x, y, z);
                    } catch (Exception ex) {
                        JOptionPane
                                .showMessageDialog(null,
                                        "Invalid numeric value in column " + (tableHolder.xColIdx + 1)
                                                + ", row " + (row + 1),
                                        "Invalid value", JOptionPane.ERROR_MESSAGE);
                        return;
                    }
                }
            }
        }
    });
    gbc.weightx = 1.0;
    gbc.gridwidth = gbl_playerPanel.columnWidths.length;
    playerPanel.add(progressBar, gbc);

    stopButton = addPlayerButton(0, new ImageIcon(getClass().getResource("/stop.png")));
    rewButton = addPlayerButton(1, new ImageIcon(getClass().getResource("/rew.png")));
    playButton = addPlayerButton(2, playIcon);
    ffwButton = addPlayerButton(3, new ImageIcon(getClass().getResource("/ffw.png")));
    showIntepCells = addCheckBox(4, "Show interpolation cells");
    showSignifCells = addCheckBox(5, "Show significant cell");
    showTraceLine = addCheckBox(6, "Show trace line");
    showTraceMarker = addCheckBox(7, "Show plot trace marker");

    gbc.weightx = 0.0;
    gbc.gridwidth = 0;
    gbc.gridy = 1;
    panel.add(playerPanel, gbc);
}

From source file:org.openfaces.component.chart.impl.renderers.XYLineFillRenderer.java

private double calculateItemXPoint(int series, int item, Rectangle2D dataArea, ValueAxis domainAxis,
        XYDataset dataSet, XYPlot plot) {
    double xValue = dataSet.getXValue(series, item);
    return domainAxis.valueToJava2D(xValue, dataArea, plot.getDomainAxisEdge());
}

From source file:com.newatlanta.bluedragon.CustomXYStepRenderer.java

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) {
    super.drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item,
            crosshairState, pass);/*from  w ww.j a  v  a  2  s. c  om*/

    // draw the item label if there is one...
    if (isItemLabelVisible(series, item)) {
        // get the data point...
        double x1 = dataset.getXValue(series, item);
        double y1 = dataset.getYValue(series, item);
        if (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);

        double xx = transX1;
        double yy = transY1;
        PlotOrientation orientation = plot.getOrientation();
        if (orientation == PlotOrientation.HORIZONTAL) {
            xx = transY1;
            yy = transX1;
        }
        drawItemLabel(g2, orientation, dataset, series, item, xx, yy, (y1 < 0.0));
    }
}

From source file:net.sf.mzmine.chartbasics.ChartLogics.java

/**
 * Translates mouse coordinates to chart coordinates (xy-axis)
 * //from   w w w .  j a  v a  2  s. c o  m
 * @param myChart
 * @param mouseX
 * @param mouseY
 * @return Range as chart coordinates
 * @throws Exception
 */
public static Point2D mouseXYToPlotXY(ChartPanel myChart, int mouseX, int mouseY) throws Exception {
    Point2D p = myChart.translateScreenToJava2D(new Point(mouseX, mouseY));

    XYPlot plot = null;
    // find plot as parent of axis
    ChartEntity entity = findChartEntity(myChart, mouseX, mouseY);
    if (entity instanceof AxisEntity) {
        Axis a = ((AxisEntity) entity).getAxis();
        if (a.getPlot() instanceof XYPlot)
            plot = (XYPlot) a.getPlot();
    }

    ChartRenderingInfo info = myChart.getChartRenderingInfo();
    int subplot = info.getPlotInfo().getSubplotIndex(p);
    Rectangle2D dataArea = info.getPlotInfo().getDataArea();
    if (subplot != -1)
        dataArea = info.getPlotInfo().getSubplotInfo(subplot).getDataArea();

    if (plot == null)
        plot = findXYSubplot(myChart.getChart(), info, p.getX(), p.getY());

    // coordinates
    double cx = 0;
    double cy = 0;
    if (plot != null) {
        // find axis
        ValueAxis domainAxis = plot.getDomainAxis();
        ValueAxis rangeAxis = plot.getRangeAxis();
        RectangleEdge domainAxisEdge = plot.getDomainAxisEdge();
        RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge();
        // parent?
        if (domainAxis == null && plot.getParent() != null && plot.getParent() instanceof XYPlot) {
            XYPlot pp = ((XYPlot) plot.getParent());
            domainAxis = pp.getDomainAxis();
            domainAxisEdge = pp.getDomainAxisEdge();
        }
        if (rangeAxis == null && plot.getParent() != null && plot.getParent() instanceof XYPlot) {
            XYPlot pp = ((XYPlot) plot.getParent());
            rangeAxis = pp.getRangeAxis();
            rangeAxisEdge = pp.getRangeAxisEdge();
        }

        if (domainAxis != null)
            cx = domainAxis.java2DToValue(p.getX(), dataArea, domainAxisEdge);
        if (rangeAxis != null)
            cy = rangeAxis.java2DToValue(p.getY(), dataArea, rangeAxisEdge);
    } else {
        throw new Exception("no xyplot found");
    }
    return new Point2D.Double(cx, cy);

}

From source file:ec.util.chart.swing.Charts.java

@Nullable
public static LegendItemEntity getSeriesForPoint(@Nonnull Point pt, @Nonnull ChartPanel cp) {

    final double chartX;
    final double chartY;
    final Rectangle2D plotArea;
    final XYPlot plot;
    {/* w w  w.ja v a  2s.  co m*/
        // Let's find the X and Y values of the clicked point
        Point2D p = cp.translateScreenToJava2D(pt);
        chartX = p.getX();
        chartY = p.getY();
        // Let's find plotArea and plot
        XYPlot tmpPlot = cp.getChart().getXYPlot();
        PlotRenderingInfo plotInfo = cp.getChartRenderingInfo().getPlotInfo();
        if (tmpPlot instanceof CombinedDomainXYPlot) {
            int subplotIndex = plotInfo.getSubplotIndex(p);
            if (subplotIndex == -1) {
                return null;
            }
            plotArea = plotInfo.getSubplotInfo(subplotIndex).getDataArea();
            plot = ((CombinedDomainXYPlot) tmpPlot).findSubplot(plotInfo, p);
        } else {
            plotArea = plotInfo.getDataArea();
            plot = tmpPlot;
        }
    }

    // Let's avoid unnecessary computation
    final ValueAxis domainAxis = plot.getDomainAxis();
    final ValueAxis rangeAxis = plot.getRangeAxis();
    final RectangleEdge domainAxisEdge = plot.getDomainAxisEdge();
    final RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge();
    final double x = domainAxis.java2DToValue(chartX, plotArea, domainAxisEdge);

    final double sensitivity = TOL;
    double distanceClickSeries = TOL + 1;

    Entry<XYDataset, Comparable> result = null;

    // For each series in each datasets
    for (XYDataset dataset : asDatasetList(plot)) {
        for (int series = 0; series < dataset.getSeriesCount(); series++) {
            // Index of the closest data item of the current series just left to the click
            int lp = getNearestLeftPoint(x, 0, dataset.getItemCount(series) - 1, series, dataset);

            try {
                // X and Y values of data items to the left and to the right
                double leftX = dataset.getXValue(series, lp);
                double leftY = dataset.getYValue(series, lp);
                double rightX = dataset.getXValue(series, lp + 1);
                double rightY = dataset.getYValue(series, lp + 1);

                double lx = domainAxis.valueToJava2D(leftX, plotArea, domainAxisEdge);
                double ly = rangeAxis.valueToJava2D(leftY, plotArea, rangeAxisEdge);
                double rx = domainAxis.valueToJava2D(rightX, plotArea, domainAxisEdge);
                double ry = rangeAxis.valueToJava2D(rightY, plotArea, rangeAxisEdge);

                // Distance to left point
                double distL = Point2D.distance(lx, ly, chartX, chartY);
                // Distance to right point
                double distR = Point2D.distance(rx, ry, chartX, chartY);
                // Average of both distances
                double distLRavg = (distL + distR) / 2d;
                // Distance to the segment between L and R
                //double distSeg = Line2D.ptSegDist(leftX, leftY, rightX, rightY, chartX, chartY);
                double distSeg = ptSegDist(lx, ly, rx, ry, chartX, chartY);

                // With a line renderer, this is probably a bit of overkill as
                // distSeg would be enough, but it becomes more reliable to check all these
                // if using splines
                double tmp = Math.min(Math.min(distSeg, Math.min(distL, distR)), distLRavg);

                // Are we closer than the previous series?
                if (tmp < sensitivity && tmp < distanceClickSeries) {
                    distanceClickSeries = tmp;
                    result = new SimpleEntry<>(dataset, dataset.getSeriesKey(series));
                }
            } catch (Exception ex) {
                /*
                 * An exception might happen when some series have less data
                 * than others, catching the the exception here will simply rule
                 * them out from the detection on this click
                 */
            }
        }
    }

    return result != null ? createFakeLegendItemEntity(result.getKey(), result.getValue()) : null;
}

From source file:no.met.jtimeseries.chart.XYHybridSplineRenderer.java

/**
 * 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//  ww w.j  ava 2 s. c o m
 *            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.
 */
@Override
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 points
    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);

    // collect points
    if (!Double.isNaN(transX1) && !Double.isNaN(transY1)) {
        ControlPoint p = new ControlPoint(
                plot.getOrientation() == PlotOrientation.HORIZONTAL ? (float) transY1 : (float) transX1,
                plot.getOrientation() == PlotOrientation.HORIZONTAL ? (float) transX1 : (float) transY1);
        if (!this.points.contains(p)) {
            this.points.add(p);
        }
    }
    if (item == dataset.getItemCount(series) - 1) {
        State s = (State) state;
        // construct path
        if (this.points.size() > 1) {
            // we need at least two points to draw something
            ControlPoint cp0 = this.points.get(0);
            s.seriesPath.moveTo(cp0.x, cp0.y);
            if (this.points.size() == 2) {
                // we need at least 3 points to spline. Draw simple line
                // for two points
                ControlPoint cp1 = this.points.get(1);
                s.seriesPath.lineTo(cp1.x, cp1.y);
            } else {
                // construct spline

                // add some cardinal spline control points
                this.points = addCardinalSplinePoints(this.points, tension);

                // applying standard spline
                int np = this.points.size(); // number of points
                float[] d = new float[np]; // Newton form coefficients
                float[] x = new float[np]; // x-coordinates of nodes
                float y;
                float t;
                float oldy = 0;
                float oldt = 0;

                float[] a = new float[np];
                float t1;
                float t2;
                float[] h = new float[np];

                for (int i = 0; i < np; i++) {
                    ControlPoint cpi = this.points.get(i);
                    x[i] = cpi.x;
                    d[i] = cpi.y;
                }

                for (int i = 1; i <= np - 1; i++) {
                    h[i] = x[i] - x[i - 1];
                }
                float[] sub = new float[np - 1];
                float[] diag = new float[np - 1];
                float[] sup = new float[np - 1];

                for (int i = 1; i <= np - 2; i++) {
                    diag[i] = (h[i] + h[i + 1]) / 3;
                    sup[i] = h[i + 1] / 6;
                    sub[i] = h[i] / 6;
                    a[i] = (d[i + 1] - d[i]) / h[i + 1] - (d[i] - d[i - 1]) / h[i];
                }
                solveTridiag(sub, diag, sup, a, np - 2);

                // note that a[0]=a[np-1]=0
                // draw
                oldt = x[0];
                oldy = d[0];
                s.seriesPath.moveTo(oldt, oldy);
                for (int i = 1; i <= np - 1; i++) {
                    // loop over intervals between nodes
                    for (int j = 1; j <= this.precision; j++) {
                        t1 = (h[i] * j) / this.precision;
                        t2 = h[i] - t1;
                        y = ((-a[i - 1] / 6 * (t2 + h[i]) * t1 + d[i - 1]) * t2
                                + (-a[i] / 6 * (t1 + h[i]) * t2 + d[i]) * t1) / h[i];
                        t = x[i - 1] + t1;
                        s.seriesPath.lineTo(t, y);
                        oldt = t;
                        oldy = y;
                    }
                }
            }
            // draw path
            drawFirstPassShape(g2, pass, series, item, s.seriesPath);
        }

        // reset points vector
        this.points = new Vector<ControlPoint>();
    }
}

From source file:com.ivli.roim.controls.ChartControl.java

private ValueMarker findMarker(MouseEvent e) {
    final XYPlot plot = getChart().getXYPlot();

    Collection mark = plot.getDomainMarkers(Layer.FOREGROUND);

    if (null == mark || mark.isEmpty())
        return null;

    final double domainX = plot.getDomainAxis().java2DToValue(e.getX(), getScreenDataArea(),
            plot.getDomainAxisEdge());

    final double Epsilon = plot.getDataRange(plot.getDomainAxis()).getLength() * .01d;

    for (Object o : mark) {
        if (o instanceof DomainMarker) {
            //DomainMarker m = (DomainMarker)o;
            double val = ((DomainMarker) o).getValue();
            if (val >= domainX - Epsilon && val <= domainX + Epsilon) {
                //getContentPane().setCursor(new Cursor(Cursor.HAND_CURSOR)); 
                return (ValueMarker) o;
            }//from  w  w w . j  a  v  a2s.c om
        }
    }
    return null;
}

From source file:lu.lippmann.cdb.lab.mds.MDSViewBuilder.java

/**
 * /*from  ww  w  . java 2s  .c  o m*/
 */
private static void buildFilteredSeries(final MDSResult mdsResult, final XYPlot xyPlot,
        final String... attrNameToUseAsPointTitle) throws Exception {

    final CollapsedInstances distMdsRes = mdsResult.getCInstances();
    final Instances instances = distMdsRes.getInstances();

    final SimpleMatrix coordinates = mdsResult.getCoordinates();

    final Instances collapsedInstances = mdsResult.getCollapsedInstances();
    int maxSize = 0;
    if (distMdsRes.isCollapsed()) {
        final List<Instances> clusters = distMdsRes.getCentroidMap().getClusters();
        final int nbCentroids = clusters.size();
        maxSize = clusters.get(0).size();
        for (int i = 1; i < nbCentroids; i++) {
            final int currentSize = clusters.get(i).size();
            if (currentSize > maxSize) {
                maxSize = currentSize;
            }
        }
    }

    Attribute clsAttribute = null;
    int nbClass = 1;
    if (instances.classIndex() != -1) {
        clsAttribute = instances.classAttribute();
        nbClass = clsAttribute.numValues();
    }
    final XYSeriesCollection dataset = (XYSeriesCollection) xyPlot.getDataset();
    final int fMaxSize = maxSize;

    final List<XYSeries> lseries = new ArrayList<XYSeries>();

    //No class : add one dummy serie
    if (nbClass <= 1) {
        lseries.add(new XYSeries("Serie #1", false));
    } else {
        //Some class : add one serie per class
        for (int i = 0; i < nbClass; i++) {
            lseries.add(new XYSeries(clsAttribute.value(i), false));
        }
    }
    dataset.removeAllSeries();

    /**
     * Initialize filtered series
     */
    final List<Instances> filteredInstances = new ArrayList<Instances>();
    for (int i = 0; i < lseries.size(); i++) {
        filteredInstances.add(new Instances(collapsedInstances, 0));
    }

    final Map<Tuple<Integer, Integer>, Integer> correspondanceMap = new HashMap<Tuple<Integer, Integer>, Integer>();
    for (int i = 0; i < collapsedInstances.numInstances(); i++) {
        final Instance oInst = collapsedInstances.instance(i);
        int indexOfSerie = 0;
        if (oInst.classIndex() != -1) {
            if (distMdsRes.isCollapsed()) {
                indexOfSerie = getStrongestClass(i, distMdsRes);
            } else {
                indexOfSerie = (int) oInst.value(oInst.classAttribute());
            }
        }
        lseries.get(indexOfSerie).add(coordinates.get(i, 0), coordinates.get(i, 1));

        filteredInstances.get(indexOfSerie).add(oInst);
        if (distMdsRes.isCollapsed()) {
            correspondanceMap.put(new Tuple<Integer, Integer>(indexOfSerie,
                    filteredInstances.get(indexOfSerie).numInstances() - 1), i);
        }
    }

    final List<Paint> colors = new ArrayList<Paint>();

    for (final XYSeries series : lseries) {
        dataset.addSeries(series);
    }

    if (distMdsRes.isCollapsed()) {
        final XYLineAndShapeRenderer xyRenderer = new XYLineAndShapeRenderer(false, true) {
            private static final long serialVersionUID = -6019883886470934528L;

            @Override
            public void drawItem(Graphics2D g2, XYItemRendererState state, java.awt.geom.Rectangle2D dataArea,
                    PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis,
                    XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) {

                if (distMdsRes.isCollapsed()) {

                    final Integer centroidIndex = correspondanceMap
                            .get(new Tuple<Integer, Integer>(series, item));
                    final Instances cluster = distMdsRes.getCentroidMap().getClusters().get(centroidIndex);
                    int size = cluster.size();

                    final int shapeSize = (int) (MAX_POINT_SIZE * size / fMaxSize + 1);

                    final double x1 = plot.getDataset().getX(series, item).doubleValue();
                    final double y1 = plot.getDataset().getY(series, item).doubleValue();

                    Map<Object, Integer> mapRepartition = new HashMap<Object, Integer>();
                    mapRepartition.put("No class", size);
                    if (cluster.classIndex() != -1) {
                        mapRepartition = WekaDataStatsUtil.getClassRepartition(cluster);
                    }

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

                    setSeriesShape(series,
                            new Ellipse2D.Double(-shapeSize / 2, -shapeSize / 2, shapeSize, shapeSize));

                    super.drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series,
                            item, crosshairState, pass);

                    //Draw pie
                    if (ENABLE_PIE_SHART) {
                        createPieChart(g2, (int) (fx - shapeSize / 2), (int) (fy - shapeSize / 2), shapeSize,
                                mapRepartition, size, colors);
                    }

                } else {

                    super.drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series,
                            item, crosshairState, pass);

                }

            }

        };

        xyPlot.setRenderer(xyRenderer);
    }

    final XYToolTipGenerator gen = new XYToolTipGenerator() {
        @Override
        public String generateToolTip(XYDataset dataset, int series, int item) {
            if (distMdsRes.isCollapsed()) {
                final StringBuilder res = new StringBuilder("<html>");
                final Integer centroidIndex = correspondanceMap.get(new Tuple<Integer, Integer>(series, item));
                final Instance centroid = distMdsRes.getCentroidMap().getCentroids().get(centroidIndex);
                final Instances cluster = distMdsRes.getCentroidMap().getClusters().get(centroidIndex);

                //Set same class index for cluster than for original instances
                //System.out.println("Cluster index = "  + cluster.classIndex() + "/" + instances.classIndex());
                cluster.setClassIndex(instances.classIndex());

                Map<Object, Integer> mapRepartition = new HashMap<Object, Integer>();
                mapRepartition.put("No class", cluster.size());
                if (cluster.classIndex() != -1) {
                    mapRepartition = WekaDataStatsUtil.getClassRepartition(cluster);
                }
                res.append(InstanceFormatter.htmlFormat(centroid, false)).append("<br/>");
                for (final Map.Entry<Object, Integer> entry : mapRepartition.entrySet()) {
                    if (entry.getValue() != 0) {
                        res.append("Class :<b>'" + StringEscapeUtils.escapeHtml(entry.getKey().toString())
                                + "</b>' -> " + entry.getValue()).append("<br/>");
                    }
                }
                res.append("</html>");
                return res.toString();
            } else {
                //return InstanceFormatter.htmlFormat(filteredInstances.get(series).instance(item),true);
                return InstanceFormatter.shortHtmlFormat(filteredInstances.get(series).instance(item));
            }
        }
    };

    final Shape shape = new Ellipse2D.Float(0f, 0f, MAX_POINT_SIZE, MAX_POINT_SIZE);

    ((XYLineAndShapeRenderer) xyPlot.getRenderer()).setUseOutlinePaint(true);

    for (int p = 0; p < nbClass; p++) {
        xyPlot.getRenderer().setSeriesToolTipGenerator(p, gen);
        ((XYLineAndShapeRenderer) xyPlot.getRenderer()).setLegendShape(p, shape);
        xyPlot.getRenderer().setSeriesOutlinePaint(p, Color.BLACK);
    }

    for (int ii = 0; ii < nbClass; ii++) {
        colors.add(xyPlot.getRenderer().getItemPaint(ii, 0));
    }

    if (attrNameToUseAsPointTitle.length > 0) {
        final Attribute attrToUseAsPointTitle = instances.attribute(attrNameToUseAsPointTitle[0]);
        if (attrToUseAsPointTitle != null) {
            final XYItemLabelGenerator lg = new XYItemLabelGenerator() {
                @Override
                public String generateLabel(final XYDataset dataset, final int series, final int item) {
                    return filteredInstances.get(series).instance(item).stringValue(attrToUseAsPointTitle);
                }
            };
            xyPlot.getRenderer().setBaseItemLabelGenerator(lg);
            xyPlot.getRenderer().setBaseItemLabelsVisible(true);
        }
    }
}