List of usage examples for org.jfree.chart.imagemap StandardURLTagFragmentGenerator StandardURLTagFragmentGenerator
public StandardURLTagFragmentGenerator()
From source file:gov.nih.nci.caintegrator.ui.graphing.util.ImageMapUtil.java
/** * Write the image map for the collection of bounding entities. * @param writer/* w w w .j a v a2 s .c o m*/ * @param name * @param boundingEntities * @param useOverlibToolTip */ private static void writeBoundingRectImageMap(PrintWriter writer, String name, Collection<ChartEntity> boundingEntities, boolean useOverlibToolTip) { System.out.println("Num entities=" + boundingEntities.size()); StringBuffer sb = new StringBuffer(); ChartEntity chartEntity; String areaTag; StandardToolTipTagFragmentGenerator ttg = new StandardToolTipTagFragmentGenerator(); StandardURLTagFragmentGenerator urlg = new StandardURLTagFragmentGenerator(); sb.append("<map id=\"" + name + "\" name=\"" + name + "\">"); sb.append(StringUtils.getLineSeparator()); for (Iterator i = boundingEntities.iterator(); i.hasNext();) { chartEntity = (ChartEntity) i.next(); areaTag = chartEntity.getImageMapAreaTag(ttg, urlg).trim(); if (areaTag.length() > 0) { if (sb.indexOf(chartEntity.getImageMapAreaTag(ttg, urlg)) == -1) { sb.append(chartEntity.getImageMapAreaTag(ttg, urlg)); sb.append(StringUtils.getLineSeparator()); } } } sb.append("</map>"); writer.println(sb.toString()); }
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 w w w . j a v a2 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:gov.nih.nci.caintegrator.ui.graphing.util.ImageMapUtil.java
public static String getBoundingRectImageMapTag(String name, boolean useOverlibToolTip, ChartRenderingInfo info) {// w w w . j a v a2s. c om EntityCollection collection = info.getEntityCollection(); Collection entities = collection.getEntities(); Collection<ChartEntity> myBoundingEntities = getBoundingEntities(entities); System.out.println("Num entities=" + myBoundingEntities.size()); StringBuffer sb = new StringBuffer(); ChartEntity chartEntity; String areaTag; ToolTipTagFragmentGenerator ttg = null; if (useOverlibToolTip) { ttg = new CAIOverlibToolTipTagFragmentGenerator(); } else { ttg = new CAIStandardToolTipTagFragmentGenerator(); } StandardURLTagFragmentGenerator urlg = new StandardURLTagFragmentGenerator(); sb.append("\n\n<MAP name=\"" + name + "\">"); sb.append(StringUtils.getLineSeparator()); for (Iterator i = myBoundingEntities.iterator(); i.hasNext();) { chartEntity = (ChartEntity) i.next(); areaTag = chartEntity.getImageMapAreaTag(ttg, urlg).trim(); if (areaTag.length() > 0) { if (sb.indexOf(chartEntity.getImageMapAreaTag(ttg, urlg)) == -1) { sb.append(chartEntity.getImageMapAreaTag(ttg, urlg)); sb.append(StringUtils.getLineSeparator()); } } } sb.append("</MAP>\n\n"); return sb.toString(); }
From source file:info.novatec.testit.livingdoc.confluence.macros.historic.AbstractChartBuilder.java
public String getChartMap(String chartMapId) throws IOException { StringWriter writer = new StringWriter(); PrintWriter pw = new PrintWriter(writer); try {//from w w w . j a v a 2 s .c o m ChartUtilities.writeImageMap(pw, chartMapId, chartRenderingInfo, new StandardToolTipTagFragmentGenerator(), new StandardURLTagFragmentGenerator()); } finally { IOUtils.closeQuietly(pw); } return writer.toString(); }
From source file:com.greenpepper.confluence.macros.historic.AbstractChartBuilder.java
public String getChartMap(String chartMapId) throws IOException { StringWriter writer = new StringWriter(); PrintWriter pw = new PrintWriter(writer); try {/*from w w w . jav a 2s. c o m*/ ChartUtilities.writeImageMap(pw, chartMapId, chartRenderingInfo, new StandardToolTipTagFragmentGenerator(), new StandardURLTagFragmentGenerator()); } finally { IOUtil.closeQuietly(pw); } return writer.toString(); }
From source file:org.openfaces.renderkit.chart.ChartRenderer.java
@Override public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException { Components.generateIdIfNotSpecified(component); ResponseWriter writer = facesContext.getResponseWriter(); Chart chart = (Chart) component;//from ww w .j av a 2s . com ChartView view = chart.getChartView(); if (!chart.isRendered() || view == null) return; writer.startElement("div", chart); writeIdAttribute(facesContext, chart); Rendering.writeComponentClassAttribute(writer, chart); writer.writeAttribute("style", "width: " + chart.getWidth() + "px;" + " height:" + chart.getHeight() + "px;", "style"); String actionFiledId = chart.getClientId(facesContext) + MapRenderUtilities.ACTION_FIELD_SUFFIX; Rendering.writeNewLine(writer); Rendering.renderHiddenField(writer, actionFiledId, null); Rendering.writeNewLine(writer); BufferedImage image = chart.make(); final byte[] imageAsByteArray = Rendering.encodeAsPNG(image); final JfcRenderHints renderHints = chart.getRenderHints(); final ChartRenderingInfo renderingInfo = renderHints.getRenderingInfo(); String mapId = renderHints.getMapId(chart); String map = MapRenderUtilities.getImageMapExt(chart, mapId, renderingInfo, new StandardToolTipTagFragmentGenerator(), new StandardURLTagFragmentGenerator()); renderHints.setMap(map); if (view.getChartPopup() != null) { encodeChartPopup(facesContext, chart, view, renderingInfo); } chart.setImageBytes(imageAsByteArray); final Integer oldEntityIndex = chart.getEntityIndex(); chart.setEntityIndex(-1); String imageCreatedKey = "_dynamicImageCreated"; if (!chart.getAttributes().containsKey(imageCreatedKey)) { chart.getAttributes().put(imageCreatedKey, true); Application application = FacesContext.getCurrentInstance().getApplication(); DynamicImage dynamicImage = (DynamicImage) application.createComponent(DynamicImage.COMPONENT_TYPE); dynamicImage.setId("img"); dynamicImage.getAttributes().put(DynamicImageRenderer.DEFAULT_STYLE_ATTR, "o_chart"); Components.addChild(chart, dynamicImage); } DynamicImage dynamicImage = Components.findChildWithClass(chart, DynamicImage.class); ValueExpression ve = new ByteArrayValueExpression(imageAsByteArray); dynamicImage.setValueExpression("data", ve); dynamicImage.setMapId(mapId); dynamicImage.setMap(map); dynamicImage.setWidth(chart.getWidth()); dynamicImage.setHeight(chart.getHeight()); copyAttributes(dynamicImage, chart, "onclick", "ondblclick", "onmousedown", "onmouseup", "onmousemove", "onmouseover", "onmouseout"); dynamicImage.setImageType(ImageType.PNG); dynamicImage.encodeAll(facesContext); chart.setEntityIndex(oldEntityIndex); if (map != null) { Resources.renderJSLinkIfNeeded(facesContext, Resources.utilJsURL(facesContext)); Resources.renderJSLinkIfNeeded(facesContext, Resources.internalURL(facesContext, "chart/chart.js")); } encodeScripts(facesContext, chart, dynamicImage); writer.endElement("div"); }
From source file:org.toobsframework.pres.chart.controller.ChartHandler.java
/** * //from www.j a v a 2 s . c o m * Retrieves the URL path to use for lookup and delegates to * <code>getViewNameForUrlPath</code>. * * @throws Exception Exception fetching or rendering component. * @see #getViewNameForUrlPath * */ @Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response, UrlDispatchInfo dispatchInfo) throws Exception { String chartId = dispatchInfo.getResourceId(); if (log.isDebugEnabled()) { log.debug("Rendering chart '" + chartId + "' for lookup path: " + dispatchInfo.getOriginalPath()); } IRequest componentRequest = this.setupComponentRequest(dispatchInfo, request, response, true); Date startTime = null; if (log.isDebugEnabled()) { startTime = new Date(); } JFreeChart chart = null; int height = 400; int width = 600; ChartDefinition chartDef = null; if (null != chartId && !chartId.equals("")) { try { request.setAttribute("chartId", chartId); chartDef = this.chartManager.getChartDefinition(chartId); } catch (ChartNotFoundException cnfe) { log.warn("Chart " + chartId + " not found."); throw cnfe; } try { chart = chartBuilder.build(chartDef, componentRequest); width = chartDef.getChartWidth(); height = chartDef.getChartHeight(); } catch (ChartException e) { Throwable t = e.rootCause(); log.info("Root cause " + t.getClass().getName() + " " + t.getMessage()); throw e; } catch (Exception e) { throw e; } finally { this.componentRequestManager.unset(); } } else { throw new Exception("No chartId specified"); } //Write out to the response. response.setHeader("Pragma", "no-cache"); // HTTP 1.0 response.setHeader("Cache-Control", "max-age=0, must-revalidate"); // HTTP 1.1 ChartRenderingInfo chartRenderingInfo = new ChartRenderingInfo(); if (chartDef.doImageWithMap()) { response.setContentType("text/html; charset=UTF-8"); String genFileName = chartDef.getId() + "-" + new Date().getTime() + ".png"; String imageOutputFileName = configuration.getUploadDir() + genFileName; File imageOutputFile = new File(imageOutputFileName); OutputStream os = null; try { os = new FileOutputStream(imageOutputFile); ChartUtilities.writeChartAsPNG(os, chart, width, height, chartRenderingInfo); } finally { if (os != null) { os.close(); } } PrintWriter writer = response.getWriter(); StringBuffer sb = new StringBuffer(); // TODO BUGBUG Chart location needs to fixed sb.append("<img id=\"chart-").append(chartDef.getId()).append("\" src=\"") .append(/*Configuration.getInstance().getMainContext() +*/ "/upload/" + genFileName) .append("\" ismap=\"ismap\" usemap=\"#").append(chartDef.getId()).append("Map\" />"); URLTagFragmentGenerator urlGenerator; if (chartDef.getUrlFragmentBean() != null) { urlGenerator = (URLTagFragmentGenerator) beanFactory.getBean(chartDef.getUrlFragmentBean()); } else { urlGenerator = new StandardURLTagFragmentGenerator(); } sb.append(ImageMapUtilities.getImageMap(chartDef.getId() + "Map", chartRenderingInfo, null, urlGenerator)); writer.print(sb.toString()); writer.flush(); } else { response.setContentType("image/png"); ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, width, height, chartRenderingInfo); } if (log.isDebugEnabled()) { Date endTime = new Date(); log.debug("Time [" + chartId + "] - " + (endTime.getTime() - startTime.getTime())); } return null; }
From source file:org.openfaces.component.chart.ChartView.java
public byte[] renderAsImageFile() { Chart chart = getChart();//from w w w . j av a2 s .c o m JfcRenderHints renderHints = chart.getRenderHints(); ChartRenderingInfo chartRenderingInfo = new ChartRenderingInfo(); renderHints.setRenderingInfo(chartRenderingInfo); ChartModel model = chart.getModel(); ModelInfo info = new ModelInfo(model); renderHints.setModelInfo(info); Plot plot = createPlot(chart, model, info); JFreeChart jFreeChart = new JFreeChartAdapter(plot, chart); int width = chart.getWidth(); int height = chart.getHeight(); BufferedImage image = jFreeChart.createBufferedImage(width, height, chartRenderingInfo); byte[] imageAsByteArray = Rendering.encodeAsPNG(image); String mapId = renderHints.getMapId(chart); if (mapId != null) { String map = MapRenderUtilities.getImageMapExt(chart, mapId, chartRenderingInfo, new StandardToolTipTagFragmentGenerator(), new StandardURLTagFragmentGenerator()); renderHints.setMap(map); } return imageAsByteArray; }
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 a v a 2 s . c om*/ } // 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.GEPlot.java
public String generateBWLog2IntensityChart(String xAxisLabel, String yAxisLabel, HttpSession session, PrintWriter pw, boolean isCoinPlot) { String bwFilename = ""; //PlotSize ps = PlotSize.MEDIUM; JFreeChart bwChart = null;// w ww .ja v a2s .c om try { //IMAGE Size Control CategoryAxis xAxis = new CategoryAxis(xAxisLabel); xAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); NumberAxis yAxis = new NumberAxis(yAxisLabel); yAxis.setAutoRangeIncludesZero(true); BoxAndWhiskerCoinPlotRenderer bwRenderer = null; CategoryPlot bwPlot = null; if (isCoinPlot) { Map<String, List<Double>> groupMap = rawDataMap.get(reporterName); DefaultBoxAndWhiskerCategoryDataset smallBwdataset = new DefaultBoxAndWhiskerCategoryDataset(); int row = 0; int column = 0; HashMap<String, List> caIntegatorCoinList = new HashMap<String, List>(); for (String group : groupList) { smallBwdataset.add(groupMap.get(group), reporterName, group); caIntegatorCoinList.put(row + "_" + column++, groupMap.get(group)); } bwRenderer = new BoxAndWhiskerCoinPlotRenderer(caIntegatorCoinList); bwRenderer.setDisplayAllOutliers(true); bwRenderer.setDisplayCoinCloud(true); bwRenderer.setDisplayMean(false); bwRenderer.setFillBox(false); bwRenderer.setPlotColor(null); bwPlot = new CategoryPlot(smallBwdataset, xAxis, yAxis, bwRenderer); if (groupList.size() < 6) imgW = 200; } else { bwRenderer = new BoxAndWhiskerCoinPlotRenderer(); bwRenderer.setDisplayAllOutliers(true); bwRenderer.setBaseToolTipGenerator(new CategoryToolTipGenerator() { public String generateToolTip(CategoryDataset dataset, int series, int item) { String tt = ""; NumberFormat formatter = new DecimalFormat(".####"); String key = ""; //String s = formatter.format(-1234.567); // -001235 if (dataset instanceof DefaultBoxAndWhiskerCategoryDataset) { DefaultBoxAndWhiskerCategoryDataset ds = (DefaultBoxAndWhiskerCategoryDataset) dataset; try { String med = formatter.format(ds.getMedianValue(series, item)); tt += "Median: " + med + "<br/>"; tt += "Mean: " + formatter.format(ds.getMeanValue(series, item)) + "<br/>"; tt += "Q1: " + formatter.format(ds.getQ1Value(series, item)) + "<br/>"; tt += "Q3: " + formatter.format(ds.getQ3Value(series, item)) + "<br/>"; tt += "Max: " + formatter.format( FaroutOutlierBoxAndWhiskerCalculator.getMaxFaroutOutlier(ds, series, item)) + "<br/>"; tt += "Min: " + formatter.format( FaroutOutlierBoxAndWhiskerCalculator.getMinFaroutOutlier(ds, series, item)) + "<br/>"; tt += "<br/><br/>Please click on the box and whisker to view a plot for this reporter.<br/>"; key = ds.getRowKeys().get(series).toString(); } catch (Exception e) { } } String returnString = "onclick=\"popCoin('" + geneSymbol + "','" + key + "');\" | "; return returnString + tt; } }); bwRenderer.setFillBox(false); bwPlot = new CategoryPlot(bwdataset, xAxis, yAxis, bwRenderer); } bwChart = new JFreeChart(bwPlot); bwChart.setBackgroundPaint(java.awt.Color.white); LegendTitle title = bwChart.getLegend(); LegendItemSource[] sources = title.getSources(); legendItemCollection = sources[0].getLegendItems(); bwChart.removeLegend(); // Write the chart image to the temporary directory ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); // BW if (bwChart != null) { //int bwwidth = new BigDecimal(1.5).multiply(new BigDecimal(imgW)).intValue(); bwFilename = ServletUtilities.saveChartAsPNG(bwChart, imgW, 400, info, session); CustomOverlibToolTipTagFragmentGenerator ttip = new CustomOverlibToolTipTagFragmentGenerator(); ttip.setExtra(" href='javascript:void(0);' "); //must have href for area tags to have cursor:pointer ChartUtilities.writeImageMap(pw, bwFilename, info, ttip, new StandardURLTagFragmentGenerator()); info.clear(); // lose the first one info = new ChartRenderingInfo(new StandardEntityCollection()); } //END BW pw.flush(); } catch (Exception e) { System.out.println("Exception - " + e.toString()); e.printStackTrace(System.out); } // return filename; //charts.put("errorBars", log2Filename); //charts.put("noErrorBars", rawFilename); //charts.put("bwFilename", bwFilename); //charts.put("legend", legendHtml); //charts.put("size", ps.toString()); return bwFilename; }