Ejemplo n.º 1
0
 private void writeAverageCalculateCountPerSecondSummaryChart() {
   List<XYSeries> seriesList =
       new ArrayList<XYSeries>(plannerBenchmarkResult.getSolverBenchmarkResultList().size());
   for (SolverBenchmarkResult solverBenchmarkResult :
       plannerBenchmarkResult.getSolverBenchmarkResultList()) {
     String solverLabel = solverBenchmarkResult.getNameWithFavoriteSuffix();
     XYSeries series = new XYSeries(solverLabel);
     for (SingleBenchmarkResult singleBenchmarkResult :
         solverBenchmarkResult.getSingleBenchmarkResultList()) {
       if (singleBenchmarkResult.hasAllSuccess()) {
         long problemScale = singleBenchmarkResult.getProblemBenchmarkResult().getProblemScale();
         long averageCalculateCountPerSecond =
             singleBenchmarkResult.getAverageCalculateCountPerSecond();
         series.add((Long) problemScale, (Long) averageCalculateCountPerSecond);
       }
     }
     seriesList.add(series);
   }
   XYPlot plot =
       createScalabilityPlot(
           seriesList,
           "Problem scale",
           NumberFormat.getInstance(locale),
           "Average calculate count per second",
           NumberFormat.getInstance(locale));
   JFreeChart chart =
       new JFreeChart(
           "Average calculate count summary (higher is better)",
           JFreeChart.DEFAULT_TITLE_FONT,
           plot,
           true);
   averageCalculateCountSummaryChartFile =
       writeChartToImageFile(chart, "averageCalculateCountSummary");
 }
Ejemplo n.º 2
0
  /**
   * Utility to facilitate fitting data plotted in JFreeChart Provide data in JFReeChart format
   * (XYSeries), and retrieve univariate function parameters that best fit (using least squares) the
   * data. All data points will be weighted equally.
   *
   * <p>TODO: investigate whether weighting (possibly automatic weighting) can improve accuracy
   *
   * @param data xy series in JFReeChart format
   * @param type one of the Fitter.FunctionType predefined functions
   * @param guess initial guess for the fit. The number and meaning of these parameters depends on
   *     the FunctionType. Implemented: Gaussian: 0: Normalization, 1: Mean 2: Sigma
   * @return array with parameters, whose meaning depends on the FunctionType. Use the function
   *     getXYSeries to retrieve the XYDataset predicted by this fit
   */
  public static double[] fit(XYSeries data, FunctionType type, double[] guess) {

    if (type == FunctionType.NoFit) {
      return null;
    }
    // create the commons math data object from the JFreeChart data object
    final WeightedObservedPoints obs = new WeightedObservedPoints();
    for (int i = 0; i < data.getItemCount(); i++) {
      obs.add(1.0, data.getX(i).doubleValue(), data.getY(i).doubleValue());
    }

    double[] result = null;
    switch (type) {
      case Pol1:
        final PolynomialCurveFitter fitter1 = PolynomialCurveFitter.create(1);
        result = fitter1.fit(obs.toList());
        break;
      case Pol2:
        final PolynomialCurveFitter fitter2 = PolynomialCurveFitter.create(2);
        result = fitter2.fit(obs.toList());
        break;
      case Pol3:
        final PolynomialCurveFitter fitter3 = PolynomialCurveFitter.create(3);
        result = fitter3.fit(obs.toList());
        break;
      case Gaussian:
        final GaussianWithOffsetCurveFitter gf = GaussianWithOffsetCurveFitter.create();
        if (guess != null) {
          gf.withStartPoint(guess);
        }
        result = gf.fit(obs.toList());
    }

    return result;
  }
Ejemplo n.º 3
0
 /**
  * Sets the value of the existing point (abscissa, value) at index index to y. If the index is
  * negative, does not do anything. If the index equals the index of the last element of the signal
  * plus one, adds an element (index, y) to the signal at the index index. If the index is greateur
  * than the index of the last element of the signal plus one, does not do anything.
  *
  * @param index index of the exsisting point. If the point does not exists, adds it
  * @param y value to be given to the corresponding point (abscissa, value).
  */
 public void setValueOf(int index, double y) {
   if (index == this.getNbSamples()) {
     data.add(index, y);
   } else if ((index >= 0) && (index < this.getNbSamples())) {
     data.updateByIndex(index, y);
   }
 }
