/**
  * {@inheritDoc}
  *
  * @see org.jfree.chart.urls.CategoryURLGenerator#generateURL(
  *     org.jfree.data.category.CategoryDataset, int, int)
  */
 public String generateURL(CategoryDataset dataset, int series, int category) {
   StringBuffer sb = new StringBuffer("queryForGraphAction.do?bagName=" + bagName);
   sb.append("&category=" + dataset.getColumnKey(category));
   sb.append("&series=" + dataset.getColumnKey(category));
   sb.append("&urlGen=org.intermine.bio.web.widget.HaemAtlasGraphURLGenerator");
   return sb.toString();
 }
  protected void configurePlot(Plot plot, JRChartPlot jrPlot) {

    super.configurePlot(plot, jrPlot);

    if (plot instanceof CategoryPlot) {
      CategoryPlot categoryPlot = (CategoryPlot) plot;
      CategoryItemRenderer categoryRenderer = categoryPlot.getRenderer();
      CategoryDataset categoryDataset = categoryPlot.getDataset();
      if (categoryDataset != null) {
        for (int i = 0; i < categoryDataset.getRowCount(); i++) {
          categoryRenderer.setSeriesOutlinePaint(i, ChartThemesConstants.TRANSPARENT_PAINT);
        }
      }
      categoryPlot.setRangeGridlinePaint(ChartThemesConstants.GRAY_PAINT_217);
      categoryPlot.setRangeGridlineStroke(new BasicStroke(0.5f));
      categoryPlot.setDomainGridlinesVisible(false);
      categoryPlot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    } else if (plot instanceof XYPlot) {
      XYPlot xyPlot = (XYPlot) plot;
      XYItemRenderer xyItemRenderer = xyPlot.getRenderer();
      XYDataset xyDataset = xyPlot.getDataset();
      if (xyDataset != null) {
        for (int i = 0; i < xyDataset.getSeriesCount(); i++) {
          xyItemRenderer.setSeriesOutlinePaint(i, ChartThemesConstants.TRANSPARENT_PAINT);
        }
      }
      xyPlot.setRangeGridlinePaint(ChartThemesConstants.GRAY_PAINT_217);
      xyPlot.setRangeGridlineStroke(new BasicStroke(0.5f));
      xyPlot.setDomainGridlinesVisible(false);
      xyPlot.setRangeZeroBaselineVisible(true);
    }
  }
    /**
     * Creates the array of items that can be passed to the
     * <code>MessageFormat</code> class for creating labels.
     *
     * @param dataset  the dataset (<code>null</code> not permitted).
     * @param row  the row index (zero-based).
     * @param column  the column index (zero-based).
     *
     * @return The items (never <code>null</code>).
     */
    protected Object[] createItemArray(CategoryDataset dataset,
                                       int row, int column) {
        Object[] result = new Object[5];
        result[0] = dataset.getRowKey(row).toString();
        result[1] = dataset.getColumnKey(column).toString();
        Number value = dataset.getValue(row, column);
        if (getNumberFormat() != null) {
            result[2] = getNumberFormat().format(value);
        }
        else if (getDateFormat() != null) {
            result[2] = getDateFormat().format(value);
        }

        if (dataset instanceof IntervalCategoryDataset) {
            IntervalCategoryDataset icd = (IntervalCategoryDataset) dataset;
            Number start = icd.getStartValue(row, column);
            Number end = icd.getEndValue(row, column);
            if (getNumberFormat() != null) {
                result[3] = getNumberFormat().format(start);
                result[4] = getNumberFormat().format(end);
            }
            else if (getDateFormat() != null) {
                result[3] = getDateFormat().format(start);
                result[4] = getDateFormat().format(end);
            }
        }
        return result;
    }
 /**
  * Returns the range of values the renderer requires to display all the items from the specified
  * dataset.
  *
  * @param dataset the dataset (<code>null</code> not permitted).
  * @return The range (or <code>null</code> if the dataset is empty).
  */
 public Range findRangeBounds(CategoryDataset dataset) {
   if (dataset == null) {
     return null;
   }
   boolean allItemsNull = true; // we'll set this to false if there is at
   // least one non-null data item...
   double minimum = 0.0;
   double maximum = 0.0;
   int columnCount = dataset.getColumnCount();
   for (int row = 0; row < dataset.getRowCount(); row++) {
     double runningTotal = 0.0;
     for (int column = 0; column <= columnCount - 1; column++) {
       Number n = dataset.getValue(row, column);
       if (n != null) {
         allItemsNull = false;
         double value = n.doubleValue();
         if (column == columnCount - 1) {
           // treat the last column value as an absolute
           runningTotal = value;
         } else {
           runningTotal = runningTotal + value;
         }
         minimum = Math.min(minimum, runningTotal);
         maximum = Math.max(maximum, runningTotal);
       }
     }
   }
   if (!allItemsNull) {
     return new Range(minimum, maximum);
   } else {
     return null;
   }
 }
Ejemplo n.º 5
0
 public String generateLabel(CategoryDataset dataset, int series, int category) {
   Comparable<?> seriesName = dataset.getRowKey(series);
   Map<Comparable<?>, String> labels = labelsMap.get(seriesName);
   if (labels != null) {
     return labels.get(dataset.getColumnKey(category));
   }
   return super.generateLabel(dataset, series, category);
 }
