/** * Handle the case where a plot implements the {@link Zoomable} interface. * * @param zoomable the zoomable plot. * @param e the mouse wheel event. */ private void handleZoomable(Zoomable zoomable, MouseWheelEvent e) { // don't zoom unless the mouse pointer is in the plot's data area ChartRenderingInfo info = this.chartPanel.getChartRenderingInfo(); PlotRenderingInfo pinfo = info.getPlotInfo(); Point2D p = this.chartPanel.translateScreenToJava2D(e.getPoint()); if (!pinfo.getDataArea().contains(p)) { return; } Plot plot = (Plot) zoomable; // do not notify while zooming each axis boolean notifyState = plot.isNotify(); plot.setNotify(false); int clicks = e.getWheelRotation(); double zf = 1.0 + this.zoomFactor; if (clicks < 0) { zf = 1.0 / zf; } if (chartPanel.isDomainZoomable()) { zoomable.zoomDomainAxes(zf, pinfo, p, true); } if (chartPanel.isRangeZoomable()) { zoomable.zoomRangeAxes(zf, pinfo, p, true); } plot.setNotify(notifyState); // this generates the change event too }
/** * 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; } } } }