// Constructor sets up the series
    public mPlotUpdater(XYPlot plot) {
      this.plot = plot;
      // only display whole numbers in domain labels
      plot.getGraphWidget().setDomainValueFormat(new DecimalFormat("0"));

      // Line plot
      if (dispForm == "WAVE") {
        LineAndPointFormatter maxFormat =
            new LineAndPointFormatter(
                Color.rgb(0, 25, 250), // line color
                Color.rgb(0, 25, 250), // point color
                null); // fill color (optional)

        LineAndPointFormatter minFormat =
            new LineAndPointFormatter(
                Color.rgb(250, 25, 0), // line color
                Color.rgb(250, 25, 0), // point color
                null); // fill color (optional)

        LineAndPointFormatter audioFormat =
            new LineAndPointFormatter(
                Color.rgb(25, 250, 0), // line color
                Color.rgb(25, 250, 0), // point color
                null); // fill color (optional)

        plot.addSeries(audioHistSeries, audioFormat);
        plot.addSeries(maxSeries, maxFormat);
        plot.addSeries(minSeries, minFormat);
      }
      // Bar plot
      if (dispForm == "FFT") {
        plot.addSeries(
            audioHistSeries,
            BarRenderer.class,
            new BarFormatter(Color.argb(100, 0, 200, 0), Color.rgb(0, 80, 0)));
      }

      // thin out domain/range tick labels so they don't overlap each other:
      plot.setGridPadding(5, 0, 5, 0);
      plot.setTicksPerDomainLabel(5);
      plot.setTicksPerRangeLabel(3);
      plot.disableAllMarkup();

      // freeze the range boundaries:
      plot.setDomainStepMode(XYStepMode.INCREMENT_BY_VAL);
      plot.setDomainStepValue(1);
      plot.setTicksPerRangeLabel(6);
      if (dispForm == "WAVE") plot.setDomainLabel("Time");
      if (dispForm == "FFT ") plot.setDomainLabel("Frequency");
      plot.getDomainLabelWidget().pack();
      plot.setRangeLabel("Amplitude");
      plot.getRangeLabelWidget().pack();
      plot.disableAllMarkup();
    }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.zoomscrollgraph);
    mySimpleXYPlot = (XYPlot) findViewById(R.id.mySimpleXYPlot);
    mySimpleXYPlot.setOnTouchListener(this);

    // Plot layout configurations
    mySimpleXYPlot.getGraphWidget().setTicksPerRangeLabel(1);
    mySimpleXYPlot.getGraphWidget().setTicksPerDomainLabel(1);
    mySimpleXYPlot.getGraphWidget().setRangeValueFormat(new DecimalFormat("#####.##"));
    mySimpleXYPlot.getGraphWidget().setDomainValueFormat(new DecimalFormat("#####.##"));
    mySimpleXYPlot.getGraphWidget().setRangeLabelWidth(25);
    mySimpleXYPlot.setRangeLabel("");
    mySimpleXYPlot.setDomainLabel("");
    mySimpleXYPlot.disableAllMarkup();

    // Creation of the series
    final Vector<Double> vector = new Vector<Double>();
    for (double x = 0.0; x < Math.PI * 5; x += Math.PI / 20) {
      vector.add(x);
      vector.add(Math.sin(x));
    }
    mySeries = new SimpleXYSeries(vector, ArrayFormat.Y_VALS_ONLY, "Series Name");

    // colors: (line, vertex, fill)
    mySimpleXYPlot.addSeries(
        mySeries,
        LineAndPointRenderer.class,
        new LineAndPointFormatter(
            Color.rgb(0, 200, 0), Color.rgb(200, 0, 0), Color.argb(100, 0, 0, 100)));

    // Enact all changes
    mySimpleXYPlot.redraw();

    // Set of internal variables for keeping track of the boundaries
    mySimpleXYPlot.calculateMinMaxVals();
    m_viewPort = new Viewport(mySimpleXYPlot);
  }