Ejemplo n.º 4
0
 private void writeTimeSpentScalabilitySummaryChart() {
   List<XYSeries> seriesList =
       new ArrayList<XYSeries>(plannerBenchmarkResult.getSolverBenchmarkResultList().size());
   for (SolverBenchmarkResult solverBenchmarkResult :
       plannerBenchmarkResult.getSolverBenchmarkResultList()) {
     String solverLabel = solverBenchmarkResult.getNameWithFavoriteSuffix();
     XYSeries series = new XYSeries(solverLabel);
     for (SingleBenchmarkResult singleBenchmarkResult :
         solverBenchmarkResult.getSingleBenchmarkResultList()) {
       if (singleBenchmarkResult.hasAllSuccess()) {
         long problemScale = singleBenchmarkResult.getProblemBenchmarkResult().getProblemScale();
         long timeMillisSpent = singleBenchmarkResult.getTimeMillisSpent();
         series.add((Long) problemScale, (Long) timeMillisSpent);
       }
     }
     seriesList.add(series);
   }
   XYPlot plot =
       createScalabilityPlot(
           seriesList,
           "Problem scale",
           NumberFormat.getInstance(locale),
           "Time spent",
           new MillisecondsSpentNumberFormat(locale));
   JFreeChart chart =
       new JFreeChart(
           "Time spent scalability summary (lower is better)",
           JFreeChart.DEFAULT_TITLE_FONT,
           plot,
           true);
   timeSpentScalabilitySummaryChartFile =
       writeChartToImageFile(chart, "timeSpentScalabilitySummary");
 }
Ejemplo n.º 5
0
  private XYDataset createDataset(String metricName) {

    series = new XYSeriesCollection();

    // For each collection of evaluations
    for (int i = 0; i < evaluationsCollection.size(); i++) {

      if (!set.contains(i)) {

        List<AbstractEvaluation> evaluations = evaluationsCollection.get(i);
        XYSeries newXYSerie = new XYSeries(queryNames.get(i));

        int evalIndex = 0;

        for (AbstractEvaluation eval : evaluations) {
          if (evalIndex % reportFrecuency == 0) {
            newXYSerie.add(eval.getLabeledSetSize(), eval.getMetricValue(metricName));
          }
          ++evalIndex;
        }
        series.addSeries(newXYSerie);
      }
    }
    // The series that belongs to passive learning is the last
    if (passiveEvaluation != null) {

      series.addSeries(createPassiveLearningSerie(metricName, evaluationsCollection.get(0)));
    }
    return series;
  }
Ejemplo n.º 6
0
  /** Creates a dataset of type XYSeries */
  public XYDataset convertDataSet() {
    int size = 0; // Initialises a value for size
    int sum = 0; // initialises a value for sum
    int pos = 0; // initialises a value for position
    int j = 0; // initialises a increment for the for loop

    XYSeriesCollection dataset = new XYSeriesCollection();
    XYSeries series = new XYSeries(super.GetTitle());

    DataCell preVal = super.GetDataSet().GetCell(0, 0);
    // Creates a new list for the found elements
    super.m_foundElements = new ArrayList<String>();

    for (int i = 0; i < super.GetDataSet().GetNumOfRows() - 1; i++) {

      if (!super.isUnique(super.GetDataSet().GetCell(super.GetXColumnPosition(), i).toString())) {
        for (j = pos; j < super.GetDataSet().GetNumOfRows() - 1; j++) {
          if (preVal
              .toString()
              .equals(super.GetDataSet().GetCell(super.GetXColumnPosition(), j).toString())) {

            // Check if datatype is a number
            if (super.GetDataSet().GetCell(super.GetXColumnPosition(), j).GetDataType()
                == DataType.INTEGER) {
              sum += super.GetDataSet().GetCell(super.GetYColumnPosition(), j).GetInteger();
            } else if (super.GetDataSet().GetCell(super.GetXColumnPosition(), j).GetDataType()
                == DataType.DOUBLE) {
              sum += super.GetDataSet().GetCell(super.GetYColumnPosition(), j).GetDouble();
            }
          }
        }
        super.m_foundElements.add(
            super.GetDataSet().GetCell(super.GetXColumnPosition(), i).toString());

        // Add to chart dataSet
        series.add(sum, preVal.GetInteger());

        preVal = super.GetDataSet().GetCell(super.GetXColumnPosition(), i++);
        sum = 0; //
        pos++;
      }
    }

    for (j = pos; j < super.GetDataSet().GetNumOfRows() - 1; j++) {
      if (super.m_foundElements
          .get(super.m_foundElements.size() - 1)
          .equals(super.GetDataSet().GetCell(super.GetXColumnPosition(), j).toString())) {
        if (super.GetDataSet().GetCell(super.GetXColumnPosition(), j).GetDataType()
            == DataType.INTEGER) {
          sum += super.GetDataSet().GetCell(super.GetYColumnPosition(), j).GetInteger();
        } else if (super.GetDataSet().GetCell(super.GetXColumnPosition(), j).GetDataType()
            == DataType.DOUBLE) {
          sum += super.GetDataSet().GetCell(super.GetYColumnPosition(), j).GetDouble();
        }
      }
    }
    series.add(sum, preVal.GetInteger());
    dataset.addSeries(series);
    return dataset;
  }
