Java Code Examples for org.jfree.chart.plot.XYPlot#getDomainAxis()

The following examples show how to use org.jfree.chart.plot.XYPlot#getDomainAxis() . 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: XYBarRendererTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Check that the renderer is calculating the domain bounds correctly.
 */
@Test
public void testFindDomainBounds() {
    XYSeriesCollection dataset
            = RendererXYPackageUtils.createTestXYSeriesCollection();
    JFreeChart chart = ChartFactory.createXYBarChart("Test Chart", "X",
            false, "Y", dataset, PlotOrientation.VERTICAL, false, false,
            false);
    XYPlot plot = (XYPlot) chart.getPlot();
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);
    Range bounds = domainAxis.getRange();
    assertFalse(bounds.contains(0.3));
    assertTrue(bounds.contains(0.5));
    assertTrue(bounds.contains(2.5));
    assertFalse(bounds.contains(2.8));
}
 
Example 2
Source File: StandardXYItemRendererTest.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * A check to ensure that an item that falls outside the plot's data area
 * does NOT generate an item entity.
 */
@Test
public void testNoDisplayedItem() {
    XYSeriesCollection dataset = new XYSeriesCollection();
    XYSeries s1 = new XYSeries("S1");
    s1.add(10.0, 10.0);
    dataset.addSeries(s1);
    JFreeChart chart = ChartFactory.createXYLineChart("Title", "X", "Y",
            dataset, PlotOrientation.VERTICAL, false, true, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(new StandardXYItemRenderer());
    NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
    xAxis.setRange(0.0, 5.0);
    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setRange(0.0, 5.0);
    BufferedImage image = new BufferedImage(200 , 100,
            BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();
    ChartRenderingInfo info = new ChartRenderingInfo();
    chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, info);
    g2.dispose();
    EntityCollection ec = info.getEntityCollection();
    assertFalse(TestUtilities.containsInstanceOf(ec.getEntities(),
            XYItemEntity.class));
}
 
Example 3
Source File: StackedXYBarRendererTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check that the renderer is calculating the domain bounds correctly.
 */
public void testFindDomainBounds() {
    TableXYDataset dataset
            = RendererXYPackageTests.createTestTableXYDataset();
    JFreeChart chart = ChartFactory.createStackedXYAreaChart("Test Chart",
            "X", "Y", dataset, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(new StackedXYBarRenderer());
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);
    Range bounds = domainAxis.getRange();
    assertFalse(bounds.contains(0.3));
    assertTrue(bounds.contains(0.5));
    assertTrue(bounds.contains(2.5));
    assertFalse(bounds.contains(2.8));
}
 
Example 4
Source File: StackedXYBarRendererTest.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Check that the renderer is calculating the domain bounds correctly.
 */
@Test
public void testFindDomainBounds() {
    TableXYDataset dataset
            = RendererXYPackageUtils.createTestTableXYDataset();
    JFreeChart chart = ChartFactory.createStackedXYAreaChart(
            "Test Chart", "X", "Y", dataset,
            PlotOrientation.VERTICAL, false, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(new StackedXYBarRenderer());
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);
    Range bounds = domainAxis.getRange();
    assertFalse(bounds.contains(0.3));
    assertTrue(bounds.contains(0.5));
    assertTrue(bounds.contains(2.5));
    assertFalse(bounds.contains(2.8));
}
 
Example 5
Source File: NumberAxisTest.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Checks that the auto-range for the domain axis on an XYPlot is
 * working as expected.
 */
@Test
public void testXYAutoRange1() {
    XYSeries series = new XYSeries("Series 1");
    series.add(1.0, 1.0);
    series.add(2.0, 2.0);
    series.add(3.0, 3.0);
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(series);
    JFreeChart chart = ChartFactory.createScatterPlot("Test", "X", "Y",
            dataset);
    XYPlot plot = (XYPlot) chart.getPlot();
    NumberAxis axis = (NumberAxis) plot.getDomainAxis();
    axis.setAutoRangeIncludesZero(false);
    assertEquals(0.9, axis.getLowerBound(), EPSILON);
    assertEquals(3.1, axis.getUpperBound(), EPSILON);
}
 
Example 6
Source File: StackedXYBarRendererTest.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Check that the renderer is calculating the domain bounds correctly.
 */
@Test
public void testFindDomainBounds() {
    TableXYDataset dataset
            = RendererXYPackageUtils.createTestTableXYDataset();
    JFreeChart chart = ChartFactory.createStackedXYAreaChart(
            "Test Chart", "X", "Y", dataset,
            PlotOrientation.VERTICAL, false, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(new StackedXYBarRenderer());
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);
    Range bounds = domainAxis.getRange();
    assertFalse(bounds.contains(0.3));
    assertTrue(bounds.contains(0.5));
    assertTrue(bounds.contains(2.5));
    assertFalse(bounds.contains(2.8));
}
 
Example 7
Source File: TimeSeriesChartDemo1.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a chart.
 * 
 * @param dataset  a dataset.
 * 
 * @return A chart.
 */
private static JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart(
        "Legal & General Unit Trust Prices",  // title
        "Date",             // x-axis label
        "Price Per Unit",   // y-axis label
        dataset,            // data
        true,               // create legend?
        true,               // generate tooltips?
        false               // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    
    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
    }
    
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
    
    return chart;

}
 
