Example usage for org.jfree.chart.entity ChartEntity getArea

List of usage examples for org.jfree.chart.entity ChartEntity getArea

Introduction

In this page you can find the example usage for org.jfree.chart.entity ChartEntity getArea.

Prototype

public Shape getArea() 

Source Link

Document

Returns the area occupied by the entity (in Java 2D space).

Usage

From source file:gov.nih.nci.caintegrator.ui.graphing.util.ImageMapUtil.java

/**
 * Get a collection of entities with the area shape equal to the bounding rectangle
 * for the shape of original entity. This is necessary because the Javascript for the sample 
 * selection lasso can only handle rect objects.
 * @param entities/*from w ww .jav  a2s.  co  m*/
 * @return a collection of entities containing the bounding rectangles of the original entities
 */
private static Collection<ChartEntity> getBoundingEntities(Collection entities) {
    ChartEntity entity;
    ChartEntity boundingEntity;
    Shape shape;
    Rectangle2D boundingRect;
    Collection<ChartEntity> boundingEntities = new ArrayList<ChartEntity>();
    for (Iterator i = entities.iterator(); i.hasNext();) {
        entity = (ChartEntity) i.next();
        shape = entity.getArea();
        boundingRect = shape.getBounds2D();
        boundingEntity = new ChartEntity(boundingRect, entity.getToolTipText(), entity.getURLText());
        boundingEntities.add(boundingEntity);
    }
    return boundingEntities;
}

From source file:gda.plots.SimpleLegendEntity.java

/**
 * Creates a SimpleLegendEntity by creating a new ChartEntity from an existing one and adding an SimpleXYSeries.
 * //from  w ww. ja  v a 2 s. com
 * @param ce
 * @param sxys
 */
public SimpleLegendEntity(ChartEntity ce, SimpleXYSeries sxys) {
    super(ce.getArea(), ce.getToolTipText(), ce.getURLText());
    this.sxys = sxys;
}

From source file:net.sf.maltcms.chromaui.charts.datastructures.QuadTreeEntityCollection.java

/**
 *
 * @param ce/*w ww .  j  a  va 2 s  . c  o  m*/
 */