Ejemplo n.º 7
0
  @Override
  protected void setChart() {
    SeriesManager<Double, Double> sf = new SeriesManager<Double, Double>(intermediateData);
    List<DataSeries<Double, Double>> seriesList = sf.getSeries();

    DataSeries<Double, Double> series = seriesList.get(0);
    List<SeriesPair<Double, Double>> values = series.getSeriesValues(Double.class, Double.class);

    XYSeries deltaMassSeries = new XYSeries(series.getIdentifier());
    for (SeriesPair<Double, Double> value : values) {
      deltaMassSeries.add(value.getX(), value.getY());
    }

    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(deltaMassSeries);

    chart =
        ChartFactory.createXYLineChart(
            getChartTitle(), // chart title
            "Experimental m/z - Theoretical m/z", // x axis label
            "Relative Frequency", // y axis label
            dataset, // chartData
            PlotOrientation.VERTICAL,
            false, // include legend
            true, // tooltips
            false // urls
            );
    chart.addSubtitle(new TextTitle(getChartSubTitle()));

    XYPlot plot = chart.getXYPlot();
    plot.setDomainZeroBaselineVisible(true);
    plot.setBackgroundAlpha(0f);
    plot.setDomainGridlinePaint(Color.red);
    plot.setRangeGridlinePaint(Color.blue);
  }
  /**
   * @return a {@link org.jfree.data.xy.XYSeries} representing the distribution of traveled
   *     distances for the mode (histogramm), or null if the mode is unknown (only modes that
   *     generated events in the previous mobsim run are "known").
   * @param step the width of the bins, in meters
   * @param mode the mode to get the data for
   */
  public XYSeries getTraveledXYsHistogram(final String mode, final double step) {
    boolean autoSort = false;
    boolean allowDuplicateXValues = true;
    XYSeries output = new XYSeries(mode, autoSort, allowDuplicateXValues);
    double[] modeRawData;
    try {
      modeRawData = this.rawData.get(mode).getElements();
    } catch (NullPointerException e) {
      return null;
    }
    Arrays.sort(modeRawData);
    double currentUpperBound = step;
    int count = 0;

    for (double xyValue : modeRawData) {
      if (xyValue < currentUpperBound) {
        count++;
      } else {
        // add the previous bin to the plot
        output.add(currentUpperBound - step, count);
        // output.add(currentUpperBound, count);

        currentUpperBound += step;
        while (xyValue > currentUpperBound) {
          output.add(currentUpperBound, 0d);
          currentUpperBound += step;
        }
        count = 1;
      }
    }
    // add the last count
    output.add(currentUpperBound - step, count);
    output.add(currentUpperBound, 0);
    return output;
  }
Ejemplo n.º 9
0
  public void execute() {
    // TODO Auto-generated method stub

    // simply get the environment datamodel
    dmodel = (StaticEnvDataModel) sim.getEnvDataModel();

    double infected = getPercentInfected(dmodel);

    synchronized (this) {
      XYSeries series;
      try {
        series = data.getSeries("infected");
        series.add(dmodel.time, infected);
      } catch (org.jfree.data.UnknownKeyException e) {
        series = new XYSeries("infected");
        data.addSeries(series);
        series.add(dmodel.time, infected);
      }

      if (dmodel.time % 100 == 0) {
        // this will cause the gui to update?
        updateChart();
      }
    }
  }
