org.jfree.chart.labels.ItemLabelPosition Java Examples

The following examples show how to use org.jfree.chart.labels.ItemLabelPosition. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BarRenderer3D.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Constructs a new renderer with the specified '3D effect'.
 *
 * @param xOffset  the x-offset for the 3D effect.
 * @param yOffset  the y-offset for the 3D effect.
 */
public BarRenderer3D(double xOffset, double yOffset) {

    super();
    this.xOffset = xOffset;
    this.yOffset = yOffset;
    this.wallPaint = DEFAULT_WALL_PAINT;
    // set the default item label positions
    ItemLabelPosition p1 = new ItemLabelPosition(ItemLabelAnchor.INSIDE12,
            TextAnchor.TOP_CENTER);
    setBasePositiveItemLabelPosition(p1);
    ItemLabelPosition p2 = new ItemLabelPosition(ItemLabelAnchor.INSIDE12,
            TextAnchor.TOP_CENTER);
    setBaseNegativeItemLabelPosition(p2);

}
 
Example #2
Source File: YIntervalRenderer.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws an item label.
 *
 * @param g2  the graphics device.
 * @param orientation  the orientation.
 * @param dataset  the dataset.
 * @param series  the series index (zero-based).
 * @param item  the item index (zero-based).
 * @param x  the x coordinate (in Java2D space).
 * @param y  the y coordinate (in Java2D space).
 */
private void drawAdditionalItemLabel(Graphics2D g2,
        PlotOrientation orientation, XYDataset dataset, int series,
        int item, double x, double y) {

    if (this.additionalItemLabelGenerator == null) {
        return;
    }

    Font labelFont = getItemLabelFont(series, item);
    Paint paint = getItemLabelPaint(series, item);
    g2.setFont(labelFont);
    g2.setPaint(paint);
    String label = this.additionalItemLabelGenerator.generateLabel(dataset,
            series, item);

    ItemLabelPosition position = getNegativeItemLabelPosition(series, item);
    Point2D anchorPoint = calculateLabelAnchorPoint(
            position.getItemLabelAnchor(), x, y, orientation);
    TextUtilities.drawRotatedString(label, g2,
            (float) anchorPoint.getX(), (float) anchorPoint.getY(),
            position.getTextAnchor(), position.getAngle(),
            position.getRotationAnchor());
}
 
Example #3
Source File: AbstractRendererTest.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testEquals_ObjectList4() {
    BarRenderer r1 = new BarRenderer();
    r1.setSeriesNegativeItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
    BarRenderer r2 = new BarRenderer();
    r2.setSeriesNegativeItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
    assertEquals(r1, r2);
    r2.setSeriesNegativeItemLabelPosition(1, new ItemLabelPosition(ItemLabelAnchor.INSIDE1, TextAnchor.CENTER));
    assertNotEquals(r1, r2);
}
 
Example #4
Source File: AbstractRenderer.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the item label position for all negative values in a series.
 *
 * @param series  the series index (zero-based).
 *
 * @return The item label position (never <code>null</code>).
 *
 * @see #setSeriesNegativeItemLabelPosition(int, ItemLabelPosition)
 */
public ItemLabelPosition getSeriesNegativeItemLabelPosition(int series) {
    // return the override, if there is one...
    if (this.negativeItemLabelPosition != null) {
        return this.negativeItemLabelPosition;
    }
    // otherwise look up the position list
    ItemLabelPosition position 
            = this.negativeItemLabelPositionMap.get(series);
    if (position == null) {
        position = this.baseNegativeItemLabelPosition;
    }
    return position;
}
 
Example #5
Source File: AbstractXYItemRenderer.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draws an item label.
 *
 * @param g2  the graphics device.
 * @param orientation  the orientation.
 * @param dataset  the dataset.
 * @param series  the series index (zero-based).
 * @param item  the item index (zero-based).
 * @param x  the x coordinate (in Java2D space).
 * @param y  the y coordinate (in Java2D space).
 * @param negative  indicates a negative value (which affects the item
 *                  label position).
 */
