Java Code Examples for org.jfree.chart.axis.NumberAxis#setInverted()

The following examples show how to use org.jfree.chart.axis.NumberAxis#setInverted() . 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: NumberAxisTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Test the translation of Java2D values to data values.
 */
public void testTranslateJava2DToValue() {
    NumberAxis axis = new NumberAxis();
    axis.setRange(50.0, 100.0);
    Rectangle2D dataArea = new Rectangle2D.Double(10.0, 50.0, 400.0, 300.0);
    double y1 = axis.java2DToValue(75.0, dataArea, RectangleEdge.LEFT);
    assertEquals(y1, 95.8333333, EPSILON);
    double y2 = axis.java2DToValue(75.0, dataArea, RectangleEdge.RIGHT);
    assertEquals(y2, 95.8333333, EPSILON);
    double x1 = axis.java2DToValue(75.0, dataArea, RectangleEdge.TOP);
    assertEquals(x1, 58.125, EPSILON);
    double x2 = axis.java2DToValue(75.0, dataArea, RectangleEdge.BOTTOM);
    assertEquals(x2, 58.125, EPSILON);
    axis.setInverted(true);
    double y3 = axis.java2DToValue(75.0, dataArea, RectangleEdge.LEFT);
    assertEquals(y3, 54.1666667, EPSILON);
    double y4 = axis.java2DToValue(75.0, dataArea, RectangleEdge.RIGHT);
    assertEquals(y4, 54.1666667, EPSILON);
    double x3 = axis.java2DToValue(75.0, dataArea, RectangleEdge.TOP);
    assertEquals(x3, 91.875, EPSILON);
    double x4 = axis.java2DToValue(75.0, dataArea, RectangleEdge.BOTTOM);
    assertEquals(x4, 91.875, EPSILON);
}
 
Example 2
Source File: NumberAxisTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Test the translation of Java2D values to data values.
 */
public void testTranslateJava2DToValue() {
    NumberAxis axis = new NumberAxis();
    axis.setRange(50.0, 100.0); 
    Rectangle2D dataArea = new Rectangle2D.Double(10.0, 50.0, 400.0, 300.0);
    double y1 = axis.java2DToValue(75.0, dataArea, RectangleEdge.LEFT);  
    assertEquals(y1, 95.8333333, EPSILON); 
    double y2 = axis.java2DToValue(75.0, dataArea, RectangleEdge.RIGHT);   
    assertEquals(y2, 95.8333333, EPSILON); 
    double x1 = axis.java2DToValue(75.0, dataArea, RectangleEdge.TOP);   
    assertEquals(x1, 58.125, EPSILON); 
    double x2 = axis.java2DToValue(75.0, dataArea, RectangleEdge.BOTTOM);   
    assertEquals(x2, 58.125, EPSILON); 
    axis.setInverted(true);
    double y3 = axis.java2DToValue(75.0, dataArea, RectangleEdge.LEFT);  
    assertEquals(y3, 54.1666667, EPSILON); 
    double y4 = axis.java2DToValue(75.0, dataArea, RectangleEdge.RIGHT);   
    assertEquals(y4, 54.1666667, EPSILON); 
    double x3 = axis.java2DToValue(75.0, dataArea, RectangleEdge.TOP);   
    assertEquals(x3, 91.875, EPSILON); 
    double x4 = axis.java2DToValue(75.0, dataArea, RectangleEdge.BOTTOM);   
    assertEquals(x4, 91.875, EPSILON); 
}
 
