Search in sources :

Example 1 with XYDatasetSelectionState

use of org.jfree.data.xy.XYDatasetSelectionState in project graphcode2vec by graphcode2vec.

the class XYPlot method clearSelection.

/**
 * Clears the selection.
 *
 * @since 1.2.0
 */
public void clearSelection() {
    // cycle through the datasets and clear the selection state
    int datasetCount = this.datasets.size();
    for (int d = 0; d < datasetCount; d++) {
        XYDataset dataset = (XYDataset) this.datasets.get(d);
        if (dataset instanceof AbstractXYDataset) {
            // FIXME:  actually, we need to get the selection state
            // taking into account the rendering source
            AbstractXYDataset axyd = (AbstractXYDataset) dataset;
            if (axyd.getSelectionState() != null) {
                XYDatasetSelectionState selState = axyd.getSelectionState();
                selState.clearSelection();
            }
        }
    }
}
Also used : AbstractXYDataset(org.jfree.data.xy.AbstractXYDataset) XYDatasetSelectionState(org.jfree.data.xy.XYDatasetSelectionState) SelectableXYDataset(org.jfree.data.xy.SelectableXYDataset) AbstractXYDataset(org.jfree.data.xy.AbstractXYDataset) XYDataset(org.jfree.data.xy.XYDataset) Paint(java.awt.Paint)

Example 2 with XYDatasetSelectionState

use of org.jfree.data.xy.XYDatasetSelectionState in project graphcode2vec by graphcode2vec.

the class XYPlot method select.

/**
 * Selects the data items within the specified region.
 *
 * @param region  the region (in Java2D coordinates).
 * @param dataArea  the data area.
 * @param source  the rendering source.
 *
 * @since 1.2.0
 */
public void select(GeneralPath region, Rectangle2D dataArea, RenderingSource source) {
    // cycle through the datasets and change the selection state for the
    // items that fall within the specified region
    int datasetCount = this.datasets.size();
    for (int d = 0; d < datasetCount; d++) {
        XYDataset dataset = (XYDataset) this.datasets.get(d);
        if (dataset == null) {
            continue;
        }
        XYDatasetSelectionState state = findSelectionStateForDataset(dataset, source);
        if (state == null) {
            continue;
        }
        GeneralPath path = convertToDataSpace(region, dataArea, dataset);
        // now we have to iterate over all the dataset values and
        // convert each point to Java2D space and then check if it should
        // be selected.
        int seriesCount = dataset.getSeriesCount();
        for (int s = 0; s < seriesCount; s++) {
            int itemCount = dataset.getItemCount(s);
            for (int i = 0; i < itemCount; i++) {
                double x = dataset.getXValue(s, i);
                double y = dataset.getYValue(s, i);
                // whether or not the item is contained in the path
                if (path.contains(x, y)) {
                    state.setSelected(s, i, true, false);
                }
            }
        }
        state.fireSelectionEvent();
    }
}
Also used : GeneralPath(java.awt.geom.GeneralPath) XYDatasetSelectionState(org.jfree.data.xy.XYDatasetSelectionState) SelectableXYDataset(org.jfree.data.xy.SelectableXYDataset) AbstractXYDataset(org.jfree.data.xy.AbstractXYDataset) XYDataset(org.jfree.data.xy.XYDataset) Paint(java.awt.Paint)

Example 3 with XYDatasetSelectionState

use of org.jfree.data.xy.XYDatasetSelectionState in project graphcode2vec by graphcode2vec.

the class XYPlot method render.

/**
 * Draws a representation of the data within the dataArea region, using the
 * current renderer.
 * <P>
 * The <code>info</code> and <code>crosshairState</code> arguments may be
 * <code>null</code>.
 *
 * @param g2  the graphics device.
 * @param dataArea  the region in which the data is to be drawn.
 * @param index  the dataset index.
 * @param info  an optional object for collection dimension information.
 * @param crosshairState  collects crosshair information
 *                        (<code>null</code> permitted).
 *
 * @return A flag that indicates whether any data was actually rendered.
 */
