0

I am using Androidplot to display real time data. The real time data is dynamic and the x axis is time. The domain is a fixed timespan. Because the values could be any double, rangeStepMode is set to subdivide the y-axis. The issue is that when all the values are the same, the plot does not draw correctly.

non-working plot

You can see in the image that there are no range grids or labels.

From this related question:

This happens because Androidplot does not have enough information to automatically calculate what a reasonable domain/range scale would be from a single point.

This makes sense, and the linked solution of setting a non-zero range boundary works but instead of an arbitrary range like miny - 1to maxy + 1, I'd like for there to be only one labeled range line in these cases across the middle of the screen.

Single Range Line

My Activity:

public class SimpleXYPlotActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.simple_xy_plot_example);
        XYPlot plot = (XYPlot) findViewById(R.id.plot);
        Number[] series1Numbers = new Number[]{
                1,
                1,
        };
        XYSeries series1 = new SimpleXYSeries(SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Series1", series1Numbers);
        LineAndPointFormatter series1Format = new LineAndPointFormatter(Color.RED, Color.GREEN, null, null);
        plot.addSeries(series1, series1Format);


        StepMode stepMode = StepMode.SUBDIVIDE;
        int stepValue = 10;
        plot.setRangeStepMode(stepMode);
        plot.setRangeStepValue(stepValue);
    }
}

My Layout:

<com.androidplot.xy.XYPlot
    android:id="@+id/plot"
    style="@style/APDefacto.Dark"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    ap:rangeStep="5"
    ap:rangeStepMode="subdivide"
    ap:domainStep="1"
    ap:domainStepMode="increment_by_val"
    />

What I've tried

The following works on the simple xy example, but when I try setting it within minmax in my time series class, the thread drawing the domain gridlines gets into a very long loop as it calculates xPix to be very very large. This also isn't a very solution for situations where I have multiple series. Any ideas on how I can get the results I want?

    Double minY = null;
    Double maxY = null;
    for (Double aDouble : series1Numbers) {
        if (minY == null) {
            minY = aDouble;
        } else {
            minY = Math.min(minY, aDouble);
        }
        if (maxY == null) {
            maxY = aDouble;
        } else {
            maxY = Math.max(maxY, aDouble);
        }
    }
    if (minY.equals(maxY)) {
        plot.setUserRangeOrigin(minY);
        plot.setRangeBoundaries(0, 2 * maxY, BoundaryMode.FIXED);
        plot.setRangeStepMode(StepMode.INCREMENT_BY_PIXELS);
        plot.setRangeStepValue(Double.POSITIVE_INFINITY);
    } else {
        plot.setUserRangeOrigin(0);
        plot.setRangeBoundaries(minY, maxY, BoundaryMode.FIXED);
        plot.setRangeStepMode(StepMode.SUBDIVIDE);
        plot.setRangeStepValue(5);
    }
Jon
  • 9,156
  • 9
  • 56
  • 73

1 Answers1

0

This wont get rid of the CPU overhead but you can use PlotUtils.minMax to find these values for you

If implementing and using FastXYSeries is a possibility for you then the overhead of using minMax drops away too, as the calculation only ever gets done when your XYSeries data changes.

Nick
  • 8,181
  • 4
  • 38
  • 63