org.jfree.chart.plot.CombinedDomainXYPlot Java Examples

The following examples show how to use org.jfree.chart.plot.CombinedDomainXYPlot. 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: SpectralMatchPanel.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
public void setChartFont(Font chartFont) {
  this.chartFont = chartFont;
  if (mirrorChart != null) {

    // add datasets and renderer
    // set up renderer
    CombinedDomainXYPlot domainPlot = (CombinedDomainXYPlot) mirrorChart.getChart().getXYPlot();
    NumberAxis axis = (NumberAxis) domainPlot.getDomainAxis();
    axis.setLabel("m/z");
    XYPlot queryPlot = (XYPlot) domainPlot.getSubplots().get(0);
    XYPlot libraryPlot = (XYPlot) domainPlot.getSubplots().get(1);
    domainPlot.getDomainAxis().setLabelFont(chartFont);
    domainPlot.getDomainAxis().setTickLabelFont(chartFont);
    queryPlot.getRangeAxis().setLabelFont(chartFont);
    queryPlot.getRangeAxis().setTickLabelFont(chartFont);
    libraryPlot.getRangeAxis().setLabelFont(chartFont);
    libraryPlot.getRangeAxis().setTickLabelFont(chartFont);
  }
}
 
Example #2
Source File: SwingCombinedChartGestureDemo.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
private JFreeChart createCombinedChart() {
  // create subplot 1...
  final XYDataset data1 = createDataset();
  final XYItemRenderer renderer1 = new StandardXYItemRenderer();
  final NumberAxis rangeAxis1 = new NumberAxis("Range 1");
  final XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1);

  // create subplot 2...
  final XYDataset data2 = createDataset();
  final XYItemRenderer renderer2 = new StandardXYItemRenderer();
  final NumberAxis rangeAxis2 = new NumberAxis("Range 2");
  final XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2);

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

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

  // return a new chart containing the overlaid plot...
  return new JFreeChart("CombinedDomainXYPlot Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
}
 
Example #3
Source File: FXCombinedChartGestureDemo.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
private JFreeChart createCombinedChart() {
  // create subplot 1...
  final XYDataset data1 = createDataset();
  final XYItemRenderer renderer1 = new StandardXYItemRenderer();
  final NumberAxis rangeAxis1 = new NumberAxis("Range 1");
  final XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1);

  // create subplot 2...
  final XYDataset data2 = createDataset();
  final XYItemRenderer renderer2 = new StandardXYItemRenderer();
  final NumberAxis rangeAxis2 = new NumberAxis("Range 2");
  final XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2);

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

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

  // return a new chart containing the overlaid plot...
  return new JFreeChart("CombinedDomainXYPlot Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
}
 
Example #4
Source File: SwingCombinedChartGestureDemo.java    From old-mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
private JFreeChart createCombinedChart() {
  // create subplot 1...
  final XYDataset data1 = createDataset();
  final XYItemRenderer renderer1 = new StandardXYItemRenderer();
  final NumberAxis rangeAxis1 = new NumberAxis("Range 1");
  final XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1);

  // create subplot 2...
  final XYDataset data2 = createDataset();
  final XYItemRenderer renderer2 = new StandardXYItemRenderer();
  final NumberAxis rangeAxis2 = new NumberAxis("Range 2");
  final XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2);

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

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

  // return a new chart containing the overlaid plot...
  return new JFreeChart("CombinedDomainXYPlot Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
}
 
Example #5
Source File: FXCombinedChartGestureDemo.java    From old-mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
private JFreeChart createCombinedChart() {
      // create subplot 1...
      final XYDataset data1 = createDataset();
      final XYItemRenderer renderer1 = new StandardXYItemRenderer();
      final NumberAxis rangeAxis1 = new NumberAxis("Range 1");
      final XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1);
      
      // create subplot 2...
      final XYDataset data2 = createDataset();
      final XYItemRenderer renderer2 = new StandardXYItemRenderer();
      final NumberAxis rangeAxis2 = new NumberAxis("Range 2");
      final XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2);

      // parent plot...
      final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("Domain"));
      plot.setGap(10.0);
      
      // add the subplots...
      plot.add(subplot1, 1);
      plot.add(subplot2, 1);
      plot.setOrientation(PlotOrientation.VERTICAL);

      // return a new chart containing the overlaid plot...
      return new JFreeChart("CombinedDomainXYPlot Demo",
                            JFreeChart.DEFAULT_TITLE_FONT, plot, true);
}
 