Esempio n. 3
0
  private void ShowPlot() {
    mySimpleXYPlot = (XYPlot) findViewById(R.id.chartPlot);
    mySimpleXYPlot.setTitle("Weight");

    if (plotLine != null) mySimpleXYPlot.removeSeries(plotLine);

    mySimpleXYPlot.getGraphWidget().getGridBackgroundPaint().setColor(Color.WHITE);
    mySimpleXYPlot.getGraphWidget().getGridLinePaint().setColor(Color.BLACK);
    mySimpleXYPlot
        .getGraphWidget()
        .getGridLinePaint()
        .setPathEffect(new DashPathEffect(new float[] {1, 1}, 1));
    mySimpleXYPlot.getGraphWidget().getDomainOriginLinePaint().setColor(Color.BLACK);
    mySimpleXYPlot.getGraphWidget().getRangeOriginLinePaint().setColor(Color.BLACK);

    mySimpleXYPlot.setBorderStyle(Plot.BorderStyle.SQUARE, null, null);
    mySimpleXYPlot.getBorderPaint().setStrokeWidth(1);
    mySimpleXYPlot.getBorderPaint().setAntiAlias(false);
    mySimpleXYPlot.getBorderPaint().setColor(Color.WHITE);
    mySimpleXYPlot.getGraphWidget().setPaddingRight(5);

    // Create a formatter to use for drawing a series using LineAndPointRenderer:
    LineAndPointFormatter series1Format =
        new LineAndPointFormatter(
            Color.rgb(0, 100, 0), // line color
            Color.rgb(0, 100, 0), // point color
            Color.rgb(100, 200, 0)); // fill color

    // setup our line fill paint to be a slightly transparent gradient:
    Paint lineFill = new Paint();
    lineFill.setAlpha(200);
    lineFill.setShader(
        new LinearGradient(0, 0, 0, 250, Color.WHITE, Color.GREEN, Shader.TileMode.MIRROR));

    LineAndPointFormatter formatter =
        new LineAndPointFormatter(Color.rgb(0, 0, 0), Color.BLUE, Color.RED);
    formatter.setFillPaint(lineFill);

    plotLine = new SimpleXYSeries(Arrays.asList(dates), Arrays.asList(weights), "Weight over time");
    mySimpleXYPlot.addSeries(plotLine, formatter);
    mySimpleXYPlot.redraw();

    // draw a domain tick for each year:
    int min = DomainMin();
    int max = DomainMax();
    int domainStep = domainStep(min, max);
    mySimpleXYPlot.setDomainStep(XYStepMode.SUBDIVIDE, domainStep);
    // mySimpleXYPlot.setDomainBoundaries(min, max, BoundaryMode.AUTO);

    // customize our domain/range labels
    mySimpleXYPlot.setDomainLabel("Date");
    mySimpleXYPlot.setRangeLabel("Weight");

    Double minimum = FindMinimum();
    Double maximum = FindMaximum();
    Double stepSize = FindStep(maximum, minimum);
    mySimpleXYPlot.setRangeBoundaries(minimum, maximum, BoundaryMode.FIXED);
    mySimpleXYPlot.setRangeStep(XYStepMode.INCREMENT_BY_VAL, stepSize);

    mySimpleXYPlot.setDomainValueFormat(
        new Format() {
          private SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM");

          @Override
          public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) {

            // because our timestamps are in seconds and SimpleDateFormat expects milliseconds
            // we multiply our timestamp by 1000:
            long timestamp = ((Number) obj).longValue() * 1000;
            Date date = new Date(timestamp);
            return dateFormat.format(date, toAppendTo, pos);
          }

          @Override
          public Object parseObject(String source, ParsePosition pos) {
            return null;
          }
        });

    // by default, AndroidPlot displays developer guides to aid in laying out your plot.
    // To get rid of them call disableAllMarkup():
    mySimpleXYPlot.disableAllMarkup();
  }