Ejemplo n.º 10
0
  /**
   * precondition : 'attribute' MUST contain number values only
   *
   * @param cases
   * @param attribute
   * @return DefaultXYDataset with all values of 'attribute' against event numbers or timestamps.
   */
  private XYSeriesCollection getDataAttributes(
      String[] attributes, boolean byTime, double timesize) {
    XYSeriesCollection result = new XYSeriesCollection();
    for (int index = 0; index < attributes.length; index++) {
      String attribute = attributes[index];
      Integer i = 0;
      XYSeries row = new XYSeries(attribute);
      for (ProcessInstance pi : mylog.getInstances()) {
        Integer x = 0; // count event number
        Date begin = pi.getAuditTrailEntries().first().getTimestamp(); // starting
        // time
        // of
        // process
        // instance

        for (AuditTrailEntry ate : pi.getListOfATEs()) {
          if (ate.getAttributes().containsKey(attribute)) {
            Double val;
            val = Double.valueOf(ate.getAttributes().get(attribute));
            if (byTime) {
              row.add(timediff(begin, ate.getTimestamp()) / timesize, val.doubleValue());
            } else {
              row.add(x.doubleValue(), val.doubleValue());
            }
          }
          x++; // event number in case
        }
        i++; // case number
      }
      result.addSeries(row);
    }
    return result;
  }
Ejemplo n.º 11
0
  private static XYDataset createDataset(
      String expName, String hostName, String metric, String category) throws Exception {

    DBManager dba = new DBManager();
    XYSeries series = new XYSeries(category);

    String sql =
        "SELECT time_s*100000+time_us as time, data from "
            + expName
            + "_proc WHERE instance = '"
            + category
            + "' and metric = '"
            + metric
            + "' and hostname = '"
            + hostName
            + "' ORDER BY time_s,time_us;";
    //  System.out.println(sql);
    ArrayList resultList = dba.executeSql(sql);

    for (int i = 0; i < resultList.size(); i++) {
      HashMap hash = (HashMap) resultList.get(i);
      double time = Double.parseDouble(hash.get("TIME").toString());
      double data = Double.parseDouble(hash.get("DATA").toString());
      System.out.println(time + " and " + data);
      series.add(time, data);
    }

    XYSeriesCollection result = new XYSeriesCollection(series);
    return result;
  }
  private void crearImagen() {

    XYSeries serie = new XYSeries("Serie");
    Iterator<Double> iterator = ejercicio.getHistoricoSolucion().iterator();
    for (int i = 0; i < ejercicio.getHistoricoSolucion().size(); i++) {
      serie.add(i, iterator.next());
    }

    XYSeriesCollection coleccionSeries = new XYSeriesCollection();
    coleccionSeries.addSeries(serie);

    JFreeChart chart =
        ChartFactory.createXYLineChart(
            "Comportamiento Simulated Annealing",
            "Ciclo",
            "Solucion",
            coleccionSeries,
            PlotOrientation.VERTICAL,
            false,
            false,
            true);

    ChartPanel panel = new ChartPanel(chart);
    panel.setMouseZoomable(true);
    this.add(panel);
  }
Ejemplo n.º 13
0
 private XYDataset filterData(List<double[]> ds) {
   this.setCursor(new Cursor(Cursor.WAIT_CURSOR));
   double[] correlation = null;
   double[] dblData1 = applyWindow(ds.get(0), (String) getTaperCB().getSelectedItem());
   try {
     if (ds.size() == 1) {
       correlation = IstiUtilsMath.correlate(dblData1, dblData1);
     } else {
       double[] dblData2 = applyWindow(ds.get(1), (String) taperCB.getSelectedItem());
       correlation = IstiUtilsMath.correlate(dblData1, dblData2);
     }
   } catch (IllegalArgumentException e) {
     logger.error("IllegalArgumentException:", e);
   }
   logger.debug("correlation computed, size = " + correlation.length);
   XYSeriesCollection dataset = new XYSeriesCollection();
   XYSeries series = new XYSeries(seriesName);
   double ampMax = 0;
   int ampMaxPoint = -1;
   for (int i = 0; i < correlation.length; i++) {
     series.add(sampleRate * (i - correlation.length / 2) / 1000, correlation[i]);
     if (Math.abs(correlation[i]) > ampMax) {
       ampMax = Math.abs(correlation[i]);
       ampMaxPoint = i;
     }
   }
   dataset.addSeries(series);
   getAmpMaxL().setText("Max Amplitude: " + dFormat.format(ampMax));
   getLagTimeL()
       .setText("Lag time: " + sampleRate * (ampMaxPoint - correlation.length / 2) / 1000 + " s");
   this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
   return dataset;
 }