Example #6
Source File: SpectralMatchPanel.java    From mzmine2 with GNU General Public License v2.0 6 votes vote down vote up
public void setChartFont(Font chartFont) {
  this.chartFont = chartFont;
  if (mirrorChart != null) {

    // add datasets and renderer
    // set up renderer
    CombinedDomainXYPlot domainPlot = (CombinedDomainXYPlot) mirrorChart.getChart().getXYPlot();
    NumberAxis axis = (NumberAxis) domainPlot.getDomainAxis();
    axis.setLabel("m/z");
    XYPlot queryPlot = (XYPlot) domainPlot.getSubplots().get(0);
    XYPlot libraryPlot = (XYPlot) domainPlot.getSubplots().get(1);
    domainPlot.getDomainAxis().setLabelFont(chartFont);
    domainPlot.getDomainAxis().setTickLabelFont(chartFont);
    queryPlot.getRangeAxis().setLabelFont(chartFont);
    queryPlot.getRangeAxis().setTickLabelFont(chartFont);
    libraryPlot.getRangeAxis().setLabelFont(chartFont);
    libraryPlot.getRangeAxis().setTickLabelFont(chartFont);
  }
}
 
Example #7
Source File: CombinedDomainXYPlotTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check that only one chart change event is generated by a change to a
 * subplot.
 */
public void testNotification() {
    CombinedDomainXYPlot plot = createPlot();
    JFreeChart chart = new JFreeChart(plot);
    chart.addChangeListener(this);
    XYPlot subplot1 = (XYPlot) plot.getSubplots().get(0);
    NumberAxis yAxis = (NumberAxis) subplot1.getRangeAxis();
    yAxis.setAutoRangeIncludesZero(!yAxis.getAutoRangeIncludesZero());
    assertEquals(1, this.events.size());

    // a redraw should NOT trigger another change event
    BufferedImage image = new BufferedImage(200, 100,
            BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();
    this.events.clear();
    chart.draw(g2, new Rectangle2D.Double(0.0, 0.0, 200.0, 100.0));
    assertTrue(this.events.isEmpty());
}
 
Example #8
Source File: SwingCombinedChartGestureDemo.java    From mzmine2 with GNU General Public License v2.0 6 votes vote down vote up
private JFreeChart createCombinedChart() {
  // create subplot 1...
  final XYDataset data1 = createDataset();
  final XYItemRenderer renderer1 = new StandardXYItemRenderer();
  final NumberAxis rangeAxis1 = new NumberAxis("Range 1");
  final XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1);

  // create subplot 2...
  final XYDataset data2 = createDataset();
  final XYItemRenderer renderer2 = new StandardXYItemRenderer();
  final NumberAxis rangeAxis2 = new NumberAxis("Range 2");
  final XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2);

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

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

  // return a new chart containing the overlaid plot...
  return new JFreeChart("CombinedDomainXYPlot Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
}
 
Example #9
Source File: FXCombinedChartGestureDemo.java    From mzmine2 with GNU General Public License v2.0 6 votes vote down vote up
private JFreeChart createCombinedChart() {
      // create subplot 1...
      final XYDataset data1 = createDataset();
      final XYItemRenderer renderer1 = new StandardXYItemRenderer();
      final NumberAxis rangeAxis1 = new NumberAxis("Range 1");
      final XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1);
      
      // create subplot 2...
      final XYDataset data2 = createDataset();
      final XYItemRenderer renderer2 = new StandardXYItemRenderer();
      final NumberAxis rangeAxis2 = new NumberAxis("Range 2");
      final XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2);

      // parent plot...
      final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("Domain"));
      plot.setGap(10.0);
      
      // add the subplots...
      plot.add(subplot1, 1);
      plot.add(subplot2, 1);
      plot.setOrientation(PlotOrientation.VERTICAL);

      // return a new chart containing the overlaid plot...
      return new JFreeChart("CombinedDomainXYPlot Demo",
                            JFreeChart.DEFAULT_TITLE_FONT, plot, true);
}
 