protected void drawItemLabel(Graphics2D g2, PlotOrientation orientation,
        XYDataset dataset, int series, int item, double x, double y,
        boolean negative) {

    XYItemLabelGenerator generator = getItemLabelGenerator(series, item);
    if (generator != null) {
        Font labelFont = getItemLabelFont(series, item);
        Paint paint = getItemLabelPaint(series, item);
        g2.setFont(labelFont);
        g2.setPaint(paint);
        String label = generator.generateLabel(dataset, series, item);

        // get the label position..
        ItemLabelPosition position;
        if (!negative) {
            position = getPositiveItemLabelPosition(series, item);
        }
        else {
            position = getNegativeItemLabelPosition(series, item);
        }

        // work out the label anchor point...
        Point2D anchorPoint = calculateLabelAnchorPoint(
                position.getItemLabelAnchor(), x, y, orientation);
        TextUtilities.drawRotatedString(label, g2,
                (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                position.getTextAnchor(), position.getAngle(),
                position.getRotationAnchor());
    }

}
 
Example #6
Source File: ScatterPlotRenderer.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Draws an item label.
 * 
 * @param g2 the graphics device.
 * @param orientation the orientation.
 * @param dataset the dataset.
 * @param series the series index (zero-based).
 * @param item the item index (zero-based).
 * @param x the x coordinate (in Java2D space).
 * @param y the y coordinate (in Java2D space).
 * @param negative indicates a negative value (which affects the item label position).
 */
protected void drawItemLabel(Graphics2D g2, PlotOrientation orientation, XYDataset dataset,
    int series, int item, double x, double y, boolean negative) {

  XYItemLabelGenerator generator = getItemLabelGenerator(series, item);
  Font labelFont = getItemLabelFont(series, item);
  g2.setFont(labelFont);
  String label = generator.generateLabel(dataset, series, item);

  if ((label == null) || (label.length() == 0))
    return;

  // get the label position..
  ItemLabelPosition position = null;
  if (!negative) {
    position = getPositiveItemLabelPosition(series, item);
  } else {
    position = getNegativeItemLabelPosition(series, item);
  }

  // work out the label anchor point...
  Point2D anchorPoint =
      calculateLabelAnchorPoint(position.getItemLabelAnchor(), x, y, orientation);

  FontMetrics metrics = g2.getFontMetrics(labelFont);
  int width = SwingUtilities.computeStringWidth(metrics, label) + 2;
  int height = metrics.getHeight();

  int X = (int) (anchorPoint.getX() - (width / 2));
  int Y = (int) (anchorPoint.getY() - (height));

  g2.setPaint(searchColor);
  g2.fillRect(X, Y, width, height);

  super.drawItemLabel(g2, orientation, dataset, series, item, x, y, negative);

}
 
Example #7
Source File: StackedXYBarRenderer.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new renderer.
 *
 * @param margin  the percentual amount of the bars that are cut away.
 */
public StackedXYBarRenderer(double margin) {
    super(margin);
    this.renderAsPercentages = false;

    // set the default item label positions, which will only be used if
    // the user requests visible item labels...
    ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.CENTER,
            TextAnchor.CENTER);
    setBasePositiveItemLabelPosition(p);
    setBaseNegativeItemLabelPosition(p);
    setPositiveItemLabelPositionFallback(null);
    setNegativeItemLabelPositionFallback(null);
}
 
Example #8
Source File: AbstractCategoryItemRenderer.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draws an item label.
 *
 * @param g2  the graphics device.
 * @param orientation  the orientation.
 * @param dataset  the dataset.
 * @param row  the row.
 * @param column  the column.
 * @param x  the x coordinate (in Java2D space).
 * @param y  the y coordinate (in Java2D space).
 * @param negative  indicates a negative value (which affects the item
 *                  label position).
 */
protected void drawItemLabel(Graphics2D g2, PlotOrientation orientation,
        CategoryDataset dataset, int row, int column,
        double x, double y, boolean negative) {

    CategoryItemLabelGenerator generator = getItemLabelGenerator(row,
            column);
    if (generator != null) {
        Font labelFont = getItemLabelFont(row, column);
        Paint paint = getItemLabelPaint(row, column);
        g2.setFont(labelFont);
        g2.setPaint(paint);
        String label = generator.generateLabel(dataset, row, column);
        ItemLabelPosition position;
        if (!negative) {
            position = getPositiveItemLabelPosition(row, column);
        }
        else {
            position = getNegativeItemLabelPosition(row, column);
        }
        Point2D anchorPoint = calculateLabelAnchorPoint(
                position.getItemLabelAnchor(), x, y, orientation);
        TextUtilities.drawRotatedString(label, g2,
                (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                position.getTextAnchor(),
                position.getAngle(), position.getRotationAnchor());
    }

}
 
Example #9
Source File: StackedBarRenderer.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new renderer.
 *
 * @param renderAsPercentages  a flag that controls whether the data values
 *                             are rendered as percentages.
 */
public StackedBarRenderer(boolean renderAsPercentages) {
    super();
    this.renderAsPercentages = renderAsPercentages;

    // set the default item label positions, which will only be used if
    // the user requests visible item labels...
    ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.CENTER,
            TextAnchor.CENTER);
    setBasePositiveItemLabelPosition(p);
    setBaseNegativeItemLabelPosition(p);
    setPositiveItemLabelPositionFallback(null);
    setNegativeItemLabelPositionFallback(null);
}
 