Ejemplo n.º 6
0
  public Paint getItemPaint(int row, int column) {
    CategoryDataset cd = getPlot().getDataset();
    if (cd != null) {
      String s_rowKey = (String) cd.getRowKey(row);
      double rowKey = Double.parseDouble(s_rowKey);
      return rowKey == 1.0
          ? Color.RED
          : (rowKey == 2.0 ? Color.YELLOW : (rowKey == 3.0 ? Color.GREEN : Color.PINK));
    }

    return Color.WHITE;
  }
  public String generateToolTip(CategoryDataset dataset, int row, int column) {
    String r = dataset.getRowKey(row).toString();
    String c = dataset.getColumnKey(column).toString();
    String both = r + "," + c;
    if (StringUtil.isEmpty(r)) both = c;
    if (StringUtil.isEmpty(c)) both = r;

    return LabelFormatUtil.format(labelFormat, dataset.getValue(row, column).doubleValue())
        + " ("
        + both
        + ")";
  }
 protected JFreeChart createStackedBar3DChart() throws JRException {
   JFreeChart jfreeChart = super.createStackedBar3DChart();
   CategoryPlot categoryPlot = (CategoryPlot) jfreeChart.getPlot();
   BarRenderer3D barRenderer3D = (BarRenderer3D) categoryPlot.getRenderer();
   barRenderer3D.setWallPaint(ChartThemesConstants.TRANSPARENT_PAINT);
   barRenderer3D.setItemMargin(0);
   CategoryDataset categoryDataset = categoryPlot.getDataset();
   if (categoryDataset != null) {
     for (int i = 0; i < categoryDataset.getRowCount(); i++) {
       barRenderer3D.setSeriesOutlinePaint(i, ChartThemesConstants.TRANSPARENT_PAINT);
     }
   }
   return jfreeChart;
 }
  public void createChart() {

    CategoryDataset categorydataset = (CategoryDataset) this.datasetStrategy.getDataset();
    report =
        ChartFactory.createStackedBarChart(
            this.datasetStrategy.getTitle(),
            this.datasetStrategy.getYAxisLabel(),
            this.datasetStrategy.getXAxisLabel(),
            categorydataset,
            PlotOrientation.HORIZONTAL,
            true,
            true,
            false);
    // report.setBackgroundPaint( Color.lightGray );
    report.setAntiAlias(false);
    report.setPadding(new RectangleInsets(5.0d, 5.0d, 5.0d, 5.0d));
    CategoryPlot categoryplot = (CategoryPlot) report.getPlot();
    categoryplot.setBackgroundPaint(Color.white);
    categoryplot.setRangeGridlinePaint(Color.lightGray);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    if (datasetStrategy instanceof CloverBarChartStrategy
        || datasetStrategy instanceof MultiCloverBarChartStrategy) {
      numberaxis.setRange(0.0D, StackedBarChartRenderer.NUMBER_AXIS_RANGE);
      numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance());
    } else {
      numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }
    numberaxis.setLowerMargin(0.0D);
    StackedBarRenderer stackedbarrenderer = (StackedBarRenderer) categoryplot.getRenderer();
    stackedbarrenderer.setDrawBarOutline(false);
    stackedbarrenderer.setItemLabelsVisible(true);
    stackedbarrenderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    stackedbarrenderer.setItemLabelFont(
        StackedBarRenderer.DEFAULT_VALUE_LABEL_FONT.deriveFont(Font.BOLD));
    int height =
        (categorydataset.getColumnCount() * ChartUtils.STANDARD_BARCHART_ENTRY_HEIGHT * 2)
            + ChartUtils.STANDARD_BARCHART_ADDITIONAL_HEIGHT
            + 10;
    if (height > ChartUtils.MINIMUM_HEIGHT) {
      super.setHeight(height);
    } else {
      super.setHeight(ChartUtils.MINIMUM_HEIGHT);
    }
    Paint[] paints = this.datasetStrategy.getPaintColor();

    for (int i = 0; i < categorydataset.getRowCount() && i < paints.length; i++) {
      stackedbarrenderer.setSeriesPaint(i, paints[i]);
    }
  }
  protected JFreeChart createGanttChart() throws JRException {

    JFreeChart jfreeChart = super.createGanttChart();
    CategoryPlot categoryPlot = (CategoryPlot) jfreeChart.getPlot();
    categoryPlot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.STANDARD);
    categoryPlot.setDomainGridlinesVisible(true);
    categoryPlot.setDomainGridlinePosition(CategoryAnchor.END);
    categoryPlot.setDomainGridlineStroke(
        new BasicStroke(
            0.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 50, new float[] {1}, 0));

    categoryPlot.setDomainGridlinePaint(ChartThemesConstants.GRAY_PAINT_217);

    categoryPlot.setRangeGridlinesVisible(true);
    categoryPlot.setRangeGridlineStroke(
        new BasicStroke(
            0.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 50, new float[] {1}, 0));

    categoryPlot.setRangeGridlinePaint(ChartThemesConstants.GRAY_PAINT_217);
    //		JRBarPlot barPlot = (BarPlot)categoryPlot;
    //		categoryPlot.getDomainAxis().setTickLabelsVisible(
    //				categoryPlot.getShowTickLabels() == null ? true : barPlot.getShowTickLabels().
    //				true
    //				);
    CategoryItemRenderer categoryRenderer = categoryPlot.getRenderer();
    categoryRenderer.setBaseItemLabelsVisible(true);
    BarRenderer barRenderer = (BarRenderer) categoryRenderer;
    List seriesPaints =
        (List) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.SERIES_COLORS);
    barRenderer.setSeriesPaint(0, (Paint) seriesPaints.get(3));
    barRenderer.setSeriesPaint(1, (Paint) seriesPaints.get(0));
    CategoryDataset categoryDataset = categoryPlot.getDataset();
    if (categoryDataset != null) {
      for (int i = 0; i < categoryDataset.getRowCount(); i++) {
        barRenderer.setSeriesItemLabelFont(i, categoryPlot.getDomainAxis().getTickLabelFont());
        barRenderer.setSeriesItemLabelsVisible(i, true);
        //			barRenderer.setSeriesPaint(i, GRADIENT_PAINTS[i]);
        //			CategoryMarker categoryMarker = new
        // CategoryMarker(categoryDataset.getColumnKey(i),MARKER_COLOR, new BasicStroke(1f));
        //			categoryMarker.setAlpha(0.5f);
        //			categoryPlot.addDomainMarker(categoryMarker, Layer.BACKGROUND);
      }
    }
    categoryPlot.setOutlinePaint(Color.DARK_GRAY);
    categoryPlot.setOutlineStroke(new BasicStroke(1.5f));
    categoryPlot.setOutlineVisible(true);
    return jfreeChart;
  }
Ejemplo n.º 11
0
  /**
   * Initialises the renderer. This method gets called once at the start of the process of drawing a
   * chart.
   *
   * @param g2 the graphics device.
   * @param dataArea the area in which the data is to be plotted.
   * @param plot the plot.
   * @param rendererIndex the renderer index.
   * @param info collects chart rendering information for return to caller.
   * @return The renderer state.
   */
  public CategoryItemRendererState initialise(
      Graphics2D g2,
      Rectangle2D dataArea,
      CategoryPlot plot,
      int rendererIndex,
      PlotRenderingInfo info) {

    CategoryItemRendererState state = super.initialise(g2, dataArea, plot, rendererIndex, info);

    // calculate the box width
    CategoryAxis domainAxis = getDomainAxis(plot, rendererIndex);
    CategoryDataset dataset = plot.getDataset(rendererIndex);
    if (dataset != null) {
      int columns = dataset.getColumnCount();
      int rows = dataset.getRowCount();
      double space = 0.0;
      PlotOrientation orientation = plot.getOrientation();
      if (orientation == PlotOrientation.HORIZONTAL) {
        space = dataArea.getHeight();
      } else if (orientation == PlotOrientation.VERTICAL) {
        space = dataArea.getWidth();
      }
      double maxWidth = space * getMaximumBarWidth();
      double categoryMargin = 0.0;
      double currentItemMargin = 0.0;
      if (columns > 1) {
        categoryMargin = domainAxis.getCategoryMargin();
      }
      if (rows > 1) {
        currentItemMargin = getItemMargin();
      }
      double used =
          space
              * (1
                  - domainAxis.getLowerMargin()
                  - domainAxis.getUpperMargin()
                  - categoryMargin
                  - currentItemMargin);
      if ((rows * columns) > 0) {
        state.setBarWidth(
            Math.min(used / (dataset.getColumnCount() * dataset.getRowCount()), maxWidth));
      } else {
        state.setBarWidth(Math.min(used, maxWidth));
      }
    }

    return state;
  }
