Esempio n. 1
0
  /**
   * Standard constructor: builds a property panel for the specified axis.
   *
   * @param axis the axis, which should be changed.
   */
  public DefaultValueAxisEditor(ValueAxis axis) {

    super(axis);

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

    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);

    other.add(localizationResources.getString("TickUnit"), createTickUnitPanel());
  }
Esempio n. 2
0
 private void computeRegressionAndAcceptableDeviationData() {
   acceptableDeviationDataset.removeAllSeries();
   regressionDataset.removeAllSeries();
   getPlot().removeAnnotation(r2Annotation);
   if (computedDatas != null) {
     final ValueAxis domainAxis = getPlot().getDomainAxis();
     final double min = domainAxis.getLowerBound();
     final double max = domainAxis.getUpperBound();
     acceptableDeviationDataset.addSeries(computeAcceptableDeviationData(min, max));
     if (scatterPlotModel.showRegressionLine) {
       final XYIntervalSeries series = computeRegressionData(min, max);
       if (series != null) {
         regressionDataset.addSeries(series);
         computeCoefficientOfDetermination();
       }
     }
   }
 }
  /**
   * Draws the visual representation of a single data item when the plot has a vertical orientation.
   *
   * @param g2 the graphics device.
   * @param state the renderer state.
   * @param dataArea the area within which the plot is being drawn.
   * @param plot the plot (can be used to obtain standard color information etc).
   * @param domainAxis the domain axis.
   * @param rangeAxis the range axis.
   * @param dataset the dataset (must be an instance of {@link BoxAndWhiskerCategoryDataset}).
   * @param row the row index (zero-based).
   * @param column the column index (zero-based).
   */
  public void drawVerticalItem(
      Graphics2D g2,
      CategoryItemRendererState state,
      Rectangle2D dataArea,
      CategoryPlot plot,
      CategoryAxis domainAxis,
      ValueAxis rangeAxis,
      CategoryDataset dataset,
      int row,
      int column) {

    BoxAndWhiskerCategoryDataset bawDataset = (BoxAndWhiskerCategoryDataset) dataset;

    double categoryEnd =
        domainAxis.getCategoryEnd(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());
    double categoryStart =
        domainAxis.getCategoryStart(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());
    double categoryWidth = categoryEnd - categoryStart;

    double xx = categoryStart;
    int seriesCount = getRowCount();
    int categoryCount = getColumnCount();

    if (seriesCount > 1) {
      double seriesGap =
          dataArea.getWidth() * getItemMargin() / (categoryCount * (seriesCount - 1));
      double usedWidth = (state.getBarWidth() * seriesCount) + (seriesGap * (seriesCount - 1));
      // offset the start of the boxes if the total width used is smaller
      // than the category width
      double offset = (categoryWidth - usedWidth) / 2;
      xx = xx + offset + (row * (state.getBarWidth() + seriesGap));
    } else {
      // offset the start of the box if the box width is smaller than the
      // category width
      double offset = (categoryWidth - state.getBarWidth()) / 2;
      xx = xx + offset;
    }

    double yyAverage = 0.0;
    double yyOutlier;

    Paint itemPaint = getItemPaint(row, column);
    g2.setPaint(itemPaint);
    Stroke s = getItemStroke(row, column);
    g2.setStroke(s);

    double aRadius = 0; // average radius

    RectangleEdge location = plot.getRangeAxisEdge();

    Number yQ1 = bawDataset.getQ1Value(row, column);
    Number yQ3 = bawDataset.getQ3Value(row, column);
    Number yMax = bawDataset.getMaxRegularValue(row, column);
    Number yMin = bawDataset.getMinRegularValue(row, column);
    Shape box = null;
    if (yQ1 != null && yQ3 != null && yMax != null && yMin != null) {

      double yyQ1 = rangeAxis.valueToJava2D(yQ1.doubleValue(), dataArea, location);
      double yyQ3 = rangeAxis.valueToJava2D(yQ3.doubleValue(), dataArea, location);
      double yyMax = rangeAxis.valueToJava2D(yMax.doubleValue(), dataArea, location);
      double yyMin = rangeAxis.valueToJava2D(yMin.doubleValue(), dataArea, location);
      double xxmid = xx + state.getBarWidth() / 2.0;

      // draw the upper shadow...
      g2.draw(new Line2D.Double(xxmid, yyMax, xxmid, yyQ3));
      g2.draw(new Line2D.Double(xx, yyMax, xx + state.getBarWidth(), yyMax));

      // draw the lower shadow...
      g2.draw(new Line2D.Double(xxmid, yyMin, xxmid, yyQ1));
      g2.draw(new Line2D.Double(xx, yyMin, xx + state.getBarWidth(), yyMin));

      // draw the body...
      box =
          new Rectangle2D.Double(
              xx, Math.min(yyQ1, yyQ3), state.getBarWidth(), Math.abs(yyQ1 - yyQ3));
      if (this.fillBox) {
        g2.fill(box);
      }
      g2.setStroke(getItemOutlineStroke(row, column));
      g2.setPaint(getItemOutlinePaint(row, column));
      g2.draw(box);
    }

    g2.setPaint(this.artifactPaint);

    // draw mean - SPECIAL AIMS REQUIREMENT...
    Number yMean = bawDataset.getMeanValue(row, column);
    if (yMean != null) {
      yyAverage = rangeAxis.valueToJava2D(yMean.doubleValue(), dataArea, location);
      aRadius = state.getBarWidth() / 4;
      // here we check that the average marker will in fact be visible
      // before drawing it...
      if ((yyAverage > (dataArea.getMinY() - aRadius))
          && (yyAverage < (dataArea.getMaxY() + aRadius))) {
        Ellipse2D.Double avgEllipse =
            new Ellipse2D.Double(xx + aRadius, yyAverage - aRadius, aRadius * 2, aRadius * 2);
        g2.fill(avgEllipse);
        g2.draw(avgEllipse);
      }
    }

    // draw median...
    Number yMedian = bawDataset.getMedianValue(row, column);
    if (yMedian != null) {
      double yyMedian = rangeAxis.valueToJava2D(yMedian.doubleValue(), dataArea, location);
      g2.draw(new Line2D.Double(xx, yyMedian, xx + state.getBarWidth(), yyMedian));
    }

    // draw yOutliers...
    double maxAxisValue =
        rangeAxis.valueToJava2D(rangeAxis.getUpperBound(), dataArea, location) + aRadius;
    double minAxisValue =
        rangeAxis.valueToJava2D(rangeAxis.getLowerBound(), dataArea, location) - aRadius;

    g2.setPaint(itemPaint);

    // draw outliers
    double oRadius = state.getBarWidth() / 3; // outlier radius
    List outliers = new ArrayList();
    OutlierListCollection outlierListCollection = new OutlierListCollection();

    // From outlier array sort out which are outliers and put these into a
    // list If there are any farouts, set the flag on the
    // OutlierListCollection
    List yOutliers = bawDataset.getOutliers(row, column);
    if (yOutliers != null) {
      for (int i = 0; i < yOutliers.size(); i++) {
        double outlier = ((Number) yOutliers.get(i)).doubleValue();
        Number minOutlier = bawDataset.getMinOutlier(row, column);
        Number maxOutlier = bawDataset.getMaxOutlier(row, column);
        Number minRegular = bawDataset.getMinRegularValue(row, column);
        Number maxRegular = bawDataset.getMaxRegularValue(row, column);
        if (outlier > maxOutlier.doubleValue()) {
          outlierListCollection.setHighFarOut(true);
        } else if (outlier < minOutlier.doubleValue()) {
          outlierListCollection.setLowFarOut(true);
        } else if (outlier > maxRegular.doubleValue()) {
          yyOutlier = rangeAxis.valueToJava2D(outlier, dataArea, location);
          outliers.add(new Outlier(xx + state.getBarWidth() / 2.0, yyOutlier, oRadius));
        } else if (outlier < minRegular.doubleValue()) {
          yyOutlier = rangeAxis.valueToJava2D(outlier, dataArea, location);
          outliers.add(new Outlier(xx + state.getBarWidth() / 2.0, yyOutlier, oRadius));
        }
        Collections.sort(outliers);
      }

      // Process outliers. Each outlier is either added to the
      // appropriate outlier list or a new outlier list is made
      for (Iterator iterator = outliers.iterator(); iterator.hasNext(); ) {
        Outlier outlier = (Outlier) iterator.next();
        outlierListCollection.add(outlier);
      }

      for (Iterator iterator = outlierListCollection.iterator(); iterator.hasNext(); ) {
        OutlierList list = (OutlierList) iterator.next();
        Outlier outlier = list.getAveragedOutlier();
        Point2D point = outlier.getPoint();

        if (list.isMultiple()) {
          drawMultipleEllipse(point, state.getBarWidth(), oRadius, g2);
        } else {
          drawEllipse(point, oRadius, g2);
        }
      }

      // draw farout indicators
      if (outlierListCollection.isHighFarOut()) {
        drawHighFarOut(aRadius / 2.0, g2, xx + state.getBarWidth() / 2.0, maxAxisValue);
      }

      if (outlierListCollection.isLowFarOut()) {
        drawLowFarOut(aRadius / 2.0, g2, xx + state.getBarWidth() / 2.0, minAxisValue);
      }
    }
    // collect entity and tool tip information...
    if (state.getInfo() != null && box != null) {
      EntityCollection entities = state.getEntityCollection();
      if (entities != null) {
        addItemEntity(entities, dataset, row, column, box);
      }
    }
  }