Example #10
Source File: XYBarRendererTest.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
@Test
public void testSerialization2() {
    XYBarRenderer r1 = new XYBarRenderer();
    r1.setPositiveItemLabelPositionFallback(new ItemLabelPosition());
    XYBarRenderer r2 = (XYBarRenderer) TestUtilities.serialised(r1);
    assertEquals(r1, r2);
}
 
Example #11
Source File: AbstractRendererTest.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testEquals_ObjectList3() {
    BarRenderer r1 = new BarRenderer();
    r1.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
    BarRenderer r2 = new BarRenderer();
    r2.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
    assertEquals(r1, r2);
    r2.setSeriesPositiveItemLabelPosition(1, new ItemLabelPosition(ItemLabelAnchor.INSIDE1, TextAnchor.CENTER));
    assertNotEquals(r1, r2);
}
 
Example #12
Source File: AbstractRendererTest.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test that setting the negative item label position for ALL series does
 * in fact work.
 */
@Test
public void testSetNegativeItemLabelPosition() {
    BarRenderer r = new BarRenderer();
    r.setNegativeItemLabelPosition(new ItemLabelPosition(
            ItemLabelAnchor.INSIDE1, TextAnchor.BASELINE_LEFT));
    assertEquals(new ItemLabelPosition(
            ItemLabelAnchor.INSIDE1, TextAnchor.BASELINE_LEFT),
            r.getNegativeItemLabelPosition(0, 0));
}
 
Example #13
Source File: AbstractRendererTest.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test that setting the positive item label position for ALL series does
 * in fact work.
 */
@Test
public void testSetPositiveItemLabelPosition() {
    BarRenderer r = new BarRenderer();
    r.setPositiveItemLabelPosition(new ItemLabelPosition(
            ItemLabelAnchor.INSIDE1, TextAnchor.BASELINE_LEFT));
    assertEquals(new ItemLabelPosition(
            ItemLabelAnchor.INSIDE1, TextAnchor.BASELINE_LEFT),
            r.getPositiveItemLabelPosition(0, 0));
}
 
Example #14
Source File: BarRendererTest.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Test that the equals() method distinguishes all fields.
 */
@Test
public void testEquals() {
    BarRenderer r1 = new BarRenderer();
    BarRenderer r2 = new BarRenderer();
    assertTrue(r1.equals(r2));
    assertTrue(r2.equals(r1));

    // base value
    r1.setBase(0.123);
    assertFalse(r1.equals(r2));
    r2.setBase(0.123);
    assertTrue(r1.equals(r2));

    // itemMargin
    r1.setItemMargin(0.22);
    assertFalse(r1.equals(r2));
    r2.setItemMargin(0.22);
    assertTrue(r1.equals(r2));

    // drawBarOutline
    r1.setDrawBarOutline(!r1.isDrawBarOutline());
    assertFalse(r1.equals(r2));
    r2.setDrawBarOutline(!r2.isDrawBarOutline());
    assertTrue(r1.equals(r2));

    // maximumBarWidth
    r1.setMaximumBarWidth(0.11);
    assertFalse(r1.equals(r2));
    r2.setMaximumBarWidth(0.11);
    assertTrue(r1.equals(r2));

    // minimumBarLength
    r1.setMinimumBarLength(0.04);
    assertFalse(r1.equals(r2));
    r2.setMinimumBarLength(0.04);
    assertTrue(r1.equals(r2));

    // gradientPaintTransformer
    r1.setGradientPaintTransformer(new StandardGradientPaintTransformer(
            GradientPaintTransformType.CENTER_VERTICAL));
    assertFalse(r1.equals(r2));
    r2.setGradientPaintTransformer(new StandardGradientPaintTransformer(
            GradientPaintTransformType.CENTER_VERTICAL));
    assertTrue(r1.equals(r2));

    // positiveItemLabelPositionFallback
    r1.setPositiveItemLabelPositionFallback(new ItemLabelPosition(
            ItemLabelAnchor.INSIDE1, TextAnchor.CENTER));
    assertFalse(r1.equals(r2));
    r2.setPositiveItemLabelPositionFallback(new ItemLabelPosition(
            ItemLabelAnchor.INSIDE1, TextAnchor.CENTER));
    assertTrue(r1.equals(r2));

    // negativeItemLabelPositionFallback
    r1.setNegativeItemLabelPositionFallback(new ItemLabelPosition(
            ItemLabelAnchor.INSIDE1, TextAnchor.CENTER));
    assertFalse(r1.equals(r2));
    r2.setNegativeItemLabelPositionFallback(new ItemLabelPosition(
            ItemLabelAnchor.INSIDE1, TextAnchor.CENTER));
    assertTrue(r1.equals(r2));

    // barPainter
    r1.setBarPainter(new GradientBarPainter(0.1, 0.2, 0.3));
    assertFalse(r1.equals(r2));
    r2.setBarPainter(new GradientBarPainter(0.1, 0.2, 0.3));
    assertTrue(r1.equals(r2));

    // shadowsVisible
    r1.setShadowVisible(false);
    assertFalse(r1.equals(r2));
    r2.setShadowVisible(false);
    assertTrue(r1.equals(r2));

    r1.setShadowPaint(Color.red);
    assertFalse(r1.equals(r2));
    r2.setShadowPaint(Color.red);
    assertTrue(r1.equals(r2));

    // shadowXOffset
    r1.setShadowXOffset(3.3);
    assertFalse(r1.equals(r2));
    r2.setShadowXOffset(3.3);
    assertTrue(r1.equals(r2));

    // shadowYOffset
    r1.setShadowYOffset(3.3);
    assertFalse(r1.equals(r2));
    r2.setShadowYOffset(3.3);
    assertTrue(r1.equals(r2));

}
 