Ejemplo n.º 12
0
 private JFreeChart createChart(CategoryDataset setCategory) {
   JFreeChart chart =
       ChartFactory.createBarChart(
           this.chartTitle, "", "", setCategory, PlotOrientation.VERTICAL, true, true, false);
   CategoryPlot plot = (CategoryPlot) chart.getPlot();
   plot.addRangeMarker(ChartUtil.getAverageMarker(this.average), Layer.FOREGROUND);
   BookModel model = this.mainFrame.getBookModel();
   Session session = model.beginTransaction();
   StrandDAOImpl daoStrand = new StrandDAOImpl(session);
   List strands = daoStrand.findAll();
   model.commit();
   Color[] colors = new Color[strands.size()];
   int i = 0;
   Object iObject = strands.iterator();
   while (((Iterator) iObject).hasNext()) {
     Strand strand = (Strand) ((Iterator) iObject).next();
     colors[i] = ColorUtil.darker(strand.getJColor(), 0.25D);
     i++;
   }
   iObject = (BarRenderer) plot.getRenderer();
   for (int j = 0; j < setCategory.getRowCount(); j++) {
     Color color = colors[(j % colors.length)];
     ((BarRenderer) iObject).setSeriesPaint(j, color);
   }
   return chart;
 }
  /**
   * Initialises the renderer and returns a state object that will be used for the remainder of the
   * drawing process for a single chart. The state object allows for the fact that the renderer may
   * be used simultaneously by multiple threads (each thread will work with a separate state
   * object).
   *
   * <p>Stores a reference to the {@link PlotRenderingInfo} object (which might be <code>null</code>
   * ), and then sets the useCategoriesPaint flag according to the special case conditions a) there
   * is only one series and b) the categoriesPaint array is not null.
   *
   * @param g2 the graphics device.
   * @param dataArea the data area.
   * @param plot the plot.
   * @param rendererIndex the renderer index.
   * @param info an object for returning information about the structure of the plot (<code>null
   *     </code> permitted).
   * @return The renderer state.
   */
  public CategoryItemRendererState initialise(
      Graphics2D g2,
      Rectangle2D dataArea,
      CategoryPlot plot,
      int rendererIndex,
      PlotRenderingInfo info) {

    setPlot(plot);
    CategoryDataset data = plot.getDataset(rendererIndex);
    if (data != null) {
      this.rowCount = data.getRowCount();
      this.columnCount = data.getColumnCount();
    } else {
      this.rowCount = 0;
      this.columnCount = 0;
    }
    return new CategoryItemRendererState(info);
  }
Ejemplo n.º 14
0
 @Override
 public ChartView.Element getElementAt(int x, int y) {
   ChartView.Element element = new ChartView.Element(0, 0);
   ChartEntity chartEntity = getChartEntityAt(x, y);
   if (chartEntity instanceof CategoryItemEntity) {
     CategoryItemEntity categoryItemEntity = (CategoryItemEntity) chartEntity;
     CategoryDataset dataset = categoryItemEntity.getDataset();
     String columnKey = (String) categoryItemEntity.getColumnKey();
     int columnIndex = dataset.getColumnIndex(columnKey);
     String rowKey = (String) categoryItemEntity.getRowKey();
     int rowIndex = dataset.getRowIndex(rowKey);
     element = new ChartView.Element(rowIndex, columnIndex);
   } else if (chartEntity instanceof XYItemEntity) {
     XYItemEntity xyItemEntity = (XYItemEntity) chartEntity;
     element = new ChartView.Element(xyItemEntity.getSeriesIndex(), xyItemEntity.getItem());
   }
   return element;
 }
Ejemplo n.º 15
0
  /**
   * Returns a legend item for a series.
   *
   * @param datasetIndex the dataset index (zero-based).
   * @param series the series index (zero-based).
   * @return The legend item.
   */
  @Override
  public LegendItem getLegendItem(int datasetIndex, int series) {

    // if there is no plot, there is no dataset to access...
    CategoryPlot cp = getPlot();
    if (cp == null) {
      return null;
    }

    // check that a legend item needs to be displayed...
    if (!isSeriesVisible(series) || !isSeriesVisibleInLegend(series)) {
      return null;
    }

    CategoryDataset dataset = cp.getDataset(datasetIndex);
    String label = getLegendItemLabelGenerator().generateLabel(dataset, series);
    String description = label;
    String toolTipText = null;
    if (getLegendItemToolTipGenerator() != null) {
      toolTipText = getLegendItemToolTipGenerator().generateLabel(dataset, series);
    }
    String urlText = null;
    if (getLegendItemURLGenerator() != null) {
      urlText = getLegendItemURLGenerator().generateLabel(dataset, series);
    }
    Shape shape = lookupLegendShape(series);
    Paint paint = lookupSeriesPaint(series);
    Paint outlinePaint = lookupSeriesOutlinePaint(series);
    Stroke outlineStroke = lookupSeriesOutlineStroke(series);

    LegendItem result =
        new LegendItem(
            label, description, toolTipText, urlText, shape, paint, outlineStroke, outlinePaint);
    result.setLabelFont(lookupLegendTextFont(series));
    Paint labelPaint = lookupLegendTextPaint(series);
    if (labelPaint != null) {
      result.setLabelPaint(labelPaint);
    }
    result.setDataset(dataset);
    result.setDatasetIndex(datasetIndex);
    result.setSeriesKey(dataset.getRowKey(series));
    result.setSeriesIndex(series);
    return result;
  }
 /**
  * Returns a (possibly empty) collection of legend items for the series that this renderer is
  * responsible for drawing.
  *
  * @return The legend item collection (never <code>null</code>).
  */
 public LegendItemCollection getLegendItems() {
   if (this.plot == null) {
     return new LegendItemCollection();
   }
   LegendItemCollection result = new LegendItemCollection();
   int index = this.plot.getIndexOf(this);
   CategoryDataset dataset = this.plot.getDataset(index);
   if (dataset != null) {
     int seriesCount = dataset.getRowCount();
     for (int i = 0; i < seriesCount; i++) {
       if (isSeriesVisibleInLegend(i)) {
         LegendItem item = getLegendItem(index, i);
         if (item != null) {
           result.add(item);
         }
       }
     }
   }
   return result;
 }
 /**
  * @see
  *     org.jfree.chart.labels.CategoryToolTipGenerator#generateToolTip(org.jfree.data.category.CategoryDataset,
  *     int, int) {@inheritDoc}
  */
 public String generateToolTip(CategoryDataset pCategory, int pRowIndex, int pColumIndex) {
   String result = "";
   if (pRowIndex < AbstractRepartitionMaker.NB_SERIES_FOR_FLOAT_GRAPH - 1) {
     result =
         "("
             + pCategory.getRowKey(pRowIndex)
             + ","
             + pCategory.getRowKey(pRowIndex + 1)
             + ")="
             + pCategory.getValue(pRowIndex, pColumIndex);
   } else {
     result =
         "("
             + pCategory.getRowKey(pRowIndex)
             + ",3.0"
             + ")="
             + pCategory.getValue(pRowIndex, pColumIndex);
   }
   return result;
 }
  /**
   * Creates the array of items that can be passed to the {@link MessageFormat} class for creating
   * labels.
   *
   * @param dataset the dataset (<code>null</code> not permitted).
   * @param row the row index (zero-based).
   * @param column the column index (zero-based).
   * @return The items (never <code>null</code>).
   */
  protected Object[] createItemArray(CategoryDataset dataset, int row, int column) {
    Object[] result = new Object[4];
    result[0] = dataset.getRowKey(row).toString();
    result[1] = dataset.getColumnKey(column).toString();
    Number value = dataset.getValue(row, column);
    if (value != null) {
      if (this.numberFormat != null) {
        result[2] = this.numberFormat.format(value);
      } else if (this.dateFormat != null) {
        result[2] = this.dateFormat.format(value);
      }
    } else {
      result[2] = this.nullValueString;
    }
    if (value != null) {
      double total = DataUtilities.calculateColumnTotal(dataset, column);
      double percent = value.doubleValue() / total;
      result[3] = this.percentFormat.format(percent);
    }

    return result;
  }
  /**
   * Returns the middle coordinate (in Java2D space) for a series within a category.
   *
   * @param category the category (<code>null</code> not permitted).
   * @param seriesKey the series key (<code>null</code> not permitted).
   * @param dataset the dataset (<code>null</code> not permitted).
   * @param itemMargin the item margin (0.0 <= itemMargin < 1.0);
   * @param area the area (<code>null</code> not permitted).
   * @param edge the edge (<code>null</code> not permitted).
   * @return The coordinate in Java2D space.
   * @since 1.0.7
   */
  public double getCategorySeriesMiddle(
      Comparable category,
      Comparable seriesKey,
      CategoryDataset dataset,
      double itemMargin,
      Rectangle2D area,
      RectangleEdge edge) {

    int categoryIndex = dataset.getColumnIndex(category);
    int categoryCount = dataset.getColumnCount();
    int seriesIndex = dataset.getRowIndex(seriesKey);
    int seriesCount = dataset.getRowCount();
    double start = getCategoryStart(categoryIndex, categoryCount, area, edge);
    double end = getCategoryEnd(categoryIndex, categoryCount, area, edge);
    double width = end - start;
    if (seriesCount == 1) {
      return start + width / 2.0;
    }
    double gap = (width * itemMargin) / (seriesCount - 1);
    double ww = (width * (1 - itemMargin)) / seriesCount;
    return start + (seriesIndex * (ww + gap)) + ww / 2.0;
  }