Ejemplo n.º 14
0
  /**
   * A check for the datasetIndex and seriesIndex fields in the LegendItem returned by the
   * getLegendItem() method.
   */
  public void testGetLegendItemSeriesIndex() {
    XYSeriesCollection d1 = new XYSeriesCollection();
    XYSeries s1 = new XYSeries("S1");
    s1.add(1.0, 1.1);
    XYSeries s2 = new XYSeries("S2");
    s2.add(1.0, 1.1);
    d1.addSeries(s1);
    d1.addSeries(s2);

    XYSeriesCollection d2 = new XYSeriesCollection();
    XYSeries s3 = new XYSeries("S3");
    s3.add(1.0, 1.1);
    XYSeries s4 = new XYSeries("S4");
    s4.add(1.0, 1.1);
    XYSeries s5 = new XYSeries("S5");
    s5.add(1.0, 1.1);
    d2.addSeries(s3);
    d2.addSeries(s4);
    d2.addSeries(s5);

    XYDotRenderer r = new XYDotRenderer();
    XYPlot plot = new XYPlot(d1, new NumberAxis("x"), new NumberAxis("y"), r);
    plot.setDataset(1, d2);
    /*JFreeChart chart =*/ new JFreeChart(plot);
    LegendItem li = r.getLegendItem(1, 2);
    assertEquals("S5", li.getLabel());
    assertEquals(1, li.getDatasetIndex());
    assertEquals(2, li.getSeriesIndex());
  }
Ejemplo n.º 15
0
  public static XYSeries getXY(String url) {
    XYSeries xyseries = new XYSeries("");

    Path path = new Path(url);
    Configuration conf = HUtils.getConf();
    SequenceFile.Reader reader = null;
    try {
      reader =
          new SequenceFile.Reader(
              conf, Reader.file(path), Reader.bufferSize(4096), Reader.start(0));
      DoubleArrStrWritable dkey =
          (DoubleArrStrWritable) ReflectionUtils.newInstance(reader.getKeyClass(), conf);
      DoublePairWritable dvalue =
          (DoublePairWritable) ReflectionUtils.newInstance(reader.getValueClass(), conf);

      while (reader.next(dkey, dvalue)) { // 循环读取文件
        xyseries.add(dvalue.getFirst(), dvalue.getSecond());
      }
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      IOUtils.closeStream(reader);
    }
    return xyseries;
  }
Ejemplo n.º 16
0
  private boolean plotCorrectionData() {
    plot3d.removeAllPlots();
    XYSeries series;
    XYPlot plot = chartPanel.getChart().getXYPlot();
    XYSeriesCollection lineDataset = (XYSeriesCollection) plot.getDataset(0);
    DecimalFormat df = new DecimalFormat(".00");
    String val;
    int i = 0;
    int j = 0;
    if (!Utils.isTableEmpty(corrTable)) {
      try {
        for (i = 1; i < corrTable.getColumnCount(); ++i) {
          val = corrTable.getValueAt(0, i).toString();
          series = new XYSeries(df.format(Double.valueOf(val)));
          for (j = 1; j < corrTable.getRowCount(); ++j) {
            if (corrTable.getValueAt(j, i) != null) {
              val = corrTable.getValueAt(j, i).toString();
              if (!val.isEmpty())
                series.add(
                    Double.valueOf(corrTable.getValueAt(j, 0).toString()), Double.valueOf(val));
            }
          }
          if (series.getItemCount() > 0) {
            corrData.add(series);
            series.setDescription(series.getKey().toString());
            lineDataset.addSeries(series);
          }
        }
        plot.getDomainAxis(0).setAutoRange(true);
        plot.getRangeAxis(0).setAutoRange(true);
        plot.getDomainAxis(0).setLabel(xAxisName);
        plot.getRangeAxis(0).setLabel(yAxisName);
        plot.getRenderer(0).setSeriesVisible(0, false);

        double[] x = new double[xAxisArray.size()];
        for (i = 0; i < xAxisArray.size(); ++i) x[i] = xAxisArray.get(i);
        double[] y = new double[yAxisArray.size()];
        for (i = 0; i < yAxisArray.size(); ++i) y[i] = yAxisArray.get(i);
        double[][] z = Utils.doubleZArray(corrTable, x, y);
        Color[][] colors = Utils.generateTableColorMatrix(corrTable, 1, 1);
        plot3d.addGridPlot("Average Error % Plot", colors, x, y, z);
      } catch (NumberFormatException e) {
        logger.error(e);
        JOptionPane.showMessageDialog(
            null,
            "Error parsing number from "
                + corrTableName
                + " table, cell("
                + i
                + " : "
                + j
                + "): "
                + e,
            "Error",
            JOptionPane.ERROR_MESSAGE);
        return false;
      }
    }
    return true;
  }