Esempio n. 4
0
 public void adjustComponents(ValueAxis axis, int numDecimalPlaces) {
   adjustComponents(axis.getLowerBound(), axis.getUpperBound(), numDecimalPlaces);
 }
  /**
   * When a checkbox is changed ...
   *
   * @param event the event.
   */
  public void actionPerformed(final ActionEvent event) {
    final ValueAxis[] axes = new ValueAxis[4];
    final XYPlot plot = this.chart.getXYPlot();
    axes[0] = plot.getDomainAxis();
    axes[1] = plot.getRangeAxis();
    axes[2] = plot.getDomainAxis(1);
    axes[3] = plot.getRangeAxis(1);

    final Object source = event.getSource();

    if (source == this.symbolicAxesCheckBox) {

      final boolean val = this.symbolicAxesCheckBox.isSelected();

      for (int i = 0; i < axes.length; i++) {
        ValueAxis axis = axes[i];
        final String label = axis.getLabel();
        final int maxTick = (int) axis.getUpperBound();
        final String[] tickLabels = new String[maxTick];
        final Font ft = axis.getTickLabelFont();
        for (int itk = 0; itk < maxTick; itk++) {
          tickLabels[itk] = "Label " + itk;
        }
        axis = val ? new SymbolicAxis(label, tickLabels) : new NumberAxis(label);
        axis.setTickLabelFont(ft);
        axes[i] = axis;
      }
      plot.setDomainAxis(axes[0]);
      plot.setRangeAxis(axes[1]);
      plot.setDomainAxis(1, axes[2]);
      plot.setRangeAxis(1, axes[3]);
    }

    if (source == this.symbolicAxesCheckBox || source == this.verticalTickLabelsCheckBox) {
      final boolean val = this.verticalTickLabelsCheckBox.isSelected();

      for (int i = 0; i < axes.length; i++) {
        axes[i].setVerticalTickLabels(val);
      }

    } else if (source == this.symbolicAxesCheckBox || source == this.horizontalPlotCheckBox) {

      final PlotOrientation val =
          this.horizontalPlotCheckBox.isSelected()
              ? PlotOrientation.HORIZONTAL
              : PlotOrientation.VERTICAL;
      this.chart.getXYPlot().setOrientation(val);

    } else if (source == this.symbolicAxesCheckBox || source == this.fontSizeTextField) {
      final String s = this.fontSizeTextField.getText();
      if (s.length() > 0) {
        final float sz = Float.parseFloat(s);
        for (int i = 0; i < axes.length; i++) {
          final ValueAxis axis = axes[i];
          Font ft = axis.getTickLabelFont();
          ft = ft.deriveFont(sz);
          axis.setTickLabelFont(ft);
        }
      }
    }
  }