Ejemplo n.º 20
0
  /**
   * Creates a new plot with a given dataset and paint maps.
   *
   * @param dataset The dataset.
   * @param paintMaps The paint maps..
   */
  public ChartMultiplePiePlot(CategoryDataset dataset, PaintMaps paintMaps) {
    super(dataset);

    this.paintMaps = paintMaps;
    this.sectionPaints = new HashMap();
    this.drawingSupplier = new DefaultDrawingSupplier();

    this.baseItemLabelGenerator = new StandardCategoryItemLabelGenerator();
    this.legendItemLabelGenerator = new StandardCategoryItemLabelGenerator();

    // important: listen to change events from dataset
    dataset.addChangeListener(this);
  }
  /**
   * Returns a legend item for a series.
   *
   * @param datasetIndex the dataset index (zero-based).
   * @param series the series index (zero-based).
   * @return The legend item.
   */
  public LegendItem getLegendItem(int datasetIndex, int series) {

    CategoryPlot p = getPlot();
    if (p == null) {
      return null;
    }

    // check that a legend item needs to be displayed...
    if (!isSeriesVisible(series) || !isSeriesVisibleInLegend(series)) {
      return null;
    }

    CategoryDataset dataset = p.getDataset(datasetIndex);
    String label = getLegendItemLabelGenerator().generateLabel(dataset, series);
    String description = label;
    String toolTipText = null;
    if (getLegendItemToolTipGenerator() != null) {
      toolTipText = getLegendItemToolTipGenerator().generateLabel(dataset, series);
    }
    String urlText = null;
    if (getLegendItemURLGenerator() != null) {
      urlText = getLegendItemURLGenerator().generateLabel(dataset, series);
    }
    Shape shape = lookupLegendShape(series);
    Paint paint = lookupSeriesPaint(series);

    LegendItem item = new LegendItem(label, description, toolTipText, urlText, shape, paint);
    item.setLabelFont(lookupLegendTextFont(series));
    Paint labelPaint = lookupLegendTextPaint(series);
    if (labelPaint != null) {
      item.setLabelPaint(labelPaint);
    }
    item.setSeriesKey(dataset.getRowKey(series));
    item.setSeriesIndex(series);
    item.setDataset(dataset);
    item.setDatasetIndex(datasetIndex);
    return item;
  }
  /**
   * Adds an entity with the specified hotspot, but only if an entity collection is accessible via
   * the renderer state.
   *
   * @param entities the entity collection.
   * @param dataset the dataset.
   * @param row the row index.
   * @param column the column index.
   * @param hotspot the hotspot.
   */
  protected void addItemEntity(
      EntityCollection entities, CategoryDataset dataset, int row, int column, Shape hotspot) {

    String tip = null;
    CategoryToolTipGenerator tipster = getToolTipGenerator(row, column);
    if (tipster != null) {
      tip = tipster.generateToolTip(dataset, row, column);
    }
    String url = null;
    CategoryURLGenerator urlster = getItemURLGenerator(row, column);
    if (urlster != null) {
      url = urlster.generateURL(dataset, row, column);
    }
    CategoryItemEntity entity =
        new CategoryItemEntity(
            hotspot, tip, url, dataset, row, dataset.getColumnKey(column), column);
    entities.add(entity);
  }
 /**
  * Creates the array of items that can be passed to the {@link MessageFormat} class for creating
  * labels.
  *
  * @param dataset the dataset (<code>null</code> not permitted).
  * @param series the series (zero-based index).
  * @return The items (never <code>null</code>).
  */
 protected Object[] createItemArray(CategoryDataset dataset, int series) {
   Object[] result = new Object[1];
   result[0] = dataset.getRowKey(series).toString();
   return result;
 }
