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();
}
}
}
}
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();
}
}
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;
}
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
}
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));
}
}
}
}
}
Aggregations