Example #1
0
  /** Some checks for the setLowerBound() method. */
  @Test
  public void testSetLowerBound() {
    NumberAxis axis = new NumberAxis("X");
    axis.setRange(0.0, 10.0);
    axis.setLowerBound(5.0);
    assertEquals(5.0, axis.getLowerBound(), EPSILON);
    axis.setLowerBound(10.0);
    assertEquals(10.0, axis.getLowerBound(), EPSILON);
    assertEquals(11.0, axis.getUpperBound(), EPSILON);

    // axis.setRangeType(RangeType.POSITIVE);
    // axis.setLowerBound(-5.0);
    // assertEquals(0.0, axis.getLowerBound(), EPSILON);
  }
  /**
   * Set lower and upper limits for an ordinate
   *
   * @param axis Axis to configure
   */
  void setOrdinateRange(final NumberAxis axis) {
    axis.setAutoRange(false);
    GridPane grid = new GridPane();
    grid.setHgap(10);
    grid.setVgap(10);
    grid.setPadding(new Insets(0, 10, 0, 10));
    final TextField tfMax;
    final TextField tfMin;
    final TextField tfTick;
    final TextField tfFuente;
    grid.add(new Label("Axis"), 0, 0);
    grid.add(new Label(axis.getLabel()), 1, 0);
    grid.add(new Label("Lower"), 0, 1);
    grid.add(tfMin = new TextField(), 1, 1);
    grid.add(new Label("Upper"), 0, 2);
    grid.add(tfMax = new TextField(), 1, 2);
    grid.add(new Label("Space"), 0, 3);
    grid.add(tfTick = new TextField(), 1, 3);

    tfMin.setText(String.valueOf(axis.getLowerBound()));
    tfMax.setText(String.valueOf(axis.getUpperBound()));
    tfTick.setText(String.valueOf(axis.getTickUnit().getSize()));

    new PseudoModalDialog(skeleton, grid, true) {
      @Override
      public boolean validation() {
        axis.setLowerBound(Double.valueOf(tfMin.getText()));
        axis.setUpperBound(Double.valueOf(tfMax.getText()));
        axis.setTickUnit(new NumberTickUnit(Double.valueOf(tfTick.getText())));
        return true;
      }
    }.show();
  }
Example #3
0
 /**
  * A simple test for the auto-range calculation looking at a NumberAxis used as the range axis for
  * a CategoryPlot.
  */
 @Test
 public void testAutoRange1() {
   DefaultCategoryDataset dataset = new DefaultCategoryDataset();
   dataset.setValue(100.0, "Row 1", "Column 1");
   dataset.setValue(200.0, "Row 1", "Column 2");
   JFreeChart chart = ChartFactory.createBarChart("Test", "Categories", "Value", dataset);
   CategoryPlot plot = (CategoryPlot) chart.getPlot();
   NumberAxis axis = (NumberAxis) plot.getRangeAxis();
   assertEquals(axis.getLowerBound(), 0.0, EPSILON);
   assertEquals(axis.getUpperBound(), 210.0, EPSILON);
 }
  /**
   * A simple test for the auto-range calculation looking at a NumberAxis used as the range axis for
   * a CategoryPlot. In this case, the 'autoRangeIncludesZero' flag is set to false AND the original
   * dataset is replaced with a new dataset.
   */
  public void testAutoRange3() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.setValue(100.0, "Row 1", "Column 1");
    dataset.setValue(200.0, "Row 1", "Column 2");
    JFreeChart chart =
        ChartFactory.createBarChart(
            "Test", "Categories", "Value", dataset, PlotOrientation.VERTICAL, false, false, false);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    NumberAxis axis = (NumberAxis) plot.getRangeAxis();
    axis.setAutoRangeIncludesZero(false);
    assertEquals(axis.getLowerBound(), 95.0, EPSILON);
    assertEquals(axis.getUpperBound(), 205.0, EPSILON);

    // now replacing the dataset should update the axis range...
    DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
    dataset2.setValue(900.0, "Row 1", "Column 1");
    dataset2.setValue(1000.0, "Row 1", "Column 2");
    plot.setDataset(dataset2);
    assertEquals(axis.getLowerBound(), 895.0, EPSILON);
    assertEquals(axis.getUpperBound(), 1005.0, EPSILON);
  }