Example #15
Source File: KendrickMassPlotTask.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * create 2D Kendrick mass plot
 */
private JFreeChart create2DKendrickMassPlot() {

  if (zAxisLabel.equals("none")) {
    logger.info("Creating new 2D chart instance");
    appliedSteps++;

    // load dataset
    dataset2D = new KendrickMassPlotXYDataset(parameters);

    // create chart
    chart = ChartFactory.createScatterPlot(title, xAxisLabel, yAxisLabel, dataset2D,
        PlotOrientation.VERTICAL, true, true, true);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainCrosshairPaint(Color.GRAY);
    plot.setRangeCrosshairPaint(Color.GRAY);
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    appliedSteps++;

    // set axis
    NumberAxis domain = (NumberAxis) plot.getDomainAxis();
    NumberAxis range = (NumberAxis) plot.getRangeAxis();
    range.setRange(0, 1);
    if (xAxisLabel.contains("KMD")) {
      domain.setRange(0, 1);
    }

    // set renderer
    XYBlockPixelSizeRenderer renderer = new XYBlockPixelSizeRenderer();

    // set tooltip generator
    ScatterPlotToolTipGenerator tooltipGenerator =
        new ScatterPlotToolTipGenerator(xAxisLabel, yAxisLabel, zAxisLabel, rows);
    renderer.setSeriesToolTipGenerator(0, tooltipGenerator);
    plot.setRenderer(renderer);

    // set item label generator
    NameItemLabelGenerator generator = new NameItemLabelGenerator(rows);
    renderer.setDefaultItemLabelGenerator(generator);
    renderer.setDefaultItemLabelsVisible(false);
    renderer.setDefaultItemLabelFont(legendFont);
    renderer.setDefaultPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER,
        TextAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT, -45), true);
  }
  return chart;
}
 
Example #16
Source File: AbstractRenderer.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Default constructor.
 */