Example #10
Source File: TileCacheMonitor.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private static TimeSeriesCollection addSubPlot(CombinedDomainXYPlot plot, String label) {
    final TimeSeriesCollection seriesCollection = new TimeSeriesCollection(new TimeSeries(label, Millisecond.class));
    NumberAxis rangeAxis = new NumberAxis();
    rangeAxis.setAutoRangeIncludesZero(false);
    XYPlot subplot = new XYPlot(seriesCollection, null, rangeAxis, new StandardXYItemRenderer());
    subplot.setBackgroundPaint(Color.lightGray);
    subplot.setDomainGridlinePaint(Color.white);
    subplot.setRangeGridlinePaint(Color.white);
    plot.add(subplot);
    return seriesCollection;
}
 
Example #11
Source File: CombinedDomainXYPlotTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a sample plot.
 * 
 * @return A sample plot.
 */
private CombinedDomainXYPlot createPlot() {
    // create subplot 1...
    XYDataset data1 = createDataset1();
    XYItemRenderer renderer1 = new StandardXYItemRenderer();
    NumberAxis rangeAxis1 = new NumberAxis("Range 1");
    XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1);
    subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    
    XYTextAnnotation annotation 
        = new XYTextAnnotation("Hello!", 50.0, 10000.0);
    annotation.setFont(new Font("SansSerif", Font.PLAIN, 9));
    annotation.setRotationAngle(Math.PI / 4.0);
    subplot1.addAnnotation(annotation);
    
    // create subplot 2...
    XYDataset data2 = createDataset2();
    XYItemRenderer renderer2 = new StandardXYItemRenderer();
    NumberAxis rangeAxis2 = new NumberAxis("Range 2");
    rangeAxis2.setAutoRangeIncludesZero(false);
    XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2);
    subplot2.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);

    // parent plot...
    CombinedDomainXYPlot plot 
        = new CombinedDomainXYPlot(new NumberAxis("Domain"));
    plot.setGap(10.0);
    
    // add the subplots...
    plot.add(subplot1, 1);
    plot.add(subplot2, 1);
    plot.setOrientation(PlotOrientation.VERTICAL);
    return plot;
}
 
Example #12
Source File: CombinedDomainXYPlotTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests the equals() method.
 */
public void testEquals() {
    CombinedDomainXYPlot plot1 = createPlot();
    CombinedDomainXYPlot plot2 = createPlot();
    assertTrue(plot1.equals(plot2));    
    assertTrue(plot2.equals(plot1));
}
 
Example #13
Source File: CombinedDomainXYPlotTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * This is a test to replicate the bug report 987080.
 */
public void testRemoveSubplot() {
    CombinedDomainXYPlot plot = new CombinedDomainXYPlot();
    XYPlot plot1 = new XYPlot();
    XYPlot plot2 = new XYPlot();
    plot.add(plot1);
    plot.add(plot2);
    // remove plot2, but plot1 is removed instead
    plot.remove(plot2);
    List plots = plot.getSubplots();
    assertTrue(plots.get(0) == plot1);
}
 
Example #14
Source File: CombinedDomainXYPlotTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a sample plot.
 *
 * @return A sample plot.
 */
private CombinedDomainXYPlot createPlot() {
    // create subplot 1...
    XYDataset data1 = createDataset1();
    XYItemRenderer renderer1 = new StandardXYItemRenderer();
    NumberAxis rangeAxis1 = new NumberAxis("Range 1");
    XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1);
    subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    XYTextAnnotation annotation
        = new XYTextAnnotation("Hello!", 50.0, 10000.0);
    annotation.setFont(new Font("SansSerif", Font.PLAIN, 9));
    annotation.setRotationAngle(Math.PI / 4.0);
    subplot1.addAnnotation(annotation);

    // create subplot 2...
    XYDataset data2 = createDataset2();
    XYItemRenderer renderer2 = new StandardXYItemRenderer();
    NumberAxis rangeAxis2 = new NumberAxis("Range 2");
    rangeAxis2.setAutoRangeIncludesZero(false);
    XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2);
    subplot2.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);

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

    // add the subplots...
    plot.add(subplot1, 1);
    plot.add(subplot2, 1);
    plot.setOrientation(PlotOrientation.VERTICAL);
    return plot;
}
 
Example #15
Source File: CombinedDomainXYPlotTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests the equals() method.
 */
public void testEquals() {
    CombinedDomainXYPlot plot1 = createPlot();
    CombinedDomainXYPlot plot2 = createPlot();
    assertTrue(plot1.equals(plot2));
    assertTrue(plot2.equals(plot1));
}
 