public boolean render(Graphics2D g2, Rectangle2D dataArea, int index, PlotRenderingInfo info, CrosshairState crosshairState) {
    boolean foundData = false;
    XYDataset dataset = getDataset(index);
    if (!DatasetUtilities.isEmptyOrNull(dataset)) {
        foundData = true;
        ValueAxis xAxis = getDomainAxisForDataset(index);
        ValueAxis yAxis = getRangeAxisForDataset(index);
        if (xAxis == null || yAxis == null) {
            // can't render anything without axes
            return foundData;
        }
        XYItemRenderer renderer = getRenderer(index);
        if (renderer == null) {
            renderer = getRenderer();
            if (renderer == null) {
                // no default renderer available
                return foundData;
            }
        }
        XYItemRendererState state = renderer.initialise(g2, dataArea, this, dataset, info);
        XYDatasetSelectionState selectionState = state.getSelectionState();
        int passCount = renderer.getPassCount();
        SeriesRenderingOrder seriesOrder = getSeriesRenderingOrder();
        if (seriesOrder == SeriesRenderingOrder.REVERSE) {
            // render series in reverse order
            for (int pass = 0; pass < passCount; pass++) {
                int seriesCount = dataset.getSeriesCount();
                for (int series = seriesCount - 1; series >= 0; series--) {
                    int firstItem = 0;
                    int lastItem = dataset.getItemCount(series) - 1;
                    if (lastItem == -1) {
                        continue;
                    }
                    if (state.getProcessVisibleItemsOnly()) {
                        int[] itemBounds = RendererUtilities.findLiveItems(dataset, series, xAxis.getLowerBound(), xAxis.getUpperBound());
                        firstItem = Math.max(itemBounds[0] - 1, 0);
                        lastItem = Math.min(itemBounds[1] + 1, lastItem);
                    }
                    state.startSeriesPass(dataset, series, firstItem, lastItem, pass, passCount);
                    for (int item = firstItem; item <= lastItem; item++) {
                        boolean selected = false;
                        if (selectionState != null) {
                            selected = selectionState.isSelected(series, item);
                        }
                        renderer.drawItem(g2, state, dataArea, this, xAxis, yAxis, dataset, series, item, selected, pass);
                    }
                    state.endSeriesPass(dataset, series, firstItem, lastItem, pass, passCount);
                }
            }
        } else {
            // render series in forward order
            for (int pass = 0; pass < passCount; pass++) {
                int seriesCount = dataset.getSeriesCount();
                for (int series = 0; series < seriesCount; series++) {
                    int firstItem = 0;
                    int lastItem = dataset.getItemCount(series) - 1;
                    if (state.getProcessVisibleItemsOnly()) {
                        int[] itemBounds = RendererUtilities.findLiveItems(dataset, series, xAxis.getLowerBound(), xAxis.getUpperBound());
                        firstItem = Math.max(itemBounds[0] - 1, 0);
                        lastItem = Math.min(itemBounds[1] + 1, lastItem);
                    }
                    state.startSeriesPass(dataset, series, firstItem, lastItem, pass, passCount);
                    for (int item = firstItem; item <= lastItem; item++) {
                        boolean selected = false;
                        if (selectionState != null) {
                            selected = selectionState.isSelected(series, item);
                        }
                        renderer.drawItem(g2, state, dataArea, this, xAxis, yAxis, dataset, series, item, selected, pass);
                    }
                    state.endSeriesPass(dataset, series, firstItem, lastItem, pass, passCount);
                }
            }
        }
    }
    return foundData;
}
Also used : ValueAxis(org.jfree.chart.axis.ValueAxis) XYDatasetSelectionState(org.jfree.data.xy.XYDatasetSelectionState) SelectableXYDataset(org.jfree.data.xy.SelectableXYDataset) AbstractXYDataset(org.jfree.data.xy.AbstractXYDataset) XYDataset(org.jfree.data.xy.XYDataset) XYItemRendererState(org.jfree.chart.renderer.xy.XYItemRendererState) AbstractXYItemRenderer(org.jfree.chart.renderer.xy.AbstractXYItemRenderer) XYItemRenderer(org.jfree.chart.renderer.xy.XYItemRenderer) Paint(java.awt.Paint)

Example 4 with XYDatasetSelectionState

use of org.jfree.data.xy.XYDatasetSelectionState in project graphcode2vec by graphcode2vec.

the class XYPlot method findSelectionStateForDataset.