Ejemplo n.º 24
0
  /**
   * Draw a single data item.
   *
   * @param g2 the graphics device.
   * @param state the renderer state.
   * @param dataArea the area in which the data is drawn.
   * @param plot the plot.
   * @param domainAxis the domain axis.
   * @param rangeAxis the range axis.
   * @param dataset the dataset.
   * @param row the row index (zero-based).
   * @param column the column index (zero-based).
   * @param pass the pass index.
   */
  @Override
  public void drawItem(
      Graphics2D g2,
      CategoryItemRendererState state,
      Rectangle2D dataArea,
      CategoryPlot plot,
      CategoryAxis domainAxis,
      ValueAxis rangeAxis,
      CategoryDataset dataset,
      int row,
      int column,
      int pass) {

    if (!getItemVisible(row, column)) {
      return;
    }

    // nothing is drawn for null...
    Number v = dataset.getValue(row, column);
    if (v == null) {
      return;
    }

    Rectangle2D adjusted =
        new Rectangle2D.Double(
            dataArea.getX(),
            dataArea.getY() + getYOffset(),
            dataArea.getWidth() - getXOffset(),
            dataArea.getHeight() - getYOffset());

    PlotOrientation orientation = plot.getOrientation();

    // current data point...
    double x1 =
        domainAxis.getCategoryMiddle(column, getColumnCount(), adjusted, plot.getDomainAxisEdge());
    double value = v.doubleValue();
    double y1 = rangeAxis.valueToJava2D(value, adjusted, plot.getRangeAxisEdge());

    Shape shape = getItemShape(row, column);
    if (orientation == PlotOrientation.HORIZONTAL) {
      shape = ShapeUtilities.createTranslatedShape(shape, y1, x1);
    } else if (orientation == PlotOrientation.VERTICAL) {
      shape = ShapeUtilities.createTranslatedShape(shape, x1, y1);
    }

    if (pass == 0 && getItemLineVisible(row, column)) {
      if (column != 0) {

        Number previousValue = dataset.getValue(row, column - 1);
        if (previousValue != null) {

          // previous data point...
          double previous = previousValue.doubleValue();
          double x0 =
              domainAxis.getCategoryMiddle(
                  column - 1, getColumnCount(), adjusted, plot.getDomainAxisEdge());
          double y0 = rangeAxis.valueToJava2D(previous, adjusted, plot.getRangeAxisEdge());

          double x2 = x0 + getXOffset();
          double y2 = y0 - getYOffset();
          double x3 = x1 + getXOffset();
          double y3 = y1 - getYOffset();

          GeneralPath clip = new GeneralPath();

          if (orientation == PlotOrientation.HORIZONTAL) {
            clip.moveTo((float) y0, (float) x0);
            clip.lineTo((float) y1, (float) x1);
            clip.lineTo((float) y3, (float) x3);
            clip.lineTo((float) y2, (float) x2);
            clip.lineTo((float) y0, (float) x0);
            clip.closePath();
          } else if (orientation == PlotOrientation.VERTICAL) {
            clip.moveTo((float) x0, (float) y0);
            clip.lineTo((float) x1, (float) y1);
            clip.lineTo((float) x3, (float) y3);
            clip.lineTo((float) x2, (float) y2);
            clip.lineTo((float) x0, (float) y0);
            clip.closePath();
          }

          g2.setPaint(getItemPaint(row, column));
          g2.fill(clip);
          g2.setStroke(getItemOutlineStroke(row, column));
          g2.setPaint(getItemOutlinePaint(row, column));
          g2.draw(clip);
        }
      }
    }

    // draw the item label if there is one...
    if (pass == 1 && isItemLabelVisible(row, column)) {
      if (orientation == PlotOrientation.HORIZONTAL) {
        drawItemLabel(g2, orientation, dataset, row, column, y1, x1, (value < 0.0));
      } else if (orientation == PlotOrientation.VERTICAL) {
        drawItemLabel(g2, orientation, dataset, row, column, x1, y1, (value < 0.0));
      }
    }

    // add an item entity, if this information is being collected
    EntityCollection entities = state.getEntityCollection();
    if (entities != null) {
      addItemEntity(entities, dataset, row, column, shape);
    }
  }
  /**
   * Draw a single data item.
   *
   * @param g2 the graphics device.
   * @param state the renderer state.
   * @param dataArea the area in which the data is drawn.
   * @param plot the plot.
   * @param domainAxis the domain axis.
   * @param rangeAxis the range axis.
   * @param dataset the dataset (a {@link StatisticalCategoryDataset} is required).
   * @param row the row index (zero-based).
   * @param column the column index (zero-based).
   * @param pass the pass.
   */
  @Override
  public void drawItem(
      Graphics2D g2,
      CategoryItemRendererState state,
      Rectangle2D dataArea,
      CategoryPlot plot,
      CategoryAxis domainAxis,
      ValueAxis rangeAxis,
      CategoryDataset dataset,
      int row,
      int column,
      int pass) {

    // do nothing if item is not visible
    if (!getItemVisible(row, column)) {
      return;
    }

    // if the dataset is not a StatisticalCategoryDataset then just revert
    // to the superclass (LineAndShapeRenderer) behaviour...
    if (!(dataset instanceof StatisticalCategoryDataset)) {
      super.drawItem(g2, state, dataArea, plot, domainAxis, rangeAxis, dataset, row, column, pass);
      return;
    }

    int visibleRow = state.getVisibleSeriesIndex(row);
    if (visibleRow < 0) {
      return;
    }
    int visibleRowCount = state.getVisibleSeriesCount();

    StatisticalCategoryDataset statDataset = (StatisticalCategoryDataset) dataset;
    Number meanValue = statDataset.getMeanValue(row, column);
    if (meanValue == null) {
      return;
    }
    PlotOrientation orientation = plot.getOrientation();

    // current data point...
    double x1;
    if (getUseSeriesOffset()) {
      x1 =
          domainAxis.getCategorySeriesMiddle(
              column,
              dataset.getColumnCount(),
              visibleRow,
              visibleRowCount,
              getItemMargin(),
              dataArea,
              plot.getDomainAxisEdge());
    } else {
      x1 =
          domainAxis.getCategoryMiddle(
              column, getColumnCount(), dataArea, plot.getDomainAxisEdge());
    }
    double y1 = rangeAxis.valueToJava2D(meanValue.doubleValue(), dataArea, plot.getRangeAxisEdge());

    // draw the standard deviation lines *before* the shapes (if they're
    // visible) - it looks better if the shape fill colour is different to
    // the line colour
    Number sdv = statDataset.getStdDevValue(row, column);
    if (pass == 1 && sdv != null) {
      // standard deviation lines
      RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
      double valueDelta = sdv.doubleValue();
      double highVal, lowVal;
      if ((meanValue.doubleValue() + valueDelta) > rangeAxis.getRange().getUpperBound()) {
        highVal =
            rangeAxis.valueToJava2D(rangeAxis.getRange().getUpperBound(), dataArea, yAxisLocation);
      } else {
        highVal =
            rangeAxis.valueToJava2D(meanValue.doubleValue() + valueDelta, dataArea, yAxisLocation);
      }

      if ((meanValue.doubleValue() + valueDelta) < rangeAxis.getRange().getLowerBound()) {
        lowVal =
            rangeAxis.valueToJava2D(rangeAxis.getRange().getLowerBound(), dataArea, yAxisLocation);
      } else {
        lowVal =
            rangeAxis.valueToJava2D(meanValue.doubleValue() - valueDelta, dataArea, yAxisLocation);
      }

      if (this.errorIndicatorPaint != null) {
        g2.setPaint(this.errorIndicatorPaint);
      } else {
        g2.setPaint(getItemPaint(row, column));
      }
      if (this.errorIndicatorStroke != null) {
        g2.setStroke(this.errorIndicatorStroke);
      } else {
        g2.setStroke(getItemOutlineStroke(row, column));
      }
      Line2D line = new Line2D.Double();
      if (orientation == PlotOrientation.HORIZONTAL) {
        line.setLine(lowVal, x1, highVal, x1);
        g2.draw(line);
        line.setLine(lowVal, x1 - 5.0d, lowVal, x1 + 5.0d);
        g2.draw(line);
        line.setLine(highVal, x1 - 5.0d, highVal, x1 + 5.0d);
        g2.draw(line);
      } else { // PlotOrientation.VERTICAL
        line.setLine(x1, lowVal, x1, highVal);
        g2.draw(line);
        line.setLine(x1 - 5.0d, highVal, x1 + 5.0d, highVal);
        g2.draw(line);
        line.setLine(x1 - 5.0d, lowVal, x1 + 5.0d, lowVal);
        g2.draw(line);
      }
    }

    Shape hotspot = null;
    if (pass == 1 && getItemShapeVisible(row, column)) {
      Shape shape = getItemShape(row, column);
      if (orientation == PlotOrientation.HORIZONTAL) {
        shape = ShapeUtilities.createTranslatedShape(shape, y1, x1);
      } else if (orientation == PlotOrientation.VERTICAL) {
        shape = ShapeUtilities.createTranslatedShape(shape, x1, y1);
      }
      hotspot = shape;

      if (getItemShapeFilled(row, column)) {
        if (getUseFillPaint()) {
          g2.setPaint(getItemFillPaint(row, column));
        } else {
          g2.setPaint(getItemPaint(row, column));
        }
        g2.fill(shape);
      }
      if (getDrawOutlines()) {
        if (getUseOutlinePaint()) {
          g2.setPaint(getItemOutlinePaint(row, column));
        } else {
          g2.setPaint(getItemPaint(row, column));
        }
        g2.setStroke(getItemOutlineStroke(row, column));
        g2.draw(shape);
      }
      // draw the item label if there is one...
      if (isItemLabelVisible(row, column)) {
        if (orientation == PlotOrientation.HORIZONTAL) {
          drawItemLabel(
              g2, orientation, dataset, row, column, y1, x1, (meanValue.doubleValue() < 0.0));
        } else if (orientation == PlotOrientation.VERTICAL) {
          drawItemLabel(
              g2, orientation, dataset, row, column, x1, y1, (meanValue.doubleValue() < 0.0));
        }
      }
    }

    if (pass == 0 && getItemLineVisible(row, column)) {
      if (column != 0) {

        Number previousValue = statDataset.getValue(row, column - 1);
        if (previousValue != null) {

          // previous data point...
          double previous = previousValue.doubleValue();
          double x0;
          if (getUseSeriesOffset()) {
            x0 =
                domainAxis.getCategorySeriesMiddle(
                    column - 1,
                    dataset.getColumnCount(),
                    visibleRow,
                    visibleRowCount,
                    getItemMargin(),
                    dataArea,
                    plot.getDomainAxisEdge());
          } else {
            x0 =
                domainAxis.getCategoryMiddle(
                    column - 1, getColumnCount(), dataArea, plot.getDomainAxisEdge());
          }
          double y0 = rangeAxis.valueToJava2D(previous, dataArea, plot.getRangeAxisEdge());

          Line2D line = null;
          if (orientation == PlotOrientation.HORIZONTAL) {
            line = new Line2D.Double(y0, x0, y1, x1);
          } else if (orientation == PlotOrientation.VERTICAL) {
            line = new Line2D.Double(x0, y0, x1, y1);
          }
          g2.setPaint(getItemPaint(row, column));
          g2.setStroke(getItemStroke(row, column));
          g2.draw(line);
        }
      }
    }

    if (pass == 1) {
      // add an item entity, if this information is being collected
      EntityCollection entities = state.getEntityCollection();
      if (entities != null) {
        addEntity(entities, hotspot, dataset, row, column, x1, y1);
      }
    }
  }
  /**
   * Draws the bar for a single (series, category) data item.
   *
   * @param g2 the graphics device.
   * @param state the renderer state.
   * @param dataArea the data area.
   * @param plot the plot.
   * @param domainAxis the domain axis.
   * @param rangeAxis the range axis.
   * @param dataset the dataset.
   * @param row the row index (zero-based).
   * @param column the column index (zero-based).
   * @param pass the pass index.
   */
  public void drawItem(
      Graphics2D g2,
      CategoryItemRendererState state,
      Rectangle2D dataArea,
      CategoryPlot plot,
      CategoryAxis domainAxis,
      ValueAxis rangeAxis,
      CategoryDataset dataset,
      int row,
      int column,
      int pass) {

    double previous = state.getSeriesRunningTotal();
    if (column == dataset.getColumnCount() - 1) {
      previous = 0.0;
    }
    double current = 0.0;
    Number n = dataset.getValue(row, column);
    if (n != null) {
      current = previous + n.doubleValue();
    }
    state.setSeriesRunningTotal(current);

    int categoryCount = getColumnCount();
    PlotOrientation orientation = plot.getOrientation();

    double rectX = 0.0;
    double rectY = 0.0;

    RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge();

    // Y0
    double j2dy0 = rangeAxis.valueToJava2D(previous, dataArea, rangeAxisLocation);

    // Y1
    double j2dy1 = rangeAxis.valueToJava2D(current, dataArea, rangeAxisLocation);

    double valDiff = current - previous;
    if (j2dy1 < j2dy0) {
      double temp = j2dy1;
      j2dy1 = j2dy0;
      j2dy0 = temp;
    }

    // BAR WIDTH
    double rectWidth = state.getBarWidth();

    // BAR HEIGHT
    double rectHeight = Math.max(getMinimumBarLength(), Math.abs(j2dy1 - j2dy0));

    Comparable seriesKey = dataset.getRowKey(row);
    Comparable categoryKey = dataset.getColumnKey(column);
    if (orientation == PlotOrientation.HORIZONTAL) {
      rectY =
          domainAxis.getCategorySeriesMiddle(
              categoryKey, seriesKey, dataset, getItemMargin(), dataArea, RectangleEdge.LEFT);

      rectX = j2dy0;
      rectHeight = state.getBarWidth();
      rectY = rectY - rectHeight / 2.0;
      rectWidth = Math.max(getMinimumBarLength(), Math.abs(j2dy1 - j2dy0));

    } else if (orientation == PlotOrientation.VERTICAL) {
      rectX =
          domainAxis.getCategorySeriesMiddle(
              categoryKey, seriesKey, dataset, getItemMargin(), dataArea, RectangleEdge.TOP);
      rectX = rectX - rectWidth / 2.0;
      rectY = j2dy0;
    }
    Rectangle2D bar = new Rectangle2D.Double(rectX, rectY, rectWidth, rectHeight);
    Paint seriesPaint = getFirstBarPaint();
    if (column == 0) {
      seriesPaint = getFirstBarPaint();
    } else if (column == categoryCount - 1) {
      seriesPaint = getLastBarPaint();
    } else {
      if (valDiff < 0.0) {
        seriesPaint = getNegativeBarPaint();
      } else if (valDiff > 0.0) {
        seriesPaint = getPositiveBarPaint();
      } else {
        seriesPaint = getLastBarPaint();
      }
    }
    if (getGradientPaintTransformer() != null && seriesPaint instanceof GradientPaint) {
      GradientPaint gp = (GradientPaint) seriesPaint;
      seriesPaint = getGradientPaintTransformer().transform(gp, bar);
    }
    g2.setPaint(seriesPaint);
    g2.fill(bar);

    // draw the outline...
    if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
      Stroke stroke = getItemOutlineStroke(row, column);
      Paint paint = getItemOutlinePaint(row, column);
      if (stroke != null && paint != null) {
        g2.setStroke(stroke);
        g2.setPaint(paint);
        g2.draw(bar);
      }
    }

    CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
    if (generator != null && isItemLabelVisible(row, column)) {
      drawItemLabel(g2, dataset, row, column, plot, generator, bar, (valDiff < 0.0));
    }

    // add an item entity, if this information is being collected
    EntityCollection entities = state.getEntityCollection();
    if (entities != null) {
      addItemEntity(entities, dataset, row, column, bar);
    }
  }