Example 8
Source File: ChartLogics.java    From old-mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Auto range the range axis
 * 
 * @param myChart
 * @param zoom
 * @param autoRangeY if true the range (Y) axis auto bounds will be restored
 */
public static void autoDomainAxis(ChartPanel myChart) {
  XYPlot plot = (XYPlot) myChart.getChart().getPlot();
  NumberAxis axis = (NumberAxis) plot.getDomainAxis();
  // trick. Otherwise auto range will fail sometimes
  axis.setRange(axis.getRange());
  axis.setAutoRangeIncludesZero(false);
  myChart.restoreAutoDomainBounds();
}
 
Example 9
Source File: ChartLogics.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Zoom into a chart panel
 * 
 * @param myChart
 * @param zoom
 * @param autoRangeY if true the range (Y) axis auto bounds will be restored
 */
public static void setZoomDomainAxis(ChartPanel myChart, Range zoom, boolean autoRangeY) {
  XYPlot plot = (XYPlot) myChart.getChart().getPlot();
  ValueAxis domainAxis = plot.getDomainAxis();
  setZoomAxis(domainAxis, keepRangeWithinAutoBounds(domainAxis, zoom));

  if (autoRangeY) {
    autoRangeAxis(myChart);
  }
}
 
Example 10
Source File: ChartLogics.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Auto range the range axis
 * 
 * @param myChart
 * @param zoom
 * @param autoRangeY if true the range (Y) axis auto bounds will be restored
 */
public static void autoDomainAxis(ChartPanel myChart) {
  XYPlot plot = (XYPlot) myChart.getChart().getPlot();
  NumberAxis axis = (NumberAxis) plot.getDomainAxis();
  // trick. Otherwise auto range will fail sometimes
  axis.setRange(axis.getRange());
  axis.setAutoRangeIncludesZero(false);
  myChart.restoreAutoDomainBounds();
}
 
Example 11
Source File: XYLineAndShapeRendererTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check that the renderer is calculating the domain bounds correctly.
 */
public void testFindDomainBounds() {
    XYSeriesCollection dataset
            = RendererXYPackageTests.createTestXYSeriesCollection();
    JFreeChart chart = ChartFactory.createXYLineChart(
            "Test Chart", "X", "Y", dataset, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);
    Range bounds = domainAxis.getRange();
    assertFalse(bounds.contains(0.9));
    assertTrue(bounds.contains(1.0));
    assertTrue(bounds.contains(2.0));
    assertFalse(bounds.contains(2.10));
}
 
Example 12
Source File: AbstractChartPanel.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Restores the auto-range calculation on the domain axis.
 */

