コード例 #1
0
ファイル: GallonsPlot.java プロジェクト: nikunjkacha/FillUp
  /**
   * DESCRIPTION: Creates the graph.
   *
   * @see android.app.Activity#onCreate(android.os.Bundle)
   */
  public void onCreate(Bundle savedInstanceState, Activity parent, XYPlot xyplot) {
    this.activity = parent;
    this.plot = xyplot;

    // get current units of measurement
    units = new Units(Settings.KEY_UNITS);

    // create a formatter to use for drawing the plot series
    plotFormatter =
        new BarFormatter(
            activity.getResources().getColor(R.color.plot_fill_color),
            activity.getResources().getColor(R.color.plot_line_color));

    // create a formatter for average label
    float hOffset = 50f;
    float vOffset = -10f;
    avgLabelFormatter =
        new PointLabelFormatter(
            activity.getResources().getColor(R.color.plot_avgline_color), hOffset, vOffset);

    // create a formatter to use for drawing the average line
    avgFormatter =
        new LineAndPointFormatter(
            activity.getResources().getColor(R.color.plot_avgline_color),
            null,
            null,
            avgLabelFormatter);

    // white background for the plot
    plot.getGraphWidget().getGridBackgroundPaint().setColor(Color.WHITE);

    // remove the series legend
    plot.getLayoutManager().remove(plot.getLegendWidget());

    // make room for bigger labels
    // TODO: is there a better way to do this?
    float width = plot.getGraphWidget().getRangeLabelWidth() * 2f;
    plot.getGraphWidget().setRangeLabelWidth(width);
    width = plot.getGraphWidget().getDomainLabelWidth() * 1.5f;
    plot.getGraphWidget().setDomainLabelWidth(width);
    float margin = plot.getGraphWidget().getMarginTop() * 3f;
    plot.getGraphWidget().setMarginTop(margin);
    margin = plot.getGraphWidget().getMarginBottom() * 3f;
    plot.getGraphWidget().setMarginBottom(margin);

    // define plot axis labels
    plot.setRangeLabel(units.getLiquidVolumeLabel());
    plot.setDomainLabel(activity.getString(R.string.months_label));

    // specify format of axis value labels
    plot.setRangeValueFormat(ylabels);
    plot.setDomainValueFormat(xlabels);

    // plot the data
    drawPlot();
  }
コード例 #2
0
ファイル: Poincare.java プロジェクト: Golis/Variand
  @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);
  }