Ejemplo n.º 27
0
  /**
   * Draw a single data item.
   *
   * @param g2 the graphics device.
   * @param state the renderer state.
   * @param dataArea the data plot area.
   * @param plot the plot.
   * @param domainAxis the domain axis.
   * @param rangeAxis the range axis.
   * @param dataset the dataset.
   * @param row the row index (zero-based).
   * @param column the column index (zero-based).
   * @param pass the pass index.
   */
  @Override
  public void drawItem(
      Graphics2D g2,
      CategoryItemRendererState state,
      Rectangle2D dataArea,
      CategoryPlot plot,
      CategoryAxis domainAxis,
      ValueAxis rangeAxis,
      CategoryDataset dataset,
      int row,
      int column,
      int pass) {

    // do nothing if item is not visible or null
    if (!getItemVisible(row, column)) {
      return;
    }
    Number value = dataset.getValue(row, column);
    if (value == null) {
      return;
    }
    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge axisEdge = plot.getDomainAxisEdge();
    int count = dataset.getColumnCount();
    float x0 = (float) domainAxis.getCategoryStart(column, count, dataArea, axisEdge);
    float x1 = (float) domainAxis.getCategoryMiddle(column, count, dataArea, axisEdge);
    float x2 = (float) domainAxis.getCategoryEnd(column, count, dataArea, axisEdge);

    x0 = Math.round(x0);
    x1 = Math.round(x1);
    x2 = Math.round(x2);

    if (this.endType == AreaRendererEndType.TRUNCATE) {
      if (column == 0) {
        x0 = x1;
      } else if (column == getColumnCount() - 1) {
        x2 = x1;
      }
    }

    double yy1 = value.doubleValue();

    double yy0 = 0.0;
    if (this.endType == AreaRendererEndType.LEVEL) {
      yy0 = yy1;
    }
    if (column > 0) {
      Number n0 = dataset.getValue(row, column - 1);
      if (n0 != null) {
        yy0 = (n0.doubleValue() + yy1) / 2.0;
      }
    }

    double yy2 = 0.0;
    if (column < dataset.getColumnCount() - 1) {
      Number n2 = dataset.getValue(row, column + 1);
      if (n2 != null) {
        yy2 = (n2.doubleValue() + yy1) / 2.0;
      }
    } else if (this.endType == AreaRendererEndType.LEVEL) {
      yy2 = yy1;
    }

    RectangleEdge edge = plot.getRangeAxisEdge();
    float y0 = (float) rangeAxis.valueToJava2D(yy0, dataArea, edge);
    float y1 = (float) rangeAxis.valueToJava2D(yy1, dataArea, edge);
    float y2 = (float) rangeAxis.valueToJava2D(yy2, dataArea, edge);
    float yz = (float) rangeAxis.valueToJava2D(0.0, dataArea, edge);
    double labelXX = x1;
    double labelYY = y1;
    g2.setPaint(getItemPaint(row, column));
    g2.setStroke(getItemStroke(row, column));

    GeneralPath area = new GeneralPath();

    if (orientation == PlotOrientation.VERTICAL) {
      area.moveTo(x0, yz);
      area.lineTo(x0, y0);
      area.lineTo(x1, y1);
      area.lineTo(x2, y2);
      area.lineTo(x2, yz);
    } else if (orientation == PlotOrientation.HORIZONTAL) {
      area.moveTo(yz, x0);
      area.lineTo(y0, x0);
      area.lineTo(y1, x1);
      area.lineTo(y2, x2);
      area.lineTo(yz, x2);
      double temp = labelXX;
      labelXX = labelYY;
      labelYY = temp;
    }
    area.closePath();

    g2.setPaint(getItemPaint(row, column));
    g2.fill(area);

    // draw the item labels if there are any...
    if (isItemLabelVisible(row, column)) {
      drawItemLabel(
          g2, orientation, dataset, row, column, labelXX, labelYY, (value.doubleValue() < 0.0));
    }

    // submit the current data point as a crosshair candidate
    int datasetIndex = plot.indexOf(dataset);
    updateCrosshairValues(
        state.getCrosshairState(),
        dataset.getRowKey(row),
        dataset.getColumnKey(column),
        yy1,
        datasetIndex,
        x1,
        y1,
        orientation);

    // add an item entity, if this information is being collected
    EntityCollection entities = state.getEntityCollection();
    if (entities != null) {
      addItemEntity(entities, dataset, row, column, area);
    }
  }
 /**
  * Generates a label for the specified row.
  *
  * @param dataset the dataset (<code>null</code> not permitted).
  * @param column the column index (zero-based).
  * @return The label.
  */
 public String generateColumnLabel(CategoryDataset dataset, int column) {
   return dataset.getColumnKey(column).toString();
 }
  /**
   * Draw a single data item.
   *
   * @param g2 the graphics device.
   * @param state the renderer state.
   * @param dataArea the area in which the data is drawn.
   * @param plot the plot.
   * @param domainAxis the domain axis.
   * @param rangeAxis the range axis.
   * @param dataset the dataset.
   * @param row the row index (zero-based).
   * @param column the column index (zero-based).
   * @param pass the pass index.
   */
  public void drawItem(
      Graphics2D g2,
      CategoryItemRendererState state,
      Rectangle2D dataArea,
      CategoryPlot plot,
      CategoryAxis domainAxis,
      ValueAxis rangeAxis,
      CategoryDataset dataset,
      int row,
      int column,
      int pass) {

    // do nothing if item is not visible
    if (!getItemVisible(row, column)) {
      return;
    }

    Number value = dataset.getValue(row, column);
    if (value == null) {
      return;
    }
    PlotOrientation orientation = plot.getOrientation();

    // current data point...
    double x1s =
        domainAxis.getCategoryStart(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());
    double x1 =
        domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());
    double x1e = 2 * x1 - x1s; // or: x1s + 2*(x1-x1s)
    double y1 = rangeAxis.valueToJava2D(value.doubleValue(), dataArea, plot.getRangeAxisEdge());
    g2.setPaint(getItemPaint(row, column));
    g2.setStroke(getItemStroke(row, column));

    if (column != 0) {
      Number previousValue = dataset.getValue(row, column - 1);
      if (previousValue != null) {
        // previous data point...
        double previous = previousValue.doubleValue();
        double x0s =
            domainAxis.getCategoryStart(
                column - 1, getColumnCount(), dataArea, plot.getDomainAxisEdge());
        double x0 =
            domainAxis.getCategoryMiddle(
                column - 1, getColumnCount(), dataArea, plot.getDomainAxisEdge());
        double x0e = 2 * x0 - x0s; // or: x0s + 2*(x0-x0s)
        double y0 = rangeAxis.valueToJava2D(previous, dataArea, plot.getRangeAxisEdge());
        if (getStagger()) {
          int xStagger = row * STAGGER_WIDTH;
          if (xStagger > (x1s - x0e)) {
            xStagger = (int) (x1s - x0e);
          }
          x1s = x0e + xStagger;
        }
        drawLine(g2, (State) state, orientation, x0e, y0, x1s, y0);
        // extend x0's flat bar

        drawLine(g2, (State) state, orientation, x1s, y0, x1s, y1);
        // upright bar
      }
    }
    drawLine(g2, (State) state, orientation, x1s, y1, x1e, y1);
    // x1's flat bar

    // draw the item labels if there are any...
    if (isItemLabelVisible(row, column)) {
      drawItemLabel(g2, orientation, dataset, row, column, x1, y1, (value.doubleValue() < 0.0));
    }

    // add an item entity, if this information is being collected
    EntityCollection entities = state.getEntityCollection();
    if (entities != null) {
      Rectangle2D hotspot = new Rectangle2D.Double();
      if (orientation == PlotOrientation.VERTICAL) {
        hotspot.setRect(x1s, y1, x1e - x1s, 4.0);
      } else {
        hotspot.setRect(y1 - 2.0, x1s, 4.0, x1e - x1s);
      }
      addItemEntity(entities, dataset, row, column, hotspot);
    }
  }