Example 3
Source File: MirrorChartFactory.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
private static JFreeChart createMirrorChart(String labelA, double precursorMZA, double rtA,
    DataPoint[] dpsA, String labelB, double precursorMZB, double rtB, DataPoint[] dpsB,
    boolean showTitle, boolean showLegend) {
  PseudoSpectrumDataSet data =
      dpsA == null ? null : createMSMSDataSet(precursorMZA, rtA, dpsA, labelA);
  PseudoSpectrumDataSet dataMirror =
      dpsB == null ? null : createMSMSDataSet(precursorMZB, rtB, dpsB, labelB);

  NumberFormat mzForm = MZmineCore.getConfiguration().getMZFormat();
  NumberFormat intensityFormat = new DecimalFormat("0.#");

  // set the X axis (retention time) properties
  NumberAxis xAxis = new NumberAxis("m/z");
  xAxis.setNumberFormatOverride(mzForm);
  xAxis.setUpperMargin(0.08);
  xAxis.setLowerMargin(0.00);
  xAxis.setTickLabelInsets(new RectangleInsets(0, 0, 20, 20));
  xAxis.setAutoRangeIncludesZero(false);
  xAxis.setMinorTickCount(5);

  PseudoSpectraRenderer renderer1 = new PseudoSpectraRenderer(Color.BLACK, false);
  PseudoSpectraRenderer renderer2 = new PseudoSpectraRenderer(Color.BLACK, false);

  // create subplot 1...
  final NumberAxis rangeAxis1 = new NumberAxis("rel. intensity [%]");
  final XYPlot subplot1 = new XYPlot(data, null, rangeAxis1, renderer1);
  subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
  rangeAxis1.setNumberFormatOverride(intensityFormat);
  rangeAxis1.setAutoRangeIncludesZero(true);
  rangeAxis1.setAutoRangeStickyZero(true);

  // create subplot 2...
  final NumberAxis rangeAxis2 = new NumberAxis("rel. intensity [%]");
  rangeAxis2.setNumberFormatOverride(intensityFormat);
  rangeAxis2.setAutoRangeIncludesZero(true);
  rangeAxis2.setAutoRangeStickyZero(true);
  rangeAxis2.setInverted(true);
  final XYPlot subplot2 = new XYPlot(dataMirror, null, rangeAxis2, renderer2);
  subplot2.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);

  // parent plot...
  final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(xAxis);
  plot.setGap(0);

  // add the subplots...
  plot.add(subplot1, 1);
  plot.add(subplot2, 1);
  plot.setOrientation(PlotOrientation.VERTICAL);

  // set the plot properties
  plot.setBackgroundPaint(Color.white);
  plot.setAxisOffset(RectangleInsets.ZERO_INSETS);

  // set rendering order
  plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

  // set crosshair (selection) properties
  plot.setDomainCrosshairVisible(false);
  plot.setRangeCrosshairVisible(false);

  // return a new chart containing the overlaid plot...
  JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
  chart.setBackgroundPaint(Color.white);
  chart.getTitle().setVisible(false);

  chart.getXYPlot().setRangeZeroBaselineVisible(true);
  chart.getTitle().setVisible(showTitle);
  chart.getLegend().setVisible(showLegend);

  return chart;
}
 
Example 4
Source File: SpectrumChartFactory.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
public static EChartPanel createMirrorChartPanel(String labelA, double precursorMZA, double rtA,
    DataPoint[] dpsA, String labelB, double precursorMZB, double rtB, DataPoint[] dpsB,
    boolean showTitle, boolean showLegend) {
  PseudoSpectrumDataSet data =
      dpsA == null ? null : createMSMSDataSet(precursorMZA, rtA, dpsA, labelA);
  PseudoSpectrumDataSet dataMirror =
      dpsB == null ? null : createMSMSDataSet(precursorMZB, rtB, dpsB, labelB);

  NumberFormat mzForm = MZmineCore.getConfiguration().getMZFormat();
  NumberFormat intensityFormat = new DecimalFormat("0.#");

  // set the X axis (retention time) properties
  NumberAxis xAxis = new NumberAxis("m/z");
  xAxis.setNumberFormatOverride(mzForm);
  xAxis.setUpperMargin(0.08);
  xAxis.setLowerMargin(0.00);
  xAxis.setTickLabelInsets(new RectangleInsets(0, 0, 20, 20));
  xAxis.setAutoRangeIncludesZero(false);
  xAxis.setMinorTickCount(5);

  PseudoSpectraRenderer renderer1 = new PseudoSpectraRenderer(Color.BLACK, false);
  PseudoSpectraRenderer renderer2 = new PseudoSpectraRenderer(Color.BLACK, false);

  // create subplot 1...
  final NumberAxis rangeAxis1 = new NumberAxis("rel. intensity [%]");
  final XYPlot subplot1 = new XYPlot(data, null, rangeAxis1, renderer1);
  subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
  rangeAxis1.setNumberFormatOverride(intensityFormat);
  rangeAxis1.setAutoRangeIncludesZero(true);
  rangeAxis1.setAutoRangeStickyZero(true);

  // create subplot 2...
  final NumberAxis rangeAxis2 = new NumberAxis("rel. intensity [%]");
  rangeAxis2.setNumberFormatOverride(intensityFormat);
  rangeAxis2.setAutoRangeIncludesZero(true);
  rangeAxis2.setAutoRangeStickyZero(true);
  rangeAxis2.setInverted(true);
  final XYPlot subplot2 = new XYPlot(dataMirror, null, rangeAxis2, renderer2);
  subplot2.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);

  // parent plot...
  final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("Domain"));
  plot.setGap(0);

  // add the subplots...
  plot.add(subplot1, 1);
  plot.add(subplot2, 1);
  plot.setOrientation(PlotOrientation.VERTICAL);


  // set the plot properties
  plot.setBackgroundPaint(Color.white);
  plot.setAxisOffset(RectangleInsets.ZERO_INSETS);

  // set rendering order
  plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

  // set crosshair (selection) properties
  plot.setDomainCrosshairVisible(false);
  plot.setRangeCrosshairVisible(false);

  // return a new chart containing the overlaid plot...
  JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
  chart.setBackgroundPaint(Color.white);
  chart.getTitle().setVisible(false);

  // chart.getXYPlot().setRangeZeroBaselineVisible(true);
  chart.getTitle().setVisible(showTitle);
  chart.getLegend().setVisible(showLegend);

  return new EChartPanel(chart);
}