/** Some checks for the findRangeBounds() method. */
  @Test
  public void testFindRangeBounds() {
    StatisticalLineAndShapeRenderer r = new StatisticalLineAndShapeRenderer();
    assertNull(r.findRangeBounds(null));

    // an empty dataset should return a null range
    DefaultStatisticalCategoryDataset dataset = new DefaultStatisticalCategoryDataset();
    assertNull(r.findRangeBounds(dataset));

    dataset.add(1.0, 0.5, "R1", "C1");
    assertEquals(new Range(0.5, 1.5), r.findRangeBounds(dataset));

    dataset.add(-2.0, 0.2, "R1", "C2");
    assertEquals(new Range(-2.2, 1.5), r.findRangeBounds(dataset));

    dataset.add(null, null, "R1", "C3");
    assertEquals(new Range(-2.2, 1.5), r.findRangeBounds(dataset));

    dataset.add(5.0, 1.0, "R2", "C3");
    assertEquals(new Range(-2.2, 6.0), r.findRangeBounds(dataset));

    // check that the series visible flag is observed
    r.setSeriesVisible(1, Boolean.FALSE);
    assertEquals(new Range(-2.2, 1.5), r.findRangeBounds(dataset));
  }
  public static DefaultStatisticalCategoryDataset createDefaultStatisticalCategoryDataset(
      ValueSource valueSource, PlotInstance plotInstance) throws ChartPlottimeException {
    ValueSourceData valueSourceData = plotInstance.getPlotData().getValueSourceData(valueSource);
    assertMaxValueCountNotExceededOrThrowException(valueSourceData);
    GroupCellSeriesData dataForAllGroupCells = valueSourceData.getSeriesDataForAllGroupCells();
    DefaultStatisticalCategoryDataset dataset = new DefaultStatisticalCategoryDataset();
    DefaultDimensionConfig domainConfig = valueSource.getDomainConfig();
    DimensionConfigData domainConfigData =
        plotInstance.getPlotData().getDimensionConfigData(domainConfig);

    // Loop all group cells and add data to dataset
    for (GroupCellKeyAndData groupCellKeyAndData : dataForAllGroupCells) {
      GroupCellKey groupCellKey = groupCellKeyAndData.getKey();
      GroupCellData groupCellData = groupCellKeyAndData.getData();
      String seriesName =
          generateSeriesName(
              valueSource, groupCellKey, plotInstance.getCurrentPlotConfigurationClone());

      Map<PlotDimension, double[]> mainSeriesData =
          groupCellData.getDataForUsageType(SeriesUsageType.MAIN_SERIES);
      double[] xValues = mainSeriesData.get(PlotDimension.DOMAIN);
      double[] yValues = mainSeriesData.get(PlotDimension.VALUE);
      double[] yErrorValues = valueSourceData.getAbsoluteUtilityValues(groupCellKeyAndData, true);
      if (yErrorValues == null) {
        throw new ChartPlottimeException(
            "undefined_series", valueSource.toString(), SeriesUsageType.INDICATOR_1);
      }

      // this dataset does not support unsymmetric errors
      if (groupCellData.getDataForUsageType(SeriesUsageType.INDICATOR_2) != null) {
        throw new ChartPlottimeException(
            "unsymmetric_utility_not_supported", valueSource.toString());
      }

      int rowCount = xValues.length;

      // Loop all rows and add data to series
      double xValue;
      double yValue;
      double yErrorValue;
      String xString;
      for (int row = 0; row < rowCount; ++row) {
        xValue = xValues[row];
        xString = domainConfigData.getStringForValue(xValue);
        yValue = yValues[row];
        yErrorValue = yErrorValues[row] - yValue;

        dataset.add(yValue, yErrorValue, seriesName, xString);
      }
    }
    return dataset;
  }
 /**
  * Draws the chart with a <code>null</code> info object to make sure that no exceptions are thrown
  * (particularly by code in the renderer).
  */
 @Test
 public void testDrawWithNullInfo() {
   try {
     DefaultStatisticalCategoryDataset dataset = new DefaultStatisticalCategoryDataset();
     dataset.add(1.0, 2.0, "S1", "C1");
     dataset.add(3.0, 4.0, "S1", "C2");
     CategoryPlot plot =
         new CategoryPlot(
             dataset,
             new CategoryAxis("Category"),
             new NumberAxis("Value"),
             new StatisticalLineAndShapeRenderer());
     JFreeChart chart = new JFreeChart(plot);
     /* BufferedImage image = */ chart.createBufferedImage(300, 200, null);
   } catch (NullPointerException e) {
     fail("No exception should be thrown.");
   }
 }
Beispiel #4
0
  /**
   * Creates a sample dataset.
   *
   * @return The dataset.
   */
  private StatisticalCategoryDataset createDataset() {

    final DefaultStatisticalCategoryDataset result = new DefaultStatisticalCategoryDataset();
    String stats =
        ParamLoader.basePath + ParamLoader.slash + "out" + ParamLoader.slash + "Stats.xml";
    StatisticsHandler px = new StatisticsHandler();
    ArrayList<SimulationResults> sc = new ArrayList<SimulationResults>();
    try {
      sc = px.parseXMLStatistics(stats);
    } catch (SAXException e) {
      e.printStackTrace();
    }
    // parser fichier XML
    // System.out.println(sc.size());
    for (int i = 0; i < sc.size(); i++) {
      result.add(
          Integer.parseInt(sc.get(i).getNbMessages()),
          15,
          "Messages exchanged",
          sc.get(i).getName());
      result.add(
          Integer.parseInt(sc.get(i).getNbMappingInit()), 15, "Mapping", sc.get(i).getName());
      result.add(
          Integer.parseInt(sc.get(i).getNbMappingFinal()),
          15,
          "Mapping & Axiom",
          sc.get(i).getName());

      result.add(
          Integer.parseInt(sc.get(i).nbMappingFinal) - Integer.parseInt(sc.get(i).nbMappingInit),
          15,
          "Mapping difference",
          sc.get(i).getName());
      // result.add(40, 15, "SimulationResults", " ");
    }
    return result;
  }
 private static CategoryDataset createDataset() {
   DefaultStatisticalCategoryDataset defaultstatisticalcategorydataset =
       new DefaultStatisticalCategoryDataset();
   defaultstatisticalcategorydataset.add(10D, 2.3999999999999999D, "Row 1", "Column 1");
   defaultstatisticalcategorydataset.add(15D, 4.4000000000000004D, "Row 1", "Column 2");
   defaultstatisticalcategorydataset.add(13D, 2.1000000000000001D, "Row 1", "Column 3");
   defaultstatisticalcategorydataset.add(7D, 1.3D, "Row 1", "Column 4");
   defaultstatisticalcategorydataset.add(22D, 2.3999999999999999D, "Row 2", "Column 1");
   defaultstatisticalcategorydataset.add(18D, 4.4000000000000004D, "Row 2", "Column 2");
   defaultstatisticalcategorydataset.add(28D, 2.1000000000000001D, "Row 2", "Column 3");
   defaultstatisticalcategorydataset.add(17D, 1.3D, "Row 2", "Column 4");
   return defaultstatisticalcategorydataset;
 }