Ejemplo n.º 17
0
 /**
  * Looks for the element of the given abscissa and sets its value to ordiante. If there is no
  * points existing with the given abcisssa, adds a point (abscissa, ordinate) to the signal.
  * (actually, this method does the exact same thing as addElement).
  *
  * @param abscissa abscissa of the considered point
  * @param ordinate value to add or update in the signal
  */
 public void setElement(double abscissa, double ordinate) {
   int index = data.indexOf(abscissa);
   if (index < 0) {
     data.add(abscissa, ordinate);
   } else {
     data.updateByIndex(index, ordinate);
   }
 }
 /**
  * Creates a series for testing.
  *
  * @return A series.
  */
 private XYSeries createSeries1() {
   XYSeries series1 = new XYSeries("Series 1", true, false);
   series1.add(1.0, 1.0);
   series1.add(2.0, 1.0);
   series1.add(4.0, 1.0);
   series1.add(5.0, 1.0);
   return series1;
 }
 /**
  * Creates a sample dataset.
  *
  * @param index the dataset index.
  * @return A dataset.
  */
 private XYDataset createDataset(int index) {
   XYSeries series1 = new XYSeries("Series " + (index + 1));
   series1.add(-10.0, -5.0);
   series1.add(10.0, 5.0);
   XYSeriesCollection dataset = new XYSeriesCollection();
   dataset.addSeries(series1);
   return dataset;
 }
Ejemplo n.º 20
0
 /**
  * Returns the average of the ys in a XYSeries
  *
  * @param data input data
  * @return y average
  */
 public static double getYAvg(XYSeries data) {
   double avg = 0;
   for (int i = 0; i < data.getItemCount(); i++) {
     avg += data.getY(i).doubleValue();
   }
   avg = avg / data.getItemCount();
   return avg;
 }
Ejemplo n.º 21
0
  public void setPath(List<XYPoint> xyList) {
    mIdeal.clear();
    clearActuals();

    for (int i = 0; i < xyList.size(); ++i) {
      mIdeal.add(xyList.get(i).mX, xyList.get(i).mY);
    }
  }
 /**
  * Clear a series
  *
  * @param seriesName Name of series to clear
  */
 public void clear(String seriesName) {
   for (XYSeries serie : seriesList) {
     if (serie.getKey().toString().equals(seriesName)) {
       serie.clear();
       break;
     }
   }
 }
  /**
   * @param valueSource
   * @param plotInstance
   * @param autoWidthFraction If this value is greater than 0, an auto width for the intervals is
   *     calculated such that the intervals nearest to each other touch. This value is then
   *     multiplied with the value of autoWidthFtraction. If unset, the intervals have width 0.
   * @param allowDuplicates
   * @param sortByDomain if true, the data is sorted by domain values (useful for bar and area
   *     charts)
   * @return
   * @throws ChartPlottimeException
   */
  public static XYSeriesCollection createXYSeriesCollection(
      ValueSource valueSource,
      PlotInstance plotInstance,
      double autoWidthFraction,
      boolean allowDuplicates,
      boolean sortByDomain)
      throws ChartPlottimeException {
    XYSeriesCollection xyDataset = new XYSeriesCollection();
    if (autoWidthFraction > 0) {
      xyDataset.setAutoWidth(true);
    } else {
      xyDataset.setAutoWidth(false);
      xyDataset.setIntervalWidth(0);
    }

    ValueSourceData valueSourceData = plotInstance.getPlotData().getValueSourceData(valueSource);
    assertMaxValueCountNotExceededOrThrowException(valueSourceData);
    GroupCellSeriesData dataForAllGroupCells = valueSourceData.getSeriesDataForAllGroupCells();

    // Loop over 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());

      XYSeries series = new XYSeries(seriesName, sortByDomain, allowDuplicates);
      Map<PlotDimension, double[]> dataForUsageType =
          groupCellData.getDataForUsageType(SeriesUsageType.MAIN_SERIES);
      int rowCount = dataForUsageType.get(PlotDimension.DOMAIN).length;
      double[] xValues = dataForUsageType.get(PlotDimension.DOMAIN);
      double[] yValues = dataForUsageType.get(PlotDimension.VALUE);

      try {
        // Loop over rows and add data to series
        for (int row = 0; row < rowCount; ++row) {
          double x = xValues[row];
          double y = yValues[row];
          if (!Double.isNaN(x)) {
            series.add(x, y);
          }
        }
      } catch (SeriesException e) {
        throw new ChartPlottimeException(
            "duplicate_value", valueSource.toString(), PlotDimension.DOMAIN.getName());
      }

      xyDataset.addSeries(series);
    }
    // intervals should not touch each other, so decrease auto width.
    if (xyDataset.getIntervalWidth() > 0) {
      xyDataset.setIntervalWidth(xyDataset.getIntervalWidth() * autoWidthFraction);
    }
    return xyDataset;
  }
 /**
  * Creates a series for testing.
  *
  * @return A series.
  */
 private XYSeries createSeries2() {
   XYSeries series2 = new XYSeries("Series 2", true, false);
   series2.add(2.0, 2.0);
   series2.add(3.0, 2.0);
   series2.add(4.0, 2.0);
   series2.add(5.0, 2.0);
   series2.add(6.0, 2.0);
   return series2;
 }