Example #5
0
 /**
  * A simple test for the auto-range calculation looking at a NumberAxis used as the range axis for
  * a CategoryPlot. In this case, the 'autoRangeIncludesZero' flag is set to false.
  */
 @Test
 public void testAutoRange2() {
   DefaultCategoryDataset dataset = new DefaultCategoryDataset();
   dataset.setValue(100.0, "Row 1", "Column 1");
   dataset.setValue(200.0, "Row 1", "Column 2");
   JFreeChart chart =
       ChartFactory.createLineChart(
           "Test", "Categories", "Value", dataset, PlotOrientation.VERTICAL, false, false, false);
   CategoryPlot plot = (CategoryPlot) chart.getPlot();
   NumberAxis axis = (NumberAxis) plot.getRangeAxis();
   axis.setAutoRangeIncludesZero(false);
   assertEquals(axis.getLowerBound(), 95.0, EPSILON);
   assertEquals(axis.getUpperBound(), 205.0, EPSILON);
 }
Example #6
0
 /** Checks that the auto-range for the range axis on an XYPlot is working as expected. */
 @Test
 public void testXYAutoRange2() {
   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.getRangeAxis();
   axis.setAutoRangeIncludesZero(false);
   assertEquals(0.9, axis.getLowerBound(), EPSILON);
   assertEquals(3.1, axis.getUpperBound(), EPSILON);
 }
  /**
   * Standard constructor: builds a property panel for the specified axis.
   *
   * @param axis the axis, which should be changed.
   */
  public NumberAxisPropertyEditPanel(NumberAxis axis) {

    super(axis);

    this.autoRange = axis.isAutoRange();
    this.minimumValue = axis.getLowerBound();
    this.maximumValue = axis.getUpperBound();

    this.gridPaintSample = new PaintSample(Color.blue);
    this.gridStrokeSample = new StrokeSample(new BasicStroke(1.0f));

    this.availableStrokeSamples = new StrokeSample[3];
    this.availableStrokeSamples[0] = new StrokeSample(new BasicStroke(1.0f));
    this.availableStrokeSamples[1] = new StrokeSample(new BasicStroke(2.0f));
    this.availableStrokeSamples[2] = new StrokeSample(new BasicStroke(3.0f));

    JTabbedPane other = getOtherTabs();

    JPanel range = new JPanel(new LCBLayout(3));
    range.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));

    range.add(new JPanel());
    this.autoRangeCheckBox =
        new JCheckBox(localizationResources.getString("Auto-adjust_range"), this.autoRange);
    this.autoRangeCheckBox.setActionCommand("AutoRangeOnOff");
    this.autoRangeCheckBox.addActionListener(this);
    range.add(this.autoRangeCheckBox);
    range.add(new JPanel());

    range.add(new JLabel(localizationResources.getString("Minimum_range_value")));
    this.minimumRangeValue = new JTextField(Double.toString(this.minimumValue));
    this.minimumRangeValue.setEnabled(!this.autoRange);
    this.minimumRangeValue.setActionCommand("MinimumRange");
    this.minimumRangeValue.addActionListener(this);
    this.minimumRangeValue.addFocusListener(this);
    range.add(this.minimumRangeValue);
    range.add(new JPanel());

    range.add(new JLabel(localizationResources.getString("Maximum_range_value")));
    this.maximumRangeValue = new JTextField(Double.toString(this.maximumValue));
    this.maximumRangeValue.setEnabled(!this.autoRange);
    this.maximumRangeValue.setActionCommand("MaximumRange");
    this.maximumRangeValue.addActionListener(this);
    this.maximumRangeValue.addFocusListener(this);
    range.add(this.maximumRangeValue);
    range.add(new JPanel());

    other.add(localizationResources.getString("Range"), range);

    //        JPanel grid = new JPanel(new LCBLayout(3));
    //        grid.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));

    //        grid.add(new JPanel());
    //        showGridLinesCheckBox = new JCheckBox("Show grid lines",
    //            axis.isGridLinesVisible());
    //       grid.add(showGridLinesCheckBox);
    //       grid.add(new JPanel());

    //        grid.add(new JLabel("Grid stroke:"));
    //       JButton button = new JButton("Set stroke...");
    //        button.setActionCommand("GridStroke");
    //       button.addActionListener(this);
    //       grid.add(gridStrokeSample);
    //       grid.add(button);

    //        grid.add(new JLabel("Grid paint:"));
    //        button = new JButton("Set paint...");
    //        button.setActionCommand("GridPaint");
    //       button.addActionListener(this);
    //       grid.add(gridPaintSample);
    //        grid.add(button);

    //       other.add("Grid", grid);

  }