public AbstractRenderer() {
    this.seriesVisible = null;
    this.seriesVisibleList = new BooleanList();
    this.baseSeriesVisible = true;

    this.seriesVisibleInLegend = null;
    this.seriesVisibleInLegendList = new BooleanList();
    this.baseSeriesVisibleInLegend = true;

    this.paint = null;
    this.paintList = new PaintList();
    this.basePaint = DEFAULT_PAINT;
    this.autoPopulateSeriesPaint = true;

    this.fillPaint = null;
    this.fillPaintList = new PaintList();
    this.baseFillPaint = Color.white;
    this.autoPopulateSeriesFillPaint = false;

    this.outlinePaint = null;
    this.outlinePaintList = new PaintList();
    this.baseOutlinePaint = DEFAULT_OUTLINE_PAINT;
    this.autoPopulateSeriesOutlinePaint = false;

    this.stroke = null;
    this.strokeList = new StrokeList();
    this.baseStroke = DEFAULT_STROKE;
    this.autoPopulateSeriesStroke = true;

    this.outlineStroke = null;
    this.outlineStrokeList = new StrokeList();
    this.baseOutlineStroke = DEFAULT_OUTLINE_STROKE;
    this.autoPopulateSeriesOutlineStroke = false;

    this.shape = null;
    this.shapeList = new ShapeList();
    this.baseShape = DEFAULT_SHAPE;
    this.autoPopulateSeriesShape = true;

    this.itemLabelsVisible = null;
    this.itemLabelsVisibleList = new BooleanList();
    this.baseItemLabelsVisible = Boolean.FALSE;

    this.itemLabelFont = null;
    this.itemLabelFontMap = new HashMap<Integer, Font>();
    this.baseItemLabelFont = new Font("SansSerif", Font.PLAIN, 10);

    this.itemLabelPaint = null;
    this.itemLabelPaintList = new PaintList();
    this.baseItemLabelPaint = Color.black;

    this.positiveItemLabelPosition = null;
    this.positiveItemLabelPositionMap 
            = new HashMap<Integer, ItemLabelPosition>();
    this.basePositiveItemLabelPosition = new ItemLabelPosition(
            ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER);

    this.negativeItemLabelPosition = null;
    this.negativeItemLabelPositionMap 
            = new HashMap<Integer, ItemLabelPosition>();
    this.baseNegativeItemLabelPosition = new ItemLabelPosition(
            ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER);

    this.createEntities = null;
    this.createEntitiesList = new BooleanList();
    this.baseCreateEntities = true;

    this.defaultEntityRadius = 3;

    this.legendShapeList = new ShapeList();
    this.baseLegendShape = null;

    this.treatLegendShapeAsLine = false;

    this.legendTextFontMap = new HashMap<Integer, Font>();
    this.baseLegendTextFont = null;

    this.legendTextPaint = new PaintList();
    this.baseLegendTextPaint = null;

    this.listenerList = new EventListenerList();
}
 
Example #17
Source File: PseudoSpectraRenderer.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void drawItemLabel(Graphics2D g2, XYDataset dataset, int series, int item, XYPlot plot,
    XYItemLabelGenerator generator, Rectangle2D bar, boolean negative) {
  // super.drawItemLabel(g2, dataset, series, item, plot, generator, bar,
  // negative);

  if (generator != null) {
    String label = generator.generateLabel(dataset, series, item);

    if (label != null) {
      Font labelFont = getItemLabelFont(series, item);
      Paint paint = getItemLabelPaint(series, item);
      g2.setFont(labelFont);
      g2.setPaint(paint);

      // get the label position..
      ItemLabelPosition position;
      if (!negative) {
        position = getPositiveItemLabelPosition(series, item);
      } else {
        position = getNegativeItemLabelPosition(series, item);
      }

      // work out the label anchor point...
      Point2D anchorPoint =
          calculateLabelAnchorPoint(position.getItemLabelAnchor(), bar, plot.getOrientation());

      // split by \n
      String symbol = "\n";
      String[] splitted = label.split(symbol);

      if (splitted.length > 1) {
        FontRenderContext frc = g2.getFontRenderContext();
        GlyphVector gv = g2.getFont().createGlyphVector(frc, "Fg,");
        int height = 4 + (int) gv.getPixelBounds(null, 0, 0).getHeight();
        // draw more than one row
        for (int i = 0; i < splitted.length; i++) {
          int offset = -height * (splitted.length - i - 1);
          TextUtils.drawRotatedString(splitted[i], g2, (float) anchorPoint.getX(),
              (float) anchorPoint.getY() + offset, position.getTextAnchor(), position.getAngle(),
              position.getRotationAnchor());
        }
      } else {
        // one row
        TextUtils.drawRotatedString(label, g2, (float) anchorPoint.getX(),
            (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(),
            position.getRotationAnchor());
      }
    }
  }

}
 
Example #18
Source File: XYBarRendererTest.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Test that the equals() method distinguishes all fields.
 */
@Test
public void testEquals() {

    // default instances
    XYBarRenderer r1 = new XYBarRenderer();
    XYBarRenderer r2 = new XYBarRenderer();
    assertTrue(r1.equals(r2));
    assertTrue(r2.equals(r1));

    // setBase()
    r1.setBase(1.0);
    assertFalse(r1.equals(r2));
    r2.setBase(1.0);
    assertTrue(r1.equals(r2));

    // setUseYInterval
    r1.setUseYInterval(!r1.getUseYInterval());
    assertFalse(r1.equals(r2));
    r2.setUseYInterval(!r2.getUseYInterval());
    assertTrue(r1.equals(r2));

    // setMargin()
    r1.setMargin(0.10);
    assertFalse(r1.equals(r2));
    r2.setMargin(0.10);
    assertTrue(r1.equals(r2));

    // setDrawBarOutline()
    r1.setDrawBarOutline(!r1.isDrawBarOutline());
    assertFalse(r1.equals(r2));
    r2.setDrawBarOutline(!r2.isDrawBarOutline());
    assertTrue(r1.equals(r2));

    // setGradientPaintTransformer()
    r1.setGradientPaintTransformer(new StandardGradientPaintTransformer(
            GradientPaintTransformType.CENTER_HORIZONTAL));
    assertFalse(r1.equals(r2));
    r2.setGradientPaintTransformer(new StandardGradientPaintTransformer(
            GradientPaintTransformType.CENTER_HORIZONTAL));
    assertTrue(r1.equals(r2));

    // legendBar
    r1.setLegendBar(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0));
    assertFalse(r1.equals(r2));
    r2.setLegendBar(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0));
    assertTrue(r1.equals(r2));

    // positiveItemLabelFallbackPosition
    r1.setPositiveItemLabelPositionFallback(new ItemLabelPosition());
    assertFalse(r1.equals(r2));
    r2.setPositiveItemLabelPositionFallback(new ItemLabelPosition());
    assertTrue(r1.equals(r2));

    // negativeItemLabelFallbackPosition
    r1.setNegativeItemLabelPositionFallback(new ItemLabelPosition());
    assertFalse(r1.equals(r2));
    r2.setNegativeItemLabelPositionFallback(new ItemLabelPosition());
    assertTrue(r1.equals(r2));

    // barPainter
    r1.setBarPainter(new GradientXYBarPainter(0.11, 0.22, 0.33));
    assertFalse(r1.equals(r2));
    r2.setBarPainter(new GradientXYBarPainter(0.11, 0.22, 0.33));
    assertTrue(r1.equals(r2));

    // shadowsVisible
    r1.setShadowVisible(false);
    assertFalse(r1.equals(r2));
    r2.setShadowVisible(false);
    assertTrue(r1.equals(r2));

    // shadowXOffset
    r1.setShadowXOffset(3.3);
    assertFalse(r1.equals(r2));
    r2.setShadowXOffset(3.3);
    assertTrue(r1.equals(r2));

    // shadowYOffset
    r1.setShadowYOffset(3.3);
    assertFalse(r1.equals(r2));
    r2.setShadowYOffset(3.3);
    assertTrue(r1.equals(r2));

}
 
