예제 #1
0
  /**
   * 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
  }
  /** if a button is pressed ... */
  public void actionPerformed(ActionEvent evt) {
    try {
      String acmd = evt.getActionCommand();

      if (acmd.equals(ACTION_CMD_PRINT)) {

        this.chartPanel.createChartPrintJob();

      } else if (acmd.equals(ACTION_CMD_SAVE_AS)) {

        this.chartPanel.doSaveAs();

      } else if (acmd.equals(ACTION_CMD_ZOOM_IN)) {

        ChartRenderingInfo info = chartPanel.getChartRenderingInfo();
        Rectangle2D rect = info.getChartArea();
        chartPanel.setZoomInFactor(ZOOM_FACTOR);
        chartPanel.zoomInDomain(rect.getCenterX(), rect.getCenterY());
      } else if (acmd.equals(ACTION_CMD_ZOOM_OUT)) {

        ChartRenderingInfo info = chartPanel.getChartRenderingInfo();
        Rectangle2D rect = info.getChartArea();
        chartPanel.setZoomOutFactor(1 / ZOOM_FACTOR);
        chartPanel.zoomOutDomain(rect.getCenterX(), rect.getCenterY());

      } else if (acmd.equals(ACTION_CMD_ZOOM_TO_FIT)) {
        // X-axis (has no fixed borders)
        chartPanel.restoreAutoBounds();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
예제 #3
0
 /**
  * Returns a clone of this object.
  *
  * @return A clone.
  * @throws CloneNotSupportedException if the object cannot be cloned.
  */
 @Override
 public Object clone() throws CloneNotSupportedException {
   ChartRenderingInfo clone = (ChartRenderingInfo) super.clone();
   if (this.chartArea != null) {
     clone.chartArea = (Rectangle2D) this.chartArea.clone();
   }
   if (this.entities instanceof PublicCloneable) {
     PublicCloneable pc = (PublicCloneable) this.entities;
     clone.entities = (EntityCollection) pc.clone();
   }
   return clone;
 }
예제 #4
0
  /**
   * 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();
           }
         }
       }
     }
   }
 }
예제 #6
0
  /**
   * 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;
        }
      }
    }
  }