Ejemplo n.º 25
0
 /**
  * Returns the value (the ordianate) of a point given its abscissa.
  *
  * @param abscissa abscissa of the considered point
  * @return return the value of the considered point (returns -1 if there is no points with the
  *     given abscissa in the signal).
  */
 public double getValueOfAbscissa(double abscissa) {
   int isInSeries = data.indexOf(abscissa);
   if (isInSeries >= 0) {
     return data.getY(isInSeries).doubleValue();
   } else {
     System.out.println("There is no point whith the abscissa " + abscissa + " in the signal.\n");
     return -1;
   }
 }
 /**
  * Add sample to a series
  *
  * @param x Abcissa
  * @param y Ordinate
  * @param seriesName Series name
  */
 @Override
 public void addSample(double x, double y, String seriesName) {
   for (XYSeries serie : seriesList) {
     if (serie.getKey().toString().equals(seriesName)) {
       serie.add(x, y);
       break;
     }
   }
 }
Ejemplo n.º 27
0
 public XYSeries getXYSeries(String rowname, long factor) {
   XYSeries mydataset = new XYSeries(rowname);
   for (Integer key : ysum.keySet()) {
     Double value = ysum.get(key) / (double) count.get(key);
     Double point = (double) xsum.get(key) / (double) count.get(key);
     mydataset.add(point / factor, value);
   }
   return mydataset;
 }
Ejemplo n.º 28
0
 /**
  * Returns <code>true</code> if all the y-values for the specified x-value are <code>null</code>
  * and <code>false</code> otherwise.
  *
  * @param x the x-value.
  * @return A boolean.
  */
 protected boolean canPrune(Number x) {
   for (int s = 0; s < this.data.size(); s++) {
     XYSeries series = (XYSeries) this.data.get(s);
     if (series.getY(series.indexOf(x)) != null) {
       return false;
     }
   }
   return true;
 }
Ejemplo n.º 29
0
 /** Creates a float[] time-series */
 public XYDataset createDataset(Float[] ds, String label) {
   XYSeries observations = new XYSeries(label);
   int n = ds.length;
   for (int i = 0; i < n; i++) {
     observations.add(i, ds[i]);
   }
   XYSeriesCollection collection = new XYSeriesCollection();
   collection.addSeries(observations);
   return collection;
 }
Ejemplo n.º 30
0
 /**
  * Creates a dataset.
  *
  * @return the dataset.
  */
 public XYDataset createDataset(DataSequence ds, String label) {
   XYSeries observations = new XYSeries(label);
   int n = ds.size();
   for (int i = 0; i < n; i++) {
     observations.add(i, ds.get(i).value);
   }
   XYSeriesCollection collection = new XYSeriesCollection();
   collection.addSeries(observations);
   return collection;
 }