/**
  * {@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();
 }
    /**
     * 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;
    }
 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);
 }
  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
        + ")";
  }
  /**
   * 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 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;
  }
  /**
   * 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);
    }
  }
Example #8
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();
 }
    // copied and modified from jfreechart-1.0.14 org.jfree.chart.renderer.category.BarRenderer
    private void drawItemInternal(
        Graphics2D g2,
        CategoryItemRendererState state,
        Rectangle2D dataArea,
        CategoryPlot plot,
        CategoryAxis domainAxis,
        ValueAxis rangeAxis,
        CategoryDataset dataset,
        int row,
        int column,
        int pass) {

      // nothing is drawn if the row index is not included in the list with
      // the indices of the visible rows...
      int visibleRow = state.getVisibleSeriesIndex(row);
      if (visibleRow < 0) {
        return;
      }
      // nothing is drawn for null values...
      Number dataValue = dataset.getValue(row, column);
      if (dataValue == null) {
        return;
      }

      final double value = dataValue.doubleValue();
      PlotOrientation orientation = plot.getOrientation();
      double barW0 =
          calculateBarW0(plot, orientation, dataArea, domainAxis, state, visibleRow, column);
      double[] barL0L1 = calculateBarL0L1(value);
      if (barL0L1 == null) {
        return; // the bar is not visible
      }

      RectangleEdge edge = plot.getRangeAxisEdge();
      double transL0 = rangeAxis.valueToJava2D(barL0L1[0], dataArea, edge);
      double transL1 = rangeAxis.valueToJava2D(barL0L1[1], dataArea, edge);

      // in the following code, barL0 is (in Java2D coordinates) the LEFT
      // end of the bar for a horizontal bar chart, and the TOP end of the
      // bar for a vertical bar chart.  Whether this is the BASE of the bar
      // or not depends also on (a) whether the data value is 'negative'
      // relative to the base value and (b) whether or not the range axis is
      // inverted.  This only matters if/when we apply the minimumBarLength
      // attribute, because we should extend the non-base end of the bar
      boolean positive = (value >= this.getBase());
      boolean inverted = rangeAxis.isInverted();
      double barL0 = Math.min(transL0, transL1);
      double barLength = Math.abs(transL1 - transL0);
      double barLengthAdj = 0.0;
      if (barLength > 0.0 && barLength < getMinimumBarLength()) {
        barLengthAdj = getMinimumBarLength() - barLength;
      }
      double barL0Adj = 0.0;
      RectangleEdge barBase;
      if (orientation == PlotOrientation.HORIZONTAL) {
        if (positive && inverted || !positive && !inverted) {
          barL0Adj = barLengthAdj;
          barBase = RectangleEdge.RIGHT;
        } else {
          barBase = RectangleEdge.LEFT;
        }
      } else {
        if (positive && !inverted || !positive && inverted) {
          barL0Adj = barLengthAdj;
          barBase = RectangleEdge.BOTTOM;
        } else {
          barBase = RectangleEdge.TOP;
        }
      }

      // draw the bar...
      RectangularShape bar = null;
      if (orientation == PlotOrientation.HORIZONTAL) {
        bar =
            getBarShape(
                row, barL0 - barL0Adj, barW0, barLength + barLengthAdj, state.getBarWidth());
      } else {
        bar =
            getBarShape(
                row, barW0, barL0 - barL0Adj, state.getBarWidth(), barLength + barLengthAdj);
      }

      if (getShadowsVisible()) {
        this.getBarPainter().paintBarShadow(g2, this, row, column, bar, barBase, true);
      }
      this.getBarPainter().paintBar(g2, this, row, column, bar, barBase);

      //          FIXME
      //            CategoryItemLabelGenerator generator = getItemLabelGenerator(row,
      //                    column);
      //            if (generator != null && isItemLabelVisible(row, column)) {
      //                drawItemLabel(g2, dataset, row, column, plot, generator, bar,
      //                        (value < 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),
          value,
          datasetIndex,
          barW0,
          barL0,
          orientation);

      // add an item entity, if this information is being collected
      EntityCollection entities = state.getEntityCollection();
      if (entities != null) {
        addItemEntity(entities, dataset, row, column, bar);
      }
    }