Example #19
Source File: VanKrevelenDiagramTask.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * create 2D Van Krevelen Diagram chart
 */
private JFreeChart create2DVanKrevelenDiagram() {
  logger.info("Creating new 2D chart instance");
  appliedSteps++;

  // load dataset
  VanKrevelenDiagramXYDataset dataset2D = new VanKrevelenDiagramXYDataset(filteredRows);

  // create chart
  chart = ChartFactory.createScatterPlot(title, "O/C", "H/C", dataset2D, PlotOrientation.VERTICAL,
      true, true, false);

  XYPlot plot = (XYPlot) chart.getPlot();
  plot.setBackgroundPaint(Color.WHITE);
  plot.setDomainCrosshairPaint(Color.GRAY);
  plot.setRangeCrosshairPaint(Color.GRAY);
  plot.setDomainCrosshairVisible(true);
  plot.setRangeCrosshairVisible(true);
  appliedSteps++;

  // set renderer
  XYBlockPixelSizeRenderer renderer = new XYBlockPixelSizeRenderer();

  // calc block sizes
  double maxX = plot.getDomainAxis().getRange().getUpperBound();
  double maxY = plot.getRangeAxis().getRange().getUpperBound();

  renderer.setBlockWidth(0.001);
  renderer.setBlockHeight(renderer.getBlockWidth() / (maxX / maxY));

  // set tooltip generator
  ScatterPlotToolTipGenerator tooltipGenerator =
      new ScatterPlotToolTipGenerator("O/C", "H/C", zAxisLabel, filteredRows);
  renderer.setSeriesToolTipGenerator(0, tooltipGenerator);
  plot.setRenderer(renderer);

  // set item label generator
  NameItemLabelGenerator generator = new NameItemLabelGenerator(filteredRows);
  renderer.setDefaultItemLabelGenerator(generator);
  renderer.setDefaultItemLabelsVisible(false);
  renderer.setDefaultItemLabelFont(legendFont);
  renderer.setDefaultPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER,
      TextAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT, -45), true);

  return chart;
}
 
Example #20
Source File: BarRenderer.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws an item label.  This method is overridden so that the bar can be
 * used to calculate the label anchor point.
 *
 * @param g2  the graphics device.
 * @param data  the dataset.
 * @param row  the row.
 * @param column  the column.
 * @param plot  the plot.
 * @param generator  the label generator.
 * @param bar  the bar.
 * @param negative  a flag indicating a negative value.
 */