Example #16
Source File: CombinedDomainXYPlotTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * This is a test to replicate the bug report 987080.
 */
public void testRemoveSubplot() {
    CombinedDomainXYPlot plot = new CombinedDomainXYPlot();
    XYPlot plot1 = new XYPlot();
    XYPlot plot2 = new XYPlot();
    plot.add(plot1);
    plot.add(plot2);
    // remove plot2, but plot1 is removed instead
    plot.remove(plot2);
    List plots = plot.getSubplots();
    assertTrue(plots.get(0) == plot1);
}
 
Example #17
Source File: GUIUtils.java    From egads with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Compute the time-series of anomalies.
 */
public void addAnomalyTS(CombinedDomainXYPlot plot, DataSequence observedSeries, DataSequence expectedSeries) {
    // Compute the time-series of errors.
    HashMap<String, ArrayList<Float>> allErrors = aes.initAnomalyErrors(observedSeries, expectedSeries);
    Float sDAutoSensitivity = (float) 0.0;
    Float amntAutoSensitivity = (float) 0.0;
    if (config.getProperty("AUTO_SENSITIVITY_ANOMALY_PCNT") != null) {
      amntAutoSensitivity = new Float(config.getProperty("AUTO_SENSITIVITY_ANOMALY_PCNT"));
    }
    
    if (config.getProperty("AUTO_SENSITIVITY_SD") != null) {
      sDAutoSensitivity = new Float(config.getProperty("AUTO_SENSITIVITY_SD"));
    }

    String errorDebug = "";
    for (int i = 0; i < (aes.getIndexToError().keySet()).size(); i++) {
        Float[] fArray = (allErrors.get(aes.getIndexToError().get(i))).toArray(new Float[(allErrors.get(aes.getIndexToError().get(i))).size()]);
        XYDataset data1 = createDataset(fArray, aes.getIndexToError().get(i));
        XYItemRenderer renderer1 = new StandardXYItemRenderer();
        NumberAxis rangeAxis1 = new NumberAxis(aes.getIndexToError().get(i));
        XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1);
        // Get threshold.
        Float d = AutoSensitivity.getLowDensitySensitivity(fArray, sDAutoSensitivity, amntAutoSensitivity);
        subplot1.addRangeMarker(new ValueMarker(d));
        subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
        plot.add(subplot1, 1);
        errorDebug += aes.getIndexToError().get(i) + ": " + d + " ";
    }
    
    System.out.println(errorDebug);
}
 
Example #18
Source File: GUIUtils.java    From egads with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a combined chart.
 *
 * @return The combined chart.
 */
private JFreeChart createCombinedChart(DataSequence tsOne, DataSequence tsTwo, ArrayList<Anomaly> anomalyList) {

    // create subplot 1.
    final XYDataset data1 = createDataset(tsOne, "Original");
    final XYItemRenderer renderer1 = new StandardXYItemRenderer();
    final NumberAxis rangeAxis1 = new NumberAxis("Original Value");
    XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1);
    subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    
    // plot anomalies on subplot 1.
    addAnomalies(subplot1, anomalyList);
    
    // create subplot 2.
    final XYDataset data2 = createDataset(tsTwo, "Forecast");
    final XYItemRenderer renderer2 = new StandardXYItemRenderer();
    final NumberAxis rangeAxis2 = new NumberAxis("Forecast Value");
    rangeAxis2.setAutoRangeIncludesZero(false);
    final XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2);
    subplot2.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);

    // parent plot.
    final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("Time"));
    plot.setGap(10.0);
    
    // add the subplots.
    plot.add(subplot1, 1);
    plot.add(subplot2, 1);
    
    // Add anomaly score time-series.
    addAnomalyTS(plot, tsOne, tsTwo);
    
    plot.setOrientation(PlotOrientation.VERTICAL);

    // return a new chart containing the overlaid plot.
    return new JFreeChart("EGADS GUI",
                          JFreeChart.DEFAULT_TITLE_FONT,
                          plot,
                          true);
}
 
Example #19
Source File: CombinedDomainXYPlotTests.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Confirm that the constructor will accept a null axis.
 */
public void testConstructor1() {
    CombinedDomainXYPlot plot = new CombinedDomainXYPlot(null);
    assertEquals(null, plot.getDomainAxis());
}
 
Example #20
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);
}
 
