Ejemplo n.º 1
0
  private void updatePlot(SeriesSize seriesSize) {

    // Remove all current series from each plot
    plot.clear();

    // Setup our Series with the selected number of elements
    series1 =
        new SimpleXYSeries(
            Arrays.asList(series1Numbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Us");
    series2 =
        new SimpleXYSeries(
            Arrays.asList(series2Numbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Them");

    plot.setDomainBoundaries(-1, series1.size(), BoundaryMode.FIXED);
    plot.setRangeUpperBoundary(
        SeriesUtils.minMax(series1, series2).getMaxY().doubleValue() + 1, BoundaryMode.FIXED);

    if (seriesSize != null) {
      switch (seriesSize) {
        case TEN:
          plot.setDomainStep(StepMode.INCREMENT_BY_VAL, 2);
          break;
        case TWENTY:
          plot.setDomainStep(StepMode.INCREMENT_BY_VAL, 4);
          break;
        case SIXTY:
          plot.setDomainStep(StepMode.INCREMENT_BY_VAL, 6);
          break;
      }
    }

    // add a new series' to the xyplot:
    if (series1CheckBox.isChecked()) plot.addSeries(series1, formatter1);
    if (series2CheckBox.isChecked()) plot.addSeries(series2, formatter2);

    // Setup the BarRenderer with our selected options
    MyBarRenderer renderer = plot.getRenderer(MyBarRenderer.class);
    renderer.setBarOrientation((BarRenderer.BarOrientation) spRenderStyle.getSelectedItem());
    final BarRenderer.BarGroupWidthMode barGroupWidthMode =
        (BarRenderer.BarGroupWidthMode) spWidthStyle.getSelectedItem();
    renderer.setBarGroupWidth(
        barGroupWidthMode,
        barGroupWidthMode == BarRenderer.BarGroupWidthMode.FIXED_WIDTH
            ? sbFixedWidth.getProgress()
            : sbVariableWidth.getProgress());

    if (BarRenderer.BarOrientation.STACKED.equals(spRenderStyle.getSelectedItem())) {
      plot.getInnerLimits().setMaxY(15);
    } else {
      plot.getInnerLimits().setMaxY(0);
    }

    plot.redraw();
  }
Ejemplo n.º 2
0
  public GraphUpdater(Activity activity) {
    this.activity = activity;
    wifi = (WifiManager) activity.getSystemService(Context.WIFI_SERVICE);
    plot = (XYPlot) activity.findViewById(R.id.graph);
    hash = new HashMap<String, WifiStrengthXYSeries>();

    plot.setTitle("");
    plot.setTicksPerRangeLabel(2);
    plot.setDomainStep(XYStepMode.INCREMENT_BY_VAL, 1);
    plot.setDomainBoundaries(-1, 15, BoundaryMode.FIXED);
    plot.setDomainLabel("Channel");
    DecimalFormat df = new DecimalFormat("#0");
    df.setParseIntegerOnly(true);
    plot.setDomainValueFormat(df);
    plot.setRangeBoundaries(-100, -20, BoundaryMode.FIXED);
    plot.setRangeLabel("Strength");
    plot.getLegendWidget().setVisible(false);
  }
Ejemplo n.º 3
0
  /** DESCRIPTION: Sets the boundaries for the X and Y-axis based on the data values. */
  private void setPlotAxisBoundaries() {

    // set y-axis boundaries
    long boundy = 25;
    while (maxy >= boundy) boundy *= 2;
    plot.setRangeBoundaries(0, (float) boundy, BoundaryMode.FIXED);

    // set y-axis steps
    double stepy = ((double) boundy) / 10;
    plot.setRangeStep(XYStepMode.INCREMENT_BY_VAL, stepy);
    plot.setTicksPerRangeLabel(2);

    // set x-axis boundaries
    lowerboundx = minx - 1;
    upperboundx = maxx + 1;
    plot.setDomainBoundaries(lowerboundx, upperboundx, BoundaryMode.FIXED);

    // set x-axis steps
    plot.setDomainStep(XYStepMode.INCREMENT_BY_VAL, 1);
    plot.setTicksPerDomainLabel(1);

    // determine the number of months being plotted
    long months = maxx - minx + 1;

    // adjust bar thickness based on number of months being plotted
    BarRenderer<?> barRenderer = (BarRenderer<?>) plot.getRenderer(BarRenderer.class);
    if (barRenderer != null) {
      Display display = activity.getWindowManager().getDefaultDisplay();
      float displayWidth = Utilities.convertPixelsToDp(display.getWidth());
      float plotWidth = displayWidth * 0.75f;
      float barWidth = plotWidth / months;
      barRenderer.setBarWidth(barWidth);
    }

    // adjust label size based on number of months being plotted
    xlabels.setAbbreviate(months > 6);
  }
Ejemplo n.º 4
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();
  }