protected void drawItemLabel(Graphics2D g2,
                             CategoryDataset data,
                             int row,
                             int column,
                             CategoryPlot plot,
                             CategoryItemLabelGenerator generator,
                             Rectangle2D bar,
                             boolean negative) {

    String label = generator.generateLabel(data, row, column);
    if (label == null) {
        return;  // nothing to do
    }

    Font labelFont = getItemLabelFont(row, column);
    g2.setFont(labelFont);
    Paint paint = getItemLabelPaint(row, column);
    g2.setPaint(paint);

    // find out where to place the label...
    ItemLabelPosition position;
    if (!negative) {
        position = getPositiveItemLabelPosition(row, column);
    }
    else {
        position = getNegativeItemLabelPosition(row, column);
    }

    // work out the label anchor point...
    Point2D anchorPoint = calculateLabelAnchorPoint(
            position.getItemLabelAnchor(), bar, plot.getOrientation());

    if (isInternalAnchor(position.getItemLabelAnchor())) {
        Shape bounds = TextUtilities.calculateRotatedStringBounds(label,
                g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                position.getTextAnchor(), position.getAngle(),
                position.getRotationAnchor());

        if (bounds != null) {
            if (!bar.contains(bounds.getBounds2D())) {
                if (!negative) {
                    position = getPositiveItemLabelPositionFallback();
                }
                else {
                    position = getNegativeItemLabelPositionFallback();
                }
                if (position != null) {
                    anchorPoint = calculateLabelAnchorPoint(
                            position.getItemLabelAnchor(), bar,
                            plot.getOrientation());
                }
            }
        }

    }

    if (position != null) {
        TextUtilities.drawRotatedString(label, g2,
                (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                position.getTextAnchor(), position.getAngle(),
                position.getRotationAnchor());
    }
}
 
Example #21
Source File: XYBarRenderer.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws an item label.  This method is provided as an alternative to
 * {@link #drawItemLabel(Graphics2D, PlotOrientation, XYDataset, int, int,
 * double, double, boolean)} so that the bar can be used to calculate the
 * label anchor point.
 *
 * @param g2  the graphics device.
 * @param dataset  the dataset.
 * @param series  the series index.
 * @param item  the item index.
 * @param plot  the plot.
 * @param generator  the label generator (<code>null</code> permitted, in
 *         which case the method does nothing, just returns).
 * @param bar  the bar.
 * @param negative  a flag indicating a negative value.
 */
protected void drawItemLabel(Graphics2D g2, XYDataset dataset,
        int series, int item, XYPlot plot, XYItemLabelGenerator generator,
        Rectangle2D bar, boolean negative) {

    if (generator == null) {
        return;  // nothing to do
    }
    String label = generator.generateLabel(dataset, series, item);
    if (label == null) {
        return;  // nothing to do
    }

    Font labelFont = getItemLabelFont(series, item);
    g2.setFont(labelFont);
    Paint paint = getItemLabelPaint(series, item);
    g2.setPaint(paint);

    // find out where to place the label...
    ItemLabelPosition position;
    if (!negative) {
        position = getPositiveItemLabelPosition(series, item);
    }
    else {
        position = getNegativeItemLabelPosition(series, item);
    }

    // work out the label anchor point...
    Point2D anchorPoint = calculateLabelAnchorPoint(
            position.getItemLabelAnchor(), bar, plot.getOrientation());

    if (isInternalAnchor(position.getItemLabelAnchor())) {
        Shape bounds = TextUtilities.calculateRotatedStringBounds(label,
                g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                position.getTextAnchor(), position.getAngle(),
                position.getRotationAnchor());

        if (bounds != null) {
            if (!bar.contains(bounds.getBounds2D())) {
                if (!negative) {
                    position = getPositiveItemLabelPositionFallback();
                }
                else {
                    position = getNegativeItemLabelPositionFallback();
                }
                if (position != null) {
                    anchorPoint = calculateLabelAnchorPoint(
                            position.getItemLabelAnchor(), bar,
                            plot.getOrientation());
                }
            }
        }

    }

    if (position != null) {
        TextUtilities.drawRotatedString(label, g2,
                (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                position.getTextAnchor(), position.getAngle(),
                position.getRotationAnchor());
    }
}
 
Example #22
Source File: AbstractRenderer.java    From openstock with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Sets the item label position for negative values in a series and (if
 * requested) sends a {@link RendererChangeEvent} to all registered
 * listeners.
 *
 * @param series  the series index (zero-based).
 * @param position  the position (<code>null</code> permitted).
 * @param notify  notify registered listeners?
 *
 * @see #getSeriesNegativeItemLabelPosition(int)
 */
public void setSeriesNegativeItemLabelPosition(int series,
        ItemLabelPosition position, boolean notify) {
    this.negativeItemLabelPositionMap.put(series, position);
    if (notify) {
        fireChangeEvent();
    }
}
 
Example #23
Source File: AbstractRenderer.java    From openstock with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Sets the item label position for all positive values in a series and (if
 * requested) sends a {@link RendererChangeEvent} to all registered
 * listeners.
 *
 * @param series  the series index (zero-based).
 * @param position  the position (<code>null</code> permitted).
 * @param notify  notify registered listeners?
 *
 * @see #getSeriesPositiveItemLabelPosition(int)
 */
public void setSeriesPositiveItemLabelPosition(int series,
        ItemLabelPosition position, boolean notify) {
    this.positiveItemLabelPositionMap.put(series, position);
    if (notify) {
        fireChangeEvent();
    }
}
 
Example #24
Source File: AbstractRenderer.java    From openstock with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Sets the base positive item label position and, if requested, sends a
 * {@link RendererChangeEvent} to all registered listeners.
 *
 * @param position  the position (<code>null</code> not permitted).
 * @param notify  notify registered listeners?
 *
 * @see #getBasePositiveItemLabelPosition()
 */
public void setBasePositiveItemLabelPosition(ItemLabelPosition position,
        boolean notify) {
    ParamChecks.nullNotPermitted(position, "position");
    this.basePositiveItemLabelPosition = position;
    if (notify) {
        fireChangeEvent();
    }
}
 
Example #25
Source File: AbstractRenderer.java    From openstock with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Sets the positive item label position for ALL series and (if requested)
 * sends a {@link RendererChangeEvent} to all registered listeners.
 *
 * @param position  the position (<code>null</code> permitted).
 * @param notify  notify registered listeners?
 *
 * @see #getPositiveItemLabelPosition()
 *
 * @deprecated This method should no longer be used (as of version 1.0.6).
 *     It is sufficient to rely on
 *     {@link #setSeriesPositiveItemLabelPosition(int, ItemLabelPosition,
 *     boolean)} and {@link #setBasePositiveItemLabelPosition(
 *     ItemLabelPosition, boolean)}.
 */
