Package org.jfree.data.xy

Examples of org.jfree.data.xy.DefaultXYDataset


    /**
     * Some checks for the findLiveItemsUpperBound() method when the dataset is
     * DESCENDING.
     */
    public void testFindLiveItemsUpperBound_Descending() {
        DefaultXYDataset d = new DefaultXYDataset() {
            public DomainOrder getDomainOrder() {
                // we're doing this for testing only, and make sure that we
                // only add data in descending order by x-value
                return DomainOrder.DESCENDING;
            }
        };
        // check a series with no items
        d.addSeries("S1", new double[][] {{}, {}});
        assertEquals(0, RendererUtilities.findLiveItemsUpperBound(d, 0, 10.0,
                11.0));

        // check a series with one item
        d.addSeries("S2", new double[][] {{1.0}, {9.9}});
        assertEquals(0, RendererUtilities.findLiveItemsUpperBound(d, 1, 0.0,
                1.0));
        assertEquals(0, RendererUtilities.findLiveItemsUpperBound(d, 1, 1.1,
                2.0));

        // check a series with two items
        d.addSeries("S3", new double[][] {{2.0, 1.0}, {9.9, 9.9}});
        assertEquals(1, RendererUtilities.findLiveItemsUpperBound(d, 2, 0.1,
                0.5));
        assertEquals(1, RendererUtilities.findLiveItemsUpperBound(d, 2, 0.1,
                1.0));
        assertEquals(0, RendererUtilities.findLiveItemsUpperBound(d, 2, 1.1,
                2.0));
        assertEquals(0, RendererUtilities.findLiveItemsUpperBound(d, 2, 2.2,
                3.0));
        assertEquals(0, RendererUtilities.findLiveItemsUpperBound(d, 2, 3.3,
                4.0));

        // check a series with three items
        d.addSeries("S4", new double[][] {{3.0, 2.0, 1.0}, {9.9, 9.9, 9.9}});
        assertEquals(2, RendererUtilities.findLiveItemsUpperBound(d, 3, 0.0,
                1.0));
        assertEquals(2, RendererUtilities.findLiveItemsUpperBound(d, 3, 1.0,
                2.0));
        assertEquals(1, RendererUtilities.findLiveItemsUpperBound(d, 3, 2.0,
                3.0));
        assertEquals(0, RendererUtilities.findLiveItemsUpperBound(d, 3, 3.0,
                4.0));

        // check a series with four items
        d.addSeries("S5", new double[][] {{4.0, 3.0, 2.0, 1.0}, {9.9, 9.9,
                9.9, 9.9}});
        assertEquals(3, RendererUtilities.findLiveItemsUpperBound(d, 4, 0.1,
                0.5));
        assertEquals(3, RendererUtilities.findLiveItemsUpperBound(d, 4, 0.1,
                1.0));
        assertEquals(2, RendererUtilities.findLiveItemsUpperBound(d, 4, 1.1,
                2.0));
        assertEquals(1, RendererUtilities.findLiveItemsUpperBound(d, 4, 2.2,
                3.0));
        assertEquals(0, RendererUtilities.findLiveItemsUpperBound(d, 4, 3.3,
                4.0));
        assertEquals(0, RendererUtilities.findLiveItemsUpperBound(d, 4, 4.4,
                5.0));

        // check a series with repeating items
        d.addSeries("S6", new double[][] {{3.0, 2.0, 2.0, 2.0, 1.0}, {9.9, 9.9,
                9.9, 9.9, 9.9}});
        assertEquals(4, RendererUtilities.findLiveItemsUpperBound(d, 5, 0.0,
                5.0));
        assertEquals(4, RendererUtilities.findLiveItemsUpperBound(d, 5, 1.0,
                5.0));
View Full Code Here


  public DatasetMap calculateValue() throws Exception {
    logger.debug("IN");
    String res=DataSetAccessFunctions.getDataSetResultFromId(profile, getData(),parametersObject);

    DefaultXYDataset dataset = new DefaultXYDataset();

    SourceBean sbRows=SourceBean.fromXMLString(res);
    List listAtts=sbRows.getAttributeAsList("ROW");

    series=new Vector();

    boolean firstX=true;
    boolean firstY=true;
    double xTempMax=0.0;
    double xTempMin=0.0;
    double yTempMax=0.0;
    double yTempMin=0.0;
    boolean first=true;

    // In list atts there are all the series, let's run each
    for (Iterator iterator = listAtts.iterator(); iterator.hasNext();) {
      SourceBean serie = (SourceBean) iterator.next();
      List atts=serie.getContainedAttributes();

      String catValue="";
      String serValue="";

      if(first){
        if (name.indexOf("$F{") >= 0){
          setTitleParameter(atts);
        }
        if (getSubName()!= null && getSubName().indexOf("$F") >= 0){
          setSubTitleParameter(atts);
        }
        if (yMarkerLabel != null && yMarkerLabel.indexOf("$F{") >= 0){
          setYMarkerLabel(atts);
        }
        first=false;
      }
     
      //defines real dimension of attributes x1,y1,x2,y2...the number must be the same for x and y column
      int  numAttsX = 0;
      int  numAttsY = 0;
     
      for (Iterator iterator2 = atts.iterator(); iterator2.hasNext();) {
        SourceBeanAttribute object = (SourceBeanAttribute) iterator2.next();

        String name=new String(object.getKey());
        if(!name.equalsIgnoreCase("x")) {
          if (String.valueOf(name.charAt(0)).equalsIgnoreCase("x"))        
            numAttsX++;
          else if (String.valueOf(name.charAt(0)).equalsIgnoreCase("y"))    
            numAttsY++;
        }
      }
      int  maxNumAtts = (numAttsX < numAttsY)? numAttsY : numAttsX;
      //double[] x=new double[atts.size()];
      //double[] y=new double[atts.size()];
      double[] x=new double[maxNumAtts];
      double[] y=new double[maxNumAtts];

      String name="";
      String value="";

      //run all the attributes of the serie
      for (Iterator iterator2 = atts.iterator(); iterator2.hasNext();) {
        SourceBeanAttribute object = (SourceBeanAttribute) iterator2.next();

        name=new String(object.getKey());
        value=(((String)object.getValue()).equals("null"))?"0":new String((String)object.getValue());

        if(name.equalsIgnoreCase("x"))
        {
          catValue=value;
        }
        else if(String.valueOf(name.charAt(0)).equalsIgnoreCase("x") ||
            String.valueOf(name.charAt(0)).equalsIgnoreCase("y")) {
         
          //String pos=name;
          String pos=String.valueOf(name.charAt(0));
          String numS=name.substring(1);
          int num=Integer.valueOf(numS).intValue();

          double valueD=0.0;
          try{
            valueD=(Double.valueOf(value)).doubleValue();
          }
          catch (NumberFormatException e) {
            Integer intero=Integer.valueOf(value);
            valueD=intero.doubleValue();

          }


          if(pos.equalsIgnoreCase("x")){
            //num++;
            x[num]=valueD;

            if(firstX){
              xTempMin=valueD;
              xTempMax=valueD;
              firstX=false;
            }
            if(valueD<xMin)xMin=valueD;
            if(valueD>xMax)xMax=valueD;


          }
          else if(pos.equalsIgnoreCase("y")){
            y[num]=valueD;

            if(firstY){
              yTempMin=valueD;
              yTempMax=valueD;
              firstY=false;
            }
            if(valueD<yMin)yMin=valueD;
            if(valueD>yMax)yMax=valueD;   
          }
        }
      }

      double[][] seriesT = new double[][] { y, x};

      dataset.addSeries(catValue, seriesT);
      series.add(catValue);
      //add annotations on the chart if requested
      if (viewAnnotations != null && viewAnnotations.equalsIgnoreCase("true")){
          double tmpx = seriesT[1][0];
          double tmpy = seriesT[0][0];
View Full Code Here

    return datasets;
  }

  public JFreeChart createChart(DatasetMap datasets) {

    DefaultXYDataset dataset=(DefaultXYDataset)datasets.getDatasets().get("1");

    JFreeChart chart = ChartFactory.createScatterPlot(
        name, yLabel, xLabel, dataset,
        PlotOrientation.HORIZONTAL, false, true, false);

    TextTitle title =setStyleTitle(name, styleTitle);
    chart.setTitle(title);
    chart.setBackgroundPaint(Color.white);
    if(subName!= null && !subName.equals("")){
      TextTitle subTitle =setStyleTitle(subName, styleSubTitle);
      chart.addSubtitle(subTitle);
    }
   
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setForegroundAlpha(0.65f);
   

    XYItemRenderer renderer = plot.getRenderer();

    //defines colors
    int seriesN=dataset.getSeriesCount();
    if((colorMap!=null && colorMap.size() > 0) || (defaultColor != null && !defaultColor.equals(""))){
      for (int i = 0; i < seriesN; i++) {
        String serieName=(String)dataset.getSeriesKey(i);
        Color color = new Color(Integer.decode(defaultColor).intValue());
        if (colorMap != null && colorMap.size() > 0) color=(Color)colorMap.get(serieName);
        if(color!=null) renderer.setSeriesPaint(i, color);         
      }
    }
View Full Code Here

public class SimpleScatter extends ScatterCharts {

  public JFreeChart createChart(DatasetMap datasets) {

    DefaultXYDataset dataset=(DefaultXYDataset)datasets.getDatasets().get("1");

    JFreeChart chart = ChartFactory.createScatterPlot(
        name, yLabel, xLabel, dataset,
        PlotOrientation.HORIZONTAL, false, true, false);

    Font font = new Font("Tahoma", Font.BOLD, titleDimension);
    //TextTitle title = new TextTitle(name, font);
    TextTitle title =setStyleTitle(name, styleTitle);
    chart.setTitle(title);
    chart.setBackgroundPaint(Color.white);
    if(subName!= null && !subName.equals("")){
      TextTitle subTitle =setStyleTitle(subName, styleSubTitle);
      chart.addSubtitle(subTitle);
    }
   
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setForegroundAlpha(0.65f);

    XYItemRenderer renderer = plot.getRenderer();


    int seriesN=dataset.getSeriesCount();
    if(colorMap!=null){
      for (int i = 0; i < seriesN; i++) {
        String serieName=(String)dataset.getSeriesKey(i);
        Color color=(Color)colorMap.get(serieName);
        if(color!=null){
          renderer.setSeriesPaint(i, color);
       
      }
View Full Code Here

  public DatasetMap calculateValue() throws Exception {
    logger.debug("IN");
    String res=DataSetAccessFunctions.getDataSetResultFromId(profile, getData(),parametersObject);

    DefaultXYDataset dataset = new DefaultXYDataset();

    SourceBean sbRows=SourceBean.fromXMLString(res);
    List listAtts=sbRows.getAttributeAsList("ROW");

    series=new Vector();

    boolean firstX=true;
    boolean firstY=true;
    double xTempMax=0.0;
    double xTempMin=0.0;
    double yTempMax=0.0;
    double yTempMin=0.0;
    boolean first=true;

    // In list atts there are all the series, let's run each
    for (Iterator iterator = listAtts.iterator(); iterator.hasNext();) {
      SourceBean serie = (SourceBean) iterator.next();
      List atts=serie.getContainedAttributes();

      String catValue="";
      String serValue="";

      if(first){
        if (name.indexOf("$F{") >= 0){
          setTitleParameter(atts);
        }
        if (getSubName()!= null &&  getSubName().indexOf("$F") >= 0){
          setSubTitleParameter(atts);
        }
        first=false;
      }

      double[] x=new double[atts.size()];
      double[] y=new double[atts.size()];

      //List x=new ArrayList();
      //List y=new ArrayList();
      //ArrayList z=new ArrayList();

      String name="";
      String value="";

      //run all the attributes of the serie
      for (Iterator iterator2 = atts.iterator(); iterator2.hasNext();) {
        SourceBeanAttribute object = (SourceBeanAttribute) iterator2.next();

        name=new String(object.getKey());
        value=(((String)object.getValue()).equals("null"))?"0":new String((String)object.getValue());

        if(name.equalsIgnoreCase("x"))
        {
          catValue=value;


        }

        else if(String.valueOf(name.charAt(0)).equalsIgnoreCase("x") ||
            String.valueOf(name.charAt(0)).equalsIgnoreCase("y")) {
          String pos=String.valueOf(name.charAt(0));
          String numS=name.substring(1);
          int num=Integer.valueOf(numS).intValue();

          double valueD=0.0;
          try{
            valueD=(Double.valueOf(value)).doubleValue();
          }
          catch (NumberFormatException e) {
            Integer intero=Integer.valueOf(value);
            valueD=intero.doubleValue();

          }


          if(pos.equalsIgnoreCase("x")){
            x[num]=valueD;

            if(firstX){
              xTempMin=valueD;
              xTempMax=valueD;
              firstX=false;
            }
            if(valueD<xTempMin)xTempMin=valueD;
            if(valueD>xTempMax)xTempMax=valueD;


          }
          else if(pos.equalsIgnoreCase("y")){
            y[num]=valueD;

            if(firstY){
              yTempMin=valueD;
              yTempMax=valueD;
              firstY=false;
            }
              if(valueD<yTempMin)yTempMin=valueD;
              if(valueD>yTempMax)yTempMax=valueD;   


          }
        }

      }
     
      xMin=xTempMin;
      xMax=xTempMax;
     
      yMin=yTempMin;
      yMax=yTempMax;
     

      double[][] seriesT = new double[][] { y, x};

      dataset.addSeries(catValue, seriesT);
      series.add(catValue);
      //add annotations on the chart if requested
      if (viewAnnotations != null && viewAnnotations.equalsIgnoreCase("true")){
        annotationMap.put(catValue, seriesT);
      }
View Full Code Here

    {
        String title = chartingDefinition.getChartTitle();
        String xAxisTitle = chartingDefinition.getXAxisTitle();
        String yAxisTitle = chartingDefinition.getYAxisTitle();

        final DefaultXYDataset dataset = new DefaultXYDataset();
        _seriesBuilder.setSeriesBuilderCallback(new SeriesBuilderCallback()
        {
            private List<Double[]> _xyPairs = null;

            @Override
            public void beginSeries(SeriesDefinition seriesDefinition)
            {
                _xyPairs = new ArrayList<Double[]>();
            }

            @Override
            public void addDataPointToSeries(SeriesDefinition seriesDefinition,
                    Object[] row)
            {
                double x = Double.parseDouble(row[0].toString());
                double y = Double.parseDouble(row[1].toString());
                _xyPairs.add(new Double[] {x, y});
            }


            @Override
            public void endSeries(SeriesDefinition seriesDefinition)
            {
                double[][] seriesData = listToSeriesDataArray();
                dataset.addSeries(seriesDefinition.getSeriesLegend(), seriesData);
            }

            private double[][] listToSeriesDataArray()
            {
                double[][] seriesData = new double[2][_xyPairs.size()];
View Full Code Here

        double[] score = {currentResults.getScoreLimit()};
        double[] fdr = {currentResults.getFdrLimit()};
        double[] fnr = {currentResults.getFnrLimit()};
        double[] benefit = {100 - currentResults.getFnrLimit()};

        DefaultXYDataset fdrData = new DefaultXYDataset();
        double[][] fdrSeries = {score, fdr};
        fdrData.addSeries("Retained FDR ", fdrSeries);
        fdrFnrPlot.setDataset(3, fdrData);
        fdrFnrPlot.mapDatasetToRangeAxis(3, 0);

        DefaultXYDataset probaFnrData = new DefaultXYDataset();
        double[][] probaFnrSeries = {score, fnr};
        probaFnrData.addSeries("Retained FNR ", probaFnrSeries);
        fdrFnrPlot.setDataset(4, probaFnrData);
        fdrFnrPlot.mapDatasetToRangeAxis(4, 0);

        XYLineAndShapeRenderer fdrRendrer = new XYLineAndShapeRenderer();
        fdrRendrer.setSeriesShapesVisible(0, true);
        fdrRendrer.setSeriesLinesVisible(0, false);
        fdrRendrer.setSeriesShape(0, DefaultDrawingSupplier.createStandardSeriesShapes()[1]);

        if (currentResults.isClassicalEstimators()) {
            fdrRendrer.setSeriesPaint(0, Color.blue);
        } else {
            fdrRendrer.setSeriesPaint(0, Color.green);
        }

        fdrFnrPlot.setRenderer(3, fdrRendrer);

        XYLineAndShapeRenderer probaFnrRendrer = new XYLineAndShapeRenderer();
        probaFnrRendrer.setSeriesShapesVisible(0, true);
        probaFnrRendrer.setSeriesLinesVisible(0, false);
        probaFnrRendrer.setSeriesPaint(0, Color.RED);
        probaFnrRendrer.setSeriesShape(0, DefaultDrawingSupplier.createStandardSeriesShapes()[2]);
        fdrFnrPlot.setRenderer(4, probaFnrRendrer);

        DefaultXYDataset benefitData = new DefaultXYDataset();
        double[][] benefitSeries = {fdr, benefit};
        benefitData.addSeries("Retained Cost/Benefit", benefitSeries);
        costBenefitPlot.setDataset(1, benefitData);
        costBenefitPlot.mapDatasetToRangeAxis(1, 0);

        XYLineAndShapeRenderer benefitRendrer = new XYLineAndShapeRenderer();
        benefitRendrer.setSeriesShapesVisible(0, true);
View Full Code Here

    /**
     * Updates the confidence chart.
     */
    private void updateConfidenceChart() {

        DefaultXYDataset confidenceData = new DefaultXYDataset();

        // get the x and y values for the plot
        double[] scores = targetDecoySeries.getScores();
        double[] confidences = targetDecoySeries.getConfidence();

        // extend the dataset by two elements to be able to make the vertical drop
        double[][] confidenceSeries = new double[2][scores.length + 2];
        double[][] tempSeries = new double[2][scores.length + 2];

        // get the location of the vertical red line
        double confidenceValue = confidenceMarker.getValue();

        int index = 0;

        // add all the values up to the red line
        while (index < scores.length && scores[index] < confidenceValue) {
            confidenceSeries[0][index] = scores[index];
            confidenceSeries[1][index] = confidences[index];
            tempSeries[0][index] = scores[index];
            tempSeries[1][index] = 100;
            index++;
        }

        if (index < scores.length) {

            double minorShift = 0.0000000001;

            // add the special cases surrounding the red line
            confidenceSeries[0][index] = confidenceValue - minorShift;
            confidenceSeries[1][index] = confidences[index];
            confidenceSeries[0][index + 1] = confidenceValue;
            confidenceSeries[1][index + 1] = confidences[index];
            confidenceSeries[0][index + 2] = confidenceValue + minorShift;
            confidenceSeries[1][index + 2] = confidences[index];

            tempSeries[0][index] = confidenceValue - minorShift;
            tempSeries[1][index] = 100;
            index++;
            tempSeries[0][index] = confidenceValue;
            tempSeries[1][index] = 50;
            index++;
            tempSeries[0][index] = confidenceValue + minorShift;
            tempSeries[1][index] = 0;
            index++;

            // add the values after the red line
            while (index < scores.length + 2) {

                confidenceSeries[0][index] = scores[index - 2];
                confidenceSeries[1][index] = confidences[index - 2];

                tempSeries[0][index] = scores[index - 2];
                tempSeries[1][index] = 0;
                index++;
            }
        }

        // add the series to the dataset
        confidenceData.addSeries("Confidence", confidenceSeries);
        confidenceData.addSeries("Area", tempSeries);
        confidencePlot.setDataset(0, confidenceData);

        // setup the renderer
        XYDifferenceRenderer confidenceRendrer = new XYDifferenceRenderer(fnrHighlightColor, fdrHighlightColor, false);
        confidenceRendrer.setSeriesPaint(0, Color.blue);
View Full Code Here

    /**
     * Updates the pep chart.
     */
    private void updatePepChart() {

        DefaultXYDataset pepData = new DefaultXYDataset();
        double[][] pepSeries = {targetDecoySeries.getScores(), targetDecoySeries.getPEP()};
        pepData.addSeries("PEP", pepSeries);
        pepPlot.setDataset(0, pepData);
        pepPlot.mapDatasetToRangeAxis(0, 0);

        XYLineAndShapeRenderer pepRendrer = new XYLineAndShapeRenderer();
        pepRendrer.setSeriesShapesVisible(0, false);
View Full Code Here

    /**
     * Updates the FDR estimators comparison chart.
     */
    private void updateFDRsChart() {
        DefaultXYDataset fdrsData = new DefaultXYDataset();
        double[][] fdrsSeries = {targetDecoySeries.getClassicalFDR(), targetDecoySeries.getProbaFDR()};
        fdrsData.addSeries("Probabilistic FDR", fdrsSeries);
        fdrPlot.setDataset(0, fdrsData);
        fdrPlot.mapDatasetToRangeAxis(0, 0);

        DefaultXYDataset refData = new DefaultXYDataset();
        double[][] refSeries = {targetDecoySeries.getClassicalFDR(), targetDecoySeries.getClassicalFDR()};
        refData.addSeries("x=y", refSeries);
        fdrPlot.setDataset(1, refData);
        fdrPlot.mapDatasetToRangeAxis(1, 0);

        XYLineAndShapeRenderer fdrsRendrer = new XYLineAndShapeRenderer();
        fdrsRendrer.setSeriesShapesVisible(0, false);
View Full Code Here

TOP

Related Classes of org.jfree.data.xy.DefaultXYDataset

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.