public void selectCompleteDomainBounds() {
	Plot plot = this.chart.getPlot();
	if (plot instanceof Zoomable) {
		Zoomable z = (Zoomable) plot;
		// here we tweak the notify flag on the plot so that only
		// one notification happens even though we update multiple
		// axes...
		boolean savedNotify = plot.isNotify();
		plot.setNotify(false);
		// we need to guard against this.zoomPoint being null
		Point2D zp = this.zoomPoint != null ? this.zoomPoint : new Point();
		z.zoomDomainAxes(0.0, this.info.getPlotInfo(), zp);
		plot.setNotify(savedNotify);

		if (plot instanceof XYPlot) {
			XYPlot xyPlot = (XYPlot) plot;
			Selection selectionObject = new Selection();
			for (int i = 0; i < xyPlot.getDomainAxisCount(); i++) {
				ValueAxis domain = xyPlot.getDomainAxis(i);
				Range axisRange = new Range(domain.getLowerBound(), domain.getUpperBound());
				for (String axisName : axisNameResolver.resolveXAxis(i)) {
					selectionObject.addDelimiter(axisName, axisRange);
				}
			}
			informSelectionListener(selectionObject, null);
		}
	}
}
 
Example 13
Source File: ChartLogicsFX.java    From old-mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Apply an absolute offset to domain (x) axis and move it
 * 
 * @param myChart
 * @param xoffset
 * @param autoRangeY
 */
public static void offsetDomainAxisAbsolute(ChartViewer myChart, double xoffset,
    boolean autoRangeY) {
  XYPlot plot = (XYPlot) myChart.getChart().getPlot();
  ValueAxis domainAxis = plot.getDomainAxis();
  // apply offset on x

  Range range =
      new Range(domainAxis.getLowerBound() + xoffset, domainAxis.getUpperBound() + xoffset);
  setZoomDomainAxis(myChart, keepRangeWithinAutoBounds(domainAxis, range), autoRangeY);
}
 
Example 14
Source File: SWTTimeSeriesDemo.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a chart.
 * 
 * @param dataset  a dataset.
 * 
 * @return A chart.
 */
private static JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart(
        "Legal & General Unit Trust Prices",  // title
        "Date",             // x-axis label
        "Price Per Unit",   // y-axis label
        dataset,            // data
        true,               // create legend?
        true,               // generate tooltips?
        false               // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    
    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
    }
    
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
    
    return chart;

}
 
Example 15
Source File: TimeSeriesChartDemo1.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a chart.
 *
 * @param dataset  a dataset.
 *
 * @return A chart.
 */
private static JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart(
        "Legal & General Unit Trust Prices",  // title
        "Date",             // x-axis label
        "Price Per Unit",   // y-axis label
        dataset,            // data
        true,               // create legend?
        true,               // generate tooltips?
        false               // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
        renderer.setDrawSeriesLineAsPath(true);
    }

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));

    return chart;

}
 
Example 16
Source File: DomLineChart.java    From DominionSim with MIT License 5 votes vote down vote up
private JFreeChart createChart(XYDataset dataset) {
        JFreeChart chart = ChartFactory.createXYLineChart(
            myType.equals("VP")? "Average Victory Points gained/turn" : "Average $ generated/turn",      // chart title
            "turns",                      // x axis label
            myType.equals("VP")? "VP gained" : "available money",                      // y axis label
            dataset,                  // data
            PlotOrientation.VERTICAL,
            true,                     // include legend
            true,                     // tooltips
            false                     // urls
        );
//        chart.setBackgroundPaint(Color.darkGray);
//        final StandardLegend legend = (StandardLegend) chart.getLegend();
  //      legend.setDisplaySeriesShapes(true);
        // get a reference to the plot for further customisation...
        final XYPlot plot = chart.getXYPlot();
        plot.setBackgroundPaint(Color.white);
//        plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
        plot.setDomainGridlinePaint(Color.black);
        plot.setRangeGridlinePaint(Color.black);
        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
        renderer.setSeriesPaint(0,Color.black);
        renderer.setSeriesPaint(1,Color.blue);
        renderer.setSeriesPaint(2,Color.red);
        renderer.setSeriesPaint(3,Color.cyan);
        renderer.setBaseShapesVisible(true);
        plot.setRenderer(renderer);
        // change the auto tick unit selection to integer units only...
        NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
        domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
//        domainAxis.setTickUnit( new NumberTickUnit( 1 ) );
        NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
//        rangeAxis.setTickUnit( new NumberTickUnit( 1 ) );
                
        return chart;
	}
 
