List of usage examples for org.jfree.chart.entity EntityCollection getEntityCount
public int getEntityCount();
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);/*from www .ja v 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:net.sf.jasperreports.charts.util.ChartUtil.java
/** * /* w ww. jav a 2s. c o m*/ */ public static List<JRPrintImageAreaHyperlink> getImageAreaHyperlinks(JFreeChart chart, ChartHyperlinkProvider chartHyperlinkProvider, Graphics2D grx, Rectangle2D renderingArea)// throws JRException { List<JRPrintImageAreaHyperlink> areaHyperlinks = null; if (chartHyperlinkProvider != null && chartHyperlinkProvider.hasHyperlinks()) { ChartRenderingInfo renderingInfo = new ChartRenderingInfo(); if (grx == null) { chart.createBufferedImage((int) renderingArea.getWidth(), (int) renderingArea.getHeight(), renderingInfo); } else { chart.draw(grx, renderingArea, renderingInfo); } EntityCollection entityCollection = renderingInfo.getEntityCollection(); if (entityCollection != null && entityCollection.getEntityCount() > 0) { areaHyperlinks = new ArrayList<JRPrintImageAreaHyperlink>(entityCollection.getEntityCount()); for (@SuppressWarnings("unchecked") Iterator<ChartEntity> it = entityCollection.iterator(); it.hasNext();) { ChartEntity entity = it.next(); JRPrintHyperlink printHyperlink = chartHyperlinkProvider.getEntityHyperlink(entity); if (printHyperlink != null) { JRPrintImageArea area = getImageArea(entity); JRPrintImageAreaHyperlink areaHyperlink = new JRPrintImageAreaHyperlink(); areaHyperlink.setArea(area); areaHyperlink.setHyperlink(printHyperlink); areaHyperlinks.add(areaHyperlink); } } } } return areaHyperlinks; }
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 w w w. j a v a 2s . c om*/ }); } } 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(); }/*from www . j a v a 2 s . c o 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. */// w ww. java 2 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.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 ww w. j a va 2 s . co 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 v a2s .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 w w . j ava2 s .co 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; }