List of usage examples for org.jfree.chart.entity ChartEntity getToolTipText
public String getToolTipText()
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 ww w .ja v a2s. c om 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:net.sourceforge.processdash.ui.web.CGIChartBase.java
private void writeImageHtml(int width, int height, int imgID, ChartRenderingInfo info) throws IOException { String tooltip = getParameter("tooltip"); if (!StringUtils.hasValue(tooltip)) tooltip = resources.getHTML("More_Detail_Here_Instruction"); String href = getParameter("href"); if (StringUtils.hasValue(href)) { // create a copy of the entity collection, and place an entity for // the entire chart at the beginning of the list. This will // make it appear last in the image map (which is important, // because browsers process the image map areas in the order that // they appear; having the entire chart area listed first would // obscure all of the other image map areas). EntityCollection entities = new StandardEntityCollection(); entities.add(new ChartEntity(info.getChartArea(), tooltip, href)); if (info.getEntityCollection() != null) entities.addAll(info.getEntityCollection()); // Next: most of our chart entities will not have URLs. URL values // don't inherit in the imagemap, so if we want the entire image // to have a single URL, we need to assign that URL to every // area in the chart. for (Iterator i = entities.iterator(); i.hasNext();) { ChartEntity ce = (ChartEntity) i.next(); // check for no-op chart entity - these won't appear in the // image map anyway, so they don't need to be adjusted if (ce.getToolTipText() == null && ce.getURLText() == null) continue; // for other entities, add a tooltip and a URL as needed. if (!StringUtils.hasValue(ce.getToolTipText())) ce.setToolTipText(tooltip); if (!StringUtils.hasValue(ce.getURLText())) ce.setURLText(href);/*ww w.j ava 2 s . co m*/ } // install our modified version of the entity collection into // the chart info object, so it will be used when generating // the image map later. info.setEntityCollection(entities); } // write the image tag out.write("<img width=\"" + width + "\" height=\"" + height + "\" src=\"/reports/pngCache?id=" + imgID + "\" usemap=\"#IMG" + imgID + '"'); // imagemaps have hyperlink borders by default, even if we don't // have a URL we're pointing to. Turn that border off. if (!StringUtils.hasValue(href) || parameters.containsKey("noBorder")) out.write(" border=\"0\""); // Our client might want to add attributes to the image tag. Look // through the query parameters we received for arbitrary attributes // starting with the prefix "img", and copy them into the tag. for (Iterator i = parameters.entrySet().iterator(); i.hasNext();) { Map.Entry e = (Map.Entry) i.next(); String attrName = (String) e.getKey(); if (attrName.startsWith("img") && !attrName.endsWith("_ALL")) { out.write(" " + attrName.substring(3) + "=\""); out.write(HTMLUtils.escapeEntities(e.getValue().toString())); out.write('"'); } } out.write(">"); // finally, write the image map. Note that we have to strip line // break characters from the resulting HTML, otherwise firefox seems // to decide that the <map> tag actually takes up space on the page String imageMapHtml = ImageMapUtilities.getImageMap("IMG" + imgID, info, getToolTipGenerator(tooltip), new StandardURLTagFragmentGenerator()); for (int i = 0; i < imageMapHtml.length(); i++) { char c = imageMapHtml.charAt(i); if (c != '\r' && c != '\n') out.write(c); } out.flush(); }
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// w ww . j ava2 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:org.orbeon.oxf.processor.JFreeChartProcessor.java
public ProcessorOutput createOutput(String name) { return new ProcessorOutputImpl(JFreeChartProcessor.this, name) { public void readImpl(PipelineContext context, XMLReceiver xmlReceiver) { JFreeChartSerializer.ChartConfig chartConfig = readChartConfig(context); ChartInfo info = createChart(context, chartConfig); try { xmlReceiver.startDocument(); xmlReceiver.startElement("", "chart-info", "chart-info", new AttributesImpl()); xmlReceiver.startElement("", "file", "file", new AttributesImpl()); xmlReceiver.characters(info.file.toCharArray(), 0, info.file.length()); xmlReceiver.endElement("", "file", "file"); if (chartConfig.getMap() != null) { AttributesImpl atts = new AttributesImpl(); atts.addAttribute("", "name", "name", "CDATA", chartConfig.getMap()); xmlReceiver.startElement("", "map", "map", atts); EntityCollection entities = info.getInfo().getEntityCollection(); Iterator iterator = entities.iterator(); while (iterator.hasNext()) { ChartEntity entity = (ChartEntity) iterator.next(); AttributesImpl attr = new AttributesImpl(); attr.addAttribute("", "shape", "shape", "CDATA", entity.getShapeType()); attr.addAttribute("", "coords", "coords", "CDATA", entity.getShapeCoords()); if (entity.getURLText() != null && !entity.getURLText().equals("")) { attr.addAttribute("", "href", "href", "CDATA", entity.getURLText()); }// w w w . j a v a 2 s . c o m if (entity.getToolTipText() != null && !entity.getToolTipText().equals("")) { attr.addAttribute("", "title", "title", "CDATA", entity.getToolTipText()); } xmlReceiver.startElement("", "area", "area", attr); xmlReceiver.endElement("", "area", "area"); } xmlReceiver.endElement("", "map", "map"); } xmlReceiver.endElement("", "chart-info", "chart-info"); xmlReceiver.endDocument(); } catch (SAXException e) { throw new OXFException(e); } } }; }
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 w w. ja v a 2 s . c om*/ * @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:org.adempiere.webui.apps.graph.jfreegraph.ChartRendererServiceImpl.java
@Override public boolean renderPerformanceGraph(Component parent, int chartWidth, int chartHeight, final GoalModel goalModel) { GraphBuilder builder = new GraphBuilder(); builder.setMGoal(goalModel.goal);/*ww w. j a va 2 s. c o m*/ builder.setXAxisLabel(goalModel.xAxisLabel); builder.setYAxisLabel(goalModel.yAxisLabel); builder.loadDataSet(goalModel.columnList); JFreeChart chart = builder.createChart(goalModel.chartType); ChartRenderingInfo info = new ChartRenderingInfo(); chart.getPlot().setForegroundAlpha(0.6f); if (goalModel.zoomFactor > 0) { chartWidth = chartWidth * goalModel.zoomFactor / 100; chartHeight = chartHeight * goalModel.zoomFactor / 100; } if (!goalModel.showTitle) { chart.setTitle(""); } BufferedImage bi = chart.createBufferedImage(chartWidth, chartHeight, BufferedImage.TRANSLUCENT, info); try { byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true); AImage image = new AImage("", bytes); Imagemap myImage = new Imagemap(); myImage.setContent(image); parent.appendChild(myImage); int count = 0; for (Iterator<?> it = info.getEntityCollection().getEntities().iterator(); it.hasNext();) { ChartEntity entity = (ChartEntity) it.next(); String key = null; if (entity instanceof CategoryItemEntity) { Comparable<?> colKey = ((CategoryItemEntity) entity).getColumnKey(); if (colKey != null) { key = colKey.toString(); } } else if (entity instanceof PieSectionEntity) { Comparable<?> sectionKey = ((PieSectionEntity) entity).getSectionKey(); if (sectionKey != null) { key = sectionKey.toString(); } } if (key == null) { continue; } Area area = new Area(); myImage.appendChild(area); area.setCoords(entity.getShapeCoords()); area.setShape(entity.getShapeType()); area.setTooltiptext(entity.getToolTipText()); area.setId(count + "_WG_" + key); count++; } myImage.addEventListener(Events.ON_CLICK, new EventListener<Event>() { public void onEvent(Event event) throws Exception { MouseEvent me = (MouseEvent) event; String areaId = me.getArea(); if (areaId != null) { List<GraphColumn> list = goalModel.columnList; for (int i = 0; i < list.size(); i++) { String s = "_WG_" + list.get(i).getLabel(); if (areaId.endsWith(s)) { chartMouseClicked(goalModel.goal, list.get(i)); return; } } } } }); } catch (Exception e) { log.log(Level.SEVERE, "", e); return false; } return true; }
From source file:org.operamasks.faces.render.graph.ChartRenderer.java
private void encodeItemTips(FacesContext context, UIChart comp, ChartRenderingInfo info) throws IOException { StringBuilder buf = new StringBuilder(); buf.append("Ext.om.AreaTips.init();\n"); buf.append("Ext.om.AreaTips.register({"); buf.append("target:'").append(comp.getClientId(context)).append("'"); buf.append(",trackMouse:true"); buf.append(",areas:["); EntityCollection entities = info.getEntityCollection(); Iterator it = entities.iterator(); while (it.hasNext()) { ChartEntity entity = (ChartEntity) it.next(); String tooltip = entity.getToolTipText(); if (tooltip != null) { buf.append("{"); buf.append("shape:'").append(entity.getShapeType()).append("'"); buf.append(",coords:[").append(entity.getShapeCoords()).append("]"); buf.append(",text:").append(HtmlEncoder.enquote(tooltip)); buf.append("},"); }// w w w .ja v a 2 s . co m } if (buf.charAt(buf.length() - 1) == ',') { buf.setLength(buf.length() - 1); } buf.append("]});\n"); ResourceManager rm = ResourceManager.getInstance(context); if (isAjaxResponse(context)) { AjaxResponseWriter out = (AjaxResponseWriter) context.getResponseWriter(); out.writeScript("OM.ajax.loadScript('" + rm.getResourceURL("/ext/om/AreaTips.js") + "');\n"); out.writeScript(buf.toString()); } else { YuiExtResource resource = YuiExtResource.register(rm, "Ext.om.AreaTips"); resource.addInitScript(buf.toString()); } }
From source file:org.adempiere.webui.apps.graph.WGraph.java
private void render(JFreeChart chart) { ChartRenderingInfo info = new ChartRenderingInfo(); int width = 560; int height = 400; if (zoomFactor > 0) { width = width * zoomFactor / 100; height = height * zoomFactor / 100; }// w w w. j ava 2 s . com if (m_hideTitle) { chart.setTitle(""); } BufferedImage bi = chart.createBufferedImage(width, height, BufferedImage.TRANSLUCENT, info); try { byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true); AImage image = new AImage("", bytes); Imagemap myImage = new Imagemap(); myImage.setContent(image); if (panel.getPanelchildren() != null) { panel.getPanelchildren().getChildren().clear(); panel.getPanelchildren().appendChild(myImage); } else { Panelchildren pc = new Panelchildren(); panel.appendChild(pc); pc.appendChild(myImage); } int count = 0; for (Iterator<?> it = info.getEntityCollection().getEntities().iterator(); it.hasNext();) { ChartEntity entity = (ChartEntity) it.next(); String key = null; if (entity instanceof CategoryItemEntity) { Comparable<?> colKey = ((CategoryItemEntity) entity).getColumnKey(); if (colKey != null) { key = colKey.toString(); } } else if (entity instanceof PieSectionEntity) { Comparable<?> sectionKey = ((PieSectionEntity) entity).getSectionKey(); if (sectionKey != null) { key = sectionKey.toString(); } } if (key == null) { continue; } Area area = new Area(); myImage.appendChild(area); area.setCoords(entity.getShapeCoords()); area.setShape(entity.getShapeType()); area.setTooltiptext(entity.getToolTipText()); area.setId(count + "_WG_" + key); count++; } myImage.addEventListener(Events.ON_CLICK, new EventListener() { public void onEvent(Event event) throws Exception { MouseEvent me = (MouseEvent) event; String areaId = me.getArea(); if (areaId != null) { for (int i = 0; i < list.size(); i++) { String s = "_WG_" + list.get(i).getLabel(); if (areaId.endsWith(s)) { chartMouseClicked(i); return; } } } } }); } catch (Exception e) { log.log(Level.SEVERE, "", e); } }
From source file:de.xirp.ui.widgets.custom.XChartComposite.java
/** * Returns a string for the tooltip.//from w w w. j a va 2 s.c o m * * @param e * the mouse event. * @return A tool tip or <code>null</code> if no tooltip is * available. */ public String getToolTipText(org.eclipse.swt.events.MouseEvent e) { String result = null; if (this.info != null) { EntityCollection entities = this.info.getEntityCollection(); if (entities != null) { Rectangle insets = getBounds(); ChartEntity entity = entities.getEntity((int) ((e.x - insets.x) / this.scaleX), (int) ((e.y - insets.y) / this.scaleY)); if (entity != null) { result = entity.getToolTipText(); } } } return result; }
From source file:org.tsho.dmc2.core.chart.jfree.DmcChartPanel.java
/** * Returns a string for the tooltip./*from w ww.ja va2 s .co m*/ * * @param e the mouse event. * * @return a tool tip or <code>null</code> if no tooltip is available. */ public String getToolTipText(MouseEvent e) { String result = null; if (this.info != null) { EntityCollection entities = this.info.getEntityCollection(); if (entities != null) { Insets insets = getInsets(); ChartEntity entity = entities.getEntity((int) (e.getX() - insets.left), (int) (e.getY() - insets.top)); if (entity != null) { result = entity.getToolTipText(); } } } return result; }