Example 17
Source File: Scatter.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
public void setXRange( double min, double max ) {
    XYPlot plot = (XYPlot) getChart().getPlot();
    ValueAxis domainAxis = plot.getDomainAxis();
    domainAxis.setRange(min, max);
}
 
Example 18
Source File: ROCChartPlotter.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
private JFreeChart createChart(XYDataset dataset) {
	// create the chart...
	JFreeChart chart = ChartFactory.createXYLineChart(null,      // chart title
			null,                      // x axis label
			null,                      // y axis label
			dataset,                  // data
			PlotOrientation.VERTICAL, true,                     // include legend
			true,                     // tooltips
			false                     // urls
			);

	chart.setBackgroundPaint(Color.white);

	// get a reference to the plot for further customisation...
	XYPlot plot = (XYPlot) chart.getPlot();
	plot.setBackgroundPaint(Color.WHITE);
	plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
	plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
	plot.setRangeGridlinePaint(Color.LIGHT_GRAY);

	ValueAxis valueAxis = plot.getRangeAxis();
	valueAxis.setLabelFont(PlotterAdapter.LABEL_FONT_BOLD);
	valueAxis.setTickLabelFont(PlotterAdapter.LABEL_FONT);

	ValueAxis domainAxis = plot.getDomainAxis();
	domainAxis.setLabelFont(PlotterAdapter.LABEL_FONT_BOLD);
	domainAxis.setTickLabelFont(PlotterAdapter.LABEL_FONT);

	DeviationRenderer renderer = new DeviationRenderer(true, false);
	Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
	if (dataset.getSeriesCount() == 1) {
		renderer.setSeriesStroke(0, stroke);
		renderer.setSeriesPaint(0, Color.RED);
		renderer.setSeriesFillPaint(0, Color.RED);
	} else if (dataset.getSeriesCount() == 2) {
		renderer.setSeriesStroke(0, stroke);
		renderer.setSeriesPaint(0, Color.RED);
		renderer.setSeriesFillPaint(0, Color.RED);

		renderer.setSeriesStroke(1, stroke);
		renderer.setSeriesPaint(1, Color.BLUE);
		renderer.setSeriesFillPaint(1, Color.BLUE);
	} else {
		for (int i = 0; i < dataset.getSeriesCount(); i++) {
			renderer.setSeriesStroke(i, stroke);
			Color color = colorProvider.getPointColor((double) i / (double) (dataset.getSeriesCount() - 1));
			renderer.setSeriesPaint(i, color);
			renderer.setSeriesFillPaint(i, color);
		}
	}
	renderer.setAlpha(0.12f);
	plot.setRenderer(renderer);

	// legend settings
	LegendTitle legend = chart.getLegend();
	if (legend != null) {
		legend.setPosition(RectangleEdge.TOP);
		legend.setFrame(BlockBorder.NONE);
		legend.setHorizontalAlignment(HorizontalAlignment.LEFT);
		legend.setItemFont(PlotterAdapter.LABEL_FONT);
	}
	return chart;
}
 
