/** * 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()); }
/** * 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</code> 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 for the chart (the area inside the axes) with the * current scaling applied (that is, the area as it appears on screen). * * @return The scaled data area. */ public Rectangle2D getScreenDataArea() { Rectangle2D dataArea = this.info.getPlotInfo().getDataArea(); Insets insets = getInsets(); double x = dataArea.getX() * this.scaleX + insets.left; double y = dataArea.getY() * this.scaleY + insets.top; double w = dataArea.getWidth() * this.scaleX; double h = dataArea.getHeight() * this.scaleY; return new Rectangle2D.Double(x, y, w, h); }
/** * Returns the data area for the chart (the area inside the axes) with the * current scaling applied (that is, the area as it appears on screen). * * @return The scaled data area. */ public Rectangle2D getScreenDataArea() { Rectangle2D dataArea = this.info.getPlotInfo().getDataArea(); Insets insets = getInsets(); double x = dataArea.getX() * this.scaleX + insets.left; double y = dataArea.getY() * this.scaleY + insets.top; double w = dataArea.getWidth() * this.scaleX; double h = dataArea.getHeight() * this.scaleY; return new Rectangle2D.Double(x, y, w, h); }
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());
@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()); }
/** * Restores the auto-range calculation on the range axis. */ public void restoreAutoRangeBounds() { Plot plot = this.chart.getPlot(); if (plot instanceof Zoomable) { Zoomable z = (Zoomable) plot; // here we tweak the notify flag on the plot so that only // one notification happens even though we update multiple // axes... boolean savedNotify = plot.isNotify(); plot.setNotify(false); // we need to guard against this.zoomPoint being null Point2D zp = (this.zoomPoint != null ? this.zoomPoint : new Point()); z.zoomRangeAxes(0.0, this.info.getPlotInfo(), zp); plot.setNotify(savedNotify); } }
/** * Restores the auto-range calculation on the domain axis. */ public void restoreAutoDomainBounds() { Plot plot = this.chart.getPlot(); if (plot instanceof Zoomable) { Zoomable z = (Zoomable) plot; // here we tweak the notify flag on the plot so that only // one notification happens even though we update multiple // axes... boolean savedNotify = plot.isNotify(); plot.setNotify(false); // we need to guard against this.zoomPoint being null Point2D zp = (this.zoomPoint != null ? this.zoomPoint : new Point()); z.zoomDomainAxes(0.0, this.info.getPlotInfo(), zp); plot.setNotify(savedNotify); } }
/** * Restores the auto-range calculation on the range axis. */ public void restoreAutoRangeBounds() { Plot plot = this.chart.getPlot(); if (plot instanceof Zoomable) { Zoomable z = (Zoomable) plot; // here we tweak the notify flag on the plot so that only // one notification happens even though we update multiple // axes... boolean savedNotify = plot.isNotify(); plot.setNotify(false); // we need to guard against this.zoomPoint being null Point2D zp = (this.zoomPoint != null ? this.zoomPoint : new Point()); z.zoomRangeAxes(0.0, this.info.getPlotInfo(), zp); plot.setNotify(savedNotify); } }
/** * Restores the auto-range calculation on the domain axis. */ public void restoreAutoDomainBounds() { Plot plot = this.chart.getPlot(); if (plot instanceof Zoomable) { Zoomable z = (Zoomable) plot; // here we tweak the notify flag on the plot so that only // one notification happens even though we update multiple // axes... boolean savedNotify = plot.isNotify(); plot.setNotify(false); // we need to guard against this.zoomPoint being null Point2D zp = (this.zoomPoint != null ? this.zoomPoint : new Point()); z.zoomDomainAxes(0.0, this.info.getPlotInfo(), zp); plot.setNotify(savedNotify); } }
/** * Increases the length of the domain axis, centered about the given * coordinate on the screen. The length of the domain axis is increased * by the value of {@link #getZoomOutFactor()}. * * @param x the x coordinate (in screen coordinates). * @param y the y-coordinate (in screen coordinates). */ public void zoomOutDomain(double x, double y) { Plot plot = this.chart.getPlot(); if (plot instanceof Zoomable) { // here we tweak the notify flag on the plot so that only // one notification happens even though we update multiple // axes... boolean savedNotify = plot.isNotify(); plot.setNotify(false); Zoomable z = (Zoomable) plot; z.zoomDomainAxes(this.zoomOutFactor, this.info.getPlotInfo(), translateScreenToJava2D(new Point((int) x, (int) y)), this.zoomAroundAnchor); plot.setNotify(savedNotify); } }
/** * Decreases the length of the domain axis, centered about the given * coordinate on the screen. The length of the domain axis is reduced * by the value of {@link #getZoomInFactor()}. * * @param x the x coordinate (in screen coordinates). * @param y the y-coordinate (in screen coordinates). */ public void zoomInDomain(double x, double y) { Plot plot = this.chart.getPlot(); if (plot instanceof Zoomable) { // here we tweak the notify flag on the plot so that only // one notification happens even though we update multiple // axes... boolean savedNotify = plot.isNotify(); plot.setNotify(false); Zoomable z = (Zoomable) plot; z.zoomDomainAxes(this.zoomInFactor, this.info.getPlotInfo(), translateScreenToJava2D(new Point((int) x, (int) y)), this.zoomAroundAnchor); plot.setNotify(savedNotify); } }
/** * Increases the length the range axis, centered about the given * coordinate on the screen. The length of the range axis is increased * by the value of {@link #getZoomOutFactor()}. * * @param x the x coordinate (in screen coordinates). * @param y the y-coordinate (in screen coordinates). */ public void zoomOutRange(double x, double y) { Plot plot = this.chart.getPlot(); if (plot instanceof Zoomable) { // here we tweak the notify flag on the plot so that only // one notification happens even though we update multiple // axes... boolean savedNotify = plot.isNotify(); plot.setNotify(false); Zoomable z = (Zoomable) plot; z.zoomRangeAxes(this.zoomOutFactor, this.info.getPlotInfo(), translateScreenToJava2D(new Point((int) x, (int) y)), this.zoomAroundAnchor); plot.setNotify(savedNotify); } }
/** * Decreases the length of the range axis, centered about the given * coordinate on the screen. The length of the range axis is reduced by * the value of {@link #getZoomInFactor()}. * * @param x the x-coordinate (in screen coordinates). * @param y the y coordinate (in screen coordinates). */ public void zoomInRange(double x, double y) { Plot plot = this.chart.getPlot(); if (plot instanceof Zoomable) { // here we tweak the notify flag on the plot so that only // one notification happens even though we update multiple // axes... boolean savedNotify = plot.isNotify(); plot.setNotify(false); Zoomable z = (Zoomable) plot; z.zoomRangeAxes(this.zoomInFactor, this.info.getPlotInfo(), translateScreenToJava2D(new Point((int) x, (int) y)), this.zoomAroundAnchor); plot.setNotify(savedNotify); } }
/** * Decreases the length of the domain axis, centered about the given * coordinate on the screen. The length of the domain axis is reduced * by the value of {@link #getZoomInFactor()}. * * @param x the x coordinate (in screen coordinates). * @param y the y-coordinate (in screen coordinates). */ public void zoomInDomain(double x, double y) { Plot plot = this.chart.getPlot(); if (plot instanceof Zoomable) { // here we tweak the notify flag on the plot so that only // one notification happens even though we update multiple // axes... boolean savedNotify = plot.isNotify(); plot.setNotify(false); Zoomable z = (Zoomable) plot; z.zoomDomainAxes(this.zoomInFactor, this.info.getPlotInfo(), translateScreenToJava2D(new Point((int) x, (int) y)), this.zoomAroundAnchor); plot.setNotify(savedNotify); } }
/** * Decreases the length of the range axis, centered about the given * coordinate on the screen. The length of the range axis is reduced by * the value of {@link #getZoomInFactor()}. * * @param x the x-coordinate (in screen coordinates). * @param y the y coordinate (in screen coordinates). */ public void zoomInRange(double x, double y) { Plot plot = this.chart.getPlot(); if (plot instanceof Zoomable) { // here we tweak the notify flag on the plot so that only // one notification happens even though we update multiple // axes... boolean savedNotify = plot.isNotify(); plot.setNotify(false); Zoomable z = (Zoomable) plot; z.zoomRangeAxes(this.zoomInFactor, this.info.getPlotInfo(), translateScreenToJava2D(new Point((int) x, (int) y)), this.zoomAroundAnchor); plot.setNotify(savedNotify); } }
/** * Increases the length of the domain axis, centered about the given * coordinate on the screen. The length of the domain axis is increased * by the value of {@link #getZoomOutFactor()}. * * @param x the x coordinate (in screen coordinates). * @param y the y-coordinate (in screen coordinates). */ public void zoomOutDomain(double x, double y) { Plot plot = this.chart.getPlot(); if (plot instanceof Zoomable) { // here we tweak the notify flag on the plot so that only // one notification happens even though we update multiple // axes... boolean savedNotify = plot.isNotify(); plot.setNotify(false); Zoomable z = (Zoomable) plot; z.zoomDomainAxes(this.zoomOutFactor, this.info.getPlotInfo(), translateScreenToJava2D(new Point((int) x, (int) y)), this.zoomAroundAnchor); plot.setNotify(savedNotify); } }
/** * Increases the length the range axis, centered about the given * coordinate on the screen. The length of the range axis is increased * by the value of {@link #getZoomOutFactor()}. * * @param x the x coordinate (in screen coordinates). * @param y the y-coordinate (in screen coordinates). */ public void zoomOutRange(double x, double y) { Plot plot = this.chart.getPlot(); if (plot instanceof Zoomable) { // here we tweak the notify flag on the plot so that only // one notification happens even though we update multiple // axes... boolean savedNotify = plot.isNotify(); plot.setNotify(false); Zoomable z = (Zoomable) plot; z.zoomRangeAxes(this.zoomOutFactor, this.info.getPlotInfo(), translateScreenToJava2D(new Point((int) x, (int) y)), this.zoomAroundAnchor); plot.setNotify(savedNotify); } }
/** * 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; }
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; } }