Esempio n. 4
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.poincare);

    // Rellenar vector RR1
    for (int i = 1; i < Representar.RR.size(); i++) {
      RR1.add(Representar.RR.get(i));
    }
    // Rellenar vector RRaux
    for (int i = 0; i < Representar.RR.size() - 1; i++) {
      RRaux.add(Representar.RR.get(i));

      Log.i("RRaux", String.valueOf(Representar.RR.get(i)));
    }

    // Declarar el Plot
    mySimpleXYPlot = (XYPlot) findViewById(R.id.plotPoincare);

    // Configurar el Plot
    XYSeries series1 =
        new SimpleXYSeries(
            RRaux, // Vector a representar en el eje X
            RR1, // Vector a representar en el eje Y
            "Poincaré"); // Etiqueta

    LineAndPointFormatter series1Format =
        new LineAndPointFormatter(
            Color.TRANSPARENT, // Color de la línea
            Color.rgb(
                Representar.color0, Representar.color1, Representar.color2), // Color de los puntos
            null); // Color de relleno

    // Propiedades para configurar el Plot
    mySimpleXYPlot.addSeries(series1, series1Format);
    mySimpleXYPlot.setTicksPerRangeLabel(4);
    mySimpleXYPlot.disableAllMarkup();
    mySimpleXYPlot.getBackgroundPaint().setAlpha(0);
    mySimpleXYPlot.getGraphWidget().getBackgroundPaint().setAlpha(0);
    mySimpleXYPlot.getGraphWidget().getGridBackgroundPaint().setAlpha(0);
    // Redibujar el Plot
    mySimpleXYPlot.redraw();

    // Configuración boundaries
    mySimpleXYPlot.calculateMinMaxVals();
    // Cálculo del valor mínimo y máximo
    minXY =
        new PointF(
            mySimpleXYPlot.getCalculatedMinX().floatValue(),
            mySimpleXYPlot.getCalculatedMinY().floatValue());
    maxXY =
        new PointF(
            mySimpleXYPlot.getCalculatedMaxX().floatValue(),
            mySimpleXYPlot.getCalculatedMaxY().floatValue());
    mySimpleXYPlot.setScrollbarFadingEnabled(true);
    mySimpleXYPlot.setScrollContainer(true);

    mySimpleXYPlot.getLayoutManager().remove(mySimpleXYPlot.getLegendWidget());
    // Etiquetas vertical y horizontal
    mySimpleXYPlot.setRangeLabel("RR N+1");
    mySimpleXYPlot.setDomainLabel("RR N");
    mySimpleXYPlot.getLayoutManager().remove(mySimpleXYPlot.getTitleWidget());
    // Márgenes del Plot
    mySimpleXYPlot.setPlotMargins(10, 10, 10, 10);
    mySimpleXYPlot.setPlotPadding(10, 10, 10, 10);
    // Comienzo y fin del plot
    mySimpleXYPlot.setDomainBoundaries(
        mySimpleXYPlot.getCalculatedMinX().floatValue() - 10.0,
        mySimpleXYPlot.getCalculatedMaxX().floatValue() + 10.0,
        BoundaryMode.FIXED);
    mySimpleXYPlot.setRangeBoundaries(
        mySimpleXYPlot.getCalculatedMinY().floatValue() - 10.0,
        mySimpleXYPlot.getCalculatedMaxY().floatValue() + 10.0,
        BoundaryMode.FIXED);
  }
