robinhood/spark

Set Data Bound, Y max and Y min

alifgiant opened this issue · 3 comments

How can we set a minimum and maximum value for the graph?
I can't found it on docs. is there a way?

You should be able to override SparkAdapter.getDataBounds() and return whatever min/max values you want for x and y. Is that what you mean?

Yeah, that's exactly what i mean. I think, you should add it to your Readme.md

import android.graphics.RectF;
...
        @Override
        public RectF getDataBounds() {
            final int count = getCount();

            float minY = -0.1f;  // custom value
            float maxY = 0.1f;  // custom value
            float minX = Float.MAX_VALUE;
            float maxX = -Float.MAX_VALUE;
            for (int i = 0; i < count; i++) {
                final float x = getX(i);
                minX = Math.min(minX, x);
                maxX = Math.max(maxX, x);

                final float y = getY(i);
                minY = Math.min(minY, y);
                maxY = Math.max(maxY, y);
            }

            // set custom values on the return object
            return new RectF(minX, minY, maxX, maxY);
        }

or something like that. Thank you very much