Ejemplo n.º 30
0
  /**
   * Draws the category labels and returns the updated axis state.
   *
   * @param g2 the graphics device (<code>null</code> not permitted).
   * @param plotArea the plot area (<code>null</code> not permitted).
   * @param dataArea the area inside the axes (<code>null</code> not permitted).
   * @param edge the axis location (<code>null</code> not permitted).
   * @param state the axis state (<code>null</code> not permitted).
   * @param plotState collects information about the plot (<code>null</code> permitted).
   * @return The updated axis state (never <code>null</code>).
   */
  protected AxisState drawSubCategoryLabels(
      Graphics2D g2,
      Rectangle2D plotArea,
      Rectangle2D dataArea,
      RectangleEdge edge,
      AxisState state,
      PlotRenderingInfo plotState) {

    if (state == null) {
      throw new IllegalArgumentException("Null 'state' argument.");
    }

    g2.setFont(this.subLabelFont);
    g2.setPaint(this.subLabelPaint);
    CategoryPlot plot = (CategoryPlot) getPlot();
    CategoryDataset dataset = plot.getDataset();
    int categoryCount = dataset.getColumnCount();

    double maxdim = getMaxDim(g2, edge);
    for (int categoryIndex = 0; categoryIndex < categoryCount; categoryIndex++) {

      double x0 = 0.0;
      double x1 = 0.0;
      double y0 = 0.0;
      double y1 = 0.0;
      if (edge == RectangleEdge.TOP) {
        x0 = getCategoryStart(categoryIndex, categoryCount, dataArea, edge);
        x1 = getCategoryEnd(categoryIndex, categoryCount, dataArea, edge);
        y1 = state.getCursor();
        y0 = y1 - maxdim;
      } else if (edge == RectangleEdge.BOTTOM) {
        x0 = getCategoryStart(categoryIndex, categoryCount, dataArea, edge);
        x1 = getCategoryEnd(categoryIndex, categoryCount, dataArea, edge);
        y0 = state.getCursor();
        y1 = y0 + maxdim;
      } else if (edge == RectangleEdge.LEFT) {
        y0 = getCategoryStart(categoryIndex, categoryCount, dataArea, edge);
        y1 = getCategoryEnd(categoryIndex, categoryCount, dataArea, edge);
        x1 = state.getCursor();
        x0 = x1 - maxdim;
      } else if (edge == RectangleEdge.RIGHT) {
        y0 = getCategoryStart(categoryIndex, categoryCount, dataArea, edge);
        y1 = getCategoryEnd(categoryIndex, categoryCount, dataArea, edge);
        x0 = state.getCursor();
        x1 = x0 + maxdim;
      }
      Rectangle2D area = new Rectangle2D.Double(x0, y0, (x1 - x0), (y1 - y0));
      int subCategoryCount = this.subCategories.size();
      float width = (float) ((x1 - x0) / subCategoryCount);
      float height = (float) ((y1 - y0) / subCategoryCount);
      float xx = 0.0f;
      float yy = 0.0f;
      for (int i = 0; i < subCategoryCount; i++) {
        if (RectangleEdge.isTopOrBottom(edge)) {
          xx = (float) (x0 + (i + 0.5) * width);
          yy = (float) area.getCenterY();
        } else {
          xx = (float) area.getCenterX();
          yy = (float) (y0 + (i + 0.5) * height);
        }
        String label = this.subCategories.get(i).toString();
        TextUtilities.drawRotatedString(
            label, g2, xx, yy, TextAnchor.CENTER, 0.0, TextAnchor.CENTER);
      }
    }

    if (edge.equals(RectangleEdge.TOP)) {
      double h = maxdim;
      state.cursorUp(h);
    } else if (edge.equals(RectangleEdge.BOTTOM)) {
      double h = maxdim;
      state.cursorDown(h);
    } else if (edge == RectangleEdge.LEFT) {
      double w = maxdim;
      state.cursorLeft(w);
    } else if (edge == RectangleEdge.RIGHT) {
      double w = maxdim;
      state.cursorRight(w);
    }
    return state;
  }