Example usage for org.jfree.chart.entity EntityCollection getEntity

List of usage examples for org.jfree.chart.entity EntityCollection getEntity

Introduction

In this page you can find the example usage for org.jfree.chart.entity EntityCollection getEntity.

Prototype

public ChartEntity getEntity(int index);

Source Link

Document

Returns an entity from the collection.

Usage

From source file:org.openfaces.component.chart.impl.helpers.MapRenderUtilities.java

public static String getImageMapExt(Chart chart, String name, ChartRenderingInfo info,
        ToolTipTagFragmentGenerator toolTipTagFragmentGenerator,
        URLTagFragmentGenerator urlTagFragmentGenerator) {
    StringBuilder sb = new StringBuilder();
    sb.append("<map id=\"").append(name).append("\" name=\"").append(name).append("\">");
    sb.append(StringUtils.getLineSeparator());

    // the following is needed for displaying tooltips under IE (doesn't display tooltips if there's no area with href)
    String fakeArea = "<area shape=\"rect\" coords=\"0,0,0,0\" href=\"fake.jsp\" alt=\"\" title=\"\" />";
    sb.append(fakeArea);//w  w w. j  av a 2  s  .c  o  m
    sb.append(StringUtils.getLineSeparator());

    EntityCollection entities = info.getEntityCollection();
    if (entities != null) {
        int count = entities.getEntityCount();
        ChartView view = chart.getChartView();

        for (int i = count - 1; i >= 0; i--) {
            ChartEntity entity = entities.getEntity(i);

            if (entity.getToolTipText() == null && entity.getURLText() == null
                    && getOnClick(chart, chart.getChartView(), entity) == null && !viewHasAction(view)
                    && !viewHasPopup(view) && chart.getChartSelection() == null)
                continue;

            String area;
            if (i == 0) {
                area = getTitleImageMapAreaTag(chart, new StandardToolTipTagFragmentGenerator(),
                        new StandardURLTagFragmentGenerator(), entity);
            } else {
                if (entity instanceof PieSectionEntity) {
                    area = getImageMapAreaTag(chart, view, toolTipTagFragmentGenerator, urlTagFragmentGenerator,
                            entity, i);
                } else if (entity instanceof CategoryItemEntity) {
                    area = getImageMapAreaTag(chart, view, toolTipTagFragmentGenerator, urlTagFragmentGenerator,
                            entity, i);
                } else if (entity instanceof XYItemEntity) {
                    area = getImageMapAreaTag(chart, view, toolTipTagFragmentGenerator, urlTagFragmentGenerator,
                            entity, i);
                } else {
                    area = "";
                }
            }

            if (area.length() > 0) {
                sb.append(area);
                sb.append(StringUtils.getLineSeparator());
            }
        }

    }

    sb.append("</map>");
    return sb.toString();
}

From source file:com.swordlord.gozer.components.wicket.graph.common.GWChartPanel.java

protected DynamicImageMap constructImageMap(ChartImage image, String mapName) {
    DynamicImageMap imageMap = new DynamicImageMap("imageMap", mapName);
    EntityCollection entities = image.getRenderingInfo().getEntityCollection();
    if (entities != null) {
        int count = entities.getEntityCount();
        for (int i = count - 1; i >= 0; i--) {
            final ChartEntity entity = entities.getEntity(i);
            imageMap.addArea(entity.getShapeType(), entity.getShapeCoords(), entity.getToolTipText(),
                    new AjaxLink<Object>("link") {
                        private static final long serialVersionUID = -7982198051678987986L;

                        @Override
                        public void onClick(AjaxRequestTarget target) {
                            onClickCallback(target, entity);
                        }/*from  ww w.  j a v a 2 s.  c  o m*/
                    });
        }
    }
    return imageMap;
}

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();
    }/*www  .  j a va  2s .  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: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  w  w  .ja  v  a  2 s.  co  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.openfaces.renderkit.chart.ChartRenderer.java

private void encodeChartPopup(FacesContext facesContext, Chart chart, ChartView view,
        ChartRenderingInfo renderingInfo) throws IOException {
    EntityCollection entities = renderingInfo.getEntityCollection();
    if (entities != null) {
        int count = entities.getEntityCount();

        for (int i = count - 1; i >= 0; i--) {
            ChartEntity entity = entities.getEntity(i);

            Map<String, Object> requestMap = facesContext.getExternalContext().getRequestMap();
            chart.setEntityIndex(i);/*from w  ww  .  j a va2  s. c o  m*/

            if (view instanceof GridChartView) {
                final GridPointInfo pointInfo = ChartInfoUtil.getGridPointInfo(entity, chart);
                if (pointInfo != null) {
                    Object oldAttributeValue = requestMap.put("point", pointInfo);
                    renderChartPopup(facesContext, view);
                    requestMap.put("point", oldAttributeValue);
                }
            } else if (view instanceof PieChartView) {
                final PieSectorInfo pieSectorInfo = ChartInfoUtil.getPieSectorInfo(entity);
                if (pieSectorInfo != null) {
                    Object oldAttributeValue = requestMap.put("sector", pieSectorInfo);
                    renderChartPopup(facesContext, view);
                    requestMap.put("sector", oldAttributeValue);
                }
            }
        }
    }
}

From source file:nextapp.echo.chart.webcontainer.sync.component.ChartDisplayPeer.java

private String getImageMap(Component comp) {
    StringBuffer sb = new StringBuffer();

    ChartDisplay chartDisplay = (ChartDisplay) comp;

    Extent ewidth = (Extent) chartDisplay.getRenderProperty(ChartDisplay.PROPERTY_WIDTH);
    int width = ewidth != null ? ewidth.getValue() : ChartDisplayPeer.DEFAULT_WIDTH;

    Extent eheight = (Extent) chartDisplay.getRenderProperty(ChartDisplay.PROPERTY_HEIGHT);
    int height = ewidth != null ? eheight.getValue() : ChartDisplayPeer.DEFAULT_HEIGHT;

    JFreeChart chart = chartDisplay.getChart();
    BufferedImage image;/* ww w  .ja va 2s . c  o  m*/
    ChartRenderingInfo info = new ChartRenderingInfo();
    synchronized (chart) {
        image = chart.createBufferedImage(width, height, info);
    }
    EntityCollection coll = info.getEntityCollection();
    //        debug("About to show entities");
    //        for (int i = 0; i < coll.getEntityCount(); i++) {
    //           debug("Entity: " + coll.getEntity(i).getShapeCoords());
    //           debug("Entity: " + coll.getEntity(i).getShapeType());
    //           debug("Entity: " + coll.getEntity(i).getToolTipText());
    //        }
    sb.append("[");
    for (int i = 0; i < coll.getEntityCount(); i++) {
        if (i > 0) {
            sb.append(", ");
        }
        sb.append("{ shapeType: '" + coll.getEntity(i).getShapeType() + "'");
        sb.append(", shapeCoords: '" + coll.getEntity(i).getShapeCoords() + "'");
        sb.append(", actionCommand: '" + chartDisplay.getActionCommands()[i] + "'");
        sb.append(", toolTipText: '" + coll.getEntity(i).getToolTipText() + "'}");

    }
    sb.append("]");

    return sb.toString();
}

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   w  ww.ja v a2  s  . c  o  m
 * @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

private ChartEntity getFirstEntity() {
    EntityCollection entities = this.info.getEntityCollection();
    return entities.getEntity(0);

}