Example #21
Source File: CombinedDomainXYPlotTests.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Confirm that the constructor will accept a null axis.
 */
public void testConstructor1() {
    CombinedDomainXYPlot plot = new CombinedDomainXYPlot(null);
    assertEquals(null, plot.getDomainAxis());
}
 
Example #22
Source File: StlPlotter.java    From stl-java with Apache License 2.0 4 votes vote down vote up
private JFreeChart createChart() {

      final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis("Time"));
      final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);
      final ClusteredXYBarRenderer barRenderer = new ClusteredXYBarRenderer();
      final GradientPaint black = new GradientPaint(0.0f, 0.0f, Color.black, 0.0f, 0.0f, Color.black);

      final TimeSeries seriests = new TimeSeries("Series");
      final TimeSeries seasonalts = new TimeSeries("Seasonal");
      final TimeSeries trendts = new TimeSeries("Trend");
      final TimeSeries remainderts = new TimeSeries("Remainder");

      final TimeSeries[] tsArray = new TimeSeries[]{seriests, seasonalts, trendts};
      final String[] labels = new String[]{"Series", "Seasonal", "Trend"};

      for (int i = 0; i < series.length; i++) {
        final Date d = new Date((long) times[i]);
        RegularTimePeriod rtp = RegularTimePeriod.createInstance(this.timePeriod, d, TimeZone.getDefault());
        seriests.addOrUpdate(rtp, series[i]);
        seasonalts.addOrUpdate(rtp, seasonal[i]);
        trendts.addOrUpdate(rtp, trend[i]);
        remainderts.addOrUpdate(rtp, remainder[i]);
      }

      plot.setGap(10.0);
      renderer.setSeriesPaint(0, black);
      barRenderer.setSeriesPaint(0, black);
      plot.setOrientation(PlotOrientation.VERTICAL);

      for (int i = 0; i < tsArray.length; i++) {
        final XYDataset ts = new TimeSeriesCollection(tsArray[i]);
        final XYPlot p = new XYPlot(ts, new DateAxis(labels[i]), new NumberAxis(labels[i]), renderer);
        plot.add(p);
      }

      final XYDataset rts = new TimeSeriesCollection(remainderts);
      final XYDataset sts = new TimeSeriesCollection(seriests);
      final XYDataset tts = new TimeSeriesCollection(trendts);
      final XYPlot rplot = new XYPlot(rts, new DateAxis(), new NumberAxis("Remainder"), barRenderer);
      final XYPlot seriesAndTrend = new XYPlot(sts, new DateAxis(), new NumberAxis("S & T"), renderer);

      seriesAndTrend.setDataset(1, tts);
      seriesAndTrend.setRenderer(1, renderer);

      plot.add(rplot);
      plot.add(seriesAndTrend);

      return new JFreeChart(this.title, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    }
 
Example #23
Source File: TaChartViewer.java    From TAcharting with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Creates a new viewer instance.
 *
 * @param chart  the org.sjwimmer.tacharting.chart ({@code null} permitted).
 * @param contextMenuEnabled  enable the context menu?
 */
