/** * Creates an image map element that complies with the XHTML 1.0 specification. * * @param name the map name (<code>null</code> not permitted). * @param info the chart rendering info (<code>null</code> not permitted). * @param toolTipTagFragmentGenerator a generator for the HTML fragment that will contain the * tooltip text (<code>null</code> not permitted if <code>info</code> contains tooltip * information). * @param urlTagFragmentGenerator a generator for the HTML fragment that will contain the URL * reference (<code>null</code> not permitted if <code>info</code> contains URLs). * @return The map tag. */ public static String getImageMap( String name, ChartRenderingInfo info, ToolTipTagFragmentGenerator toolTipTagFragmentGenerator, URLTagFragmentGenerator urlTagFragmentGenerator) { StringBuilder sb = new StringBuilder(); sb.append("<map id=\"").append(htmlEscape(name)); sb.append("\" name=\"").append(htmlEscape(name)).append("\">"); sb.append(StringUtils.getLineSeparator()); EntityCollection entities = info.getEntityCollection(); if (entities != null) { int count = entities.getEntityCount(); for (int i = count - 1; i >= 0; i--) { ChartEntity entity = entities.getEntity(i); if (entity.getToolTipText() != null || entity.getURLText() != null) { String area = entity.getImageMapAreaTag(toolTipTagFragmentGenerator, urlTagFragmentGenerator); if (area.length() > 0) { sb.append(area); sb.append(StringUtils.getLineSeparator()); } } } } sb.append("</map>"); return sb.toString(); }
private void populateInfo(final ChartRenderingInfo info) { if (urlTemplate == null) { return; } Iterator iter = info.getEntityCollection().iterator(); while (iter.hasNext()) { ChartEntity entity = (ChartEntity) iter.next(); if (entity instanceof XYItemEntity) { if (urlTemplate != null) { XYItemEntity xyItemEntity = (XYItemEntity) entity; if (paramName == null) { xyItemEntity.setURLText(urlTemplate); } else { try { int seriesIndex = xyItemEntity.getSeriesIndex(); int itemIndex = xyItemEntity.getItem(); String xySeriesKey = (String) ((XYZSeriesCollectionChartDefinition) xyItemEntity.getDataset()) .getSeriesKey(seriesIndex); String encodedVal = URLEncoder.encode(xySeriesKey, LocaleHelper.getSystemEncoding()); String drillURL = TemplateUtil.applyTemplate(urlTemplate, paramName, encodedVal); String itemValueStr = ((XYZSeriesCollectionChartDefinition) xyItemEntity.getDataset()) .getX(seriesIndex, itemIndex) .toString(); encodedVal = URLEncoder.encode(itemValueStr, LocaleHelper.getSystemEncoding()); if (seriesName == null) { drillURL = TemplateUtil.applyTemplate(drillURL, "SERIES", encodedVal); // $NON-NLS-1$ } else { drillURL = TemplateUtil.applyTemplate(drillURL, seriesName, encodedVal); } xyItemEntity.setURLText(drillURL); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } } }
/** * Draws the plot on a Java 2D graphics device (such as the screen or a printer). * * @param g2 the graphics device. * @param area the area within which the plot should be drawn. * @param anchor the anchor point (<code>null</code> permitted). * @param parentState the state from the parent plot, if there is one. * @param info collects info about the drawing. */ public void draw( Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) { // adjust the drawing area for the plot insets (if any)... RectangleInsets insets = getInsets(); insets.trim(area); drawBackground(g2, area); drawOutline(g2, area); // check that there is some data to display... if (DatasetUtilities.isEmptyOrNull(getDataset())) { drawNoDataMessage(g2, area); return; } int pieCount = 0; if (getDataExtractOrder() == TableOrder.BY_ROW) { pieCount = getDataset().getRowCount(); } else { pieCount = getDataset().getColumnCount(); } // the columns variable is always >= rows int displayCols = (int) Math.ceil(Math.sqrt(pieCount)); int displayRows = (int) Math.ceil((double) pieCount / (double) displayCols); // swap rows and columns to match plotArea shape if (displayCols > displayRows && area.getWidth() < area.getHeight()) { int temp = displayCols; displayCols = displayRows; displayRows = temp; } prefetchSectionPaints(); int x = (int) area.getX(); int y = (int) area.getY(); int width = ((int) area.getWidth()) / displayCols; int height = ((int) area.getHeight()) / displayRows; int row = 0; int column = 0; int diff = (displayRows * displayCols) - pieCount; int xoffset = 0; Rectangle rect = new Rectangle(); for (int pieIndex = 0; pieIndex < pieCount; pieIndex++) { rect.setBounds(x + xoffset + (width * column), y + (height * row), width, height); String title = null; if (getDataExtractOrder() == TableOrder.BY_ROW) { title = getDataset().getRowKey(pieIndex).toString(); } else { title = getDataset().getColumnKey(pieIndex).toString(); } getPieChart().setTitle(title); PieDataset piedataset = null; PieDataset dd = new CategoryToPieDataset(getDataset(), getDataExtractOrder(), pieIndex); if (getLimit() > 0.0) { piedataset = DatasetUtilities.createConsolidatedPieDataset(dd, getAggregatedItemsKey(), getLimit()); } else { piedataset = dd; } PiePlot piePlot = (PiePlot) getPieChart().getPlot(); piePlot.setDataset(piedataset); piePlot.setPieIndex(pieIndex); // update the section colors to match the global colors... for (int i = 0; i < piedataset.getItemCount(); i++) { Comparable key = piedataset.getKey(i); Paint p; if (key.equals(getAggregatedItemsKey())) { p = getAggregatedItemsPaint(); } else { p = (Paint) this.sectionPaints.get(key); } piePlot.setSectionPaint(key, p); } ChartRenderingInfo subinfo = null; if (info != null) { subinfo = new ChartRenderingInfo(); } getPieChart().draw(g2, rect, subinfo); if (info != null) { info.getOwner().getEntityCollection().addAll(subinfo.getEntityCollection()); info.addSubplotInfo(subinfo.getPlotInfo()); } ++column; if (column == displayCols) { column = 0; ++row; if (row == displayRows - 1 && diff != 0) { xoffset = (diff * width) / 2; } } } }