Esempio n. 5
0
  void generatePlot() {
    TextView tv = (TextView) findViewById(R.id.plotViewTitle);
    tv.setText(
        "Avistamientos durante " + meses[actualMonth - 1] + " del " + String.valueOf(actualYear));

    SQLiteDatabase myDB = null;

    myDB = this.openOrCreateDatabase(DB_NAME, 1, null);

    myDB.execSQL(
        "CREATE TABLE IF NOT EXISTS "
            + TABLE
            + " ("
            + ADDR_DB
            + " TEXT NOT NULL PRIMARY KEY, "
            + COORD_X_DB
            + " INTEGER NOT NULL, "
            + COORD_Y_DB
            + " INTEGER NOT NULL, "
            + INF_DB
            + " TEXT, "
            + DAY_DB
            + " INTEGER, "
            + MONTH_DB
            + " INTEGER, "
            + YEAR_DB
            + " INTEGER);");

    /*
     * Solo obtendremos los días donde se han visto avistamientos ordenados por menor a mayor.
     */
    String[] FROM = {DAY_DB};
    String ORDER_BY = YEAR_DB + " DESC, " + MONTH_DB + " DESC, " + DAY_DB + " DESC";

    Cursor c =
        myDB.query(
            TABLE,
            FROM,
            MONTH_DB + "=" + actualMonth + " AND " + YEAR_DB + "=" + actualYear,
            null,
            null,
            null,
            ORDER_BY);

    /*
     * Preparamos el vector de Number dependiendo del mes que tengamos que mostrar
     */
    Number[] series1Numbers;
    int daysOfMonth = 0;

    if (actualMonth == 1
        || actualMonth == 3
        || actualMonth == 5
        || actualMonth == 7
        || actualMonth == 8
        || actualMonth == 10
        || actualMonth == 12) {
      daysOfMonth = 32;
      series1Numbers = new Number[daysOfMonth];
      for (int i = 0; i < daysOfMonth; ++i) series1Numbers[i] = 0;
    } else if (actualMonth == 2) {
      daysOfMonth = 29;
      series1Numbers = new Number[daysOfMonth];
      for (int i = 0; i < daysOfMonth; ++i) series1Numbers[i] = 0;
    } else {
      daysOfMonth = 31;
      series1Numbers = new Number[daysOfMonth];
      for (int i = 0; i < daysOfMonth; ++i) series1Numbers[i] = 0;
    }

    int max = 0; // sirve para establecer el máximo Y valor del gráfico
    int aux = 0;
    int dayAux = 0;

    startManagingCursor(c);
    while (c.moveToNext()) {
      int dayDB = c.getInt(0);
      if (max < aux) max = aux;
      if (dayAux == 0) {
        dayAux = dayDB;
        ++aux;
      } else {
        if (dayAux == dayDB) ++aux;
        else {
          series1Numbers[dayAux] = aux;
          aux = 1;
          dayAux = dayDB;
        }
      }
    }
    if (dayAux != 0) series1Numbers[dayAux] = aux;

    c.close();

    if (myDB != null) {
      myDB.close();
    }

    // Inicializamos el objeto XYPlot búscandolo desde el layout:
    mySimpleXYPlot = (XYPlot) findViewById(R.id.plot);
    mySimpleXYPlot.clear();
    mySimpleXYPlot.setDomainLabel("Días de " + meses[actualMonth - 1]);
    mySimpleXYPlot.setRangeLabel("Número de avistamientos");

    // Añadimos Línea Número UNO:
    XYSeries series1 =
        new SimpleXYSeries(
            Arrays.asList(series1Numbers), // Array de datos
            SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, // Valores verticales
            "Número de avistamientos"); // Nombre de la serie

    // Modificamos los colores de la primera serie
    LineAndPointFormatter series1Format =
        new LineAndPointFormatter(
            Color.rgb(200, 0, 0), // Color de la l�nea
            Color.rgb(0, 0, 0), // Color del punto
            Color.rgb(190, 150, 150)); // Relleno

    // Una vez definida la serie (datos y estilo), la añadimos al panel
    mySimpleXYPlot.addSeries(series1, series1Format);

    if (max == 0) ++max;

    // Tuneamos el grafico
    mySimpleXYPlot.setDomainValueFormat(new DecimalFormat("#"));
    mySimpleXYPlot.setDomainBoundaries(1, daysOfMonth - 1, BoundaryMode.FIXED);
    mySimpleXYPlot.setDomainStepValue(daysOfMonth);
    if (daysOfMonth == 32) {
      mySimpleXYPlot.setTicksPerDomainLabel(2);
    } else if (daysOfMonth == 31) {
      mySimpleXYPlot.setTicksPerDomainLabel(3);
    } else if (daysOfMonth == 28) {
      mySimpleXYPlot.setTicksPerDomainLabel(2);
    }
    mySimpleXYPlot.setRangeUpperBoundary(max + 2, BoundaryMode.FIXED);
    mySimpleXYPlot.setRangeStepValue(max + 3);
    mySimpleXYPlot.setTicksPerRangeLabel(1);
    mySimpleXYPlot.disableAllMarkup();

    /*
     * Generamos la vista de nueva para mostrar la nueva gráfica
     */
    ScrollView sv = (ScrollView) findViewById(R.id.scrollView);
    sv.postInvalidate();
  }