public TaChartViewer(JFreeChart chart, boolean contextMenuEnabled) {
    this.canvas = new TaChartCanvas(chart);
    this.canvas.setTooltipEnabled(true);
    this.canvas.addMouseHandler(new TaZoomHandlerFX("zoom", this));
    setFocusTraversable(true);
    getChildren().add(this.canvas);

    this.zoomRectangle = new Rectangle(0, 0, new Color(0, 0, 1, 0.5));
    this.zoomRectangle.setManaged(false);
    this.zoomRectangle.setVisible(false);
    getChildren().add(this.zoomRectangle);

    this.contextMenu = createContextMenu();
    setOnContextMenuRequested((ContextMenuEvent event) -> {
        contextMenu.show(TaChartViewer.this.getScene().getWindow(),
                event.getScreenX(), event.getScreenY());
    });

    getContextMenu().setOnShowing(
            e -> TaChartViewer.this.getCanvas().setTooltipEnabled(false));
    getContextMenu().setOnHiding(
            e -> TaChartViewer.this.getCanvas().setTooltipEnabled(true));

    this.xCrosshair = new Line(0,0,this.getPrefWidth(),0);
    this.yCrosshair = new Line(0,0,0,this.getPrefHeight());
    this.xCrosshair.setMouseTransparent(true);
    this.yCrosshair.setMouseTransparent(true);
    this.getChildren().add(xCrosshair);
    this.getChildren().add(yCrosshair);
    this.xLabel = new Label("");
    this.yLabel = new Label("");
    this.yLabel.setMouseTransparent(true);
    this.xLabel.setMouseTransparent(true);
    this.getChildren().add(xLabel);
    this.getChildren().add(yLabel);


    /**Custom Mouse Listener for the CrosshairOverlay */
    this.setOnMouseMoved( e ->{
        final double x = e.getX();
        final double y = e.getY();


        Rectangle2D dataArea = getCanvas().getRenderingInfo().getPlotInfo().getDataArea();

        if(x > dataArea.getMinX() && y > dataArea.getMinY() && x < dataArea.getMaxX() && y < dataArea.getMaxY()) {
            setCrosshairVisible(true);
            CombinedDomainXYPlot combinedDomainXYPlot = (CombinedDomainXYPlot) getCanvas().getChart().getPlot();
            XYPlot plot = (XYPlot) combinedDomainXYPlot.getSubplots().get(0);

            org.jfree.chart.axis.ValueAxis xAxis = plot.getDomainAxis();
            RectangleEdge xAxisEdge = plot.getDomainAxisEdge();

            xCrosshair.setStartY(dataArea.getMinY());
            xCrosshair.setStartX(x);
            xCrosshair.setEndY(dataArea.getMaxY());
            xCrosshair.setEndX(x);
            xLabel.setLayoutX(x);
            xLabel.setLayoutY(dataArea.getMinY());

            double value = xAxis.java2DToValue(e.getX(), dataArea, xAxisEdge);
            long itemLong = (long) (value);
            Date itemDate = new Date(itemLong);
            xLabel.setText(String.valueOf(new SimpleDateFormat().format(itemDate)));


            org.jfree.chart.axis.ValueAxis yAxis = plot.getRangeAxis();
            RectangleEdge yAxisEdge = plot.getRangeAxisEdge();
            Rectangle2D subDataArea = getCanvas().getRenderingInfo().getPlotInfo().getSubplotInfo(0).getDataArea();

            yCrosshair.setStartY(y);
            yCrosshair.setStartX(dataArea.getMinX());
            yCrosshair.setEndX(dataArea.getMaxX());
            yCrosshair.setEndY(y);
            yLabel.setLayoutY(y);
            yLabel.setLayoutX(dataArea.getMinX());
            String yValue = CalculationUtils.roundToString(yAxis.java2DToValue(y, subDataArea, yAxisEdge), 2);
            yLabel.setText(yValue);
        } else {
            setCrosshairVisible(false);
        }
    });
}
 
Example #24
Source File: TileCacheMonitor.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates a new monitor panel.
 *
 * @return the monitor panel
 */
public JPanel createPanel() {

    JPanel mainPanel = new JPanel(new BorderLayout());
    CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis("Time"));
    this.datasets = new TimeSeriesCollection[4];
    this.datasets[0] = addSubPlot(plot, "#Tiles");
    this.datasets[1] = addSubPlot(plot, "#Hits");
    this.datasets[2] = addSubPlot(plot, "#Misses");
    this.datasets[3] = addSubPlot(plot, "Mem (kB)");

    JFreeChart chart = new JFreeChart(plot);
    LegendTitle legend = (LegendTitle) chart.getSubtitle(0);
    legend.setPosition(RectangleEdge.RIGHT);
    legend.setMargin(new RectangleInsets(UnitType.ABSOLUTE, 0, 4, 0, 4));
    chart.setBorderPaint(Color.black);
    chart.setBorderVisible(true);
    chart.setBackgroundPaint(Color.white);

    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(4, 4, 4, 4));
    ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);
    axis.setFixedAutoRange(60000.0);  // 60 seconds

    textarea = new JTextArea();
    tableModel = new TileCacheTableModel();
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 470));
    chartPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    tabbedPane = new JTabbedPane();
    tabbedPane.add(CACHE_INFO_TAB, new JScrollPane(textarea));
    tabbedPane.add(CACHE_CHART_TAB, chartPanel);
    tabbedPane.add(IMAGES_TAB, new JScrollPane(new JTable(tableModel)));
    tabbedPane.setSelectedIndex(0);

    mainPanel.add(tabbedPane);

    return mainPanel;
}
 
Example #25
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;
}