/** * Renders a clickable map. */ public void doMap(StaplerRequest req, StaplerResponse rsp) throws IOException { if (req.checkIfModified(timestamp, rsp)) return; ChartRenderingInfo info = new ChartRenderingInfo(); render(req,info); rsp.setContentType("text/plain;charset=UTF-8"); rsp.getWriter().println(ChartUtilities.getImageMap( "map", info )); } }
g2.setFont(getTickLabelFont(tick.getCategory())); g2.setPaint(getTickLabelPaint(tick.getCategory())); x1 = x0 - state.getMax(); Rectangle2D area = new Rectangle2D.Double(x0, y0, (x1 - x0), (y1 - y0)); if(r==null || !r.intersects(area)) { position.getLabelAnchor(), (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getAngle()); if (plotState != null && plotState.getOwner() != null) { EntityCollection entities = plotState.getOwner().getEntityCollection(); if (entities != null) { String tooltip = getCategoryLabelToolTip( tick.getCategory()); entities.add(new CategoryLabelEntity(tick.getCategory(), bounds, tooltip, null));
dy = ((VectorXYDataset) dataset).getVectorYValue(series, item); double xx0 = domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge()); double yy0 = rangeAxis.valueToJava2D(y, dataArea, plot.getRangeAxisEdge()); double xx1 = domainAxis.valueToJava2D(x + dx, dataArea, plot.getDomainAxisEdge()); double yy1 = rangeAxis.valueToJava2D(y + dy, dataArea, plot.getRangeAxisEdge()); line = new Line2D.Double(xx0, yy0, xx1, yy1); g2.setPaint(getItemPaint(series, item)); g2.setStroke(getItemStroke(series, item)); g2.draw(line); entities = info.getOwner().getEntityCollection(); if (entities != null) { addEntity(entities, line.getBounds(), dataset, series, item,
g2.setRenderingHint(ChartHints.KEY_BEGIN_ELEMENT, m); info.clear(); info.setChartArea(chartArea); entities = info.getEntityCollection(); entities.add(new JFreeChartEntity((Rectangle2D) chartArea.clone(), this)); Shape savedClip = g2.getClip(); g2.clip(chartArea); g2.addRenderingHints(this.renderingHints); Rectangle2D nonTitleArea = new Rectangle2D.Double(); nonTitleArea.setRect(chartArea); this.padding.trim(nonTitleArea); (entities != null)); if (e != null && entities != null) { entities.addAll(e); (entities != null)); if (e != null && entities != null) { entities.addAll(e); plotInfo = info.getPlotInfo();
EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); Object antiAlias = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); for (int k = 0; k < x.length; k++) { transX = domainAxis.valueToJava2D(x[k], dataArea, RectangleEdge.BOTTOM) - 0.5 * size; transY = rangeAxis.valueToJava2D(y[k], dataArea, RectangleEdge.LEFT) - 0.5 * size; transDX = size; g2.setPaint(colorBar.getPaint(zNumber[k].doubleValue())); g2.fill(rect); (RectangularShape) entityArea.clone(), tip, url); entity.setIndex(k); entities.add(entity);
public void mouseMoved(MouseEvent e) { Graphics2D g2 = (Graphics2D) getGraphics(); g2.dispose(); EntityCollection entities = this.info.getEntityCollection(); if (entities != null) { entity = entities.getEntity(x, y);
Pannable p = (Pannable) this.chart.getPlot(); if (p.getOrientation() == PlotOrientation.VERTICAL) { p.panDomainAxes(wPercent, this.info.getPlotInfo(), this.panLast); p.panRangeAxes(hPercent, this.info.getPlotInfo(), this.panLast); p.panDomainAxes(hPercent, this.info.getPlotInfo(), this.panLast); p.panRangeAxes(wPercent, this.info.getPlotInfo(), this.panLast); this.zoomRectangle = new Rectangle2D.Double( this.zoomPoint.getX(), this.zoomPoint.getY(), xmax - this.zoomPoint.getX(), ymax - this.zoomPoint.getY()); this.zoomRectangle = new Rectangle2D.Double( this.zoomPoint.getX(), scaledDataArea.getMinY(), xmax - this.zoomPoint.getX(), scaledDataArea.getHeight()); this.zoomRectangle = new Rectangle2D.Double( scaledDataArea.getMinX(), this.zoomPoint.getY(), scaledDataArea.getWidth(), ymax - this.zoomPoint.getY()); g2.dispose();
JFreeChart chart = functionWhichRetrievesTheChart(); ChartRenderingInfo info = new ChartRenderingInfo(); // PLOT_SIZE is the size if the graph and has to be the same size as the original drawn chart.createBufferedImage(PLOT_SIZE, PLOT_SIZE, info); graph, otherwise the pixel position points to somewhere else PlotRenderingInfo plotInfo = info.getPlotInfo(); XYPlot plot = (XYPlot)chart.getPlot(); Point p = new Point(x,y); // x and y are the pixel positions // this is the domain value which belongs to the pixel position x double domain = plot.getDomainAxis().java2DToValue(p.getX(), plotInfo.getDataArea(), plot.getDomainAxisEdge()); // this is the range value which belongs to the pixel position y double range = plot.getRangeAxis().java2DToValue(p.getY(), plotInfo.getDataArea(), plot.getRangeAxisEdge());
NumberAxis domain = (NumberAxis) plot.getDomainAxis(); Rectangle2D chartArea = p.getChartRenderingInfo().getPlotInfo() .getDataArea(); Double xval = domain.java2DToValue((double) me.getPoint().x, chartArea, plot.getDomainAxisEdge()); Double yval = plot.getRangeAxis().java2DToValue( (double) me.getPoint().y, chartArea, plot.getRangeAxisEdge());
int rendererIndex, PlotRenderingInfo info) { anchorX = domainAxis.valueToJava2D(this.x, dataArea, domainEdge); anchorY = rangeAxis.valueToJava2D(this.y, dataArea, rangeEdge); Rectangle2D titleRect = new Rectangle2D.Double(0, 0, size.width, size.height); Point2D anchorPoint = this.anchor.getAnchorPoint(titleRect); BlockParams p = new BlockParams(); if (info != null) { if (info.getOwner().getEntityCollection() != null) { p.setGenerateEntities(true); if (result instanceof EntityBlockResult) { EntityBlockResult ebr = (EntityBlockResult) result; info.getOwner().getEntityCollection().addAll( ebr.getEntityCollection());
protected String getTooltipAtPoint(Point point) { XYPlot plot = (XYPlot) getChart().getPlot(); PlotRenderingInfo info = getChartRenderingInfo().getPlotInfo(); double x0 = point.getX(); double x1 = x0 - 2 * getScaleX(); double x2 = x0 + 4 * getScaleX(); ValueAxis domainAxis = plot.getDomainAxis(); Rectangle2D screenArea = scale(info.getDataArea()); double tx1 = domainAxis.java2DToValue(x1, screenArea, BOTTOM); double tx2 = domainAxis.java2DToValue(x2, screenArea, BOTTOM); for (int datasetIndex = 0; datasetIndex < plot.getDatasetCount(); datasetIndex++) { XYDataset dataset = plot.getDataset(datasetIndex); for (int seriesIndex = 0; seriesIndex < dataset.getSeriesCount(); seriesIndex++) { int itemCount = dataset.getItemCount(seriesIndex); for (int itemIndex = 0; itemIndex < itemCount; itemIndex++) { double xValue = dataset.getXValue(seriesIndex, itemIndex); if (tx1 < xValue && xValue < tx2) return toolTipGenerator.generateToolTip(dataset, seriesIndex, itemIndex); } } } return null; } }
/** * A utility method for adding an {@link XYAnnotationEntity} to * a {@link PlotRenderingInfo} instance. * * @param info the plot rendering info ({@code null} permitted). * @param hotspot the hotspot area. * @param rendererIndex the renderer index. * @param toolTipText the tool tip text. * @param urlText the URL text. */ protected void addEntity(PlotRenderingInfo info, Shape hotspot, int rendererIndex, String toolTipText, String urlText) { if (info == null) { return; } EntityCollection entities = info.getOwner().getEntityCollection(); if (entities == null) { return; } XYAnnotationEntity entity = new XYAnnotationEntity(hotspot, rendererIndex, toolTipText, urlText); entities.add(entity); }
@Override public RepresentationResponse producePresentation(DesignOptions options) throws Exception { ChartRenderingInfo renderingInfo = new ChartRenderingInfo(new StandardEntityCollection()); String chartUrl = createChart(options, renderingInfo); Rectangle2D plotArea = renderingInfo.getPlotInfo().getDataArea(); for (Axis axis : renderer.getAxisMapping().values()) { axis.setMaxY(plotArea.getMaxY()); axis.setMinY(plotArea.getMinY()); } ImageEntity[] entities = {}; if (!this.isOverview) { LOGGER.debug("Produced EES diagram " + chartUrl); entities = createImageEntities(renderingInfo.getEntityCollection()); } else { LOGGER.debug("Produced EES Overview diagram " + chartUrl); } Bounds chartArea = new Bounds(plotArea.getMinX(), plotArea.getMaxX(), plotArea.getMinY(), plotArea.getMaxY()); return new EESDataResponse(chartUrl, options, chartArea, entities, renderer.getAxisMapping()); }
ChartRenderingInfo renderingInfo = new ChartRenderingInfo(); EntityCollection entityCollection = renderingInfo.getEntityCollection(); if (entityCollection != null && entityCollection.getEntityCount() > 0) areaHyperlinks = new ArrayList(entityCollection.getEntityCount()); for (Iterator it = entityCollection.iterator(); it.hasNext();)
/** * A convenience method that returns a reference to the entity * collection (may be {@code null}) being used to record * chart entities. * * @return The entity collection (possibly {@code null}). */ public EntityCollection getEntityCollection() { EntityCollection result = null; if (this.info != null) { ChartRenderingInfo owner = this.info.getOwner(); if (owner != null) { result = owner.getEntityCollection(); } } return result; }
/** * Returns the chart entity at a given point. * <P> * This method will return null if there is (a) no entity at the given * point, or (b) no entity collection has been generated. * * @param viewX the x-coordinate. * @param viewY the y-coordinate. * * @return The chart entity (possibly <code>null</code>). */ public ChartEntity getEntityForPoint(int viewX, int viewY) { ChartEntity result = null; if (this.info != null) { Insets insets = getInsets(); double x = (viewX - insets.left) / this.scaleX; double y = (viewY - insets.top) / this.scaleY; EntityCollection entities = this.info.getEntityCollection(); result = entities != null ? entities.getEntity(x, y) : null; } return result; }
private void populateInfo( final ChartRenderingInfo info ) { if ( urlTemplate == null ) { return; } ArrayList seriesListArray = null; Iterator iter = info.getEntityCollection().iterator(); while ( iter.hasNext() ) { ChartEntity entity = (ChartEntity) iter.next(); if ( entity instanceof PieSectionEntity ) { populatePieSectionEntity( (PieSectionEntity) entity ); } else if ( entity instanceof CategoryItemEntity ) { populateCategoryItemEntity( (CategoryItemEntity) entity, seriesListArray ); } } }
/** * Handles a 'click' on the chart. JFreeChart is not a UI component, so * some other object (for example, {@link ChartPanel}) needs to capture * the click event and pass it onto the JFreeChart object. * If you are not using JFreeChart in a client application, then this * method is not required. * * @param x x-coordinate of the click (in Java2D space). * @param y y-coordinate of the click (in Java2D space). * @param info contains chart dimension and entity information * ({@code null} not permitted). */ public void handleClick(int x, int y, ChartRenderingInfo info) { // pass the click on to the plot... // rely on the plot to post a plot change event and redraw the chart... this.plot.handleClick(x, y, info.getPlotInfo()); }
/** * Returns the data area (the area inside the axes) for the plot or subplot, * with the current scaling applied. * * @param x the x-coordinate (for subplot selection). * @param y the y-coordinate (for subplot selection). * * @return The scaled data area. */ public Rectangle2D getScreenDataArea(int x, int y) { PlotRenderingInfo plotInfo = this.info.getPlotInfo(); Rectangle2D result; if (plotInfo.getSubplotCount() == 0) { result = getScreenDataArea(); } else { // get the origin of the zoom selection in the Java2D space used for // drawing the chart (that is, before any scaling to fit the panel) Point2D selectOrigin = translateScreenToJava2D(new Point(x, y)); int subplotIndex = plotInfo.getSubplotIndex(selectOrigin); if (subplotIndex == -1) { return null; } result = scale(plotInfo.getSubplotInfo(subplotIndex).getDataArea()); } return result; }