コード例 #3
0
  @Override
  public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.bar_plot_example);

    // initialize our XYPlot reference:
    plot = (XYPlot) findViewById(R.id.plot);

    formatter1 = new MyBarFormatter(Color.rgb(100, 150, 100), Color.LTGRAY);
    formatter1.setMarginLeft(PixelUtils.dpToPix(1));
    formatter1.setMarginRight(PixelUtils.dpToPix(1));
    formatter2 = new MyBarFormatter(Color.rgb(100, 100, 150), Color.LTGRAY);
    formatter2.setMarginLeft(PixelUtils.dpToPix(1));
    formatter2.setMarginRight(PixelUtils.dpToPix(1));
    selectionFormatter = new MyBarFormatter(Color.YELLOW, Color.WHITE);

    selectionWidget =
        new TextLabelWidget(
            plot.getLayoutManager(),
            NO_SELECTION_TXT,
            new Size(
                PixelUtils.dpToPix(100), SizeMode.ABSOLUTE,
                PixelUtils.dpToPix(100), SizeMode.ABSOLUTE),
            TextOrientation.HORIZONTAL);

    selectionWidget.getLabelPaint().setTextSize(PixelUtils.dpToPix(16));

    // add a dark, semi-transparent background to the selection label widget:
    Paint p = new Paint();
    p.setARGB(100, 0, 0, 0);
    selectionWidget.setBackgroundPaint(p);

    selectionWidget.position(
        0,
        HorizontalPositioning.RELATIVE_TO_CENTER,
        PixelUtils.dpToPix(45),
        VerticalPositioning.ABSOLUTE_FROM_TOP,
        Anchor.TOP_MIDDLE);
    selectionWidget.pack();

    // reduce the number of range labels
    plot.setLinesPerRangeLabel(3);
    plot.setRangeLowerBoundary(0, BoundaryMode.FIXED);

    plot.setLinesPerDomainLabel(2);

    // setup checkbox listers:
    series1CheckBox = (CheckBox) findViewById(R.id.s1CheckBox);
    series1CheckBox.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            onS1CheckBoxClicked(b);
          }
        });

    series2CheckBox = (CheckBox) findViewById(R.id.s2CheckBox);
    series2CheckBox.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            onS2CheckBoxClicked(b);
          }
        });

    plot.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View view, MotionEvent motionEvent) {
            if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
              onPlotClicked(new PointF(motionEvent.getX(), motionEvent.getY()));
            }
            return true;
          }
        });

    spRenderStyle = (Spinner) findViewById(R.id.spRenderStyle);
    ArrayAdapter<BarRenderer.BarOrientation> adapter =
        new ArrayAdapter<BarRenderer.BarOrientation>(
            this, android.R.layout.simple_spinner_item, BarRenderer.BarOrientation.values());
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spRenderStyle.setAdapter(adapter);
    spRenderStyle.setSelection(BarRenderer.BarOrientation.OVERLAID.ordinal());
    spRenderStyle.setOnItemSelectedListener(
        new OnItemSelectedListener() {
          public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            updatePlot();
          }

          @Override
          public void onNothingSelected(AdapterView<?> arg0) {}
        });

    spWidthStyle = (Spinner) findViewById(R.id.spWidthStyle);
    ArrayAdapter<BarRenderer.BarGroupWidthMode> adapter1 =
        new ArrayAdapter<BarRenderer.BarGroupWidthMode>(
            this, android.R.layout.simple_spinner_item, BarRenderer.BarGroupWidthMode.values());
    adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spWidthStyle.setAdapter(adapter1);
    spWidthStyle.setSelection(BarRenderer.BarGroupWidthMode.FIXED_WIDTH.ordinal());
    spWidthStyle.setOnItemSelectedListener(
        new OnItemSelectedListener() {
          public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            if (BarRenderer.BarGroupWidthMode.FIXED_WIDTH.equals(spWidthStyle.getSelectedItem())) {
              sbFixedWidth.setVisibility(View.VISIBLE);
              sbVariableWidth.setVisibility(View.INVISIBLE);
            } else {
              sbFixedWidth.setVisibility(View.INVISIBLE);
              sbVariableWidth.setVisibility(View.VISIBLE);
            }
            updatePlot();
          }

          @Override
          public void onNothingSelected(AdapterView<?> arg0) {}
        });

    spSeriesSize = (Spinner) findViewById(R.id.spSeriesSize);
    ArrayAdapter<SeriesSize> adapter11 =
        new ArrayAdapter<SeriesSize>(
            this, android.R.layout.simple_spinner_item, SeriesSize.values());
    adapter11.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spSeriesSize.setAdapter(adapter11);
    spSeriesSize.setSelection(SeriesSize.TEN.ordinal());
    spSeriesSize.setOnItemSelectedListener(
        new OnItemSelectedListener() {
          public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            final SeriesSize selectedSize = (SeriesSize) arg0.getSelectedItem();
            switch (selectedSize) {
              case TEN:
                series1Numbers = series1Numbers10;
                series2Numbers = series2Numbers10;
                break;
              case TWENTY:
                series1Numbers = series1Numbers20;
                series2Numbers = series2Numbers20;
                break;
              case SIXTY:
                series1Numbers = series1Numbers60;
                series2Numbers = series2Numbers60;
                break;
              default:
                break;
            }
            updatePlot(selectedSize);
          }

          @Override
          public void onNothingSelected(AdapterView<?> arg0) {}
        });

    sbFixedWidth = (SeekBar) findViewById(R.id.sbFixed);
    sbFixedWidth.setProgress(50);
    sbFixedWidth.setOnSeekBarChangeListener(
        new SeekBar.OnSeekBarChangeListener() {
          @Override
          public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
            updatePlot();
          }

          @Override
          public void onStartTrackingTouch(SeekBar seekBar) {}

          @Override
          public void onStopTrackingTouch(SeekBar seekBar) {}
        });

    sbVariableWidth = (SeekBar) findViewById(R.id.sbVariable);
    sbVariableWidth.setProgress(1);
    sbVariableWidth.setVisibility(View.INVISIBLE);
    sbVariableWidth.setOnSeekBarChangeListener(
        new SeekBar.OnSeekBarChangeListener() {
          @Override
          public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
            updatePlot();
          }

          @Override
          public void onStartTrackingTouch(SeekBar seekBar) {}

          @Override
          public void onStopTrackingTouch(SeekBar seekBar) {}
        });

    plot.getGraph()
        .getLineLabelStyle(XYGraphWidget.Edge.BOTTOM)
        .setFormat(
            new NumberFormat() {
              @Override
              public StringBuffer format(double value, StringBuffer buffer, FieldPosition field) {
                int year = (int) (value + 0.5d) / 12;
                int month = (int) ((value + 0.5d) % 12);
                return new StringBuffer(
                    DateFormatSymbols.getInstance().getShortMonths()[month] + " '0" + year);
              }

              @Override
              public StringBuffer format(long value, StringBuffer buffer, FieldPosition field) {
                throw new UnsupportedOperationException("Not yet implemented.");
              }

              @Override
              public Number parse(String string, ParsePosition position) {
                throw new UnsupportedOperationException("Not yet implemented.");
              }
            });
    updatePlot();
  }