@Override
public void add(ChartEntity ce) {
    qt.put(getPoint(ce.getArea().getBounds2D().getCenterX(), ce.getArea().getBounds2D().getCenterY()), ce);
    ll.add(ce);
    //        System.out.println(""+ll.size()+" entities in collection!");
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.JFreeChartReportDrawable.java

/**
 * Returns an optional image-map for the entry.
 *
 * @param bounds the bounds for which the image map is computed.
 * @return the computed image-map or null if there is no image-map available.
 *///from   w ww .  j av  a2 s  . c o m
public ImageMap getImageMap(final Rectangle2D bounds) {
    if (chartRenderingInfo == null) {
        return null;
    }
    final Rectangle2D dataArea = getDataAreaOffset();
    final Rectangle2D otherArea = new Rectangle2D.Double();

    if ((ObjectUtilities.equal(bounds, this.bounds)) == false) {
        final BufferedImage image = new BufferedImage(1, 1, BufferedImage.TYPE_4BYTE_ABGR);
        final Graphics2D graphics = image.createGraphics();
        draw(graphics, bounds);
        graphics.dispose();
    }

    final ImageMap map = new ImageMap();
    final EntityCollection entityCollection = chartRenderingInfo.getEntityCollection();
    final int count = entityCollection.getEntityCount();
    for (int i = 0; i < count; i++) {
        final ChartEntity chartEntity = entityCollection.getEntity(i);
        final Shape area = chartEntity.getArea();
        final String hrefValue = chartEntity.getURLText();
        final String tooltipValue = chartEntity.getToolTipText();
        if (StringUtils.isEmpty(tooltipValue) == false || StringUtils.isEmpty(hrefValue) == false) {
            final AbstractImageMapEntry entry;
            if (chartEntity instanceof XYItemEntity || chartEntity instanceof CategoryItemEntity
                    || chartEntity instanceof PieSectionEntity) {
                entry = createMapEntry(area, dataArea);
            } else {
                entry = createMapEntry(area, otherArea);
            }
            if (entry == null) {
                continue;
            }
            if (StringUtils.isEmpty(hrefValue) == false) {
                entry.setAttribute(LibXmlInfo.XHTML_NAMESPACE, "href", hrefValue);
            } else {
                entry.setAttribute(LibXmlInfo.XHTML_NAMESPACE, "href", "#");
            }
            if (StringUtils.isEmpty(tooltipValue) == false) {
                entry.setAttribute(LibXmlInfo.XHTML_NAMESPACE, "title", tooltipValue);
            }
            map.addMapEntry(entry);
        }
    }

    return map;
}

From source file:org.mwc.cmap.grideditor.chart.JFreeChartComposite.java

@Override
public void mouseDoubleClick(final MouseEvent event) {
    final Rectangle scaledDataArea = getScreenDataArea(event.x, event.y);
    if (scaledDataArea == null)
        return;/*from w ww .  j a  v a 2 s. co  m*/
    int x = (int) ((event.x - getClientArea().x) / getScaleX());
    int y = (int) ((event.y - getClientArea().y) / getScaleY());
    x = (int) ((event.x - getClientArea().x));
    y = (int) ((event.y - getClientArea().y));

    if (this.getChartRenderingInfo() != null) {
        final EntityCollection entities = this.getChartRenderingInfo().getEntityCollection();
        if (entities != null) {
            for (final Object next : entities.getEntities()) {
                final ChartEntity nextEntity = (ChartEntity) next;
                if (false == nextEntity instanceof XYItemEntity) {
                    continue;
                }

                if (nextEntity.getArea().contains(x, y)) {
                    // sort out it's details
                    final XYItemEntity xyEntity = (XYItemEntity) nextEntity;
                    int theIndex = 0;
                    if (xyEntity.getDataset() instanceof XYSeriesCollection) {
                        theIndex = xyEntity.getItem();

                        //                     BackedChartItem backedChartItem;
                        //                     XYSeries series = ((XYSeriesCollection) xyEntity.getDataset())
                        //                           .getSeries(seriesKey);
                        //                     XYDataItem dataItem = series.getDataItem(xyEntity.getItem());
                        //                     if (dataItem instanceof BackedChartItem)
                        //                     {
                        //                        backedChartItem = (BackedChartItem) dataItem;
                        //                     }
                    } else if (xyEntity.getDataset() instanceof TimeSeriesCollection) {
                        final TimeSeriesCollection theDataset = (TimeSeriesCollection) xyEntity.getDataset();
                        final TimeSeries theSeries = theDataset.getSeries(xyEntity.getSeriesIndex());
                        theIndex = xyEntity.getItem();
                        final int itemCount = theSeries.getItemCount();
                        // the items are in reverse order. reverse the index
                        theIndex = itemCount - (theIndex + 1);

                        // TimeSeries series = ((TimeSeriesCollection)
                        // xyEntity.getDataset())
                        // .getSeries(seriesKey);
                        // TimeSeriesDataItem dataItem = series
                        // .getDataItem(xyEntity.getItem());
                        // if (dataItem instanceof BackedChartItem)
                        // {
                        // backedChartItem = (BackedChartItem) dataItem;
                        // }
                    }

                    // clear the selection, as long as ctrl isn't selected
                    if ((event.stateMask & SWT.CTRL) != 0) {
                        // control is selected, so we don't want to clear the selection
                    } else if ((event.stateMask & SWT.SHIFT) != 0) {
                        // shift is selected, so we want to extend the selection
                    } else {
                        // we're not extending the selection, clear it,
                        _dataGrid.getTableViewer().getTable().deselectAll();
                    }

                    // try to select it
                    _dataGrid.getTableViewer().getTable().select(theIndex);

                    // and make sure it's visible
                    _dataGrid.getTableViewer().getTable().showSelection();

                    // and tell the action buttons what's happened
                    _dataGrid.getActionContext().setSelection(_dataGrid.getTableViewer().getSelection());

                    break;
                }
            }
        }
    }
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.JFreeChartReportDrawable.java

public void draw(final Graphics2D graphics2D, final Rectangle2D bounds) {
    this.bounds = (Rectangle2D) bounds.clone();
    if (chartRenderingInfo != null) {
        this.chartRenderingInfo.clear();
    }//from  w  w  w .j  a va  2 s .co m
    final Graphics2D g2 = (Graphics2D) graphics2D.create();
    this.chart.draw(g2, bounds, chartRenderingInfo);
    g2.dispose();

    if (chartRenderingInfo == null || debugRendering == false) {
        return;
    }

    graphics2D.setColor(Color.RED);
    final Rectangle2D dataArea = getDataAreaOffset();
    final EntityCollection entityCollection = chartRenderingInfo.getEntityCollection();
    for (int i = 0; i < entityCollection.getEntityCount(); i++) {
        final ChartEntity chartEntity = entityCollection.getEntity(i);
        if (chartEntity instanceof XYItemEntity || chartEntity instanceof CategoryItemEntity
                || chartEntity instanceof PieSectionEntity) {
            final Area a = new Area(chartEntity.getArea());
            if (buggyDrawArea) {
                a.transform(AffineTransform.getTranslateInstance(dataArea.getX(), dataArea.getY()));
            }
            a.intersect(new Area(dataArea));
            graphics2D.draw(a);
        } else {
            graphics2D.draw(chartEntity.getArea());
        }
    }
}

From source file:gov.nih.nci.cma.web.graphing.CMAPrincipalComponentAnalysisPlot.java

/**
 * Get a collection of entities with the area shape equal to the bounding rectangle
 * for the shape of original entity. This is necessary because the Javascript for the sample
 * selection lasso can only handle rect objects.
 * @param entities// ww  w  . j  a  v  a  2  s.c  o m
 * @return a collection of entities containing the bounding rectangles of the original entities
 */
private Collection<ChartEntity> getBoundingEntities(Collection entities) {
    ChartEntity entity;
    ChartEntity boundingEntity;
    Shape shape;
    Rectangle2D boundingRect;
    Collection<ChartEntity> boundingEntities = new ArrayList<ChartEntity>();
    for (Iterator i = entities.iterator(); i.hasNext();) {
        entity = (ChartEntity) i.next();
        shape = entity.getArea();
        boundingRect = shape.getBounds2D();
        boundingEntity = new ChartEntity(boundingRect, entity.getToolTipText(), entity.getURLText());
        boundingEntities.add(boundingEntity);
    }
    return boundingEntities;
}

From source file:gov.nih.nci.caintegrator.ui.graphing.chart.plot.PrincipalComponentAnalysisPlot.java

/**
 * Get a collection of entities with the area shape equal to the bounding rectangle
 * for the shape of original entity. This is necessary because the Javascript for the sample 
 * selection lasso can only handle rect objects.
 * @param entities/* w  ww.  j  a  va  2s  .  c o  m*/
 * @return a collection of entities containing the bounding rectangles of the original entities
 */
protected Collection<ChartEntity> getBoundingEntities(Collection entities) {
    ChartEntity entity;
    ChartEntity boundingEntity;
    Shape shape;
    Rectangle2D boundingRect;
    Collection<ChartEntity> boundingEntities = new ArrayList<ChartEntity>();
    for (Iterator i = entities.iterator(); i.hasNext();) {
        entity = (ChartEntity) i.next();
        shape = entity.getArea();
        boundingRect = shape.getBounds2D();
        boundingEntity = new ChartEntity(boundingRect, entity.getToolTipText(), entity.getURLText());
        boundingEntities.add(boundingEntity);
    }
    return boundingEntities;
}

From source file:probe.com.view.core.chart4j.VennDiagramPanel.java

/**
 * Returns a list of the entities at the given x, y view location.
 *
 * @param viewX the x location//from  www . j a  v  a2 s  .com
 * @param viewY the y location
 * @return a list of the entities
 */
public ArrayList<ChartEntity> getEntitiesForPoint(int viewX, int viewY) {

    ArrayList<ChartEntity> entitiesForPoint = new ArrayList<ChartEntity>();
    ChartRenderingInfo info = chartPanel.getChartRenderingInfo();

    if (info != null) {
        Insets insets = chartPanel.getInsets();
        double x = (viewX - insets.left) / chartPanel.getScaleX();
        double y = (viewY - insets.top) / chartPanel.getScaleY();
        EntityCollection allEntities = info.getEntityCollection();
        int numEntities = allEntities.getEntityCount();

        for (int i = 0; i < numEntities; i++) {
            ChartEntity entity = allEntities.getEntity(i);
            if (entity.getArea().contains(x, y)) {
                entitiesForPoint.add(entity);
            }
        }
    }

    return entitiesForPoint;
}

From source file:edu.pitt.dbmi.odie.ui.jfreechart.EnhancedChartComposite.java

/**
 * Bounds the selection rectangle between the first and the last chart
 * entity bounds. and between the top and bottom bounds of the chart area.
 *//*from   w w  w . j a v a2s  .  c  om*/
private void boundSelectionRectangle() {
    int FIRSTENTITYERROR = 2;
    if (selectedEntities.size() > 0) {
        ChartEntity first = selectedEntities.get(0);

        ChartEntity last = selectedEntities.get(selectedEntities.size() - 1);
        Point firstp = first.getArea().getBounds().getLocation();
        Point lastp = last.getArea().getBounds().getLocation();

        Rectangle screenArea = getScreenDataArea();
        Point2D screenPoint = translateScreenToJava2D(new Point(screenArea.x, screenArea.y));

        if (this.orientation == PlotOrientation.VERTICAL) {
            selectionRectangle = new Rectangle(firstp.x - FIRSTENTITYERROR, (int) screenPoint.getY(),
                    lastp.x + last.getArea().getBounds().width - firstp.x, (int) (screenArea.height / scaleY));
        } else {
            selectionRectangle = new Rectangle((int) screenPoint.getX(), firstp.y,
                    (int) (screenArea.width / scaleX), lastp.y + last.getArea().getBounds().height - firstp.y);
        }
    }
}