/**
 * Returns the selection state for the specified dataset.  This could be
 * <code>null</code> if the dataset hasn't been set up to support
 * selections.
 *
 * @param dataset  the dataset.
 * @param source  the selection source.
 *
 * @return The selection state (possibly <code>null</code>).
 */
private XYDatasetSelectionState findSelectionStateForDataset(XYDataset dataset, Object source) {
    if (dataset instanceof SelectableXYDataset) {
        SelectableXYDataset sd = (SelectableXYDataset) dataset;
        XYDatasetSelectionState s = sd.getSelectionState();
        return s;
    }
    throw new RuntimeException();
// return null;  // TODO: implement
}
Also used : SelectableXYDataset(org.jfree.data.xy.SelectableXYDataset) XYDatasetSelectionState(org.jfree.data.xy.XYDatasetSelectionState)

Example 5 with XYDatasetSelectionState

use of org.jfree.data.xy.XYDatasetSelectionState in project graphcode2vec by graphcode2vec.

the class XYPlot method select.

/**
 * Selects a single point.
 *
 * @param xx  the x coordinate in Java 2D space.
 * @param yy  the y coordinate in Java 2D space.
 * @param dataArea  the data area.
 * @param source  the rendering source (can be used to locate the
 *         appropriate selection state).
 *
 * @since 1.2.0
 */
public void select(double xx, double yy, Rectangle2D dataArea, RenderingSource source) {
    int datasetCount = this.datasets.size();
    for (int d = 0; d < datasetCount; d++) {
        XYDataset dataset = (XYDataset) this.datasets.get(d);
        if (dataset == null) {
            continue;
        }
        XYDatasetSelectionState state = findSelectionStateForDataset(dataset, source);
        if (state == null) {
            continue;
        }
        Graphics2D g2 = source.createGraphics2D();
        XYItemRenderer renderer = getRendererForDataset(dataset);
        XYItemRendererState rs = renderer.initialise(source.createGraphics2D(), dataArea, this, dataset, null);
        int seriesCount = dataset.getSeriesCount();
        for (int s = 0; s < seriesCount; s++) {
            int itemCount = dataset.getItemCount(s);
            for (int i = 0; i < itemCount; i++) {
                // whether or not the item is contained in the path
                if (renderer.hitTest(xx, yy, g2, dataArea, this, getDomainAxisForDataset(d), getRangeAxisForDataset(d), dataset, s, i, rs, false)) {
                    state.setSelected(s, i, !state.isSelected(s, i));
                }
            }
        }
    }
}
Also used : XYDatasetSelectionState(org.jfree.data.xy.XYDatasetSelectionState) SelectableXYDataset(org.jfree.data.xy.SelectableXYDataset) AbstractXYDataset(org.jfree.data.xy.AbstractXYDataset) XYDataset(org.jfree.data.xy.XYDataset) XYItemRendererState(org.jfree.chart.renderer.xy.XYItemRendererState) AbstractXYItemRenderer(org.jfree.chart.renderer.xy.AbstractXYItemRenderer) XYItemRenderer(org.jfree.chart.renderer.xy.XYItemRenderer) Paint(java.awt.Paint) Graphics2D(java.awt.Graphics2D)

Aggregations

SelectableXYDataset (org.jfree.data.xy.SelectableXYDataset)7 XYDatasetSelectionState (org.jfree.data.xy.XYDatasetSelectionState)7 Paint (java.awt.Paint)4 AbstractXYDataset (org.jfree.data.xy.AbstractXYDataset)4 XYDataset (org.jfree.data.xy.XYDataset)4 GeneralPath (java.awt.geom.GeneralPath)2 ChartRenderingInfo (org.jfree.chart.ChartRenderingInfo)2 RenderingSource (org.jfree.chart.RenderingSource)2 AbstractXYItemRenderer (org.jfree.chart.renderer.xy.AbstractXYItemRenderer)2 XYItemRenderer (org.jfree.chart.renderer.xy.XYItemRenderer)2 XYItemRendererState (org.jfree.chart.renderer.xy.XYItemRendererState)2 Graphics2D (java.awt.Graphics2D)1 ValueAxis (org.jfree.chart.axis.ValueAxis)1 CrosshairState (org.jfree.chart.plot.CrosshairState)1