public void setPositiveItemLabelPosition(ItemLabelPosition position,
                                         boolean notify) {
    this.positiveItemLabelPosition = position;
    if (notify) {
        fireChangeEvent();
    }
}
 
Example #26
Source File: AbstractRenderer.java    From openstock with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Sets the base negative item label position and, if requested, sends a
 * {@link RendererChangeEvent} to all registered listeners.
 *
 * @param position  the position (<code>null</code> not permitted).
 * @param notify  notify registered listeners?
 *
 * @see #getBaseNegativeItemLabelPosition()
 */
public void setBaseNegativeItemLabelPosition(ItemLabelPosition position,
        boolean notify) {
    ParamChecks.nullNotPermitted(position, "position");
    this.baseNegativeItemLabelPosition = position;
    if (notify) {
        fireChangeEvent();
    }
}
 
Example #27
Source File: CategoryItemRenderer.java    From openstock with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Returns the item label position for all positive values in a series.
 *
 * @param series  the series index (zero-based).
 *
 * @return The item label position.
 *
 * @see #setSeriesPositiveItemLabelPosition(int, ItemLabelPosition)
 */
public ItemLabelPosition getSeriesPositiveItemLabelPosition(int series);
 
Example #28
Source File: CategoryItemRenderer.java    From openstock with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Sets the base positive item label position.
 *
 * @param position  the position.
 *
 * @see #getBasePositiveItemLabelPosition()
 */
public void setBasePositiveItemLabelPosition(ItemLabelPosition position);
 
Example #29
Source File: CategoryItemRenderer.java    From openstock with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Sets the item label position for all positive values in a series and
 * sends a {@link RendererChangeEvent} to all registered listeners.
 *
 * @param series  the series index (zero-based).
 * @param position  the position (<code>null</code> permitted).
 *
 * @see #getSeriesPositiveItemLabelPosition(int)
 */
public void setSeriesPositiveItemLabelPosition(int series,
                                               ItemLabelPosition position);
 
Example #30
Source File: CategoryItemRenderer.java    From openstock with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Sets the item label position for all positive values in a series and (if
 * requested) sends a {@link RendererChangeEvent} to all registered
 * listeners.
 *
 * @param series  the series index (zero-based).
 * @param position  the position (<code>null</code> permitted).
 * @param notify  notify registered listeners?
 *
 * @see #getSeriesPositiveItemLabelPosition(int)
 */
public void setSeriesPositiveItemLabelPosition(int series,
        ItemLabelPosition position, boolean notify);