Example 19
Source File: SpectrumChartFactory.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
public static JFreeChart createChart(PseudoSpectrumDataSet dataset, boolean showTitle,
    boolean showLegend, double rt, double precursorMZ) {
  //
  if (dataset == null)
    return null;
  //
  NumberFormat mzForm = MZmineCore.getConfiguration().getMZFormat();
  NumberFormat rtForm = MZmineCore.getConfiguration().getRTFormat();
  NumberFormat intensityFormat = MZmineCore.getConfiguration().getIntensityFormat();

  String title = "";
  if (precursorMZ == 0)
    title = "RT=" + mzForm.format(precursorMZ);
  else
    title = MessageFormat.format("MSMS for m/z={0} RT={1}", mzForm.format(precursorMZ),
        rtForm.format(rt));

  JFreeChart chart = ChartFactory.createXYLineChart(title, // title
      "m/z", // x-axis label
      "Intensity", // y-axis label
      dataset, // data set
      PlotOrientation.VERTICAL, // orientation
      true, // isotopeFlag, // create legend?
      true, // generate tooltips?
      false // generate URLs?
  );
  chart.setBackgroundPaint(Color.white);
  chart.getTitle().setVisible(false);
  // set the plot properties
  XYPlot plot = chart.getXYPlot();
  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);

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

  // set the Y axis (intensity) properties
  NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
  yAxis.setNumberFormatOverride(intensityFormat);
  yAxis.setUpperMargin(0.20);

  PseudoSpectraRenderer renderer = new PseudoSpectraRenderer(Color.BLACK, false);
  plot.setRenderer(0, renderer);
  plot.setRenderer(1, renderer);
  plot.setRenderer(2, renderer);
  renderer.setSeriesVisibleInLegend(1, false);
  renderer.setSeriesPaint(2, Color.ORANGE);
  //
  chart.getTitle().setVisible(showTitle);
  chart.getLegend().setVisible(showLegend);
  //
  if (precursorMZ != 0)
    addPrecursorMarker(chart, precursorMZ);
  return chart;
}
 
Example 20
Source File: MsSpectrumPlotWindowController.java    From old-mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
public void initialize() {

    final JFreeChart chart = chartNode.getChart();
    final XYPlot plot = chart.getXYPlot();

    // Do not set colors and strokes dynamically. They are instead provided
    // by the dataset and configured in configureRenderer()
    plot.setDrawingSupplier(null);
    plot.setDomainGridlinePaint(JavaFXUtil.convertColorToAWT(gridColor));
    plot.setRangeGridlinePaint(JavaFXUtil.convertColorToAWT(gridColor));
    plot.setBackgroundPaint(JavaFXUtil.convertColorToAWT(backgroundColor));
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);

    // chart properties
    chart.setBackgroundPaint(JavaFXUtil.convertColorToAWT(backgroundColor));

    // legend properties
    LegendTitle legend = chart.getLegend();
    // legend.setItemFont(legendFont);
    legend.setFrame(BlockBorder.NONE);

    // set the X axis (m/z) properties
    NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
    xAxis.setLabel("m/z");
    xAxis.setUpperMargin(0.03);
    xAxis.setLowerMargin(0.03);
    xAxis.setRangeType(RangeType.POSITIVE);
    xAxis.setTickLabelInsets(new RectangleInsets(0, 0, 20, 20));

    // set the Y axis (intensity) properties
    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setLabel("Intensity");
    yAxis.setRangeType(RangeType.POSITIVE);
    yAxis.setAutoRangeIncludesZero(true);

    // set the fixed number formats, because otherwise JFreeChart sometimes
    // shows exponent, sometimes it doesn't
    DecimalFormat mzFormat = MZmineCore.getConfiguration().getMZFormat();
    xAxis.setNumberFormatOverride(mzFormat);
    DecimalFormat intensityFormat = MZmineCore.getConfiguration().getIntensityFormat();
    yAxis.setNumberFormatOverride(intensityFormat);

    chartTitle = chartNode.getChart().getTitle();
    chartTitle.setMargin(5, 0, 0, 0);
    chartTitle.setFont(titleFont);

    chartNode.setCursor(Cursor.CROSSHAIR);

    // Remove the dataset if it is removed from the list
    datasets.addListener((Change<? extends MsSpectrumDataSet> c) -> {
      while (c.next()) {
        if (c.wasRemoved()) {
          for (MsSpectrumDataSet ds : c.getRemoved()) {
            int index = plot.indexOf(ds);
            plot.setDataset(index, null);
          }
        }
      }
    });

    itemLabelsVisible.addListener((prop, oldVal, newVal) -> {
      for (MsSpectrumDataSet dataset : datasets) {
        int datasetIndex = plot.indexOf(dataset);
        XYItemRenderer renderer = plot.getRenderer(datasetIndex);
        renderer.setBaseItemLabelsVisible(newVal);
      }
    });

    legendVisible.addListener((prop, oldVal, newVal) -> {
      legend.setVisible(newVal);
    });

  }